Ticket #2709: explore_init.patch

File explore_init.patch, 7.3 KB (added by Itms, 10 years ago)
  • binaries/data/mods/public/simulation/components/Fogging.js

     
    106106        );
    107107};
    108108
     109Fogging.prototype.ForceMiraging = function(player)
     110{
     111    this.seen[player] = true;
     112    this.LoadMirage(player);
     113};
     114
    109115Fogging.prototype.IsMiraged = function(player)
    110116{
    111117    if (player >= this.mirages.length)
  • binaries/data/mods/public/simulation/helpers/InitGame.js

     
    99
    1010function InitGame(settings)
    1111{
     12    if (settings.ExploreMap)
     13    {
     14        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     15        if (cmpRangeManager)
     16            for (var i = 0; i < settings.PlayerData.length; i++)
     17                cmpRangeManager.ExploreAllTiles(i+1);
     18    }
     19    else
     20    {
     21        // Explore the map only inside the players' territory borders
     22        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     23        cmpRangeManager.ExploreTerritories();
     24    }
     25
    1226    // No settings when loading a map in Atlas, so do nothing
    1327    if (!settings)
    1428        return;
  • binaries/data/mods/public/simulation/helpers/Setup.js

     
    3636            cmpObstructionManager.SetPassabilityCircular(true);
    3737    }
    3838
    39     if (settings.ExploreMap)
    40     {
    41         // this needs to happen after changing the map to a circular one
    42         // as by making the map circular, the explored tiles get reset
    43         var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    44         if (cmpRangeManager)
    45             for (var i = 0; i < settings.PlayerData.length; i++)
    46                 cmpRangeManager.ExploreAllTiles(i+1);
    47     }
    48 
    4939    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
    5040    if (settings.GameType)
    5141        cmpEndGameManager.SetGameType(settings.GameType);
  • source/simulation2/components/CCmpRangeManager.cpp

     
    287287    std::vector<bool> m_LosRevealAll;
    288288    bool m_LosCircular;
    289289    i32 m_TerrainVerticesPerSide;
    290     size_t m_TerritoriesDirtyID;
    291290   
    292291    // Cache for visibility tracking (not serialized)
    293292    i32 m_LosTilesPerSide;
     
    343342
    344343        m_LosCircular = false;
    345344        m_TerrainVerticesPerSide = 0;
    346 
    347         m_TerritoriesDirtyID = 0;
    348345    }
    349346
    350347    virtual void Deinit()
     
    16031600                m_LosState[i + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1)));
    16041601            }
    16051602        }
     1603
     1604        SeeExploredEntities(p);
    16061605    }
    16071606
    1608     void UpdateTerritoriesLos()
     1607    virtual void ExploreTerritories()
    16091608    {
    16101609        CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSystemEntity());
    1611         if (!cmpTerritoryManager || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
    1612             return;
    16131610
    16141611        const Grid<u8>& grid = cmpTerritoryManager->GetTerritoryGrid();
    16151612        ENSURE(grid.m_W == m_TerrainVerticesPerSide-1 && grid.m_H == m_TerrainVerticesPerSide-1);
     
    16361633                }
    16371634            }
    16381635        }
     1636
     1637        for (player_id_t p = 1; p < MAX_LOS_PLAYER_ID+1; ++p)
     1638            SeeExploredEntities(p);
    16391639    }
    16401640
    16411641    /**
     1642     * Force any entity in explored territory to appear for player p.
     1643     * This is useful for miraging entities inside the territory borders at the beginning of a game,
     1644     * or if the "Explore Map" option has been set.
     1645     */
     1646    void SeeExploredEntities(player_id_t p)
     1647    {
     1648        for (EntityMap<EntityData>::iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it)
     1649        {
     1650            CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), it->first);
     1651            if (!cmpPosition || !cmpPosition->IsInWorld())
     1652                continue;
     1653
     1654            CFixedVector2D pos = cmpPosition->GetPosition2D();
     1655            int i = (pos.X / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
     1656            int j = (pos.Y / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
     1657
     1658            CLosQuerier los(GetSharedLosMask(p), m_LosState, m_TerrainVerticesPerSide);
     1659            if (!los.IsExplored(i,j) || los.IsVisible(i,j))
     1660                continue;
     1661
     1662            CmpPtr<ICmpFogging> cmpFogging(GetSimContext(), it->first);
     1663            if (cmpFogging)
     1664                cmpFogging->ForceMiraging(p);
     1665        }
     1666    }
     1667
     1668    /**
    16421669     * Returns whether the given vertex is outside the normal bounds of the world
    16431670     * (i.e. outside the range of a circular map)
    16441671     */
  • source/simulation2/components/ICmpFogging.cpp

     
    3939    {
    4040        return m_Script.Call<bool>("IsMiraged", player);
    4141    }
     42
     43    virtual void ForceMiraging(player_id_t player)
     44    {
     45        return m_Script.CallVoid("ForceMiraging", player);
     46    }
    4247};
    4348
    4449REGISTER_COMPONENT_SCRIPT_WRAPPER(FoggingScripted)
  • source/simulation2/components/ICmpFogging.h

     
    3232public:
    3333    virtual bool WasSeen(player_id_t player) = 0;
    3434    virtual bool IsMiraged(player_id_t player) = 0;
     35    virtual void ForceMiraging(player_id_t player) = 0;
    3536
    3637    DECLARE_INTERFACE_TYPE(Fogging)
    3738};
  • source/simulation2/components/ICmpRangeManager.cpp

     
    4747DEFINE_INTERFACE_METHOD_1("GetEntitiesByPlayer", std::vector<entity_id_t>, ICmpRangeManager, GetEntitiesByPlayer, player_id_t)
    4848DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool)
    4949DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t)
     50DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories)
    5051DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool)
    5152DEFINE_INTERFACE_METHOD_1("GetLosRevealAll", bool, ICmpRangeManager, GetLosRevealAll, player_id_t)
    5253DEFINE_INTERFACE_METHOD_5("GetElevationAdaptedRange", entity_pos_t, ICmpRangeManager, GetElevationAdaptedRange, CFixedVector3D, CFixedVector3D, entity_pos_t, entity_pos_t, entity_pos_t)
  • source/simulation2/components/ICmpRangeManager.h

     
    339339    virtual void ExploreAllTiles(player_id_t p) = 0;
    340340
    341341    /**
     342     * Explore the tiles inside each player's territory.
     343     * This is done only at the beginning of the game.
     344     */
     345    virtual void ExploreTerritories() = 0;
     346
     347    /**
    342348     * Set whether the whole map should be made visible to the given player.
    343349     * If player is -1, the map will be made visible to all players.
    344350     */