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

Digging: implement digging status on right click. Fix issue 401

This is also fix possibility to dig on some non-blockable objects like event.
This commit is contained in:
ArseniyShestakov 2015-11-29 12:32:06 +03:00
parent f940e3ed42
commit f55bfe41d6
9 changed files with 55 additions and 29 deletions

View File

@ -2036,7 +2036,7 @@ void VCAI::tryRealize(Goals::BuildThis & g)
void VCAI::tryRealize(Goals::DigAtTile & g)
{
assert(g.hero->visitablePos() == g.tile); //surely we want to crash here?
if (g.hero->diggingStatus() == CGHeroInstance::CAN_DIG)
if (g.hero->diggingStatus() == EDiggingStatus::CAN_DIG)
{
cb->dig(g.hero.get());
completeGoal(sptr(g)); // finished digging

View File

@ -2315,23 +2315,22 @@ 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;
CGHeroInstance::ECanDig isDiggingPossible = h->diggingStatus();
if(hlp.length())
isDiggingPossible = CGHeroInstance::TILE_OCCUPIED; //TODO integrate with canDig
switch(isDiggingPossible)
{
case CGHeroInstance::CAN_DIG:
case EDiggingStatus::CAN_DIG:
break;
case CGHeroInstance::LACK_OF_MOVEMENT:
case EDiggingStatus::LACK_OF_MOVEMENT:
msgToShow = 56; //"Digging for artifacts requires a whole day, try again tomorrow."
break;
case CGHeroInstance::TILE_OCCUPIED:
case EDiggingStatus::TILE_OCCUPIED:
msgToShow = 97; //Try searching on clear ground.
break;
case CGHeroInstance::WRONG_TERRAIN:
case EDiggingStatus::WRONG_TERRAIN:
msgToShow = 60; ////Try looking on land!
break;
default:

View File

@ -1579,7 +1579,13 @@ void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terN
if(t.hasFavourableWinds())
out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS);
else if(terName)
{
out = CGI->generaltexth->terrainNames[t.terType];
if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
{
out = boost::str(boost::format("%s %s") % out % CGI->generaltexth->allTexts[330]); /// digging ok
}
}
}
void CMapHandler::discardWorldViewCache()

View File

@ -777,6 +777,28 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const ETerrainType terr
ID_LIKE_OPERATORS(ETerrainType, ETerrainType::EETerrainType)
class DLL_LINKAGE EDiggingStatus
{
public:
enum EEDiggingStatus
{
UNKNOWN = -1,
CAN_DIG = 0,
LACK_OF_MOVEMENT,
WRONG_TERRAIN,
TILE_OCCUPIED
};
EDiggingStatus(EEDiggingStatus _num = UNKNOWN) : num(_num)
{}
ID_LIKE_CLASS_COMMON(EDiggingStatus, EEDiggingStatus)
EEDiggingStatus num;
};
ID_LIKE_OPERATORS(EDiggingStatus, EDiggingStatus::EEDiggingStatus)
class DLL_LINKAGE EPathfindingLayer
{
public:

View File

@ -1189,22 +1189,12 @@ int CGHeroInstance::movementPointsAfterEmbark(int MPsBefore, int basicCost, bool
return 0; //take all MPs otherwise
}
CGHeroInstance::ECanDig CGHeroInstance::diggingStatus() const
EDiggingStatus CGHeroInstance::diggingStatus() const
{
if(movement < maxMovePoints(true))
return LACK_OF_MOVEMENT;
else if(cb->getTile(getPosition(false))->terType == ETerrainType::WATER)
return WRONG_TERRAIN;
else
{
const TerrainTile *t = cb->getTile(getPosition());
//TODO look for hole
//CGI->mh->getTerrainDescr(h->getPosition(false), hlp, false);
if(/*hlp.length() || */t->blockingObjects.size() > 1)
return TILE_OCCUPIED;
else
return CAN_DIG;
}
return EDiggingStatus::LACK_OF_MOVEMENT;
return cb->getTile(getPosition(false))->getDiggingStatus();
}
ArtBearer::ArtBearer CGHeroInstance::bearerType() const

View File

@ -40,10 +40,6 @@ public:
class DLL_LINKAGE CGHeroInstance : public CArmedInstance, public IBoatGenerator, public CArtifactSet, public ISpellCaster
{
public:
enum ECanDig
{
CAN_DIG, LACK_OF_MOVEMENT, WRONG_TERRAIN, TILE_OCCUPIED
};
//////////////////////////////////////////////////////////////////////////
ui8 moveDir; //format: 123
@ -174,7 +170,7 @@ public:
bool canCastThisSpell(const CSpell * spell) const; //determines if this hero can cast given spell; takes into account existing spell in spellbook, existing spellbook and artifact bonuses
CStackBasicDescriptor calculateNecromancy (const BattleResult &battleResult) const;
void showNecromancyDialog(const CStackBasicDescriptor &raisedStack) const;
ECanDig diggingStatus() const; //0 - can dig; 1 - lack of movement; 2 -
EDiggingStatus diggingStatus() const;
//////////////////////////////////////////////////////////////////////////

View File

@ -146,6 +146,18 @@ bool TerrainTile::isCoastal() const
return extTileFlags & 64;
}
EDiggingStatus TerrainTile::getDiggingStatus(const bool excludeTop) const
{
if(terType == ETerrainType::WATER || terType == ETerrainType::ROCK)
return EDiggingStatus::WRONG_TERRAIN;
int allowedBlocked = excludeTop ? 1 : 0;
if(blockingObjects.size() > allowedBlocked || topVisitableObj(excludeTop))
return EDiggingStatus::TILE_OCCUPIED;
else
return EDiggingStatus::CAN_DIG;
}
bool TerrainTile::hasFavourableWinds() const
{
return extTileFlags & 128;

View File

@ -277,6 +277,7 @@ struct DLL_LINKAGE TerrainTile
CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
bool isWater() const;
bool isCoastal() const;
EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
bool hasFavourableWinds() const;
ETerrainType terType;

View File

@ -4896,7 +4896,7 @@ bool CGameHandler::dig( const CGHeroInstance *h )
}
}
if(h->diggingStatus() != CGHeroInstance::CAN_DIG) //checks for terrain and movement
if(h->diggingStatus() != EDiggingStatus::CAN_DIG) //checks for terrain and movement
COMPLAIN_RETF("Hero cannot dig (error code %d)!", h->diggingStatus());
//create a hole