| 52 | } |
| 53 | |
| 54 | bool 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)); |
nothing calls this directly
no test coverage detected