1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00

Sight map: add enum with readable names to FoWChange netpack

This commit is contained in:
Arseniy Shestakov
2016-09-22 07:34:32 +03:00
parent 33f8686ca6
commit 06b50d5eb6
6 changed files with 22 additions and 12 deletions

View File

@ -1539,10 +1539,10 @@ void CGameState::addSightObj(TeamID team, const CGObjectInstance * obj, bool add
{
if(add)
{
if(ts->fogOfWarMap[t.x][t.y][t.z] == 0)
ts->fogOfWarMap[t.x][t.y][t.z] = 2;
if(ts->fogOfWarMap[t.x][t.y][t.z] == FoWChange::HIDDEN)
ts->fogOfWarMap[t.x][t.y][t.z] = FoWChange::WITHIN_SIGHT_RANGE; //Object revealed tile
else
ts->fogOfWarMap[t.x][t.y][t.z]++;
ts->fogOfWarMap[t.x][t.y][t.z]++; //One more object have sight over tile
}
else
{

View File

@ -336,6 +336,13 @@ struct FoWChange : public CPackForClient
void applyCl(CClient *cl);
DLL_LINKAGE void applyGs(CGameState *gs);
enum : ui8
{
HIDDEN = 0, //tile is hidden in fog of war
REVEALED = 1, //tile is visible for player
WITHIN_SIGHT_RANGE = 2 //at least one player-owned object have sight over tile
};
std::unordered_set<int3, struct ShashInt3 > tiles;
PlayerColor player;
ui8 mode; //mode==0 - hide, mode==1 - reveal

View File

@ -218,12 +218,15 @@ DLL_LINKAGE void SetMovePoints::applyGs(CGameState *gs)
DLL_LINKAGE void FoWChange::applyGs(CGameState *gs)
{
assert(mode < WITHIN_SIGHT_RANGE); //Not valid mode
TeamState * team = gs->getPlayerTeam(player);
for(int3 t : tiles)
{
if(mode == 0 && team->fogOfWarMap[t.x][t.y][t.z] > 1)
//Tile within sight range of player-owned objects cannot be hidden
if(mode == HIDDEN && team->fogOfWarMap[t.x][t.y][t.z] >= WITHIN_SIGHT_RANGE)
continue;
else if(mode == 1 && team->fogOfWarMap[t.x][t.y][t.z])
//Don't do anything if tile is already revealed
if(mode == REVEALED && team->fogOfWarMap[t.x][t.y][t.z])
continue;
team->fogOfWarMap[t.x][t.y][t.z] = mode;

View File

@ -1329,7 +1329,7 @@ void CGTownInstance::battleFinished(const CGHeroInstance *hero, const BattleResu
cb->setOwner (this, hero->tempOwner); //give control after checkout is done
FoWChange fw;
fw.player = hero->tempOwner;
fw.mode = 1;
fw.mode = FoWChange::REVEALED;
cb->getTilesInRange(fw.tiles, getSightCenter(), getSightRadius(), tempOwner, 1);
cb->sendAndApply (&fw);
}

View File

@ -1557,7 +1557,7 @@ void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const
FoWChange fw;
fw.player = h->tempOwner;
fw.mode = 1;
fw.mode = FoWChange::REVEALED;
cb->getTilesInRange (fw.tiles, pos, 20, h->tempOwner, 1);
cb->sendAndApply (&fw);
break;
@ -1884,7 +1884,7 @@ void CGMagi::onHeroVisit(const CGHeroInstance * h) const
FoWChange fw;
fw.player = h->tempOwner;
fw.mode = 1;
fw.mode = FoWChange::REVEALED;
fw.waitForDialogs = true;
for(auto it : eyelist[subID])
@ -2051,7 +2051,7 @@ void CCartographer::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answ
{
cb->giveResource (hero->tempOwner, Res::GOLD, -1000);
FoWChange fw;
fw.mode = 1;
fw.mode = FoWChange::REVEALED;
fw.player = hero->tempOwner;
//subIDs of different types of cartographers:

View File

@ -1705,7 +1705,7 @@ void CGameHandler::newTurn()
if (player != PlayerColor::NEUTRAL) //do not reveal fow for neutral player
{
FoWChange fw;
fw.mode = 1;
fw.mode = FoWChange::REVEALED;
fw.player = player;
// find all hidden tiles
const auto & fow = getPlayerTeam(player)->fogOfWarMap;
@ -3020,7 +3020,7 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID,
// now when everything is built - reveal tiles for lookout tower
FoWChange fw;
fw.player = t->tempOwner;
fw.mode = 1;
fw.mode = FoWChange::REVEALED;
getTilesInRange(fw.tiles, t->getSightCenter(), t->getSightRadius(), t->tempOwner, 1);
sendAndApply(&fw);
@ -6299,7 +6299,7 @@ void CGameHandler::changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, Pl
FoWChange fow;
fow.tiles = tiles;
fow.player = player;
fow.mode = hide? 0 : 1;
fow.mode = hide ? FoWChange::HIDDEN : FoWChange::REVEALED;
sendAndApply(&fow);
}