Ticket #3992: entityModif.patch

File entityModif.patch, 8.3 KB (added by mimo, 8 years ago)
  • binaries/data/mods/public/simulation/ai/common-api/baseAI.js

     
    4444    this.accessibility = sharedAI.accessibility;
    4545    this.terrainAnalyzer = sharedAI.terrainAnalyzer;
    4646   
    47     this.techModifications = sharedAI._techModifications[this.player];
    48     this.playerData = sharedAI.playersData[this.player];
    49    
    5047    this.gameState = sharedAI.gameState[this.player];
    5148    this.gameState.ai = this;
    5249    this.sharedScript = sharedAI;
     
    5350   
    5451    this.timeElapsed = sharedAI.timeElapsed;
    5552
    56     this.circularMap = sharedAI.circularMap;
    57 
    58     this.gameType = sharedAI.gameType;
    59 
    60     this.barterPrices = sharedAI.barterPrices;
    61 
    6253    this.CustomInit(this.gameState, this.sharedScript);
    6354};
    6455
  • binaries/data/mods/public/simulation/ai/common-api/entity.js

     
    1616    get: function(string)
    1717    {
    1818        var value = this._template;
    19         if (this._auraTemplateModif && this._auraTemplateModif.has(string))
    20             return this._auraTemplateModif.get(string);
    21         else if (this._techModif && this._techModif.has(string))
    22             return this._techModif.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);
    2323
    2424        if (!this._tpCache.has(string))
    2525        {
     
    565565
    566566        this._templateName = entity.template;
    567567        this._entity = entity;
    568         this._auraTemplateModif = new Map();    // template modification from auras. this is only for this entity.
     568
    569569        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);
    573578    },
    574579
    575580    toString: function() {
  • binaries/data/mods/public/simulation/ai/common-api/gamestate.js

     
    2020    this.entities = SharedScript.entities;
    2121    this.player = player;
    2222    this.playerData = SharedScript.playersData[this.player];
    23     this.techModifications = SharedScript._techModifications[this.player];
    2423    this.barterPrices = SharedScript.barterPrices;
    2524    this.gameType = SharedScript.gameType;
    2625
     
    6160    this._entities = SharedScript._entities;
    6261    this.entities = SharedScript.entities;
    6362    this.playerData = SharedScript.playersData[this.player];
    64     this.techModifications = SharedScript._techModifications[this.player];
    6563    this.barterPrices = SharedScript.barterPrices;
    6664};
    6765
     
    129127{
    130128    if (this.techTemplates[type] !== undefined)
    131129        return new m.Technology(this.techTemplates, type);
    132    
     130
    133131    if (!this.templates[type])
    134132        return null;
    135    
    136     return new m.Template(this.templates[type], this.techModifications);
     133
     134    return new m.Template(this.templates[type]);
    137135};
    138136
    139137m.GameState.prototype.applyCiv = function(str)
  • binaries/data/mods/public/simulation/ai/common-api/shared.js

     
    1818
    1919    // array of entity collections
    2020    this._entityCollections = new Map();
    21     this._techModifications = {};
     21    this._entitiesModifications = new Map();    // entities modifications
     22    this._templatesModifications = {};  // template modifications
    2223    // each name is a reference to the actual one.
    2324    this._entityCollectionsName = new Map();
    2425    this._entityCollectionsByDynProp = {};
     
    3839{
    3940    return {
    4041        "players": this._players,
    41         "techTp": this._techTemplates,
    42         "techModifications": this._techModifications,
     42        "techTemplates": this._techTemplates,
     43        "templatesModifications": this._templatesModifications,
     44        "entitiesModifications": this._entitiesModifications,
    4345        "metadata": this._entityMetadata
    4446    };
    4547};
     
    4951m.SharedScript.prototype.Deserialize = function(data)
    5052{
    5153    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;
    5457    this._entityMetadata = data.metadata;
    55     this._derivedTemplates = {}; 
     58    this._derivedTemplates = {};
    5659
    5760    this.isDeserialized = true;
    5861};
     
    8386{   
    8487    if (this._templates[name])
    8588        return this._templates[name];
    86    
     89
    8790    if (this._derivedTemplates[name])
    8891        return this._derivedTemplates[name];
    89    
     92
    9093    // If this is a foundation template, construct it automatically
    9194    if (name.indexOf("foundation|") !== -1)
    9295    {
     
    112115        this._derivedTemplates[name] = resource;
    113116        return resource;
    114117    }
    115    
     118
    116119    error("Tried to retrieve invalid template '"+name+"'");
    117120    return null;
    118121};
     
    123126m.SharedScript.prototype.init = function(state, deserialization)
    124127{
    125128    if (!deserialization)
     129    {
     130        this._entitiesModifications = new Map();
    126131        for (let i = 0; i < state.players.length; ++i)
    127             this._techModifications[i] = {};
     132            this._templatesModifications[i] = {};
     133    }
    128134
    129135    this.ApplyTemplatesDelta(state);
    130136
     
    310316        this.entities.removeEnt(entity);
    311317       
    312318        this._entities.delete(evt.entity);
     319        this._entitiesModifications.delete(evt.entity)
    313320        for (let j in this._players)
    314321            delete this._entityMetadata[this._players[j]][evt.entity];
    315322    }
     
    332339        if (!this._entities.has(+id))
    333340            continue;   // dead, presumably.
    334341        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);
    336345        for (let change of changes)
    337             entity._auraTemplateModif.set(change.variable, change.value);
     346            modif.set(change.variable, change.value);
    338347    }
    339348    Engine.ProfileStop();
    340349};
     
    349358        for (let template in playerDiff)
    350359        {
    351360            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];
    354364            for (let change of changes)
    355                 this._techModifications[player][template].set(change.variable, change.value);
     365                modif.set(change.variable, change.value);
    356366        }
    357367    }
    358368    Engine.ProfileStop();
  • binaries/data/mods/public/simulation/ai/petra/mapModule.js

     
    127127    var border = Math.round(80 / map.cellSize);
    128128    var passabilityMap = gameState.sharedScript.passabilityMap;
    129129    var obstructionMask = gameState.getPassabilityClassMask("unrestricted");
    130     if (gameState.ai.circularMap)
     130    if (gameState.circularMap)
    131131    {
    132132        let ic = (width - 1) / 2;
    133133        let radcut = (ic - border) * (ic - border);