Ticket #1520: experimental-ai-techs-r12056.patch
File experimental-ai-techs-r12056.patch, 7.6 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/simulation/ai/common-api-v2/base.js
9 9 Object.defineProperty(this, "_derivedTemplates", {value: {}, enumerable: false}); 10 10 11 11 this._entityMetadata = {}; 12 this._techModifications = {}; 12 13 13 14 this._entityCollections = []; 14 15 this._entityCollectionsByDynProp = {}; … … 29 30 return { 30 31 _rawEntities: rawEntities, 31 32 _entityMetadata: this._entityMetadata, 33 _techModifications: this._techModifications, 32 34 }; 33 35 34 36 // TODO: ought to get the AI script subclass to serialize its own state … … 40 42 { 41 43 var rawEntities = data._rawEntities; 42 44 this._entityMetadata = data._entityMetadata; 43 this._entities = {} 45 this._entities = {}; 46 this._techModifications = data._techModifications; 44 47 45 48 for (var id in rawEntities) 46 49 { … … 89 92 90 93 BaseAI.prototype.HandleMessage = function(state) 91 94 { 95 // Update tech modifications data (used for constructing entities and templates) 96 this._techModifications = state.players[this._player].techModifications; 97 92 98 if (!this._entities) 93 99 { 94 100 // Do a (shallow) clone of all the initial entity properties (in order … … 116 122 this.templates = this._templates; 117 123 this.territoryMap = state.territoryMap; 118 124 this.timeElapsed = state.timeElapsed; 125 this.techModifications = this._techModifications; 119 126 120 127 Engine.ProfileStop(); 121 128 … … 131 138 delete this.templates; 132 139 delete this.territoryMap; 133 140 delete this.timeElapsed; 141 delete this.techModifications; 134 142 }; 135 143 136 144 BaseAI.prototype.ApplyEntitiesDelta = function(state) -
binaries/data/mods/public/simulation/ai/common-api-v2/entity.js
1 1 var EntityTemplate = Class({ 2 2 3 _init: function(template )3 _init: function(template, techModifications) 4 4 { 5 this._techModifications = techModifications; 5 6 this._template = template; 6 7 }, 7 8 … … 34 35 35 36 var ret = {}; 36 37 for (var type in this._template.Cost.Resources) 37 ret[type] = +this._template.Cost.Resources[type];38 ret[type] = GetTechModifiedProperty(this._techModifications, this._template, "Cost/Resources/"+type, +this._template.Cost.Resources[type]); 38 39 return ret; 39 40 }, 40 41 … … 69 70 return undefined; 70 71 71 72 return { 72 hack: +this._template.Armour.Hack,73 pierce: +this._template.Armour.Pierce,74 crush: +this._template.Armour.Crush73 hack: GetTechModifiedProperty(this._techModifications, this._template, "Armour/Hack", +this._template.Armour.Hack), 74 pierce: GetTechModifiedProperty(this._techModifications, this._template, "Armour/Pierce", +this._template.Armour.Pierce), 75 crush: GetTechModifiedProperty(this._techModifications, this._template, "Armour/Crush", +this._template.Armour.Crush) 75 76 }; 76 77 }, 77 78 … … 91 92 return undefined; 92 93 93 94 return { 94 max: +this._template.Attack[type].MaxRange,95 min: +(this._template.Attack[type].MinRange || 0)95 max: GetTechModifiedProperty(this._techModifications, this._template, "Attack/MaxRange", +this._template.Attack[type].MaxRange), 96 min: GetTechModifiedProperty(this._techModifications, this._template, "Attack/MinRange", +(this._template.Attack[type].MinRange || 0)) 96 97 }; 97 98 }, 98 99 … … 101 102 return undefined; 102 103 103 104 return { 104 hack: +(this._template.Attack[type].Hack || 0),105 pierce: +(this._template.Attack[type].Pierce || 0),106 crush: +(this._template.Attack[type].Crush || 0)105 hack: GetTechModifiedProperty(this._techModifications, this._template, "Attack/"+type+"/Hack", +(this._template.Attack[type].Hack || 0)), 106 pierce: GetTechModifiedProperty(this._techModifications, this._template, "Attack/"+type+"/Pierce", +(this._template.Attack[type].Pierce || 0)), 107 crush: GetTechModifiedProperty(this._techModifications, this._template, "Attack/"+type+"/Crush", +(this._template.Attack[type].Crush || 0)) 107 108 }; 108 109 }, 109 110 … … 112 113 return undefined; 113 114 114 115 return { 115 prepare: +(this._template.Attack[type].PrepareTime || 0),116 repeat: +(this._template.Attack[type].RepeatTime || 1000)116 prepare: GetTechModifiedProperty(this._techModifications, this._template, "Attack/"+type+"/PrepareTime", +(this._template.Attack[type].PrepareTime || 0)), 117 repeat: GetTechModifiedProperty(this._techModifications, this._template, "Attack/"+type+"/RepeatTime", +(this._template.Attack[type].RepeatTime || 1000)) 117 118 }; 118 119 }, 119 120 … … 152 153 if (!this._template.ResourceGatherer) 153 154 return undefined; 154 155 var ret = {}; 156 var baseSpeed = GetTechModifiedProperty(this._techModifications, this._template, "ResourceGatherer/BaseSpeed", +this._template.ResourceGatherer.BaseSpeed); 155 157 for (var r in this._template.ResourceGatherer.Rates) 156 ret[r] = this._template.ResourceGatherer.Rates[r] * this._template.ResourceGatherer.BaseSpeed;158 ret[r] = GetTechModifiedProperty(this._techModifications, this._template, "ResourceGatherer/Rates/"+r, +this._template.ResourceGatherer.Rates[r]) * baseSpeed; 157 159 return ret; 158 160 }, 159 161 … … 229 231 230 232 _init: function(baseAI, entity) 231 233 { 232 this._super.call(this, baseAI.GetTemplate(entity.template) );234 this._super.call(this, baseAI.GetTemplate(entity.template), baseAI._techModifications); 233 235 234 236 this._ai = baseAI; 235 237 this._templateName = entity.template; -
binaries/data/mods/public/simulation/ai/jubot/gamestate.js
14 14 this.entities = ai.entities; 15 15 this.player = ai.player; 16 16 this.playerData = ai.playerData; 17 this.techModifications = ai.techModifications; 17 18 18 19 if (!this.ai._gameStateStore){ 19 20 this.ai._gameStateStore = {}; … … 30 31 { 31 32 if (!this.templates[type]) 32 33 return null; 33 return new EntityTemplate(this.templates[type] );34 return new EntityTemplate(this.templates[type], this.techModifications); 34 35 }, 35 36 36 37 applyCiv: function(str) -
binaries/data/mods/public/simulation/ai/qbot/gamestate.js
12 12 this.player = ai.player; 13 13 this.playerData = ai.playerData; 14 14 this.buildingsBuilt = 0; 15 this.techModifications = ai.techModifications; 15 16 16 17 if (!this.ai._gameStateStore){ 17 18 this.ai._gameStateStore = {}; … … 41 42 return null; 42 43 } 43 44 44 return new EntityTemplate(this.templates[type] );45 return new EntityTemplate(this.templates[type], this.techModifications); 45 46 }; 46 47 47 48 GameState.prototype.applyCiv = function(str) { -
binaries/data/mods/public/simulation/components/AIProxy.js
155 155 156 156 // TODO: event handlers for all the other things 157 157 158 // TODO: research - could updates tech modifications data in the Entity/EntityTemplates 159 158 160 AIProxy.prototype.GetFullRepresentation = function() 159 161 { 160 162 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);