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): take orders during the exit path, carry them out once clear
Olcay Seygan815c6c9cf461
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bd2037ecc..be1ffe8d2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -694,7 +694,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- One picture is one order, cut to match the command bar's artwork.- The strip is half the size it was: it says the same thing and takes back the screen it was eating.- Whatever is actually being built counts down inside its own picture. The ones queued behind it stay blank, because their wait depends on everything in front of them.-- A unit finishes walking out of its factory before it takes an order.+- A unit still rolling out of its factory takes your orders. Click a tank the moment it appears and send it anywhere, or queue a route with shift: it drives out of the door first and then goes, instead of ignoring the click until it was clear. The order replaces the rally point. A dozer told to build the instant it leaves the Command Center used to drive straight from the door to the site, through the Command Center's walls; it comes out and goes round now.- An upgrade stays available if any selected building can still buy it.- One right click cancels one thing, counted the moment you press.- A build button takes a batch: Shift queues five, Ctrl twenty, both together as many as the queue will hold and the bank will pay for. Right-click with the same keys and the same number comes back out. Ten tanks used to be ten clicks. How many are still coming is written in the corner of the button, half again bigger than the price and the countdown beside it and on a plate you can actually read it against: at the size the other markings wear, the one number you check in the middle of a fight was a smudge you had to look for.diff --git a/GeneralsMD/Code/Data/Scenarios/exitmovebuild.txt b/GeneralsMD/Code/Data/Scenarios/exitmovebuild.txtnew file mode 100644index 000000000..79df4df9e--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/exitmovebuild.txt@@ -0,0 +1,20 @@+# A dozer told to move and then to build while it is still driving out of the command center. The+# build is the newer order and has to win: the move is held until the dozer is out, and if it were+# still held when the build came it would cancel the job on the way out. The tally reads two power+# plants at 1600 health, the spawned one and the one this dozer built; a lost job leaves the second+# at 1 health, placed and never started.+#+# The starting dozer is sent off west first and the move below sends it further, so the build click+# picks the new dozer, the idle builder nearest the site. Same map, seed and frames as exitorders.+#+# generals.exe -headless -quickstart -noshellmap -multiInstance -noFPSLimit+# -randommap 1 2 small -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 1600+# -scenario exitmovebuild -logPrefix exitmovebuild_++1 spawn 0 AmericaPowerPlant 1 start0:-200:200+2 playermove 0 AmericaVehicleDozer 1100 400+30 produce 0 AmericaCommandCenter AmericaVehicleDozer 1+181 playermove 0 AmericaVehicleDozer 1100 400+183 construct 0 AmericaPowerPlant 1510 880+1590 tally 0 AmericaPowerPlantdiff --git a/GeneralsMD/Code/Data/Scenarios/exitorders.txt b/GeneralsMD/Code/Data/Scenarios/exitorders.txtnew file mode 100644index 000000000..0c764bf9b--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/exitorders.txt@@ -0,0 +1,28 @@+# Orders given to units still driving out of the structure that built them.+#+# A dozer from the command center is told to build on the far side of that command center the frame+# after it appears, and a Crusader from the war factory is told to drive behind the war factory, with+# a shift move queued after it. Both orders are kept while the exit path runs and carried out once+# the unit is out, so neither should cross its producer's footprint: the dozer comes out of the door+# and goes round, where it used to drive straight through the walls to the site.+#+# The starting dozer is put on a power plant of its own first, so the construct click below picks+# the new dozer (the idle builder nearest the site). On this map and seed the command center stands+# at 1450,640, the dozer appears on frame 180 and leaves its exit path on 307, the Crusader appears+# on 360 and leaves on 476. The EXITTRACE lines this was measured with were a temporary log.+#+# generals.exe -headless -quickstart -noshellmap -multiInstance -noFPSLimit+# -randommap 1 2 small -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 1600+# -scenario exitorders -logPrefix exitorders_++1 spawn 0 AmericaPowerPlant 1 start0:-200:200+1 spawn 0 AmericaWarFactory 1 start0:250:0+30 produce 0 AmericaCommandCenter AmericaVehicleDozer 1+60 produce 0 AmericaWarFactory AmericaTankCrusader 1+150 construct 0 AmericaPowerPlant 1150 640+181 construct 0 AmericaPowerPlant 1510 880+361 playermove 0 AmericaTankCrusader 1600 700+362 shiftmove 0 AmericaTankCrusader 1600 900+1590 tally 0 AmericaPowerPlant+1590 tally 0 AmericaTankCrusaderdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.hindex bccaf7f2e..190e7e682 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h@@ -757,6 +757,7 @@ public:// this is intended for use ONLY by the production exit modules.void friend_setExitProductionRallyPoint( const Coord3D *pos );+ void friend_dropOrdersAfterExit() { m_hasExitProductionRallyPoint = FALSE; m_ordersAfterExit.clear(); } ///< a newer order replaces the rally point and the held ones// this is intended for use ONLY by the salvage collection pass in GameLogic.void friend_setSalvageReturnPosition( const Coord3D *pos );@@ -767,6 +768,7 @@ public:Bool hasTunnelTrip() const { return m_hasTunnelTrip; } ///< on its way through the tunnel network to a move order's goalvoid endTunnelTrip(); ///< what the trip was for is gone: forget it, unless the unit is already undergroundconst Coord3D *getTunnelTripGoal() const { return &m_tunnelTripGoal; } ///< where the trip ends, once out of the far mouth+ Bool isExitingProducer() const; ///< still driving the exit path out of the structure that built itTunnelTripEnd getTunnelTripEnd() const { return m_tunnelTripEnd; } ///< how the leg from the far mouth is walked#if defined(_DEBUG) || defined(_INTERNAL)inline const Coord3D *friend_getRequestedDestination() const { return &m_requestedDestination; }@@ -954,6 +956,7 @@ private:ObjectID m_moveOutOfWay2;Coord3D m_exitProductionRallyPoint; ///< Rally point to attack-move to once we are clear of the producer that just built us.Bool m_hasExitProductionRallyPoint; ///< True while m_exitProductionRallyPoint is still waiting to be ordered.+ mutable std::vector<AICommandParmsStorage> m_ordersAfterExit; ///< Player orders given while still on the exit path, carried out in order once off it.Coord3D m_salvageReturnPosition; ///< Where we stood when we were sent to fetch a salvage crate.Bool m_hasSalvageReturnPosition; ///< True while the walk back to m_salvageReturnPosition is still owed.Coord3D m_tunnelTripGoal; ///< Where a move order sent us before a tunnel shortened the way there.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cppindex 1eb2fa1fc..68c2a0081 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp@@ -385,7 +385,15 @@ Object *BuildAssistant::buildObjectNow( Object *constructorObject, const ThingTeDozerAIInterface *dozer = ai->getDozerAIInterface();Bool keepsCurrentJob = owningPlayer->getPlayerType() == PLAYER_HUMAN &&dozer && dozer->isTaskPending( DOZER_TASK_BUILD );- if( !keepsCurrentJob )+ if( ai->isExitingProducer() )+ {+ // a builder still leaving the structure that made it finishes leaving before it takes up+ // the job (DozerAIUpdate::update); idling it here dropped the exit path and it walked to+ // the site through the walls. The job takes the place of the rally point and of any+ // order given on the way out, which would cancel it when it came due.+ ai->friend_dropOrdersAfterExit();+ }+ else if( !keepsCurrentJob ){// a tunnel trip to the last order's goal with it, or the builder walks there firstai->endTunnelTrip();diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cppindex d07e97f2d..d00d61dae 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp@@ -225,6 +225,12 @@ static Bool OrderQueue_isWorking( const Object *obj, const AIUpdateInterface *aiif( ai->isIdle() )return FALSE;+ // a unit still driving out of the structure that built it holds the player's orders until it is+ // out (AIUpdateInterface::isAllowedToRespondToAiCommands); a queued one handed over now would be+ // held with them and replace the order in front of it+ if( ai->isExitingProducer() )+ return TRUE;+if( ai->getCurrentStateID() == AI_ATTACK_MOVE_TO )return TRUE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex 7a819a300..2fd3dfd0e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -1239,6 +1239,29 @@ UpdateSleepTime AIUpdateInterface::update( void )StateReturnType stRet = getStateMachine()->updateStateMachine();+ // Orders the player gave while the unit was still on its exit path (isAllowedToRespondToAiCommands+ // kept them), now that it is out: given in the order they came, as they would have been had it been+ // listening, and the first one drops the trip to the producer's rally point like any order does.+ // One that is now inside something was put there by somebody else, and an order whose target is+ // gone has nothing left to do.+ if (!m_ordersAfterExit.empty() && !isExitingProducer())+ {+ std::vector<AICommandParmsStorage> orders;+ orders.swap( m_ordersAfterExit );+ if (getObject()->getContainedBy() == NULL)+ {+ for (std::vector<AICommandParmsStorage>::const_iterator it = orders.begin(); it != orders.end(); ++it)+ {+ AICommandParms parms( AICMD_NO_COMMAND, CMD_FROM_PLAYER );+ it->reconstitute( parms );+ if (it->getTargetObjectID() != INVALID_ID && parms.m_obj == NULL)+ continue;+ aiDoCommand( &parms );+ }+ stRet = STATE_CONTINUE;+ }+ }+// A unit that was just built walks a short exit path out of its producer and then, if the player// set a rally point, attack moves to it - so it stops and fights whatever it runs into on the way// instead of taking the shots and walking on. This is checked right after the machine ran,@@ -4605,20 +4628,36 @@ Bool AIUpdateInterface::isAllowedToRespondToAiCommands(const AICommandParms* par//// A unit that is still walking the exit path out of the thing that produced it finishes that- // step before it will listen to anyone. Taking an order mid-doorway leaves it turning around- // inside the building's footprint, which blocks the next unit off the line and, with- // setCanPathThroughUnits on for the exit path, lets it be shoved back through the wall.- // Aircraft are left alone: their "exit path" is the taxi and takeoff run off a helipad or- // airfield, which the player is expected to be able to redirect.+ // step before it carries out a player's order. Taking the order mid-doorway leaves it turning+ // around inside the building's footprint, which blocks the next unit off the line and, with+ // setCanPathThroughUnits on for the exit path, lets it cut back through the walls. The order is+ // kept instead, and update() gives it once the unit is out, so it can be told what to do from the+ // moment it appears. Every derived aiDoCommand asks here first, which is why the keeping is done+ // in this const query. Aircraft are left alone: their "exit path" is the taxi and takeoff run+ // off a helipad or airfield, which the player is expected to be able to redirect.//- if ( parms->m_cmdSource == CMD_FROM_PLAYER- && getStateMachine()->getCurrentStateID() == AI_FOLLOW_EXITPRODUCTION_PATH- && isDoingGroundMovement() )+ if ( parms->m_cmdSource == CMD_FROM_PLAYER && isExitingProducer() )+ {+ AICommandParmsStorage order;+ order.store( *parms );+ m_ordersAfterExit.push_back( order );return FALSE;+ }++ // Anything else that takes the unit off its exit path - a script, the computer, a capture, which+ // idles it - is newer than the held orders and ends the wait for them.+ if ( parms->m_cmd != AICMD_FOLLOW_EXITPRODUCTION_PATH && isExitingProducer() )+ m_ordersAfterExit.clear();return TRUE;}+//-------------------------------------------------------------------------------------------------+Bool AIUpdateInterface::isExitingProducer() const+{+ return getStateMachine()->getCurrentStateID() == AI_FOLLOW_EXITPRODUCTION_PATH && isDoingGroundMovement();+}+//-------------------------------------------------------------------------------------------------void AIUpdateInterface::aiDoCommand(const AICommandParms* parms){@@ -7418,12 +7457,13 @@ void AIUpdateInterface::crc( Xfer *x )* 17: how the tunnel trip's last leg is walked* 18: the target a helicopter keeps shooting while it moves away* 19: the radius a player's guard order set- * 20: the aggressive stance */+ * 20: the aggressive stance+ * 21: the player's orders held until the exit path is done */// ------------------------------------------------------------------------------------------------void AIUpdateInterface::xfer( Xfer *xfer ){// version- const XferVersion currentVersion = 20;+ const XferVersion currentVersion = 21;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -7768,6 +7808,15 @@ void AIUpdateInterface::xfer( Xfer *xfer )if (version >= 20)xfer->xferBool(&m_aggressiveStance);+ if (version >= 21)+ {+ Int count = (Int)m_ordersAfterExit.size();+ xfer->xferInt(&count);+ m_ordersAfterExit.resize(count);+ for (Int i = 0; i < count; ++i)+ m_ordersAfterExit[i].doXfer(xfer);+ }+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cppindex 4abc17a57..dc50338b0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp@@ -1804,8 +1804,10 @@ UpdateSleepTime DozerAIUpdate::update( void )elsegetObject()->setWeaponSetFlag(WEAPONSET_MINE_CLEARING_DETAIL);//maybe go clear some mines, if I feel like it- // run our own state machine- m_dozerMachine->updateStateMachine();+ // run our own state machine, once we are out of the structure that built us: a job taken up on the+ // exit path walked the builder straight from the door to the site, through the building's walls+ if( !isExitingProducer() )+ m_dozerMachine->updateStateMachine();return UPDATE_SLEEP_NONE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cppindex 80b7ca41b..bcaeec024 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp@@ -333,8 +333,9 @@ UpdateSleepTime WorkerAIUpdate::update( void )} // end if- // update dozer behavior- m_dozerMachine->updateStateMachine();+ // update dozer behavior, once out of the structure that built us (DozerAIUpdate::update)+ if( !isExitingProducer() )+ m_dozerMachine->updateStateMachine();} // end ifelse