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.

feat(gameengine): infantry turn, brake and attack-move on their feet

Olcay Seygane30331cd0932
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f1336af05..3129ddb6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -47,6 +47,12 @@ found and fixed — EA's own, not port damage.**
- 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.
- Groups get where they are going as fast as before. Twenty Crusaders crossing a generated map arrived on average within 3% of the old time over eight maps, and the last of them a fifth of a second later. A replay recorded before this change plays back differently.
+## Soldiers turn and stop on their feet
+
+- Send a running Ranger back the way he came and he used to slide backwards past his own nose for a sixth of a second while he swung round. Now his feet carry him round with the turn, and past a right angle he plants them and pivots. On a gentle bend he barely slows: through 30 degrees a Ranger keeps 85% of his pace where he used to drop to 68%, and a 90 degree corner costs him half the time it did.
+- A soldier told to stop takes three short steps to a halt instead of freezing mid-stride, about one more step of ground. Arriving at the end of a move looks the same way. He still starts walking as quickly after the click as he always did.
+- Infantry on attack move look before they step. A Ranger used to walk three paces toward the move point, stop and turn on an enemy that had been in plain sight, and a Red Guard came at it from the side and pivoted on the spot before he fired. Both now walk straight at the enemy and arrive facing it. A replay recorded before this change plays back differently.
+
## Tanks shoot on the move
- A turret that picked its own target on the move fired once and then let go of it until its next look round, two seconds later for most units. A Technical driving past four Troop Crawlers hit them twice. It now hits every 6 frames, 11 times, as fast as it fires standing still. On the same drive a Quad Cannon went from 28 hits to 53 and a Gattling Tank from 28 to 50, and an Overlord's second shell comes 10 frames after its first instead of 38.
diff --git a/GeneralsMD/Code/Data/Scenarios/infantrywalk.txt b/GeneralsMD/Code/Data/Scenarios/infantrywalk.txt
index 24c3724d1..f7e4169c3 100644
--- a/GeneralsMD/Code/Data/Scenarios/infantrywalk.txt
+++ b/GeneralsMD/Code/Data/Scenarios/infantrywalk.txt
@@ -53,6 +53,34 @@
# walks a diagonal 33 degrees off the Hacker's bearing, stops 110 short from its full 0.83 in one
# frame and pivots the 33 degrees in 2 frames on the spot before it fires. The Rebel repeats the Ranger. The Pathfinder pivots 4 frames on
# the spot, kills the Hacker from where it stands and walks on without stopping again.
+#
+# After the infantry drive (Locomotor::moveTowardsPositionLegs, brakeLegs) and the attack-move scan
+# on the first frame for infantry. Same command line, same twelve ids, every run on CRC 0x434F4651.
+# Before is the same script over the logs above, so where it reads a frame differently from the
+# table above it does so on both sides.
+#
+# Ranger Red Guard Pathfinder squad (8)
+# order to first step 2 / 2 2 / 2 2 / 2 2-4 / 2-4
+# order to top speed 7 / 7 9 / 9 10 / 10 7-9 / 7-9
+# frames lost 30 deg 0.7 / 0.3 0.8 / 0.2 0.6 / 0.2 0.4-0.8 / 0.2-0.5
+# 60 deg 2.3 / 1.0 2.7 / 1.0 2.2 / 1.0 1.9-2.4 / 0.9-1.0
+# 90 deg 4.4 / 2.1 5.4 / 2.2 4.9 / 2.4 2.8-4.9 / 1.7-2.3
+# 132 deg 6.4 / 5.1 7.5 / 5.7 8.5 / 6.3 6.1-7.0 / 4.6-5.9
+# 175 deg 8.1 / 7.6 9.3 / 7.8 9.3 / 8.8 7.8-8.4 / 7.2-7.8
+# least forward speed, bends -0.135 / +0.012 -0.191 / +0.015 -0.259 / +0.018
+# stop order 1 frame, 0.67 / 3 frames 0.45 0.23 0, 1.33 long (Red Guard 1.67, Pathfinder 2.0)
+# arrival brake 0.56 0.02 0 / 0.45 0.22 0.01 0, 3 to 5 off the point both times
+#
+# Nobody skids backwards any more: his walk turns with his nose, and on a bend he keeps the cosine of
+# what is still to turn, so a 30 degree bend keeps him at 74 to 90% where it used to drop him to 65 to
+# 80%. Past a right angle he stops in three frames and turns on the spot, which is why the slowest
+# speed through a reverse reads 3% now. The turn winds up and down over two frames and still peaks at
+# 16.7 degrees a frame. Attack-move: no false start on any walker or squad member (five of the eight
+# took one before). The Ranger stands still 6 frames while the approach path comes, then walks
+# straight in and stops 112 from the Hacker on frame 76 facing it (frame 77, after the false start,
+# before); the Red Guard stops 109 short on frame 77 facing it, 0 degrees off where it was 18 and
+# pivoted, on frame 79. Squad at the +840 goal: last stop 100 frames after the order (116 before),
+# 9 to 42 from the point.
30 spawn 0 AirF_AmericaInfantryRanger 8 900 3500 15
60 move 0 AirF_AmericaInfantryRanger 1298 3498
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
index 244a68191..f902ee9c8 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
@@ -416,7 +416,9 @@ protected:
void maintainCurrentPositionThrust(Object* obj, PhysicsBehavior *physics);
void maintainCurrentPositionOther(Object* obj, PhysicsBehavior *physics);
- void maintainCurrentPositionLegs(Object* obj, PhysicsBehavior *physics) { maintainCurrentPositionOther(obj, physics); }
+ Bool maintainCurrentPositionLegs(Object* obj, PhysicsBehavior *physics);
+ Bool brakeLegs(Object* obj, PhysicsBehavior *physics);
+ Real getLegsStopDecel(const Object* obj) const;
void maintainCurrentPositionWheels(Object* obj, PhysicsBehavior *physics) { maintainCurrentPositionOther(obj, physics); }
void maintainCurrentPositionTreads(Object* obj, PhysicsBehavior *physics) { maintainCurrentPositionOther(obj, physics); }
void maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physics);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 72bc3fc31..7575956b2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -3702,6 +3702,10 @@ StateReturnType AIAttackMoveToState::onEnter()
m_frameToApproachOn = 0;
// spread the scans of a group that was all ordered on the same frame over the scan interval.
m_frameToScanOn = TheGameLogic->getFrame() + ((UnsignedInt)owner->getID() % ATTACK_MOVE_SCAN_RATE);
+ /* A soldier looks before he steps. Spread like the rest, a Ranger walked three steps towards the
+ move point, stopped and turned on an enemy that had been in sight from the start. */
+ if (owner->isKindOf(KINDOF_INFANTRY))
+ m_frameToScanOn = TheGameLogic->getFrame();
return AIMoveToState::onEnter();
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index 9b710a726..cf5c65188 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -81,6 +81,10 @@ static const Real VEHICLE_CORNER_GRIP = 0.5f; // share of its braking a car
static const Real WHEEL_MIN_RADIUS_BODY_LENGTHS = 1.5f; // a car turns no tighter than this, unless that arc cannot reach the goal
static const Real WHEEL_TIGHT_RADIUS_BODY_LENGTHS = 0.3f; // and then crawls round this, at its turn speed
+// Infantry on two legs (moveTowardsPositionLegs, maintainCurrentPositionLegs).
+static const Real INFANTRY_YAW_EASE_FRAMES = 2.0f; // frames for a turn on the move to wind up to TurnRate, or back down from it
+static const Real INFANTRY_STOP_FRAMES = 3.0f; // a soldier stops from top speed in this many frames, whatever its Braking
+
#define MAX_BRAKING_FACTOR 5.0f
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1077,6 +1081,9 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle)
brakeHelicopter(obj, physics);
m_yawRate = 0.0f; // this turn is rotateTowardsPosition's, which parking needs to stop dead on the heading
}
+ // a soldier turning to aim may still be walking off the end of his approach
+ if (m_template->m_appearance == LOCO_LEGS_TWO)
+ brakeLegs(obj, physics);
handleBehaviorZ(obj, physics, *obj->getPosition());
}
@@ -1110,7 +1117,7 @@ void Locomotor::setPhysicsOptions(Object* obj)
physics->setStickToGround(getStickToGround()); // walking guys aren't allowed to catch huge (or even small) air.
Bool helicopter = isHelicopter(obj);
physics->setMotiveSteersSideways(helicopter);
- if (!helicopter && !isGroundVehicle(obj))
+ if (!helicopter && !isGroundVehicle(obj) && m_template->m_appearance != LOCO_LEGS_TWO)
{
// landed, taxiing or dying: whatever it was pulling or swinging when it last flew or drove is over
m_yawRate = 0.0f;
@@ -2197,26 +2204,32 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c
}
Real relAngle = stdAngleDiff(desiredAngle, angle);
- locoUpdate_moveTowardsAngle(obj, desiredAngle);
-
- //
- // Modulate speed according to turning. The more we have to turn, the slower we go
- //
- const Real QUARTERPI = PI / 4.0f;
- Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI);
- if (angleCoeff > 1.0f)
- angleCoeff = 1.0;
+ if (fabs(goalPos.x - obj->getPosition()->x) < 0.1f && fabs(goalPos.y - obj->getPosition()->y) < 0.1f)
+ relAngle = 0.0f; // right on it the bearing is rounding noise
+
+ /* EA swung the nose at a flat TurnRate and left the walk on its old line, so a soldier sent back
+ the way he came skidded backwards past his own nose for five frames while it came round, and any
+ bend past 45 degrees took his speed to nothing. The turn now winds up and down over
+ INFANTRY_YAW_EASE_FRAMES, his feet carry the walk round with the nose, and his speed follows the
+ cosine of what is left to turn: nearly all of it on a gentle bend, none past a right angle, where
+ he stops in INFANTRY_STOP_FRAMES and turns on the spot. */
+ Real turnRate = getMaxTurnRate(obj->getBodyModule()->getDamageState());
+ turnVehicle(obj, physics, easeYaw(relAngle, turnRate, turnRate / INFANTRY_YAW_EASE_FRAMES));
- Real goalSpeed = (1.0f - angleCoeff) * desiredSpeed;
+ Real goalSpeed = desiredSpeed * Cos(relAngle);
+ if (goalSpeed < 0.0f)
+ goalSpeed = 0.0f;
- //Real slowDownDist = (actualSpeed - m_template->m_minSpeed) / getBraking();
- Real slowDownDist = calcSlowDownDist(actualSpeed, m_template->m_minSpeed, getBraking());
- if (onPathDistToGoal < slowDownDist && !getFlag(NO_SLOW_DOWN_AS_APPROACHING_DEST))
+ // the fastest he can still stop from before the end of the route
+ Real stopDecel = getLegsStopDecel(obj);
+ if (!getFlag(NO_SLOW_DOWN_AS_APPROACHING_DEST))
{
- goalSpeed = m_template->m_minSpeed;
+ Real stopSpeed = sqrt(2.0f * stopDecel * onPathDistToGoal);
+ if (goalSpeed > stopSpeed)
+ goalSpeed = stopSpeed;
}
-
-
+ if (goalSpeed < m_template->m_minSpeed)
+ goalSpeed = m_template->m_minSpeed;
//
// Maintain goal speed
@@ -2225,7 +2238,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c
if (speedDelta != 0.0f)
{
Real mass = physics->getMass();
- Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking();
+ Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -stopDecel;
Real accelForce = mass * acceleration;
/*
@@ -3297,12 +3310,8 @@ Bool Locomotor::locoUpdate_maintainCurrentPosition(Object* obj)
requiresConstantCalling = TRUE;
break;
case LOCO_LEGS_TWO:
- maintainCurrentPositionLegs(obj, physics);
- requiresConstantCalling = FALSE;
- break;
case LOCO_CLIMBER:
- maintainCurrentPositionLegs(obj, physics);
- requiresConstantCalling = FALSE;
+ requiresConstantCalling = maintainCurrentPositionLegs(obj, physics);
break;
case LOCO_WHEELS_FOUR:
case LOCO_MOTORCYCLE:
@@ -3451,6 +3460,41 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi
}
+//-------------------------------------------------------------------------------------------------
+/// a soldier with nowhere to go comes to a stop; TRUE while he still moves
+Bool Locomotor::maintainCurrentPositionLegs(Object* obj, PhysicsBehavior *physics)
+{
+ physics->setTurning(TURN_NONE);
+ return brakeLegs(obj, physics);
+}
+
+//-------------------------------------------------------------------------------------------------
+/**
+ Take a soldier's walk off at getLegsStopDecel a frame, along whatever line it is on; TRUE while
+ some is left. EA zeroed it on the frame of a stop order or an arrival, and the man stood dead
+ still in mid-stride.
+*/
+Bool Locomotor::brakeLegs(Object* obj, PhysicsBehavior *physics)
+{
+ m_yawRate = 0.0f; // a turn from here is rotateTowardsPosition's
+ if (!physics->isMotive()) // no need to stop something that isn't moving
+ return FALSE;
+ const Coord3D *vel = physics->getVelocity();
+ Real speed = sqrt(vel->x*vel->x + vel->y*vel->y) - getLegsStopDecel(obj);
+ physics->scrubVelocity2D(speed > 0.0f ? speed : 0.0f);
+ return speed > 0.0f;
+}
+
+//-------------------------------------------------------------------------------------------------
+/// the hardest a soldier brakes: his Braking, or whatever stops him from top speed in INFANTRY_STOP_FRAMES
+Real Locomotor::getLegsStopDecel(const Object* obj) const
+{
+ Real decel = getMaxSpeedForCondition(obj->getBodyModule()->getDamageState()) / INFANTRY_STOP_FRAMES;
+ if (decel < getBraking())
+ decel = getBraking();
+ return decel;
+}
+
//-------------------------------------------------------------------------------------------------
void Locomotor::maintainCurrentPositionOther(Object* obj, PhysicsBehavior *physics)
{