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.
This commit is contained in:
Vantha 2026-01-03 11:24:13 +01:00 committed by Vantha
parent 21a61721a7
commit c7247936bf
10 changed files with 37 additions and 20 deletions

View file

@ -1 +1 @@
Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetLosRevealWholeMap(-1, true);
Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetLosRevealWholeMapForAll(true);

View file

@ -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);

View file

@ -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)

View file

@ -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)

View file

@ -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);

View file

@ -431,7 +431,8 @@ public:
using LosRegion = std::pair<u16, u16>;
std::array<bool, MAX_LOS_PLAYER_ID+2> m_LosRevealWholeMap;
std::array<bool, MAX_LOS_PLAYER_ID+1> 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;

View file

@ -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)

View file

@ -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.
*/

View file

@ -334,7 +334,7 @@ ActorViewer::ActorViewer()
// Remove FOW since we're in Atlas
CmpPtr<ICmpRangeManager> cmpRangeManager(m.Simulation2, SYSTEM_ENTITY);
if (cmpRangeManager)
cmpRangeManager->SetLosRevealWholeMap(-1, true);
cmpRangeManager->SetLosRevealWholeMapForAll(true);
m.Simulation2.InitGame();
}

View file

@ -115,7 +115,7 @@ namespace
// as visual actors cache their visibility state on first render.
CmpPtr<ICmpRangeManager> cmpRangeManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
if (cmpRangeManager)
cmpRangeManager->SetLosRevealWholeMap(-1, true);
cmpRangeManager->SetLosRevealWholeMapForAll(true);
PSRETURN ret = g_Game->ReallyStartGame();
ENSURE(ret == PSRETURN_OK);