Browse Source

Support for Cover of Darkness

DjWarmonger 15 years ago
parent
commit
2ed69d3f4d
4 changed files with 68 additions and 10 deletions
  1. 12 0
      client/CAdvmapInterface.cpp
  2. 2 0
      client/CPlayerInterface.cpp
  3. 32 8
      hch/CObjectHandler.cpp
  4. 22 2
      lib/NetPacksLib.cpp

+ 12 - 0
client/CAdvmapInterface.cpp

@@ -429,6 +429,18 @@ void CMinimap::showVisibleTiles(int level)
 
 void CMinimap::hideTile(const int3 &pos)
 {
+	int3 mapSizes = LOCPLINT->cb->getMapSize();
+	//drawing terrain
+	int mw = map[0]->w, mh = map[0]->h;
+	double wo = ((double)mw)/mapSizes.x, ho = ((double)mh)/mapSizes.y;
+	for (int ii=0; ii<wo; ii++)
+	{
+		for (int jj=0; jj<ho; jj++)
+		{
+			if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
+				CSDL_Ext::SDL_PutPixelWithoutRefresh(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0);
+		}
+	}
 }
 
 void CMinimap::show( SDL_Surface * to )

+ 2 - 0
client/CPlayerInterface.cpp

@@ -913,6 +913,8 @@ void CPlayerInterface::tileHidden(const std::set<int3> &pos)
 	boost::unique_lock<boost::recursive_mutex> un(*pim);
 	for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
 		adventureInt->minimap.hideTile(*i);
+	if(pos.size())
+		GH.totalRedraw();
 }
 
 void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)

+ 32 - 8
hch/CObjectHandler.cpp

@@ -4377,16 +4377,40 @@ void CGEvent::activated( const CGHeroInstance * h ) const
 void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const
 {
 	InfoWindow iw;
-	iw.soundID = soundBase::LIGHTHOUSE;
 	iw.player = h->tempOwner;
-	iw.text.addTxt(MetaString::ADVOB_TXT,98 + (ID==60));
-	cb->showInfoDialog(&iw);
+	switch (ID)
+	{
+		case 58://redwood observatory
+		case 60://pillar of fire
+		{
+			iw.soundID = soundBase::LIGHTHOUSE;
+			iw.text.addTxt(MetaString::ADVOB_TXT,98 + (ID==60));
 
-	FoWChange fw;
-	fw.player = h->tempOwner;
-	fw.mode = 1;
-	cb->getTilesInRange(fw.tiles,pos,20,h->tempOwner,1);
-	cb->sendAndApply(&fw);
+			FoWChange fw;
+			fw.player = h->tempOwner;
+			fw.mode = 1;
+			cb->getTilesInRange (fw.tiles, pos, 20, h->tempOwner, 1);
+			cb->sendAndApply (&fw);
+			break;
+		}
+		case 15://cover of darkness
+		{
+			iw.text.addTxt (MetaString::ADVOB_TXT, 31);
+			for (int i = 0; i < cb->gameState()->players.size(); ++i)
+			{
+				if ((h->tempOwner != i) && (cb->gameState()->getPlayer(i)->status == PlayerState::INGAME)) //TODO: team support
+				{
+					FoWChange fw;
+				    fw.mode = 0;
+					fw.player = i;
+					cb->getTilesInRange (fw.tiles, pos, 20, i, -1);
+					cb->sendAndApply (&fw);
+				}
+			}
+			break;
+		}
+	}
+	cb->showInfoDialog(&iw);
 }
 
 void CGShrine::onHeroVisit( const CGHeroInstance * h ) const

+ 22 - 2
lib/NetPacksLib.cpp

@@ -164,10 +164,30 @@ DLL_EXPORT void SetMovePoints::applyGs( CGameState *gs )
 
 DLL_EXPORT void FoWChange::applyGs( CGameState *gs )
 {
-	BOOST_FOREACH(int3 t, tiles)
+		BOOST_FOREACH(int3 t, tiles)
 		gs->getPlayer(player)->fogOfWarMap[t.x][t.y][t.z] = mode;
+	if (mode == 0) //do not hide too much
+	{
+		std::set<int3> tilesRevealed;
+		for (size_t i = 0; i < gs->map->objects.size(); i++)
+		{
+			if(gs->map->objects[i] && gs->map->objects[i]->tempOwner == player) //check owned observators
+			{
+				switch(gs->map->objects[i]->ID)
+				{
+				case 34://hero
+				case 53://mine
+				case 98://town
+				case 220:
+					gs->map->objects[i]->getSightTiles(tilesRevealed);
+					break;
+				}
+			}
+		}
+		BOOST_FOREACH(int3 t, tilesRevealed) //probably not the most optimal solution ever
+			gs->getPlayer(player)->fogOfWarMap[t.x][t.y][t.z] = 1;
+	}
 }
-
 DLL_EXPORT void SetAvailableHeroes::applyGs( CGameState *gs )
 {
 	gs->getPlayer(player)->availableHeroes.clear();