Ticket #973: naval-manager.diff

File naval-manager.diff, 6.4 KB (added by Darth_Malloc, 10 years ago)
  • 0ad/binaries/data/mods/public/simulation/ai/aegis/naval-manager.js

     
    2222    this.seaShips = [];
    2323    this.seaTpShips = [];
    2424    this.seaWarships = [];
     25    this.fishingShips = [];
    2526
    2627    // wanted NB per zone.
    2728    this.wantedTpShips = [];
    2829    this.wantedWarships = [];
     30    this.wantedFishShips = [];
    2931   
    3032    this.transportPlans = [];
    3133    this.askedPlans = [];
     
    4244    // note: those two can overlap (some transport ships are warships too and vice-versa).
    4345    this.tpShips = this.ships.filter(Filters.byCanGarrison());
    4446    this.warships = this.ships.filter(Filters.byClass("Warship"));
     47    this.fishingShips = this.ships.filter(Filters.byClass("FishingBoat"));
    4548
    4649    this.ships.registerUpdates();
    4750    this.tpShips.registerUpdates();
    4851    this.warships.registerUpdates();
     52    this.fishingShips.registerUpdates();
    4953   
    5054    for (var i = 0; i < gameState.ai.accessibility.regionSize.length; ++i)
    5155    {
     
    5559            this.seaShips.push(new EntityCollection(gameState.sharedScript));
    5660            this.seaTpShips.push(new EntityCollection(gameState.sharedScript));
    5761            this.seaWarships.push(new EntityCollection(gameState.sharedScript));
     62            this.fishingShips.push(new EntityCollection(gameState.sharedScript));
    5863            this.wantedTpShips.push(0);
    5964            this.wantedWarships.push(0);
     65            this.wantedFishShips.push(0);
    6066        } else {
    6167            var collec = this.ships.filter(Filters.byStaticMetadata(PlayerID, "sea", i));
    6268            collec.registerUpdates();
     
    6773            var collec = this.warships.filter(Filters.byStaticMetadata(PlayerID, "sea", i));
    6874            collec.registerUpdates();
    6975            this.seaWarships.push(collec);
     76            collec = this.warships.filter(Filters.byStaticMetadata(PlayerID, "sea", i));
     77            collec.registerUpdates();
    7078           
    7179            this.wantedTpShips.push(1);
    7280            this.wantedWarships.push(1);
     
    181189NavalManager.prototype.maintainFleet = function(gameState, queues, events) {
    182190    // check if we have enough transport ships.
    183191    // 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();
    184201    for (var i = 0; i < this.seaShips.length; ++i)
    185202    {
    186203        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)
    189206        {
    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        }           
    193273    }
    194274};
    195275
     276NavalManager.prototype.findFish = function(gameState, resource) {
     277};
     278
     279NavalManager.prototype.orderFishing = function(gameState, queues) {
     280};
     281
    196282// bumps up the number of ships we want if we need more.
    197283NavalManager.prototype.checkLevels = function(gameState, queues) {
    198284    if (queues.ships.length() !== 0)