From c7247936bf86e826b086b6c543d6f02a99fe715d Mon Sep 17 00:00:00 2001 From: Vantha Date: Sat, 3 Jan 2026 11:24:13 +0100 Subject: [PATCH] Introduce separate LosRevealWholeMapForAll flag It was previously stored at the end of the array of per-player flags and set by calling SetLosRevealWholeMap with the player ID -1. However, ever since the introduction of observer mode in 883f307b40, -1 is the player ID of observers everywhere else including for GetLosRevealWhole: GetLosRevealWhole(-1) always returns true in order to reveal the map to observers, however, the cinema manager, for example, called it meaning to find out whether the whole map is revealed to all players. To fix this and avoid confusion about this in the future, this patch splits this flag from the per-player flag array and introduces new functions to set and retrieve it. --- .../public/maps/random/wall_demo_triggers.js | 2 +- .../mods/public/simulation/helpers/Cheat.js | 2 +- .../public/simulation/helpers/Commands.js | 2 +- .../mods/public/simulation/helpers/Setup.js | 2 +- .../components/CCmpCinemaManager.cpp | 4 +-- .../components/CCmpRangeManager.cpp | 28 +++++++++++-------- .../components/ICmpRangeManager.cpp | 2 ++ .../simulation2/components/ICmpRangeManager.h | 11 +++++++- .../tools/atlas/GameInterface/ActorViewer.cpp | 2 +- .../GameInterface/Handlers/MapHandlers.cpp | 2 +- 10 files changed, 37 insertions(+), 20 deletions(-) diff --git a/binaries/data/mods/public/maps/random/wall_demo_triggers.js b/binaries/data/mods/public/maps/random/wall_demo_triggers.js index 52329a8356..74f9ee0c99 100644 --- a/binaries/data/mods/public/maps/random/wall_demo_triggers.js +++ b/binaries/data/mods/public/maps/random/wall_demo_triggers.js @@ -1 +1 @@ -Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetLosRevealWholeMap(-1, true); +Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetLosRevealWholeMapForAll(true); diff --git a/binaries/data/mods/public/simulation/helpers/Cheat.js b/binaries/data/mods/public/simulation/helpers/Cheat.js index 757eed6abb..598c2f95a3 100644 --- a/binaries/data/mods/public/simulation/helpers/Cheat.js +++ b/binaries/data/mods/public/simulation/helpers/Cheat.js @@ -22,7 +22,7 @@ function Cheat(input) cmpPlayer.AddResource(input.text, input.parameter); return; case "revealmap": - Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetLosRevealWholeMap(-1, true); + Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetLosRevealWholeMapForAll(true); return; case "maxpopulation": cmpPlayer.SetPopulationBonuses(cmpPopulationManager.GetPopulationCap() + 500); diff --git a/binaries/data/mods/public/simulation/helpers/Commands.js b/binaries/data/mods/public/simulation/helpers/Commands.js index 5f69bfd1a9..35fbd1847a 100644 --- a/binaries/data/mods/public/simulation/helpers/Commands.js +++ b/binaries/data/mods/public/simulation/helpers/Commands.js @@ -101,7 +101,7 @@ var g_Commands = { // Reveal the map for all players, not just the current player, // primarily to make it obvious to everyone that the player is cheating var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - cmpRangeManager.SetLosRevealWholeMap(-1, cmd.enable); + cmpRangeManager.SetLosRevealWholeMapForAll(cmd.enable); }, "walk": function(player, cmd, data) diff --git a/binaries/data/mods/public/simulation/helpers/Setup.js b/binaries/data/mods/public/simulation/helpers/Setup.js index d2c7a7970a..5ea87bdc84 100644 --- a/binaries/data/mods/public/simulation/helpers/Setup.js +++ b/binaries/data/mods/public/simulation/helpers/Setup.js @@ -19,7 +19,7 @@ function LoadMapSettings(settings) { const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); if (cmpRangeManager) - cmpRangeManager.SetLosRevealWholeMap(-1, true); + cmpRangeManager.SetLosRevealWholeMapForAll(true); } if (settings.DisableTreasures) diff --git a/source/simulation2/components/CCmpCinemaManager.cpp b/source/simulation2/components/CCmpCinemaManager.cpp index 9374dcefbb..be15731d28 100644 --- a/source/simulation2/components/CCmpCinemaManager.cpp +++ b/source/simulation2/components/CCmpCinemaManager.cpp @@ -252,9 +252,9 @@ public: if (cmpRangeManager) { if (enabled) - m_MapRevealed = cmpRangeManager->GetLosRevealWholeMap(-1); + m_MapRevealed = cmpRangeManager->GetLosRevealWholeMapForAll(); // TODO: improve m_MapRevealed state and without fade in - cmpRangeManager->SetLosRevealWholeMap(-1, enabled); + cmpRangeManager->SetLosRevealWholeMapForAll(enabled); } if (cmpTerritoryManager) cmpTerritoryManager->SetVisibility(!enabled); diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 976898bb19..6cbcb9d9ad 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -431,7 +431,8 @@ public: using LosRegion = std::pair; - std::array m_LosRevealWholeMap; + std::array m_LosRevealWholeMap; + bool m_LosRevealWholeMapForAll; bool m_LosCircular; i32 m_LosVerticesPerSide; @@ -2003,13 +2004,14 @@ public: void SetLosRevealWholeMap(player_id_t player, bool enabled) override { - if (player == -1) - m_LosRevealWholeMap[MAX_LOS_PLAYER_ID+1] = enabled; - else - { - ENSURE(player >= 0 && player <= MAX_LOS_PLAYER_ID); - m_LosRevealWholeMap[player] = enabled; - } + m_LosRevealWholeMap.at(player) = enabled; + + // On next update, update the visibility of every entity in the world + m_GlobalVisibilityUpdate = true; + } + + void SetLosRevealWholeMapForAll(bool enabled) override { + m_LosRevealWholeMapForAll = enabled; // On next update, update the visibility of every entity in the world m_GlobalVisibilityUpdate = true; @@ -2017,17 +2019,21 @@ public: bool GetLosRevealWholeMap(player_id_t player) const override { - // Special player value can force reveal-all for every player - if (m_LosRevealWholeMap[MAX_LOS_PLAYER_ID+1] || player == -1) + // Always reveal the whole map to observers. + if (m_LosRevealWholeMapForAll || player == -1) return true; + ENSURE(player >= 0 && player <= MAX_LOS_PLAYER_ID+1); - // Otherwise check the player-specific flag if (m_LosRevealWholeMap[player]) return true; return false; } + bool GetLosRevealWholeMapForAll() const override { + return m_LosRevealWholeMapForAll; + } + void SetLosCircular(bool enabled) override { m_LosCircular = enabled; diff --git a/source/simulation2/components/ICmpRangeManager.cpp b/source/simulation2/components/ICmpRangeManager.cpp index 4f01d0fae2..a39aa2783c 100644 --- a/source/simulation2/components/ICmpRangeManager.cpp +++ b/source/simulation2/components/ICmpRangeManager.cpp @@ -64,6 +64,8 @@ DEFINE_INTERFACE_METHOD("ExploreMap", ICmpRangeManager, ExploreMap) DEFINE_INTERFACE_METHOD("ExploreTerritories", ICmpRangeManager, ExploreTerritories) DEFINE_INTERFACE_METHOD("SetLosRevealWholeMap", ICmpRangeManager, SetLosRevealWholeMap) DEFINE_INTERFACE_METHOD("GetLosRevealWholeMap", ICmpRangeManager, GetLosRevealWholeMap) +DEFINE_INTERFACE_METHOD("SetLosRevealWholeMapForAll", ICmpRangeManager, SetLosRevealWholeMapForAll) +DEFINE_INTERFACE_METHOD("GetLosRevealWholeMapForAll", ICmpRangeManager, GetLosRevealWholeMapForAll) DEFINE_INTERFACE_METHOD("GetEffectiveParabolicRange", ICmpRangeManager, GetEffectiveParabolicRange) DEFINE_INTERFACE_METHOD("GetElevationAdaptedRange", ICmpRangeManager, GetElevationAdaptedRange) DEFINE_INTERFACE_METHOD("ActivateScriptedVisibility", ICmpRangeManager, ActivateScriptedVisibility) diff --git a/source/simulation2/components/ICmpRangeManager.h b/source/simulation2/components/ICmpRangeManager.h index f9f87640ab..4ed58b91e5 100644 --- a/source/simulation2/components/ICmpRangeManager.h +++ b/source/simulation2/components/ICmpRangeManager.h @@ -343,15 +343,24 @@ public: /** * Set whether the whole map should be made visible to the given player. - * If player is -1, the map will be made visible to all players. */ virtual void SetLosRevealWholeMap(player_id_t player, bool enabled) = 0; + /** + * Set whether the whole map should be made visible to all players. + */ + virtual void SetLosRevealWholeMapForAll(bool enabled) = 0; + /** * Returns whether the whole map has been made visible to the given player. */ virtual bool GetLosRevealWholeMap(player_id_t player) const = 0; + /** + * Returns whether the whole map has been made visible to all players. + */ + virtual bool GetLosRevealWholeMapForAll() const = 0; + /** * Set the LOS to be restricted to a circular map. */ diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index 21d4ef9ad8..51edd83e4a 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -334,7 +334,7 @@ ActorViewer::ActorViewer() // Remove FOW since we're in Atlas CmpPtr cmpRangeManager(m.Simulation2, SYSTEM_ENTITY); if (cmpRangeManager) - cmpRangeManager->SetLosRevealWholeMap(-1, true); + cmpRangeManager->SetLosRevealWholeMapForAll(true); m.Simulation2.InitGame(); } diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index 4f8df2f804..d5c1ba46b9 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -115,7 +115,7 @@ namespace // as visual actors cache their visibility state on first render. CmpPtr cmpRangeManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); if (cmpRangeManager) - cmpRangeManager->SetLosRevealWholeMap(-1, true); + cmpRangeManager->SetLosRevealWholeMapForAll(true); PSRETURN ret = g_Game->ReallyStartGame(); ENSURE(ret == PSRETURN_OK);