MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / update

Method update

game/state/city/city.cpp:231–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229}
230
231void City::update(GameState &state, unsigned int ticks)
232{
233 /* FIXME: Temporary 'get something working' HACK
234 * Every now and then give a landed vehicle a new 'goto random building' mission, so there's
235 * some activity in the city*/
236 std::uniform_int_distribution<int> bld_distribution(0, (int)this->buildings.size() - 1);
237
238 // Need to use a 'safe' iterator method (IE keep the next it before calling ->update)
239 // as update() calls can erase it's object from the lists
240
241 for (auto it = this->projectiles.begin(); it != this->projectiles.end();)
242 {
243 auto p = *it++;
244 // Projectile can die here
245 p->update(state, ticks);
246 }
247 // Since projectiles can kill projectiles just kill everyone in the end
248 std::set<std::tuple<sp<Projectile>, bool, bool>> deadProjectiles;
249 for (auto &p : projectiles)
250 {
251 auto c = p->checkProjectileCollision(*map);
252 if (c)
253 {
254 bool displayDoodad = true;
255 bool playSound = true;
256 switch (c.obj->getType())
257 {
258 case TileObject::Type::Vehicle:
259 {
260 auto vehicle = std::static_pointer_cast<TileObjectVehicle>(c.obj)->getVehicle();
261 displayDoodad = !vehicle->handleCollision(state, c, playSound);
262 break;
263 }
264 case TileObject::Type::Scenery:
265 {
266 auto sceneryTile = std::static_pointer_cast<TileObjectScenery>(c.obj);
267 displayDoodad = !sceneryTile->getOwner()->handleCollision(state, c);
268 playSound = displayDoodad;
269 break;
270 }
271 case TileObject::Type::Projectile:
272 {
273 deadProjectiles.emplace(
274 std::static_pointer_cast<TileObjectProjectile>(c.obj)->getProjectile(),
275 true, true);
276 break;
277 }
278 default:
279 LogError("Collision with non-collidable object");
280 }
281 deadProjectiles.emplace(c.projectile->shared_from_this(), displayDoodad, playSound);
282 }
283 }
284 // Kill projectiles that collided
285 for (auto &p : deadProjectiles)
286 {
287 std::get<0>(p)->die(state, std::get<1>(p), std::get<2>(p));
288 }

Callers

nothing calls this directly

Calls 10

endMethod · 0.80
getVehicleMethod · 0.80
getProjectileMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
getTypeMethod · 0.45
handleCollisionMethod · 0.45
getOwnerMethod · 0.45
dieMethod · 0.45

Tested by

no test coverage detected