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
fix(gameengine): let go of a claimed target instead of holding fire
Olcay Seygan75dcab70c9fc
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex abf097a9d..42560b3c6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -213,6 +213,7 @@ found and fixed — EA's own, not port damage.**- Damage counts the moment a shot leaves the barrel, not when it lands.- A unit says what it is about to do before it does it. Lining up a shot takes time, and a wind-up can run a second on some weapons, and for all of that time there was nothing anywhere saying the target was already being dealt with, so the second and third unit committed to it too and only found out when the first one fired. The shot is now on the books while it is still being aimed. Whoever called it first keeps the target and everyone else looks elsewhere before making the trip, not after arriving.- Once an enemy is accounted for, the rest of the group retargets.+- Soldiers in a heavy fight no longer stand there like statues. One whose target was already covered by somebody else's shot held his fire and kept the target, waiting for the others to finish it, while enemies nobody had called stood within reach. Thirty Red Guards on one burning Crusader meant a handful shooting and the rest watching. He lets that target go now and turns on the next enemy he can hit. Over five 280-unit clashes, soldiers who stood three seconds or more with an enemy in range and never fired went from 146 to 21. Replays recorded before this play out differently.- An order you gave by hand is held to rather than thrown away, but it holds its fire too. The unit keeps the target and keeps its aim and simply does not spend the round, so the volley is still in the tubes when you point the group at something else. Ordered attacks used to fire regardless, which is why a flight of four planes put all four loads into the first tank it reached.- A reservation lapses within half a second if the shot never arrives.- Ctrl+Q now takes infantry only, not every armed thing you own.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex bf04dec53..79c4a1123 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -71,6 +71,7 @@ Data/Scenarios/squad30.txtData/Scenarios/standinbuild.txtData/Scenarios/standinfake.txtData/Scenarios/stashbeside.txt+Data/Scenarios/statues.txtData/Scenarios/techrespawn.txtData/Scenarios/towncross.txtData/Scenarios/trailer_arrival.txtdiff --git a/GeneralsMD/Code/Data/Scenarios/statues.txt b/GeneralsMD/Code/Data/Scenarios/statues.txtnew file mode 100644index 000000000..ecd9943df--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/statues.txt@@ -0,0 +1,32 @@+# Statues: soldiers that stand in a heavy fight with an enemy in reach and neither move nor shoot.+#+# A player report: "where the fighting is heavy, soldiers stand like statues". Two infantry-heavy+# armies with tanks behind them attack-move into each other on Twilight Flame, and a second wave+# follows each into the same fight. HEADLESS STATUE counts every unit that stood three seconds or+# more without a shot while an enemy it could hit was inside its weapon's reach, and says what it+# was doing at that moment; the STATUE lines name the first forty.+#+# 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 2700+# -scenario statues -logPrefix statues_++30 spawn 0 AmericaInfantryRanger 50 start0:250:300 16+30 spawn 0 AmericaInfantryMissileDefender 20 start0:-250:300 16+30 spawn 0 AmericaTankCrusader 15 start0:0:300 40+30 spawn 1 ChinaInfantryRedguard 60 start1:250:300 16+30 spawn 1 ChinaInfantryTankHunter 20 start1:-250:300 16+30 spawn 1 ChinaTankBattleMaster 15 start1:0:300 40+60 attackmove 0 * start1+60 attackmove 1 * start0++900 spawn 0 AmericaInfantryRanger 40 start0:250:300 16+900 spawn 0 AmericaTankCrusader 10 start0:0:300 40+900 spawn 1 ChinaInfantryRedguard 40 start1:250:300 16+900 spawn 1 ChinaTankBattleMaster 10 start1:0:300 40+930 attackmove 0 * start1+930 attackmove 1 * start0++# What is left of each side at the end, which says whether the fight played out differently.+2690 tally 0 *+2690 tally 1 *diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex c64bf0295..a1c951057 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -5665,6 +5665,18 @@ StateReturnType AIAttackAimAtTargetState::update()if (!victim || victim->isEffectivelyDead())return STATE_FAILURE; // can't aim at dead things+ // The fire state holds the round when the victim is already paid for and falls back to aiming,+ // and aiming hands it straight back to the fire state, so a unit that keeps this victim keeps+ // holding its fire for as long as somebody else's claim covers it. In a crowd that is most of+ // a squad standing silent beside enemies nobody has claimed while a few of them whittle down+ // one target. Let go of a target we chose ourselves: the scan that chose it passes over+ // doomed ones and finds the next. An order is kept, as the fire state promises.+ if (sourceAI->getLastCommandSource() == CMD_FROM_AI &&+ IncomingDamageTracker::isSpokenFor(victim, source->getID()))+ {+ return STATE_FAILURE;+ }+// tell everyone else what this shot is going to take off the victim while it is still being// aimed, so a second unit lining up the same target can see the kill is covered before it// commits to the trip rather than on the frame the first round launches@@ -5694,16 +5706,6 @@ StateReturnType AIAttackAimAtTargetState::update()// return STATE_SUCCESS;// }- // The fire state holds the round when the victim is already paid for, and falls back to aiming,- // which is fine for a unit that leaves this state; a turret's aim never does. A Gattling Cannon- // that had picked the tank itself went silent until the booking lapsed, with a second tank- // driving up. Let go of a target we chose ourselves: the scan that chose it passes over doomed- // ones. An order is kept, as the fire state promises.- if (m_isAttackingObject && sourceAI->getLastCommandSource() == CMD_FROM_AI &&- IncomingDamageTracker::isSpokenFor(victim, source->getID()))- {- return STATE_FAILURE;- }return STATE_CONTINUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cppindex 5cc7384c6..27bc8cd53 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp@@ -49,8 +49,13 @@#include "GameLogic/TerrainLogic.h"#include "GameClient/ControlBar.h" // COMMAND_FIRED_BY_SCRIPT, the flag every script-fired power carries#include "GameClient/ParticleSys.h"+#include "GameLogic/PartitionManager.h"+#include "GameLogic/IncomingDamage.h"+#include "GameLogic/Module/BodyModule.h"+#include "GameLogic/Weapon.h"#include <algorithm>+#include <map>#include <vector>// ------------------------------------------------------------------------------------------------@@ -872,8 +877,123 @@ static void updateArrivals( UnsignedInt now )}}+/** 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. */+struct StatueTrack+{+ Coord3D lastSeenAt;+ UnsignedInt lastShot;+ Int stillFor;+ Bool counted;+ Bool seen;+};+static const Int STATUE_FRAMES = 3 * LOGICFRAMES_PER_SECOND;+static const Int STATUE_DETAIL_LINES = 40;+static std::map<ObjectID, StatueTrack> theStatueTracks;+static Int theStatueStops = 0;+static Int theStatueInfantryStops = 0;+static Int theStatueSeconds = 0;+static Int theStatueWaiting = 0;+static Int theStatueBlocked = 0;+static Int theStatueNoVictim = 0;+static Int theStatueVictimInRange = 0;+static Int theStatueVictimOutOfRange = 0;+static Int theStatueByState[ NUM_AI_STATES ];++static void updateStatues( UnsignedInt now )+{+ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )+ {+ if (!(obj->isKindOf( KINDOF_INFANTRY ) || obj->isKindOf( KINDOF_VEHICLE )) || obj->isKindOf( KINDOF_AIRCRAFT ))+ continue;+ if (obj->isEffectivelyDead() || obj->getContainedBy() != NULL || obj->isDisabled())+ continue;+ AIUpdateInterface *ai = obj->getAIUpdateInterface();+ const Weapon *weapon = obj->getCurrentWeapon();+ if (ai == NULL || weapon == NULL)+ continue;++ StatueTrack &track = theStatueTracks[ obj->getID() ];+ const Coord3D *pos = obj->getPosition();+ const Real sx = pos->x - track.lastSeenAt.x;+ const Real sy = pos->y - track.lastSeenAt.y;+ const Bool moved = sx * sx + sy * sy >= SCENARIO_STILL_DISTANCE * SCENARIO_STILL_DISTANCE;+ const Bool fired = obj->getLastShotFiredFrame() != track.lastShot;+ track.lastSeenAt = *pos;+ track.lastShot = obj->getLastShotFiredFrame();+ if (!track.seen || moved || fired)+ {+ track.seen = TRUE;+ track.stillFor = 0;+ track.counted = FALSE;+ continue;+ }+ ++track.stillFor;+ if (track.stillFor < STATUE_FRAMES || (track.stillFor % LOGICFRAMES_PER_SECOND) != 0)+ continue;++ PartitionFilterRelationship enemies( obj, PartitionFilterRelationship::ALLOW_ENEMIES );+ PartitionFilterAlive alive;+ PartitionFilterPossibleToAttack attackable( ATTACK_NEW_TARGET, obj, CMD_FROM_AI );+ PartitionFilter *filters[] = { &enemies, &alive, &attackable, NULL };+ Real enemyDist = 0.0f;+ Object *enemy = ThePartitionManager->getClosestObject( obj, weapon->getAttackRange( obj ), FROM_BOUNDINGSPHERE_2D, filters, &enemyDist );+ if (enemy == NULL)+ continue;++ ++theStatueSeconds;+ if (track.counted)+ continue;+ track.counted = TRUE;++ ++theStatueStops;+ if (obj->isKindOf( KINDOF_INFANTRY ))+ ++theStatueInfantryStops;+ const StateID state = ai->getCurrentStateID();+ if (state >= 0 && state < NUM_AI_STATES)+ ++theStatueByState[ state ];+ Object *victim = ai->getCurrentVictim();+ if (ai->isWaitingForPath())+ ++theStatueWaiting;+ else if (ai->getNumFramesBlocked() > 0 || ai->isBlockedAndStuck())+ ++theStatueBlocked;+ else if (victim == NULL)+ ++theStatueNoVictim;+ else if (weapon->isWithinAttackRange( obj, victim ))+ ++theStatueVictimInRange;+ else+ ++theStatueVictimOutOfRange;++ // "spoken for" is somebody else's shot, in the air or announced, covering what the victim has left+ if (theStatueStops <= STATUE_DETAIL_LINES)+ {+ DEBUG_LOG(("STATUE: frame %d id %d '%s' state %d idle %d waiting %d blocked %d victim %d '%s' at %.0f health %.0f spoken for %d, enemy %d '%s' at %.0f, range %.0f, weapon '%s' status %d\n",+ now, obj->getID(), obj->getTemplate()->getName().str(), (Int)state, ai->isIdle(),+ ai->isWaitingForPath(), ai->getNumFramesBlocked(),+ victim ? victim->getID() : 0, victim ? victim->getTemplate()->getName().str() : "",+ victim ? sqrt( ThePartitionManager->getDistanceSquared( obj, victim, FROM_BOUNDINGSPHERE_2D ) ) : 0.0f,+ victim ? victim->getBodyModule()->getHealth() : 0.0f,+ victim ? IncomingDamageTracker::isSpokenFor( victim, obj->getID() ) : 0,+ enemy->getID(), enemy->getTemplate()->getName().str(), enemyDist,+ weapon->getAttackRange( obj ), weapon->getName().str(), (Int)weapon->getStatus()));+ }+ }+}++static void logStatues( void )+{+ DEBUG_LOG(("HEADLESS STATUE: %d stops of %.0f s or more with an enemy in reach and no shot (%d infantry), %d unit-seconds - %d waiting for a path, %d blocked, %d no target, %d target in range, %d target out of range\n",+ theStatueStops, (Real)STATUE_FRAMES / (Real)LOGICFRAMES_PER_SECOND, theStatueInfantryStops, theStatueSeconds,+ theStatueWaiting, theStatueBlocked, theStatueNoVictim, theStatueVictimInRange, theStatueVictimOutOfRange));+ for( Int s = 0; s < NUM_AI_STATES; ++s )+ if (theStatueByState[ s ] > 0)+ DEBUG_LOG(("HEADLESS STATUE STATE: state %d, %d stops\n", s, theStatueByState[ s ]));+}+void ScenarioDrill_logArrivals( void ){+ logStatues();for( std::vector<ScenarioArrival>::const_iterator it = theScenarioArrivals.begin();it != theScenarioArrivals.end(); ++it ){@@ -1342,6 +1462,8 @@ void ScenarioDrill_tick( void )if (!theScenarioLoaded)loadScenario();+ updateStatues( now );+while (theScenarioCursor < (Int)theScenarioActions.size()&& theScenarioActions[ theScenarioCursor ].frame <= now){