bool Emigrant::_checkNearestHouse() { city::Helper helper( _city() ); for( int k=1; k < 3; k++ ) { TilePos offset( k, k ); HouseList houses = helper.find<House>( building::house, pos()-offset, pos() + offset ); std::map< int, HousePtr > vacantRoomPriority; foreach( it, houses ) { HousePtr house = *it; unsigned int freeRoom = house->maxHabitants() - house->habitants().count(); vacantRoomPriority[ 1000 - freeRoom ] = house; } foreach( it, vacantRoomPriority ) //have destination { HousePtr house = it->second; int freeRoom = house->maxHabitants() - house->habitants().count(); if( freeRoom > 0 ) { Pathway pathway = PathwayHelper::create( pos(), house->pos(), makeDelegate( _d.data(), &Impl::mayWalk ) ); _updatePathway( pathway ); go(); return true; } }
void Emigrant::_append2house( HousePtr house ) { int freeRoom = house->maxHabitants() - house->habitants().count(); if( freeRoom > 0 ) { house->addHabitants( _d->peoples ); _lockHouse( HousePtr() ); } }