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

Method checkSpellCast

source/spells/SpellCreatureDefense.cpp:76–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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