Ticket #1520: experimental-ai-techs-r12056.patch

File experimental-ai-techs-r12056.patch, 7.6 KB (added by historic_bruno, 12 years ago)
  • binaries/data/mods/public/simulation/ai/common-api-v2/base.js

     
    99    Object.defineProperty(this, "_derivedTemplates", {value: {}, enumerable: false});
    1010
    1111    this._entityMetadata = {};
     12    this._techModifications = {};
    1213
    1314    this._entityCollections = [];
    1415    this._entityCollectionsByDynProp = {};
     
    2930    return {
    3031        _rawEntities: rawEntities,
    3132        _entityMetadata: this._entityMetadata,
     33        _techModifications: this._techModifications,
    3234    };
    3335
    3436    // TODO: ought to get the AI script subclass to serialize its own state
     
    4042{
    4143    var rawEntities = data._rawEntities;
    4244    this._entityMetadata = data._entityMetadata;
    43     this._entities = {}
     45    this._entities = {};
     46    this._techModifications = data._techModifications;
    4447   
    4548    for (var id in rawEntities)
    4649    {
     
    8992
    9093BaseAI.prototype.HandleMessage = function(state)
    9194{
     95    // Update tech modifications data (used for constructing entities and templates)
     96    this._techModifications = state.players[this._player].techModifications;
     97
    9298    if (!this._entities)
    9399    {
    94100        // Do a (shallow) clone of all the initial entity properties (in order
     
    116122    this.templates = this._templates;
    117123    this.territoryMap = state.territoryMap;
    118124    this.timeElapsed = state.timeElapsed;
     125    this.techModifications = this._techModifications;
    119126
    120127    Engine.ProfileStop();
    121128
     
    131138    delete this.templates;
    132139    delete this.territoryMap;
    133140    delete this.timeElapsed;
     141    delete this.techModifications;
    134142};
    135143
    136144BaseAI.prototype.ApplyEntitiesDelta = function(state)
  • binaries/data/mods/public/simulation/ai/common-api-v2/entity.js

     
    11var EntityTemplate = Class({
    22
    3     _init: function(template)
     3    _init: function(template, techModifications)
    44    {
     5        this._techModifications = techModifications;
    56        this._template = template;
    67    },
    78
     
    3435
    3536        var ret = {};
    3637        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]);
    3839        return ret;
    3940    },
    4041
     
    6970            return undefined;
    7071
    7172        return {
    72             hack: +this._template.Armour.Hack,
    73             pierce: +this._template.Armour.Pierce,
    74             crush: +this._template.Armour.Crush
     73            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)
    7576        };
    7677    },
    7778
     
    9192            return undefined;
    9293
    9394        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))
    9697        };
    9798    },
    9899
     
    101102            return undefined;
    102103
    103104        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))
    107108        };
    108109    },
    109110   
     
    112113            return undefined;
    113114
    114115        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))
    117118        };
    118119    },
    119120
     
    152153        if (!this._template.ResourceGatherer)
    153154            return undefined;
    154155        var ret = {};
     156        var baseSpeed = GetTechModifiedProperty(this._techModifications, this._template, "ResourceGatherer/BaseSpeed", +this._template.ResourceGatherer.BaseSpeed);
    155157        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;
    157159        return ret;
    158160    },
    159161
     
    229231
    230232    _init: function(baseAI, entity)
    231233    {
    232         this._super.call(this, baseAI.GetTemplate(entity.template));
     234        this._super.call(this, baseAI.GetTemplate(entity.template), baseAI._techModifications);
    233235
    234236        this._ai = baseAI;
    235237        this._templateName = entity.template;
  • binaries/data/mods/public/simulation/ai/jubot/gamestate.js

     
    1414        this.entities = ai.entities;
    1515        this.player = ai.player;
    1616        this.playerData = ai.playerData;
     17        this.techModifications = ai.techModifications;
    1718   
    1819        if (!this.ai._gameStateStore){
    1920            this.ai._gameStateStore = {};
     
    3031    {
    3132        if (!this.templates[type])
    3233            return null;
    33         return new EntityTemplate(this.templates[type]);
     34        return new EntityTemplate(this.templates[type], this.techModifications);
    3435    },
    3536
    3637    applyCiv: function(str)
  • binaries/data/mods/public/simulation/ai/qbot/gamestate.js

     
    1212    this.player = ai.player;
    1313    this.playerData = ai.playerData;
    1414    this.buildingsBuilt = 0;
     15    this.techModifications = ai.techModifications;
    1516   
    1617    if (!this.ai._gameStateStore){
    1718        this.ai._gameStateStore = {};
     
    4142        return null;
    4243    }
    4344   
    44     return new EntityTemplate(this.templates[type]);
     45    return new EntityTemplate(this.templates[type], this.techModifications);
    4546};
    4647
    4748GameState.prototype.applyCiv = function(str) {
  • binaries/data/mods/public/simulation/components/AIProxy.js

     
    155155
    156156// TODO: event handlers for all the other things
    157157
     158// TODO: research - could updates tech modifications data in the Entity/EntityTemplates
     159
    158160AIProxy.prototype.GetFullRepresentation = function()
    159161{
    160162    var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);