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

Method getLocationForBed

source/rooms/RoomDormitory.cpp:299–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297}
298
299Tile* RoomDormitory::getLocationForBed(Creature* creature)
300{
301 int bedDim1 = creature->getDefinition()->getBedDim1();
302 int bedDim2 = creature->getDefinition()->getBedDim2();
303 if((bedDim1 <= 0) || (bedDim2 <= 0))
304 {
305 OD_LOG_ERR("creature=" + creature->getName() + " wrong bed size bedDim1=" + Helper::toString(bedDim1) + ", bedDim2=" + Helper::toString(bedDim2));
306 return nullptr;
307 }
308
309 for(int i = 0; i < 2; ++i)
310 {
311 int xDim;
312 int yDim;
313 // We try the default size and with a rotation
314 if(i == 0)
315 {
316 xDim = bedDim1;
317 yDim = bedDim2;
318 }
319 else
320 {
321 xDim = bedDim2;
322 yDim = bedDim1;
323 }
324
325 // Check to see if there is even enough space available for the bed.
326 std::vector<Tile*> tempVector = getOpenTiles();
327 unsigned int area = xDim * yDim;
328 if (tempVector.size() < area)
329 return nullptr;
330
331 // Randomly shuffle the open tiles in tempVector so that the dormitory are filled up in a random order.
332 std::random_shuffle(tempVector.begin(), tempVector.end());
333
334 // Loop over each of the open tiles in tempVector and for each one, check to see if it
335 for (unsigned int i = 0; i < tempVector.size(); ++i)
336 {
337 if (tileCanAcceptBed(tempVector[i], xDim, yDim, getOpenTiles()))
338 return tempVector[i];
339 }
340 }
341
342 // We got to the end of the open tile list without finding an open tile for the bed so return nullptr to indicate failure.
343 return nullptr;
344}
345
346const Ogre::Vector3& RoomDormitory::getSleepDirection(Creature* creature) const
347{

Callers 1

handleFindHomeMethod · 0.80

Calls 4

getBedDim1Method · 0.80
getDefinitionMethod · 0.80
getBedDim2Method · 0.80
toStringFunction · 0.50

Tested by

no test coverage detected