Ticket #2969: InitGame.js.2.patch

File InitGame.js.2.patch, 6.5 KB (added by Itms, 9 years ago)

same patch, plus tweaks to init functions

  • binaries/data/mods/public/simulation/components/PlayerManager.js

     
    5252    this.playerEntities[id] = ent;
    5353    cmpPlayer.SetDiplomacy(diplo);
    5454    Engine.DestroyEntity(oldent);
    55     Engine.FlushDestroyedComponents();
     55    Engine.FlushDestroyedEntities();
    5656
    5757    for (var e of entities)
    5858    {
  • binaries/data/mods/public/simulation/helpers/InitGame.js

     
    44 */
    55function PreInitGame()
    66{
     7    // We need to replace skirmish "default" entities with real ones.
     8    // This needs to happen before AI initialization (in InitGame).
     9    // And we need to flush destroyed entities otherwise the AI gets the wrong game state in
     10    // the beginning and a bunch of "destroy" messages on turn 0, which just shouldn't happen.
    711    Engine.BroadcastMessage(MT_SkirmishReplace, {});
     12    Engine.FlushDestroyedEntities();
    813
    914    let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    1015    let playerIds = cmpPlayerManager.GetAllPlayerEntities().slice(1); // ignore gaia
     
    1419        if (cmpTechnologyManager)
    1520            cmpTechnologyManager.UpdateAutoResearch();
    1621    }
     22
     23    // Explore the map inside the players' territory borders
     24    let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     25    cmpRangeManager.ExploreTerritories();
    1726}
    1827
    1928function InitGame(settings)
     
    2231    if (!settings)
    2332        return;
    2433
    25     let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    2634    if (settings.ExploreMap)
     35    {
     36        let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    2737        for (let i = 1; i < settings.PlayerData.length; ++i)
    2838            cmpRangeManager.ExploreAllTiles(i);
    29     else
    30         // Explore the map only inside the players' territory borders
    31         cmpRangeManager.ExploreTerritories();
     39    }
    3240
    3341    let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    3442    let cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager);
  • source/ps/Game.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    213213    if (!m_IsSavedGame)
    214214    {
    215215        if (!g_AtlasGameLoop->running)
    216         {
    217             // We need to replace skirmish "default" entities with real ones.
    218             // This needs to happen before AI initialization (in InitGame).
    219             // And we need to flush destroyed entities otherwise the AI
    220             // gets the wrong game state in the beginning and a bunch of
    221             // "destroy" messages on turn 0, which just shouldn't happen.
    222216            m_Simulation2->PreInitGame();
    223             m_Simulation2->FlushDestroyedEntities();
    224         }
     217
    225218        JS::RootedValue settings(cx);
    226219        JS::RootedValue tmpInitAttributes(cx, m_Simulation2->GetInitAttributes().get());
    227220        m_Simulation2->GetScriptInterface().GetProperty(tmpInitAttributes, "settings", &settings);
  • source/simulation2/system/ComponentManager.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    8484        m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddEntity> ("AddEntity");
    8585        m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddLocalEntity> ("AddLocalEntity");
    8686        m_ScriptInterface.RegisterFunction<void, int, CComponentManager::Script_DestroyEntity> ("DestroyEntity");
    87         m_ScriptInterface.RegisterFunction<void, CComponentManager::Script_FlushDestroyedComponents> ("FlushDestroyedComponents");
     87        m_ScriptInterface.RegisterFunction<void, CComponentManager::Script_FlushDestroyedEntities> ("FlushDestroyedEntities");
    8888        m_ScriptInterface.RegisterFunction<CScriptVal, std::wstring, CComponentManager::Script_ReadJSONFile> ("ReadJSONFile");
    8989        m_ScriptInterface.RegisterFunction<CScriptVal, std::wstring, CComponentManager::Script_ReadCivJSONFile> ("ReadCivJSONFile");
    9090        m_ScriptInterface.RegisterFunction<std::vector<std::string>, std::wstring, bool, CComponentManager::Script_FindJSONFiles> ("FindJSONFiles");
     
    508508    componentManager->DestroyComponentsSoon(ent);
    509509}
    510510
    511 void CComponentManager::Script_FlushDestroyedComponents(ScriptInterface::CxPrivate *pCxPrivate)
     511void CComponentManager::Script_FlushDestroyedEntities(ScriptInterface::CxPrivate *pCxPrivate)
    512512{
    513513    CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData);
    514514    componentManager->FlushDestroyedComponents();
  • source/simulation2/system/ComponentManager.h

     
    1 /* Copyright (C) 2011 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    283283    static int Script_AddEntity(ScriptInterface::CxPrivate* pCxPrivate, std::string templateName);
    284284    static int Script_AddLocalEntity(ScriptInterface::CxPrivate* pCxPrivate, std::string templateName);
    285285    static void Script_DestroyEntity(ScriptInterface::CxPrivate* pCxPrivate, int ent);
    286     static void Script_FlushDestroyedComponents(ScriptInterface::CxPrivate* pCxPrivate);
     286    static void Script_FlushDestroyedEntities(ScriptInterface::CxPrivate* pCxPrivate);
    287287    static CScriptVal Script_ReadJSONFile(ScriptInterface::CxPrivate* pCxPrivate, std::wstring fileName);
    288288    static CScriptVal Script_ReadCivJSONFile(ScriptInterface::CxPrivate* pCxPrivate, std::wstring fileName);
    289289    static std::vector<std::string> Script_FindJSONFiles(ScriptInterface::CxPrivate* pCxPrivate, std::wstring subPath, bool recursive);