Ticket #973: naval-manager.diff
File naval-manager.diff, 6.4 KB (added by , 10 years ago) |
---|
-
0ad/binaries/data/mods/public/simulation/ai/aegis/naval-manager.js
22 22 this.seaShips = []; 23 23 this.seaTpShips = []; 24 24 this.seaWarships = []; 25 this.fishingShips = []; 25 26 26 27 // wanted NB per zone. 27 28 this.wantedTpShips = []; 28 29 this.wantedWarships = []; 30 this.wantedFishShips = []; 29 31 30 32 this.transportPlans = []; 31 33 this.askedPlans = []; … … 42 44 // note: those two can overlap (some transport ships are warships too and vice-versa). 43 45 this.tpShips = this.ships.filter(Filters.byCanGarrison()); 44 46 this.warships = this.ships.filter(Filters.byClass("Warship")); 47 this.fishingShips = this.ships.filter(Filters.byClass("FishingBoat")); 45 48 46 49 this.ships.registerUpdates(); 47 50 this.tpShips.registerUpdates(); 48 51 this.warships.registerUpdates(); 52 this.fishingShips.registerUpdates(); 49 53 50 54 for (var i = 0; i < gameState.ai.accessibility.regionSize.length; ++i) 51 55 { … … 55 59 this.seaShips.push(new EntityCollection(gameState.sharedScript)); 56 60 this.seaTpShips.push(new EntityCollection(gameState.sharedScript)); 57 61 this.seaWarships.push(new EntityCollection(gameState.sharedScript)); 62 this.fishingShips.push(new EntityCollection(gameState.sharedScript)); 58 63 this.wantedTpShips.push(0); 59 64 this.wantedWarships.push(0); 65 this.wantedFishShips.push(0); 60 66 } else { 61 67 var collec = this.ships.filter(Filters.byStaticMetadata(PlayerID, "sea", i)); 62 68 collec.registerUpdates(); … … 67 73 var collec = this.warships.filter(Filters.byStaticMetadata(PlayerID, "sea", i)); 68 74 collec.registerUpdates(); 69 75 this.seaWarships.push(collec); 76 collec = this.warships.filter(Filters.byStaticMetadata(PlayerID, "sea", i)); 77 collec.registerUpdates(); 70 78 71 79 this.wantedTpShips.push(1); 72 80 this.wantedWarships.push(1); … … 181 189 NavalManager.prototype.maintainFleet = function(gameState, queues, events) { 182 190 // check if we have enough transport ships. 183 191 // check per region. 192 193 // check if we can build the Ptolemaic Champion Juggernaut. 194 var superShipAllowed = gameState.getTemplate(gameState.applyCiv("units/ptol_champion_juggernaut")).available(gameState); 195 196 // check if we can build more than one. 197 var hasSuperShipHero = ((gameState.getOwnEntities().filter(Filters.byType("units/ptol_hero_ptolemy_IV"))).length() === 1) ? true : false; 198 199 // check how many we already have. 200 var totalSuperShips = (gameState.getOwnEntities().filter(Filters.byType("units/ptol_champion_juggernaut"))).length(); 184 201 for (var i = 0; i < this.seaShips.length; ++i) 185 202 { 186 203 var tpNb = gameState.countOwnQueuedEntitiesWithMetadata("sea", i); 187 if (this.accessibleSeas.indexOf(i) !== -1 && this.seaTpShips[i].length < this.wantedTpShips[i]188 && tpNb + queues.ships.length() === 0 && gameState.getTemplate(gameState.applyCiv("units/{civ}_ship_bireme")).available(gameState))204 var warNb = gameState.countOwnQueuedEntitiesWithMetadata("sea", (0 - i)); 205 if (this.accessibleSeas.indexOf(i) !== -1) 189 206 { 190 // TODO: check our dock can build the wanted ship types, for Carthage. 191 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_bireme", { "sea" : i }, 1, 0, -1, 1 )); 192 } 207 if (gameState.getTemplate(gameState.applyCiv("units/iber_ship_fire")).available(gameState)) // Check our naval options. 208 { 209 if (this.seaWarships[i].length < this.wantedWarships[i] && warNb + queues.ships.length() === 0) 210 { 211 queues.ships.addItem(new TrainingPlan(gameState, "units/iber_ship_fire", { "sea" : (0 - i) }, 1, 0, -1, 1)); 212 } 213 if (this.seaTpShips[i].length < this.wantedTpShips[i] && tpNb + queues.ships.length() === 0) 214 { 215 queues.ships.addItem(new TrainingPlan(gameState, "units/iber_ship_merchant", { "sea" : i }, 1, 0, -1, 1)); 216 } 217 } 218 else 219 { 220 if (gameState.getTemplate(gameState.applyCiv("units/{civ}_ship_quinquereme")).available(gameState)) // Check if we command Rome, Carthage, Ptolemies, or Seleucids. 221 { 222 if (this.seaWarships[i].length < this.wantedWarships[i] && warNb + queues.ships.length() === 0) 223 { 224 if (i % 5 === 0) // be sparing in production of big ships, so as to conserve resources and population space. 225 { 226 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_quinquereme", { "sea" : (0 - i) }, 1, 0, -1, 1)); 227 } 228 else 229 { 230 if (i % 7 === 0 && superShipAllowed && (totalSuperShips === 0 || (totalSuperShips < 5 && hasSuperShipHero))) 231 { 232 queues.ships.addItem(new TrainingPlan(gameState, "units/ptol_champion_juggernaut", { "sea" : (0 - i) }, 1, 0, -1, 1)); 233 } 234 else 235 { 236 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_trireme", { "sea" : (0 - i) }, 1, 0, -1, 1)); 237 } 238 } 239 } 240 if (this.seaTpShips[i].length < this.wantedTpShips[i] && tpNb + queues.ships.length() === 0) 241 { 242 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_bireme", { "sea" : i }, 1, 0, -1, 1)); 243 } 244 } 245 else 246 { 247 if (this.seaWarships[i].length < this.wantedWarships[i] && warNb + queues.ships.length() === 0) 248 { 249 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_trireme", { "sea" : (0 - i) }, 1, 0, -1, 1)); 250 } 251 if (this.seaTpShips[i].length < this.wantedTpShips && tpNb + queues.ships.length() === 0) 252 { 253 if (gameState.getTemplate(gameState.applyCiv("units/{civ}_ship_bireme")).available(gameState)) 254 { 255 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_bireme", { "sea" : i }, 1, 0, -1, 1)); 256 } 257 else 258 { 259 if (i % 3 === 0) 260 { 261 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_trireme", { "sea" : i }, 1, 0. -1, 1)); 262 } 263 else 264 { 265 queues.ships.addItem(new TrainingPlan(gameState, "units/{civ}_ship_merchant", { "sea" : i }, 1, 0, -1, 1)); 266 } 267 } 268 269 } 270 } 271 } 272 } 193 273 } 194 274 }; 195 275 276 NavalManager.prototype.findFish = function(gameState, resource) { 277 }; 278 279 NavalManager.prototype.orderFishing = function(gameState, queues) { 280 }; 281 196 282 // bumps up the number of ships we want if we need more. 197 283 NavalManager.prototype.checkLevels = function(gameState, queues) { 198 284 if (queues.ships.length() !== 0)