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): a tank backs up only while that is the quicker way

Olcay Seygan363174bf79d5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc83933f1..320557829 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -243,7 +243,7 @@ found and fixed — EA's own, not port damage.**
- A Crusader used to reach top speed in a thirtieth of a second, on its very first frame moving twice as fast as it ever could again, and stopped dead the frame it was told to. Every tank, car and bike now picks up speed over about a second and brakes over most of one: told to stop at full speed, a Crusader rolls 12 more units and a Technical 26, where both used to halt on the spot. A vehicle sees the end of its move coming and is already braking for it.
- Vehicles slow down for a corner they can see coming. EA cut a tank to 60% of its speed on every frame near a turn in its route and threw it back to full speed in between, so a column on a winding road lurched along in a sawtooth. Now a vehicle brakes before a bend by as much as the bend needs, turns through it on the move and speeds up out of it. A tank still stops and swings round on the spot for anything sharper than a right angle, at half the rate it used to; an Overlord sent straight behind itself comes all the way round in about 2.4 seconds.
-- Sent a short way behind itself, a tank backs up. It used to spin round on the spot and drive off nose first every time. Anything sent within three lengths behind it now reverses at a bit under half speed, and so does a car that has a reverse gear. A Humvee sent a long way behind does a three-point turn instead of pirouetting in its own length. Cars used to reverse at full speed; they now back up at 45% of it.
+- Sent a short way behind itself, a tank backs up. It used to spin round on the spot and drive off nose first every time. A tank reverses at a bit under half speed, and only as far as backing up is still the quicker way there: about 40 units for a Crusader with the spot dead behind it. It used to back up for three of its lengths, and players noticed the crawl. A Crusader sent 70 behind itself spent 5.6 seconds reversing there and now turns round and arrives in 4.2. A car that has a reverse gear backs up to anything within three lengths behind it. A Humvee sent a long way behind does a three-point turn instead of pirouetting in its own length. Cars used to reverse at full speed; they now back up at 45% of it.
- A car turns no tighter than a car can. EA turned a Quad Cannon round in less than its own length about its rear axle, so its middle swung sideways at twice the speed it drove. A car's turn is held to a circle one and a half lengths across at speed, and only when that circle cannot reach the spot it was sent to does it crawl round a tight one instead, so it still gets everywhere it used to. Without a reverse gear that costs time: a Quad Cannon sent 50 behind itself takes 4.8 seconds where it took 2.2.
- A vehicle that had just parked used to start its next move with a lurch, and arrived crabbing sideways into its spot. Both are gone.
- Players told us the tanks felt sluggish off the line, and they were right. Every vehicle you can build, on all three sides and in all nine generals' armies, now pulls away and brakes a quarter harder than it did. A Crusader is at full speed 1.17 seconds after the order instead of 1.37, an Overlord after 1.27 instead of 1.5, and a Humvee sent across a short stretch of ground arrives an eighth of a second sooner. Top speeds are unchanged, and soldiers, aircraft and boats are untouched. Replays recorded before this change will not play back.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index 37ef95c6e..0f477fc58 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -71,7 +71,7 @@ static const Real VEHICLE_STOP_SECONDS = 0.8f; // no vehicle takes longer tha
static const Real VEHICLE_YAW_EASE_FRAMES = ConvertRetailFrames(6.0f); // frames for a turn to wind up to TurnRate, or back down from it
static const Real VEHICLE_STILL_SHARE = 0.1f; // below this share of top speed a vehicle may choose to go forward or back
static const Real VEHICLE_REVERSE_SHARE = 0.45f; // share of top speed a vehicle backs up at
-static const Real VEHICLE_REVERSE_BODY_LENGTHS = 3.0f; // a goal behind and closer than this along the route is backed up to
+static const Real VEHICLE_REVERSE_BODY_LENGTHS = 3.0f; // a car backs straight up to a goal behind and closer than this along the route; a tank times it
static const Real VEHICLE_REVERSE_COS = -0.34f; // cos 110 degrees: behind, for that
static const Real VEHICLE_BEND_COS = 0.985f; // cos 10 degrees: a gentler bend is driven at full speed
static const Real VEHICLE_MIN_SLIDE = ConvertRetailPerFrameRate(0.08f); // the slide onto the goal in the last cell moves at least this far a frame
@@ -1993,6 +1993,18 @@ void Locomotor::moveTowardsPositionVehicle(Object* obj, PhysicsBehavior *physics
{
Bool behind = (treads || m_template->m_canMoveBackward) && goalCos < VEHICLE_REVERSE_COS;
Bool close = onPathDistToGoal < VEHICLE_REVERSE_BODY_LENGTHS * bodyLength;
+ if (treads)
+ {
+ /* A tank backs up only while that is the quicker way there: the trip at VEHICLE_REVERSE_SHARE of
+ its speed against pivoting round to the goal at TREAD_PIVOT_SHARE of its TurnRate and driving
+ it at full speed. Three body lengths backed a Crusader up as far as 90 units: sent 70 behind
+ itself it took 5.6 seconds backing and takes 4.2 turning round. It still backs up to about
+ 40 with the goal dead behind and 24 at 110 degrees. Multiplied out, so a TurnRate of 0
+ reverses rather than divides by it. */
+ Real turnAround = ATan2(fabs(goalSin), goalCos);
+ close = onPathDistToGoal * (1.0f - VEHICLE_REVERSE_SHARE) * TREAD_PIVOT_SHARE * turnRate
+ < turnAround * VEHICLE_REVERSE_SHARE * maxSpeed;
+ }
setFlag(MOVING_BACKWARDS, behind && (close || !treads));
setFlag(DOING_THREE_POINT_TURN, behind && !close && !treads);
}