Ticket #2180: AIFix_.3.patch

File AIFix_.3.patch, 6.0 KB (added by wraitii, 10 years ago)
  • binaries/data/mods/public/simulation/ai/aegis/base-manager.js

     
    222222                if (ent && ent.resourceSupplyAmount() && ent.owner() == 0)
    223223                    this.assignResourceToDP(gameState,ent);
    224224            }
     225        }  else if (events[i].type == "EntityRenamed")
     226        {
     227            var evt = events[i];
     228            debug (evt);
     229
    225230        }
    226231    }
    227232};
     
    483488    // for each dropsite, recalculate
    484489    for (i in this.dropsites)
    485490    {
     491        warn(uneval(i));
    486492        for (type in this.dropsites[i])
    487493        {
    488494            this.updateDropsite(gameState,gameState.getEntityById(i),type);
  • binaries/data/mods/public/simulation/ai/common-api-v3/shared.js

     
    180180        this._techModifications[o] = state.players[o].techModifications;
    181181   
    182182    this._entities = {};
    183     this.entities = new EntityCollection(this);
    184183
    185     /* (var id in state.entities)
     184    for (var id in state.entities)
    186185    {
    187186        this._entities[id] = new Entity(this, state.entities[id]);
    188187    }
    189188    // entity collection updated on create/destroy event.
    190189    this.entities = new EntityCollection(this, this._entities);
    191     */
    192190   
    193     this.ApplyEntitiesDelta(state);
    194 
    195191    // create the terrain analyzer
    196192    this.terrainAnalyzer = new TerrainAnalysis();
    197193    this.terrainAnalyzer.init(this, state);
     
    214210// applies entity deltas, and each gamestate.
    215211SharedScript.prototype.onUpdate = function(state)
    216212{
    217     if (this.turn !== 0)
    218         this.ApplyEntitiesDelta(state);
     213    this.ApplyEntitiesDelta(state);
    219214
    220215    Engine.ProfileStart("onUpdate");
    221216   
     
    297292            for (var i in this._players)
    298293                delete this._entityMetadata[this._players[i]][evt.msg.entity];
    299294        }
     295        else if (evt.type == "EntityRenamed")
     296        {
     297            //combines destroy and create.
     298
     299            warn(uneval(evt.msg));
     300
     301            // Switch the metadata
     302            for (var i in this._players)
     303            {
     304                warn (uneval(this._entityMetadata[this._players[i]][evt.msg.entity]));
     305                this._entityMetadata[this._players[i]][evt.msg.newentity] = this._entityMetadata[this._players[i]][evt.msg.entity];
     306                this._entityMetadata[this._players[i]][evt.msg.entity] = {};
     307            }
     308        }
    300309        else if (evt.type == "TrainingFinished")
    301310        {
    302311            // Apply metadata stored in training queues
  • binaries/data/mods/public/simulation/components/AIInterface.js

     
    3737    return state;
    3838};
    3939// Intended to be called first, during the map initialization: no caching
    40 AIInterface.prototype.GetFullRepresentation = function()
     40AIInterface.prototype.GetFullRepresentation = function(flushEvents)
    4141{
    4242    var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    4343   
     
    4646   
    4747    // Add some extra AI-specific data
    4848    state.events = this.events;
     49    if (flushEvents)
     50    {
     51        state.events = [];
     52        this.events = [];
     53    }
    4954   
    5055    // Add entity representations
    5156    Engine.ProfileStart("proxy representations");
     
    8186    this.events.push({"type": "PlayerDefeated", "msg": msg});
    8287};
    8388
     89AIInterface.prototype.OnGlobalEntityRenamed = function(msg)
     90{
     91    this.events.push({"type": "EntityRenamed", "msg": msg});
     92};
     93
    8494Engine.RegisterComponentType(IID_AIInterface, "AIInterface", AIInterface);
  • binaries/data/mods/public/simulation/components/SkirmishReplacer.js

     
    5555    var cmpReplacementOwnership = Engine.QueryInterface(replacement, IID_Ownership);
    5656    cmpReplacementOwnership.SetOwner(cmpCurOwnership.GetOwner());
    5757
     58    Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: replacement});
    5859    Engine.DestroyEntity(this.entity);
    5960};
    6061
  • source/simulation2/components/CCmpAIManager.cpp

     
    994994        ENSURE(cmpAIInterface);
    995995       
    996996        // Get the game state from AIInterface
    997         CScriptVal state = cmpAIInterface->GetFullRepresentation();
     997        CScriptVal state = cmpAIInterface->GetFullRepresentation(true);
    998998
    999999        // Get the passability data
    10001000        Grid<u16> dummyGrid;
  • source/simulation2/components/ICmpAIInterface.cpp

     
    3434    {
    3535        return m_Script.Call<CScriptVal> ("GetRepresentation");
    3636    }
    37     virtual CScriptVal GetFullRepresentation()
     37    virtual CScriptVal GetFullRepresentation(bool flushEvents = false)
    3838    {
    39         return m_Script.Call<CScriptVal> ("GetFullRepresentation");
     39        return m_Script.Call<CScriptVal> ("GetFullRepresentation",flushEvents);
    4040    }
    4141   
    4242};
  • source/simulation2/components/ICmpAIInterface.h

     
    3232     * Returns a script object that represents the current world state,
    3333     * to be passed to AI scripts. No caching for initialization
    3434     */
    35     virtual CScriptVal GetFullRepresentation() = 0;
     35    virtual CScriptVal GetFullRepresentation(bool flushEvents) = 0;
    3636
    3737    DECLARE_INTERFACE_TYPE(AIInterface)
    3838};