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

Method computeDestination

source/entities/MissileObject.cpp:204–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204bool MissileObject::computeDestination(const Ogre::Vector3& position, double moveDist, const Ogre::Vector3& direction,
205 Ogre::Vector3& destination, std::list<Tile*>& tiles)
206{
207 destination = position + (moveDist * direction);
208 tiles = getGameMap()->tilesBetween(Helper::round(position.x),
209 Helper::round(position.y), Helper::round(destination.x), Helper::round(destination.y));
210 if(tiles.empty())
211 {
212 OD_LOG_ERR("missile=" + getName() + " has unexpected empty tiles destination");
213 return false;
214 }
215
216 // If we get out of the map, we take the last tile as the destination
217 if((direction.x > 0.0 && destination.x > static_cast<Ogre::Real>(getGameMap()->getMapSizeX() - 1)) ||
218 (direction.x < 0.0 && destination.x < 0.0) ||
219 (direction.y > 0 && destination.y > static_cast<Ogre::Real>(getGameMap()->getMapSizeY() - 1)) ||
220 (direction.y < 0 && destination.y < 0))
221 {
222 Tile* lastTile = tiles.back();
223 destination.x = static_cast<Ogre::Real>(lastTile->getX());
224 destination.y = static_cast<Ogre::Real>(lastTile->getY());
225
226 // We are in the last position, we can die
227 if(tiles.size() <= 1)
228 return false;
229 }
230
231 return true;
232}
233
234bool MissileObject::notifyDead(GameEntity* entity)
235{

Callers

nothing calls this directly

Calls 6

roundFunction · 0.85
tilesBetweenMethod · 0.80
getMapSizeXMethod · 0.80
getMapSizeYMethod · 0.80
getXMethod · 0.45
getYMethod · 0.45

Tested by

no test coverage detected