Ticket #3858: AITerritory.patch
File AITerritory.patch, 5.2 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/ai/petra/baseManager.js
172 172 for (let entity of this.buildings.values()) 173 173 bestbase.assignEntity(gameState, entity); 174 174 gameState.ai.HQ.resetActiveBase(); 175 gameState.ai.HQ.updateTerritories(gameState);176 175 }; 177 176 178 177 /** -
binaries/data/mods/public/simulation/ai/petra/headquarters.js
31 31 this.targetNumWorkers = this.Config.Economy.targetNumWorkers; 32 32 this.supportRatio = this.Config.Economy.supportRatio; 33 33 34 this.lastTerritoryUpdate = -1;35 34 this.stopBuilding = new Map(); // list of buildings to stop (temporarily) production because no room 36 35 37 36 this.fortStartTime = 180; // wooden defense towers, will start at fortStartTime + towerLapseTime … … 95 94 let base = this.getBaseByID(ent.getMetadata(PlayerID, "base")); 96 95 base.assignResourceToDropsite(gameState, ent); 97 96 } 97 98 this.updateTerritories(gameState); 98 99 }; 99 100 100 101 // returns the sea index linking regions 1 and region 2 (supposed to be different land region) … … 117 118 118 119 m.HQ.prototype.checkEvents = function (gameState, events, queues) 119 120 { 121 for (let evt of events.TerritoriesChanged) 122 { 123 this.updateTerritories(gameState); 124 break; 125 } 126 120 127 for (let evt of events.Create) 121 128 { 122 129 // Let's check if we have a building set to create a new base. … … 178 185 base.anchor = ent; 179 186 base.anchorId = evt.newentity; 180 187 base.buildings.updateEnt(ent); 181 this.updateTerritories(gameState);182 188 if (base.ID === this.baseManagers[1].ID) 183 189 { 184 190 // this is our first base, let us configure our starting resources … … 191 197 this.saveSpace = undefined; 192 198 } 193 199 } 194 else if (ent.hasTerritoryInfluence())195 this.updateTerritories(gameState);196 200 } 197 201 } 198 202 … … 237 241 newbase.init(gameState, "captured"); 238 242 newbase.setAnchor(gameState, ent); 239 243 this.baseManagers.push(newbase); 240 this.updateTerritories(gameState);241 244 newbase.assignEntity(gameState, ent); 242 245 } 243 246 else … … 244 247 { 245 248 // TODO should be reassigned later if a better base is captured 246 249 m.getBestBase(gameState, ent).assignEntity(gameState, ent); 247 if (ent.hasTerritoryInfluence())248 this.updateTerritories(gameState);249 250 if (ent.decaying()) 250 251 { 251 252 if (ent.isGarrisonHolder() && this.garrisonManager.addDecayingStructure(gameState, evt.entity, true)) … … 1824 1825 1825 1826 m.HQ.prototype.updateTerritories = function(gameState) 1826 1827 { 1827 // TODO may-be update also when territory decreases. For the moment, only increases are taking into account1828 if (this.lastTerritoryUpdate == gameState.ai.playedTurn)1829 return;1830 this.lastTerritoryUpdate = gameState.ai.playedTurn;1831 1832 1828 var passabilityMap = gameState.getMap(); 1833 1829 var width = this.territoryMap.width; 1834 1830 var cellSize = this.territoryMap.cellSize; … … 2066 2062 phaseName = gameState.getTemplate(gameState.cityPhase()).name(); 2067 2063 2068 2064 m.chatNewPhase(gameState, phaseName, false); 2069 this.updateTerritories(gameState);2070 2065 } 2071 else if (gameState.ai.playedTurn - this.lastTerritoryUpdate > 100)2072 this.updateTerritories(gameState);2073 2066 2074 2067 if (gameState.getGameType() === "wonder") 2075 2068 this.buildWonder(gameState, queues); … … 2145 2138 "lastFailedGather": this.lastFailedGather, 2146 2139 "supportRatio": this.supportRatio, 2147 2140 "targetNumWorkers": this.targetNumWorkers, 2148 "lastTerritoryUpdate": this.lastTerritoryUpdate,2149 2141 "stopBuilding": this.stopBuilding, 2150 2142 "fortStartTime": this.fortStartTime, 2151 2143 "towerStartTime": this.towerStartTime, -
binaries/data/mods/public/simulation/components/AIInterface.js
16 16 "OwnershipChanged", 17 17 "Garrison", 18 18 "UnGarrison", 19 "TerritoriesChanged", 19 20 "TerritoryDecayChanged", 20 21 "TributeExchanged", 21 22 "AttackRequest" … … 166 167 167 168 AIInterface.prototype.OnGlobalPlayerDefeated = function(msg) 168 169 { 169 this.events ["PlayerDefeated"].push(msg);170 this.events.PlayerDefeated.push(msg); 170 171 }; 171 172 172 173 AIInterface.prototype.OnGlobalEntityRenamed = function(msg) … … 173 174 { 174 175 var cmpMirage = Engine.QueryInterface(msg.entity, IID_Mirage); 175 176 if (!cmpMirage) 176 this.events ["EntityRenamed"].push(msg);177 this.events.EntityRenamed.push(msg); 177 178 }; 178 179 179 180 AIInterface.prototype.OnGlobalTributeExchanged = function(msg) 180 181 { 181 this.events ["TributeExchanged"].push(msg);182 this.events.TributeExchanged.push(msg); 182 183 }; 183 184 185 AIInterface.prototype.OnTerritoriesChanged = function(msg) 186 { 187 this.events.TerritoriesChanged.push(msg); 188 }; 189 184 190 // When a new technology is researched, check which templates it affects, 185 191 // and send the updated values to the AI. 186 192 // this relies on the fact that any "value" in a technology can only ever change