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): a helix aims with its turret, not its body

Olcay Seygand16004ba9b90
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 959fcb021..dd6749952 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,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 Helix with the gattling cannon on its back lets the cannon do the aiming. The cannon sits on a turret that turns all the way round, yet the whole Helix used to swing round to point at whatever it was shooting. Now it holds its heading and only the turret tracks. With a Crusader driving circles round it, a Helix that used to turn 336 degrees following the tank does not turn at all, and its cannon fired 458 times where it fired 251. Infantry shooting out of a Helix bunker leave the Helix just as free once they are on its target. The Helix's own nose gun only fires forward, so while the cannon has the target it fires only when the target crosses in front.
- 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. 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.
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index ce87777a2..470864936 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -45,6 +45,7 @@ Data/Scenarios/chokeprobe.txt
Data/Scenarios/crowdbattle.txt
Data/Scenarios/helislide.txt
Data/Scenarios/helitypes.txt
+Data/Scenarios/helixturret.txt
Data/Scenarios/inferno30.txt
Data/Scenarios/jetpass.txt
Data/Scenarios/leadinfantry.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/helixturret.txt b/GeneralsMD/Code/Data/Scenarios/helixturret.txt
new file mode 100644
index 000000000..8127e7976
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/helixturret.txt
@@ -0,0 +1,58 @@
+# Two Helixes with the gattling cannon, which is on the Helix's back by frame 640. The first is put
+# on two Paladins with three Rangers beside them, then sent north past them, then west away from
+# them, then attack-moved east through them. The second is put on a Crusader, which cannot shoot at
+# aircraft, and the tank drives two laps of a circle 100 round it, inside the Helix's own gun's
+# range so the Helix never has to chase.
+#
+# 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 helixturret -logPrefix helixturret_
+#
+# Measured 2026-10-03 with a temporary per-frame log of the Helix's heading, the cannon's turret angle
+# and both guns' last shot. Before, the first Helix swung itself 18 degrees onto the Paladin while it
+# hovered and fired its own gun 15 times; the second turned 336 degrees following the circling
+# Crusader, its own gun firing 145 times and the cannon 251. After, neither Helix turns at all to
+# aim: the cannon's turret alone covers 652 degrees round the circle and fires 458 times, and each
+# Helix's own gun, which points only along the nose, fires only when a target crosses it (0 and 7
+# times). Sent past and away the first Helix behaves as it did, because a move order already took
+# its own gun off the target; the 149 degrees it turns going away is its nose coming round into the
+# flight.
+
+30 spawn 1 Tank_ChinaVehicleHelix 1 1200 2700
+40 shiftupgrade 1 Tank_ChinaVehicleHelix Upgrade_ChinaHelixGattlingCannon
+700 spawn 0 AmericaTankPaladin 2 1420 2760
+700 spawn 0 AmericaInfantryRanger 3 1420 2640
+720 attack 1 Tank_ChinaVehicleHelix 0 AmericaTankPaladin
+900 move 1 Tank_ChinaVehicleHelix 1250 3000
+1050 move 1 Tank_ChinaVehicleHelix 900 2700
+1200 attackmove 1 Tank_ChinaVehicleHelix 1700 2700
+720 tally 0 AmericaTankPaladin
+900 tally 0 AmericaTankPaladin
+1050 tally 0 AmericaTankPaladin
+1200 tally 0 AmericaTankPaladin
+1700 tally 0 AmericaTankPaladin
+1700 tally 0 AmericaInfantryRanger
+
+30 spawn 1 ChinaVehicleHelix 1 1200 3700
+40 shiftupgrade 1 ChinaVehicleHelix Upgrade_ChinaHelixGattlingCannon
+700 spawn 0 AmericaTankCrusader 1 1300 3700
+720 attack 1 ChinaVehicleHelix 0 AmericaTankCrusader
+740 move 0 AmericaTankCrusader 1271 3771
+800 move 0 AmericaTankCrusader 1200 3800
+860 move 0 AmericaTankCrusader 1129 3771
+920 move 0 AmericaTankCrusader 1100 3700
+980 move 0 AmericaTankCrusader 1129 3629
+1040 move 0 AmericaTankCrusader 1200 3600
+1100 move 0 AmericaTankCrusader 1271 3629
+1160 move 0 AmericaTankCrusader 1300 3700
+1220 move 0 AmericaTankCrusader 1271 3771
+1280 move 0 AmericaTankCrusader 1200 3800
+1340 move 0 AmericaTankCrusader 1129 3771
+1400 move 0 AmericaTankCrusader 1100 3700
+1460 move 0 AmericaTankCrusader 1129 3629
+1520 move 0 AmericaTankCrusader 1200 3600
+1580 move 0 AmericaTankCrusader 1271 3629
+1640 move 0 AmericaTankCrusader 1300 3700
+1000 tally 0 AmericaTankCrusader
+1700 tally 0 AmericaTankCrusader
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
index d32076e5d..ed862fcf6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
@@ -610,8 +610,9 @@ public:
void transferAttack(ObjectID fromID, ObjectID toID);
void setCurrentVictim( const Object *nemesis ); ///< Current victim.
- Object *getCurrentVictim( void ) const;
+ Object *getCurrentVictim( void ) const;
virtual void notifyVictimIsDead() { }
+ Bool isCarriedGunOn( const Object *victim ) const; ///< a rider's turret or a passenger is already shooting at victim
// if we are attacking a position (and NOT an object), return it. otherwise return null.
const Coord3D *getCurrentVictimPos( void ) const;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index a9ec363ec..53d133fab 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -5695,9 +5695,13 @@ StateReturnType AIAttackAimAtTargetState::update()
}
//DEBUG_LOG(("AIM: desired %f, actual %f, delta %f, aimDelta %f, goalpos %f %f\n",rad2deg(obj->getOrientation() + relAngle),rad2deg(obj->getOrientation()),rad2deg(relAngle),rad2deg(aimDelta),victim->getPosition()->x,victim->getPosition()->y));
+ // a helicopter whose carried turret is already on the victim keeps its heading; its own fixed
+ // gun fires when the victim comes past the nose
+ const Locomotor *loco = sourceAI->getCurLocomotor();
+ Bool headingFree = m_isAttackingObject && loco && loco->isHelicopter(source) && sourceAI->isCarriedGunOn(victim);
if (m_canTurnInPlace)
{
- if (fabs(relAngle) > aimDelta)
+ if (fabs(relAngle) > aimDelta && !headingFree)
{
Real desiredAngle = source->getOrientation() + relAngle;
sourceAI->setLocomotorGoalOrientation(desiredAngle);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 37d90a04d..4441ef879 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -3910,7 +3910,8 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
/* 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. */
+ turret that turns needs no help, and neither does a fixed gun whose target a carried
+ turret is already on: a Helix flies where it likes while its gattling cannon tracks. */
Coord3D faceTargetPos;
const Coord3D *faceTarget = NULL;
if (m_curLocomotor->isHelicopter(getObject()))
@@ -3927,7 +3928,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
if (target == NULL)
target = getCurrentVictim();
}
- if (target && !target->isEffectivelyDead())
+ if (target && !target->isEffectivelyDead() && !isCarriedGunOn(target))
{
faceTargetPos = *target->getPosition();
faceTarget = &faceTargetPos;
@@ -6170,6 +6171,50 @@ Object *AIUpdateInterface::getCurrentVictim( void ) const
return NULL;
}
+//-------------------------------------------------------------------------------------------------
+/**
+ Whether something in contain is already shooting at victim and can do it without its carrier
+ turning: a rider whose gun is on a turret that turns (a Helix's gattling cannon), a passenger
+ allowed to fire out (the infantry in a Helix's bunker), or the same inside the rider (the Infantry
+ General's Helix bunker holds its infantry itself). No turret in this tree limits its arc, so such a
+ gun reaches the victim from any heading.
+*/
+static Bool AIUpdate_containsGunOn( ContainModuleInterface *contain, const Object *victim )
+{
+ const Object *rider = contain->friend_getRider();
+ if (rider)
+ {
+ const AIUpdateInterface *riderAI = rider->getAI();
+ if (riderAI && riderAI->getCurrentVictim() == victim)
+ {
+ WhichTurretType tur = riderAI->getWhichTurretForCurWeapon();
+ if (tur != TURRET_INVALID && riderAI->getTurretTurnRate(tur) != 0.0f)
+ return TRUE;
+ }
+ if (rider->getContain() && AIUpdate_containsGunOn(rider->getContain(), victim))
+ return TRUE;
+ }
+
+ const ContainedItemsList *passengers = contain->getContainedItemsList();
+ for (ContainedItemsList::const_iterator it = passengers->begin(); it != passengers->end(); ++it)
+ {
+ const Object *passenger = *it;
+ const AIUpdateInterface *passengerAI = passenger->getAI();
+ if (passengerAI && passenger->isKindOf(KINDOF_INFANTRY) && contain->isPassengerAllowedToFire(passenger->getID())
+ && passengerAI->getCurrentVictim() == victim)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------------------------------
+/// whether something this unit carries is already shooting at victim from any heading (AIUpdate_containsGunOn)
+Bool AIUpdateInterface::isCarriedGunOn( const Object *victim ) const
+{
+ ContainModuleInterface *contain = getObject()->getContain();
+ return contain && AIUpdate_containsGunOn(contain, victim);
+}
+
// if we are attacking a position (and NOT an object), return it. otherwise return null.
const Coord3D *AIUpdateInterface::getCurrentVictimPos( void ) const
{