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(gameclient): force-attack/attack-move keys, drag-circle queue, shift-queued attacks
Olcay Seygan9a782ec60a37
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b34019d47..4d5604f80 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -116,7 +116,11 @@ found and fixed — EA's own, not port damage.**- Ctrl+Q now takes infantry only, not every armed thing you own.- A box drawn with Ctrl held takes those units back out of your selection instead of replacing it, so a group is trimmed by dragging over the corner of it rather than picked again from scratch. Held with Alt the box keeps only what can shoot: drag across your base and you get the tanks, not the dozers and supply trucks standing among them. Both are drag-only, and a single click still means exactly what it always did.- The three buttons each do one thing now. Left selects, and only selects. Right gives orders, and nothing it does moves the camera. The camera is on the middle button, and it scrolls the way the right button used to: the spot you pressed on stays put, and the further you pull away from it the faster the map runs. Hold Ctrl and the same drag turns the view instead. The wheel zooms toward whatever the cursor is over and the screen edges still scroll. The classic scheme, where left both selected and commanded and right scrolled and deselected, is gone rather than switched off, and the two checkboxes that used to choose between them are out of the options screen.-- Drag the right button and you draw a line: the selection spreads itself evenly along it, in the order the units already stand, so a column arrives as a firing line instead of a queue. It is the line you actually drew, curves and all, so you can bend a defence round a hillside or pour men along a wall instead of only across a straight run. Ticks on it show where each unit lands before you let go, and letting go over the sidebar finishes the order rather than leaving the line stuck to the cursor. This is what the right button freed up. `FormationDrag = no` in Options.ini turns it off if you would rather a slipped click did nothing.+- Drag the right button and you draw a line: the selection spreads itself evenly along it, in the order the units already stand, so a column arrives as a firing line instead of a queue. It is the line you actually drew, curves and all, however far you keep drawing it: a long sweep used to give up partway through and finish as one straight run to the cursor, and now it holds its shape to the end. Letting go over the sidebar finishes the order rather than leaving the line stuck to the cursor. Draw the same line with attack move armed and the whole line is an attack move: artillery spread across a front, each gun firing on what walks into it, instead of one clump on one spot. Armed with attack instead, every unit fires on its own station along the line, which is a barrage laid across a ridge in one drag. This is what the right button freed up. `FormationDrag = no` in Options.ini turns it off if you would rather a slipped click did nothing.+- Selected units draw a thread to wherever they are going, and the marker on the spot is the game's own cursor. Every order that has a cursor gets that cursor: move, attack move, attack, force fire, ground fire, enter, dock, repair, heal, capture, hack, guard, a waypoint path. Green for a move, pink for an attack-move, red for anything that shoots, so a group told three different things reads as three different colours. It is not a flash at the moment of the order: the line is asked of the unit every frame, so it lasts until the unit gets there, changes its mind or leaves your selection, and it shows on the formation line while you are still drawing it. A unit that has walked off the edge of the screen still draws its line, which is how you see where the half of your army you cannot see is headed.+- A is attack and F is attack move, each arming the next order click. A click on the ground with A held down is a shot at that ground, on your own tank a shot at your own tank, and the mode drops again the moment the order goes out, so nothing stays armed behind your back. Ctrl still forces fire while you hold it. The two keys turn each other off, and the letters they took were sitting on grid commands that moved.+- 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. Any order you give by hand ends the list, and so does changing what is selected.+- 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.- 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.## Aircraft, guards, and orders that used to be ignored@@ -396,7 +400,7 @@ found and fixed — EA's own, not port damage.**- The main menu plays its battle again instead of showing one still picture. The game asks Windows how much memory the machine has and compares the answer against a 256MB minimum, and on a machine with more than 4GB installed that answer arrived as minus one - so the better the machine, the more certain the game was that it did not meet the 2003 minimum. It switched off the animated menu, forced textures down and, at the preset detail levels, took the trees out. It reads the real figure now.- The Default button in the options menu no longer throws away your resolution. It reset the display along with everything else, dropping you to 800x600 with no undo.- Text does not vanish at large sizes. Any font over 100 points simply failed to load, which on a 4K screen is a missing line of interface.-- Zoom further out, with the whole map drawn instead of black corners.+- Zoom further out, with the whole map drawn instead of black corners. The ceiling is twice what it was again, which is the difference between watching your own half of the map and watching both.- The zoom-out ceiling is the same for everyone; no setting buys you a wider view.- The wheel covers that whole range in about six notches instead of thirty-eight.- Zoom toward the cursor works; the spot under your pointer stays there.diff --git a/GeneralsMD/Code/Data/INI/CommandMap.ini b/GeneralsMD/Code/Data/INI/CommandMap.iniindex 5d3a170ae..1b7318d7d 100644--- a/GeneralsMD/Code/Data/INI/CommandMap.ini+++ b/GeneralsMD/Code/Data/INI/CommandMap.ini@@ -18,9 +18,9 @@; slot 01 03 05 07 09 11 13 (top row) Q W E R T Y U; slot 02 04 06 08 10 12 14 (bottom row) Z X C V B N M;-; The bottom row is Z X C V B N M so that A (attack move) and S (stop) stay-; free for the units. The previous owners of the grid letters moved onto a-; modifier - see "displaced" below.+; The bottom row is Z X C V B N M so that A (attack), S (stop) and F (attack+; move) stay free for the units. The previous owners of the grid letters moved+; onto a modifier - see "displaced" below.; column 1, top rowCommandMap COMMAND_SLOT01@@ -305,10 +305,11 @@ CommandMap SELECT_NEXT_IDLE_WORKERDisplayName = GUI:SelectNextIdleWorkerEnd-; attack move. 'A' arms the mode, the next order click issues it (CommandXlat-; clears the mode again right after, so it is single shot).+; attack move. 'F' arms the mode, the next order click issues it (CommandXlat+; clears the mode again right after, so it is single shot). It sits next to the+; attack key below, and the two turn each other off.CommandMap TOGGLE_ATTACKMOVE- Key = KEY_A+ Key = KEY_FTransition = DOWNModifiers = NONEUseableIn = GAME@@ -317,6 +318,37 @@ CommandMap TOGGLE_ATTACKMOVEDisplayName = GUI:ToggleAttackMoveEnd+; attack. 'A' arms force fire the same way, so a click on the ground, on rubble+; or on your own tank is an attack rather than a move. Ctrl held still does it.+CommandMap TOGGLE_FORCEATTACK+ Key = KEY_A+ Transition = DOWN+ Modifiers = NONE+ UseableIn = GAME+ Category = CONTROL+ Description = GUI:ToggleForceAttackDescription+ DisplayName = GUI:ToggleForceAttack+End++; the order queue. Retail put it on ALT; here it is SHIFT, the key every other RTS+; queues with, and the same key that adds to the selection - the two records both+; fire on the one modifier (MetaEvent.cpp), so a shift-click still adds a unit and+; a shift-right-click still queues an order. Each queued point draws its own+; thread and marker, and they stay up after the key is let go.+CommandMap BEGIN_WAYPOINTS+ Key = KEY_NONE+ Transition = DOWN+ Modifiers = SHIFT+ UseableIn = GAME+End++CommandMap END_WAYPOINTS+ Key = KEY_NONE+ Transition = UP+ Modifiers = SHIFT+ UseableIn = GAME+End+; the general's promotion screen, on the key above tabCommandMap TOGGLE_PURCHASE_SCIENCEKey = KEY_TICKdiff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex cb95bcf9a..a981829db 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -161,6 +161,14 @@ GUI:ToggleAttackMoveDescription"Arms attack move: the next move order makes the selected units fight anything they meet on the way."END+GUI:ToggleForceAttack+"Attack"+END++GUI:ToggleForceAttackDescription+"Arms force fire: the next order click is an attack on whatever is under it, your own units and bare ground included."+END+GUI:HoldPosition"Hold Position"ENDdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/DrawnPath.h b/GeneralsMD/Code/GameEngine/Include/Common/DrawnPath.hnew file mode 100644index 000000000..47674f1c1--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Include/Common/DrawnPath.h@@ -0,0 +1,58 @@+/*+** 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/>.+*/++// FILE: DrawnPath.h ////////////////////////////////////////////////////////////////////////////+//+// The curve the player traces with the right button, and the arithmetic that turns it into+// standing room. Both sides of the engine need the same answers: the logic to decide who goes+// where, the client to draw it while the line is still being dragged. Written once here so the+// two pictures cannot drift apart.+//+///////////////////////////////////////////////////////////////////////////////////////////////++#pragma once++#ifndef _H_DrawnPath+#define _H_DrawnPath++#include "Lib/BaseType.h"+#include "Common/STLTypedefs.h"++class Object;++/// running length of the curve up to each of its points; arc[0] is zero, arc.back() is the whole+extern void buildPathArcLengths( const std::vector<Coord3D>& path, std::vector<Real>& arc );++/// how far along the curve the point on it nearest to (x,y) sits+extern Real distanceAlongPath( const std::vector<Coord3D>& path, const std::vector<Real>& arc,+ Real x, Real y );++/// the point that far along the curve; the ground height is not filled in+extern void pointAlongPath( const std::vector<Coord3D>& path, const std::vector<Real>& arc,+ Real dist, Coord3D *out );++/**+ * Put these units in the order the stations are handed out: whoever is nearest the start of the+ * curve takes the first one, so nobody crosses anybody on the way in. The object id breaks a tie,+ * which makes the order a total one - the same set of units sorts the same way on every machine+ * and in the client's own picture of it, whatever order they arrived in.+ */+extern void orderAlongPath( std::vector<Object *>& movers, const std::vector<Coord3D>& path,+ const std::vector<Real>& arc );++#endif // _H_DrawnPathdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex eb0964116..d8b9fe7fe 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -291,6 +291,7 @@ public:MSG_META_TAKE_SCREENSHOT, ///< take screenshotMSG_META_ALL_CHEER, ///< Yay! :)MSG_META_TOGGLE_ATTACKMOVE, ///< enter attack-move mode+ MSG_META_TOGGLE_FORCEATTACK, ///< arm force fire for the next order click (fork)MSG_META_HOLD_POSITION, ///< hold position: guard in place, no pursuit (fork)MSG_META_TOGGLE_PAUSE, ///< pause/unpause, single player and replay only (fork)MSG_META_GAME_SPEED_UP, ///< raise the logic rate (fork)@@ -635,6 +636,8 @@ public:MSG_ENABLE_RETALIATION_MODE, ///< Turn retaliation mode on or off for the player who sent it.MSG_DO_HOLD_POSITION, ///< Every selected unit guards the spot it is standing on (fork)MSG_DO_FORMATION_MOVETO, ///< (location...) spread the selection along a drawn curve (fork)+ MSG_DO_FORMATION_ATTACKMOVETO, ///< (location...) the same curve, taken as an attack move (fork)+ MSG_DO_FORMATION_FORCEATTACK, ///< (location...) the same curve, each unit force firing its own point (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/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 3f4346604..314834e2c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -400,12 +400,73 @@ public: // ********************************************************************// The line the player is dragging out for a formation move, in screen pixels. It is the curve// the cursor actually traced, not the chord: an arc round a rock is a shape a straight segment// cannot say.- enum { MAX_FORMATION_DRAG_POINTS = 32 };+ enum+ {+ MAX_FORMATION_DRAG_POINTS = 32, ///< the message carries these, so the curve cannot grow forever+ FORMATION_DRAG_MIN_SPACING = 12 ///< pixels between kept points, doubled when the curve fills up+ };void addFormationDragPoint( const ICoord2D& pt );- void clearFormationDrag( void ) { m_isFormationDragging = FALSE; m_formationDragPoints.clear(); }+ void clearFormationDrag( void ) { m_isFormationDragging = FALSE; m_formationDragPoints.clear(); m_orderHints.clear(); }Bool isFormationDragging( void ) const { return m_isFormationDragging; }const std::vector<ICoord2D>& getFormationDragPoints( void ) const { return m_formationDragPoints; }+ // Where each selected unit is headed, and what kind of order sent it there. While a formation+ // line is being drawn these are worked out from the curve, with the same ordering the logic+ // uses, so the preview and the orders agree; the rest of the time they are read straight off+ // the units' own goals, so they last exactly as long as the order does.+ // One kind per cursor the game already owns, because the marker on the destination is that+ // cursor: an order the player can give with a distinct cursor reads back with the same one.+ enum OrderHintKind+ {+ ORDER_HINT_MOVE = 0, ///< go there+ ORDER_HINT_ATTACK_MOVE, ///< go there, shooting whatever gets in the way+ ORDER_HINT_ATTACK, ///< kill that+ ORDER_HINT_FORCE_ATTACK, ///< kill that, whoever owns it+ ORDER_HINT_ATTACK_GROUND, ///< shoot that spot+ ORDER_HINT_ENTER, ///< get inside it+ ORDER_HINT_DOCK, ///< dock with it+ ORDER_HINT_GET_REPAIRED, ///< go and be repaired+ ORDER_HINT_GET_HEALED, ///< go and be healed+ ORDER_HINT_DO_REPAIR, ///< go and repair it+ ORDER_HINT_CAPTURE, ///< go and take it+ ORDER_HINT_HACK, ///< go and hack it+ ORDER_HINT_GUARD, ///< hold that spot+ ORDER_HINT_WAYPOINT ///< walking a path somebody laid down+ };+ struct OrderHint+ {+ Coord3D from; ///< where the unit is now+ Coord3D to; ///< where it is going+ OrderHintKind kind;+ };+ const std::vector<OrderHint>& getOrderHints( void ) const { return m_orderHints; }++ // A circle dragged out with the left button while the attack key is armed. Everything hostile+ // and visible inside it becomes a list, and the selection works down that list one target at a+ // time: the next one is ordered the moment the current one stops existing.+ void beginAttackCircle( const ICoord2D& pt );+ void updateAttackCircle( const ICoord2D& pt );+ void issueAttackCircle( void );+ void cancelAttackCircle( void ) { m_isAttackCircling = FALSE; }+ Bool isAttackCircling( void ) const { return m_isAttackCircling; }+ const ICoord2D& getAttackCircleAnchor( void ) const { return m_attackCircleAnchor; }+ const ICoord2D& getAttackCircleCursor( void ) const { return m_attackCircleCursor; }+ void clearAttackQueue( void );++ // 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, driven the same+ // way the attack circle's is: an ordinary message the client sends again once the order before+ // it is over, nothing new for the logic to learn.+ struct AttackWaypoint+ {+ Coord3D pos; ///< where to attack-move to, or the last known spot of targetID+ ObjectID targetID; ///< INVALID_ID for a plain attack-move point, a specific victim otherwise+ };+ void queueAttackWaypoint( const Coord3D *pos, Object *targetObj );+ void clearShiftAttackQueue( void );+ Bool isShiftAttackQueueActive( void ) const { return !m_shiftAttackQueue.empty() || m_shiftAttackQueueRunning; }+ const std::vector<AttackWaypoint>& getShiftAttackQueue( void ) const { return m_shiftAttackQueue; }+virtual void createMoveHint( const GameMessage *msg ); ///< A move command has occurred, start graphical "hint"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"@@ -776,9 +837,15 @@ public: // ********************************************************************void setForceAttackMode( Bool enabled ) { m_forceAttackMode = enabled; }void setPreferSelectionMode( Bool enabled ) { m_preferSelection = enabled; }- void toggleAttackMoveToMode( void ) { m_attackMoveToMode = !m_attackMoveToMode; }+ void toggleAttackMoveToMode( void ) { m_attackMoveToMode = !m_attackMoveToMode; m_forceAttackArmed = FALSE; }Bool isInAttackMoveToMode( void ) const { return m_attackMoveToMode; }- void clearAttackMoveToMode( void ) { m_attackMoveToMode = FALSE; }+ void clearAttackMoveToMode( void ) { m_attackMoveToMode = FALSE; m_forceAttackArmed = FALSE; }++ // the attack key arms force fire the way the attack move key arms an attack move: the next+ // order click shoots whatever is under it, ground included, and the mode drops again with the+ // same call that drops attack move+ void toggleForceAttackArmed( void ) { m_forceAttackArmed = !m_forceAttackArmed; m_attackMoveToMode = FALSE; }+ Bool isForceAttackArmed( void ) const { return m_forceAttackArmed; }// zeroing the repeat clock makes the first quantized step happen on the very next update, so a// tap of the key is one eighth and a hold is one eighth every CAMERA_SNAP_REPEAT_MS.@@ -967,6 +1034,25 @@ protected:IRegion2D m_dragSelectRegion; ///< if isDragSelecting is TRUE, this contains select regionBool m_isFormationDragging; ///< TRUE while a formation line is being drawn (fork)std::vector<ICoord2D> m_formationDragPoints; ///< the traced curve, in pixels, first point is where it started+ Int m_formationDragSpacing; ///< pixels a new point has to earn, doubled each time the curve fills up+ std::vector<OrderHint> m_orderHints; ///< who is going where, for drawing++ Bool m_isAttackCircling; ///< TRUE while an attack circle is being dragged (fork)+ ICoord2D m_attackCircleAnchor; ///< where the circle was started, in pixels+ ICoord2D m_attackCircleCursor; ///< where the cursor is now, which is the rim+ std::vector<ObjectID> m_attackQueue; ///< targets still owed, nearest first+ ObjectID m_attackQueueTarget; ///< the one the group is on now+ std::vector<ObjectID> m_attackQueueUnits; ///< who was told, so a changed selection drops the queue++ 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+ std::vector<ObjectID> m_shiftAttackQueueUnits; ///< who was told, so a changed selection drops the queue++ void updateFormationHints( void ); ///< recompute who goes where from the curve being drawn+ void updateOrderHints( void ); ///< read the selection's own goals, once a frame+ void updateAttackQueue( void ); ///< order the next target when the current one is gone+ void updateShiftAttackQueue( void ); ///< send the next queued attack once the current one is overBool m_displayedMaxWarning; ///< keeps the warning from being shown over and overMoveHintStruct m_moveHint[ MAX_MOVE_HINTS ];Int m_nextMoveHint;@@ -1198,6 +1284,7 @@ protected:Bool m_forceAttackMode; ///< are we in force attack mode?Bool m_forceMoveToMode; ///< are we in force move mode?Bool m_attackMoveToMode; ///< are we in attack move mode?+ Bool m_forceAttackArmed; ///< is the attack key holding force fire for the next click?Bool m_preferSelection; ///< the shift key has been depressed.// wall clock of the previous update(), so a held camera key can be stepped by elapseddiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.hindex 526f1a2d1..889e3f980 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h@@ -47,6 +47,7 @@ private:Bool m_leftMouseButtonIsDown;Bool m_dragSelecting;+ Bool m_attackCircleJustIssued; ///< a circle drag just went out, so eat the click that ends it (fork)UnsignedInt m_lastGroupSelTime;Int m_lastGroupSelGroup;ICoord2D m_selectFeedbackAnchor; // Note: Used for drawing feedback only.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/DrawnPath.cpp b/GeneralsMD/Code/GameEngine/Source/Common/DrawnPath.cppnew file mode 100644index 000000000..163e49c84--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Source/Common/DrawnPath.cpp@@ -0,0 +1,130 @@+/*+** 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/>.+*/++// FILE: DrawnPath.cpp //////////////////////////////////////////////////////////////////////////++#include "PreRTS.h"++#include "Common/DrawnPath.h"+#include "GameLogic/Object.h"++//-------------------------------------------------------------------------------------------------+void buildPathArcLengths( const std::vector<Coord3D>& path, std::vector<Real>& arc )+{+ arc.clear();+ if (path.empty())+ return;++ arc.push_back( 0.0f );+ for (Int i = 1; i < (Int)path.size(); i++)+ {+ const Real dx = path[ i ].x - path[ i - 1 ].x;+ const Real dy = path[ i ].y - path[ i - 1 ].y;+ arc.push_back( arc[ i - 1 ] + sqrtf( dx * dx + dy * dy ) );+ }+}++//-------------------------------------------------------------------------------------------------+Real distanceAlongPath( const std::vector<Coord3D>& path, const std::vector<Real>& arc,+ Real x, Real y )+{+ Real best = 0.0f;+ Real bestDistSqr = -1.0f;++ for (Int i = 1; i < (Int)path.size(); i++)+ {+ const Real sx = path[ i - 1 ].x;+ const Real sy = path[ i - 1 ].y;+ const Real dx = path[ i ].x - sx;+ const Real dy = path[ i ].y - sy;+ const Real segLenSqr = dx * dx + dy * dy;++ Real t = 0.0f;+ if (segLenSqr > 0.0f)+ {+ t = ((x - sx) * dx + (y - sy) * dy) / segLenSqr;+ if (t < 0.0f)+ t = 0.0f;+ else if (t > 1.0f)+ t = 1.0f;+ }++ const Real px = sx + dx * t;+ const Real py = sy + dy * t;+ const Real distSqr = (x - px) * (x - px) + (y - py) * (y - py);+ if (bestDistSqr < 0.0f || distSqr < bestDistSqr)+ {+ bestDistSqr = distSqr;+ best = arc[ i - 1 ] + sqrtf( segLenSqr ) * t;+ }+ }++ return best;+}++//-------------------------------------------------------------------------------------------------+void pointAlongPath( const std::vector<Coord3D>& path, const std::vector<Real>& arc,+ Real dist, Coord3D *out )+{+ Int i = 1;+ while (i < (Int)path.size() - 1 && arc[ i ] < dist)+ i++;++ const Real segLen = arc[ i ] - arc[ i - 1 ];+ const Real t = (segLen > 0.0f) ? ((dist - arc[ i - 1 ]) / segLen) : 0.0f;+ out->x = path[ i - 1 ].x + (path[ i ].x - path[ i - 1 ].x) * t;+ out->y = path[ i - 1 ].y + (path[ i ].y - path[ i - 1 ].y) * t;+ out->z = 0.0f;+}++//-------------------------------------------------------------------------------------------------+void orderAlongPath( std::vector<Object *>& movers, const std::vector<Coord3D>& path,+ const std::vector<Real>& arc )+{+ const Int count = movers.size();++ // the keys are worked out once: the sort below asks for them n-squared times, and each one is a+ // walk of the whole curve+ std::vector<Real> keys;+ keys.reserve( count );+ for (Int i = 0; i < count; i++)+ keys.push_back( distanceAlongPath( path, arc,+ movers[ i ]->getPosition()->x,+ movers[ i ]->getPosition()->y ) );++ // Insertion sort, keys and units together: the selection is a few dozen objects at most, and+ // the comparator is a total order, so the answer does not depend on the order they came in.+ for (Int i = 1; i < count; i++)+ {+ Object *held = movers[ i ];+ const Real heldKey = keys[ i ];++ Int j = i - 1;+ while (j >= 0)+ {+ if (keys[ j ] < heldKey || (keys[ j ] == heldKey && movers[ j ]->getID() < held->getID()))+ break;+ movers[ j + 1 ] = movers[ j ];+ keys[ j + 1 ] = keys[ j ];+ j--;+ }++ movers[ j + 1 ] = held;+ keys[ j + 1 ] = heldKey;+ }+}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex fb6471240..c0cb42022 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -396,6 +396,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)CHECK_IF(MSG_META_TAKE_SCREENSHOT)CHECK_IF(MSG_META_ALL_CHEER)CHECK_IF(MSG_META_TOGGLE_ATTACKMOVE)+ CHECK_IF(MSG_META_TOGGLE_FORCEATTACK)CHECK_IF(MSG_META_TOGGLE_PURCHASE_SCIENCE)CHECK_IF(MSG_META_HOLD_POSITION)CHECK_IF(MSG_META_TOGGLE_PAUSE)@@ -675,6 +676,8 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)CHECK_IF(MSG_DO_GUARD_POSITION)CHECK_IF(MSG_DO_HOLD_POSITION)CHECK_IF(MSG_DO_FORMATION_MOVETO)+ CHECK_IF(MSG_DO_FORMATION_ATTACKMOVETO)+ CHECK_IF(MSG_DO_FORMATION_FORCEATTACK)CHECK_IF(MSG_DO_GUARD_OBJECT)CHECK_IF(MSG_DO_STOP)CHECK_IF(MSG_DO_SCATTER)diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 395360737..1fe261d17 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -32,6 +32,7 @@#define DEFINE_SHADOW_NAMES#include "Common/ActionManager.h"+#include "Common/DrawnPath.h"#include "Common/GameAudio.h"#include "Common/GameEngine.h"#include "Common/GameType.h"@@ -79,6 +80,8 @@#include "GameClient/GlobalLanguage.h"#include "GameLogic/AIGuard.h"+#include "GameLogic/AIStateMachine.h"+#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Weapon.h"#include "GameLogic/Object.h"#include "GameLogic/GameLogic.h"@@ -1006,6 +1009,7 @@ InGameUI::InGameUI()m_inputEnabled = true;m_isDragSelecting = false;m_isFormationDragging = FALSE;+ m_formationDragSpacing = FORMATION_DRAG_MIN_SPACING;m_nextMoveHint = 0;m_selectCount = 0;m_frameSelectionChanged = 0;@@ -1209,7 +1213,11 @@ InGameUI::InGameUI()m_forceAttackMode = false;m_forceMoveToMode = false;m_attackMoveToMode = false;+ m_forceAttackArmed = false;m_preferSelection = false;+ m_isAttackCircling = FALSE;+ m_attackQueueTarget = INVALID_ID;+ m_shiftAttackQueueRunning = FALSE;m_curRcType = RADIUSCURSOR_NONE;@@ -1919,6 +1927,15 @@ void InGameUI::preDraw( void )// handle radius-cursors, if anyhandleRadiusCursor();+ // where the selection is headed, read fresh from the units themselves+ updateOrderHints();++ // and the next target of an attack circle, if the current one has stopped existing+ updateAttackQueue();++ // and the next point of a shift-queued attack, if the current one 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@@ -2393,7 +2410,15 @@ void InGameUI::reset( void )m_forceAttackMode = false;m_forceMoveToMode = false;m_attackMoveToMode = false;+ m_forceAttackArmed = false;m_preferSelection = false;+ m_isAttackCircling = FALSE;+ m_attackQueueTarget = INVALID_ID;+ m_attackQueue.clear();+ m_attackQueueUnits.clear();+ m_shiftAttackQueue.clear();+ m_shiftAttackQueueUnits.clear();+ m_shiftAttackQueueRunning = FALSE;m_clientQuiet = false;m_windowLayouts.clear();@@ -2597,33 +2622,516 @@ void InGameUI::addFormationDragPoint( const ICoord2D& pt )if( m_formationDragPoints.empty() ){+ m_formationDragSpacing = FORMATION_DRAG_MIN_SPACING;m_formationDragPoints.push_back( pt );+ updateFormationHints();return;}// The last point always follows the cursor, so the end of the line sits exactly where the hand// is. A new point is only kept once the cursor has moved far enough for the curve to be saying// something; without that a slow drag stores one point a frame and fills the message with noise.- const Int MIN_SPACING = 12;- if( (Int)m_formationDragPoints.size() < MAX_FORMATION_DRAG_POINTS )+ Bool keep = TRUE;+ const Int keptIndex = (Int)m_formationDragPoints.size() - 2;+ if( keptIndex >= 0 )+ {+ const Int dx = pt.x - m_formationDragPoints[ keptIndex ].x;+ const Int dy = pt.y - m_formationDragPoints[ keptIndex ].y;+ keep = ( dx * dx + dy * dy >= m_formationDragSpacing * m_formationDragSpacing );+ }++ if( keep ){- const Int keptIndex = (Int)m_formationDragPoints.size() - 2;- if( keptIndex < 0 )+ // A long drag would otherwise run out of points, and everything after that would collapse+ // into one straight rubber band from the last kept point to the cursor - which is the kink+ // that showed up in play. Halve the resolution instead: throw away every second point and+ // double the spacing. The shape survives at a coarser step and the line keeps growing for+ // as long as the player keeps dragging.+ if( (Int)m_formationDragPoints.size() >= MAX_FORMATION_DRAG_POINTS ){- m_formationDragPoints.push_back( pt );- return;+ std::vector<ICoord2D> thinned;+ for( Int i = 0; i < (Int)m_formationDragPoints.size(); i += 2 )+ thinned.push_back( m_formationDragPoints[ i ] );+ m_formationDragPoints = thinned;+ m_formationDragSpacing *= 2;}- const Int dx = pt.x - m_formationDragPoints[ keptIndex ].x;- const Int dy = pt.y - m_formationDragPoints[ keptIndex ].y;- if( dx * dx + dy * dy >= MIN_SPACING * MIN_SPACING )+ m_formationDragPoints.push_back( pt );+ }+ else+ {+ m_formationDragPoints.back() = pt;+ }++ updateFormationHints();+}++//-------------------------------------------------------------------------------------------------+/** Work out who is going where, from the curve as it stands. This is the same arithmetic the logic+ * runs when the button comes up - same curve, same filter, same total order - so what the player+ * is shown is what the units will do. */+//-------------------------------------------------------------------------------------------------+void InGameUI::updateFormationHints( void )+{+ m_orderHints.clear();++ if( m_formationDragPoints.size() < 2 )+ return;++ std::vector<Coord3D> path;+ for( std::vector<ICoord2D>::const_iterator pt = m_formationDragPoints.begin();+ pt != m_formationDragPoints.end(); ++pt )+ {+ Coord3D world;+ TheTacticalView->screenToTerrain( &(*pt), &world );+ path.push_back( world );+ }++ std::vector<Real> arc;+ buildPathArcLengths( path, arc );++ const Real span = arc.back();+ if( span < 1.0f )+ return;++ std::vector<Object *> movers;+ for( DrawableList::const_iterator it = m_selectedDrawables.begin();+ it != m_selectedDrawables.end(); ++it )+ {+ Object *obj = (*it)->getObject();+ if( !obj || obj->getControllingPlayer() != ThePlayerList->getLocalPlayer() )+ continue;+ if( obj->isKindOf( KINDOF_IMMOBILE ) || obj->getAIUpdateInterface() == NULL )+ continue;+ movers.push_back( obj );+ }++ if( movers.empty() )+ return;++ orderAlongPath( movers, path, arc );++ const Int count = movers.size();+ for( Int i = 0; i < count; i++ )+ {+ OrderHint hint;+ hint.kind = isInAttackMoveToMode() ? ORDER_HINT_ATTACK_MOVE+ : isForceAttackArmed() ? ORDER_HINT_ATTACK+ : ORDER_HINT_MOVE;+ hint.from = *movers[ i ]->getPosition();+ pointAlongPath( path, arc, span * ((count == 1) ? 1.0f : ((Real)i / (Real)(count - 1))),+ &hint.to );+ hint.to.z = TheTerrainLogic->getGroundHeight( hint.to.x, hint.to.y );+ m_orderHints.push_back( hint );+ }+}++//-------------------------------------------------------------------------------------------------+/** Where each selected unit is going, asked of the unit rather than remembered from the order. A+ * line therefore lives exactly as long as the order behind it: it appears the frame the unit+ * accepts the command and goes when the unit arrives, changes its mind or leaves the selection. */+//-------------------------------------------------------------------------------------------------+void InGameUI::updateOrderHints( void )+{+ if( m_isFormationDragging )+ {+ updateFormationHints();+ return;+ }++ m_orderHints.clear();++ Player *local = ThePlayerList->getLocalPlayer();+ for( DrawableList::const_iterator it = m_selectedDrawables.begin();+ it != m_selectedDrawables.end(); ++it )+ {+ Object *obj = (*it)->getObject();+ if( !obj || obj->getControllingPlayer() != local )+ continue;++ AIUpdateInterface *ai = obj->getAIUpdateInterface();+ if( ai == NULL )+ continue;++ OrderHint hint;+ switch( ai->getCurrentStateID() )+ {+ case AI_MOVE_TO:+ case AI_FOLLOW_PATH:+ case AI_FOLLOW_EXITPRODUCTION_PATH:+ case AI_MOVE_AND_EVACUATE:+ case AI_MOVE_AND_EVACUATE_AND_EXIT:+ case AI_MOVE_AND_DELETE:+ case AI_MOVE_AND_TIGHTEN:+ case AI_PICK_UP_CRATE:+ hint.kind = ORDER_HINT_MOVE;+ break;++ case AI_FOLLOW_WAYPOINT_PATH_AS_TEAM:+ case AI_FOLLOW_WAYPOINT_PATH_AS_INDIVIDUALS:+ case AI_FOLLOW_WAYPOINT_PATH_AS_TEAM_EXACT:+ case AI_FOLLOW_WAYPOINT_PATH_AS_INDIVIDUALS_EXACT:+ hint.kind = ORDER_HINT_WAYPOINT;+ break;++ case AI_ATTACK_MOVE_TO:+ case AI_ATTACKFOLLOW_WAYPOINT_PATH_AS_INDIVIDUALS:+ case AI_ATTACKFOLLOW_WAYPOINT_PATH_AS_TEAM:+ case AI_HUNT:+ hint.kind = ORDER_HINT_ATTACK_MOVE;+ break;++ case AI_ATTACK_OBJECT:+ case AI_ATTACK_AND_FOLLOW_OBJECT:+ case AI_ATTACK_SQUAD:+ hint.kind = ORDER_HINT_ATTACK;+ break;++ case AI_FORCE_ATTACK_OBJECT:+ hint.kind = ORDER_HINT_FORCE_ATTACK;+ break;++ case AI_ATTACK_POSITION:+ case AI_ATTACK_AREA:+ hint.kind = ORDER_HINT_ATTACK_GROUND;+ break;++ case AI_ENTER:+ case AI_RAPPEL_INTO:+ case AI_COMBATDROP:+ hint.kind = ORDER_HINT_ENTER;+ break;++ case AI_DOCK:+ hint.kind = ORDER_HINT_DOCK;+ break;++ case AI_GET_REPAIRED:+ hint.kind = ORDER_HINT_GET_REPAIRED;+ break;++ case AI_HACK_INTERNET:+ hint.kind = ORDER_HINT_HACK;+ break;++ case AI_GUARD:+ case AI_GUARD_RETALIATE:+ case AI_GUARD_TUNNEL_NETWORK:+ hint.kind = ORDER_HINT_GUARD;+ break;++ default:+ continue;+ }++ hint.from = *obj->getPosition();++ // a queued path is shown point by point: one thread from the unit to its next point and one+ // from each point to the one after it, so the whole shift queue is on the ground at once and+ // stays there after the key is let go+ const Int pathSize = ai->friend_getWaypointGoalPathSize();+ const Int pathIndex = ai->friend_getCurrentGoalPathIndex();+ if( pathSize > 0 && pathIndex >= 0 && pathIndex < pathSize )+ {+ for( Int i = pathIndex; i < pathSize; i++ )+ {+ hint.to = *ai->friend_getGoalPathPosition( i );+ m_orderHints.push_back( hint );+ hint.from = hint.to;+ }+ continue;+ }++ // a goal object outranks the goal position: a unit chasing something is headed wherever that+ // thing is standing now, not where it stood when the order was given+ Object *goalObj = ai->getGoalObject();+ if( goalObj )+ hint.to = *goalObj->getPosition();+ else+ hint.to = *ai->getGoalPosition();++ m_orderHints.push_back( hint );++ // 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( !m_shiftAttackQueue.empty() &&+ std::find( m_shiftAttackQueueUnits.begin(), m_shiftAttackQueueUnits.end(), obj->getID() ) != m_shiftAttackQueueUnits.end() )+ {+ hint.from = hint.to;+ for( std::vector<AttackWaypoint>::const_iterator qit = m_shiftAttackQueue.begin();+ qit != m_shiftAttackQueue.end(); ++qit )+ {+ hint.to = qit->pos;+ m_orderHints.push_back( hint );+ hint.from = hint.to;+ }+ }+ }+}++//-------------------------------------------------------------------------------------------------+/** The attack key is armed and the player has pressed the left button: from here a drag draws a+ * circle rather than a selection box. */+//-------------------------------------------------------------------------------------------------+void InGameUI::beginAttackCircle( const ICoord2D& pt )+{+ m_isAttackCircling = TRUE;+ m_attackCircleAnchor = pt;+ m_attackCircleCursor = pt;+ DEBUG_LOG(("attack circle: begun at %d,%d with %d selected\n", pt.x, pt.y, getSelectCount()));+}++//-------------------------------------------------------------------------------------------------+void InGameUI::updateAttackCircle( const ICoord2D& pt )+{+ m_attackCircleCursor = pt;+}++//-------------------------------------------------------------------------------------------------+/** Everything hostile standing in the circle becomes a 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. */+//-------------------------------------------------------------------------------------------------+void InGameUI::issueAttackCircle( void )+{+ m_isAttackCircling = FALSE;+ clearAttackQueue();++ Coord3D center, rim;+ TheTacticalView->screenToTerrain( &m_attackCircleAnchor, ¢er );+ TheTacticalView->screenToTerrain( &m_attackCircleCursor, &rim );++ const Real dx = rim.x - center.x;+ const Real dy = rim.y - center.y;+ const Real radius = sqrtf( dx * dx + dy * dy );+ if( radius < 1.0f )+ return;++ Player *local = ThePlayerList->getLocalPlayer();+ const Int localIndex = local->getPlayerIndex();++ ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( ¢er, radius,+ FROM_CENTER_2D, NULL,+ ITER_SORTED_NEAR_TO_FAR );+ MemoryPoolObjectHolder holder( iter );+ for( Object *obj = iter->first(); obj; obj = iter->next() )+ {+ if( obj->isEffectivelyDead() )+ continue;+ if( local->getRelationship( obj->getTeam() ) != ENEMIES )+ continue;+ if( obj->getShroudedStatus( localIndex ) > OBJECTSHROUD_PARTIAL_CLEAR )+ continue;++ m_attackQueue.push_back( obj->getID() );+ }++ DEBUG_LOG(("attack circle: radius %.0f, %d targets\n", radius, (Int)m_attackQueue.size()));+ if( m_attackQueue.empty() )+ return;++ // who the queue belongs to. The orders go to whatever is selected when each one is sent, so a+ // changed selection has to end the queue rather than quietly redirect it+ for( DrawableList::const_iterator it = m_selectedDrawables.begin();+ it != m_selectedDrawables.end(); ++it )+ {+ Object *obj = (*it)->getObject();+ if( obj )+ m_attackQueueUnits.push_back( obj->getID() );+ }+ std::sort( m_attackQueueUnits.begin(), m_attackQueueUnits.end() );++ updateAttackQueue();+}++//-------------------------------------------------------------------------------------------------+void InGameUI::clearAttackQueue( void )+{+ m_attackQueue.clear();+ m_attackQueueUnits.clear();+ m_attackQueueTarget = INVALID_ID;+}++//-------------------------------------------------------------------------------------------------+/** One order per target, sent when the target before it stops existing. This is the player's own+ * click repeated by the client, so it is an ordinary message on the stream and the logic learns+ * nothing new: no queue lives in the simulation. */+//-------------------------------------------------------------------------------------------------+void InGameUI::updateAttackQueue( void )+{+ if( m_attackQueue.empty() && m_attackQueueTarget == INVALID_ID )+ return;++ // the selection is the queue's owner, so a different selection means the queue is over+ std::vector<ObjectID> current;+ for( DrawableList::const_iterator it = m_selectedDrawables.begin();+ it != m_selectedDrawables.end(); ++it )+ {+ Object *obj = (*it)->getObject();+ if( obj )+ current.push_back( obj->getID() );+ }+ std::sort( current.begin(), current.end() );++ if( current != m_attackQueueUnits )+ {+ clearAttackQueue();+ return;+ }++ Object *target = TheGameLogic->findObjectByID( m_attackQueueTarget );+ if( target && !target->isEffectivelyDead() )+ return;++ while( !m_attackQueue.empty() )+ {+ const ObjectID next = m_attackQueue.front();+ m_attackQueue.erase( m_attackQueue.begin() );++ Object *obj = TheGameLogic->findObjectByID( next );+ if( obj == NULL || obj->isEffectivelyDead() )+ continue;++ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );+ msg->appendObjectIDArgument( next );+ m_attackQueueTarget = next;+ return;+ }++ clearAttackQueue();+}++//-------------------------------------------------------------------------------------------------+/** 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;++ // who the queue belongs to. A changed selection starts a fresh queue rather than adding to+ // whatever the old selection was doing+ std::vector<ObjectID> current;+ for( DrawableList::const_iterator it = m_selectedDrawables.begin();+ it != m_selectedDrawables.end(); ++it )+ {+ Object *obj = (*it)->getObject();+ if( obj )+ current.push_back( obj->getID() );+ }+ std::sort( current.begin(), current.end() );++ if( !m_shiftAttackQueueRunning || current != m_shiftAttackQueueUnits )+ {+ clearShiftAttackQueue();+ m_shiftAttackQueueUnits = current;+ m_shiftAttackQueueRunning = TRUE;+ m_shiftAttackQueueActive = order;++ if( order.targetID != INVALID_ID ){- m_formationDragPoints.push_back( pt );+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );+ msg->appendObjectIDArgument( order.targetID );+ }+ else+ {+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );+ msg->appendLocationArgument( order.pos );+ msg->appendBooleanArgument( isInForceAttackMode() );+ }+ 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();+}++//-------------------------------------------------------------------------------------------------+/** The order in flight ends when its target dies (an object target) or nobody selected is still+ * chasing it down (an attack-move point); either way, the next queued order goes out then, same+ * as updateAttackQueue(). */+//-------------------------------------------------------------------------------------------------+void InGameUI::updateShiftAttackQueue( void )+{+ if( !m_shiftAttackQueueRunning )+ return;++ // the selection is the queue's owner, so a different selection means the queue is over+ std::vector<ObjectID> current;+ for( DrawableList::const_iterator it = m_selectedDrawables.begin();+ it != m_selectedDrawables.end(); ++it )+ {+ Object *obj = (*it)->getObject();+ if( obj )+ current.push_back( obj->getID() );+ }+ std::sort( current.begin(), current.end() );++ if( current != m_shiftAttackQueueUnits )+ {+ clearShiftAttackQueue();+ return;+ }++ if( m_shiftAttackQueueActive.targetID != INVALID_ID )+ {+ Object *target = TheGameLogic->findObjectByID( m_shiftAttackQueueActive.targetID );+ if( target && !target->isEffectivelyDead() )return;+ }+ else+ {+ 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 && ai->getAIStateType() == AI_ATTACK_MOVE_TO )+ return;}}- m_formationDragPoints.back() = pt;+ 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() )+ continue;++ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );+ msg->appendObjectIDArgument( next.targetID );+ }+ else+ {+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );+ msg->appendLocationArgument( next.pos );+ msg->appendBooleanArgument( isInForceAttackMode() );+ }++ m_shiftAttackQueueActive = next;+ return;+ }++ clearShiftAttackQueue();}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 42fae4d8d..42622dfb1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -110,7 +110,10 @@ Bool CommandXlat_isForceAttackTargeting( Bool ctrlHeld, Bool attackMoveArmed )static Bool isForceAttackTargeting( void ){- return CommandXlat_isForceAttackTargeting( TheInGameUI->isInForceAttackMode(),+ // ctrl still does it while held; the attack key arms the same thing for one click, which is+ // what leaves ctrl free to mean something else on a plain move+ return CommandXlat_isForceAttackTargeting( TheInGameUI->isInForceAttackMode()+ || TheInGameUI->isForceAttackArmed(),TheInGameUI->isInAttackMoveToMode() );}@@ -923,7 +926,20 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *if (m_teamExists){- if( TheInGameUI->isInWaypointMode() )+ // 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 queuedAttack = TheInGameUI->isInWaypointMode()+ && ( TheInGameUI->isInAttackMoveToMode() || forceAttackHere );++ 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;}@@ -931,11 +947,11 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *{msgType = GameMessage::MSG_DO_ATTACKMOVETO;}- else if( TheInGameUI->isInForceMoveToMode() )+ else if( TheInGameUI->isInForceMoveToMode() ){msgType = GameMessage::MSG_DO_FORCEMOVETO;}- else if( isForceAttackTargeting() && isForceAttackable )+ else if( forceAttackHere ){msgType = GameMessage::MSG_DO_ATTACK_OBJECT;}@@ -943,7 +959,7 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *{msgType = GameMessage::MSG_DO_MOVETO;}- if( commandType == DO_COMMAND )+ if( commandType == DO_COMMAND && !queuedAttack ){GameMessage *movemsg = TheMessageStream->appendMessage( msgType );if (msgType == GameMessage::MSG_DO_ATTACK_OBJECT)@@ -957,7 +973,7 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *movemsg->appendBooleanArgument( TheInGameUI->isInForceAttackMode() );} // end if- }+ }// only make sounds if we really did the command messagesif( commandType == DO_COMMAND )@@ -3377,6 +3393,12 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessageTheInGameUI->toggleAttackMoveToMode( );break;+ //-----------------------------------------------------------------------------------------+ // the attack key, which arms force fire the same way the key above arms an attack move+ case GameMessage::MSG_META_TOGGLE_FORCEATTACK:+ TheInGameUI->toggleForceAttackArmed( );+ break;+//-----------------------------------------------------------------------------------------// the general's promotion screen. It is one click away on the stars button and nowhere on// the keyboard, which is the wrong way round for something you open the moment a promotion@@ -3923,14 +3945,25 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage// copied out before the drag is cleared, which throws the curve awaystd::vector<ICoord2D> curve = TheInGameUI->getFormationDragPoints();+ // the preview goes with the drag; from here on the units' own goals are what gets drawn,+ // so the picture carries on without a breakTheInGameUI->clearFormationDrag();m_formationDragArmed = FALSE;if( wasDrag && curve.size() >= 2 ){+ // the same curve means "attack along this" while one of the attack modes is armed, which+ // is the artillery gesture: a line of fire instead of a line of tanks. Attack move+ // walks it and shoots what it meets; the attack key fires on the line where it stands+ GameMessage::Type formationType = GameMessage::MSG_DO_FORMATION_MOVETO;+ if( TheInGameUI->isInAttackMoveToMode() )+ formationType = GameMessage::MSG_DO_FORMATION_ATTACKMOVETO;+ else if( TheInGameUI->isForceAttackArmed() )+ formationType = GameMessage::MSG_DO_FORMATION_FORCEATTACK;+// the traced curve becomes world points; who stands where along it is decided on// the logic side, where every machine decides it the same way- GameMessage *newMsg = TheMessageStream->appendMessage( GameMessage::MSG_DO_FORMATION_MOVETO );+ GameMessage *newMsg = TheMessageStream->appendMessage( formationType );for( std::vector<ICoord2D>::const_iterator it = curve.begin(); it != curve.end(); ++it ){Coord3D world;@@ -3939,6 +3972,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage}TheInGameUI->clearAttackMoveToMode();+ TheInGameUI->clearAttackQueue();const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();if( selected && !selected->empty() )@@ -4018,6 +4052,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagedisp = DESTROY_MESSAGE;TheInGameUI->clearAttackMoveToMode();+ // a hand-given order ends whatever list the circle was working through+ TheInGameUI->clearAttackQueue();}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cppindex 246943a81..b4852cef7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp@@ -178,6 +178,7 @@ static const LookupListRec GameMessageMetaTypeNames[] ={ "SCATTER", GameMessage::MSG_META_SCATTER },{ "STOP", GameMessage::MSG_META_STOP },{ "TOGGLE_ATTACKMOVE", GameMessage::MSG_META_TOGGLE_ATTACKMOVE },+ { "TOGGLE_FORCEATTACK", GameMessage::MSG_META_TOGGLE_FORCEATTACK },{ "TOGGLE_PURCHASE_SCIENCE", GameMessage::MSG_META_TOGGLE_PURCHASE_SCIENCE },{ "HOLD_POSITION", GameMessage::MSG_META_HOLD_POSITION },{ "TOGGLE_PAUSE", GameMessage::MSG_META_TOGGLE_PAUSE },@@ -568,7 +569,10 @@ GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessa//DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() Mods-only change: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));/*GameMessage *metaMsg =*/ TheMessageStream->appendMessage(map->m_meta);disp = DESTROY_MESSAGE;- break;+ // every record on this modifier fires, not the first one found: shift is both "add to+ // the selection" on the left button and "queue the order" on the right, and the two+ // are separate records that have to come on and go off together+ continue;}// ok, now check for "normal" key transitions.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex 46b119aaf..9a35876da 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -268,6 +268,7 @@ SelectionTranslator::SelectionTranslator(){m_leftMouseButtonIsDown = FALSE;m_dragSelecting = FALSE;+ m_attackCircleJustIssued = FALSE;m_lastGroupSelTime = 0;m_lastGroupSelGroup = -1;m_selectFeedbackAnchor.x = 0;@@ -413,6 +414,13 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa// modifier appears to be unused, and the argument doesn't exist. jba.//Int modifier = msg->getArgument( 1 )->integer;+ // an attack circle owns the button while it is being dragged, so no box grows behind it+ if( TheInGameUI->isAttackCircling() )+ {+ TheInGameUI->updateAttackCircle( pixel );+ break;+ }+if (m_leftMouseButtonIsDown){ICoord2D delta;@@ -620,6 +628,16 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa//-----------------------------------------------------------------------------case GameMessage::MSG_MOUSE_LEFT_CLICK:{+ // the release that ended an attack circle still arrives here as a click. Letting it+ // through would reselect whatever sat under the anchor, and a changed selection is exactly+ // what drops the queue that was just built+ if( m_attackCircleJustIssued )+ {+ m_attackCircleJustIssued = FALSE;+ disp = DESTROY_MESSAGE;+ break;+ }+// If the quit menu is visible, we need to not process left clicks through the selection translator.if (TheInGameUI->isQuitMenuVisible()){@@ -1001,6 +1019,11 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa// cannot actually start area selection yet - have to wait for cursor to move a bitm_leftMouseButtonIsDown = true;m_selectFeedbackAnchor = msg->getArgument( 0 )->pixel;++ // with the attack key armed the left button draws a circle instead of a selection box,+ // and everything hostile inside it becomes a target list+ if( TheInGameUI->isForceAttackArmed() && TheInGameUI->getSelectCount() > 0 )+ TheInGameUI->beginAttackCircle( m_selectFeedbackAnchor );break;}@@ -1011,7 +1034,17 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessacase GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP:{m_leftMouseButtonIsDown = FALSE;-++ // the circle is finished on the same button that drew it: the targets go out here, and the+ // click that follows this release has to be eaten or it would reselect under the anchor+ if( TheInGameUI->isAttackCircling() )+ {+ TheInGameUI->issueAttackCircle();+ TheInGameUI->clearAttackMoveToMode();+ m_attackCircleJustIssued = TRUE;+ break;+ }+if (m_dragSelecting) {// Stop drag selecting now, thanks.m_dragSelecting = FALSE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 1f7bd0756..1177dc6b6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -31,6 +31,7 @@#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine#include "Common/CRCDebug.h"+#include "Common/DrawnPath.h"#include "Common/GameAudio.h"#include "Common/GameEngine.h"#include "Common/GlobalData.h"@@ -260,63 +261,6 @@ static void doSetRallyPoint( Object *obj, const Coord3D& pos )}-//--------------------------------------------------------------------------------------------------/** How far along a drawn curve the point nearest to (x,y) sits. The formation move uses this to- * order the units: whoever is nearest the start of the curve takes the first station. */-//--------------------------------------------------------------------------------------------------static Real distanceAlongPath( const std::vector<Coord3D>& path, const std::vector<Real>& arc,- Real x, Real y )-{- Real best = 0.0f;- Real bestDistSqr = -1.0f;-- for (Int i = 1; i < (Int)path.size(); i++)- {- const Real sx = path[ i - 1 ].x;- const Real sy = path[ i - 1 ].y;- const Real dx = path[ i ].x - sx;- const Real dy = path[ i ].y - sy;- const Real segLenSqr = dx * dx + dy * dy;-- Real t = 0.0f;- if (segLenSqr > 0.0f)- {- t = ((x - sx) * dx + (y - sy) * dy) / segLenSqr;- if (t < 0.0f)- t = 0.0f;- else if (t > 1.0f)- t = 1.0f;- }-- const Real px = sx + dx * t;- const Real py = sy + dy * t;- const Real distSqr = (x - px) * (x - px) + (y - py) * (y - py);- if (bestDistSqr < 0.0f || distSqr < bestDistSqr)- {- bestDistSqr = distSqr;- best = arc[ i - 1 ] + sqrtf( segLenSqr ) * t;- }- }-- return best;-}--//--------------------------------------------------------------------------------------------------/** The point that far along a drawn curve, ground height not filled in. */-//--------------------------------------------------------------------------------------------------static void pointAlongPath( const std::vector<Coord3D>& path, const std::vector<Real>& arc,- Real dist, Coord3D *out )-{- Int i = 1;- while (i < (Int)path.size() - 1 && arc[ i ] < dist)- i++;-- const Real segLen = arc[ i ] - arc[ i - 1 ];- const Real t = (segLen > 0.0f) ? ((dist - arc[ i - 1 ]) / segLen) : 0.0f;- out->x = path[ i - 1 ].x + (path[ i ].x - path[ i - 1 ].x) * t;- out->y = path[ i - 1 ].y + (path[ i ].y - path[ i - 1 ].y) * t;-}-static Object * getSingleObjectFromSelection(const AIGroup *currentlySelectedGroup){// an empty group is not the same as no group: the iterator below was taken from an empty@@ -1036,10 +980,15 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )// the message is the drawn curve instead of a list of orders.//case GameMessage::MSG_DO_FORMATION_MOVETO:+ case GameMessage::MSG_DO_FORMATION_ATTACKMOVETO:+ case GameMessage::MSG_DO_FORMATION_FORCEATTACK:{if (currentlySelectedGroup == NULL)break;+ const Bool attackAlong = (msg->getType() == GameMessage::MSG_DO_FORMATION_ATTACKMOVETO);+ const Bool fireAlong = (msg->getType() == GameMessage::MSG_DO_FORMATION_FORCEATTACK);+// the curve the cursor traced, however many corners the player's hand put in itstd::vector<Coord3D> path;const Int pointCount = msg->getArgumentCount();@@ -1067,41 +1016,13 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )// arc length up to each point, so a station is a distance along the whole curve and not a// fraction of one segment - a hand-drawn line has segments of every sizestd::vector<Real> arc;- arc.push_back( 0.0f );- for (Int i = 1; i < (Int)path.size(); i++)- {- const Real dx = path[ i ].x - path[ i - 1 ].x;- const Real dy = path[ i ].y - path[ i - 1 ].y;- arc.push_back( arc[ i - 1 ] + sqrtf( dx * dx + dy * dy ) );- }+ buildPathArcLengths( path, arc );const Real span = arc.back();if (span < 1.0f)break;- //- // Sort by where each unit already sits along the curve. Insertion sort: the selection is- // a few dozen objects at most, and it keeps the order a total one - the object id breaks- // a tie - so every machine hands out the same stations.- //- for (Int i = 1; i < (Int)movers.size(); i++)- {- Object *held = movers[ i ];- const Real heldKey = distanceAlongPath( path, arc,- held->getPosition()->x, held->getPosition()->y );- Int j = i - 1;- while (j >= 0)- {- const Real key = distanceAlongPath( path, arc,- movers[ j ]->getPosition()->x,- movers[ j ]->getPosition()->y );- if (key < heldKey || (key == heldKey && movers[ j ]->getID() < held->getID()))- break;- movers[ j + 1 ] = movers[ j ];- j--;- }- movers[ j + 1 ] = held;- }+ orderAlongPath( movers, path, arc );currentlySelectedGroup->releaseWeaponLockForGroup( LOCKED_TEMPORARILY );@@ -1115,7 +1036,12 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )pointAlongPath( path, arc, span * t, &station );station.z = TheTerrainLogic->getGroundHeight( station.x, station.y );- movers[ i ]->getAIUpdateInterface()->aiMoveToPosition( &station, CMD_FROM_PLAYER );+ if (fireAlong)+ movers[ i ]->getAIUpdateInterface()->aiAttackPosition( &station, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );+ else if (attackAlong)+ movers[ i ]->getAIUpdateInterface()->aiAttackMoveToPosition( &station, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );+ else+ movers[ i ]->getAIUpdateInterface()->aiMoveToPosition( &station, CMD_FROM_PLAYER );}break;diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.hindex 48311b0c7..95ad9f727 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h@@ -80,6 +80,8 @@ protected:virtual void drawPlaceAngle( View *view ); ///< draw place building angle if neededvirtual void drawBuildGrid( void ); ///< the pathfinder's build grid under a pending structurevirtual void drawFormationLine( void ); ///< the line a right drag is spreading the selection along+ virtual void drawOrderHints( void ); ///< a line from each selected unit to where its order sends it+ virtual void drawAttackCircle( void ); ///< the circle a left drag is sweeping targets out ofRenderObjClass *m_moveHintRenderObj[ MAX_MOVE_HINTS ];HAnimClass *m_moveHintAnim[ MAX_MOVE_HINTS ];diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 551e4580f..69f4afea0 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -43,6 +43,8 @@#include "GameClient/GameWindowManager.h"#include "GameClient/GadgetSlider.h"#include "GameClient/ControlBar.h"+#include "GameClient/Image.h"+#include "GameClient/Mouse.h"#include "W3DDevice/GameClient/W3DAssetManager.h"#include "W3DDevice/GameClient/W3DGUICallbacks.h"#include "W3DDevice/GameClient/W3DInGameUI.h"@@ -51,6 +53,7 @@#include "W3DDevice/Common/W3DConvert.h"#include "WW3D2/WW3D.h"#include "WW3D2/HAnim.h"+#include "WW3D2/Texture.h"#include "WW3D2/DX8Wrapper.h"#include "WW3D2/dx8vertexbuffer.h"#include "WW3D2/dx8indexbuffer.h"@@ -409,6 +412,13 @@ void W3DInGameUI::draw( void )if( m_isFormationDragging )drawFormationLine();+ // and where everything selected is headed, drag or no drag+ drawOrderHints();++ // the attack circle, while the left button is still sweeping it out+ if( isAttackCircling() )+ drawAttackCircle();+// for each view draw hints/// @todo should the UI be iterating through views like this?if( TheDisplay )@@ -773,66 +783,295 @@ void W3DInGameUI::drawSelectionRegion( void )} // end drawSelectionRegion//--------------------------------------------------------------------------------------------------/** draw the line a right drag is spreading the selection along, with one tick per unit so the- * spacing you are about to get is visible before you let go */+/** draw the line a right drag is spreading the selection along. Where each unit will stand is+ * said by the cursor sitting there, not by a mark on the line *///-------------------------------------------------------------------------------------------------void W3DInGameUI::drawFormationLine( void ){const Real width = 2.0f;- const UnsignedInt color = 0xCC33FF33; //0xAARRGGBB- const Real tickHalfLength = 6.0f;-+ // the line says which order it is about to be, in the colours the order hints already use+ const UnsignedInt color = isInAttackMoveToMode() ? 0xCCFF66CC+ : isForceAttackArmed() ? 0xCCFF5555+ : 0xCC33FF33; //0xAARRGGBBconst std::vector<ICoord2D>& curve = m_formationDragPoints;const Int points = (Int)curve.size();if( points < 2 )return;- // arc length up to each point, so the ticks divide the whole curve rather than each segment- Real arc[ MAX_FORMATION_DRAG_POINTS ];- arc[ 0 ] = 0.0f;for( Int i = 1; i < points; ++i )- {- const Real dx = (Real)(curve[ i ].x - curve[ i - 1 ].x);- const Real dy = (Real)(curve[ i ].y - curve[ i - 1 ].y);- arc[ i ] = arc[ i - 1 ] + sqrtf( dx * dx + dy * dy );-TheDisplay->drawLine( curve[ i - 1 ].x, curve[ i - 1 ].y, curve[ i ].x, curve[ i ].y,width, color );++ // no ticks along it any more. Every station already carries the cursor of the order it is about+ // to receive, drawn by drawOrderHints off the same hints, and a tick beside a cursor was the+ // same fact said twice++} // end drawFormationLine++//-------------------------------------------------------------------------------------------------+/** draw the circle a left drag is sweeping targets out of. It is a circle on the ground, not on+ * the screen, so it follows the terrain the way the selection it is about to make does */+//-------------------------------------------------------------------------------------------------+void W3DInGameUI::drawAttackCircle( void )+{+ Coord3D center, rim;+ TheTacticalView->screenToTerrain( &getAttackCircleAnchor(), ¢er );+ TheTacticalView->screenToTerrain( &getAttackCircleCursor(), &rim );++ const Real dx = rim.x - center.x;+ const Real dy = rim.y - center.y;+ const Real radius = (Real)sqrt( dx * dx + dy * dy );+ if( radius < 1.0f )+ return;++ const Int segments = 48;+ const UnsignedInt color = 0xCCFF5555; //0xAARRGGBB, the attack red the hints use+ const Real width = 2.0f;++ ICoord2D previous;+ Bool havePrevious = FALSE;+ for( Int i = 0; i <= segments; ++i )+ {+ const Real angle = 2.0f * PI * (Real)i / (Real)segments;+ Coord3D world;+ world.x = center.x + radius * (Real)cos( angle );+ world.y = center.y + radius * (Real)sin( angle );+ world.z = TheTerrainLogic->getGroundHeight( world.x, world.y );++ ICoord2D screen;+ if( TheTacticalView->worldToScreenTriReturn( &world, &screen ) == View::WTS_INVALID )+ {+ havePrevious = FALSE;+ continue;+ }++ if( havePrevious )+ TheDisplay->drawLine( previous.x, previous.y, screen.x, screen.y, width, color );++ previous = screen;+ havePrevious = TRUE;+ }++ // and the radius itself, so the drag reads as a radius rather than a rubber band+ ICoord2D middle;+ center.z = TheTerrainLogic->getGroundHeight( center.x, center.y );+ if( TheTacticalView->worldToScreenTriReturn( ¢er, &middle ) != View::WTS_INVALID )+ TheDisplay->drawLine( middle.x, middle.y, getAttackCircleCursor().x,+ getAttackCircleCursor().y, 1.0f, 0x66FF5555 );++} // end drawAttackCircle++//-------------------------------------------------------------------------------------------------+/** The marker on a destination is the cursor the player would be holding if they were pointing at+ * it: the move cursor for a move, the attack-move one for an attack-move, the attack one for an+ * attack. Same art, out of Mouse.ini, so nothing here has to invent a second visual language. */+//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+/** One cursor per order, out of the set the game already draws under the hand. A unit told to+ * garrison shows the garrison cursor where it is going, one sent to a repair bay shows that one,+ * and a group given four different jobs reads as four different markers rather than four arrows. */+//-------------------------------------------------------------------------------------------------+/** The thread is coloured by what it is for: anything that ends in a shot is red, an attack move+ * is pink, everything else is green. The marker on the end of it is the plain pointer in the same+ * colour - one shape for every order, so the colour is the whole message. */+//-------------------------------------------------------------------------------------------------+static UnsignedInt orderHintLineColor( InGameUI::OrderHintKind kind )+{+ switch( kind )+ {+ case InGameUI::ORDER_HINT_ATTACK_MOVE:+ return 0x66FF66CC;+ case InGameUI::ORDER_HINT_ATTACK:+ case InGameUI::ORDER_HINT_FORCE_ATTACK:+ case InGameUI::ORDER_HINT_ATTACK_GROUND:+ return 0x66FF5555;+ default:+ return 0x6655FF55;+ }+}++static UnsignedInt orderHintMarkerColor( InGameUI::OrderHintKind kind )+{+ return orderHintLineColor( kind ) | 0xFF000000;+}++struct OrderCursorArt+{+ const Image *image;+ ICoord2D hotSpot;+ Bool tried;+};+static OrderCursorArt s_orderCursorArt[ Mouse::NUM_MOUSE_CURSORS ];++//-------------------------------------------------------------------------------------------------+/** Turn one Windows cursor into something the 2D renderer can draw. Mouse.ini's Image entries+ * name mapped images that do not exist in the shipped data, and the Texture entries name .ANI+ * files rather than textures - so the art the player is actually holding only exists as an HCURSOR.+ * Pull the first frame's bits out of it and keep them as a texture. */+//-------------------------------------------------------------------------------------------------+static const Image *loadOrderCursorImage( Mouse::MouseCursor cursor, ICoord2D *hotSpot )+{+ const AsciiString& name = TheMouse->m_cursorInfo[ cursor ].textureName;+ if( name.isEmpty() )+ return NULL;++ char path[ 256 ];+ sprintf( path, "data\\cursors\\%s.ANI", name.str() );++ HCURSOR hcursor = LoadCursorFromFile( path );+ if( hcursor == NULL )+ return NULL;++ ICONINFO info;+ if( GetIconInfo( hcursor, &info ) == FALSE )+ return NULL;++ const Image *result = NULL;++ BITMAP bm;+ if( info.hbmColor && GetObject( info.hbmColor, sizeof( BITMAP ), &bm ) )+ {+ const Int w = bm.bmWidth;+ const Int h = bm.bmHeight;++ BITMAPINFO bi;+ memset( &bi, 0, sizeof( bi ) );+ bi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );+ bi.bmiHeader.biWidth = w;+ bi.bmiHeader.biHeight = -h; // negative means top down, which is the order a texture wants+ bi.bmiHeader.biPlanes = 1;+ bi.bmiHeader.biBitCount = 32;+ bi.bmiHeader.biCompression = BI_RGB;++ UnsignedInt *color = NEW UnsignedInt[ w * h ];+ UnsignedInt *mask = NEW UnsignedInt[ w * h ];++ HDC dc = GetDC( NULL );+ GetDIBits( dc, info.hbmColor, 0, h, color, &bi, DIB_RGB_COLORS );+ GetDIBits( dc, info.hbmMask, 0, h, mask, &bi, DIB_RGB_COLORS );+ ReleaseDC( NULL, dc );++ //+ // a 32-bit cursor carries its own alpha; an older one leaves it zero and says what is+ // transparent in the AND mask instead, where a white pixel is a hole+ //+ Bool hasAlpha = FALSE;+ for( Int i = 0; i < w * h; ++i )+ if( color[ i ] & 0xFF000000 )+ {+ hasAlpha = TRUE;+ break;+ }++ if( hasAlpha == FALSE )+ for( Int i = 0; i < w * h; ++i )+ color[ i ] |= (mask[ i ] & 0x00FFFFFF) ? 0x00000000 : 0xFF000000;++ TextureClass *texture = MSGNEW("TextureClass") TextureClass( w, h, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1 );+ SurfaceClass *surface = texture->Get_Surface_Level();+ Int pitch;+ UnsignedByte *bits = (UnsignedByte *)surface->Lock( &pitch );+ for( Int row = 0; row < h; ++row )+ memcpy( bits + row * pitch, color + row * w, w * sizeof( UnsignedInt ) );+ surface->Unlock();+ REF_PTR_RELEASE( surface );++ delete [] color;+ delete [] mask;++ Image *image = newInstance(Image);+ Region2D uv;+ uv.lo.x = 0.0f;+ uv.lo.y = 0.0f;+ uv.hi.x = 1.0f;+ uv.hi.y = 1.0f;+ image->setStatus( IMAGE_STATUS_RAW_TEXTURE );+ image->setRawTextureData( texture );+ image->setUV( &uv );+ image->setTextureWidth( w );+ image->setTextureHeight( h );+ ICoord2D size;+ size.x = w;+ size.y = h;+ image->setImageSize( &size );++ hotSpot->x = info.xHotspot;+ hotSpot->y = info.yHotspot;+ result = image;+ }++ if( info.hbmColor )+ DeleteObject( info.hbmColor );+ if( info.hbmMask )+ DeleteObject( info.hbmMask );++ return result;+}++//-------------------------------------------------------------------------------------------------+/** The marker on a destination is the cursor the player would be holding if they were pointing at+ * it: the move cursor for a move, the attack-move one for an attack-move, the attack one for an+ * attack. Same art, so nothing here has to invent a second visual language. Built once. */+//-------------------------------------------------------------------------------------------------+static const Image *orderCursorImage( Mouse::MouseCursor cursor, ICoord2D *hotSpot )+{+ OrderCursorArt& art = s_orderCursorArt[ cursor ];+ if( art.tried == FALSE )+ {+ art.image = loadOrderCursorImage( cursor, &art.hotSpot );+ art.tried = TRUE;}- const Int count = getSelectCount();- const Real span = arc[ points - 1 ];- if( count < 2 || span < 1.0f )+ *hotSpot = art.hotSpot;+ return art.image;+}++//-------------------------------------------------------------------------------------------------+/** One faint line per selected unit, from where it stands to where it is going, with the order's+ * own cursor sitting on the destination. Green for a move, pink for an attack-move, red for an+ * attack. The goals are read off the units every frame, so the lines last as long as the orders+ * do and go when the units arrive or the selection changes. */+//-------------------------------------------------------------------------------------------------+void W3DInGameUI::drawOrderHints( void )+{+ const std::vector<OrderHint>& hints = getOrderHints();+ if( hints.empty() )return;- Int seg = 1;- for( Int i = 0; i < count; ++i )+ const Real width = 1.0f;++ for( std::vector<OrderHint>::const_iterator it = hints.begin(); it != hints.end(); ++it ){- const Real dist = span * (Real)i / (Real)(count - 1);- while( seg < points - 1 && arc[ seg ] < dist )- ++seg;-- const Real segLen = arc[ seg ] - arc[ seg - 1 ];- const Real t = (segLen > 0.0f) ? ((dist - arc[ seg - 1 ]) / segLen) : 0.0f;- const Real dx = (Real)(curve[ seg ].x - curve[ seg - 1 ].x);- const Real dy = (Real)(curve[ seg ].y - curve[ seg - 1 ].y);- const Real sx = (Real)curve[ seg - 1 ].x + dx * t;- const Real sy = (Real)curve[ seg - 1 ].y + dy * t;-- // perpendicular to the segment the station sits on, so a tick reads as a slot rather than as- // part of the line- const Real segSpan = (segLen > 0.0f) ? segLen : 1.0f;- const Real px = -dy / segSpan;- const Real py = dx / segSpan;-- TheDisplay->drawLine( REAL_TO_INT_FLOOR( sx - px * tickHalfLength ),- REAL_TO_INT_FLOOR( sy - py * tickHalfLength ),- REAL_TO_INT_FLOOR( sx + px * tickHalfLength ),- REAL_TO_INT_FLOOR( sy + py * tickHalfLength ),- width, color );+ const UnsignedInt lineColor = orderHintLineColor( it->kind );++ // a unit off the edge of the screen still has a destination worth seeing, and the line to it+ // says which way it went. WTS_OUTSIDE_FRUSTUM still gives usable pixels, so only points+ // behind the camera are dropped+ ICoord2D from, to;+ if( TheTacticalView->worldToScreenTriReturn( &it->from, &from ) == View::WTS_INVALID )+ continue;+ if( TheTacticalView->worldToScreenTriReturn( &it->to, &to ) == View::WTS_INVALID )+ continue;++ TheDisplay->drawLine( from.x, from.y, to.x, to.y, width, lineColor );++ // the marker is the plain pointer, tinted: its white body takes the order colour and the+ // dark outline stays. The hot spot is the pixel the player aims with, so that is the pixel+ // that goes on the destination - a pointer hung by its top left corner points at the wrong+ // ground+ ICoord2D hotSpot;+ const Image *image = orderCursorImage( Mouse::ARROW, &hotSpot );+ if( image )+ {+ const Int w = image->getImageWidth();+ const Int h = image->getImageHeight();+ const Int x = to.x - hotSpot.x;+ const Int y = to.y - hotSpot.y;+ TheDisplay->drawImage( image, x, y, x + w, y + h, orderHintMarkerColor( it->kind ) );+ }}-} // end drawFormationLine+} // end drawOrderHints//-------------------------------------------------------------------------------------------------/** Draw the visual feedback for clicking in the world and telling unitsdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex 15c9b990f..74e6c6210 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -268,7 +268,7 @@ void W3DView::setOrigin( Int x, Int y)// how far past the map's default max camera height the player may zoom out by hand.// only the manual zoom limit is stretched - the default/scripted views still use// m_maxHeightAboveGround, so a map still opens framed the way its author meant it to.-#define ZOOM_OUT_LIMIT_FACTOR (1.6f)+#define ZOOM_OUT_LIMIT_FACTOR (3.2f)void W3DView::buildCameraTransform( Matrix3D *transform ){Vector3 sourcePos, targetPos;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cppindex 470316f66..7d9d9e283 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp@@ -189,60 +189,12 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)- if( TheInGameUI->isInWaypointMode() )- {- //Create a default light environment with no lights and only full ambient.- //@todo: Fix later by copying default scene light environement from W3DScene.cpp.- LightEnvironmentClass lightEnv;- lightEnv.Reset(Vector3(0,0,0), Vector3(1.0f,1.0f,1.0f));- lightEnv.Pre_Render_Update(rinfo.Camera.Get_Transform());- RenderInfoClass localRinfo(rinfo.Camera);- localRinfo.light_environment=&lightEnv;- Vector3 points[ MAX_DISPLAY_NODES + 1 ]; //Lines have nodes + 1 points.+ // Retail drew its own white nodes-and-lines here for every selected unit's goal path while+ // isInWaypointMode() (shift held) was true. The shift queue now has its own colored, per-order+ // hint threads (InGameUI::updateOrderHints / W3DInGameUI::drawOrderHints), which cover the same+ // ground and stay up after the key is let go, so the white duplicate is gone rather than merely+ // hidden - its only firing condition was this same isInWaypointMode() check.-- const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();- Drawable *draw;- for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )- {- draw = *it;- Object *obj = draw->getObject();- Int numPoints = 1;- if( obj && ! obj->isKindOf( KINDOF_IGNORED_IN_GUI ))//so mobs and stuff sont make a gazillion lines- {- AIUpdateInterface *ai = obj->getAI();- Int goalSize = ai ? ai->friend_getWaypointGoalPathSize() : 0;- Int gpIdx = ai ? ai->friend_getCurrentGoalPathIndex() : 0;-- if( ai && gpIdx >= 0 && gpIdx < goalSize )- {- const Coord3D *pos = obj->getPosition();- points[ 0 ].Set( Vector3( pos->x, pos->y, pos->z ) );-- for( int i = gpIdx; i < goalSize; i++ )- {- const Coord3D *waypoint = ai->friend_getGoalPathPosition( i );- if( waypoint )- {- //Render line from previous point to current node.-- if( numPoints < MAX_DISPLAY_NODES + 1 )- {- points[ numPoints ].Set( Vector3( waypoint->x, waypoint->y, waypoint->z ) );- numPoints++;- }-- m_waypointNodeRobj->Set_Position(Vector3(waypoint->x,waypoint->y,waypoint->z));- WW3D::Render(*m_waypointNodeRobj,localRinfo);- }- }- //Now render the lines in one pass!- queueLine( numPoints, points );- }- }- }- renderQueuedLines( localRinfo );- }// Rally points, drawn whenever we are not actively laying down waypoints. This used to be the// else of the block above, which is why turning that block on full time hid every rally line.if( !TheInGameUI->isInWaypointMode() )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 18e07f378..a70911da5 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -942,6 +942,75 @@ TEST(formation_drag_takes_the_right_button_only_when_it_is_asked_for)CHECK( !Command_formationDragArmed( true, true, true ) );}+/* DrawnPath.cpp: the drawn curve is measured by arc length, not by segment, so the stations divide+ the whole line however uneven the hand that drew it was. */+#include "Common/DrawnPath.h"++static Coord3D drawnPathPoint( Real x, Real y )+{+ Coord3D p;+ p.x = x; p.y = y; p.z = 0.0f;+ return p;+}++TEST(drawn_path_measures_by_arc_length_not_by_segment)+{+ /* an L: 100 along x, then 100 along y, with the corner deliberately not in the middle of the+ point list - the second segment is one point, the first is two. */+ std::vector<Coord3D> path;+ path.push_back( drawnPathPoint( 0.0f, 0.0f ) );+ path.push_back( drawnPathPoint( 40.0f, 0.0f ) );+ path.push_back( drawnPathPoint( 100.0f, 0.0f ) );+ path.push_back( drawnPathPoint( 100.0f, 100.0f ) );++ std::vector<Real> arc;+ buildPathArcLengths( path, arc );++ CHECK_EQ( 4, (int)arc.size() );+ CHECK_NEAR( 0.0f, arc[0], 0.001f );+ CHECK_NEAR( 40.0f, arc[1], 0.001f );+ CHECK_NEAR( 200.0f, arc[3], 0.001f );++ /* halfway along the whole curve is the corner, not the middle of either segment. */+ Coord3D at;+ pointAlongPath( path, arc, 100.0f, &at );+ CHECK_NEAR( 100.0f, at.x, 0.001f );+ CHECK_NEAR( 0.0f, at.y, 0.001f );++ /* three quarters along is halfway up the second leg. */+ pointAlongPath( path, arc, 150.0f, &at );+ CHECK_NEAR( 100.0f, at.x, 0.001f );+ CHECK_NEAR( 50.0f, at.y, 0.001f );++ /* the ends stay put. */+ pointAlongPath( path, arc, 0.0f, &at );+ CHECK_NEAR( 0.0f, at.x, 0.001f );+ pointAlongPath( path, arc, 200.0f, &at );+ CHECK_NEAR( 100.0f, at.x, 0.001f );+ CHECK_NEAR( 100.0f, at.y, 0.001f );+}++TEST(drawn_path_orders_units_by_where_they_already_stand)+{+ std::vector<Coord3D> path;+ path.push_back( drawnPathPoint( 0.0f, 0.0f ) );+ path.push_back( drawnPathPoint( 100.0f, 0.0f ) );+ path.push_back( drawnPathPoint( 100.0f, 100.0f ) );++ std::vector<Real> arc;+ buildPathArcLengths( path, arc );++ /* a unit sitting off to one side belongs to the nearest point on the curve. */+ CHECK_NEAR( 30.0f, distanceAlongPath( path, arc, 30.0f, -25.0f ), 0.001f );++ /* one past the corner is measured round it, not across it. */+ CHECK_NEAR( 160.0f, distanceAlongPath( path, arc, 140.0f, 60.0f ), 0.001f );++ /* before the start clamps to the start, past the end to the end. */+ CHECK_NEAR( 0.0f, distanceAlongPath( path, arc, -50.0f, -50.0f ), 0.001f );+ CHECK_NEAR( 200.0f, distanceAlongPath( path, arc, 100.0f, 400.0f ), 0.001f );+}+/* AssaultTransportAIUpdate.cpp: the troop crawler deploys its passengers at a target and used toleave them walking behind it for the rest of the attack move once that target died - and on aplain attack order it re-boarded them the instant the target died, once per dead enemy. Both