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

Method checkSpellCast

source/spells/SpellCreatureStrength.cpp:75–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75void 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;

Callers

nothing calls this directly

Calls 13

squaredDistanceFunction · 0.85
getLocalPlayerMethod · 0.80
getSpellConfigInt32Method · 0.80
getManaMethod · 0.80
fillWithEntitiesMethod · 0.80
toStringFunction · 0.50
getSeatMethod · 0.45
displayTextMethod · 0.45
selectSquaredTilesMethod · 0.45
getTileMethod · 0.45
getObjectTypeMethod · 0.45
unselectAllTilesMethod · 0.45

Tested by

no test coverage detected