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): let groups spread over a bridge deck
Olcay Seyganef746ffa5b58
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 03db89915..a68db7253 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -184,6 +184,8 @@ found and fixed — EA's own, not port damage.**- Tanks and infantry sent together no longer trip over each other. A tank that caught up with a soldier of its own side marching the same way told him to step aside, and a soldier who steps aside forgets his route and stands for a full second before he may ask for another. In a mixed squad of 20 Crusaders and 10 Rangers every one of the 28 second-long stops across eight maps was exactly that. The tank now rolls through a soldier walking its way, the way soldiers already walk through each other; one standing still or crossing its path is still asked to move. Stops of a second or more fell from 48 to 12 in that squad and from 977 to 546 in a 200-unit army, and both arrive sooner: the last Crusader 2.5 seconds earlier, the whole army 1.9 seconds earlier on average. In computer-against-computer matches, time spent wedged fell 11%.- Two columns that meet head-on get past each other. The game has a rule for it, written by the original team: two tanks nose to nose for a second drive through each other. A counter that reset itself every frame meant it never once fired, so the front pair stood there, sometimes for more than seven seconds, and everything behind them queued. It fires now, after a quarter of a second. Twenty tanks meeting twenty in the open used to stop 104 times and bring the last one in after 72 seconds; now they stop once, and the last one arrives after 23. Two armies of 420 crossing the map through each other get there in half the time: the Crusaders' average trip went from 167 seconds to 91, the Battlemasters' from 149 to 75.- A group you send round a corner goes round it side by side. Every tank used to work out its own route, every one of those routes ran over the tip of the corner, and the whole group squeezed onto that one point with the outside tanks cutting across the inside ones to reach it. Now the group takes one route and each vehicle drives its own lane of it: the outside lane swings wide, the inside one stays clear of the wall, and where the street narrows the lanes close up over a few corners rather than zigzagging. A tank whose place is short of the click stops at it, instead of driving its lane to the far end and coming back. Twenty-four tanks sent through the streets of Alpine Assault came to a dead stop 7 times a crossing instead of 10 and spent a third less time pressed against each other, and the column in the Forgotten Forest trailer scene gets its last tank home 20 seconds sooner. Infantry, and any group whose route crosses a bridge, still find their own way. A replay recorded before this change plays back differently.+- A group spreads out over a bridge instead of crossing it in single file. Every bridge used to count as one lane wide, so a group closed up into a queue on the bank and went over one tank at a time, even though the Kandahar bridge on Golden Oasis carries three Crusaders abreast. The deck now keeps its real width, and the lanes close up to that width just before the ramp, so the tanks on the flanks come onto the ramp instead of nosing into the end of the railing beside it. Twenty Crusaders over the Kandahar bridge get their last tank across four seconds sooner.+- No tank is left under a bridge any more. A tank that came up beside a ramp instead of onto it could drive on underneath the deck and sit there at full throttle for the rest of the match, shaking against the side of the ramp while it tried to reach the deck over its head; it was never counted as stuck, because shaking looks like moving. One tank in ten sent over the long bridge on Golden Oasis never got across that way. A tank shaking on the spot next to a bridge on its route now asks for a new way round to the ramp, and twenty out of twenty get across.- A jet shot down in the air flies on before it falls. Its wings stopped working on the frame it was hit, so it dropped almost vertically and hit the ground under the spot it was killed at, which is the one thing a plane doing three hundred knots cannot do. It keeps its lift now and gives it up over the next second or so, carrying forward and nosing over as it goes.- And the bombers come down at all. A B-52, a Spectre gunship, a cargo plane and an A-10 all left the falling speed out of their data, and nought means the lift exactly cancels gravity: shot down, they flew on at cruising height, burning, and blew up in the air still level. Every one of them now falls at half gravity or better, and the fireball waits for the ground instead of going off on a timer somewhere over the map. Measured on the way in: a B-52 falls for 2.8 seconds and lands, where it used to detonate at a hundred feet. On the way home it still did not: after the drop a bomber flies off the map on a precise course that is allowed three times its normal lift, which held a dead one up with lift to spare. A bomber shot down after its run now comes down like one shot down before it.diff --git a/GeneralsMD/Code/Data/Scenarios/bridgelong.txt b/GeneralsMD/Code/Data/Scenarios/bridgelong.txtnew file mode 100644index 000000000..65d708161--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/bridgelong.txt@@ -0,0 +1,16 @@+# Long bridge crossing.+#+# Twenty tanks, one right click, over the long bridge in the east of Golden Oasis, whose deck runs+# from 2637,1165 to 2948,1550 and is about twelve cells wide: three Crusaders abreast. The start and+# the goal sit 350 units back from each end of the deck, on its line. bridgecross.txt is the short+# Kandahar bridge; this one is long enough that a group either spreads across the deck or spends+# the whole crossing in single file.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Golden Oasis\Golden Oasis.map" -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 4000+# -scenario bridgelong -logPrefix bridgelong_++30 spawn 0 AmericaTankCrusader 20 2417 893 40+60 playermove 0 AmericaTankCrusader 3168 1822+60 arrive 0 AmericaTankCrusader 3168 1822 200diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/CrowdModel.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/CrowdModel.hindex 05c18ee68..5e2bcab28 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/CrowdModel.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/CrowdModel.h@@ -64,10 +64,10 @@ enum/// a lane taken to get round somebody is held this long, so it cannot flap side to sideCROWD_HOLD_FRAMES = 45,- /* How many samples either side of a bridge lose their band as well, so the approach funnels in.- Six cells and not four: a unit that is still a lane wide of the centre when the band shuts is- a unit arriving at the abutment sideways, and the sideways step is rate-limited to a quarter- of its speed. The funnel has to be longer than the time that step takes. */+ /* How many samples either side of a bridge are held to the deck's width, so the approach funnels+ in. Six cells and not four: a unit that is still a lane wide of the deck when the band shuts+ is a unit arriving at the abutment sideways, and the sideways step is rate-limited to a+ quarter of its speed. The funnel has to be longer than the time that step takes. */CROWD_BRIDGE_SEAL = 6,/// how far ahead of itself a unit steers, in cells, before its own body length is added@@ -178,10 +178,11 @@ public:void buildForTest( const Coord3D *pts, Int count, Real halfWidth,const PathfindLayerEnum *layers = NULL, const Real *halfWidths = NULL );- /// close the band on every bridge deck and on the ground either side of one+ /// hold the ground either side of every bridge deck to a funnel onto the deck's own widthvoid sealBridges( void );private:+ void holdApproach( Int end, Int step ); ///< see sealBridges/// the sample at or before `along`, with the fraction of the way to the next oneInt bracket( Real along, Real *frac ) const;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/CrowdModel.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/CrowdModel.cppindex 5c5f340d8..06e34a403 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/CrowdModel.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/CrowdModel.cpp@@ -195,15 +195,19 @@ Bool CrowdCorridor::build( const Object *obj, const LocomotorSet& locomotorSet,/* Smooth the two width curves. A single sample that happened to land beside a rock reports ametre of road in the middle of a field, and a lane clamped to that one sample jerks sideways- and back again over two frames. Two [1 2 1] passes, which is what the sandbox settled on. */+ and back again over two frames. Two [1 2 1] passes, which is what the sandbox settled on.+ Never across a change of deck: the riverbank either side of a bridge is a field, and averaged+ into the deck it widens the first cells of the bridge by half a field. */const Int n = (Int)m_samples.size();std::vector<Real> tmpL( n ), tmpR( n );for (Int pass = 0; pass < 2; pass++){for (Int i = 0; i < n; i++){- const Int p = (i > 0) ? i - 1 : 0;- const Int q = (i < n - 1) ? i + 1 : n - 1;+ Int p = (i > 0) ? i - 1 : 0;+ Int q = (i < n - 1) ? i + 1 : n - 1;+ if (m_samples[ p ].layer != m_samples[ i ].layer) p = i;+ if (m_samples[ q ].layer != m_samples[ i ].layer) q = i;tmpL[ i ] = (m_samples[ p ].left + 2.0f * m_samples[ i ].left + m_samples[ q ].left) * 0.25f;tmpR[ i ] = (m_samples[ p ].right + 2.0f * m_samples[ i ].right + m_samples[ q ].right) * 0.25f;}@@ -220,16 +224,16 @@ Bool CrowdCorridor::build( const Object *obj, const LocomotorSet& locomotorSet,}//--------------------------------------------------------------------------------------------------/** A bridge has no band, and neither does the ground each side of one.-- Probing the right deck already reports a bridge as narrow, but narrow is not the same as- single file: half a lane of drift is enough to put a tank over the railing, and the roadway is- a different width from the pathfind cells that carry it. The approach matters as much as the- deck. A unit holding a lane a body width off centre while it rolls up to a bridge arrives- beside the entrance rather than at it, stops against the abutment, and every unit behind it- queues on the bank - which is the not getting onto the bridge at all. So the band closes- CROWD_BRIDGE_SEAL samples before the deck starts and opens the same distance after it ends,- and inside that stretch every unit drives the centre line exactly the way retail does. */+/** The ground each side of a bridge is no wider than the bridge.++ The deck keeps the band its own layer measured: a bridge is a road, and the Kandahar bridge on+ Golden Oasis carries three Crusaders abreast. It used to be sealed to the centre line, which+ put a whole group through it in single file. What does matter is the approach. The bank+ either side of the ramp is open field, and a unit holding a lane a field's width off the+ centre rolls up beside the entrance rather than onto it and stops against the abutment, with+ every unit behind it queueing on the bank. So for CROWD_BRIDGE_SEAL samples before the deck+ starts and after it ends the band is held to the deck's own width at that end, and the lanes+ come onto the ramp already the width of the road they are about to drive. *///-------------------------------------------------------------------------------------------------void CrowdCorridor::sealBridges( void ){@@ -240,17 +244,36 @@ void CrowdCorridor::sealBridges( void )if (m_samples[ i ].layer <= LAYER_GROUND)continue;- Int lo = i - CROWD_BRIDGE_SEAL;- Int hi = i + CROWD_BRIDGE_SEAL;- if (lo < 0) lo = 0;- if (hi > n - 1) hi = n - 1;- for (Int j = lo; j <= hi; j++)- {- m_samples[ j ].left = 0.0f;- m_samples[ j ].right = 0.0f;- }+ // only the ends of a run of deck samples have an approach, and it runs outward from them+ const Bool first = i == 0 || m_samples[ i - 1 ].layer != m_samples[ i ].layer;+ const Bool last = i == n - 1 || m_samples[ i + 1 ].layer != m_samples[ i ].layer;+ if (first)+ holdApproach( i, -1 );+ if (last)+ holdApproach( i, 1 );}+}+//-------------------------------------------------------------------------------------------------+/** The approach to one end of a deck, from the deck end at sample `end` outward in `step`:+ CROWD_BRIDGE_SEAL samples held to the deck's own width at the ramp.++ A funnel instead, opening back from the ramp as fast as a unit may slide sideways, was tried+ and measured worse: it squeezed the group into the deck's width a long way out, and twenty+ Crusaders over the Kandahar bridge took longer and were blocked more than with this. */+//-------------------------------------------------------------------------------------------------+void CrowdCorridor::holdApproach( Int end, Int step )+{+ const Int n = (Int)m_samples.size();+ const Sample& deck = m_samples[ end ];+ for (Int k = 1; k <= CROWD_BRIDGE_SEAL; k++)+ {+ const Int j = end + k * step;+ if (j < 0 || j >= n || m_samples[ j ].layer > LAYER_GROUND)+ break;+ if (m_samples[ j ].left > deck.left) m_samples[ j ].left = deck.left;+ if (m_samples[ j ].right > deck.right) m_samples[ j ].right = deck.right;+ }}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex 23575b449..5bcbe4bc9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -1673,6 +1673,7 @@ static const Int STUCK_BACKOUT_FRAMES = 66; ///< how long a backing-out manoeuvstatic const Int STUCK_COOL_FRAMES = 90; ///< no second drastic thing inside this, or a wedged pair rock foreverstatic const Int STUCK_CYCLE_FRAMES = 150; ///< five seconds past the last rung: run the whole ladder againstatic const Int STUCK_DITHER_FRAMES = 90; ///< three seconds is long enough to tell a shuffle from a corner+static const Real STUCK_BRIDGE_NEAR = PATHFIND_CELL_SIZE_F * 20.0f; ///< a unit shaking this close to a deck on its route is at the rampstatic const Real STUCK_DITHER_RATIO = 0.3f; ///< gained less than this much of the ground it coveredstatic const Int CROWD_MERGE_FRAMES = 45; ///< a second and a half: how far ahead a merge is worth noticingstatic const Int CROWD_TTC_FRAMES = 21; ///< closing this fast on somebody counts as being in our way, wherever it sits@@ -2690,6 +2691,28 @@ void AIUpdateInterface::updateProgress( void )if (AIUpdate_isDithering( net, m_ditherTravel, body ))Pathfinder::bumpDither();+ /* The one case that is acted on: a unit on the ground beside or underneath a bridge its route+ goes over, shaking on the spot. It came in beside the ramp rather than onto it and is+ pressing against the side of the ramp at full throttle for a spot on the deck: it moves+ every frame, so no count of stuck frames ever rises for it, and it covers too little ground+ to read as dithering either. Two of twenty Crusaders over the long bridge on Golden Oasis+ never got across for that. A route asked for from where it stands leads it round to the+ ramp. */+ const Bool shaking = net < body * 0.25f && m_ditherTravel > body;+ if (shaking && self->getLayer() == LAYER_GROUND && m_path != NULL && now >= m_rescueCool)+ {+ for (const PathNode *node = m_path->getFirstNode(); node != NULL; node = node->getNextOptimized())+ {+ const Real dx = node->getPosition()->x - myPos->x;+ const Real dy = node->getPosition()->y - myPos->y;+ if (node->getLayer() > LAYER_GROUND && dx * dx + dy * dy < STUCK_BRIDGE_NEAR * STUCK_BRIDGE_NEAR)+ {+ crowdRepath();+ break;+ }+ }+ }+m_ditherFrame = now;m_ditherFrom = *myPos;m_ditherTravel = 0.0f;@@ -3868,7 +3891,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )}Coord3D goalPos;Real onPathDistToGoal;- if (!isDoingGroundMovement())+ if (!isDoingGroundMovement()){// airborne locomotor. Get the goal and distance direct to the goal, don't consider obstacles.onPathDistToGoal = getPath()->computeFlightDistToGoal(getObject()->getPosition(), goalPos);diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex afb3099af..c3dc2ee41 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -11836,53 +11836,58 @@ TEST(crowd_corridor_steering_point_slides_instead_of_hopping)CHECK_NEAR( ends.x, pts[ 5 ].x, 0.001f );}-TEST(crowd_corridor_has_no_band_on_a_bridge_or_at_its_approaches)+TEST(a_bridge_keeps_its_width_and_its_approach_funnels_onto_it){- /* A bridge deck is not road with room either side of it, and the ground beside a bridge is a- riverbank. A lane held across either one drives the unit off the side, and a lane held on the- approach arrives beside the abutment instead of at the entrance - which is a unit that never- gets onto the bridge and a queue behind it that never gets anywhere. The band closes over the- deck and for CROWD_BRIDGE_SEAL samples each side of it. */+ /* A deck is a road: the band on it is what its own layer measured, so a group goes over three+ abreast where the bridge carries three. The riverbank either side of the ramp is a field, and a+ lane held a field's width off the centre arrives beside the entrance, against the end of the+ railing. So for CROWD_BRIDGE_SEAL samples before and after the deck the ground is held to+ the deck's width at the ramp. */Coord3D pts[ 20 ];PathfindLayerEnum layers[ 20 ];+ Real width[ 20 ];for (Int k = 0; k < 20; k++){pts[ k ].x = (Real)k * 10.0f;pts[ k ].y = 0.0f;pts[ k ].z = 0.0f;layers[ k ] = LAYER_GROUND;+ width[ k ] = 60.0f; // open bank}- layers[ 10 ] = (PathfindLayerEnum)2; // the deck: three samples of it, out over the water- layers[ 11 ] = (PathfindLayerEnum)2;- layers[ 12 ] = (PathfindLayerEnum)2;+ for (Int k = 10; k <= 12; k++)+ {+ layers[ k ] = (PathfindLayerEnum)2; // the deck: three samples of it, out over the water+ width[ k ] = 10.0f;+ }+ width[ 8 ] = 5.0f; // and a rock on the bank, narrower than the deckCrowdCorridor corr;- corr.buildForTest( pts, 20, 15.0f, layers );- CHECK_EQ( corr.count(), 20 );-- // open road, far from the bridge either side: the band is what it was built with- CHECK_NEAR( corr.at( 0 ).left, 15.0f, 0.001f );- CHECK_NEAR( corr.at( 5 ).right, 15.0f, 0.001f );- CHECK_NEAR( corr.at( 19 ).left, 15.0f, 0.001f );-+ corr.buildForTest( pts, 20, 0.0f, layers, width );corr.sealBridges();+ // the deck keeps its own width+ for (Int k = 10; k <= 12; k++)+ {+ CHECK_NEAR( corr.at( k ).left, 10.0f, 0.001f );+ CHECK_NEAR( corr.at( k ).right, 10.0f, 0.001f );+ }++ // the approach at both ends is the deck's width, and a lane on it is cut to thatconst Int sealLo = 10 - (Int)CROWD_BRIDGE_SEAL;const Int sealHi = 12 + (Int)CROWD_BRIDGE_SEAL;-- // the deck itself, and the sealed samples each side of it- for (Int k = sealLo; k <= sealHi; k++)+ for (Int k = sealLo; k < 10; k++){- CHECK_NEAR( corr.at( k ).left, 0.0f, 0.001f );- CHECK_NEAR( corr.at( k ).right, 0.0f, 0.001f );- CHECK_NEAR( corr.clampLat( k, 12.0f ), 0.0f, 0.001f );- CHECK_NEAR( corr.clampLatAt( corr.at( k ).along, -12.0f ), 0.0f, 0.001f );+ if (k != 8)+ CHECK_NEAR( corr.at( k ).left, 10.0f, 0.001f );}+ for (Int k = 13; k <= sealHi; k++)+ CHECK_NEAR( corr.at( k ).right, 10.0f, 0.001f );+ CHECK_NEAR( corr.clampLat( 9, 40.0f ), 10.0f, 0.001f );- // and the road on either side of that stretch keeps its band- CHECK_NEAR( corr.at( sealLo - 1 ).left, 15.0f, 0.001f );- CHECK_NEAR( corr.at( sealHi + 1 ).right, 15.0f, 0.001f );- CHECK_NEAR( corr.clampLat( sealLo - 1, 12.0f ), 12.0f, 0.001f );+ // it never widens anything, and the bank past the approach keeps its own band+ CHECK_NEAR( corr.at( 8 ).left, 5.0f, 0.001f );+ CHECK_NEAR( corr.at( sealLo - 1 ).left, 60.0f, 0.001f );+ CHECK_NEAR( corr.at( sealHi + 1 ).right, 60.0f, 0.001f );// a route with no bridge on it is untouchedCrowdCorridor plain;