| 181 | } |
| 182 | |
| 183 | bool 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 | |
| 228 | void RoomHatchery::handleCreatureUsingAbsorbedRoom(Creature& creature) |
| 229 | { |
nothing calls this directly
no test coverage detected