Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameengine): helicopters turn into a long flight while they fly it

Olcay Seygan88a5f763c559
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 718bbd656..959fcb021 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,7 +42,7 @@ found and fixed — EA's own, not port damage.**
- Every helicopter in the game, on every side and for every general, used to drive like a tank with rotors. Told to go somewhere behind it, a Comanche swung its nose all the way round on the spot and only then flew off nose first. Now it flies where it is sent, backwards or sideways, with its nose left where it was. Sent 300 behind itself, a Comanche turned 178 degrees before it went and was 30 out after a second and a half; now it goes tail first, never turns, and is 30 out after one second. On a long flight the nose comes round into the direction of travel while the helicopter is already on its way.
- A Comanche keeps its guns on what it is shooting at while it flies. Its cannon and missiles only fire straight ahead, so a Comanche ordered to move in the middle of a fight turned away from its target. It now holds its nose on the target and slides along beside it: one sent across in front of an Overlord it had been shooting stayed within a degree of the tank the whole way, where it used to point 84 degrees off on average. One flying past a supply truck 120 off its line now turns to it and shoots, where it used to fly straight by.
- A helicopter leans into the move. It dips its nose to speed up and lifts it to stop, rolls into a slide sideways and comes level again in a hover, never past about 12 degrees and never with a jerk: the lean moves by at most a degree and a half from one frame to the next.
-- Helicopters ease in and out of everything they do. Speed builds up over a moment instead of all at once, a stop flares out and settles on the exact spot it was sent to, and a turn winds up to full speed over a third of a second and winds down again before the nose arrives. Chinooks and Helixes fly the same way as the Comanche, and a gattling Helix keeps its gun on a tank while it slides past. A replay recorded before this change plays back differently.
+- Helicopters ease in and out of everything they do. Speed builds up over a moment instead of all at once, a stop flares out and settles on the exact spot it was sent to, and a turn winds up to full speed over a third of a second and winds down again before the nose arrives. Sent on a long flight behind itself, a helicopter sets off backwards at once and brings its nose round as it picks up speed; 30 out, the nose is still about 90 degrees off its course, where it used to have finished the whole turn before it got anywhere. Chinooks and Helixes fly the same way as the Comanche, and a gattling Helix keeps its gun on a tank while it slides past. A replay recorded before this change plays back differently.
## The frame rate cap is gone
diff --git a/GeneralsMD/Code/Data/Scenarios/helislide.txt b/GeneralsMD/Code/Data/Scenarios/helislide.txt
index 9d3290b61..4f616364b 100644
--- a/GeneralsMD/Code/Data/Scenarios/helislide.txt
+++ b/GeneralsMD/Code/Data/Scenarios/helislide.txt
@@ -22,6 +22,10 @@
# a frame at most, where it jumped by 3; it ends every leg with no overshoot. Its lean, replayed
# from the logged motion, tops out at 12.4 degrees and moves 1.3 a frame at most, where the first
# free-flight build hit 22.9 and moved 30 in a frame when it braked.
+#
+# On the westward flight the nose used to finish its 170 degree turn by the time the Comanche was
+# 30 out (34 frames). With the turn rate held down until the speed builds it is 85 degrees off the
+# course at that point and comes round by frame 55, while the travel itself is unchanged.
30 spawn 0 AmericaVehicleComanche 1 1100 3500
150 move 0 AmericaVehicleComanche 800 3500
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
index b2c3022c1..f5cf7fb5d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
@@ -392,7 +392,7 @@ protected:
void moveTowardsPositionHover(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed, const Coord3D *faceTarget);
void moveTowardsPositionHelicopter(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed, const Coord3D *faceTarget);
void brakeHelicopter(Object* obj, PhysicsBehavior *physics);
- PhysicsTurningType turnHelicopter(Object* obj, const Coord3D *toward);
+ PhysicsTurningType turnHelicopter(Object* obj, const Coord3D *toward, Real rateShare = 1.0f);
void steerHelicopter(Object* obj, PhysicsBehavior *physics, Real wantX, Real wantY);
Real getHelicopterStopDecel(BodyDamageType condition) const;
void moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index 4d8a9f1ee..55b4abe37 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -2103,6 +2103,7 @@ void Locomotor::moveTowardsPositionHelicopter(Object* obj, PhysicsBehavior *phys
const Real LONG_FLIGHT_SECONDS = 3.0f;
const Real LONG_FLIGHT_MIN_DIST = 400.0f; // so a slow Helix still slides a short hop instead of turning for it
const Real TOO_CLOSE_TO_AIM = 1.0f; // right over the target the bearing to it is noise
+ const Real LONG_FLIGHT_TURN_FROM_HOVER = 0.25f; // share of TurnRate a long flight's turn starts at from a hover
BodyDamageType bdt = obj->getBodyModule()->getDamageState();
Real maxSpeed = getMaxSpeedForCondition(bdt);
@@ -2110,7 +2111,10 @@ void Locomotor::moveTowardsPositionHelicopter(Object* obj, PhysicsBehavior *phys
desiredSpeed = maxSpeed;
const Coord3D *pos = obj->getPosition();
+ const Coord3D *vel = physics->getVelocity();
+ Real speed = sqrt(sqr(vel->x) + sqr(vel->y));
const Coord3D *noseToward = NULL;
+ Real rateShare = 1.0f;
if (faceTarget)
{
if (fabs(faceTarget->x - pos->x) > TOO_CLOSE_TO_AIM || fabs(faceTarget->y - pos->y) > TOO_CLOSE_TO_AIM)
@@ -2119,9 +2123,15 @@ void Locomotor::moveTowardsPositionHelicopter(Object* obj, PhysicsBehavior *phys
else if (onPathDistToGoal > maxSpeed * LOGICFRAMES_PER_SECOND * LONG_FLIGHT_SECONDS
&& onPathDistToGoal > LONG_FLIGHT_MIN_DIST)
{
+ /* Turning into the flight is no hurry: the nose comes round as the speed builds, at
+ LONG_FLIGHT_TURN_FROM_HOVER of TurnRate from a hover and all of it at full speed. At full
+ TurnRate a Comanche swings 180 degrees before it has gone 30, and the turn reads as done on
+ the spot. */
noseToward = &goalPos;
+ if (speed < maxSpeed)
+ rateShare = LONG_FLIGHT_TURN_FROM_HOVER + (1.0f - LONG_FLIGHT_TURN_FROM_HOVER) * speed / maxSpeed;
}
- physics->setTurning(turnHelicopter(obj, noseToward));
+ physics->setTurning(turnHelicopter(obj, noseToward, rateShare));
Real goalSpeed = desiredSpeed;
if (!getFlag(NO_SLOW_DOWN_AS_APPROACHING_DEST))
@@ -2131,8 +2141,6 @@ void Locomotor::moveTowardsPositionHelicopter(Object* obj, PhysicsBehavior *phys
the ease speed taken off, the braking fades out at the end. The distance is counted short
by the travel of the lead frames, the time the eased braking takes to build up, or the
helicopter overshoots a short hop. */
- const Coord3D *vel = physics->getVelocity();
- Real speed = sqrt(sqr(vel->x) + sqr(vel->y));
Real distLeft = onPathDistToGoal - speed * HELICOPTER_STOP_LEAD_FRAMES;
if (distLeft < 0.0f)
distLeft = 0.0f;
@@ -2215,12 +2223,14 @@ void Locomotor::brakeHelicopter(Object* obj, PhysicsBehavior *physics)
/**
Swing a helicopter's nose towards a point, or let the swing die away when toward is null. The
turn winds up to TurnRate over HELICOPTER_YAW_EASE_FRAMES and winds down again so it stops on the
- heading, where rotateTowardsPosition jumps straight to full rate and stops dead.
+ heading, where rotateTowardsPosition jumps straight to full rate and stops dead. rateShare takes
+ the top rate below TurnRate.
*/
-PhysicsTurningType Locomotor::turnHelicopter(Object* obj, const Coord3D *toward)
+PhysicsTurningType Locomotor::turnHelicopter(Object* obj, const Coord3D *toward, Real rateShare)
{
- Real maxRate = getMaxTurnRate(obj->getBodyModule()->getDamageState());
- Real yawAccel = maxRate / HELICOPTER_YAW_EASE_FRAMES;
+ Real turnRate = getMaxTurnRate(obj->getBodyModule()->getDamageState());
+ Real yawAccel = turnRate / HELICOPTER_YAW_EASE_FRAMES;
+ Real maxRate = turnRate * rateShare;
Real angle = obj->getOrientation();
Real wantRate = 0.0f;