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

Method addCreatureUsingRoom

source/rooms/RoomLibrary.cpp:226–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226bool RoomLibrary::addCreatureUsingRoom(Creature* creature)
227{
228 if(!Room::addCreatureUsingRoom(creature))
229 return false;
230
231 int index = Random::Int(0, mUnusedSpots.size() - 1);
232 Tile* tileSpot = mUnusedSpots[index];
233 mUnusedSpots.erase(mUnusedSpots.begin() + index);
234 mCreaturesSpots[creature] = tileSpot;
235 const Ogre::Vector3& creaturePosition = creature->getPosition();
236 Ogre::Real wantedX = -1;
237 Ogre::Real wantedY = -1;
238 getCreatureWantedPos(creature, tileSpot, wantedX, wantedY);
239 if(creaturePosition.x != wantedX ||
240 creaturePosition.y != wantedY)
241 {
242 // We move to the good tile
243 std::list<Tile*> pathToSpot = getGameMap()->path(creature, tileSpot);
244 if(pathToSpot.empty())
245 {
246 OD_LOG_ERR("unexpected empty pathToSpot");
247 return true;
248 }
249
250 std::vector<Ogre::Vector3> path;
251 Creature::tileToVector3(pathToSpot, path, true, 0.0);
252 // We add the last step to take account of the offset
253 Ogre::Vector3 dest(wantedX, wantedY, 0.0);
254 path.push_back(dest);
255 creature->setWalkPath(EntityAnimation::walk_anim, EntityAnimation::idle_anim, true, true, path);
256 }
257
258 return true;
259}
260
261void RoomLibrary::removeCreatureUsingRoom(Creature* c)
262{

Callers

nothing calls this directly

Calls 3

IntFunction · 0.85
pathMethod · 0.80
setWalkPathMethod · 0.80

Tested by

no test coverage detected