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): keep the shift queue in the logic, any order mix
Olcay Seyganb89e0689b3cd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e8d2073d0..f01adde6e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -178,6 +178,7 @@ found and fixed — EA's own, not port damage.**- With A armed, hold the left button and drag a circle instead: everything hostile you can see inside it becomes a target list, nearest first, and the selection works down that list on its own. When the current target dies the next order goes out the same frame, so a strike group clears a circle without you clicking once per tank. It moves on from a target the group has stopped working on, too, rather than only from a dead one: something none of them can reach or hurt used to sit at the head of the list and hold every other target behind it for the rest of the match. That list is the same queue a shift-clicked attack builds, so you can see it: every target still owed has its own thread and marker, in the order they will be taken, instead of one line to whatever is being shot at this second. Hold shift while you draw the circle and its targets go on the end of what the group is already working through; draw it without shift and the circle replaces the lot. The ground inside the circle is washed the same red while you drag it, painted on the map rather than over it, so it runs up the hills inside the circle and your own tanks stand on top of it. Any order you give by hand ends the list. Losing a unit does not: the list belongs to the group that was told and carries on with whoever is left, which is worth saying because for a while it did not, and one tank dying threw away every target still owed. A target with enough of your fire already in the air to kill it counts as done, so the rest of the group takes the next thing on the list rather than emptying itself into something that is dead and has not fallen over yet. Aircraft are what this is for: a flight fires from range and the missiles are seconds behind, and four planes used to spend all four loads on the first tank in the circle. Running out of ammo does not cost you the list either. A flight that empties its racks flies home, lands, rearms and comes back to the target it left, and the queue waits for it instead of counting the trip as the group giving up: a circle drawn for four planes used to be empty by the time they were back in the air, one entry lost every two seconds they were away. The threads stay on the ground for the whole trip, too. A plane flying home has no target and no order to read, so the list it was still holding used to vanish off the map the moment it turned for base and reappear only when it was shooting again, which looks exactly like the list being thrown away. What the circle picks up is what you can shoot: a shell or a missile crossing it is on the enemy's side like everything else and used to go on the list as a target, costing the group a two second stall on something that was about to stop existing. A target that has driven into the shroud since you picked it keeps its place in the list but stops drawing its thread, so the line cannot be used to trace it through the fog. An attack-move queued behind other orders keeps the force fire it was given rather than losing it when the attack key drops.- Shift queues a guard as well, and it is where the line of orders stops. Hold shift with G armed and click, and the group takes up its post once it has finished everything queued in front of it: clear that ridge, then sit on it, in one set of clicks instead of standing over the fight waiting to give the last order. Nothing goes behind a guard, because a posted unit has no next place to be. The thread to the post is drawn in the guard colour like any other guard.- Shift queues an attack now, not only a move. A or F held down while you shift-click adds a force-attack or an attack-move to the line of orders a group is already holding, and it fires the moment the order in front of it is finished - a target dead, or nobody left chasing an attack-move point. The coloured thread that shows a queued order covers it too, so a queue of "go here, then attack that, then attack-move over there" reads as one continuous line in three colours. The game's own white waypoint markings, which used to draw over the same ground the moment shift went down, are gone - they only ever duplicated what the coloured thread already showed, and doing both left a queued attack sitting under two different pictures of itself.+- The shift queue takes any mix of orders now and stays with the units you gave it to. Move, attack-move, attack a target, draw a formation line, then guard: hold shift, click them in whatever order you like, and the group works down the list by itself. Queue an army's whole route, select something else, go back to your base, and the army keeps going. Before, clicking anything else threw the list away. Each step also starts the moment the one before it is done. It used to wait for the order to travel to the other players and back, which on a 250ms connection was a quarter of a second standing still at every corner. The group keeps together: nobody starts the next order until everyone still alive has finished this one, so a column does not string out behind its fastest tank. Select part of a group and shift-click, and that part takes its own copy of the list with the new order on the end while the others carry on with theirs. Shift-click a group that is already on an ordinary move and the new point goes behind the move instead of replacing it.- What the circle picks up is what you can see, and a stealthed unit is not that. Shroud was the only test, so a hidden tank parked in ground you had already cleared went on the list like anything else: drag a circle over open country and the group opened fire on air, one order per hidden unit, which is a stealth detector drawn with the mouse. An undetected unit is not in the circle.- Ctrl+D takes every unit of the kinds you have selected that is on the screen, and pressed twice inside half a second takes them across the whole map. One tank selected and two keystrokes is your whole armour, wherever it is standing. It was on Shift+Ctrl+E, which is three fingers for something you do in every fight, and it only ever reached across the map when the screen had nothing left to give - so the wide selection happened to you instead of being asked for.diff --git a/GeneralsMD/Code/Data/Scenarios/shiftqueue.txt b/GeneralsMD/Code/Data/Scenarios/shiftqueue.txtnew file mode 100644index 000000000..8f7322a26--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/shiftqueue.txt@@ -0,0 +1,36 @@+# Six Scorpions are given a whole shift queue at once and have to work through it on their own:+# walk two points, attack-move onto a Humvee, kill a named Crusader, walk back and guard there.+# Two Quad Cannons are sent off with a plain move first and then shift-moved, which is the list+# starting behind an order that was given without shift.+#+# Nothing here is a player's click. The shift verbs hand each order to the seat's order queue the+# way it arrives over the network, so the log's "order queue:" lines are the list at work and the+# two arrive lines say whether each group reached the end of it.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover+# -side 0 FactionGLA -side 1 FactionAmerica -seed 1 -maxframes 2400+# -scenario shiftqueue -logPrefix shiftqueue_+#+# See mobstress.txt for the line grammar.++30 spawn 0 GLATankScorpion 6 760 920 30+30 spawn 0 GLAVehicleQuadCannon 2 760 1100 30+30 spawn 1 AmericaVehicleHumvee 1 1400 1400+30 spawn 1 AmericaTankCrusader 1 1250 1550++60 shiftmove 0 GLATankScorpion 1000 900+61 shiftmove 0 GLATankScorpion 1100 1150+62 shiftattackmove 0 GLATankScorpion 1400 1400+63 shiftattack 0 GLATankScorpion 1 AmericaTankCrusader+64 shiftmove 0 GLATankScorpion 900 1250+65 shiftguard 0 GLATankScorpion 900 1250++60 playermove 0 GLAVehicleQuadCannon 1000 1300+61 shiftmove 0 GLAVehicleQuadCannon 700 1500++66 arrive 0 GLATankScorpion 900 1250 150+66 arrive 0 GLAVehicleQuadCannon 700 1500 150++2390 tally 1 AmericaVehicleHumvee+2390 tally 1 AmericaTankCrusaderdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex e319754a6..27b16a124 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -645,6 +645,7 @@ public:MSG_DO_FORMATION_GUARD, ///< (location...) the same curve, each unit guarding its own point (fork)MSG_PLACE_SIGNAL, ///< (location, Int SignalKind) smoke only the sender's allies are shown (fork)MSG_CHEAT, ///< (Int CheatKind, Int amount) a console cheat, refused in a network game (fork)+ MSG_QUEUE_NEXT_ORDER, ///< (Int OrderQueueMode) the order right after this one is a shift-queued one (fork)MSG_BEGIN_DEBUG_NETWORK_MESSAGES = 1900, ///< network messages that exist only in debug/internal builds. all grouped separately.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex 225e644dd..adf374c8e 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -57,6 +57,7 @@#include "Common/Money.h"#include "Common/Science.h"#include "GameLogic/AI.h" // AISkillLevel and AIRole, asked of a player from outside the AI+#include "GameLogic/OrderQueue.h"#include "Common/UnicodeString.h"#include "Common/NameKeyGenerator.h"#include "Common/Thing.h"@@ -782,7 +783,11 @@ public:// return the requested hotkey squadSquad *getHotkeySquad(Int squadNumber);-++ // the orders this player has lined up with shift (fork)+ OrderQueue *getOrderQueue() { return &m_orderQueue; }+ const OrderQueue *getOrderQueue() const { return &m_orderQueue; }+// return the hotkey squad that a unit is in, or NO_HOTKEY_SQUAD if it isn't in one.Int getSquadNumberForObject(const Object *objToFind) const;@@ -964,6 +969,7 @@ private:Squad *m_squads[NUM_HOTKEY_SQUADS]; ///< The hotkeyed squadsSquad *m_currentSelection; ///< This player's currently selected group+ OrderQueue m_orderQueue; ///< shift-queued orders, handed out as the units finish each one (fork)Bool m_isPlayerDead;Bool m_logicalRetaliationModeEnabled;diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex c2a899c8f..2723b469d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -45,6 +45,7 @@#include "Common/UnicodeString.h"#include "GameClient/DisplayString.h"#include "GameClient/HtmlTemplate.h"+#include "GameLogic/OrderQueue.h" // the shift queue, which the logic keeps and the UI draws#include <set>@@ -537,28 +538,9 @@ public: // ********************************************************************const ICoord2D& getAttackCircleCursor( void ) const { return m_attackCircleCursor; }Bool getAttackCircleGround( Coord3D& center, Real& radius ) const; ///< the circle in world terms, FALSE while it is still a dot- // An attack order (force-attack or attack-move) added to the shift queue. The goal path the- // plain move queue rides on carries no order type, so this is a second queue: an ordinary- // message the client sends again once the order before it is over, nothing new for the logic- // to learn.- enum AttackWaypointKind- {- ATTACK_WAYPOINT_ATTACK, ///< attack-move to a point, or force-attack a victim- ATTACK_WAYPOINT_GUARD ///< post the group here. A guard never ends, so it ends the queue- };-- struct AttackWaypoint- {- Coord3D pos; ///< where to go, or the last known spot of targetID- ObjectID targetID; ///< INVALID_ID for a point, a specific victim otherwise- Bool forceAttack; ///< what the attack key said when it was queued, not when it goes out- AttackWaypointKind kind; ///< which order this entry sends when it reaches the front- };- void queueAttackWaypoint( const Coord3D *pos, Object *targetObj );- void queueGuardWaypoint( const Coord3D *pos );- void clearShiftAttackQueue( void );- Bool isShiftAttackQueueActive( void ) const { return !m_shiftAttackQueue.empty() || m_shiftAttackQueueRunning; }- const std::vector<AttackWaypoint>& getShiftAttackQueue( void ) const { return m_shiftAttackQueue; }+ /// The order about to go on the message stream is a shift-queued one: MSG_QUEUE_NEXT_ORDER goes+ /// in front of it. The logic keeps the list; see OrderQueue.h.+ void markNextOrderQueued( OrderQueueMode mode );virtual void createAttackHint( const GameMessage *msg ); ///< An attack command has occurred, start graphical "hint"virtual void createForceAttackHint( const GameMessage *msg ); ///< A force attack command has occurred, start graphical "hint"@@ -1132,28 +1114,15 @@ protected:ICoord2D m_attackCircleAnchor; ///< where the circle was started, in pixelsICoord2D m_attackCircleCursor; ///< where the cursor is now, which is the rim- std::vector<AttackWaypoint> m_shiftAttackQueue; ///< attack points still owed, in click order (fork)- Bool m_shiftAttackQueueRunning; ///< TRUE once the first order of the queue has been sent- AttackWaypoint m_shiftAttackQueueActive; ///< the order that was sent, so its completion can be noticed- UnsignedInt m_shiftAttackQueueEngagedFrame; ///< the last logic frame somebody was still working on the order in flight- std::vector<ObjectID> m_shiftAttackQueueUnits; ///< who was told, so a changed selection drops the queue- Bool m_shiftAttackQueueWaitingForRearm; ///< the order stands but its aircraft went home for ammo- Bool m_shiftAttackQueueWaitingForSelection; ///< the order stands but nothing that was told is in hand-void updateFormationHints( void ); ///< recompute who goes where from the curve being drawnvoid updateOrderHints( void ); ///< read the selection's own goals, once a framevoid collectOrderHints( void ); ///< one hint per selected unit and queued pointvoid bunchOrderHints( void ); ///< merge the hints of units going the same way- void updateShiftAttackQueue( void ); ///< send the next queued attack once the current one is overvoid addOrderHint( OrderHint& hint, const std::vector<OrderHint>& previous ); ///< keep a marker's age across the frame the list is rebuilt onBool getHeldAircraftOrder( const Object *obj, OrderHintKind& kind, Coord3D& to ) const; ///< the order an aircraft is sitting on until it is airborne- void pushShiftAttackOrder( const AttackWaypoint& order ); ///< add one order to the queue, or start a queue with it- void sendShiftAttackOrder( const AttackWaypoint& waypoint ); ///< put one queue entry on the message stream- void logShiftAttackQueue( const char *why ) const; ///< one line saying what the queue did and what its group was doing- void addShiftAttackQueueTail( OrderHint& hint, const std::vector<OrderHint>& previous ); ///< every target still owed, drawn on from where the hint leaves off+ void addQueuedOrderTail( OrderHint& hint, const OrderChain& chain, const std::vector<OrderHint>& previous ); ///< every order still owed, drawn on from where the hint leaves off+ Bool getQueuedOrderHint( const QueuedOrder& order, OrderHintKind& kind, Coord3D& to ) const; ///< the marker a queued order draws, FALSE for noneBool isHiddenByShroud( const Object *obj ) const; ///< is the shroud over this, for the player at this machine- void collectSelectedObjectIDs( std::vector<ObjectID>& ids ) const; ///< the selection by id, sorted- Bool selectionOwnsShiftAttackQueue( const std::vector<ObjectID>& selected ) const; ///< is this still the group the queue was given toBool m_displayedMaxWarning; ///< keeps the warning from being shown over and overconst CommandButton * m_pendingGUICommand; ///< GUI command that needs additional interaction from the userBuildProgress m_buildProgress[ MAX_BUILD_PROGRESS ]; ///< progress for building unitsdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.hindex c27ce9d48..ab33dbc08 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h@@ -55,6 +55,7 @@// forward declarationsclass AudioEventRTS;+class AIGroup;class Object;class Drawable;class Player;@@ -132,8 +133,9 @@ public:void prepareNewGame( Int gameMode, GameDifficulty diff, Int rankPoints ); ///< prepare for new game- void logicMessageDispatcher( GameMessage *msg,- void *userData ); ///< Logic command list processing+ /// Logic command list processing. A NULL orderedGroup means the order is for the sender's selection;+ /// otherwise it is for exactly that group (a shift-queued order coming round), which is destroyed here.+ void logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup );void registerObject( Object *obj ); ///< Given an object, register it with the GameLogic and give it a unique IDdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/OrderQueue.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/OrderQueue.hnew file mode 100644index 000000000..8e4dc0ffe--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/OrderQueue.h@@ -0,0 +1,154 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// OrderQueue.h ///////////////////////////////////////////////////////////////////////////////////+// The orders a player has lined up with shift, kept by the logic and handed to the units one at a+// time as they finish the one in front.+//+// The queue used to live on the client, which sent each next order over the network once it saw the+// last one was over. Every step therefore waited a round trip, which at the 200-300 ms most players+// sit at is a visible pause at every corner, and the list belonged to the selection: clicking+// anything else threw it away. Here the list belongs to the units it was given to, and it moves on+// the same logic frame on every machine.+//+// A queued order is an ordinary order message with MSG_QUEUE_NEXT_ORDER in front of it. The logic+// keeps a copy of the message and dispatches it again, to the units that still hold the list, when+// its turn comes, so every kind of order the dispatcher knows can be queued without a line of its own+// here.+//+// The units that were told together form a chain and go through it together: nobody starts the next+// order until everyone left alive is done with this one, so an army does not string out across the+// map behind its fastest unit. Selecting part of a chain and adding to it splits that part off with+// a copy of the list. An order given without shift ends the list for the units it went to.+//+// Everything here is logic state: it is saved with the player, and a replay rebuilds it from the+// recorded messages.+///////////////////////////////////////////////////////////////////////////////////////////////////++#pragma once+#ifndef __ORDERQUEUE_H__+#define __ORDERQUEUE_H__++#include "Common/GameCommon.h"+#include "Common/MessageStream.h"++#include <list>+#include <vector>++class AIGroup;+class Player;+class Xfer;++/// The argument of MSG_QUEUE_NEXT_ORDER. It arrives from another machine, so it is range-checked.+enum OrderQueueMode+{+ ORDER_QUEUE_NONE = -1, ///< the next order is not queued+ ORDER_QUEUE_APPEND = 0, ///< the next order goes after whatever its units are already doing+ ORDER_QUEUE_FRESH, ///< the next order starts a new list, dropping the old one++ ORDER_QUEUE_MODE_COUNT+};++//-------------------------------------------------------------------------------------------------+/** A copy of one order message, kept until its turn comes. */+//-------------------------------------------------------------------------------------------------+class QueuedOrder+{+public:+ QueuedOrder( void );++ void copyFrom( const GameMessage *msg );+ GameMessage *makeMessage( Int playerIndex ) const; ///< the caller deletes it++ GameMessage::Type getType( void ) const { return m_type; }+ Bool isStanding( void ) const { return m_type == GameMessage::MSG_INVALID; }+ ObjectID getTargetID( void ) const; ///< the object the order names, INVALID_ID for none+ Bool getDestination( Coord3D *pos ) const; ///< the first location it carries, FALSE for none++ void xfer( Xfer *xfer );++private:+ GameMessage::Type m_type; ///< MSG_INVALID: whatever the units were doing when the list began+ std::vector<GameMessageArgumentDataType> m_argTypes;+ std::vector<GameMessageArgumentType> m_args;+};++//-------------------------------------------------------------------------------------------------+/** One group of units and the orders they still owe. */+//-------------------------------------------------------------------------------------------------+struct OrderChain+{+ OrderChain( void );++ std::vector<ObjectID> m_members; ///< sorted, so a split and a lookup agree on every machine+ QueuedOrder m_active; ///< the order the chain is on now+ std::vector<QueuedOrder> m_pending; ///< the rest, in the order they were given+ UnsignedInt m_settledFrames; ///< how many frames in a row nobody has been working on m_active+ Bool m_waitingForRearm; ///< the order stands, but its aircraft have gone home for ammo+};++typedef std::list<OrderChain> OrderChainList;++//-------------------------------------------------------------------------------------------------+/** Every chain one player has running. */+//-------------------------------------------------------------------------------------------------+class OrderQueue+{+public:+ OrderQueue( void );++ void reset( void );++ /// MSG_QUEUE_NEXT_ORDER: the next message from this player is queued in this way+ void setNextOrderMode( Int mode );++ /**+ Called for every message the player sends. Returns TRUE when the message was a queued order and+ has been dealt with here, in which case selected has been destroyed and the dispatcher must not+ carry the order out itself. An order given without shift ends the list for the units it names+ and returns FALSE, leaving selected alone.+ */+ Bool takeMessage( GameMessage *msg, AIGroup *selected, Player *owner );++ /// A MSG_QUEUE_NEXT_ORDER with no order behind it in the same frame is forgotten, not carried over.+ void forgetNextOrderMode( void ) { m_nextOrderMode = ORDER_QUEUE_NONE; }++ void update( Player *owner ); ///< once a logic frame: hand out the next order to every chain that is done++ const OrderChainList& getChains( void ) const { return m_chains; }+ const OrderChain *findChain( ObjectID id ) const;++ void xfer( Xfer *xfer );++ static Bool isOrder( GameMessage::Type type ); ///< a hand-given order to the selected units+ static Bool isQueueable( GameMessage::Type type ); ///< an order that can wait its turn in a chain+ static Bool isTerminal( GameMessage::Type type ); ///< an order that never finishes, so it ends its chain++private:+ void queueOrder( GameMessage *msg, const std::vector<ObjectID>& selected, Player *owner );+ void startChain( GameMessage *msg, const std::vector<ObjectID>& members, Player *owner );+ void appendOrder( OrderChain& chain, GameMessage *msg, Player *owner );+ void releaseUnits( const std::vector<ObjectID>& ids );+ Bool isStepOver( OrderChain& chain, Player *owner );+ Bool advance( OrderChain& chain, Player *owner ); ///< FALSE when the chain has nothing left++ OrderChainList m_chains;+ Int m_nextOrderMode; ///< an OrderQueueMode, set by MSG_QUEUE_NEXT_ORDER for the message after it+};++#endif // __ORDERQUEUE_H__diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.hindex 2092ce293..1ffd6f36f 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h@@ -38,6 +38,10 @@// stream, so a run driven by a scenario cannot be replayed. Repeatability comes from the file// plus -seed instead, which is what an A/B needs anyway.//+// The shift verbs are the exception to the script source. They hand the order to the seat's order+// queue exactly as a message with MSG_QUEUE_NEXT_ORDER in front of it would arrive, so the queue+// dispatches them as the player's own, which is the only way to exercise it without a mouse.+/////////////////////////////////////////////////////////////////////////////////////////////////////#pragma once@@ -70,7 +74,11 @@ enum ScenarioActionTypeSCENARIO_ACTION_POWER, ///< power <slot> <building> <position> [powerName]; fire its special powers (or the one named) there now, charged or notSCENARIO_ACTION_PLAYERATTACKMOVE, ///< playerattackmove <slot> <selector> <position>; the player's attack move, not a script'sSCENARIO_ACTION_PRODUCE, ///< produce <slot> <building> <template> <count>; queue that many in its first matching building- SCENARIO_ACTION_TALLY ///< tally <slot> <selector>; log how many are alive, their health and what they cost+ SCENARIO_ACTION_TALLY, ///< tally <slot> <selector>; log how many are alive, their health and what they cost+ SCENARIO_ACTION_SHIFTMOVE, ///< shiftmove <slot> <selector> <position>; a shift right click, onto the units' order queue+ SCENARIO_ACTION_SHIFTATTACKMOVE, ///< shiftattackmove <slot> <selector> <position>; the same with attack move+ SCENARIO_ACTION_SHIFTATTACK, ///< shiftattack <slot> <selector> <targetSlot> <targetSelector>; the same with an attack on one unit+ SCENARIO_ACTION_SHIFTGUARD ///< shiftguard <slot> <selector> <position>; the same with the guard key};/// ScenarioAction::atStart when the position is plain numbersdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex 7520686ce..73bc97f1f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -655,6 +655,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)CHECK_IF(MSG_DO_FORMATION_GUARD)CHECK_IF(MSG_PLACE_SIGNAL)CHECK_IF(MSG_CHEAT)+ CHECK_IF(MSG_QUEUE_NEXT_ORDER)CHECK_IF(MSG_DO_GUARD_OBJECT)CHECK_IF(MSG_DO_STOP)CHECK_IF(MSG_DO_SCATTER)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 07a8b1711..73b518474 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -405,6 +405,7 @@ void Player::init(const PlayerTemplate* pt)m_isPreorder = FALSE;m_isPlayerDead = FALSE;+ m_orderQueue.reset();m_radarCount = 0;m_disableProofRadarCount = 0;@@ -772,6 +773,8 @@ void Player::update()if( m_tunnelSystem )m_tunnelSystem->healObjects();+ m_orderQueue.update( this );+// A trickle of income that does not come from a supply line. `MoneyPerMinute` in GameData.ini,// zero and therefore absent unless somebody asks for it. Paid on the minute rather than spread// over the frames so that the figure in the readout is the figure that was asked for, and only@@ -4477,13 +4480,14 @@ void Player::crc( Xfer *xfer )* 6: Store m_unitsShouldHunt, set to true after the script "Tell player to hunt" is called.* 7: added Preorder flag* 8: Save m_disabledSciences & m_hiddenSciences. jba.+ * 9: The shift queue, m_orderQueue (fork).*/// ------------------------------------------------------------------------------------------------void Player::xfer( Xfer *xfer ){// version- const XferVersion currentVersion = 8;+ const XferVersion currentVersion = 9;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -5020,6 +5024,11 @@ void Player::xfer( Xfer *xfer )elsem_unitsShouldHunt = FALSE;+ if (version >= 9)+ m_orderQueue.xfer( xfer );+ else+ m_orderQueue.reset();+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex e0dce3306..d208673a9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -103,7 +103,6 @@#include "GameLogic/AIStateMachine.h"#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Module/JetAIUpdate.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/Weapon.h"#include "GameLogic/Object.h"#include "GameLogic/RankInfo.h"@@ -1305,10 +1304,6 @@ InGameUI::InGameUI()m_guardArmed = false;m_preferSelection = false;m_isAttackCircling = FALSE;- m_shiftAttackQueueRunning = FALSE;- m_shiftAttackQueueEngagedFrame = 0;- m_shiftAttackQueueWaitingForRearm = FALSE;- m_shiftAttackQueueWaitingForSelection = FALSE;clearAllyCursors();m_curRcType = RADIUSCURSOR_NONE;@@ -3389,10 +3384,6 @@ void InGameUI::preDraw( void )// where the selection is headed, read fresh from the units themselvesupdateOrderHints();- // and the next queued attack, hand-clicked or swept out of a circle, once the one in front of- // it is over- updateShiftAttackQueue();-// the build grid under a structure waiting to be placed is not drawn here: it is terrain// geometry now, and HeightMapRenderObjClass::Render puts it down with the ground itself@@ -3858,12 +3849,6 @@ void InGameUI::reset( void )m_guardArmed = false;m_preferSelection = false;m_isAttackCircling = FALSE;- m_shiftAttackQueue.clear();- m_shiftAttackQueueUnits.clear();- m_shiftAttackQueueRunning = FALSE;- m_shiftAttackQueueEngagedFrame = 0;- m_shiftAttackQueueWaitingForRearm = FALSE;- m_shiftAttackQueueWaitingForSelection = FALSE;clearAllyCursors();m_clientQuiet = false;@@ -4952,71 +4937,75 @@ void InGameUI::collectOrderHints( void )addOrderHint( hint, previous );- // the rest of a shift-queued attack: every point still owed after this one, drawn the same- // way a queued move is. The queue is shared by the whole group rather than kept per unit,- // so each member's tail starts wherever that unit's own current order leaves off- if( std::find( m_shiftAttackQueueUnits.begin(), m_shiftAttackQueueUnits.end(), obj->getID() )- != m_shiftAttackQueueUnits.end() )+ // the rest of the unit's shift queue: every order still owed after this one, each drawn on from+ // where the last leaves off. The list belongs to the whole chain rather than to one unit, so+ // each member's tail starts wherever that unit's own current order ends+ const OrderChain *chain = local->getOrderQueue()->findChain( obj->getID() );+ if( chain ){hint.from = hint.to;- addShiftAttackQueueTail( hint, previous );+ addQueuedOrderTail( hint, *chain, previous );}}//- // A unit holding the list that drew nothing above has to draw it anyway. An aircraft on its way- // home for ammo has no goal and no state the switch recognises, and one sitting on its airfield- // is not even in the selection, so the whole list went blank the moment the planes turned for- // home and came back only when they were shooting again - which looked exactly like the list had- // been thrown away. Here it stays on the ground for the length of the trip.+ // A unit holding a list that drew nothing above has to draw it anyway. One waiting for the rest+ // of its chain to catch up is idle, an aircraft on its way home for ammo has no goal the switch+ // recognises, and one parked on its airfield is not even in the selection - so the list went+ // blank for exactly the time the player most wanted to see it. A chain with anything selected in+ // it draws for every member.//- if( !m_shiftAttackQueueRunning )- return;-- for( std::vector<ObjectID>::const_iterator id = m_shiftAttackQueueUnits.begin();- id != m_shiftAttackQueueUnits.end(); ++id )+ const OrderChainList& chains = local->getOrderQueue()->getChains();+ for( OrderChainList::const_iterator chain = chains.begin(); chain != chains.end(); ++chain ){- Bool alreadyDrawn = FALSE;- for( std::vector<OrderHint>::const_iterator drawn = m_orderHints.begin();- drawn != m_orderHints.end(); ++drawn )+ Bool anySelected = FALSE;+ for( std::vector<ObjectID>::const_iterator id = chain->m_members.begin(); id != chain->m_members.end(); ++id ){- if( drawn->owner == *id )+ const Object *member = TheGameLogic->findObjectByID( *id );+ const Drawable *draw = member ? member->getDrawable() : NULL;+ if( draw && draw->isSelected() ){- alreadyDrawn = TRUE;+ anySelected = TRUE;break;}}- if( alreadyDrawn )+ if( !anySelected )continue;- Object *owner = TheGameLogic->findObjectByID( *id );- if( owner == NULL || owner->isEffectivelyDead() )- continue;+ for( std::vector<ObjectID>::const_iterator id = chain->m_members.begin(); id != chain->m_members.end(); ++id )+ {+ Bool alreadyDrawn = FALSE;+ for( std::vector<OrderHint>::const_iterator drawn = m_orderHints.begin();+ drawn != m_orderHints.end(); ++drawn )+ {+ if( drawn->owner == *id )+ {+ alreadyDrawn = TRUE;+ break;+ }+ }- OrderHint hint;- hint.owner = *id;- hint.from = *owner->getPosition();+ if( alreadyDrawn )+ continue;- // the order the group is on right now is no longer in the list, so it is drawn from here- const Object *active = m_shiftAttackQueueActive.targetID != INVALID_ID- ? TheGameLogic->findObjectByID( m_shiftAttackQueueActive.targetID ) : NULL;- if( active && !active->isEffectivelyDead() && !isHiddenByShroud( active ) )- {- hint.kind = ORDER_HINT_ATTACK;- hint.to = *active->getPosition();- addOrderHint( hint, previous );- hint.from = hint.to;- }- else if( m_shiftAttackQueueActive.targetID == INVALID_ID )- {- hint.kind = ORDER_HINT_ATTACK_MOVE;- hint.to = m_shiftAttackQueueActive.pos;- addOrderHint( hint, previous );- hint.from = hint.to;- }+ const Object *member = TheGameLogic->findObjectByID( *id );+ if( member == NULL || member->isEffectivelyDead() )+ continue;++ OrderHint hint;+ hint.owner = *id;+ hint.from = *member->getPosition();- addShiftAttackQueueTail( hint, previous );+ // the order the chain is on now is no longer in its list, so it is drawn from here+ if( getQueuedOrderHint( chain->m_active, hint.kind, hint.to ) )+ {+ addOrderHint( hint, previous );+ hint.from = hint.to;+ }++ addQueuedOrderTail( hint, *chain, previous );+ }}}@@ -5079,44 +5068,81 @@ void InGameUI::bunchOrderHints( void )}//--------------------------------------------------------------------------------------------------/** Every target still owed, one thread from the last point to the next, starting wherever the hint+/** Every order still owed, one thread from the last point to the next, starting wherever the hint* handed in leaves off. *///--------------------------------------------------------------------------------------------------void InGameUI::addShiftAttackQueueTail( OrderHint& hint, const std::vector<OrderHint>& previous )+void InGameUI::addQueuedOrderTail( OrderHint& hint, const OrderChain& chain, const std::vector<OrderHint>& previous ){- for( std::vector<AttackWaypoint>::const_iterator qit = m_shiftAttackQueue.begin();- qit != m_shiftAttackQueue.end(); ++qit )+ for( std::vector<QueuedOrder>::const_iterator order = chain.m_pending.begin();+ order != chain.m_pending.end(); ++order ){- if( qit->kind == ATTACK_WAYPOINT_GUARD )- {- hint.kind = ORDER_HINT_GUARD;- hint.to = qit->pos;- }- else if( qit->targetID != INVALID_ID )- {- // a queued victim is drawn where it stands now rather than where it stood when the player- // picked it, so the thread follows a target that is driving away. One that died while it- // waited its turn is drawn nowhere: the order will be skipped. Nor is one that has driven- // into the shroud since it was picked - the thread would otherwise trace it through the- // fog, which is a look at the map you have not earned- const Object *victim = TheGameLogic->findObjectByID( qit->targetID );- if( victim == NULL || victim->isEffectivelyDead() || isHiddenByShroud( victim ) )- continue;-- hint.kind = ORDER_HINT_ATTACK;- hint.to = *victim->getPosition();- }- else- {- hint.kind = ORDER_HINT_ATTACK_MOVE;- hint.to = qit->pos;- }+ if( !getQueuedOrderHint( *order, hint.kind, hint.to ) )+ continue;addOrderHint( hint, previous );hint.from = hint.to;}}+//-------------------------------------------------------------------------------------------------+/** Which marker a queued order draws, and where. A queued victim is drawn where it stands now rather+ * than where it stood when the player picked it, so the thread follows a target that is driving+ * away. One that died while it waited its turn is drawn nowhere: the order will be skipped. Nor+ * is one that has driven into the shroud since it was picked - the thread would otherwise trace it+ * through the fog, which is a look at the map you have not earned. */+//-------------------------------------------------------------------------------------------------+Bool InGameUI::getQueuedOrderHint( const QueuedOrder& order, OrderHintKind& kind, Coord3D& to ) const+{+ switch( order.getType() )+ {+ case GameMessage::MSG_DO_MOVETO:+ case GameMessage::MSG_DO_FORCEMOVETO:+ case GameMessage::MSG_DO_FORMATION_MOVETO:+ kind = ORDER_HINT_MOVE;+ break;++ case GameMessage::MSG_DO_ATTACKMOVETO:+ case GameMessage::MSG_DO_FORMATION_ATTACKMOVETO:+ kind = ORDER_HINT_ATTACK_MOVE;+ break;++ case GameMessage::MSG_DO_ATTACK_OBJECT:+ kind = ORDER_HINT_ATTACK;+ break;++ case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:+ kind = ORDER_HINT_FORCE_ATTACK;+ break;++ case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:+ case GameMessage::MSG_DO_FORMATION_FORCEATTACK:+ kind = ORDER_HINT_ATTACK_GROUND;+ break;++ case GameMessage::MSG_DO_GUARD_POSITION:+ case GameMessage::MSG_DO_GUARD_OBJECT:+ case GameMessage::MSG_DO_FORMATION_GUARD:+ kind = ORDER_HINT_GUARD;+ break;++ default:+ // a hold is wherever each unit happens to be standing, and a list that began behind an+ // unqueued order has nothing of its own to show for that order+ return FALSE;+ }++ const ObjectID targetID = order.getTargetID();+ if( targetID == INVALID_ID )+ return order.getDestination( &to );++ const Object *target = TheGameLogic->findObjectByID( targetID );+ if( target == NULL || target->isEffectivelyDead() || isHiddenByShroud( target ) )+ return FALSE;++ to = *target->getPosition();+ return TRUE;+}+//-------------------------------------------------------------------------------------------------/** Add a marker to this frame's list, carrying over when it first appeared. The list is thrown* away and rebuilt from the units every frame, so without this every marker would be newborn on@@ -5195,11 +5221,13 @@ Bool InGameUI::getAttackCircleGround( Coord3D& center, Real& radius ) const}//--------------------------------------------------------------------------------------------------/** Everything hostile standing in the circle joins the shift queue, nearest first, and the group is- * put on the head of it. Shroud decides membership: a target the player cannot see is not in the- * circle, whatever the partition manager knows about it. The targets go through the same queue a- * shift-clicked attack uses, so the whole list is drawn on the ground as threads and markers- * instead of only the one target the group happens to be shooting at. */+/** Everything hostile standing in the circle becomes a list of attacks, nearest first, and the group+ * is put on the head of it. Without shift the list replaces whatever the group was doing; with it,+ * the list goes on the end of the group's shift queue. Shroud decides membership: a target the+ * player cannot see is not in the circle, whatever the partition manager knows about it. The+ * targets go through the same queue a shift-clicked attack uses, so the whole list is drawn on the+ * ground as threads and markers instead of only the one target the group happens to be shooting+ * at. *///-------------------------------------------------------------------------------------------------Bool InGameUI::issueAttackCircle( void ){@@ -5249,7 +5277,10 @@ Bool InGameUI::issueAttackCircle( void )if( obj->isKindOf( KINDOF_PROJECTILE ) || obj->isKindOf( KINDOF_UNATTACKABLE ) )continue;- queueAttackWaypoint( obj->getPosition(), obj );+ const Bool startsList = targetCount == 0 && !isInWaypointMode();+ markNextOrderQueued( startsList ? ORDER_QUEUE_FRESH : ORDER_QUEUE_APPEND );+ GameMessage *attack = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );+ attack->appendObjectIDArgument( obj->getID() );targetCount++;}@@ -5268,429 +5299,10 @@ Bool InGameUI::isHiddenByShroud( const Object *obj ) const}//--------------------------------------------------------------------------------------------------/** Every selected object by id, sorted, which is how the shift queue recognises the group it was- * given to. */-//--------------------------------------------------------------------------------------------------void InGameUI::collectSelectedObjectIDs( std::vector<ObjectID>& ids ) const-{- ids.clear();- for( DrawableList::const_iterator it = m_selectedDrawables.begin();- it != m_selectedDrawables.end(); ++it )- {- Object *obj = (*it)->getObject();- if( obj )- ids.push_back( obj->getID() );- }- std::sort( ids.begin(), ids.end() );-}--//--------------------------------------------------------------------------------------------------/** The queue belongs to the group that was told, and it has to survive that group being shot at:- * whatever is left of it carries on down the list. Comparing the two lists for equality instead- * meant one tank dying threw away every target still owed, which is what the group stopping dead- * after its first kill was. Selecting anything that was not told ends the queue, because those- * units never agreed to the list and the next order would land on them. */-//--------------------------------------------------------------------------------------------------Bool InGameUI::selectionOwnsShiftAttackQueue( const std::vector<ObjectID>& selected ) const-{- return !selected.empty() &&- std::includes( m_shiftAttackQueueUnits.begin(), m_shiftAttackQueueUnits.end(),- selected.begin(), selected.end() );-}--//--------------------------------------------------------------------------------------------------/** Shift held, attack armed (force-attack or attack-move), left click: the order joins the shift- * queue instead of the goal path a plain move rides on, since that path carries no order type.- * The first order of a fresh queue is sent immediately, exactly like an unqueued attack; every- * one after it waits on the client for the order in front of it to be over, the same way the- * attack circle's queue does. */-//--------------------------------------------------------------------------------------------------void InGameUI::queueAttackWaypoint( const Coord3D *pos, Object *targetObj )-{- AttackWaypoint order;- order.pos = *pos;- order.targetID = targetObj ? targetObj->getID() : INVALID_ID;- order.kind = ATTACK_WAYPOINT_ATTACK;-- // remembered rather than read again when the order goes out: the attack key drops the moment the- // first order of the queue is sent, so everything behind it used to lose its force attack- order.forceAttack = isForceAttackArmed();-- pushShiftAttackOrder( order );-}--//--------------------------------------------------------------------------------------------------/** Shift held, guard armed, left click: the group takes up its post once it has finished whatever- * the queue already holds - "clear this, then sit on that ridge" in one set of clicks. A guard- * is where the queue stops, because a posted unit has no next point to walk to and nothing after- * it would ever come round. */-//--------------------------------------------------------------------------------------------------void InGameUI::queueGuardWaypoint( const Coord3D *pos )-{- AttackWaypoint order;- order.pos = *pos;- order.targetID = INVALID_ID;- order.forceAttack = FALSE;- order.kind = ATTACK_WAYPOINT_GUARD;-- pushShiftAttackOrder( order );-}--//--------------------------------------------------------------------------------------------------/** Put one order on the end of the queue, or start a fresh queue with it. A selection that is not- * part of the group holding the queue starts its own rather than adding to whatever the old- * selection was doing. */-//--------------------------------------------------------------------------------------------------void InGameUI::pushShiftAttackOrder( const AttackWaypoint& order )-{- std::vector<ObjectID> current;- collectSelectedObjectIDs( current );-- if( !m_shiftAttackQueueRunning || !selectionOwnsShiftAttackQueue( current ) )- {- clearShiftAttackQueue();-- // a guard with nothing in front of it is just a guard, and starting a queue on one would- // leave the list waiting on an order that never finishes- if( order.kind == ATTACK_WAYPOINT_GUARD )- {- sendShiftAttackOrder( order );- return;- }-- m_shiftAttackQueueUnits = current;- m_shiftAttackQueueRunning = TRUE;- m_shiftAttackQueueActive = order;- m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();- sendShiftAttackOrder( order );- return;- }-- // a guard is terminal, so anything clicked after one would never be reached- if( !m_shiftAttackQueue.empty() && m_shiftAttackQueue.back().kind == ATTACK_WAYPOINT_GUARD )- return;-- m_shiftAttackQueue.push_back( order );-}--//--------------------------------------------------------------------------------------------------void InGameUI::clearShiftAttackQueue( void )-{- m_shiftAttackQueue.clear();- m_shiftAttackQueueUnits.clear();- m_shiftAttackQueueRunning = FALSE;- m_shiftAttackQueueActive.targetID = INVALID_ID;- m_shiftAttackQueueActive.pos.zero();- m_shiftAttackQueueActive.forceAttack = FALSE;- m_shiftAttackQueueActive.kind = ATTACK_WAYPOINT_ATTACK;- m_shiftAttackQueueEngagedFrame = 0;- m_shiftAttackQueueWaitingForRearm = FALSE;- m_shiftAttackQueueWaitingForSelection = FALSE;-}--//--------------------------------------------------------------------------------------------------/** What the queue just did, and what every unit holding it was doing at that moment. The queue is- * driven by the player, so no unattended run can reproduce a fault in it; this line is the whole- * instrument. One per event, never one per frame. */-//--------------------------------------------------------------------------------------------------void InGameUI::logShiftAttackQueue( const char *why ) const-{- AsciiString census;- for( DrawableList::const_iterator it = m_selectedDrawables.begin();- it != m_selectedDrawables.end(); ++it )- {- Object *obj = (*it)->getObject();- if( obj == NULL )- continue;-- AIUpdateInterface *ai = obj->getAIUpdateInterface();- const JetAIUpdate *jet = ai ? ai->getJetAIUpdate() : NULL;-- AsciiString one;- one.format( " [%d %s state %d goal %d%s%s%s]",- (Int)obj->getID(),- obj->getTemplate()->getName().str(),- ai ? (Int)ai->getCurrentStateID() : -1,- ( ai && ai->getGoalObject() ) ? (Int)ai->getGoalObject()->getID() : 0,- obj->isOutOfAmmo() ? " dry" : "",- ( jet && jet->friend_isRearming() ) ? " rearming" : "",- ( ai && ai->isIdle() ) ? " idle" : "" );- census.concat( one );- }-- DEBUG_LOG(("shift attack queue: frame %d, %s, active %d, %d owed, told %d:%s\n",- TheGameLogic->getFrame(), why,- (Int)m_shiftAttackQueueActive.targetID,- (Int)m_shiftAttackQueue.size(),- (Int)m_shiftAttackQueueUnits.size(),- census.str()));-}--//--------------------------------------------------------------------------------------------------/** Put one entry of the queue on the message stream, as the ordinary order it would have been if the- * player had clicked it by hand. Sent again rather than remembered, so a flight that had to go- * home for ammo picks the same order back up. */-//--------------------------------------------------------------------------------------------------void InGameUI::sendShiftAttackOrder( const AttackWaypoint& waypoint )+void InGameUI::markNextOrderQueued( OrderQueueMode mode ){- if( waypoint.kind == ATTACK_WAYPOINT_GUARD )- {- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_GUARD_POSITION );- msg->appendLocationArgument( waypoint.pos );- msg->appendIntegerArgument( GUARDMODE_GUARD_WITHOUT_PURSUIT );- return;- }-- if( waypoint.targetID != INVALID_ID )- {- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );- msg->appendObjectIDArgument( waypoint.targetID );- }- else- {- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );- msg->appendLocationArgument( waypoint.pos );- msg->appendBooleanArgument( waypoint.forceAttack );- }-}--//--------------------------------------------------------------------------------------------------/** The order in flight is over when the target is dead, or when the group has genuinely given up on- * it. Dead was the only way the queue knew, and a target nobody selected could reach or hurt held- * the whole list behind it for the rest of the match - which is what "they only attacked the first- * one" was.- *- * Giving up is measured over time rather than on one frame. A unit chasing something that is- * driving away drops its goal for a frame here and there while it repaths, and a target that runs- * must not fall out of the list because of it; the order is only abandoned after nobody has been- * on it for a couple of seconds, which is long enough that the target really is out of reach. */-//--------------------------------------------------------------------------------------------------void InGameUI::updateShiftAttackQueue( void )-{- // two seconds at the logic's own rate: longer than any repath, shorter than a stalled list- const UnsignedInt ABANDON_ORDER_FRAMES = 60;-- // half a minute with the group out of hand. The list belongs to those units and waits for them,- // but a player who has walked away from it should not have it fire again ten minutes later- // because they happened to reselect the same planes- const UnsignedInt FORGET_UNHELD_FRAMES = 900;-- if( !m_shiftAttackQueueRunning )- return;-- //- // A replay is played back from the recorded command stream, and this is a place that writes new- // commands into it. A viewer who arms the attack key and drags a circle would be adding orders- // that were never in the recording, which is exactly the shape of desync that makes a replay- // stop matching its own CRC.- //- if( TheGameLogic->isInReplayGame() )- {- clearShiftAttackQueue();- return;- }-- std::vector<ObjectID> current;- collectSelectedObjectIDs( current );-- //- // Nothing in hand does not mean the list is over. An aircraft leaves the selection while it is- // on the ground at its airfield, and a flight that went home for ammo therefore stops being a- // group at all for a while - which used to throw the whole list away a second after the first- // target died, with the planes still in the air on their way back. So an empty selection holds- // the list instead of ending it, and it only really ends when every unit that was told is gone.- //- if( current.empty() )- {- Int stillAlive = 0;- for( std::vector<ObjectID>::const_iterator id = m_shiftAttackQueueUnits.begin();- id != m_shiftAttackQueueUnits.end(); ++id )- {- const Object *told = TheGameLogic->findObjectByID( *id );- if( told && !told->isEffectivelyDead() )- stillAlive++;- }-- if( stillAlive == 0 )- {- logShiftAttackQueue( "over, every unit that was told is gone" );- clearShiftAttackQueue();- return;- }-- if( !m_shiftAttackQueueWaitingForSelection )- {- m_shiftAttackQueueWaitingForSelection = TRUE;- DEBUG_LOG(("shift attack queue: frame %d, holding, nothing in hand but %d of the group is alive\n",- TheGameLogic->getFrame(), stillAlive));- }-- // the clock is deliberately not reset here, so a list nobody comes back to eventually lapses- if( TheGameLogic->getFrame() - m_shiftAttackQueueEngagedFrame > FORGET_UNHELD_FRAMES )- {- logShiftAttackQueue( "over, half a minute with none of the group in hand" );- clearShiftAttackQueue();- }-- return;- }-- if( m_shiftAttackQueueWaitingForSelection )- {- // back in hand: the order in flight gets its two seconds again rather than being judged on a- // clock that ran the whole time the group was out of the selection- m_shiftAttackQueueWaitingForSelection = FALSE;- m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();- }-- if( !selectionOwnsShiftAttackQueue( current ) )- {- logShiftAttackQueue( "dropped, the selection is not the group it was given to" );- clearShiftAttackQueue();- return;- }-- Object *target = m_shiftAttackQueueActive.targetID != INVALID_ID- ? TheGameLogic->findObjectByID( m_shiftAttackQueueActive.targetID ) : NULL;-- // a target with enough shots already in the air to kill it is finished as far as the queue is- // concerned. Aircraft are the reason: a flight fires from range and the missiles take seconds to- // arrive, and without this every plane in the group keeps circling a corpse that has not fallen- // over yet instead of taking the next target on the list- if( target && ( target->isEffectivelyDead() || IncomingDamageTracker::isAlreadyDoomed( target ) ) )- target = NULL;-- if( target || m_shiftAttackQueueActive.targetID == INVALID_ID )- {- Bool anyEngaged = FALSE;- Bool anyRearming = FALSE;- Bool anyReadyToGoAgain = FALSE;-- for( DrawableList::const_iterator it = m_selectedDrawables.begin();- it != m_selectedDrawables.end(); ++it )- {- Object *obj = (*it)->getObject();- AIUpdateInterface *ai = obj ? obj->getAIUpdateInterface() : NULL;- if( ai == NULL )- continue;-- const JetAIUpdate *jet = ai->getJetAIUpdate();-- // on the victim it was given, or walking the attack-move point it was given- Bool onOrder = target ? ( ai->getGoalObject() == target )- : ( ai->getAIStateType() == AI_ATTACK_MOVE_TO );-- //- // An aircraft that is taxiing or climbing is carrying the order in its pocket rather than- // in its goal - taking off clears the state machine - so for the length of every takeoff it- // read here as nobody being on the order at all. Two seconds of that and the list moved on- // without it, which is how a flight that went home for ammo came back to an empty queue.- //- if( !onOrder && jet != NULL )- {- ObjectID heldTarget = INVALID_ID;- Coord3D heldPos;- if( jet->friend_getHeldOrder( heldTarget, heldPos ) != AICMD_NO_COMMAND )- onOrder = target ? ( heldTarget == target->getID() ) : TRUE;- }-- if( onOrder )- {- anyEngaged = TRUE;- break;- }-- if( jet == NULL )- continue;-- if( jet->friend_isRearming() || obj->isOutOfAmmo() )- anyRearming = TRUE;- else if( ai->isIdle() )- anyReadyToGoAgain = TRUE;- }-- if( anyEngaged )- {- m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();- m_shiftAttackQueueWaitingForRearm = FALSE;- return;- }-- //- // An aircraft that has run dry leaves the target, lands, fills its racks and comes back, and- // none of that is giving up on the order - but it looks exactly like it from here, and the- // whole list used to drain one entry every two seconds while the flight was away. So the- // clock stops for the trip, and the order that was interrupted is sent again when a plane is- // back in the air with a full load. A jet is not told to resume by itself: only hunting and- // attack moving survive a reload, an ordered attack on a particular target does not.- //- if( anyRearming )- {- m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();- if( !m_shiftAttackQueueWaitingForRearm )- {- m_shiftAttackQueueWaitingForRearm = TRUE;- logShiftAttackQueue( "holding, the group has gone home for ammo" );- }- return;- }-- if( m_shiftAttackQueueWaitingForRearm && anyReadyToGoAgain )- {- m_shiftAttackQueueWaitingForRearm = FALSE;- m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();- logShiftAttackQueue( "rearmed, sending the order again" );- sendShiftAttackOrder( m_shiftAttackQueueActive );- return;- }-- if( TheGameLogic->getFrame() - m_shiftAttackQueueEngagedFrame < ABANDON_ORDER_FRAMES )- return;-- logShiftAttackQueue( "nobody on this order for two seconds, moving on" );- }- else- {- logShiftAttackQueue( "the order in flight is finished, moving on" );- }-- while( !m_shiftAttackQueue.empty() )- {- const AttackWaypoint next = m_shiftAttackQueue.front();- m_shiftAttackQueue.erase( m_shiftAttackQueue.begin() );-- if( next.targetID != INVALID_ID )- {- Object *obj = TheGameLogic->findObjectByID( next.targetID );- if( obj == NULL || obj->isEffectivelyDead() || IncomingDamageTracker::isAlreadyDoomed( obj ) )- {- DEBUG_LOG(("shift attack queue: frame %d, skipping target %d, %s\n",- TheGameLogic->getFrame(), (Int)next.targetID,- obj == NULL ? "gone" : ( obj->isEffectivelyDead() ? "dead" : "already covered" )));- continue;- }- }-- sendShiftAttackOrder( next );-- // a post is where the group stays. Nothing ends a guard, so there is nothing left to wait- // for and the queue closes with it rather than watching an order that never finishes- if( next.kind == ATTACK_WAYPOINT_GUARD )- {- logShiftAttackQueue( "guard sent, the list ends on it" );- clearShiftAttackQueue();- return;- }-- m_shiftAttackQueueActive = next;- m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();- m_shiftAttackQueueWaitingForRearm = FALSE;- logShiftAttackQueue( "next order out" );- return;- }-- logShiftAttackQueue( "list is empty, done" );- clearShiftAttackQueue();+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_QUEUE_NEXT_ORDER );+ msg->appendIntegerArgument( mode );}//-------------------------------------------------------------------------------------------------@@ -7080,13 +6692,6 @@ void InGameUI::deselectDrawable( Drawable *draw )if( draw->isSelected() ){- if( m_shiftAttackQueueRunning )- {- DEBUG_LOG(("shift attack queue: frame %d, %s is leaving the selection\n",- TheGameLogic->getFrame(),- draw->getObject() ? draw->getObject()->getTemplate()->getName().str() : "a drawable"));- }-m_frameSelectionChanged = TheGameLogic->getFrame();// clear the selected bit out of the drawabledraw->friend_clearSelected();@@ -7122,12 +6727,6 @@ void InGameUI::deselectDrawable( Drawable *draw )//-------------------------------------------------------------------------------------------------void InGameUI::deselectAllDrawables( void ){- if( m_shiftAttackQueueRunning && !m_selectedDrawables.empty() )- {- DEBUG_LOG(("shift attack queue: frame %d, the whole selection is being cleared at once\n",- TheGameLogic->getFrame()));- }-const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();const Bool hadSelectedDrawables = !selected->empty();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 68cc7bee7..b0eef5a49 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -962,36 +962,13 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *if (m_teamExists){- // under shift, an attack (force-attack on an attackable, or attack-move) joins the shift- // queue instead of the plain waypoint path - that path is a bare list of points with no- // order type, so it cannot carry an attack. See InGameUI::queueAttackWaypoint.Bool forceAttackHere = isForceAttackTargeting() && isForceAttackable;- Bool queuedGuard = TheInGameUI->isInWaypointMode() && TheInGameUI->isGuardArmed();- Bool queuedAttack = TheInGameUI->isInWaypointMode()- && ( TheInGameUI->isInAttackMoveToMode() || forceAttackHere );- // the guard key posts the selection where it is pointed, and under shift it joins the line- // of orders as its last one: clear this, then sit there. A guard never finishes, so nothing- // can be queued behind it- if( queuedGuard )+ // the guard key posts the selection where it is pointed. Under shift it joins the list as its+ // last order: clear this, then sit there+ if( TheInGameUI->isGuardArmed() ){msgType = GameMessage::MSG_DO_GUARD_POSITION;- if( commandType == DO_COMMAND )- TheInGameUI->queueGuardWaypoint( pos );- }- else if( TheInGameUI->isGuardArmed() )- {- msgType = GameMessage::MSG_DO_GUARD_POSITION;- }- else if( queuedAttack )- {- msgType = forceAttackHere ? GameMessage::MSG_DO_ATTACK_OBJECT : GameMessage::MSG_DO_ATTACKMOVETO;- if( commandType == DO_COMMAND )- TheInGameUI->queueAttackWaypoint( pos, forceAttackHere ? obj : NULL );- }- else if( TheInGameUI->isInWaypointMode() )- {- msgType = GameMessage::MSG_ADD_WAYPOINT;}else if( TheInGameUI->isInAttackMoveToMode()){@@ -1009,8 +986,12 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *{msgType = GameMessage::MSG_DO_MOVETO;}- if( commandType == DO_COMMAND && !queuedAttack && !queuedGuard )+ if( commandType == DO_COMMAND ){+ // shift puts the order on the end of the units' list rather than carrying it out now+ if( TheInGameUI->isInWaypointMode() )+ TheInGameUI->markNextOrderQueued( ORDER_QUEUE_APPEND );+GameMessage *movemsg = TheMessageStream->appendMessage( msgType );if (msgType == GameMessage::MSG_DO_ATTACK_OBJECT)movemsg->appendObjectIDArgument( obj->getID() );@@ -1492,6 +1473,10 @@ void CommandTranslator::finishFormationDrag( const ICoord2D& lift )TheInGameUI->isForceAttackArmed(),TheInGameUI->isGuardArmed() );+ // a line drawn with shift is the next order on the units' list+ if( TheInGameUI->isInWaypointMode() )+ TheInGameUI->markNextOrderQueued( ORDER_QUEUE_APPEND );+// the traced curve becomes world points; who stands where along it is decided on// the logic side, where every machine decides it the same wayGameMessage *newMsg = TheMessageStream->appendMessage( formationType );@@ -1504,11 +1489,6 @@ void CommandTranslator::finishFormationDrag( const ICoord2D& lift )TheInGameUI->clearAttackMoveToMode();- // a hand-given order ends whatever list the group was working through, unless shift- // says the player is adding to it- if( !TheInGameUI->isInWaypointMode() )- TheInGameUI->clearShiftAttackQueue();-const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();if( selected && !selected->empty() )pickAndPlayUnitVoiceResponse( selected, GameMessage::MSG_DO_MOVETO );@@ -1544,13 +1524,15 @@ GameMessage::Type CommandTranslator::evaluateForceAttack( Drawable *draw, const{retVal = GameMessage::MSG_DO_FORCE_ATTACK_OBJECT;- if( type == DO_COMMAND )+ if( type == DO_COMMAND ){pickAndPlayUnitVoiceResponse( allSelected, retVal );+ if( TheInGameUI->isInWaypointMode() )+ TheInGameUI->markNextOrderQueued( ORDER_QUEUE_APPEND );GameMessage *newMsg = TheMessageStream->appendMessage( retVal );newMsg->appendObjectIDArgument( obj->getID() );-- }++ }else if( type == DO_HINT ){retVal = GameMessage::MSG_DO_FORCE_ATTACK_OBJECT_HINT;@@ -1572,12 +1554,14 @@ GameMessage::Type CommandTranslator::evaluateForceAttack( Drawable *draw, const{retVal = GameMessage::MSG_DO_FORCE_ATTACK_GROUND;- if( type == DO_COMMAND )+ if( type == DO_COMMAND ){pickAndPlayUnitVoiceResponse( allSelected, retVal );+ if( TheInGameUI->isInWaypointMode() )+ TheInGameUI->markNextOrderQueued( ORDER_QUEUE_APPEND );GameMessage *newMsg = TheMessageStream->appendMessage( retVal );newMsg->appendLocationArgument( *pos );- }+ }else if( type == DO_HINT ){retVal = GameMessage::MSG_DO_FORCE_ATTACK_GROUND_HINT;@@ -4192,12 +4176,6 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagedisp = DESTROY_MESSAGE;TheInGameUI->clearAttackMoveToMode();-- // a hand-given order ends whatever list the group was working through, unless shift- // says the player is adding to it - in which case the order just given is itself the- // newest entry in that list- if( !TheInGameUI->isInWaypointMode() )- TheInGameUI->clearShiftAttackQueue();}}@@ -4277,11 +4255,6 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagedisp = DESTROY_MESSAGE;TheInGameUI->clearAttackMoveToMode();- // the same rule the right button's orders follow: a hand-given attack ends the list the- // group was working through, unless shift says it is being added to- if( isOrderKey && !TheInGameUI->isInWaypointMode() )- TheInGameUI->clearShiftAttackQueue();-//issueMoveToLocationCommand( &pos, draw, DO_COMMAND );}break;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex f91d4f6dd..2cac126fc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -1089,11 +1089,6 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa// click that follows this release has to be eaten or it would reselect under the anchorif( TheInGameUI->isAttackCircling() ){- // a circle drawn with shift adds its targets to the end of the list the group is- // already working through; without shift it replaces that list- if( !TheInGameUI->isInWaypointMode() )- TheInGameUI->clearShiftAttackQueue();-// a press with the attack key that never became a drag is an ordinary attack click,// and the click that follows this release is the order. Only a real circle eats itif( TheInGameUI->issueAttackCircle() )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cppnew file mode 100644index 000000000..2f0cff108--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp@@ -0,0 +1,762 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// OrderQueue.cpp /////////////////////////////////////////////////////////////////////////////////+// The shift queue, kept by the logic. See OrderQueue.h for what it is for.+///////////////////////////////////////////////////////////////////////////////////////////////////++#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine++#include "GameLogic/OrderQueue.h"++#include "Common/Player.h"+#include "Common/Xfer.h"+#include "GameLogic/AI.h"+#include "GameLogic/AIStateMachine.h"+#include "GameLogic/GameLogic.h"+#include "GameLogic/IncomingDamage.h"+#include "GameLogic/Object.h"+#include "GameLogic/Module/AIUpdate.h"+#include "GameLogic/Module/JetAIUpdate.h"++#include <algorithm>+#include <iterator>++// How long everyone in a chain has to have been off its order before the next one goes out. A unit+// that has just been given an order can read as idle for a frame while it is still being set up, and+// an aircraft taxiing out holds its order rather than being on it; four frames is an eighth of a+// second, which is invisible at a corner and longer than either of those.+static const UnsignedInt STEP_SETTLE_FRAMES = 4;++//-------------------------------------------------------------------------------------------------+QueuedOrder::QueuedOrder( void ) : m_type( GameMessage::MSG_INVALID )+{+}++//-------------------------------------------------------------------------------------------------+void QueuedOrder::copyFrom( const GameMessage *msg )+{+ m_type = msg->getType();+ m_argTypes.clear();+ m_args.clear();+ const Int count = msg->getArgumentCount();+ for( Int i = 0; i < count; i++ )+ {+ m_argTypes.push_back( msg->getArgumentDataType( i ) );+ m_args.push_back( *msg->getArgument( i ) );+ }+}++//-------------------------------------------------------------------------------------------------+GameMessage *QueuedOrder::makeMessage( Int playerIndex ) const+{+ GameMessage *msg = newInstance( GameMessage )( m_type );+ msg->friend_setPlayerIndex( playerIndex );++ const size_t count = m_args.size();+ for( size_t i = 0; i < count; i++ )+ {+ const GameMessageArgumentType& arg = m_args[ i ];+ switch( m_argTypes[ i ] )+ {+ case ARGUMENTDATATYPE_INTEGER: msg->appendIntegerArgument( arg.integer ); break;+ case ARGUMENTDATATYPE_REAL: msg->appendRealArgument( arg.real ); break;+ case ARGUMENTDATATYPE_BOOLEAN: msg->appendBooleanArgument( arg.boolean ); break;+ case ARGUMENTDATATYPE_OBJECTID: msg->appendObjectIDArgument( arg.objectID ); break;+ case ARGUMENTDATATYPE_DRAWABLEID: msg->appendDrawableIDArgument( arg.drawableID ); break;+ case ARGUMENTDATATYPE_TEAMID: msg->appendTeamIDArgument( arg.teamID ); break;+ case ARGUMENTDATATYPE_LOCATION: msg->appendLocationArgument( arg.location ); break;+ case ARGUMENTDATATYPE_PIXEL: msg->appendPixelArgument( arg.pixel ); break;+ case ARGUMENTDATATYPE_PIXELREGION: msg->appendPixelRegionArgument( arg.pixelRegion ); break;+ case ARGUMENTDATATYPE_TIMESTAMP: msg->appendTimestampArgument( arg.timestamp ); break;+ case ARGUMENTDATATYPE_WIDECHAR: msg->appendWideCharArgument( arg.wChar ); break;+ default:+ DEBUG_CRASH(( "QueuedOrder: argument %d of %s has unknown type %d", (Int)i,+ GameMessage::getCommandTypeAsAsciiString( m_type ).str(), (Int)m_argTypes[ i ] ));+ break;+ }+ }++ return msg;+}++//-------------------------------------------------------------------------------------------------+ObjectID QueuedOrder::getTargetID( void ) const+{+ for( size_t i = 0; i < m_args.size(); i++ )+ {+ if( m_argTypes[ i ] == ARGUMENTDATATYPE_OBJECTID )+ return m_args[ i ].objectID;+ }+ return INVALID_ID;+}++//-------------------------------------------------------------------------------------------------+Bool QueuedOrder::getDestination( Coord3D *pos ) const+{+ for( size_t i = 0; i < m_args.size(); i++ )+ {+ if( m_argTypes[ i ] == ARGUMENTDATATYPE_LOCATION )+ {+ *pos = m_args[ i ].location;+ return TRUE;+ }+ }+ return FALSE;+}++//-------------------------------------------------------------------------------------------------+/** Version Info:+ * 1: Initial version */+//-------------------------------------------------------------------------------------------------+void QueuedOrder::xfer( Xfer *xfer )+{+ XferVersion currentVersion = 1;+ XferVersion version = currentVersion;+ xfer->xferVersion( &version, currentVersion );++ Int type = (Int)m_type;+ xfer->xferInt( &type );+ m_type = (GameMessage::Type)type;++ UnsignedByte count = (UnsignedByte)m_args.size();+ xfer->xferUnsignedByte( &count );+ if( xfer->getXferMode() == XFER_LOAD )+ {+ m_argTypes.resize( count );+ m_args.resize( count );+ }++ for( UnsignedByte i = 0; i < count; i++ )+ {+ Int argType = (Int)m_argTypes[ i ];+ xfer->xferInt( &argType );+ m_argTypes[ i ] = (GameMessageArgumentDataType)argType;++ GameMessageArgumentType& arg = m_args[ i ];+ switch( m_argTypes[ i ] )+ {+ case ARGUMENTDATATYPE_INTEGER: xfer->xferInt( &arg.integer ); break;+ case ARGUMENTDATATYPE_REAL: xfer->xferReal( &arg.real ); break;+ case ARGUMENTDATATYPE_BOOLEAN: xfer->xferBool( &arg.boolean ); break;+ case ARGUMENTDATATYPE_OBJECTID: xfer->xferObjectID( &arg.objectID ); break;+ case ARGUMENTDATATYPE_DRAWABLEID: xfer->xferDrawableID( &arg.drawableID ); break;+ case ARGUMENTDATATYPE_TEAMID: xfer->xferUnsignedInt( &arg.teamID ); break;+ case ARGUMENTDATATYPE_LOCATION: xfer->xferCoord3D( &arg.location ); break;+ case ARGUMENTDATATYPE_PIXEL: xfer->xferICoord2D( &arg.pixel ); break;+ case ARGUMENTDATATYPE_PIXELREGION: xfer->xferIRegion2D( &arg.pixelRegion ); break;+ case ARGUMENTDATATYPE_TIMESTAMP: xfer->xferUnsignedInt( &arg.timestamp ); break;+ case ARGUMENTDATATYPE_WIDECHAR: xfer->xferUser( &arg.wChar, sizeof( arg.wChar ) ); break;+ default:+ throw XFER_INVALID_PARAMETERS;+ }+ }+}++//-------------------------------------------------------------------------------------------------+OrderChain::OrderChain( void ) : m_settledFrames( 0 ), m_waitingForRearm( FALSE )+{+}++//-------------------------------------------------------------------------------------------------+/** Is this unit still one of the chain's? A unit that has died, changed hands or climbed into+ * something has left it. A unit in the tunnels on its way somewhere is still walking the order it+ * was given. */+//-------------------------------------------------------------------------------------------------+static Bool OrderQueue_holdsChain( const Object *obj, const Player *owner )+{+ if( obj == NULL || obj->isEffectivelyDead() || obj->getControllingPlayer() != owner )+ return FALSE;++ if( obj->getContainedBy() == NULL )+ return TRUE;++ const AIUpdateInterface *ai = obj->getAIUpdateInterface();+ return ai != NULL && ai->hasTunnelTrip();+}++//-------------------------------------------------------------------------------------------------+/** Is this unit busy with an order the player gave? A fight it picked for itself while standing+ * about is not one: the group is done, and the next order takes it off that fight. Nor is a+ * guard, which never ends. */+//-------------------------------------------------------------------------------------------------+static Bool OrderQueue_isWorking( const AIUpdateInterface *ai )+{+ if( ai->isIdle() || ai->getLastCommandSource() != CMD_FROM_PLAYER )+ return FALSE;++ switch( ai->getCurrentStateID() )+ {+ case AI_GUARD:+ case AI_GUARD_RETALIATE:+ case AI_GUARD_TUNNEL_NETWORK:+ return FALSE;++ default:+ return TRUE;+ }+}++//-------------------------------------------------------------------------------------------------+/** Is this unit walking a plain move, which a queued move can be added to the end of? */+//-------------------------------------------------------------------------------------------------+static Bool OrderQueue_isWalking( const AIUpdateInterface *ai )+{+ switch( ai->getCurrentStateID() )+ {+ case AI_MOVE_TO:+ case AI_FOLLOW_PATH:+ case AI_FOLLOW_WAYPOINT_PATH_AS_INDIVIDUALS:+ case AI_FOLLOW_WAYPOINT_PATH_AS_TEAM:+ return TRUE;++ default:+ return FALSE;+ }+}++//-------------------------------------------------------------------------------------------------+static Bool OrderQueue_isAttack( GameMessage::Type type )+{+ return type == GameMessage::MSG_DO_ATTACK_OBJECT || type == GameMessage::MSG_DO_FORCE_ATTACK_OBJECT;+}++//-------------------------------------------------------------------------------------------------+/** One line per thing a chain did. The queue is driven by a player's clicks, so no unattended run+ * reproduces a fault in it and this line is the whole instrument. Never one per frame. */+//-------------------------------------------------------------------------------------------------+static void OrderQueue_log( const char *what, const OrderChain& chain, const Player *owner )+{+ DEBUG_LOG(( "order queue: frame %d, player %d, %d units, %s, on %s, %d owed\n",+ TheGameLogic->getFrame(), owner->getPlayerIndex(), (Int)chain.m_members.size(), what,+ GameMessage::getCommandTypeAsAsciiString( chain.m_active.getType() ).str(),+ (Int)chain.m_pending.size() ));+}++//-------------------------------------------------------------------------------------------------+/** Hand an order to the units, as if the player had selected exactly them and given it. */+//-------------------------------------------------------------------------------------------------+static void OrderQueue_dispatch( GameMessage *msg, const std::vector<ObjectID>& members )+{+ AIGroup *group = TheAI->createGroup();+ for( std::vector<ObjectID>::const_iterator it = members.begin(); it != members.end(); ++it )+ {+ Object *obj = TheGameLogic->findObjectByID( *it );+ if( obj )+ group->add( obj );+ }++ // the dispatcher destroys the group when it is done with it+ TheGameLogic->logicMessageDispatcher( msg, group );+}++//-------------------------------------------------------------------------------------------------+static void OrderQueue_dispatch( const QueuedOrder& order, const std::vector<ObjectID>& members, Player *owner )+{+ GameMessage *msg = order.makeMessage( owner->getPlayerIndex() );+ OrderQueue_dispatch( msg, members );+ msg->deleteInstance();+}++//-------------------------------------------------------------------------------------------------+/** A queued move while the units are already walking one goes on the end of the path they are+ * walking, the way a shift move always did, rather than waiting for them to stop first. */+//-------------------------------------------------------------------------------------------------+static void OrderQueue_extendWalk( const Coord3D& dest, const std::vector<ObjectID>& members, Player *owner )+{+ GameMessage *msg = newInstance( GameMessage )( GameMessage::MSG_ADD_WAYPOINT );+ msg->friend_setPlayerIndex( owner->getPlayerIndex() );+ msg->appendLocationArgument( dest );+ OrderQueue_dispatch( msg, members );+ msg->deleteInstance();+}++//-------------------------------------------------------------------------------------------------+OrderQueue::OrderQueue( void ) : m_nextOrderMode( ORDER_QUEUE_NONE )+{+}++//-------------------------------------------------------------------------------------------------+void OrderQueue::reset( void )+{+ m_chains.clear();+ m_nextOrderMode = ORDER_QUEUE_NONE;+}++//-------------------------------------------------------------------------------------------------+void OrderQueue::setNextOrderMode( Int mode )+{+ if( mode < ORDER_QUEUE_APPEND || mode >= ORDER_QUEUE_MODE_COUNT )+ {+ DEBUG_CRASH(( "MSG_QUEUE_NEXT_ORDER: mode %d is not an OrderQueueMode", mode ));+ m_nextOrderMode = ORDER_QUEUE_NONE;+ return;+ }+ m_nextOrderMode = mode;+}++//-------------------------------------------------------------------------------------------------+Bool OrderQueue::isOrder( GameMessage::Type type )+{+ switch( type )+ {+ case GameMessage::MSG_DO_MOVETO:+ case GameMessage::MSG_DO_ATTACKMOVETO:+ case GameMessage::MSG_DO_FORCEMOVETO:+ case GameMessage::MSG_ADD_WAYPOINT:+ case GameMessage::MSG_DO_SALVAGE:+ case GameMessage::MSG_DO_ATTACK_OBJECT:+ case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:+ case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:+ case GameMessage::MSG_DO_GUARD_POSITION:+ case GameMessage::MSG_DO_GUARD_OBJECT:+ case GameMessage::MSG_DO_HOLD_POSITION:+ case GameMessage::MSG_DO_STOP:+ case GameMessage::MSG_DO_SCATTER:+ case GameMessage::MSG_DO_FORMATION_MOVETO:+ case GameMessage::MSG_DO_FORMATION_ATTACKMOVETO:+ case GameMessage::MSG_DO_FORMATION_FORCEATTACK:+ case GameMessage::MSG_DO_FORMATION_GUARD:+ case GameMessage::MSG_ENTER:+ case GameMessage::MSG_DOCK:+ case GameMessage::MSG_GET_REPAIRED:+ case GameMessage::MSG_GET_HEALED:+ case GameMessage::MSG_DO_REPAIR:+ return TRUE;++ default:+ return FALSE;+ }+}++//-------------------------------------------------------------------------------------------------+Bool OrderQueue::isQueueable( GameMessage::Type type )+{+ switch( type )+ {+ case GameMessage::MSG_DO_MOVETO:+ case GameMessage::MSG_DO_ATTACKMOVETO:+ case GameMessage::MSG_DO_FORCEMOVETO:+ case GameMessage::MSG_DO_ATTACK_OBJECT:+ case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:+ case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:+ case GameMessage::MSG_DO_GUARD_POSITION:+ case GameMessage::MSG_DO_GUARD_OBJECT:+ case GameMessage::MSG_DO_HOLD_POSITION:+ case GameMessage::MSG_DO_FORMATION_MOVETO:+ case GameMessage::MSG_DO_FORMATION_ATTACKMOVETO:+ case GameMessage::MSG_DO_FORMATION_FORCEATTACK:+ case GameMessage::MSG_DO_FORMATION_GUARD:+ return TRUE;++ default:+ return FALSE;+ }+}++//-------------------------------------------------------------------------------------------------+Bool OrderQueue::isTerminal( GameMessage::Type type )+{+ switch( type )+ {+ case GameMessage::MSG_DO_GUARD_POSITION:+ case GameMessage::MSG_DO_GUARD_OBJECT:+ case GameMessage::MSG_DO_HOLD_POSITION:+ case GameMessage::MSG_DO_FORMATION_GUARD:+ case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:+ case GameMessage::MSG_DO_FORMATION_FORCEATTACK:+ return TRUE;++ default:+ return FALSE;+ }+}++//-------------------------------------------------------------------------------------------------+const OrderChain *OrderQueue::findChain( ObjectID id ) const+{+ for( OrderChainList::const_iterator it = m_chains.begin(); it != m_chains.end(); ++it )+ {+ if( std::binary_search( it->m_members.begin(), it->m_members.end(), id ) )+ return &(*it);+ }+ return NULL;+}++//-------------------------------------------------------------------------------------------------+Bool OrderQueue::takeMessage( GameMessage *msg, AIGroup *selected, Player *owner )+{+ const Int mode = m_nextOrderMode;+ m_nextOrderMode = ORDER_QUEUE_NONE;++ if( selected == NULL || !isOrder( msg->getType() ) )+ return FALSE;++ std::vector<ObjectID> ids = selected->getAllIDs();+ std::sort( ids.begin(), ids.end() );++ if( mode == ORDER_QUEUE_NONE || !isQueueable( msg->getType() ) )+ {+ releaseUnits( ids );+ return FALSE;+ }++ // gone before anything is dispatched: every order handed out below puts its units into a group+ // of its own, and a unit joining one leaves this one, which destroys it when the last one goes+ TheAI->destroyGroup( selected );++ if( mode == ORDER_QUEUE_FRESH )+ {+ releaseUnits( ids );+ startChain( msg, ids, owner );+ return TRUE;+ }++ queueOrder( msg, ids, owner );+ return TRUE;+}++//-------------------------------------------------------------------------------------------------+/** Shift: every chain the selection touches gets the order on its end. A chain only part of which+ * is selected splits, and the selected part carries on with its own copy of the list; units in no+ * chain start one, behind whatever they are doing now. */+//-------------------------------------------------------------------------------------------------+void OrderQueue::queueOrder( GameMessage *msg, const std::vector<ObjectID>& selected, Player *owner )+{+ // who in the selection belongs to which chain, found before any chain is split or started, so the+ // new chains are not visited as though they were old ones+ std::vector<OrderChainList::iterator> touched;+ std::vector< std::vector<ObjectID> > parts;+ std::vector<ObjectID> loose = selected;++ for( OrderChainList::iterator it = m_chains.begin(); it != m_chains.end(); ++it )+ {+ std::vector<ObjectID> part;+ std::set_intersection( it->m_members.begin(), it->m_members.end(),+ selected.begin(), selected.end(), std::back_inserter( part ) );+ if( part.empty() )+ continue;++ touched.push_back( it );+ parts.push_back( part );++ std::vector<ObjectID> rest;+ std::set_difference( loose.begin(), loose.end(), part.begin(), part.end(), std::back_inserter( rest ) );+ loose.swap( rest );+ }++ for( size_t i = 0; i < touched.size(); i++ )+ {+ OrderChain& chain = *touched[ i ];+ if( parts[ i ].size() == chain.m_members.size() )+ {+ appendOrder( chain, msg, owner );+ continue;+ }++ OrderChain split = chain;+ split.m_members = parts[ i ];++ std::vector<ObjectID> rest;+ std::set_difference( chain.m_members.begin(), chain.m_members.end(),+ parts[ i ].begin(), parts[ i ].end(), std::back_inserter( rest ) );+ chain.m_members.swap( rest );++ m_chains.push_back( split );+ appendOrder( m_chains.back(), msg, owner );+ }++ if( loose.empty() )+ return;++ Bool anyWorking = FALSE;+ Bool allWalking = TRUE;+ for( std::vector<ObjectID>::const_iterator it = loose.begin(); it != loose.end(); ++it )+ {+ const Object *obj = TheGameLogic->findObjectByID( *it );+ const AIUpdateInterface *ai = obj ? obj->getAIUpdateInterface() : NULL;+ if( ai == NULL || !OrderQueue_isWorking( ai ) )+ continue;+ anyWorking = TRUE;+ if( !OrderQueue_isWalking( ai ) )+ allWalking = FALSE;+ }++ if( !anyWorking )+ {+ startChain( msg, loose, owner );+ return;+ }++ // they are busy with an order that was given without shift, so the list starts behind it+ OrderChain chain;+ chain.m_members = loose;+ m_chains.push_back( chain );+ OrderChain& added = m_chains.back();++ if( msg->getType() == GameMessage::MSG_DO_MOVETO && allWalking )+ {+ OrderQueue_extendWalk( msg->getArgument( 0 )->location, added.m_members, owner );+ added.m_active.copyFrom( msg );+ return;+ }++ added.m_pending.push_back( QueuedOrder() );+ added.m_pending.back().copyFrom( msg );+}++//-------------------------------------------------------------------------------------------------+/** A new chain whose first order goes out now. */+//-------------------------------------------------------------------------------------------------+void OrderQueue::startChain( GameMessage *msg, const std::vector<ObjectID>& members, Player *owner )+{+ OrderQueue_dispatch( msg, members );++ // a guard is not a list, just an order+ if( isTerminal( msg->getType() ) )+ return;++ OrderChain chain;+ chain.m_members = members;+ chain.m_active.copyFrom( msg );+ m_chains.push_back( chain );+}++//-------------------------------------------------------------------------------------------------+void OrderQueue::appendOrder( OrderChain& chain, GameMessage *msg, Player *owner )+{+ // nothing after a guard would ever come round+ if( !chain.m_pending.empty() && isTerminal( chain.m_pending.back().getType() ) )+ return;++ if( msg->getType() == GameMessage::MSG_DO_MOVETO && chain.m_pending.empty()+ && chain.m_active.getType() == GameMessage::MSG_DO_MOVETO )+ {+ OrderQueue_extendWalk( msg->getArgument( 0 )->location, chain.m_members, owner );+ return;+ }++ chain.m_pending.push_back( QueuedOrder() );+ chain.m_pending.back().copyFrom( msg );+}++//-------------------------------------------------------------------------------------------------+/** An order given without shift: those units are out of whatever chain they were in. */+//-------------------------------------------------------------------------------------------------+void OrderQueue::releaseUnits( const std::vector<ObjectID>& ids )+{+ for( OrderChainList::iterator it = m_chains.begin(); it != m_chains.end(); )+ {+ std::vector<ObjectID> rest;+ std::set_difference( it->m_members.begin(), it->m_members.end(),+ ids.begin(), ids.end(), std::back_inserter( rest ) );+ it->m_members.swap( rest );++ if( it->m_members.empty() )+ it = m_chains.erase( it );+ else+ ++it;+ }+}++//-------------------------------------------------------------------------------------------------+void OrderQueue::update( Player *owner )+{+ for( OrderChainList::iterator it = m_chains.begin(); it != m_chains.end(); )+ {+ OrderChain& chain = *it;++ std::vector<ObjectID> alive;+ for( std::vector<ObjectID>::const_iterator id = chain.m_members.begin(); id != chain.m_members.end(); ++id )+ {+ if( OrderQueue_holdsChain( TheGameLogic->findObjectByID( *id ), owner ) )+ alive.push_back( *id );+ }+ chain.m_members.swap( alive );++ if( chain.m_members.empty() || ( isStepOver( chain, owner ) && !advance( chain, owner ) ) )+ it = m_chains.erase( it );+ else+ ++it;+ }+}++//-------------------------------------------------------------------------------------------------+/** The order in front is over when its target is gone, or once nobody in the chain has been working+ * on it for a few frames. An aircraft gone home for ammo is not done with it: the chain waits, and+ * sends the order again when the flight is back in the air with a full load, since an ordered+ * attack on one target does not survive a reload. */+//-------------------------------------------------------------------------------------------------+Bool OrderQueue::isStepOver( OrderChain& chain, Player *owner )+{+ const ObjectID targetID = chain.m_active.getTargetID();+ if( targetID != INVALID_ID )+ {+ const Object *target = TheGameLogic->findObjectByID( targetID );+ if( target == NULL || target->isEffectivelyDead() )+ return TRUE;++ // a flight fires from range and its missiles take seconds to arrive, so a target with enough+ // already in the air to kill it is finished as far as the list is concerned+ if( OrderQueue_isAttack( chain.m_active.getType() ) && IncomingDamageTracker::isAlreadyDoomed( target ) )+ return TRUE;+ }++ Bool anyWorking = FALSE;+ Bool anyRearming = FALSE;+ Bool anyReadyToGoAgain = FALSE;++ for( std::vector<ObjectID>::const_iterator id = chain.m_members.begin(); id != chain.m_members.end(); ++id )+ {+ const Object *obj = TheGameLogic->findObjectByID( *id );+ const AIUpdateInterface *ai = obj->getAIUpdateInterface();+ if( ai == NULL )+ continue;++ const JetAIUpdate *jet = ai->getJetAIUpdate();+ if( jet != NULL )+ {+ if( jet->friend_isRearming() || obj->isOutOfAmmo() )+ {+ anyRearming = TRUE;+ continue;+ }++ // a parked aircraft carries its order in its pocket until the wheels are up+ ObjectID heldTarget = INVALID_ID;+ Coord3D heldPos;+ if( jet->friend_getHeldOrder( heldTarget, heldPos ) != AICMD_NO_COMMAND )+ {+ anyWorking = TRUE;+ continue;+ }+ }++ if( OrderQueue_isWorking( ai ) || ai->hasTunnelTrip() )+ anyWorking = TRUE;+ else if( jet != NULL )+ anyReadyToGoAgain = TRUE;+ }++ if( anyWorking )+ {+ chain.m_settledFrames = 0;+ return FALSE;+ }++ if( anyRearming )+ {+ if( !chain.m_waitingForRearm )+ OrderQueue_log( "holding, gone home for ammo", chain, owner );+ chain.m_waitingForRearm = TRUE;+ chain.m_settledFrames = 0;+ return FALSE;+ }++ if( chain.m_waitingForRearm && anyReadyToGoAgain && !chain.m_active.isStanding() )+ {+ chain.m_waitingForRearm = FALSE;+ chain.m_settledFrames = 0;+ OrderQueue_log( "rearmed, sending the order again", chain, owner );+ OrderQueue_dispatch( chain.m_active, chain.m_members, owner );+ return FALSE;+ }++ chain.m_settledFrames++;+ return chain.m_settledFrames >= STEP_SETTLE_FRAMES;+}++//-------------------------------------------------------------------------------------------------+/** Send the next order that still makes sense. A queued attack on something that has died since+ * is skipped, and a run of moves goes out as one path so the units do not stop at every point. */+//-------------------------------------------------------------------------------------------------+Bool OrderQueue::advance( OrderChain& chain, Player *owner )+{+ while( !chain.m_pending.empty() )+ {+ const QueuedOrder next = chain.m_pending.front();+ chain.m_pending.erase( chain.m_pending.begin() );++ const ObjectID targetID = next.getTargetID();+ if( targetID != INVALID_ID )+ {+ const Object *target = TheGameLogic->findObjectByID( targetID );+ if( target == NULL || target->isEffectivelyDead()+ || ( OrderQueue_isAttack( next.getType() ) && IncomingDamageTracker::isAlreadyDoomed( target ) ) )+ continue;+ }++ OrderQueue_dispatch( next, chain.m_members, owner );+ if( isTerminal( next.getType() ) )+ {+ OrderQueue_log( "last order out, it never ends", chain, owner );+ return FALSE;+ }++ chain.m_active = next;+ chain.m_settledFrames = 0;+ chain.m_waitingForRearm = FALSE;+ OrderQueue_log( "next order out", chain, owner );++ Coord3D dest;+ while( next.getType() == GameMessage::MSG_DO_MOVETO && !chain.m_pending.empty()+ && chain.m_pending.front().getType() == GameMessage::MSG_DO_MOVETO+ && chain.m_pending.front().getDestination( &dest ) )+ {+ OrderQueue_extendWalk( dest, chain.m_members, owner );+ chain.m_pending.erase( chain.m_pending.begin() );+ }++ return TRUE;+ }++ OrderQueue_log( "list is done", chain, owner );+ return FALSE;+}++//-------------------------------------------------------------------------------------------------+/** Version Info:+ * 1: Initial version */+//-------------------------------------------------------------------------------------------------+void OrderQueue::xfer( Xfer *xfer )+{+ XferVersion currentVersion = 1;+ XferVersion version = currentVersion;+ xfer->xferVersion( &version, currentVersion );++ UnsignedShort chainCount = (UnsignedShort)m_chains.size();+ xfer->xferUnsignedShort( &chainCount );+ if( xfer->getXferMode() == XFER_LOAD )+ m_chains.resize( chainCount );++ for( OrderChainList::iterator it = m_chains.begin(); it != m_chains.end(); ++it )+ {+ xfer->xferSTLObjectIDVector( &it->m_members );+ it->m_active.xfer( xfer );++ UnsignedShort pendingCount = (UnsignedShort)it->m_pending.size();+ xfer->xferUnsignedShort( &pendingCount );+ if( xfer->getXferMode() == XFER_LOAD )+ it->m_pending.resize( pendingCount );+ for( std::vector<QueuedOrder>::iterator order = it->m_pending.begin(); order != it->m_pending.end(); ++order )+ order->xfer( xfer );++ xfer->xferUnsignedInt( &it->m_settledFrames );+ xfer->xferBool( &it->m_waitingForRearm );+ }+}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex 453ae39ab..8ebd0c7df 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -2674,6 +2674,10 @@ void GameLogic::processCommandList( CommandList *list )logicMessageDispatcher( msg, NULL );}+ // a shift prefix belongs to the order right behind it in the same frame, never to a later one+ for( Int i = 0; i < ThePlayerList->getPlayerCount(); i++ )+ ThePlayerList->getNthPlayer( i )->getOrderQueue()->forgetNextOrderMode();+if (m_shouldValidateCRCs && !TheNetwork->sawCRCMismatch()){Bool sawCRCMismatch = FALSE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 424ebe140..181427898 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -463,7 +463,7 @@ static void makeObjectHeroic( Object *obj, void *userData )* appropriate objects.* @todo Rename this to "CommandProcessor", or similiar. *///--------------------------------------------------------------------------------------------------void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )+void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup ){#ifdef _DEBUGDEBUG_ASSERTCRASH(msg != NULL && msg != (GameMessage*)0xdeadbeef, ("bad msg"));@@ -485,9 +485,9 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )return;}- AIGroup *currentlySelectedGroup = NULL;+ AIGroup *currentlySelectedGroup = orderedGroup;- if (isInGame())+ if (isInGame() && orderedGroup == NULL){if (msg->getType() >= GameMessage::MSG_BEGIN_NETWORK_MESSAGES && msg->getType() <= GameMessage::MSG_END_NETWORK_MESSAGES){@@ -540,8 +540,26 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )// process the messageGameMessage::Type msgType = msg->getType();++ //+ // The shift queue (fork). A queued order goes into the sender's order queue and comes back through+ // here later with its units named in orderedGroup; an order given without shift ends the list for+ // the units it went to. An order already coming round from the queue is not looked at again.+ // See OrderQueue.h.+ //+ if( orderedGroup == NULL && msgType != GameMessage::MSG_QUEUE_NEXT_ORDER+ && thisPlayer->getOrderQueue()->takeMessage( msg, currentlySelectedGroup, thisPlayer ) )+ return; // the queue destroyed the group+switch( msgType ){+ //---------------------------------------------------------------------------------------------+ case GameMessage::MSG_QUEUE_NEXT_ORDER:+ {+ thisPlayer->getOrderQueue()->setNextOrderMode( msg->getArgument( 0 )->integer );+ break;+ }+//---------------------------------------------------------------------------------------------case GameMessage::MSG_NEW_GAME:{@@ -2527,7 +2545,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )} // end switch/**/ /// @todo: multiplayer semantics- if (currentlySelectedGroup && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && TheControlBar->getObserverLookAtPlayer() == thisPlayer /*&& !TheRecorder->isMultiplayer()*/)+ if (currentlySelectedGroup && orderedGroup == NULL && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && TheControlBar->getObserverLookAtPlayer() == thisPlayer /*&& !TheRecorder->isMultiplayer()*/){const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();TheInGameUI->deselectAllDrawables();diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cppindex d8e26db39..6d44ef42c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp@@ -181,6 +181,14 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio*action = SCENARIO_ACTION_PRODUCE;else if (token == "tally")*action = SCENARIO_ACTION_TALLY;+ else if (token == "shiftmove")+ *action = SCENARIO_ACTION_SHIFTMOVE;+ else if (token == "shiftattackmove")+ *action = SCENARIO_ACTION_SHIFTATTACKMOVE;+ else if (token == "shiftattack")+ *action = SCENARIO_ACTION_SHIFTATTACK;+ else if (token == "shiftguard")+ *action = SCENARIO_ACTION_SHIFTGUARD;elsereturn FALSE;@@ -259,6 +267,10 @@ static Int tokensNeededFor( ScenarioActionType action )case SCENARIO_ACTION_POWER: return SCENARIO_TOKENS_MOVE;case SCENARIO_ACTION_PLAYERATTACKMOVE: return SCENARIO_TOKENS_MOVE;case SCENARIO_ACTION_ATTACKMOVE: return SCENARIO_TOKENS_MOVE;+ case SCENARIO_ACTION_SHIFTMOVE: return SCENARIO_TOKENS_MOVE;+ case SCENARIO_ACTION_SHIFTATTACKMOVE: return SCENARIO_TOKENS_MOVE;+ case SCENARIO_ACTION_SHIFTGUARD: return SCENARIO_TOKENS_MOVE;+ case SCENARIO_ACTION_SHIFTATTACK: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_ATTACK: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_ENTER: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_PRODUCE: return SCENARIO_TOKENS_ATTACK;@@ -330,6 +342,9 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *acase SCENARIO_ACTION_ATTACKMOVE:case SCENARIO_ACTION_ARRIVE:case SCENARIO_ACTION_POWER:+ case SCENARIO_ACTION_SHIFTMOVE:+ case SCENARIO_ACTION_SHIFTATTACKMOVE:+ case SCENARIO_ACTION_SHIFTGUARD:{Int next = SCENARIO_ORDER_POSITION_TOKEN;const ScenarioParseResult position = parseScenarioPosition( tokens, count, &next, action );@@ -344,6 +359,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *acase SCENARIO_ACTION_ATTACK:case SCENARIO_ACTION_ENTER:+ case SCENARIO_ACTION_SHIFTATTACK:{if (!parseWholeNumber( tokens[ 4 ], &action->targetSlot ))return SCENARIO_PARSE_BAD_SLOT;@@ -994,6 +1010,65 @@ static Bool executeTally( const ScenarioAction &action, Player *player )return TRUE;}+/** A shift click: the order goes onto the seat's order queue the way it would arrive over the network+ with MSG_QUEUE_NEXT_ORDER in front of it, carrying the arguments the command translator gives it.+ The group is destroyed here on every path, by the queue when it takes the order. */+static Bool executeShiftOrder( const ScenarioAction &action, Player *player, const Coord3D &dest,+ AIGroup *group, Int taken )+{+ GameMessage::Type type = GameMessage::MSG_DO_GUARD_POSITION;+ const char *verb = "shiftguard";+ if (action.action == SCENARIO_ACTION_SHIFTMOVE)+ {+ type = GameMessage::MSG_DO_MOVETO;+ verb = "shiftmove";+ }+ else if (action.action == SCENARIO_ACTION_SHIFTATTACKMOVE)+ {+ type = GameMessage::MSG_DO_ATTACKMOVETO;+ verb = "shiftattackmove";+ }+ else if (action.action == SCENARIO_ACTION_SHIFTATTACK)+ {+ type = GameMessage::MSG_DO_ATTACK_OBJECT;+ verb = "shiftattack";+ }++ GameMessage *msg = newInstance( GameMessage )( type );+ msg->friend_setPlayerIndex( player->getPlayerIndex() );++ if (type == GameMessage::MSG_DO_ATTACK_OBJECT)+ {+ Player *targetPlayer = findPlayerForSlot( action.targetSlot );+ Object *target = (targetPlayer != NULL) ? findFirstMatching( targetPlayer, action.targetSelector ) : NULL;+ if (target == NULL)+ {+ DEBUG_LOG(("SCENARIO: frame %d %s: slot %d owns nothing matching '%s'\n",+ action.frame, verb, action.targetSlot, action.targetSelector.str()));+ msg->deleteInstance();+ TheAI->destroyGroup( group );+ return FALSE;+ }+ msg->appendObjectIDArgument( target->getID() );+ }+ else+ {+ msg->appendLocationArgument( dest );+ if (type == GameMessage::MSG_DO_ATTACKMOVETO)+ msg->appendBooleanArgument( FALSE );+ if (type == GameMessage::MSG_DO_GUARD_POSITION)+ msg->appendIntegerArgument( GUARDMODE_GUARD_WITHOUT_PURSUIT );+ }++ player->getOrderQueue()->setNextOrderMode( ORDER_QUEUE_APPEND );+ player->getOrderQueue()->takeMessage( msg, group, player );+ msg->deleteInstance();++ DEBUG_LOG(("SCENARIO: frame %d %s slot %d '%s' x%d\n",+ action.frame, verb, action.slot, action.selector.str(), taken));+ return TRUE;+}+static Bool executeOrder( const ScenarioAction &action, Player *player, const Coord3D &dest ){AIGroup *group = TheAI->createGroup();@@ -1061,6 +1136,12 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Cobreak;}+ case SCENARIO_ACTION_SHIFTMOVE:+ case SCENARIO_ACTION_SHIFTATTACKMOVE:+ case SCENARIO_ACTION_SHIFTATTACK:+ case SCENARIO_ACTION_SHIFTGUARD:+ return executeShiftOrder( action, player, dest, group, taken ); // the group is gone either way+case SCENARIO_ACTION_STOP:{group->groupIdle( CMD_FROM_SCRIPT );diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 70bf4095c..2c70a8e09 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -51,6 +51,7 @@#include "GameClient/KeyDownInfo.h"#include "GameClient/GameWindowTransitions.h"#include "GameLogic/ScenarioDrill.h"+#include "GameLogic/OrderQueue.h"#include "Common/ControlServer.h"#include "GameLogic/LogicRandomValue.h"#include "GameClient/ClientRandomValue.h"@@ -13194,6 +13195,28 @@ TEST(scenario_parses_a_particles_line)CHECK_EQ( (Int)ScenarioDrill_parseLine( "30 particles 0 X 5 760", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );}+// A queued order that is not an order would never end a list when given without shift, and an order+// that ends its chain but cannot be queued would never be reached. The prefix itself is not an order,+// or it would release the units it is about to queue for.+TEST(order_queue_kinds_nest)+{+ for( Int type = GameMessage::MSG_BEGIN_NETWORK_MESSAGES; type <= GameMessage::MSG_END_NETWORK_MESSAGES; type++ )+ {+ const GameMessage::Type messageType = (GameMessage::Type)type;+ if( OrderQueue::isQueueable( messageType ) )+ CHECK( OrderQueue::isOrder( messageType ) );+ if( OrderQueue::isTerminal( messageType ) )+ CHECK( OrderQueue::isQueueable( messageType ) );+ }++ CHECK( !OrderQueue::isOrder( GameMessage::MSG_QUEUE_NEXT_ORDER ) );+ CHECK( OrderQueue::isQueueable( GameMessage::MSG_DO_ATTACKMOVETO ) );+ CHECK( !OrderQueue::isTerminal( GameMessage::MSG_DO_ATTACKMOVETO ) );+ CHECK( OrderQueue::isTerminal( GameMessage::MSG_DO_GUARD_POSITION ) );+ CHECK( OrderQueue::isOrder( GameMessage::MSG_DO_STOP ) );+ CHECK( !OrderQueue::isQueueable( GameMessage::MSG_DO_STOP ) );+}+TEST(scenario_parses_the_order_lines){ScenarioAction action;@@ -13225,6 +13248,18 @@ TEST(scenario_parses_the_order_lines)CHECK_EQ( (Int)ScenarioDrill_parseLine( "900 stop 2 *", &action ), (Int)SCENARIO_PARSE_OK );CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_STOP );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftmove 0 * start1:0:-400", &action ), (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTMOVE );+ CHECK_EQ( action.atStart, 1 );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftattackmove 0 * 900 700", &action ), (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTATTACKMOVE );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftguard 0 * 900 700", &action ), (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTGUARD );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftattack 0 * 1 AmericaCommandCenter", &action ), (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTATTACK );+ CHECK_STR( action.targetSelector.str(), "AmericaCommandCenter" );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftattack 0 * 1", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );+CHECK_EQ( (Int)ScenarioDrill_parseLine( "1800 tally 1 ChinaGattlingCannon", &action ), (Int)SCENARIO_PARSE_OK );CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_TALLY );CHECK_STR( action.selector.str(), "ChinaGattlingCannon" );