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.

perf(gameengine): Comanche rocket pods fire without easing into range

Olcay Seygan3f83f25deae4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a688bfe14..5733f686b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -77,6 +77,7 @@ found and fixed — EA's own, not port damage.**
- 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.
- The Comanche's chin gun turns, as the real one does, 120 degrees either side of the nose. EA bolted the cannon and the missiles straight ahead, so a Comanche had to swing its whole body round to shoot anything. Now the missiles still fly where the nose points, and the cannon tracks on its own: making a pass along four Red Guards, a Comanche turned 34 degrees where it used to turn 132, and its gun held within 4 degrees of the target while the nose stayed on the flight. A target behind the gun's reach turns the helicopter just far enough to bring it back in.
- 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.
+- Comanches fire their rocket pods sooner. Sent at a spot 800 away, a Comanche used to ease to a stop on the very edge of range before the first rocket left; now it flies in at full speed, fires the moment the spot comes into range and brakes under its own volley. Four of them fired 6 seconds after the click, where they took 7.6 to 8.4. The rockets steer for the spot by themselves, so the helicopter no longer turns its nose to within 2 degrees of it first: a spot beside a hovering Comanche is hit 3 frames sooner, one behind it 3 frames sooner too. A Comanche whose pods are still reloading fires the moment they are full, as before. Replays recorded before this change, with a helicopter firing at the ground in them, will not play back the same.
- 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 50 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/Data/INI/BalanceReforged.ini b/GeneralsMD/Code/Data/INI/BalanceReforged.ini
index f9b77aa89..832042dd3 100644
--- a/GeneralsMD/Code/Data/INI/BalanceReforged.ini
+++ b/GeneralsMD/Code/Data/INI/BalanceReforged.ini
@@ -410,6 +410,15 @@ Object SupW_AmericaVehicleComanche
End
End
+; The rocket pods sit fixed under the nose too, and EA gave them no aim tolerance, so a Comanche
+; turned until its nose was within 2 degrees of the point before the first rocket left. The rocket
+; steers for its own spot in the spread 10 units out of the pod at 180 degrees a second, so 20
+; degrees off the nose costs it a ninth of a second of turning. A side shot fires 3 frames sooner.
+
+Weapon ComancheRocketPodWeapon
+ AcceptableAimDelta = 20 ; EA: none, the 2 degrees every weapon gets
+End
+
; ---- 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
diff --git a/GeneralsMD/Code/Data/Scenarios/comanchepods.txt b/GeneralsMD/Code/Data/Scenarios/comanchepods.txt
new file mode 100644
index 000000000..620f797b1
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/comanchepods.txt
@@ -0,0 +1,27 @@
+# Four Comanches fire their rocket pods at a spot 800 ahead of them, from the button, as the player's
+# MSG_DO_WEAPON_AT_LOCATION. The airfield buys the pods (40 seconds); the move puts them in the air
+# facing east first.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionChina -side 1 FactionAmerica -seed 7 -maxframes 2700
+# -scenario comanchepods -logPrefix comanchepods_
+#
+# Measured 2026-10-05 with a temporary log of every pod shot, frames from the order to each
+# Comanche's first rocket. The same file with the spot moved gives the other cases.
+#
+# spot before after
+# 2050 3700, 800 ahead 229-251 181-192 flies in at full speed, stops the approach in range
+# 1400 3700, 150 ahead 1-4 1 AcceptableAimDelta 20 on the pods
+# 1250 3850, 150 to the side 13-16 10-13
+# 1100 3700, 150 behind 28-31 25-28 the 180 degree turn is the rest
+#
+# A Comanche whose pods are reloading (one fired 400 frames earlier) waits out the 30 second clip
+# reload before and after, 617-620 frames, while the three beside it fire on frame 1.
+
+30 spawn 1 AmericaAirfield 1 1200 3300
+30 spawn 1 AmericaPowerPlant 2 1500 3300 60
+30 spawn 1 AmericaVehicleComanche 4 1200 3700 40
+40 shiftupgrade 1 AmericaAirfield Upgrade_ComancheRocketPods
+60 move 1 AmericaVehicleComanche 1250 3700
+1400 weaponat 1 AmericaVehicleComanche 2050 3700
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index 0c38342f6..266bb47f0 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -85,7 +85,8 @@ enum ScenarioActionType
SCENARIO_ACTION_CONSTRUCT, ///< construct <slot> <template> <position>; the local player's placement click, whatever is selected, as a message that is recorded and crosses the network
SCENARIO_ACTION_STANCE, ///< stance <slot> <selector> aggressive|defensive; the stance key, as MSG_SET_STANCE
SCENARIO_ACTION_HUNT, ///< hunt <slot> <selector> <position> [radius]; the search and destroy key's sweep, through the order queue as its messages arrive
- SCENARIO_ACTION_FORCEATTACK ///< forceattack <slot> <selector> <targetSlot> <targetSelector>; the attack key's click on one unit, as MSG_DO_FORCE_ATTACK_OBJECT
+ SCENARIO_ACTION_FORCEATTACK, ///< forceattack <slot> <selector> <targetSlot> <targetSelector>; the attack key's click on one unit, as MSG_DO_FORCE_ATTACK_OBJECT
+ SCENARIO_ACTION_WEAPONAT ///< weaponat <slot> <selector> <position> [primary|secondary|tertiary]; a FIRE_WEAPON button's click on the ground, as MSG_DO_WEAPON_AT_LOCATION; tertiary when left out
};
/// ScenarioAction::atStart when the position is plain numbers
@@ -123,7 +124,7 @@ struct ScenarioAction
Real radius; ///< how close to the target counts as arrived
Int targetSlot; ///< whose units to attack
AsciiString targetSelector; ///< which of them
- AsciiString name; ///< shiftpower's special power, shiftupgrade's upgrade
+ AsciiString name; ///< shiftpower's special power, shiftupgrade's upgrade, weaponat's weapon slot
};
/** Turn one line of a scenario file into an action. Pure: no engine state is read, which is what
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 7575956b2..71c7e9e19 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -2460,6 +2460,15 @@ static Bool canPursue(Object *source, Weapon *weapon, Object *victim)
return true;
}
+//----------------------------------------------------------------------------------------------------------
+/// a helicopter on an attack at a point on the ground (the Comanche's rocket pods), not at an object
+static Bool isHelicopterAttackingGround( const Object *source, Bool attackingObject )
+{
+ const AIUpdateInterface *ai = attackingObject ? NULL : source->getAI(); // none once the machine is being deleted
+ const Locomotor *loco = ai ? ai->getCurLocomotor() : NULL;
+ return loco != NULL && loco->isHelicopter(source);
+}
+
//----------------------------------------------------------------------------------------------------------
/**
* Compute a valid spot to fire our weapon from.
@@ -2702,6 +2711,11 @@ StateReturnType AIAttackApproachTargetState::onEnter()
} else {
// Attacking a position. For a varitey of reasons, we need to destroy any existing path or we spin. jba. [8/25/2003]
ai->destroyPath();
+ // A helicopter ordered to fire at the ground flies on at full speed and stops the approach the moment
+ // the point comes into range (updateInternal). Easing to a stop on the edge of range first cost a
+ // Comanche 1.5 seconds of an 800 run before its rocket pods fired.
+ if (isHelicopterAttackingGround(source, m_isAttackingObject))
+ ai->getCurLocomotor()->setNoSlowDownAsApproachingDest(TRUE);
}
// If we have a turret, start aiming.
WhichTurretType tur = ai->getWhichTurretForCurWeapon();
@@ -2806,7 +2820,7 @@ StateReturnType AIAttackApproachTargetState::updateInternal()
// Attacking a position.
// find a good spot to shoot from
//CRCDEBUG_LOG(("AIAttackApproachTargetState::updateInternal() - calling computePath() to position for object %d\n", getMachineOwner()->getID()));
- if (m_stopIfInRange && weapon && weapon->isWithinAttackRange(source, &m_goalPosition))
+ if ((m_stopIfInRange || isHelicopterAttackingGround(source, m_isAttackingObject)) && weapon && weapon->isWithinAttackRange(source, &m_goalPosition))
{
Bool viewBlocked = false;
if ( ai->isDoingGroundMovement() )
@@ -2872,6 +2886,9 @@ void AIAttackApproachTargetState::onExit( StateExitType status )
// contained by AIAttackState, so no separate timer
AIInternalMoveToState::onExit( status );
+ if (isHelicopterAttackingGround(getMachineOwner(), m_isAttackingObject))
+ getMachineOwner()->getAI()->getCurLocomotor()->setNoSlowDownAsApproachingDest(FALSE);
+
AIUpdateInterface *ai = getMachineOwner()->getAI();
Object *obj = getMachineOwner();
if (ai) {
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index 853042319..c89b56c34 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -221,6 +221,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_HUNT;
else if (token == "forceattack")
*action = SCENARIO_ACTION_FORCEATTACK;
+ else if (token == "weaponat")
+ *action = SCENARIO_ACTION_WEAPONAT;
else
return FALSE;
@@ -304,6 +306,7 @@ static Int tokensNeededFor( ScenarioActionType action )
case SCENARIO_ACTION_SHIFTGUARD: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_CONSTRUCT: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_HUNT: return SCENARIO_TOKENS_MOVE;
+ case SCENARIO_ACTION_WEAPONAT: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_STANCE: return SCENARIO_TOKENS_STANCE;
case SCENARIO_ACTION_SHIFTATTACK: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_FORCEATTACK: return SCENARIO_TOKENS_ATTACK;
@@ -387,11 +390,18 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
case SCENARIO_ACTION_SHIFTGUARD:
case SCENARIO_ACTION_CONSTRUCT:
case SCENARIO_ACTION_HUNT:
+ case SCENARIO_ACTION_WEAPONAT:
{
Int next = SCENARIO_ORDER_POSITION_TOKEN;
const ScenarioParseResult position = parseScenarioPosition( tokens, count, &next, action );
if (position != SCENARIO_PARSE_OK)
return position;
+ if (actionType == SCENARIO_ACTION_WEAPONAT)
+ {
+ action->name = (count > next) ? tokens[ next ] : AsciiString( "tertiary" );
+ if (action->name != "primary" && action->name != "secondary" && action->name != "tertiary")
+ return SCENARIO_PARSE_BAD_ACTION;
+ }
if (actionType == SCENARIO_ACTION_HUNT)
action->radius = (count > next) ? (Real)atof( tokens[ next ].str() ) : SCENARIO_DEFAULT_SWEEP_RADIUS;
if (actionType == SCENARIO_ACTION_ARRIVE && count > next)
@@ -1362,6 +1372,28 @@ static Bool executeForceAttack( const ScenarioAction &action, Player *player, AI
return TRUE;
}
+/** A FIRE_WEAPON button with NEED_TARGET_POS, clicked on the ground (the Comanche's rocket pods): the
+ arguments GUICommandTranslator gives MSG_DO_WEAPON_AT_LOCATION, the button's default shot count and
+ nothing under the cursor, handed to the dispatcher with the matching units as the selection. The
+ dispatcher destroys the group. */
+static Bool executeWeaponAt( const ScenarioAction &action, Player *player, const Coord3D &dest, AIGroup *group, Int taken )
+{
+ const WeaponSlotType weaponSlot = (action.name == "primary") ? PRIMARY_WEAPON
+ : (action.name == "secondary") ? SECONDARY_WEAPON : TERTIARY_WEAPON;
+ GameMessage *msg = newInstance( GameMessage )( GameMessage::MSG_DO_WEAPON_AT_LOCATION );
+ msg->friend_setPlayerIndex( player->getPlayerIndex() );
+ msg->appendIntegerArgument( weaponSlot );
+ msg->appendLocationArgument( dest );
+ msg->appendIntegerArgument( 0x7fffffff ); // CommandButton's MaxShotsToFire when the INI says none
+ msg->appendObjectIDArgument( INVALID_ID );
+ TheGameLogic->logicMessageDispatcher( msg, group );
+ msg->deleteInstance();
+
+ DEBUG_LOG(("SCENARIO: frame %d weaponat slot %d '%s' x%d %s at (%.0f,%.0f)\n",
+ action.frame, action.slot, action.selector.str(), taken, action.name.str(), dest.x, dest.y));
+ return TRUE;
+}
+
/** The search and destroy key: the ring sweepRoute gives this seat round the point, from where the
units stand, each point handed to the order queue the way the key's messages arrive - the first
fresh, the rest behind it - and then a guard of the whole circle. Each message gets a group of
@@ -1500,6 +1532,9 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
case SCENARIO_ACTION_FORCEATTACK:
return executeForceAttack( action, player, group, taken ); // so does this, or it does itself
+ case SCENARIO_ACTION_WEAPONAT:
+ return executeWeaponAt( action, player, dest, group, taken ); // the dispatcher again
+
case SCENARIO_ACTION_HUNT:
return executeSweep( action, player, dest, group, taken ); // and so does this
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 42a79c816..190afb13c 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -15018,6 +15018,14 @@ TEST(scenario_parses_the_order_lines)
CHECK_STR( action.targetSelector.str(), "GLAVehicleTechnical*" );
CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 forceattack 0 * 1", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "1400 weaponat 1 AmericaVehicleComanche 2050 3700", &action ), (Int)SCENARIO_PARSE_OK );
+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_WEAPONAT );
+ CHECK_NEAR( action.at.x, 2050.0f, 0.01f );
+ CHECK_STR( action.name.str(), "tertiary" );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "1400 weaponat 1 * start0:100:0 primary", &action ), (Int)SCENARIO_PARSE_OK );
+ CHECK_STR( action.name.str(), "primary" );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "1400 weaponat 1 * 2050 3700 quaternary", &action ), (Int)SCENARIO_PARSE_BAD_ACTION );
+
CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftpower 0 * 1 AmericaSupplyCenter SpecialAbilityBlackLotusCaptureBuilding",
&action ), (Int)SCENARIO_PARSE_OK );
CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTPOWER );