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): spread a selection along a dragged formation line
Olcay Seygan6fb6a53d8050
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cbd18d759..b1dd1b0b7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -115,6 +115,7 @@ found and fixed — EA's own, not port damage.**- A reservation lapses within half a second if the shot never arrives.- 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.+- Hold Ctrl and 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. Ticks on the line show where each unit lands before you let go. The camera still scrolls on a plain right drag; if you never scroll that way, `FormationDrag = 2` in Options.ini puts the line on the bare right button, and `0` turns it off.- 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 ignoreddiff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 6c999f454..65d97d1f8 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -357,6 +357,7 @@ public:Bool m_nudgeBuildPlacement; ///< slide a blocked structure to the nearest spot it does fitBool m_middleMousePans; ///< middle-button drag pans the camera instead of rotating itBool m_zoomToCursor; ///< the mouse wheel zooms toward whatever the cursor is over+ Int m_formationDrag; ///< 0 off, 1 ctrl and the right button draw a formation line, 2 the right button aloneBool m_showHudOverlay; ///< draw the fps / elapsed time / income line in the cornerBool m_showPlacementRangeRing; ///< while placing a structure, ring its weapon rangeBool m_workersReturnToSupply; ///< a worker that finishes a build job goes back to the dock it leftdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex 4e6dcdfe8..18aaf6239 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -634,6 +634,7 @@ public:MSG_SET_MINE_CLEARING_DETAIL, ///< CRC from the logic passed around in a network game :)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, location) spread the selection along a drawn line (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/CommandXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.hindex 06d00ee91..6a85976bd 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h@@ -58,7 +58,12 @@ private:ICoord2D m_mouseRightDragLift; // the location of a possible mouse drag endUnsignedInt m_mouseRightDown; // when the mouse down happenedUnsignedInt m_mouseRightUp; // when the mouse up happened-++ // latched the moment the right button goes down: whether this drag is drawing a formation line.+ // Latched rather than asked again, so letting go of ctrl halfway through does not abandon a line+ // the player is already dragging.+ Bool m_formationDragArmed;+GameMessage::Type createMoveToLocationMessage( Drawable *draw, const Coord3D *dest, CommandEvaluateType commandType );GameMessage::Type createAttackMessage( Drawable *draw, Drawable *other, CommandEvaluateType commandType );GameMessage::Type createEnterMessage( Drawable *enter, CommandEvaluateType commandType );@@ -129,6 +134,15 @@ extern void pickAndPlayUnitVoiceResponse( const DrawableList *list, GameMessage:///< does the stop key cancel a building that is going up, rather than stopping a unit?extern Bool Command_stopMeansCancelConstruction( Int selectionCount, Bool locallyControlled, Bool underConstruction );+/** Is this right-button press the start of a formation line rather than a camera scroll?+ * setting is TheGlobalData->m_formationDrag: 0 off, 1 ctrl and the right button, 2 the right+ * button on its own. */+extern Bool Command_formationDragArmed( Int setting, Bool ctrlHeld, Bool haveMovableSelection,+ Bool guiCommandPending );++///< the same question against the live UI; LookAtXlat asks it to keep its hands off the scroll+extern Bool CommandXlat_isFormationDragArmed( void );+class Player;/** Single-player test hook: make this player the one at the keyboard, throwing away any AI behind* it first. FALSE if that player cannot be played (yourself, neutral, observer, beaten) or thisdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex e498b50ea..f96d91415 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -397,6 +397,13 @@ public: // ********************************************************************// interface for graphical "hints" which provide visual feedback for user-interface commandsvirtual void beginAreaSelectHint( const GameMessage *msg ); ///< Used by HintSpy. An area selection is occurring, start graphical "hint"virtual void endAreaSelectHint( const GameMessage *msg ); ///< Used by HintSpy. An area selection had occurred, finish graphical "hint"+ // the line the player is dragging out for a formation move, in screen pixels+ void setFormationDrag( const ICoord2D& anchor, const ICoord2D& current );+ void clearFormationDrag( void ) { m_isFormationDragging = FALSE; }+ Bool isFormationDragging( void ) const { return m_isFormationDragging; }+ const ICoord2D& getFormationDragAnchor( void ) const { return m_formationDragAnchor; }+ const ICoord2D& getFormationDragCurrent( void ) const { return m_formationDragCurrent; }+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"@@ -954,6 +961,9 @@ protected:DrawableList m_selectedLocalDrawables; ///< A list of all selected drawables owned by the local playerBool m_isDragSelecting; ///< If TRUE, an area selection is in progressIRegion2D m_dragSelectRegion; ///< if isDragSelecting is TRUE, this contains select region+ Bool m_isFormationDragging; ///< TRUE while a formation line is being drawn (fork)+ ICoord2D m_formationDragAnchor; ///< where that line started, in pixels+ ICoord2D m_formationDragCurrent; ///< where the cursor is now, in pixelsBool m_displayedMaxWarning; ///< keeps the warning from being shown over and overMoveHintStruct m_moveHint[ MAX_MOVE_HINTS ];Int m_nextMoveHint;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex a972d2884..7fb8aa343 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -194,6 +194,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;{ "NudgeBuildPlacement", INI::parseBool, NULL, offsetof( GlobalData, m_nudgeBuildPlacement ) },{ "MiddleMousePans", INI::parseBool, NULL, offsetof( GlobalData, m_middleMousePans ) },{ "ZoomToCursor", INI::parseBool, NULL, offsetof( GlobalData, m_zoomToCursor ) },+ { "FormationDrag", INI::parseInt, NULL, offsetof( GlobalData, m_formationDrag ) },{ "ShowHudOverlay", INI::parseBool, NULL, offsetof( GlobalData, m_showHudOverlay ) },{ "ShowPlacementRangeRing", INI::parseBool, NULL, offsetof( GlobalData, m_showPlacementRangeRing ) },{ "WorkersReturnToSupply", INI::parseBool, NULL, offsetof( GlobalData, m_workersReturnToSupply ) },@@ -1053,6 +1054,8 @@ GlobalData::GlobalData()// middle-drag stays a rotate by default (it snaps to 45 degrees on release); pan is opt-inm_middleMousePans = FALSE;m_zoomToCursor = TRUE;+ // ctrl plus the right button, so plain right-drag scrolling is untouched+ m_formationDrag = 1;m_snapBuildPlacementTo45 = TRUE;m_gridBuildPlacement = TRUE;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex 0fd475e93..fb6471240 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -674,6 +674,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)CHECK_IF(MSG_ADD_WAYPOINT)CHECK_IF(MSG_DO_GUARD_POSITION)CHECK_IF(MSG_DO_HOLD_POSITION)+ CHECK_IF(MSG_DO_FORMATION_MOVETO)CHECK_IF(MSG_DO_GUARD_OBJECT)CHECK_IF(MSG_DO_STOP)CHECK_IF(MSG_DO_SCATTER)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cppindex 79587ac4a..de6770619 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp@@ -49,6 +49,7 @@ OPTION_INT_ACCESSORS( m_bloomThreshold )OPTION_INT_ACCESSORS( m_windowMode )OPTION_INT_ACCESSORS( m_msaaLevel )OPTION_INT_ACCESSORS( m_healthBarMode )+OPTION_INT_ACCESSORS( m_formationDrag )//-----------------------------------------------------------------------------static const unsigned TheMsaaSamples[ OPTION_MSAA_LEVEL_COUNT ] = { 0, 2, 4, 8, 16 };@@ -112,6 +113,14 @@ const OptionDef TheOptionCatalog[] =OPTION_BOOL, APPLY_LIVE, 0, 1,get_m_zoomToCursor, set_m_zoomToCursor },+ // Which drag draws the line a selection spreads itself along. 0 is off, 1 is Ctrl and the right+ // button, which is the default because it leaves right-drag scrolling exactly where it was, and+ // 2 is the bare right button for players who never scroll that way and want the drag on one+ // hand. Under 2 a right drag with units selected no longer moves the camera.+ { "FormationDrag", "", "",+ OPTION_INT, APPLY_LIVE, 0, 2,+ get_m_formationDrag, set_m_formationDrag },+// Eight rows used to sit here: grid and nudge build placement, snap-to-45 building rotation, the// placement range ring, workers returning to supply, detailed build tooltips, the HUD overlay// and replay archiving. Every one of them is now on for everybody, decided in GlobalData'sdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 3a71fffbb..0f41a4772 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -1005,6 +1005,9 @@ InGameUI::InGameUI()m_inputEnabled = true;m_isDragSelecting = false;+ m_isFormationDragging = FALSE;+ m_formationDragAnchor.x = m_formationDragAnchor.y = 0;+ m_formationDragCurrent = m_formationDragAnchor;m_nextMoveHint = 0;m_selectCount = 0;m_frameSelectionChanged = 0;@@ -2587,6 +2590,16 @@ void InGameUI::endAreaSelectHint( const GameMessage *msg )m_isDragSelecting = false;}+//-------------------------------------------------------------------------------------------------+/** The player is dragging out the line a formation move will spread along. */+//-------------------------------------------------------------------------------------------------+void InGameUI::setFormationDrag( const ICoord2D& anchor, const ICoord2D& current )+{+ m_isFormationDragging = TRUE;+ m_formationDragAnchor = anchor;+ m_formationDragCurrent = current;+}+//-------------------------------------------------------------------------------------------------/** A move command has occurred, start graphical "hint". *///-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex c5cedb9ba..c446c2aa6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -125,6 +125,31 @@ Bool Command_stopMeansCancelConstruction( Int selectionCount, Bool locallyControreturn selectionCount == 1 && locallyControlled && underConstruction;}+//-------------------------------------------------------------------------------------------------+/**+ * Is this right-button press the start of a formation line?+ * A GUI command waiting for a target owns the next click whatever the mouse settings say, and with+ * nothing of your own selected there is nobody to spread, so both of those fall through to the+ * camera scroll the right button has always been.+ */+Bool Command_formationDragArmed( Int setting, Bool ctrlHeld, Bool haveMovableSelection,+ Bool guiCommandPending )+{+ if( setting <= 0 || guiCommandPending || !haveMovableSelection )+ return FALSE;++ return setting >= 2 || ctrlHeld;+}++Bool CommandXlat_isFormationDragArmed( void )+{+ return Command_formationDragArmed( TheGlobalData->m_formationDrag,+ TheInGameUI->isInForceAttackMode(),+ TheInGameUI->getSelectCount() > 0+ && TheInGameUI->areSelectedObjectsControllable(),+ TheInGameUI->getGUICommand() != NULL );+}+#if defined(_DEBUG) || defined(_INTERNAL)/*non-static*/ Real TheSkateDistOverride = 0.0f;@@ -1354,7 +1379,8 @@ CommandTranslator::CommandTranslator() :m_objective(0),m_teamExists(false),m_mouseRightDown(0),- m_mouseRightUp(0)+ m_mouseRightUp(0),+ m_formationDragArmed(FALSE){m_mouseRightDragAnchor.x = 0;m_mouseRightDragAnchor.y = 0;@@ -3857,6 +3883,24 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagem_mouseRightDragAnchor = msg->getArgument( 0 )->pixel;m_mouseRightDown = (UnsignedInt) msg->getArgument( 2 )->integer;+ m_formationDragArmed = CommandXlat_isFormationDragArmed();++ break;+ }++ //-----------------------------------------------------------------------------+ case GameMessage::MSG_RAW_MOUSE_POSITION:+ {+ // the line only appears once the cursor has travelled far enough that this is a drag and+ // not a click that wobbled+ if( m_formationDragArmed )+ {+ const ICoord2D& here = msg->getArgument( 0 )->pixel;+ if( (UnsignedInt)abs( here.x - m_mouseRightDragAnchor.x ) > TheMouse->m_dragTolerance+ || (UnsignedInt)abs( here.y - m_mouseRightDragAnchor.y ) > TheMouse->m_dragTolerance )+ TheInGameUI->setFormationDrag( m_mouseRightDragAnchor, here );+ }+break;}@@ -3867,6 +3911,35 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagem_mouseRightDragLift = msg->getArgument( 0 )->pixel;m_mouseRightUp = (UnsignedInt) msg->getArgument( 2 )->integer;+ if( m_formationDragArmed )+ {+ const Bool wasDrag = TheInGameUI->isFormationDragging();++ TheInGameUI->clearFormationDrag();+ m_formationDragArmed = FALSE;++ if( wasDrag )+ {+ // two screen points become two world points; who stands where along the line between+ // them is decided on the logic side, where every machine decides it the same way+ Coord3D from, to;+ TheTacticalView->screenToTerrain( &m_mouseRightDragAnchor, &from );+ TheTacticalView->screenToTerrain( &m_mouseRightDragLift, &to );++ GameMessage *newMsg = TheMessageStream->appendMessage( GameMessage::MSG_DO_FORMATION_MOVETO );+ newMsg->appendLocationArgument( from );+ newMsg->appendLocationArgument( to );++ TheInGameUI->clearAttackMoveToMode();++ const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();+ if( selected && !selected->empty() )+ pickAndPlayUnitVoiceResponse( selected, GameMessage::MSG_DO_MOVETO );++ break;+ }+ }+//Kris: July 7, 2003. Added this code to deselect build placement mode when right clicked. This fixes//a bug where you couldn't cancel the sneak attack mode via right click. This only happened when you//didn't have anything selected which is possible via the shortcut bar. Normally, it would get deselecteddiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cppindex 918f2608e..dde751ecb 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp@@ -48,6 +48,7 @@#include "GameClient/View.h"#include "GameClient/Drawable.h"#include "GameClient/LookAtXlat.h"+#include "GameClient/CommandXlat.h" // for the formation drag, which takes the right button away#include "GameLogic/Module/UpdateModule.h"#include "GameLogic/GameLogic.h"@@ -292,7 +293,9 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessagem_anchor = msg->getArgument( 0 )->pixel;m_currentPos = msg->getArgument( 0 )->pixel;- if (!TheInGameUI->isSelecting() && !m_isScrolling)+ // a right button that is about to draw a formation line is not a scroll; this translator+ // runs before CommandTranslator, so it has to ask the same question for itself+ if (!TheInGameUI->isSelecting() && !m_isScrolling && !CommandXlat_isFormationDragArmed()){setScrolling(SCROLL_RMB);}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 22c91abec..f7a8939b2 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -60,6 +60,7 @@#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Module/DozerAIUpdate.h"#include "GameLogic/Module/SupplyTruckAIUpdate.h"+#include "GameLogic/TerrainLogic.h"//-------------------------------------------------------------------------------------------------/** Which builder takes a structure job: the free one nearest the site, or failing that the@@ -968,6 +969,89 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )break;}+ //---------------------------------------------------------------------------------------------+ //+ // Formation move (fork). The player drags a line and the selection spreads itself along+ // it, one unit per station, which is the one thing the removed group movement work was+ // trying to do for them and could not: where the units end up is now drawn rather than+ // guessed at. The stations are handed out in the order the units already stand along the+ // line, so nobody crosses anybody on the way in, and the whole thing is resolved here so+ // the message is two points instead of a list of orders.+ //+ case GameMessage::MSG_DO_FORMATION_MOVETO:+ {+ Coord3D from = msg->getArgument( 0 )->location;+ Coord3D to = msg->getArgument( 1 )->location;++ if (currentlySelectedGroup == NULL)+ break;++ std::vector<Object *> movers;+ const VecObjectID& ids = currentlySelectedGroup->getAllIDs();+ for (VecObjectID::const_iterator it = ids.begin(); it != ids.end(); ++it)+ {+ Object *obj = TheGameLogic->findObjectByID( *it );+ if (!obj || obj->getControllingPlayer() != thisPlayer)+ continue;+ if (obj->isKindOf( KINDOF_IMMOBILE ) || obj->getAIUpdateInterface() == NULL)+ continue;+ movers.push_back( obj );+ }++ if (movers.empty())+ break;++ Coord2D along;+ along.x = to.x - from.x;+ along.y = to.y - from.y;+ const Real span = along.length();+ if (span < 1.0f)+ break;+ along.x /= span;+ along.y /= span;++ //+ // Sort by where each unit already sits along the line. 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 = (held->getPosition()->x - from.x) * along.x ++ (held->getPosition()->y - from.y) * along.y;+ Int j = i - 1;+ while (j >= 0)+ {+ const Real key = (movers[ j ]->getPosition()->x - from.x) * along.x ++ (movers[ j ]->getPosition()->y - from.y) * along.y;+ if (key < heldKey || (key == heldKey && movers[ j ]->getID() < held->getID()))+ break;+ movers[ j + 1 ] = movers[ j ];+ j--;+ }+ movers[ j + 1 ] = held;+ }++ currentlySelectedGroup->releaseWeaponLockForGroup( LOCKED_TEMPORARILY );++ const Int count = movers.size();+ for (Int i = 0; i < count; i++)+ {+ // one unit stands where the line ends, everyone else divides it evenly+ const Real t = (count == 1) ? 1.0f : ((Real)i / (Real)(count - 1));++ Coord3D station;+ station.x = from.x + along.x * span * t;+ station.y = from.y + along.y * span * t;+ station.z = TheTerrainLogic->getGroundHeight( station.x, station.y );++ movers[ i ]->getAIUpdateInterface()->aiMoveToPosition( &station, CMD_FROM_PLAYER );+ }++ break;+ }+//---------------------------------------------------------------------------------------------case GameMessage::MSG_DO_GUARD_OBJECT:{diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.hindex a2d3a7801..48311b0c7 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h@@ -79,6 +79,7 @@ protected:virtual void drawAttackHints( View *view ); ///< draw attack hint visual feedbackvirtual void drawPlaceAngle( View *view ); ///< draw place building angle if neededvirtual void drawBuildGrid( void ); ///< the pathfinder's build grid under a pending structure+ virtual void drawFormationLine( void ); ///< the line a right drag is spreading the selection alongRenderObjClass *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 548d9c389..9b568cb3a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -405,6 +405,10 @@ void W3DInGameUI::draw( void )if( m_isDragSelecting )drawSelectionRegion();+ // draw the formation line if one is being dragged out+ if( m_isFormationDragging )+ drawFormationLine();+// for each view draw hints/// @todo should the UI be iterating through views like this?if( TheDisplay )@@ -768,6 +772,49 @@ 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 */+//-------------------------------------------------------------------------------------------------+void W3DInGameUI::drawFormationLine( void )+{+ const Real width = 2.0f;+ const UnsignedInt color = 0xCC33FF33; //0xAARRGGBB+ const Real tickHalfLength = 6.0f;++ const Real ax = (Real)m_formationDragAnchor.x;+ const Real ay = (Real)m_formationDragAnchor.y;+ const Real bx = (Real)m_formationDragCurrent.x;+ const Real by = (Real)m_formationDragCurrent.y;++ TheDisplay->drawLine( m_formationDragAnchor.x, m_formationDragAnchor.y,+ m_formationDragCurrent.x, m_formationDragCurrent.y,+ width, color );++ const Int count = getSelectCount();+ const Real span = sqrtf( (bx - ax) * (bx - ax) + (by - ay) * (by - ay) );+ if( count < 2 || span < 1.0f )+ return;++ // perpendicular to the line, so a tick reads as a slot rather than as part of the line+ const Real px = -(by - ay) / span;+ const Real py = (bx - ax) / span;++ for( Int i = 0; i < count; ++i )+ {+ const Real t = (Real)i / (Real)(count - 1);+ const Real sx = ax + (bx - ax) * t;+ const Real sy = ay + (by - ay) * t;++ 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 );+ }++} // end drawFormationLine+//-------------------------------------------------------------------------------------------------/** Draw the visual feedback for clicking in the world and telling units* to move there */diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 8b9074115..75fe5bba4 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -924,6 +924,30 @@ TEST(ctrl_is_force_fire_only_while_the_attack_move_cursor_is_down)CHECK( !CommandXlat_isForceAttackTargeting( false, true ) );}+/* CommandXlat.cpp: the right button already scrolls the camera, so the formation line has to be+ sure it is wanted before it takes that drag away. LookAtXlat asks the same question one+ translator earlier, which is why the rule is a function rather than a condition written twice. */+extern Bool Command_formationDragArmed( Int setting, Bool ctrlHeld, Bool haveMovableSelection,+ Bool guiCommandPending );++TEST(formation_drag_takes_the_right_button_only_when_it_is_asked_for)+{+ /* setting 1, the default: ctrl and the right button together, and nothing else. */+ CHECK( Command_formationDragArmed( 1, true, true, false ) );+ CHECK( !Command_formationDragArmed( 1, false, true, false ) );++ /* setting 2: the right button on its own, ctrl or no ctrl. */+ CHECK( Command_formationDragArmed( 2, false, true, false ) );+ CHECK( Command_formationDragArmed( 2, true, true, false ) );++ /* off is off. */+ CHECK( !Command_formationDragArmed( 0, true, true, false ) );++ /* nobody to spread, or a GUI command already waiting for this click. */+ CHECK( !Command_formationDragArmed( 2, true, false, false ) );+ CHECK( !Command_formationDragArmed( 2, true, true, true ) );+}+/* 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