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

Method update

game/state/city/vehicle.cpp:363–578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361 }
362
363 void update(GameState &state, unsigned int ticks) override
364 {
365 if (vehicle.falling)
366 {
367 updateFalling(state, ticks);
368 return;
369 }
370 if (vehicle.sliding)
371 {
372 updateSliding(state, ticks);
373 return;
374 }
375 if (vehicle.carriedByVehicle)
376 {
377 auto newPos = vehicle.carriedByVehicle->position;
378 newPos.z = std::max(0.0f, newPos.z - 0.5f);
379 vehicle.setPosition(newPos);
380 vehicle.facing = vehicle.carriedByVehicle->facing;
381 vehicle.updateSprite(state);
382 return;
383 }
384 if (vehicle.crashed)
385 {
386 if (vehicle.smokeDoodad)
387 {
388 vehicle.smokeDoodad->update(state, ticks);
389 }
390 if (vehicle.type->type != VehicleType::Type::UFO)
391 {
392 updateCrashed(state, ticks);
393 return;
394 }
395 }
396 auto ticksToTurn = ticks;
397 auto ticksToMove = ticks;
398
399 unsigned lastTicksToTurn = 0;
400 unsigned lastTicksToMove = 0;
401
402 // This is amount of ticks (on average) per 1 tile travelled
403 // a units travels 4 speed per second in tiles, where 4 is ticks_per_sec/tick_scale
404 // so this = ticks_per_sec / (speed * ticks_per_sec / tick_scale / city_scale )
405 // which simplifies to 1 / (speed / tick_scale / city_scale)
406 // or to tick_scale * city_scale / speed
407 int ticksPerTile = TICK_SCALE * VELOCITY_SCALE_CITY.x / vehicle.getSpeed();
408
409 // Flag whether we need to update banking and direction
410 bool updateSprite = false;
411 // Move until we become idle or run out of ticks
412 while (ticksToMove != lastTicksToMove || ticksToTurn != lastTicksToTurn)
413 {
414 lastTicksToMove = ticksToMove;
415 lastTicksToTurn = ticksToTurn;
416
417 // We may have left the map and need to cease to move
418 auto vehicleTile = this->vehicle.tileObject;
419 if (!vehicleTile)
420 {

Callers

nothing calls this directly

Calls 9

xyToFacingFunction · 0.85
facingDistanceFunction · 0.85
updateSpriteMethod · 0.80
getAngularSpeedMethod · 0.80
setPositionMethod · 0.45
updateMethod · 0.45
getSpeedMethod · 0.45
popFinishedMissionsMethod · 0.45
getNewGoalMethod · 0.45

Tested by

no test coverage detected