Browse Source

Fix: Terrain description should be shown correctly

Dmitry Orlov 4 years ago
parent
commit
0427fa45dd
4 changed files with 62 additions and 23 deletions
  1. 9 9
      client/CPlayerInterface.cpp
  2. 35 13
      client/mapHandler.cpp
  3. 2 1
      client/mapHandler.h
  4. 16 0
      lib/mapObjects/CObjectHandler.h

+ 9 - 9
client/CPlayerInterface.cpp

@@ -2386,16 +2386,16 @@ void CPlayerInterface::acceptTurn()
 	}
 }
 
-void CPlayerInterface::tryDiggging(const CGHeroInstance *h)
+void CPlayerInterface::tryDiggging(const CGHeroInstance * h)
 {
-	std::string hlp;
-	CGI->mh->getTerrainDescr(h->getPosition(false), hlp, false);
-	auto isDiggingPossible = h->diggingStatus();
-	if (hlp.length())
-		isDiggingPossible = EDiggingStatus::TILE_OCCUPIED; //TODO integrate with canDig
-
 	int msgToShow = -1;
-	switch(isDiggingPossible)
+	const bool isBlocked = CGI->mh->hasObjectHole(h->getPosition(false)); // Don't dig in the pit.
+
+	const auto diggingStatus = isBlocked
+		? EDiggingStatus::TILE_OCCUPIED
+		: h->diggingStatus().num;
+
+	switch(diggingStatus)
 	{
 	case EDiggingStatus::CAN_DIG:
 		break;
@@ -2412,7 +2412,7 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance *h)
 		assert(0);
 	}
 
-	if (msgToShow < 0)
+	if(msgToShow < 0)
 		cb->dig(h);
 	else
 		showInfoDialog(CGI->generaltexth->allTexts[msgToShow]);

+ 35 - 13
client/mapHandler.cpp

@@ -1394,30 +1394,52 @@ CMapHandler::CMapHandler()
 	egdeAnimation->preload();
 }
 
-void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terName )
+bool CMapHandler::hasObjectHole(const int3 & pos) const
 {
-	out.clear();
-	TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
-	const TerrainTile &t = map->getTile(pos);
+	const TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
+
 	for(auto & elem : tt.objects)
 	{
-		if(elem.obj && elem.obj->ID == Obj::HOLE) //Hole
-		{
-			out = elem.obj->getObjectName();
-			return;
-		}
+		if(elem.obj && elem.obj->ID == Obj::HOLE)
+			return true;
 	}
+	return false;
+}
+
+void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRMB) const
+{
+	const TerrainTile & t = map->getTile(pos);
 
 	if(t.hasFavorableWinds())
+	{
 		out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS);
-	else if(terName)
+		return;
+	}
+	const TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
+	bool isTile2Terrain = false;
+	out.clear();
+
+	for(auto & elem : tt.objects)
 	{
-		out = CGI->generaltexth->terrainNames[t.terType];
-		if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
+		if(elem.obj)
 		{
-			out = boost::str(boost::format("%s %s") % out % CGI->generaltexth->allTexts[330]); /// digging ok
+			out = elem.obj->getObjectName();
+			if(elem.obj->ID == Obj::HOLE)
+				return;
+
+			isTile2Terrain = elem.obj->isTile2Terrain();
+			break;
 		}
 	}
+	if(!isTile2Terrain || out.empty())
+		out = CGI->generaltexth->terrainNames[t.terType];
+
+	if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
+	{
+		out = boost::str(boost::format(isRMB ? "%s\r\n%s" : "%s %s") // New line for the Message Box, space for the Status Bar
+			% out 
+			% CGI->generaltexth->allTexts[330]); // 'digging ok'
+	}
 }
 
 void CMapHandler::discardWorldViewCache()

+ 2 - 1
client/mapHandler.h

@@ -382,9 +382,10 @@ public:
 	CMapHandler();
 	~CMapHandler();
 
-	void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear
+	void getTerrainDescr(const int3 & pos, std::string & out, bool isRMB) const; // isRMB = whether Right Mouse Button is clicked
 	bool printObject(const CGObjectInstance * obj, bool fadein = false); //puts appropriate things to tiles, so obj will be visible on map
 	bool hideObject(const CGObjectInstance * obj, bool fadeout = false); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
+	bool hasObjectHole(const int3 & pos) const; // Checks if TerrainTile2 tile has a pit remained after digging.
 	void init();
 
 	EMapAnimRedrawStatus drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim = false);

+ 16 - 0
lib/mapObjects/CObjectHandler.h

@@ -159,6 +159,22 @@ public:
 	std::set<int3> getBlockedOffsets() const; //returns set of relative positions blocked by this object
 	bool isVisitable() const; //returns true if object is visitable
 
+	bool isTile2Terrain() const
+	{
+		return ID.num == Obj::CLOVER_FIELD
+			|| ID.num == Obj::CURSED_GROUND1
+			|| ID.num == Obj::CURSED_GROUND2
+			|| ID.num == Obj::EVIL_FOG
+			|| ID.num == Obj::FAVORABLE_WINDS
+			|| ID.num == Obj::FIERY_FIELDS
+			|| ID.num == Obj::HOLY_GROUNDS
+			|| ID.num == Obj::LUCID_POOLS
+			|| ID.num == Obj::MAGIC_CLOUDS
+			|| ID.num == Obj::MAGIC_PLAINS1
+			|| ID.num == Obj::MAGIC_PLAINS2
+			|| ID.num == Obj::ROCKLANDS;
+	}
+
 	boost::optional<std::string> getAmbientSound() const;
 	boost::optional<std::string> getVisitSound() const;
 	boost::optional<std::string> getRemovalSound() const;