MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / handleDigTile

Method handleDigTile

source/creatureaction/CreatureActionDigTile.cpp:54–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54bool CreatureActionDigTile::handleDigTile(Creature& creature, Tile& tileDig, Tile& tilePos)
55{
56 Tile* myTile = creature.getPositionTile();
57 if(myTile == nullptr)
58 {
59 OD_LOG_ERR("creature=" + creature.getName() + ", pos=" + Helper::toString(creature.getPosition()));
60 creature.popAction();
61 return false;
62 }
63
64 // Check if the tile should still be dug (it may have been dug by another worker)
65 if(!tileDig.getMarkedForDigging(creature.getSeat()->getPlayer()) ||
66 !tileDig.isDiggable(creature.getSeat()))
67 {
68 creature.popAction();
69 return true;
70 }
71
72 // We go to the tile we locked
73 if(&tilePos != myTile)
74 {
75 if(!creature.setDestination(&tilePos))
76 {
77 OD_LOG_ERR("creature=" + creature.getName() + ", myTile=" + Tile::displayAsString(myTile) + ", tileDig=" + Tile::displayAsString(&tileDig) + ", tilePos=" + Tile::displayAsString(&tilePos));
78 creature.popAction();
79 }
80 return true;
81 }
82
83 // Dig out the tile by decreasing the tile's fullness.
84 const Ogre::Vector3& pos = creature.getPosition();
85 Ogre::Vector3 walkDirection(tileDig.getX() - pos.x, tileDig.getY() - pos.y, 0);
86 walkDirection.normalise();
87 creature.setAnimationState(EntityAnimation::dig_anim, true, walkDirection);
88 double amountDug = tileDig.digOut(creature.getDigRate());
89 if(amountDug > 0.0)
90 {
91 creature.receiveExp(1.5 * creature.getDigRate() / 20.0);
92
93 // If the tile is a gold tile accumulate gold for this creature.
94 switch(tileDig.getType())
95 {
96 case TileType::gold:
97 {
98 static const double digCoefGold = ConfigManager::getSingleton().getDigCoefGold();
99 double tempDouble = digCoefGold * amountDug;
100 creature.addGoldCarried(static_cast<int>(tempDouble));
101 creature.getSeat()->addGoldMined(static_cast<int>(tempDouble));
102 // Receive experience for digging gold
103 creature.receiveExp(creature.getDigRate() / 20.0);
104 break;
105 }
106 case TileType::gem:
107 {
108 static const double digCoefGem = ConfigManager::getSingleton().getDigCoefGem();
109 double tempDouble = digCoefGem * amountDug;
110 creature.addGoldCarried(static_cast<int>(tempDouble));
111 creature.getSeat()->addGoldMined(static_cast<int>(tempDouble));

Callers

nothing calls this directly

Calls 15

getPositionTileMethod · 0.80
popActionMethod · 0.80
getMarkedForDiggingMethod · 0.80
isDiggableMethod · 0.80
setDestinationMethod · 0.80
digOutMethod · 0.80
getDigCoefGoldMethod · 0.80
addGoldCarriedMethod · 0.80
addGoldMinedMethod · 0.80
getDigCoefGemMethod · 0.80
getFullnessMethod · 0.80
fireCreatureSoundMethod · 0.80

Tested by

no test coverage detected