Ticket #2709: explore_init.patch
File explore_init.patch, 7.3 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Fogging.js
106 106 ); 107 107 }; 108 108 109 Fogging.prototype.ForceMiraging = function(player) 110 { 111 this.seen[player] = true; 112 this.LoadMirage(player); 113 }; 114 109 115 Fogging.prototype.IsMiraged = function(player) 110 116 { 111 117 if (player >= this.mirages.length) -
binaries/data/mods/public/simulation/helpers/InitGame.js
9 9 10 10 function InitGame(settings) 11 11 { 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 12 26 // No settings when loading a map in Atlas, so do nothing 13 27 if (!settings) 14 28 return; -
binaries/data/mods/public/simulation/helpers/Setup.js
36 36 cmpObstructionManager.SetPassabilityCircular(true); 37 37 } 38 38 39 if (settings.ExploreMap)40 {41 // this needs to happen after changing the map to a circular one42 // as by making the map circular, the explored tiles get reset43 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 49 39 var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); 50 40 if (settings.GameType) 51 41 cmpEndGameManager.SetGameType(settings.GameType); -
source/simulation2/components/CCmpRangeManager.cpp
287 287 std::vector<bool> m_LosRevealAll; 288 288 bool m_LosCircular; 289 289 i32 m_TerrainVerticesPerSide; 290 size_t m_TerritoriesDirtyID;291 290 292 291 // Cache for visibility tracking (not serialized) 293 292 i32 m_LosTilesPerSide; … … 343 342 344 343 m_LosCircular = false; 345 344 m_TerrainVerticesPerSide = 0; 346 347 m_TerritoriesDirtyID = 0;348 345 } 349 346 350 347 virtual void Deinit() … … 1603 1600 m_LosState[i + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 1604 1601 } 1605 1602 } 1603 1604 SeeExploredEntities(p); 1606 1605 } 1607 1606 1608 v oid UpdateTerritoriesLos()1607 virtual void ExploreTerritories() 1609 1608 { 1610 1609 CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSystemEntity()); 1611 if (!cmpTerritoryManager || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))1612 return;1613 1610 1614 1611 const Grid<u8>& grid = cmpTerritoryManager->GetTerritoryGrid(); 1615 1612 ENSURE(grid.m_W == m_TerrainVerticesPerSide-1 && grid.m_H == m_TerrainVerticesPerSide-1); … … 1636 1633 } 1637 1634 } 1638 1635 } 1636 1637 for (player_id_t p = 1; p < MAX_LOS_PLAYER_ID+1; ++p) 1638 SeeExploredEntities(p); 1639 1639 } 1640 1640 1641 1641 /** 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 /** 1642 1669 * Returns whether the given vertex is outside the normal bounds of the world 1643 1670 * (i.e. outside the range of a circular map) 1644 1671 */ -
source/simulation2/components/ICmpFogging.cpp
39 39 { 40 40 return m_Script.Call<bool>("IsMiraged", player); 41 41 } 42 43 virtual void ForceMiraging(player_id_t player) 44 { 45 return m_Script.CallVoid("ForceMiraging", player); 46 } 42 47 }; 43 48 44 49 REGISTER_COMPONENT_SCRIPT_WRAPPER(FoggingScripted) -
source/simulation2/components/ICmpFogging.h
32 32 public: 33 33 virtual bool WasSeen(player_id_t player) = 0; 34 34 virtual bool IsMiraged(player_id_t player) = 0; 35 virtual void ForceMiraging(player_id_t player) = 0; 35 36 36 37 DECLARE_INTERFACE_TYPE(Fogging) 37 38 }; -
source/simulation2/components/ICmpRangeManager.cpp
47 47 DEFINE_INTERFACE_METHOD_1("GetEntitiesByPlayer", std::vector<entity_id_t>, ICmpRangeManager, GetEntitiesByPlayer, player_id_t) 48 48 DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool) 49 49 DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t) 50 DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories) 50 51 DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool) 51 52 DEFINE_INTERFACE_METHOD_1("GetLosRevealAll", bool, ICmpRangeManager, GetLosRevealAll, player_id_t) 52 53 DEFINE_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
339 339 virtual void ExploreAllTiles(player_id_t p) = 0; 340 340 341 341 /** 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 /** 342 348 * Set whether the whole map should be made visible to the given player. 343 349 * If player is -1, the map will be made visible to all players. 344 350 */