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): tank turrets keep firing on the move
Olcay Seygan19447a6b8beb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 99f158212..38af39190 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -47,6 +47,15 @@ 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.+## 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.+- Told to move in the middle of a fight, a tank or car with a turret keeps shooting what it was attacking for as long as the target is alive and in range, the way helicopters already did. A Technical pulled back from four Troop Crawlers used to fall silent for two and a half seconds and no longer stops at all. A Marauder used to wait almost four seconds past its reload before the next shell and now waits half a second. A move order still never starts a new fight.+- The Marauder's turret turns. The model always had one, but the tank swung its whole body round to aim and could not shoot on the move. The turret turns 100 degrees a second, as fast as the Scorpion's: driving past four Troop Crawlers a Marauder used to fire nothing and now lands three shells, and circling them it kills all four where it never fired. The turret is slower round than the hull was, so a target appearing straight behind a parked Marauder takes its first shell most of a second later than before.+- The Gattling Tank opens fire 15 degrees before its guns are on the target and walks the stream onto it, where it used to wait until it was within 2 degrees. The Gattling Cannon defence and the Strategy Center's bombardment cannon do the same. Circling four Troop Crawlers, a Gattling Tank hit them 208 times where it hit 102, and 12 of the extra hits come from the earlier start.+- The Gattling cannon on an Overlord's back turns at the Gattling Tank's 180 degrees a second instead of 60 and opens fire the same way. A target appearing behind the Overlord is under fire 22 frames sooner and took 66 hits where it took 41.+- A replay recorded before this change plays back 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.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex dbd77e492..5074e69ec 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -44,6 +44,7 @@ Data/Scenarios/bridgelong.txtData/Scenarios/chokeprobe.txtData/Scenarios/comturret.txtData/Scenarios/crowdbattle.txt+Data/Scenarios/driveby.txtData/Scenarios/guardradius.txtData/Scenarios/helislide.txtData/Scenarios/helitypes.txt@@ -95,6 +96,7 @@ Data/Scenarios/tunnelqueue.txtData/Scenarios/tunnelshortcut.txtData/Scenarios/tunnelsplit.txtData/Scenarios/tunnelwalk.txt+Data/Scenarios/vehiclelean.txtData/Scenarios/vision.txtData/Scripts/SkirmishScripts.scbData/Turkish/Generals.strdiff --git a/GeneralsMD/Code/Data/INI/BalanceReforged.ini b/GeneralsMD/Code/Data/INI/BalanceReforged.iniindex afb262aae..18cd5615a 100644--- a/GeneralsMD/Code/Data/INI/BalanceReforged.ini+++ b/GeneralsMD/Code/Data/INI/BalanceReforged.ini@@ -419,6 +419,119 @@ Object SupW_AmericaVehicleComancheEndEnd+; ---- the Marauder's turret turns ---------------------------------------------------------------+;+; The model has a turret for each of its three gun levels and the draw module names all three, but+; EA never gave the logic a Turret block, so the whole tank swung round to aim and could not shoot+; on the move. The gun now sits on a turret that slews 100 degrees a second, as the Scorpion's does.+; That is slower than the hull turned: a target appearing straight behind a parked Marauder takes its+; first shell 24 frames later than it did, and 120 a second would still be 15 late. The new AI module+; keeps EA's only line, AutoAcquireEnemiesWhenIdle.++Object GLATankMarauder+ ReplaceModule ModuleTag_03+ Behavior = AIUpdateInterface ModuleTag_03_Reforged+ Turret+ TurretTurnRate = 100+ RecenterTime = 5000+ ControlledWeaponSlots = PRIMARY+ End+ AutoAcquireEnemiesWhenIdle = Yes+ End+ End+End++Object Chem_GLATankMarauder+ ReplaceModule ModuleTag_03+ Behavior = AIUpdateInterface ModuleTag_03_Reforged+ Turret+ TurretTurnRate = 100+ RecenterTime = 5000+ ControlledWeaponSlots = PRIMARY+ End+ AutoAcquireEnemiesWhenIdle = Yes+ End+ End+End++Object Demo_GLATankMarauder+ ReplaceModule ModuleTag_03+ Behavior = AIUpdateInterface ModuleTag_03_Reforged+ Turret+ TurretTurnRate = 100+ RecenterTime = 5000+ ControlledWeaponSlots = PRIMARY+ End+ AutoAcquireEnemiesWhenIdle = Yes+ End+ End+End++Object Slth_GLATankMarauder+ ReplaceModule ModuleTag_03+ Behavior = AIUpdateInterface ModuleTag_03_Reforged+ Turret+ TurretTurnRate = 100+ RecenterTime = 5000+ ControlledWeaponSlots = PRIMARY+ End+ AutoAcquireEnemiesWhenIdle = Yes+ End+ End+End++; ---- the Overlord's Gattling Cannon turns like a Gattling Tank's ------------------------------+;+; EA's rider turret turned 60 degrees a second against the Gattling Tank's 180 and held fire until+; it was within 2 degrees, so a target crossing the Overlord's path was mostly watched. It now has+; the Gattling Tank's turret: 180 degrees a second in both axes, and FiresWhileTurning, which opens+; fire 15 degrees out.++Object ChinaTankOverlordGattlingCannon+ ReplaceModule ModuleTag_03+ Behavior = AIUpdateInterface ModuleTag_03_Reforged+ Turret+ ControlledWeaponSlots = PRIMARY SECONDARY+ TurretTurnRate = 180+ TurretPitchRate = 180+ AllowsPitch = Yes+ FiresWhileTurning = Yes+ End+ AutoAcquireEnemiesWhenIdle = Yes+ End+ End+End++Object Nuke_ChinaTankOverlordGattlingCannon+ ReplaceModule ModuleTag_03+ Behavior = AIUpdateInterface ModuleTag_03_Reforged+ Turret+ ControlledWeaponSlots = PRIMARY SECONDARY+ TurretTurnRate = 180+ TurretPitchRate = 180+ AllowsPitch = Yes+ FiresWhileTurning = Yes+ End+ AutoAcquireEnemiesWhenIdle = Yes+ End+ End+End++Object Tank_ChinaTankOverlordGattlingCannon+ ReplaceModule ModuleTag_03+ Behavior = AIUpdateInterface ModuleTag_03_Reforged+ Turret+ ControlledWeaponSlots = PRIMARY SECONDARY+ TurretTurnRate = 180+ TurretPitchRate = 180+ AllowsPitch = Yes+ FiresWhileTurning = Yes+ End+ AutoAcquireEnemiesWhenIdle = Yes+ End+ End+End+; ---- scouts ------------------------------------------------------------------------------------; The command bar offers the scout key to a selection with one of these in it. SCOUT changes; nothing else about the unit.diff --git a/GeneralsMD/Code/Data/Scenarios/driveby.txt b/GeneralsMD/Code/Data/Scenarios/driveby.txtnew file mode 100644index 000000000..283886ef5--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/driveby.txt@@ -0,0 +1,19 @@+# A Marauder is sent 500 east past four Troop Crawlers parked 100 north of the midpoint of its+# route. It has no attack order: whatever it shoots, its turret picked for itself on the move.+#+# 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 1 -maxframes 640+# -scenario driveby -logPrefix driveby_+#+# Measured 2026-10-03 with a tally of the crawlers' health every frame (the shots below are the+# frames it dropped). Before, the Marauder had no turret in its logic and drove past without firing+# once. After, its turret turns to them and it hits on frames 239, 299 and 364, one shell per+# reload. The same route with a Technical (GLAVehicleTechnical in both places) used to hit twice,+# once per two-second target check, 58 frames apart; it now hits every 6 frames, 11 times.++5 spawn 0 GLATankMarauder 1 950 3700+20 spawn 1 ChinaVehicleTroopCrawler 4 1200 3800 14+30 playermove 0 GLATankMarauder 1450 3700+20 tally 1 ChinaVehicleTroopCrawler+630 tally 1 ChinaVehicleTroopCrawlerdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.hindex f870a68bb..af37e03e8 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h@@ -622,7 +622,7 @@ 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 noteWithdrawTarget( const Object *victim ); ///< an attack is ending; a helicopter or a turret may keep shooting victim while it movesvoid 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.@@ -848,7 +848,7 @@ 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.- ObjectID m_withdrawTargetID; ///< what a helicopter told to move mid-fight keeps shooting while it flies+ ObjectID m_withdrawTargetID; ///< what a unit told to move mid-fight keeps shooting while it movesUnsignedInt m_withdrawFrame; ///< the last frame that target was still heldReal m_desiredSpeed; ///< the desired speed of the tankCommandSourceType m_lastCommandSource; /**< Keep track of the source of the last command we got.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.hindex 73df8e57d..a8c0e907c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/TurretAI.h@@ -333,6 +333,7 @@ public:Bool friend_isAnyWeaponInRangeOf(const Object* o) const;TurretTargetType friend_getTurretTarget( Object*& obj, Coord3D& pos, Bool clearDeadTargets = TRUE ) const;Bool friend_getTargetWasSetByIdleMood() const { return m_targetWasSetByIdleMood; }+ Bool friend_getFiresWhileTurning() const { return m_firesWhileTurning; }const Team* friend_getVictimInitialTeam() const { return m_victimInitialTeam; }void friend_checkForIdleMoodTarget();UnsignedInt friend_getNextIdleMoodTargetFrame() const;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex 921c8c27a..72bc3fc31 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -5987,9 +5987,14 @@ StateReturnType AIAttackFireWeaponState::update()//to transfer attackers (AIUpdateInterface::transferAttack), it is unable to modify our current victim in our attack state//machine. When we move immediately to the aim state in the same frame as the transfer (after this call in fact), the victim//was still pointing to the building and not the hole we transferred to. This code fixes that.- if( victim != obj->getAI()->getCurrentVictim() )- {- getMachine()->setGoalObject( obj->getAI()->getCurrentVictim() );+ // Only when the AI has a victim to hand over. A turret's machine runs this state too, and a target the+ // turret picked for itself on the move has no attack state behind it: the AI's victim is null, and+ // copying that over dropped the target after every shot, so a tank driving past fired once per mood+ // check instead of at its rate of fire.+ Object *aiVictim = obj->getAI()->getCurrentVictim();+ if( aiVictim && victim != aiVictim )+ {+ getMachine()->setGoalObject( aiVictim );}// clear this, just in case.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cppindex 16a2822d6..9ad773cc3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp@@ -456,7 +456,8 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Reaif( m_angle != origAngle )getOwner()->reactToTurretChange( m_whichTurret, origAngle, m_pitch );- Bool aligned = fabs(m_angle - desiredAngle) <= relThresh && !beyondArc;+ // normalized, or a turret just either side of straight back reads as a full turn away+ Bool aligned = fabs(normalizeAngle(m_angle - desiredAngle)) <= relThresh && !beyondArc;return aligned;}@@ -1167,7 +1168,11 @@ StateReturnType TurretAIAimTurretState::update()}const Real REL_THRESH = 0.035f; // about 2 degrees. (getRelativeAngle2D is current only accurate to about 1.25 degrees)- Bool turnAlignedToNemesis = turret->friend_turnTowardsAngle(aimAngle, turnSpeedModifier, REL_THRESH);+ // A gun that fires while it turns (the Gattling's) opens up 15 degrees out and walks its fire onto the+ // target. With the 2 degree window it held fire for as long as a turning hull kept it chasing.+ const Real FIRES_WHILE_TURNING_THRESH = 0.26f;+ Real relThresh = turret->friend_getFiresWhileTurning() ? FIRES_WHILE_TURNING_THRESH : REL_THRESH;+ Bool turnAlignedToNemesis = turret->friend_turnTowardsAngle(aimAngle, turnSpeedModifier, relThresh);// this section we do even if sweep is "disabled", so that we can start firing// once we get into sweep "range"diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex b6e0dd234..f6a788050 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -3969,9 +3969,9 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )turret is already on: a Helix flies where it likes while its gattling cannon tracks. */Coord3D faceTargetPos;const Coord3D *faceTarget = NULL;+ updateWithdrawTarget();if (m_curLocomotor->isHelicopter(getObject())){- updateWithdrawTarget();Object *target = NULL;Bool noseAims;WhichTurretType tur = getAimingTurret(&noseAims);@@ -6304,14 +6304,15 @@ Bool AIUpdateInterface::isCarriedGunOn( const Object *victim ) const//-------------------------------------------------------------------------------------------------/**- 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.+ A helicopter, or a vehicle whose gun is on a turret, told to move in the middle of a fight keeps+ shooting what it was attacking while it moves. The attack is ending (AIAttackState::onExit), so+ remember its victim; updateWithdrawTarget then holds the turret on it for as long as the unit is+ on a plain move. Only a unit 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()))+ if (victim && m_curLocomotor+ && (m_curLocomotor->isHelicopter(getObject()) || getWhichTurretForCurWeapon() != TURRET_INVALID)){m_withdrawTargetID = victim->getID();m_withdrawFrame = TheGameLogic->getFrame();@@ -6357,7 +6358,8 @@ void AIUpdateInterface::updateWithdrawTarget()return;}- if (target && tur != TURRET_INVALID && getTurretTargetObject(tur, FALSE) == target)+ // a new attack on the same target owns the turret now; letting go would drop its aim for a frame+ if (target && tur != TURRET_INVALID && getTurretTargetObject(tur, FALSE) == target && getCurrentVictim() != target)setTurretTargetObject(tur, NULL, FALSE);m_withdrawTargetID = INVALID_ID;}