Browse Source

Sight map: add enum with readable names to FoWChange netpack

Arseniy Shestakov 9 years ago
parent
commit
06b50d5eb6

+ 3 - 3
lib/CGameState.cpp

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

+ 7 - 0
lib/NetPacks.h

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

+ 5 - 2
lib/NetPacksLib.cpp

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

+ 1 - 1
lib/mapObjects/CGTownInstance.cpp

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

+ 3 - 3
lib/mapObjects/MiscObjects.cpp

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

+ 3 - 3
server/CGameHandler.cpp

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