| 72 | } |
| 73 | |
| 74 | void SpellSummonWorker::checkSpellCast(GameMap* gameMap, const InputManager& inputManager, InputCommand& inputCommand) |
| 75 | { |
| 76 | Player* player = gameMap->getLocalPlayer(); |
| 77 | int32_t playerMana = static_cast<int32_t>(player->getSeat()->getMana()); |
| 78 | |
| 79 | if(inputManager.mCommandState == InputCommandState::infoOnly) |
| 80 | { |
| 81 | int32_t price = getNextWorkerPriceForPlayer(gameMap, player); |
| 82 | if(playerMana < price) |
| 83 | { |
| 84 | std::string txt = formatCastSpell(SpellType::summonWorker, price); |
| 85 | inputCommand.displayText(Ogre::ColourValue::Red, txt); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | std::string txt = formatCastSpell(SpellType::summonWorker, price); |
| 90 | inputCommand.displayText(Ogre::ColourValue::White, txt); |
| 91 | } |
| 92 | inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos, inputManager.mYPos); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | std::vector<GameEntity*> targets; |
| 97 | gameMap->playerSelects(targets, inputManager.mXPos, inputManager.mYPos, inputManager.mLStartDragX, |
| 98 | inputManager.mLStartDragY, SelectionTileAllowed::groundClaimedAllied, SelectionEntityWanted::tiles, player); |
| 99 | |
| 100 | int32_t nbFreeWorkers = ConfigManager::getSingleton().getSpellConfigInt32("SummonWorkerNbFree"); |
| 101 | int32_t nbWorkers = player->getSeat()->getNumCreaturesWorkers(); |
| 102 | int32_t pricePerWorker = ConfigManager::getSingleton().getSpellConfigInt32("SummonWorkerBasePrice"); |
| 103 | if(nbWorkers > nbFreeWorkers) |
| 104 | pricePerWorker *= std::pow(2, nbWorkers - nbFreeWorkers); |
| 105 | |
| 106 | int32_t priceTotal = 0; |
| 107 | |
| 108 | std::vector<Tile*> tiles; |
| 109 | for(GameEntity* target : targets) |
| 110 | { |
| 111 | if(target->getObjectType() != GameEntityType::tile) |
| 112 | { |
| 113 | static bool logMsg = false; |
| 114 | if(!logMsg) |
| 115 | { |
| 116 | logMsg = true; |
| 117 | OD_LOG_ERR("Wrong target name=" + target->getName() + ", type=" + Helper::toString(static_cast<int32_t>(target->getObjectType()))); |
| 118 | } |
| 119 | continue; |
| 120 | } |
| 121 | |
| 122 | Tile* tile = static_cast<Tile*>(target); |
| 123 | ++nbWorkers; |
| 124 | if(nbWorkers <= nbFreeWorkers) |
| 125 | { |
| 126 | tiles.push_back(tile); |
| 127 | continue; |
| 128 | } |
| 129 | |
| 130 | int32_t newPrice = priceTotal + pricePerWorker; |
| 131 | if(newPrice > playerMana) |
nothing calls this directly
no test coverage detected