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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): helicopters keep shooting while they pull back
Olcay Seyganb253fb19cff4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex dd6749952..00be918bf 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.+- Pull a helicopter out of a fight and it keeps shooting on the way out. Told to move while attacking, it used to drop the target at once; now it holds its gun on it for as long as the target is alive and in range, and the move goes exactly where and when it would have. A Comanche backs or slides away with its nose on the target: sent 350 straight back from three Battlemasters it fired 10 more rounds before they fell out of range, and 14 sliding off to the side, where it used to fire one. A plain move never starts a new fight; a helicopter that was not attacking anything just flies.- 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.manifestindex 470864936..b868f1ae3 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -46,6 +46,7 @@ Data/Scenarios/crowdbattle.txtData/Scenarios/helislide.txtData/Scenarios/helitypes.txtData/Scenarios/helixturret.txt+Data/Scenarios/hitrun.txtData/Scenarios/inferno30.txtData/Scenarios/jetpass.txtData/Scenarios/leadinfantry.txtdiff --git a/GeneralsMD/Code/Data/Scenarios/hitrun.txt b/GeneralsMD/Code/Data/Scenarios/hitrun.txtnew file mode 100644index 000000000..9ee86dbdf--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/hitrun.txt@@ -0,0 +1,31 @@+# Two Comanches are each put on three Battlemasters, which cannot shoot at aircraft, and 50 frames+# into the attack, with missiles still in the pod, the first is sent 350 straight back away from+# them and the second 350 off to the side.+#+# 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 500+# -scenario hitrun -logPrefix hitrun_+#+# Measured 2026-10-03 with a temporary per-frame log of heading, gun target and last shot. Before,+# each Comanche fired once more after the order and its gun let go of the tank within 6 frames.+# After, the first fires 10 more shots backing straight away and the second 14 sliding off to the+# side, both with the nose dead on the tank (0 degrees off) until it passes out of range 40 and 56+# frames in. The moves themselves are untouched: 30 out at frame 32 and the same end point both+# times. The missile pod was empty by then, so the extra shots are cannon rounds, which barely+# scratch a Battlemaster. The tanks lost 174 and 179 between frames 200 and 450 against 190 each+# before. Why the total came out lower is not pinned down; the pod's last missile left on frame 202+# in one run and 206 in the other.++30 spawn 0 AmericaVehicleComanche 1 1100 3500+30 spawn 0 AirF_AmericaVehicleComanche 1 1100 4300+140 spawn 1 ChinaTankBattleMaster 3 1300 3500+140 spawn 1 Tank_ChinaTankBattleMaster 3 1300 4300+150 attack 0 AmericaVehicleComanche 1 ChinaTankBattleMaster+150 attack 0 AirF_AmericaVehicleComanche 1 Tank_ChinaTankBattleMaster+200 move 0 AmericaVehicleComanche 750 3500+200 move 0 AirF_AmericaVehicleComanche 1000 4650+200 tally 1 ChinaTankBattleMaster+450 tally 1 ChinaTankBattleMaster+200 tally 1 Tank_ChinaTankBattleMaster+450 tally 1 Tank_ChinaTankBattleMasterdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.hindex ed862fcf6..6f9217e5c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h@@ -613,6 +613,8 @@ public: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+ void noteWithdrawTarget( const Object *victim ); ///< an attack is ending; a helicopter may keep shooting victim while it moves+ void updateWithdrawTarget(); ///< keep the turret on that target while it can, let go once it cannot// if we are attacking a position (and NOT an object), return it. otherwise return null.const Coord3D *getCurrentVictimPos( void ) const;@@ -837,7 +839,9 @@ private:AIStateMachine* m_stateMachine; ///< the state machineUnsignedInt m_nextEnemyScanTime; ///< how long until the next enemy scanObjectID m_currentVictimID; ///< if not INVALID_ID, this agent's current victim.- Real m_desiredSpeed; ///< the desired speed of the tank+ ObjectID m_withdrawTargetID; ///< what a helicopter told to move mid-fight keeps shooting while it flies+ UnsignedInt m_withdrawFrame; ///< the last frame that target was still held+ Real m_desiredSpeed; ///< the desired speed of the tankCommandSourceType m_lastCommandSource; /**< Keep track of the source of the last command we got.This is set immediately before the SetState that goesto the state machine, so onEnter in there can know wherediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex 53d133fab..d682e204b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -6420,6 +6420,7 @@ void AIAttackState::onExit( StateExitType status )if (ai){//ai->notifyVictimIsDead(); no, do NOT do this here.+ ai->noteWithdrawTarget(ai->getCurrentVictim());ai->setCurrentVictim(NULL);for (int i = 0; i < MAX_TURRETS; ++i)ai->setTurretTargetObject((WhichTurretType)i, NULL, NULL);diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex 4441ef879..b62b52bc0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -285,6 +285,8 @@ AIUpdateInterface::AIUpdateInterface( Thing *thing, const ModuleData* moduleDatam_stateMachine = NULL;m_nextEnemyScanTime = 0;m_currentVictimID = INVALID_ID;+ m_withdrawTargetID = INVALID_ID;+ m_withdrawFrame = 0;m_desiredSpeed = FAST_AS_POSSIBLE;m_lastCommandSource = CMD_FROM_AI;m_guardMode = GUARDMODE_NORMAL;@@ -3916,6 +3918,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )const Coord3D *faceTarget = NULL;if (m_curLocomotor->isHelicopter(getObject())){+ updateWithdrawTarget();Object *target = NULL;WhichTurretType tur = getWhichTurretForCurWeapon();if (tur == TURRET_INVALID)@@ -6215,6 +6218,66 @@ Bool AIUpdateInterface::isCarriedGunOn( const Object *victim ) constreturn contain && AIUpdate_containsGunOn(contain, victim);}+//-------------------------------------------------------------------------------------------------+/**+ A helicopter told to move in the middle of a fight keeps shooting what it was attacking while it+ flies. The attack is ending (AIAttackState::onExit), so remember its victim; updateWithdrawTarget+ then holds the turret on it for as long as the helicopter is on a plain move. Only a helicopter,+ and only one that already had a victim: a move order never picks a new target.+*/+void AIUpdateInterface::noteWithdrawTarget( const Object *victim )+{+ if (victim &&m_curLocomotor && m_curLocomotor->isHelicopter(getObject()))+ {+ m_withdrawTargetID = victim->getID();+ m_withdrawFrame = TheGameLogic->getFrame();+ }+}++//-------------------------------------------------------------------------------------------------+/**+ Hold the turret the current weapon is on (the Comanche's does not turn, so its nose stays on the+ target and it backs or slides away) on the remembered target, every frame of a plain move, while+ the target is alive, attackable and in range. The first frame any of that fails, or a frame is+ missed, the turret lets go and the helicopter flies the move as it would have. The move itself is+ never touched.+*/+void AIUpdateInterface::updateWithdrawTarget()+{+ if (m_withdrawTargetID == INVALID_ID)+ return;++ Object *obj = getObject();+ UnsignedInt now = TheGameLogic->getFrame();+ Object *target = TheGameLogic->findObjectByID(m_withdrawTargetID);+ StateID state = getStateMachine()->getCurrentStateID();+ Bool hold = (state == AI_MOVE_TO || state == AI_FOLLOW_PATH) && now <= m_withdrawFrame + 1+ && target && !target->isEffectivelyDead();+ // the attack state picked the weapon; with it gone, a pod reloading would hold the gun silent+ if (hold)+ obj->chooseBestWeaponForTarget(target, PREFER_MOST_DAMAGE, getLastCommandSource());+ WhichTurretType tur = getWhichTurretForCurWeapon();+ Weapon *weapon = obj->getCurrentWeapon();++ hold = hold && tur != TURRET_INVALID && weapon && weapon->isWithinAttackRange(obj, target);+ if (hold)+ {+ // the same test the turret applies to a target it already has: stealth, a changed side+ CanAttackResult result = obj->getAbleToAttackSpecificObject(ATTACK_CONTINUED_TARGET, target, getLastCommandSource());+ hold = result == ATTACKRESULT_POSSIBLE || result == ATTACKRESULT_POSSIBLE_AFTER_MOVING;+ }+ if (hold)+ {+ m_withdrawFrame = now;+ setTurretTargetObject(tur, target, FALSE);+ return;+ }++ if (target && tur != TURRET_INVALID && getTurretTargetObject(tur, FALSE) == target)+ setTurretTargetObject(tur, NULL, FALSE);+ m_withdrawTargetID = INVALID_ID;+}+// if we are attacking a position (and NOT an object), return it. otherwise return null.const Coord3D *AIUpdateInterface::getCurrentVictimPos( void ) const{@@ -7179,12 +7242,13 @@ void AIUpdateInterface::crc( Xfer *x )* 13: m_pathfindFoundNothing* 14: the salvage return position and its flag* 16: the tunnel trip's goal and its flag- * 17: how the tunnel trip's last leg is walked */+ * 17: how the tunnel trip's last leg is walked+ * 18: the target a helicopter keeps shooting while it moves away */// ------------------------------------------------------------------------------------------------void AIUpdateInterface::xfer( Xfer *xfer ){// version- const XferVersion currentVersion = 17;+ const XferVersion currentVersion = 18;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -7517,6 +7581,12 @@ void AIUpdateInterface::xfer( Xfer *xfer )m_tunnelTripEnd = (TunnelTripEnd)end;}+ if (version >= 18)+ {+ xfer->xferObjectID(&m_withdrawTargetID);+ xfer->xferUnsignedInt(&m_withdrawFrame);+ }+} // end xfer// ------------------------------------------------------------------------------------------------