1
1
forked from 0ad/0ad

Explore the map inside a player's territory border at the beginning of a game.

Also handle properly the "Explore Map" option with the new fogging
system.

Fixes #2709

This was SVN commit r15681.
This commit is contained in:
Nicolas Auvray 2014-08-26 10:01:04 +00:00
parent 4cd7dd77c1
commit ea78d97989
8 changed files with 66 additions and 16 deletions

View File

@ -106,6 +106,12 @@ Fogging.prototype.LoadMirage = function(player)
);
};
Fogging.prototype.ForceMiraging = function(player)
{
this.seen[player] = true;
this.LoadMirage(player);
};
Fogging.prototype.IsMiraged = function(player)
{
if (player >= this.mirages.length)

View File

@ -9,6 +9,20 @@ function ReplaceSkirmishGlobals()
function InitGame(settings)
{
if (settings.ExploreMap)
{
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
if (cmpRangeManager)
for (var i = 0; i < settings.PlayerData.length; i++)
cmpRangeManager.ExploreAllTiles(i+1);
}
else
{
// Explore the map only inside the players' territory borders
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
cmpRangeManager.ExploreTerritories();
}
// No settings when loading a map in Atlas, so do nothing
if (!settings)
return;

View File

@ -36,16 +36,6 @@ function LoadMapSettings(settings)
cmpObstructionManager.SetPassabilityCircular(true);
}
if (settings.ExploreMap)
{
// this needs to happen after changing the map to a circular one
// as by making the map circular, the explored tiles get reset
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
if (cmpRangeManager)
for (var i = 0; i < settings.PlayerData.length; i++)
cmpRangeManager.ExploreAllTiles(i+1);
}
var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
if (settings.GameType)
cmpEndGameManager.SetGameType(settings.GameType);

View File

@ -287,7 +287,6 @@ public:
std::vector<bool> m_LosRevealAll;
bool m_LosCircular;
i32 m_TerrainVerticesPerSide;
size_t m_TerritoriesDirtyID;
// Cache for visibility tracking (not serialized)
i32 m_LosTilesPerSide;
@ -343,8 +342,6 @@ public:
m_LosCircular = false;
m_TerrainVerticesPerSide = 0;
m_TerritoriesDirtyID = 0;
}
virtual void Deinit()
@ -1603,13 +1600,13 @@ public:
m_LosState[i + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1)));
}
}
SeeExploredEntities(p);
}
void UpdateTerritoriesLos()
virtual void ExploreTerritories()
{
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSystemEntity());
if (!cmpTerritoryManager || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
return;
const Grid<u8>& grid = cmpTerritoryManager->GetTerritoryGrid();
ENSURE(grid.m_W == m_TerrainVerticesPerSide-1 && grid.m_H == m_TerrainVerticesPerSide-1);
@ -1636,6 +1633,36 @@ public:
}
}
}
for (player_id_t p = 1; p < MAX_LOS_PLAYER_ID+1; ++p)
SeeExploredEntities(p);
}
/**
* Force any entity in explored territory to appear for player p.
* This is useful for miraging entities inside the territory borders at the beginning of a game,
* or if the "Explore Map" option has been set.
*/
void SeeExploredEntities(player_id_t p)
{
for (EntityMap<EntityData>::iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it)
{
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), it->first);
if (!cmpPosition || !cmpPosition->IsInWorld())
continue;
CFixedVector2D pos = cmpPosition->GetPosition2D();
int i = (pos.X / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
int j = (pos.Y / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
CLosQuerier los(GetSharedLosMask(p), m_LosState, m_TerrainVerticesPerSide);
if (!los.IsExplored(i,j) || los.IsVisible(i,j))
continue;
CmpPtr<ICmpFogging> cmpFogging(GetSimContext(), it->first);
if (cmpFogging)
cmpFogging->ForceMiraging(p);
}
}
/**

View File

@ -39,6 +39,11 @@ public:
{
return m_Script.Call<bool>("IsMiraged", player);
}
virtual void ForceMiraging(player_id_t player)
{
return m_Script.CallVoid("ForceMiraging", player);
}
};
REGISTER_COMPONENT_SCRIPT_WRAPPER(FoggingScripted)

View File

@ -32,6 +32,7 @@ class ICmpFogging : public IComponent
public:
virtual bool WasSeen(player_id_t player) = 0;
virtual bool IsMiraged(player_id_t player) = 0;
virtual void ForceMiraging(player_id_t player) = 0;
DECLARE_INTERFACE_TYPE(Fogging)
};

View File

@ -47,6 +47,7 @@ DEFINE_INTERFACE_METHOD_1("GetEntityFlagMask", u8, ICmpRangeManager, GetEntityFl
DEFINE_INTERFACE_METHOD_1("GetEntitiesByPlayer", std::vector<entity_id_t>, ICmpRangeManager, GetEntitiesByPlayer, player_id_t)
DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool)
DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t)
DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories)
DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool)
DEFINE_INTERFACE_METHOD_1("GetLosRevealAll", bool, ICmpRangeManager, GetLosRevealAll, player_id_t)
DEFINE_INTERFACE_METHOD_5("GetElevationAdaptedRange", entity_pos_t, ICmpRangeManager, GetElevationAdaptedRange, CFixedVector3D, CFixedVector3D, entity_pos_t, entity_pos_t, entity_pos_t)

View File

@ -338,6 +338,12 @@ public:
*/
virtual void ExploreAllTiles(player_id_t p) = 0;
/**
* Explore the tiles inside each player's territory.
* This is done only at the beginning of the game.
*/
virtual void ExploreTerritories() = 0;
/**
* 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.