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): helicopters fly in any direction and lean into it

Olcay Seygan3407a71e25e5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5ce21b364..d22df4589 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,12 @@ found and fixed — EA's own, not port damage.**
- A kill used to promote only the unit that fired the last shot. Two Crusaders could grind an Overlord down to a sliver and a passing Humvee's rocket took every point of it. Now the killing blow earns a quarter and the rest is shared out among everything that hurt the target in the last ten seconds, by how much of its health each one took off. A unit that died before the kill leaves its share to the killer. Healing counts too: an Emperor, or an Overlord or Helix with a Propaganda Tower, earns for every friendly unit it patches up, half of that unit's worth as a kill for a full repair and less for less. The kill on the scoreboard and your general's promotion points still go to the last shot. Replays recorded before this change play out differently.
+## Helicopters fly like helicopters
+
+- 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, holds a slight lean at cruising speed, and comes level again in a hover. A replay recorded before this change plays back differently.
+
## The frame rate cap is gone
- The picture now runs uncapped; the rules keep their own steady clock.
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 44efc1057..824b68922 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -43,6 +43,7 @@ Data/Scenarios/bridgecross.txt
Data/Scenarios/bridgelong.txt
Data/Scenarios/chokeprobe.txt
Data/Scenarios/crowdbattle.txt
+Data/Scenarios/helislide.txt
Data/Scenarios/inferno30.txt
Data/Scenarios/jetpass.txt
Data/Scenarios/leadinfantry.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/helislide.txt b/GeneralsMD/Code/Data/Scenarios/helislide.txt
new file mode 100644
index 000000000..4e326c476
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/helislide.txt
@@ -0,0 +1,35 @@
+# Three Comanches on open ground. The first is sent 300 behind itself, then 300 beside itself, then
+# on two long flights, east and back west. The second is sent past a supply truck that cannot shoot
+# back, 120 off its line and inside its guns' 200. The third is put on an Overlord, which cannot
+# shoot at aircraft, and a second later ordered across in front of it.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -maxframes 1800
+# -scenario helislide -logPrefix helislide_
+#
+# Measured 2026-10-03 with a temporary per-frame log of position, facing and velocity. Before
+# helicopters flew free, the first Comanche turned its nose through 178 degrees before it went
+# behind itself and was 30 out after 46 frames, and its velocity never strayed more than 36 degrees
+# off its nose. The second passed the truck with its nose 90 degrees off it on average and never
+# fired. The third pointed 84 degrees off the Overlord on average while it moved. After, the first
+# flies backwards (180 degrees off its nose) and sideways without turning, is 30 out after 30
+# frames, and turns its nose 165 degrees on the westward flight while already moving. The second
+# turns to the truck and takes 50 off it. The third stays within 0.9 degrees of the Overlord.
+
+30 spawn 0 AmericaVehicleComanche 1 1100 3500
+150 move 0 AmericaVehicleComanche 800 3500
+400 move 0 AmericaVehicleComanche 800 3800
+650 move 0 AmericaVehicleComanche 2500 3500
+1150 move 0 AmericaVehicleComanche 800 3500
+30 spawn 1 ChinaVehicleSupplyTruck 1 1300 4170
+30 spawn 0 AirF_AmericaVehicleComanche 1 800 4050
+150 move 0 AirF_AmericaVehicleComanche 1800 4050
+200 tally 1 ChinaVehicleSupplyTruck
+400 tally 1 ChinaVehicleSupplyTruck
+30 spawn 1 ChinaTankOverlord 1 1300 4600
+30 spawn 0 SupW_AmericaVehicleComanche 1 1180 4480
+90 attack 0 SupW_AmericaVehicleComanche 1 ChinaTankOverlord
+150 move 0 SupW_AmericaVehicleComanche 1420 4480
+150 tally 1 ChinaTankOverlord
+400 tally 1 ChinaTankOverlord
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
index 143772049..7a8218cee 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
@@ -230,8 +230,12 @@ public:
void setPhysicsOptions(Object* obj);
- void locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalPos,
- Real onPathDistToGoal, Real desiredSpeed, Bool *blocked);
+ /**
+ faceTarget, when not null, is where a helicopter keeps its nose while it flies to goalPos.
+ Every other locomotor ignores it.
+ */
+ void locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalPos,
+ Real onPathDistToGoal, Real desiredSpeed, Bool *blocked, const Coord3D *faceTarget = NULL);
void locoUpdate_moveTowardsAngle(Object* obj, Real angle);
/**
Kill any current (2D) velocity (but stay at current position, or as close as possible)
@@ -302,6 +306,13 @@ public:
Real calcMinTurnRadius(BodyDamageType condition, Real* timeToTravelThatDist) const;
+ /**
+ A live aircraft on a hovering air locomotor: Comanche, Chinook, Helix and every general's copy.
+ Its locomotor steers the whole 2D velocity, so it flies sideways and backwards and the nose
+ is free to point elsewhere. Drones and parachutes hover too, but are not KINDOF_AIRCRAFT.
+ */
+ Bool isHelicopter(const Object* obj) const;
+
/// this is handy for doing things like forcing helicopters to crash realistically: cut their lift.
inline void setMaxLift(Real lift) { m_maxLift = lift; }
inline void setMaxSpeed(Real speed)
@@ -378,7 +389,9 @@ protected:
void moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
void moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
void moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
- void moveTowardsPositionHover(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
+ 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);
void moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
void moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed);
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/PhysicsUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/PhysicsUpdate.h
index 5c20aa331..2044f8e02 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/PhysicsUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/PhysicsUpdate.h
@@ -192,6 +192,8 @@ public:
void setAllowBouncing(Bool allow) { setFlag(ALLOW_BOUNCE, allow); }
void setAllowCollideForce(Bool allow) { setFlag(ALLOW_COLLIDE_FORCE, allow); }
void setAllowAirborneFriction(Bool allow) { setFlag(APPLY_FRICTION2D_WHEN_AIRBORNE, allow); }
+ /// the locomotor steers the whole 2D velocity (a helicopter), so no sideways friction while it drives
+ void setMotiveSteersSideways(Bool steers) { setFlag(MOTIVE_STEERS_SIDEWAYS, steers); }
void setImmuneToFallingDamage(Bool allow) { setFlag(IMMUNE_TO_FALLING_DAMAGE, allow); }
void setStunned(Bool allow) { setFlag(IS_STUNNED, allow); }
@@ -268,6 +270,7 @@ private:
IS_IN_FREEFALL = 0x0200,
IS_IN_UPDATE = 0x0400,
IS_STUNNED = 0x0800,
+ MOTIVE_STEERS_SIDEWAYS = 0x1000,
};
/*
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index f93b992cd..ea2c84110 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -1736,19 +1736,58 @@ void Drawable::calcPhysicsXformHoverOrWings( const Locomotor *locomotor, Physics
m_locoInfo->m_pitch += m_locoInfo->m_pitchRate * UNIFORM_AXIAL_DAMPING;
m_locoInfo->m_roll += m_locoInfo->m_rollRate * UNIFORM_AXIAL_DAMPING;
- // process chassis acceleration dynamics - damp back towards zero
+ /* A helicopter tilts its rotor the way it wants to go: nose down to speed up, nose up to brake,
+ a roll into a push sideways, and a little lean held into the airflow while it cruises. The
+ lean is the point the acceleration spring below settles on, at the locomotor's PitchStiffness
+ and RollStiffness, so it comes level again in a hover. The velocity-roll factor its INI
+ carries was tuned for the small skid of a turn and would roll one flying sideways onto its
+ back, so a helicopter does not use it. */
+ const Bool helicopter = locomotor->isHelicopter(obj);
+ Real accelPitchLimit = ACCEL_PITCH_LIMIT;
+ Real decelPitchLimit = DECEL_PITCH_LIMIT;
+ Real pitchTarget = 0.0f;
+ Real rollTarget = 0.0f;
+ if (helicopter)
+ {
+ const Real LEAN_AT_FULL_ACCEL = 0.2f; // radians, at the locomotor's own Acceleration
+ const Real LEAN_AT_FULL_SPEED = 0.12f; // radians, held at the locomotor's own Speed
+ const Real MAX_LEAN = 0.4f;
+ if (accelPitchLimit == 0.0f)
+ accelPitchLimit = MAX_LEAN;
+ if (decelPitchLimit == 0.0f)
+ decelPitchLimit = MAX_LEAN;
+
+ if (physics->isMotive())
+ {
+ BodyDamageType bdt = obj->getBodyModule()->getDamageState();
+ Real maxAccel = locomotor->getMaxAcceleration(bdt);
+ Real maxSpeed = locomotor->getMaxSpeedForCondition(bdt);
+ Real accelScale = maxAccel > 0.0f ? LEAN_AT_FULL_ACCEL / maxAccel : 0.0f;
+ Real speedScale = maxSpeed > 0.0f ? LEAN_AT_FULL_SPEED / maxSpeed : 0.0f;
+
+ Real forwardVel = dir->x * vel->x + dir->y * vel->y;
+ Real lateralVel = -dir->y * vel->x + dir->x * vel->y;
+ Real forwardAccel = dir->x * accel->x + dir->y * accel->y;
+ Real lateralAccel = -dir->y * accel->x + dir->x * accel->y;
+
+ pitchTarget = forwardAccel * accelScale + forwardVel * speedScale;
+ rollTarget = lateralAccel * accelScale + lateralVel * speedScale;
+ }
+ }
- m_locoInfo->m_accelerationPitchRate += ((-PITCH_STIFFNESS * (m_locoInfo->m_accelerationPitch)) + (-PITCH_DAMPING * m_locoInfo->m_accelerationPitchRate)); // spring/damper
+ // process chassis acceleration dynamics - damp back towards zero, or a helicopter's lean
+
+ m_locoInfo->m_accelerationPitchRate += ((-PITCH_STIFFNESS * (m_locoInfo->m_accelerationPitch - pitchTarget)) + (-PITCH_DAMPING * m_locoInfo->m_accelerationPitchRate)); // spring/damper
m_locoInfo->m_accelerationPitch += m_locoInfo->m_accelerationPitchRate;
- m_locoInfo->m_accelerationRollRate += ((-ROLL_STIFFNESS * m_locoInfo->m_accelerationRoll) + (-ROLL_DAMPING * m_locoInfo->m_accelerationRollRate)); // spring/damper
+ m_locoInfo->m_accelerationRollRate += ((-ROLL_STIFFNESS * (m_locoInfo->m_accelerationRoll - rollTarget)) + (-ROLL_DAMPING * m_locoInfo->m_accelerationRollRate)); // spring/damper
m_locoInfo->m_accelerationRoll += m_locoInfo->m_accelerationRollRate;
// compute total pitch and roll of tank
info.m_totalPitch = m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch;
info.m_totalRoll = m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll;
- if (physics->isMotive())
+ if (!helicopter && physics->isMotive())
{
if (Z_VEL_PITCH_COEFF != 0.0f)
{
@@ -1777,15 +1816,15 @@ void Drawable::calcPhysicsXformHoverOrWings( const Locomotor *locomotor, Physics
// limit acceleration pitch and roll
- if (m_locoInfo->m_accelerationPitch > DECEL_PITCH_LIMIT)
- m_locoInfo->m_accelerationPitch = DECEL_PITCH_LIMIT;
- else if (m_locoInfo->m_accelerationPitch < -ACCEL_PITCH_LIMIT)
- m_locoInfo->m_accelerationPitch = -ACCEL_PITCH_LIMIT;
+ if (m_locoInfo->m_accelerationPitch > decelPitchLimit)
+ m_locoInfo->m_accelerationPitch = decelPitchLimit;
+ else if (m_locoInfo->m_accelerationPitch < -accelPitchLimit)
+ m_locoInfo->m_accelerationPitch = -accelPitchLimit;
- if (m_locoInfo->m_accelerationRoll > DECEL_PITCH_LIMIT)
- m_locoInfo->m_accelerationRoll = DECEL_PITCH_LIMIT;
- else if (m_locoInfo->m_accelerationRoll < -ACCEL_PITCH_LIMIT)
- m_locoInfo->m_accelerationRoll = -ACCEL_PITCH_LIMIT;
+ if (m_locoInfo->m_accelerationRoll > decelPitchLimit)
+ m_locoInfo->m_accelerationRoll = decelPitchLimit;
+ else if (m_locoInfo->m_accelerationRoll < -accelPitchLimit)
+ m_locoInfo->m_accelerationRoll = -accelPitchLimit;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
index 33e3292d6..6dabb9fd8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
@@ -1017,6 +1017,9 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle)
desiredPos.y += Sin(goalAngle) * 1000.0f;
PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos);
physics->setTurning(rotating);
+ // a helicopter turning in place has no sideways friction to stop a slide it came in with
+ if (isHelicopter(obj))
+ brakeHelicopter(obj, physics);
handleBehaviorZ(obj, physics, *obj->getPosition());
}
@@ -1048,11 +1051,22 @@ void Locomotor::setPhysicsOptions(Object* obj)
physics->setExtraFriction(m_template->m_extra2DFriction + extraExtraFriction);
physics->setAllowAirborneFriction(getApply2DFrictionWhenAirborne()); // you'd think we wouldn't want friction in the air, but it's needed for realistic behavior.
physics->setStickToGround(getStickToGround()); // walking guys aren't allowed to catch huge (or even small) air.
+ physics->setMotiveSteersSideways(isHelicopter(obj));
}
//-------------------------------------------------------------------------------------------------
-void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalPos,
- Real onPathDistToGoal, Real desiredSpeed, Bool *blocked)
+Bool Locomotor::isHelicopter(const Object* obj) const
+{
+ return m_template->m_appearance == LOCO_HOVER
+ && BitTest(m_template->m_surfaces, LOCOMOTORSURFACE_AIR)
+ && obj->isKindOf(KINDOF_AIRCRAFT)
+ && !obj->isEffectivelyDead(); // a dying one spirals on HelicopterSlowDeathBehavior's forces and the old friction
+}
+
+//-------------------------------------------------------------------------------------------------
+void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalPos,
+ Real onPathDistToGoal, Real desiredSpeed, Bool *blocked,
+ const Coord3D *faceTarget)
{
setFlag(MAINTAIN_POS_IS_VALID, false);
@@ -1195,7 +1209,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP
moveTowardsPositionTreads(obj, physics, goalPos, onPathDistToGoal, desiredSpeed);
break;
case LOCO_HOVER:
- moveTowardsPositionHover(obj, physics, goalPos, onPathDistToGoal, desiredSpeed);
+ moveTowardsPositionHover(obj, physics, goalPos, onPathDistToGoal, desiredSpeed, faceTarget);
break;
case LOCO_WINGS:
moveTowardsPositionWings(obj, physics, goalPos, onPathDistToGoal, desiredSpeed);
@@ -1251,9 +1265,11 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP
{
// not projectiles only cheat in x & y.
// Normalize.
- if (dist > 0.001f)
+ if (dist > 0.001f)
{
- Real vel = fabs(physics->getForwardSpeed2D());
+ // a helicopter's speed need not lie along its nose
+ const Coord3D *v = physics->getVelocity();
+ Real vel = isHelicopter(obj) ? sqrt(sqr(v->x) + sqr(v->y)) : fabs(physics->getForwardSpeed2D());
if (vel < MIN_VEL)
vel = MIN_VEL;
if (vel > dist)
@@ -1997,10 +2013,13 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics,
}
//-------------------------------------------------------------------------------------------------
-void Locomotor::moveTowardsPositionHover(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed)
+void Locomotor::moveTowardsPositionHover(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed, const Coord3D *faceTarget)
{
// handle the 2D component.
- moveTowardsPositionOther(obj, physics, goalPos, onPathDistToGoal, desiredSpeed);
+ if (isHelicopter(obj))
+ moveTowardsPositionHelicopter(obj, physics, goalPos, onPathDistToGoal, desiredSpeed, faceTarget);
+ else
+ moveTowardsPositionOther(obj, physics, goalPos, onPathDistToGoal, desiredSpeed);
// Only hover locomotors care about their OverWater special effects. (OverWater also affects speed, so this is not a client thing)
Coord3D newPosition = *obj->getPosition();
@@ -2024,6 +2043,100 @@ void Locomotor::moveTowardsPositionHover(Object* obj, PhysicsBehavior *physics,
}
}
+//-------------------------------------------------------------------------------------------------
+/*
+ A helicopter flies the velocity it wants rather than the way it faces. Every frame it pushes its
+ 2D velocity towards the goal at the speed it can still stop from, by at most its Acceleration,
+ or its Braking while it is shedding speed in the direction it is going. The nose is a separate
+ choice: on the target when there is one, turned into the flight while the goal is more than
+ LONG_FLIGHT_SECONDS out at full speed, and otherwise left where it is, so a short hop behind or
+ beside the helicopter is flown backwards or sideways and a long one turns as it goes.
+*/
+void Locomotor::moveTowardsPositionHelicopter(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed, const Coord3D *faceTarget)
+{
+ const Real LONG_FLIGHT_SECONDS = 3.0f;
+ const Real TOO_CLOSE_TO_AIM = 1.0f; // right over the target the bearing to it is noise
+
+ BodyDamageType bdt = obj->getBodyModule()->getDamageState();
+ Real maxSpeed = getMaxSpeedForCondition(bdt);
+ if (desiredSpeed > maxSpeed)
+ desiredSpeed = maxSpeed;
+
+ const Coord3D *pos = obj->getPosition();
+ PhysicsTurningType rotating = TURN_NONE;
+ if (faceTarget)
+ {
+ if (fabs(faceTarget->x - pos->x) > TOO_CLOSE_TO_AIM || fabs(faceTarget->y - pos->y) > TOO_CLOSE_TO_AIM)
+ rotating = rotateTowardsPosition(obj, *faceTarget);
+ }
+ else if (onPathDistToGoal > maxSpeed * LOGICFRAMES_PER_SECOND * LONG_FLIGHT_SECONDS)
+ {
+ rotating = rotateTowardsPosition(obj, goalPos);
+ }
+ physics->setTurning(rotating);
+
+ Real goalSpeed = desiredSpeed;
+ if (!getFlag(NO_SLOW_DOWN_AS_APPROACHING_DEST))
+ {
+ Real stopSpeed = sqrt(2.0f * getBraking() * onPathDistToGoal);
+ if (goalSpeed > stopSpeed)
+ goalSpeed = stopSpeed;
+ }
+
+ Real wantX = 0.0f;
+ Real wantY = 0.0f;
+ Real dx = goalPos.x - pos->x;
+ Real dy = goalPos.y - pos->y;
+ Real dist = sqrt(dx*dx + dy*dy);
+ if (dist > 0.001f)
+ {
+ wantX = dx * goalSpeed / dist;
+ wantY = dy * goalSpeed / dist;
+ }
+
+ const Coord3D *vel = physics->getVelocity();
+ Real ax = wantX - vel->x;
+ Real ay = wantY - vel->y;
+ Real need = sqrt(ax*ax + ay*ay);
+ if (need == 0.0f)
+ return;
+
+ Real limit = (ax * vel->x + ay * vel->y < 0.0f) ? getBraking() : getMaxAcceleration(bdt);
+ if (need > limit)
+ {
+ ax *= limit / need;
+ ay *= limit / need;
+ }
+
+ Real mass = physics->getMass();
+ Coord3D force;
+ force.x = mass * ax;
+ force.y = mass * ay;
+ force.z = 0.0f;
+ physics->applyMotiveForce(&force);
+}
+
+//-------------------------------------------------------------------------------------------------
+/// stop a helicopter's 2D velocity whichever way it points, at its Braking
+void Locomotor::brakeHelicopter(Object* obj, PhysicsBehavior *physics)
+{
+ const Coord3D *vel = physics->getVelocity();
+ Real speed = sqrt(sqr(vel->x) + sqr(vel->y));
+ if (speed == 0.0f)
+ return;
+
+ Real cut = getBraking();
+ if (cut > speed)
+ cut = speed;
+
+ Real scale = -physics->getMass() * cut / speed;
+ Coord3D force;
+ force.x = scale * vel->x;
+ force.y = scale * vel->y;
+ force.z = 0.0f;
+ physics->applyMotiveForce(&force);
+}
+
//-------------------------------------------------------------------------------------------------
void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, const Coord3D& chasedGoalPos, Real onPathDistToGoal, Real desiredSpeed)
{
@@ -2724,6 +2837,12 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi
void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physics)
{
physics->setTurning(TURN_NONE);
+ if (isHelicopter(obj))
+ {
+ if (physics->isMotive())
+ brakeHelicopter(obj, physics);
+ return;
+ }
if (physics->isMotive()) // no need to stop something that isn't moving.
{
DEBUG_ASSERTCRASH(m_template->m_minSpeed == 0.0f, ("HOVER should always have zero minSpeeds (otherwise, they WING)"));
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index e19e82f7f..37d90a04d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -3907,6 +3907,33 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
}
else
{
+ /* A helicopter flies with its nose on what it is shooting at. That matters for a gun with
+ no turret of its own, or the Comanche's, which has a turn rate of 0 and only fires along
+ the nose: without this a Comanche passing a target never shot at it. A weapon on a
+ turret that turns needs no help. */
+ Coord3D faceTargetPos;
+ const Coord3D *faceTarget = NULL;
+ if (m_curLocomotor->isHelicopter(getObject()))
+ {
+ Object *target = NULL;
+ WhichTurretType tur = getWhichTurretForCurWeapon();
+ if (tur == TURRET_INVALID)
+ {
+ target = getCurrentVictim();
+ }
+ else if (getTurretTurnRate(tur) == 0.0f)
+ {
+ target = getTurretTargetObject(tur, FALSE);
+ if (target == NULL)
+ target = getCurrentVictim();
+ }
+ if (target && !target->isEffectivelyDead())
+ {
+ faceTargetPos = *target->getPosition();
+ faceTarget = &faceTargetPos;
+ }
+ }
+
switch (m_locomotorGoalType)
{
case POSITION_EXPLICIT:
@@ -3915,8 +3942,8 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
Real myMaxSpeed = m_curLocomotor->getMaxSpeedForCondition(getObject()->getBodyModule()->getDamageState());
if( speed == FAST_AS_POSSIBLE || speed > myMaxSpeed )
speed = myMaxSpeed;
- m_curLocomotor->locoUpdate_moveTowardsPosition(getObject(),
- m_locomotorGoalData, 0.0f, speed, &blocked);
+ m_curLocomotor->locoUpdate_moveTowardsPosition(getObject(),
+ m_locomotorGoalData, 0.0f, speed, &blocked, faceTarget);
m_doFinalPosition = FALSE;
}
break;
@@ -4019,7 +4046,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
}
m_curLocomotor->locoUpdate_moveTowardsPosition(getObject(), goalPos,
- onPathDistToGoal+getPathExtraDistance(), speed, &blocked);
+ onPathDistToGoal+getPathExtraDistance(), speed, &blocked, faceTarget);
m_doFinalPosition = FALSE;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp
index b3a9b075b..9a3125db9 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp
@@ -475,7 +475,8 @@ void PhysicsBehavior::applyFrictionalForces()
Real lateralVel_x = lateralDot * -dir->y;
Real lateralVel_y = lateralDot * dir->x;
- Real lf = mass * getLateralFriction();
+ // a helicopter flying sideways is not skidding: its locomotor holds that velocity on purpose
+ Real lf = (isMotive() && getFlag(MOTIVE_STEERS_SIDEWAYS)) ? 0.0f : mass * getLateralFriction();
Coord3D accel;
accel.x = -(lf * lateralVel_x);