Ticket #3858: AITerritory-v2.patch
File AITerritory-v2.patch, 5.5 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 if (events.TerritoriesChanged.length || events.DiplomacyChanged.length) 122 this.updateTerritories(gameState); 123 120 124 for (let evt of events.Create) 121 125 { 122 126 // Let's check if we have a building set to create a new base. … … 178 182 base.anchor = ent; 179 183 base.anchorId = evt.newentity; 180 184 base.buildings.updateEnt(ent); 181 this.updateTerritories(gameState);182 185 if (base.ID === this.baseManagers[1].ID) 183 186 { 184 187 // this is our first base, let us configure our starting resources … … 191 194 this.saveSpace = undefined; 192 195 } 193 196 } 194 else if (ent.hasTerritoryInfluence())195 this.updateTerritories(gameState);196 197 } 197 198 } 198 199 … … 237 238 newbase.init(gameState, "captured"); 238 239 newbase.setAnchor(gameState, ent); 239 240 this.baseManagers.push(newbase); 240 this.updateTerritories(gameState);241 241 newbase.assignEntity(gameState, ent); 242 242 } 243 243 else … … 244 244 { 245 245 // TODO should be reassigned later if a better base is captured 246 246 m.getBestBase(gameState, ent).assignEntity(gameState, ent); 247 if (ent.hasTerritoryInfluence())248 this.updateTerritories(gameState);249 247 if (ent.decaying()) 250 248 { 251 249 if (ent.isGarrisonHolder() && this.garrisonManager.addDecayingStructure(gameState, evt.entity, true)) … … 1824 1822 1825 1823 m.HQ.prototype.updateTerritories = function(gameState) 1826 1824 { 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 1825 var passabilityMap = gameState.getMap(); 1833 1826 var width = this.territoryMap.width; 1834 1827 var cellSize = this.territoryMap.cellSize; … … 2066 2059 phaseName = gameState.getTemplate(gameState.cityPhase()).name(); 2067 2060 2068 2061 m.chatNewPhase(gameState, phaseName, false); 2069 this.updateTerritories(gameState);2070 2062 } 2071 else if (gameState.ai.playedTurn - this.lastTerritoryUpdate > 100)2072 this.updateTerritories(gameState);2073 2063 2074 2064 if (gameState.getGameType() === "wonder") 2075 2065 this.buildWonder(gameState, queues); … … 2145 2135 "lastFailedGather": this.lastFailedGather, 2146 2136 "supportRatio": this.supportRatio, 2147 2137 "targetNumWorkers": this.targetNumWorkers, 2148 "lastTerritoryUpdate": this.lastTerritoryUpdate,2149 2138 "stopBuilding": this.stopBuilding, 2150 2139 "fortStartTime": this.fortStartTime, 2151 2140 "towerStartTime": this.towerStartTime, -
binaries/data/mods/public/simulation/components/AIInterface.js
8 8 "Destroy", 9 9 "Attacked", 10 10 "ConstructionFinished", 11 "DiplomacyChanged", 11 12 "TrainingStarted", 12 13 "TrainingFinished", 13 14 "AIMetadata", … … 16 17 "OwnershipChanged", 17 18 "Garrison", 18 19 "UnGarrison", 20 "TerritoriesChanged", 19 21 "TerritoryDecayChanged", 20 22 "TributeExchanged", 21 23 "AttackRequest" … … 164 166 this.events[type].push(msg); 165 167 }; 166 168 169 AIInterface.prototype.OnDiplomacyChanged = function(msg) 170 { 171 this.events.DiplomacyChanged.push(msg); 172 }; 173 167 174 AIInterface.prototype.OnGlobalPlayerDefeated = function(msg) 168 175 { 169 this.events ["PlayerDefeated"].push(msg);176 this.events.PlayerDefeated.push(msg); 170 177 }; 171 178 172 179 AIInterface.prototype.OnGlobalEntityRenamed = function(msg) … … 173 180 { 174 181 var cmpMirage = Engine.QueryInterface(msg.entity, IID_Mirage); 175 182 if (!cmpMirage) 176 this.events ["EntityRenamed"].push(msg);183 this.events.EntityRenamed.push(msg); 177 184 }; 178 185 179 186 AIInterface.prototype.OnGlobalTributeExchanged = function(msg) 180 187 { 181 this.events ["TributeExchanged"].push(msg);188 this.events.TributeExchanged.push(msg); 182 189 }; 183 190 191 AIInterface.prototype.OnTerritoriesChanged = function(msg) 192 { 193 this.events.TerritoriesChanged.push(msg); 194 }; 195 184 196 // When a new technology is researched, check which templates it affects, 185 197 // and send the updated values to the AI. 186 198 // this relies on the fact that any "value" in a technology can only ever change