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

Method doUpkeep

source/rooms/RoomArena.cpp:170–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170void RoomArena::doUpkeep()
171{
172 Room::doUpkeep();
173
174 if(mCoveredTiles.empty())
175 return;
176
177 // Check if a creature is ko. We fill a vector with creatures to stop using
178 // the arena because we don't want to make them stop while iterating mCreaturesFighting
179 // as it would invalidate the iterator
180 std::vector<Creature*> creatures;
181 for(Creature* creature : mCreaturesFighting)
182 {
183 if(!creature->isKo())
184 continue;
185
186 creatures.push_back(creature);
187 }
188
189 for(Creature* creature : creatures)
190 creature->clearActionQueue();
191
192 // If less than 2 creatures, nothing to do
193 if(mCreaturesFighting.size() < 2)
194 return;
195
196 // Each creature not already fighting should look for the closest one and fight it
197 for(Creature* creature : mCreaturesFighting)
198 {
199 if(creature->isActionInList(CreatureActionType::fightFriendly))
200 continue;
201
202 Tile* tileCreature = creature->getPositionTile();
203 if(tileCreature == nullptr)
204 {
205 OD_LOG_ERR("room=" + getName() + ", creatureName=" + creature->getName() + ", position=" + Helper::toString(creature->getPosition()));
206 continue;
207 }
208
209 double closestDist = 0;
210 Creature* closestOpponent = nullptr;
211 for(Creature* opponent : mCreaturesFighting)
212 {
213 if(opponent == creature)
214 continue;
215
216 Tile* tileOpponent = opponent->getPositionTile();
217 if(tileOpponent == nullptr)
218 {
219 OD_LOG_ERR("room=" + getName() + ", creatureName=" + opponent->getName() + ", position=" + Helper::toString(opponent->getPosition()));
220 continue;
221 }
222
223 double dist = Pathfinding::squaredDistanceTile(*tileCreature, *tileOpponent);
224 if((closestOpponent != nullptr) && (dist >= closestDist))
225 continue;
226
227 closestDist = dist;

Callers

nothing calls this directly

Calls 7

squaredDistanceTileFunction · 0.85
isKoMethod · 0.80
clearActionQueueMethod · 0.80
isActionInListMethod · 0.80
getPositionTileMethod · 0.80
pushActionMethod · 0.80
toStringFunction · 0.50

Tested by

no test coverage detected