Ticket #3992: entityModif.patch
File entityModif.patch, 8.3 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/ai/common-api/baseAI.js
44 44 this.accessibility = sharedAI.accessibility; 45 45 this.terrainAnalyzer = sharedAI.terrainAnalyzer; 46 46 47 this.techModifications = sharedAI._techModifications[this.player];48 this.playerData = sharedAI.playersData[this.player];49 50 47 this.gameState = sharedAI.gameState[this.player]; 51 48 this.gameState.ai = this; 52 49 this.sharedScript = sharedAI; … … 53 50 54 51 this.timeElapsed = sharedAI.timeElapsed; 55 52 56 this.circularMap = sharedAI.circularMap;57 58 this.gameType = sharedAI.gameType;59 60 this.barterPrices = sharedAI.barterPrices;61 62 53 this.CustomInit(this.gameState, this.sharedScript); 63 54 }; 64 55 -
binaries/data/mods/public/simulation/ai/common-api/entity.js
16 16 get: function(string) 17 17 { 18 18 var value = this._template; 19 if (this._ auraTemplateModif && this._auraTemplateModif.has(string))20 return this._ auraTemplateModif.get(string);21 else if (this._te chModif && this._techModif.has(string))22 return this._te chModif.get(string);19 if (this._entityModif && this._entityModif.has(string)) 20 return this._entityModif.get(string); 21 else if (this._templateModif && this._templateModif.has(string)) 22 return this._templateModif.get(string); 23 23 24 24 if (!this._tpCache.has(string)) 25 25 { … … 565 565 566 566 this._templateName = entity.template; 567 567 this._entity = entity; 568 this._auraTemplateModif = new Map(); // template modification from auras. this is only for this entity. 568 569 569 this._ai = sharedAI; 570 if (!sharedAI._techModifications[entity.owner][this._templateName]) 571 sharedAI._techModifications[entity.owner][this._templateName] = new Map(); 572 this._techModif = sharedAI._techModifications[entity.owner][this._templateName]; // save a reference to the template tech modifications 570 // save a reference to the template tech modifications 571 if (!sharedAI._templatesModifications[entity.owner][this._templateName]) 572 sharedAI._templatesModifications[entity.owner][this._templateName] = new Map(); 573 this._templateModif = sharedAI._templatesModifications[entity.owner][this._templateName]; 574 // save a reference to the entity tech/aura modifications 575 if (!sharedAI._entitiesModifications.has(entity.id)) 576 sharedAI._entitiesModifications.set(entity.id, new Map()); 577 this._entityModif = sharedAI._entitiesModifications.get(entity.id); 573 578 }, 574 579 575 580 toString: function() { -
binaries/data/mods/public/simulation/ai/common-api/gamestate.js
20 20 this.entities = SharedScript.entities; 21 21 this.player = player; 22 22 this.playerData = SharedScript.playersData[this.player]; 23 this.techModifications = SharedScript._techModifications[this.player];24 23 this.barterPrices = SharedScript.barterPrices; 25 24 this.gameType = SharedScript.gameType; 26 25 … … 61 60 this._entities = SharedScript._entities; 62 61 this.entities = SharedScript.entities; 63 62 this.playerData = SharedScript.playersData[this.player]; 64 this.techModifications = SharedScript._techModifications[this.player];65 63 this.barterPrices = SharedScript.barterPrices; 66 64 }; 67 65 … … 129 127 { 130 128 if (this.techTemplates[type] !== undefined) 131 129 return new m.Technology(this.techTemplates, type); 132 130 133 131 if (!this.templates[type]) 134 132 return null; 135 136 return new m.Template(this.templates[type] , this.techModifications);133 134 return new m.Template(this.templates[type]); 137 135 }; 138 136 139 137 m.GameState.prototype.applyCiv = function(str) -
binaries/data/mods/public/simulation/ai/common-api/shared.js
18 18 19 19 // array of entity collections 20 20 this._entityCollections = new Map(); 21 this._techModifications = {}; 21 this._entitiesModifications = new Map(); // entities modifications 22 this._templatesModifications = {}; // template modifications 22 23 // each name is a reference to the actual one. 23 24 this._entityCollectionsName = new Map(); 24 25 this._entityCollectionsByDynProp = {}; … … 38 39 { 39 40 return { 40 41 "players": this._players, 41 "techTp": this._techTemplates, 42 "techModifications": this._techModifications, 42 "techTemplates": this._techTemplates, 43 "templatesModifications": this._templatesModifications, 44 "entitiesModifications": this._entitiesModifications, 43 45 "metadata": this._entityMetadata 44 46 }; 45 47 }; … … 49 51 m.SharedScript.prototype.Deserialize = function(data) 50 52 { 51 53 this._players = data.players; 52 this._techTemplates = data.techTp; 53 this._techModifications = data.techModifications; 54 this._techTemplates = data.techTemplates; 55 this._templatesModifications = data.templatesModifications; 56 this._entitiesModifications = data.entitiesModifications; 54 57 this._entityMetadata = data.metadata; 55 this._derivedTemplates = {}; 58 this._derivedTemplates = {}; 56 59 57 60 this.isDeserialized = true; 58 61 }; … … 83 86 { 84 87 if (this._templates[name]) 85 88 return this._templates[name]; 86 89 87 90 if (this._derivedTemplates[name]) 88 91 return this._derivedTemplates[name]; 89 92 90 93 // If this is a foundation template, construct it automatically 91 94 if (name.indexOf("foundation|") !== -1) 92 95 { … … 112 115 this._derivedTemplates[name] = resource; 113 116 return resource; 114 117 } 115 118 116 119 error("Tried to retrieve invalid template '"+name+"'"); 117 120 return null; 118 121 }; … … 123 126 m.SharedScript.prototype.init = function(state, deserialization) 124 127 { 125 128 if (!deserialization) 129 { 130 this._entitiesModifications = new Map(); 126 131 for (let i = 0; i < state.players.length; ++i) 127 this._techModifications[i] = {}; 132 this._templatesModifications[i] = {}; 133 } 128 134 129 135 this.ApplyTemplatesDelta(state); 130 136 … … 310 316 this.entities.removeEnt(entity); 311 317 312 318 this._entities.delete(evt.entity); 319 this._entitiesModifications.delete(evt.entity) 313 320 for (let j in this._players) 314 321 delete this._entityMetadata[this._players[j]][evt.entity]; 315 322 } … … 332 339 if (!this._entities.has(+id)) 333 340 continue; // dead, presumably. 334 341 let changes = state.changedEntityTemplateInfo[id]; 335 let entity = this._entities.get(+id); 342 if (!this._entitiesModifications.has(+id)) 343 this._entitiesModifications.set(+id, new Map()); 344 let modif = this._entitiesModifications.get(+id); 336 345 for (let change of changes) 337 entity._auraTemplateModif.set(change.variable, change.value);346 modif.set(change.variable, change.value); 338 347 } 339 348 Engine.ProfileStop(); 340 349 }; … … 349 358 for (let template in playerDiff) 350 359 { 351 360 let changes = playerDiff[template]; 352 if (!this._techModifications[player][template]) 353 this._techModifications[player][template] = new Map(); 361 if (!this._templatesModifications[player][template]) 362 this._templatesModifications[player][template] = new Map(); 363 let modif = this._templatesModifications[player][template]; 354 364 for (let change of changes) 355 this._techModifications[player][template].set(change.variable, change.value);365 modif.set(change.variable, change.value); 356 366 } 357 367 } 358 368 Engine.ProfileStop(); -
binaries/data/mods/public/simulation/ai/petra/mapModule.js
127 127 var border = Math.round(80 / map.cellSize); 128 128 var passabilityMap = gameState.sharedScript.passabilityMap; 129 129 var obstructionMask = gameState.getPassabilityClassMask("unrestricted"); 130 if (gameState. ai.circularMap)130 if (gameState.circularMap) 131 131 { 132 132 let ic = (width - 1) / 2; 133 133 let radcut = (ic - border) * (ic - border);