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

Method updateMovementFalling

game/state/battle/battleunit.cpp:2704–2868  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2702}
2703
2704void BattleUnit::updateMovementFalling(GameState &state, unsigned int &moveTicksRemaining, bool &)
2705{
2706 // Falling consumes remaining move ticks
2707 auto fallTicksRemaining = moveTicksRemaining / (agent->modified_stats.getMovementSpeed() *
2708 BASE_MOVETICKS_CONSUMPTION_RATE);
2709 moveTicksRemaining = 0;
2710
2711 if (collisionIgnoredTicks > 0)
2712 {
2713 if (collisionIgnoredTicks > fallTicksRemaining)
2714 {
2715 collisionIgnoredTicks -= fallTicksRemaining;
2716 }
2717 else
2718 {
2719 collisionIgnoredTicks = 0;
2720 }
2721 }
2722
2723 auto previousPosition = position;
2724 auto newPosition = position;
2725
2726 while (fallTicksRemaining-- > 0)
2727 {
2728 velocity.z -= FALLING_ACCELERATION_UNIT;
2729 newPosition += this->velocity / (float)TICK_SCALE / VELOCITY_SCALE_BATTLE;
2730 }
2731
2732 // Check if new position is valid
2733 auto c = (collisionIgnoredTicks > 0 || isConscious())
2734 ? Collision()
2735 : tileObject->map.findCollision(previousPosition, newPosition, {}, tileObject);
2736 if (c)
2737 {
2738 // If colliding with anything but ground, bounce back once
2739 switch (c.obj->getType())
2740 {
2741 case TileObject::Type::Unit:
2742 case TileObject::Type::LeftWall:
2743 case TileObject::Type::RightWall:
2744 case TileObject::Type::Feature:
2745 if (!bounced)
2746 {
2747 if (velocity.x != 0.0f || velocity.y != 0.0f)
2748 {
2749 // If bounced do not try to find support this time
2750 bounced = true;
2751 newPosition = previousPosition;
2752 velocity.x = -velocity.x / 4;
2753 velocity.y = -velocity.y / 4;
2754 velocity.z = std::abs(velocity.z / 4);
2755 }
2756 else
2757 {
2758 bounced = true;
2759 }
2760 break;
2761 }

Callers

nothing calls this directly

Calls 9

getMovementSpeedMethod · 0.80
findCollisionMethod · 0.80
getUnitIfPresentMethod · 0.80
getTileMethod · 0.80
getUnitMethod · 0.80
getRestingPositionMethod · 0.80
getOwningTileMethod · 0.80
CollisionClass · 0.70
getTypeMethod · 0.45

Tested by

no test coverage detected