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

Method useRoom

source/rooms/RoomHatchery.cpp:183–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183bool RoomHatchery::useRoom(Creature& creature, bool forced)
184{
185 // Check if the creature needs to eat
186 if(!creature.needsToEat(forced))
187 {
188 creature.popAction();
189 return true;
190 }
191
192 // We look for the closest chicken (if any). We consider chickens
193 // on the hatchery only
194 // Because TilesWithinSightRadius are sorted by distance, we use them rather
195 // than covered tiles.
196 ChickenEntity* chickenClosest = nullptr;
197 for(Tile* tile : creature.getTilesWithinSightRadius())
198 {
199 if(tile->getCoveringRoom() != this)
200 continue;
201
202 std::vector<GameEntity*> chickens;
203 tile->fillWithEntities(chickens, SelectionEntityWanted::chicken, getSeat()->getPlayer());
204 if(chickens.empty())
205 continue;
206
207 for(GameEntity* chickenEnt : chickens)
208 {
209 ChickenEntity* chicken = static_cast<ChickenEntity*>(chickenEnt);
210 if(chicken->getLockEat(creature))
211 continue;
212
213 chickenClosest = chicken;
214 break;
215 }
216 if(chickenClosest != nullptr)
217 break;
218 }
219
220 // If we cannot find any available chicken, nothing to do
221 if(chickenClosest == nullptr)
222 return false;
223
224 creature.pushAction(Utils::make_unique<CreatureActionEatChicken>(creature, *chickenClosest));
225 return true;
226}
227
228void RoomHatchery::handleCreatureUsingAbsorbedRoom(Creature& creature)
229{

Callers

nothing calls this directly

Calls 7

needsToEatMethod · 0.80
popActionMethod · 0.80
getCoveringRoomMethod · 0.80
fillWithEntitiesMethod · 0.80
getLockEatMethod · 0.80
pushActionMethod · 0.80
getPlayerMethod · 0.45

Tested by

no test coverage detected