diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 5c8b24654..14a1e376b 100644 --- a/client/CPlayerInterface.cpp +++ b/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]); diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index fc67c3412..54ae44a0f 100644 --- a/client/mapHandler.cpp +++ b/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) { - out = CGI->generaltexth->terrainNames[t.terType]; - if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG) + out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS); + 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() diff --git a/client/mapHandler.h b/client/mapHandler.h index 72f094904..03610ead2 100644 --- a/client/mapHandler.h +++ b/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); diff --git a/lib/mapObjects/CObjectHandler.h b/lib/mapObjects/CObjectHandler.h index cbc7f511f..42f46bfe9 100644 --- a/lib/mapObjects/CObjectHandler.h +++ b/lib/mapObjects/CObjectHandler.h @@ -159,6 +159,22 @@ public: std::set 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 getAmbientSound() const; boost::optional getVisitSound() const; boost::optional getRemovalSound() const;