| 73 | } |
| 74 | |
| 75 | void SpellCreatureStrength::checkSpellCast(GameMap* gameMap, const InputManager& inputManager, InputCommand& inputCommand) |
| 76 | { |
| 77 | Player* player = gameMap->getLocalPlayer(); |
| 78 | int32_t pricePerTarget = ConfigManager::getSingleton().getSpellConfigInt32("CreatureStrengthPrice"); |
| 79 | int32_t playerMana = static_cast<int32_t>(player->getSeat()->getMana()); |
| 80 | if(inputManager.mCommandState == InputCommandState::infoOnly) |
| 81 | { |
| 82 | if(playerMana < pricePerTarget) |
| 83 | { |
| 84 | std::string txt = formatCastSpell(SpellType::creatureStrength, pricePerTarget); |
| 85 | inputCommand.displayText(Ogre::ColourValue::Red, txt); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | std::string txt = formatCastSpell(SpellType::creatureStrength, pricePerTarget); |
| 90 | inputCommand.displayText(Ogre::ColourValue::White, txt); |
| 91 | } |
| 92 | inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos, |
| 93 | inputManager.mYPos); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | Tile* tileSelected = gameMap->getTile(inputManager.mXPos, inputManager.mYPos); |
| 98 | if(tileSelected == nullptr) |
| 99 | return; |
| 100 | |
| 101 | if(inputManager.mCommandState == InputCommandState::building) |
| 102 | { |
| 103 | inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos, |
| 104 | inputManager.mYPos); |
| 105 | } |
| 106 | |
| 107 | std::vector<GameEntity*> entities; |
| 108 | // We search the closest creature alive |
| 109 | tileSelected->fillWithEntities(entities, SelectionEntityWanted::creatureAliveAllied, player); |
| 110 | Creature* closestCreature = nullptr; |
| 111 | double closestDist = 0; |
| 112 | for(GameEntity* entity : entities) |
| 113 | { |
| 114 | if(entity->getObjectType() != GameEntityType::creature) |
| 115 | { |
| 116 | OD_LOG_ERR("entityName=" + entity->getName() + ", entityType=" + Helper::toString(static_cast<uint32_t>(entity->getObjectType()))); |
| 117 | continue; |
| 118 | } |
| 119 | |
| 120 | const Ogre::Vector3& entityPos = entity->getPosition(); |
| 121 | double dist = Pathfinding::squaredDistance(entityPos.x, inputManager.mKeeperHandPos.x, entityPos.y, inputManager.mKeeperHandPos.y); |
| 122 | if(closestCreature == nullptr) |
| 123 | { |
| 124 | closestDist = dist; |
| 125 | closestCreature = static_cast<Creature*>(entity); |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | if(dist >= closestDist) |
| 130 | continue; |
| 131 | |
| 132 | closestDist = dist; |
nothing calls this directly
no test coverage detected