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.

fix(gameengine): attack-ground fires from where the unit stands

Olcay Seygan95e224a4e179
diff --git a/CHANGELOG.md b/CHANGELOG.md
index de91bfb63..68e9ac519 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -63,6 +63,7 @@ found and fixed — EA's own, not port damage.**
- 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.
+- Tell a tank to fire at the ground and it fires from where it stands. On any slope the game read the spot as hidden behind the very hill it was lying on, so a tank with the spot well inside its range drove off looking for a better angle, swinging its hull round under its own turret, and fired on the way. Pulled off a building to shell the ground 140 behind them, a Battlemaster took 84 frames to its first shell on the new spot and now takes 45, which is how long its turret needs to come round, and a pair of Scorpions that used to wander about 200 away over eight seconds now stay where they were put. Replays recorded before this play back differently.
## Flares on the planes, lasers in clips on the tanks
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 8fa63647e..2d726c706 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -155,6 +155,7 @@ Data/Scenarios/mobopen.txt
Data/Scenarios/mobstress.txt
Data/Scenarios/mobwin.txt
Data/Scenarios/netstance.txt
+Data/Scenarios/obeyorders.txt
Data/Scenarios/overlordbridge.txt
Data/Scenarios/overlordlong.txt
Data/Scenarios/parade.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/obeyorders.txt b/GeneralsMD/Code/Data/Scenarios/obeyorders.txt
new file mode 100644
index 000000000..acf400028
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/obeyorders.txt
@@ -0,0 +1,69 @@
+# How fast a vehicle in the middle of a fight takes up a new order. Five rows of two vehicles each
+# shell a building 150 east of them. At frame 240 every row is told to attack the ground 120 behind
+# it (the attack key on open ground), at 480 to attack its building again, and at 720 to drive 200
+# west. respond lines measure, from the order, the frames to the gun pointing within 15 degrees of
+# the new point, to the first shot fired with it pointed there, and to standing 20 closer.
+#
+# 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 900
+# -scenario obeyorders -logPrefix obey_
+#
+# Measured 2026-10-06 (HEADLESS RESPOND, frames from the frame-240 ground order, mean/worst). Before,
+# the terrain line test read the ground point as hidden for one Battlemaster and both Scorpions; they
+# took an approach path to a "clear" spot (the Scorpions to 905,4015, 140 off) and drove there with
+# the turret firing: Battlemaster aimed 61.5/81, first aimed shot 64.5/84; Scorpions wandered about
+# 200 and their frame-480 re-attack fired 166/184. After (the point looked at from the shooter's
+# height): Battlemaster aimed 42/42, shot 45/45; Scorpions stand, re-attack shot 54/54. Crusader
+# 28/42, Rocket Buggy 56/60 and Tomahawk (mid clip reload) unchanged: turret turn and reload.
+
+10 spawn 1 ChinaCommandCenter 1 1260 3500
+10 spawn 1 ChinaWarFactory 1 1260 3700
+10 spawn 1 ChinaBarracks 1 1260 3900
+10 spawn 1 ChinaSupplyCenter 1 1260 4100
+10 spawn 1 ChinaPropagandaCenter 1 1260 4300
+
+20 spawn 0 AmericaTankCrusader 2 1100 3500 40
+20 spawn 0 ChinaTankBattleMaster 2 1100 3700 40
+20 spawn 0 GLATankScorpion 2 1100 3900 40
+20 spawn 0 GLAVehicleRocketBuggy 2 1100 4100 40
+20 spawn 0 AmericaVehicleTomahawk 2 1100 4300 40
+
+40 forceattack 0 AmericaTankCrusader 1 ChinaCommandCenter
+40 forceattack 0 ChinaTankBattleMaster 1 ChinaWarFactory
+40 forceattack 0 GLATankScorpion 1 ChinaBarracks
+40 forceattack 0 GLAVehicleRocketBuggy 1 ChinaSupplyCenter
+40 forceattack 0 AmericaVehicleTomahawk 1 ChinaPropagandaCenter
+
+240 forceground 0 AmericaTankCrusader 980 3500
+240 forceground 0 ChinaTankBattleMaster 980 3700
+240 forceground 0 GLATankScorpion 980 3900
+240 forceground 0 GLAVehicleRocketBuggy 980 4100
+240 forceground 0 AmericaVehicleTomahawk 980 4300
+240 respond 0 AmericaTankCrusader 980 3500
+240 respond 0 ChinaTankBattleMaster 980 3700
+240 respond 0 GLATankScorpion 980 3900
+240 respond 0 GLAVehicleRocketBuggy 980 4100
+240 respond 0 AmericaVehicleTomahawk 980 4300
+
+480 forceattack 0 AmericaTankCrusader 1 ChinaCommandCenter
+480 forceattack 0 ChinaTankBattleMaster 1 ChinaWarFactory
+480 forceattack 0 GLATankScorpion 1 ChinaBarracks
+480 forceattack 0 GLAVehicleRocketBuggy 1 ChinaSupplyCenter
+480 forceattack 0 AmericaVehicleTomahawk 1 ChinaPropagandaCenter
+480 respond 0 AmericaTankCrusader 1260 3500
+480 respond 0 ChinaTankBattleMaster 1260 3700
+480 respond 0 GLATankScorpion 1260 3900
+480 respond 0 GLAVehicleRocketBuggy 1260 4100
+480 respond 0 AmericaVehicleTomahawk 1260 4300
+
+720 playermove 0 AmericaTankCrusader 900 3500
+720 playermove 0 ChinaTankBattleMaster 900 3700
+720 playermove 0 GLATankScorpion 900 3900
+720 playermove 0 GLAVehicleRocketBuggy 900 4100
+720 playermove 0 AmericaVehicleTomahawk 900 4300
+720 respond 0 AmericaTankCrusader 900 3500
+720 respond 0 ChinaTankBattleMaster 900 3700
+720 respond 0 GLATankScorpion 900 3900
+720 respond 0 GLAVehicleRocketBuggy 900 4100
+720 respond 0 AmericaVehicleTomahawk 900 4300
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index 266bb47f0..f13491a61 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -86,7 +86,9 @@ enum ScenarioActionType
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_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
+ 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
+ SCENARIO_ACTION_FORCEGROUND, ///< forceground <slot> <selector> <position>; the attack key's click on the ground, as MSG_DO_FORCE_ATTACK_GROUND
+ SCENARIO_ACTION_RESPOND ///< respond <slot> <selector> <position>; from now, how long each unit takes to point its gun at the position, fire with it pointed there, and get closer to it
};
/// ScenarioAction::atStart when the position is plain numbers
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index 2d2e4f40b..050f5a301 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@ -11429,7 +11429,17 @@ Bool Pathfinder::isAttackViewBlockedByObstacle(const Object* attacker, const Coo
if (victim)
viewBlocked = !w->isClearGoalFiringLineOfSightTerrain(attacker, attackerPos, victim);
else
- viewBlocked = !w->isClearGoalFiringLineOfSightTerrain(attacker, attackerPos, victimPos);
+ {
+ // A point on open ground lies on the terrain itself, and the line test takes the highest
+ // corner of every cell it crosses, so on any slope the cells just short of the point stood
+ // above it and the shot read as blocked. A tank told to shell the ground in range then drove
+ // off looking for a clear spot, turning its hull under its turret, before it fired. Look at
+ // the point the way an object target is looked at: something standing there, as tall as the
+ // shooter.
+ Coord3D aimPos = victimPos;
+ aimPos.z += attacker->getGeometryInfo().getMaxHeightAbovePosition();
+ viewBlocked = !w->isClearGoalFiringLineOfSightTerrain(attacker, attackerPos, aimPos);
+ }
if (viewBlocked)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index c89b56c34..a941cef1b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -223,6 +223,10 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_FORCEATTACK;
else if (token == "weaponat")
*action = SCENARIO_ACTION_WEAPONAT;
+ else if (token == "forceground")
+ *action = SCENARIO_ACTION_FORCEGROUND;
+ else if (token == "respond")
+ *action = SCENARIO_ACTION_RESPOND;
else
return FALSE;
@@ -307,6 +311,8 @@ static Int tokensNeededFor( ScenarioActionType action )
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_FORCEGROUND: return SCENARIO_TOKENS_MOVE;
+ case SCENARIO_ACTION_RESPOND: 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;
@@ -391,6 +397,8 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
case SCENARIO_ACTION_CONSTRUCT:
case SCENARIO_ACTION_HUNT:
case SCENARIO_ACTION_WEAPONAT:
+ case SCENARIO_ACTION_FORCEGROUND:
+ case SCENARIO_ACTION_RESPOND:
{
Int next = SCENARIO_ORDER_POSITION_TOKEN;
const ScenarioParseResult position = parseScenarioPosition( tokens, count, &next, action );
@@ -522,9 +530,29 @@ static const Real SCENARIO_DEPARTED_DISTANCE = 20.0f;
static std::vector<ScenarioArrival> theScenarioArrivals;
+/** One respond line: how quickly each unit it matched took up the order given on that frame. Aim is the
+ first frame its gun (the turret the current weapon is on, or the hull) points within
+ SCENARIO_RESPOND_AIM of the position; shot the first frame it fires with the gun pointed there; closer
+ the first frame it stands SCENARIO_DEPARTED_DISTANCE nearer the position than it started. Read-only. */
+struct ScenarioResponse
+{
+ Int slot;
+ AsciiString selector;
+ Coord3D goal;
+ UnsignedInt fromFrame;
+ std::vector<ObjectID> ids;
+ std::vector<Real> startDist;
+ std::vector<UnsignedInt> aimOn;
+ std::vector<UnsignedInt> shotOn;
+ std::vector<UnsignedInt> closerOn;
+};
+static const Real SCENARIO_RESPOND_AIM = 0.26f; // 15 degrees
+static std::vector<ScenarioResponse> theScenarioResponses;
+
static void resetScenario( void )
{
theScenarioArrivals.clear();
+ theScenarioResponses.clear();
theScenarioActions.clear();
theScenarioCursor = 0;
theScenarioLoaded = FALSE;
@@ -913,6 +941,100 @@ static void updateArrivals( UnsignedInt now )
}
}
+static Real distanceTo2D( const Object *obj, const Coord3D &goal )
+{
+ const Real dx = obj->getPosition()->x - goal.x;
+ const Real dy = obj->getPosition()->y - goal.y;
+ return (Real)sqrt( dx * dx + dy * dy );
+}
+
+static Bool executeRespond( const ScenarioAction &action, Player *player, const Coord3D &goal )
+{
+ ScenarioResponse response;
+ response.slot = action.slot;
+ response.selector = action.selector;
+ response.goal = goal;
+ response.fromFrame = TheGameLogic->getFrame();
+ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
+ {
+ if (!isOrderableMatch( player, action.selector, obj ))
+ continue;
+ response.ids.push_back( obj->getID() );
+ response.startDist.push_back( distanceTo2D( obj, goal ) );
+ response.aimOn.push_back( SCENARIO_NOT_ARRIVED );
+ response.shotOn.push_back( SCENARIO_NOT_ARRIVED );
+ response.closerOn.push_back( SCENARIO_NOT_ARRIVED );
+ }
+ DEBUG_LOG(("SCENARIO: frame %d respond slot %d '%s' x%d at (%.0f,%.0f)\n",
+ action.frame, action.slot, action.selector.str(), (Int)response.ids.size(), goal.x, goal.y));
+ if (response.ids.empty())
+ return FALSE;
+ theScenarioResponses.push_back( response );
+ return TRUE;
+}
+
+static void updateResponses( UnsignedInt now )
+{
+ for( std::vector<ScenarioResponse>::iterator it = theScenarioResponses.begin(); it != theScenarioResponses.end(); ++it )
+ {
+ for( size_t i = 0; i < it->ids.size(); ++i )
+ {
+ Object *obj = TheGameLogic->findObjectByID( it->ids[ i ] );
+ if (obj == NULL || obj->isEffectivelyDead() || now <= it->fromFrame)
+ continue;
+
+ const AIUpdateInterface *ai = obj->getAIUpdateInterface();
+ Real gunAngle = 0.0f;
+ Real pitch = 0.0f;
+ const WhichTurretType tur = ai ? ai->getWhichTurretForCurWeapon() : TURRET_INVALID;
+ if (tur != TURRET_INVALID)
+ ai->getTurretRotAndPitch( tur, &gunAngle, &pitch );
+ const Bool aimed = fabs( normalizeAngle( ThePartitionManager->getRelativeAngle2D( obj, &it->goal ) - gunAngle ) ) <= SCENARIO_RESPOND_AIM;
+ if (aimed && it->aimOn[ i ] == SCENARIO_NOT_ARRIVED)
+ it->aimOn[ i ] = now;
+
+ const Weapon *weapon = obj->getCurrentWeapon();
+ // the tick runs before the objects do, so last frame's shot is the newest one there is to see
+ if (aimed && weapon && weapon->getLastShotFrame() + 1 >= now && weapon->getLastShotFrame() > it->fromFrame
+ && it->shotOn[ i ] == SCENARIO_NOT_ARRIVED)
+ it->shotOn[ i ] = weapon->getLastShotFrame();
+
+ if (it->closerOn[ i ] == SCENARIO_NOT_ARRIVED && distanceTo2D( obj, it->goal ) <= it->startDist[ i ] - SCENARIO_DEPARTED_DISTANCE)
+ it->closerOn[ i ] = now;
+ }
+ }
+}
+
+/** Mean and worst frames from the line to each of the three marks, over the units that reached it. */
+static void logResponses( void )
+{
+ for( std::vector<ScenarioResponse>::const_iterator it = theScenarioResponses.begin(); it != theScenarioResponses.end(); ++it )
+ {
+ const std::vector<UnsignedInt> *marks[ 3 ] = { &it->aimOn, &it->shotOn, &it->closerOn };
+ Int count[ 3 ] = { 0, 0, 0 };
+ Real sum[ 3 ] = { 0.0f, 0.0f, 0.0f };
+ Int worst[ 3 ] = { 0, 0, 0 };
+ for( Int m = 0; m < 3; ++m )
+ {
+ for( size_t i = 0; i < it->ids.size(); ++i )
+ {
+ const UnsignedInt on = (*marks[ m ])[ i ];
+ if (on == SCENARIO_NOT_ARRIVED)
+ continue;
+ const Int frames = (Int)(on - it->fromFrame);
+ ++count[ m ];
+ sum[ m ] += (Real)frames;
+ worst[ m ] = (frames > worst[ m ]) ? frames : worst[ m ];
+ }
+ }
+ DEBUG_LOG(("HEADLESS RESPOND: slot %d '%s' from frame %d at (%.0f,%.0f), %d units: aimed %d mean %.1f worst %d, fired %d mean %.1f worst %d, closer %d mean %.1f worst %d\n",
+ it->slot, it->selector.str(), it->fromFrame, it->goal.x, it->goal.y, (Int)it->ids.size(),
+ count[ 0 ], count[ 0 ] ? sum[ 0 ] / count[ 0 ] : 0.0f, worst[ 0 ],
+ count[ 1 ], count[ 1 ] ? sum[ 1 ] / count[ 1 ] : 0.0f, worst[ 1 ],
+ count[ 2 ], count[ 2 ] ? sum[ 2 ] / count[ 2 ] : 0.0f, worst[ 2 ]));
+ }
+}
+
/** Statues: a unit with an enemy it could shoot inside its own reach that has neither moved nor fired
for STATUE_FRAMES. Counted once per stop, by what the unit was doing when it reached the mark,
and per second for as long as it keeps standing there. Read-only, and only with a scenario. */
@@ -1028,6 +1150,7 @@ static void logStatues( void )
void ScenarioDrill_logArrivals( void )
{
logStatues();
+ logResponses();
for( std::vector<ScenarioArrival>::const_iterator it = theScenarioArrivals.begin();
it != theScenarioArrivals.end(); ++it )
{
@@ -1535,6 +1658,19 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
case SCENARIO_ACTION_WEAPONAT:
return executeWeaponAt( action, player, dest, group, taken ); // the dispatcher again
+ case SCENARIO_ACTION_FORCEGROUND:
+ {
+ // the attack key's click on open ground, through the dispatcher, which destroys the group
+ GameMessage *msg = newInstance( GameMessage )( GameMessage::MSG_DO_FORCE_ATTACK_GROUND );
+ msg->friend_setPlayerIndex( player->getPlayerIndex() );
+ msg->appendLocationArgument( dest );
+ TheGameLogic->logicMessageDispatcher( msg, group );
+ msg->deleteInstance();
+ DEBUG_LOG(("SCENARIO: frame %d forceground slot %d '%s' x%d at (%.0f,%.0f)\n",
+ action.frame, action.slot, action.selector.str(), taken, dest.x, dest.y));
+ return TRUE;
+ }
+
case SCENARIO_ACTION_HUNT:
return executeSweep( action, player, dest, group, taken ); // and so does this
@@ -1552,6 +1688,7 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
case SCENARIO_ACTION_POWER:
case SCENARIO_ACTION_PRODUCE:
case SCENARIO_ACTION_TALLY:
+ case SCENARIO_ACTION_RESPOND:
ordered = FALSE; // handled before the group is built
break;
}
@@ -1606,6 +1743,9 @@ Bool ScenarioDrill_execute( const ScenarioAction &action )
if (action.action == SCENARIO_ACTION_ARRIVE)
return executeArrive( action, player, position );
+ if (action.action == SCENARIO_ACTION_RESPOND)
+ return executeRespond( action, player, position );
+
if (action.action == SCENARIO_ACTION_POWER)
return executePower( action, player, position );
@@ -1641,6 +1781,7 @@ void ScenarioDrill_tick( void )
// before the file test, because an arrive typed down the control socket has no file behind it
updateArrivals( now );
+ updateResponses( now );
if (TheGlobalData->m_scenarioFile.isEmpty())
return;
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 5bf06a9b0..2a1e0ec6e 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -15143,6 +15143,14 @@ TEST(scenario_parses_the_order_lines)
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( "240 forceground 0 AmericaTankCrusader 980 3500", &action ), (Int)SCENARIO_PARSE_OK );
+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_FORCEGROUND );
+ CHECK_NEAR( action.at.y, 3500.0f, 0.01f );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "240 respond 0 * start0:-120:0", &action ), (Int)SCENARIO_PARSE_OK );
+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_RESPOND );
+ CHECK_EQ( action.atStart, 0 );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "240 respond 0 *", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );
+
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 );