1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Fix: Terrain description should be shown correctly

This commit is contained in:
Dmitry Orlov 2021-11-06 00:08:48 +03:00 committed by Andrii Danylchenko
parent 7cfd1fe0ca
commit 0427fa45dd
4 changed files with 63 additions and 24 deletions

View File

@ -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; 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: case EDiggingStatus::CAN_DIG:
break; break;
@ -2412,7 +2412,7 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance *h)
assert(0); assert(0);
} }
if (msgToShow < 0) if(msgToShow < 0)
cb->dig(h); cb->dig(h);
else else
showInfoDialog(CGI->generaltexth->allTexts[msgToShow]); showInfoDialog(CGI->generaltexth->allTexts[msgToShow]);

View File

@ -1394,30 +1394,52 @@ CMapHandler::CMapHandler()
egdeAnimation->preload(); egdeAnimation->preload();
} }
void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terName ) bool CMapHandler::hasObjectHole(const int3 & pos) const
{ {
out.clear(); const TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
const TerrainTile &t = map->getTile(pos);
for(auto & elem : tt.objects) for(auto & elem : tt.objects)
{ {
if(elem.obj && elem.obj->ID == Obj::HOLE) //Hole if(elem.obj && elem.obj->ID == Obj::HOLE)
{ return true;
out = elem.obj->getObjectName();
return;
}
} }
return false;
}
void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRMB) const
{
const TerrainTile & t = map->getTile(pos);
if(t.hasFavorableWinds()) if(t.hasFavorableWinds())
out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS);
else if(terName)
{ {
out = CGI->generaltexth->terrainNames[t.terType]; out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS);
if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG) return;
}
const TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
bool isTile2Terrain = false;
out.clear();
for(auto & elem : tt.objects)
{
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() void CMapHandler::discardWorldViewCache()

View File

@ -382,9 +382,10 @@ public:
CMapHandler(); CMapHandler();
~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 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 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(); void init();
EMapAnimRedrawStatus drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim = false); EMapAnimRedrawStatus drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim = false);

View File

@ -159,6 +159,22 @@ public:
std::set<int3> getBlockedOffsets() const; //returns set of relative positions blocked by this object std::set<int3> getBlockedOffsets() const; //returns set of relative positions blocked by this object
bool isVisitable() const; //returns true if object is visitable 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> getAmbientSound() const;
boost::optional<std::string> getVisitSound() const; boost::optional<std::string> getVisitSound() const;
boost::optional<std::string> getRemovalSound() const; boost::optional<std::string> getRemovalSound() const;