Skip to content

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.

fix(gameclient): three defects in the new mouse scheme

Olcay Seygand9cecaf3e53a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bfd1e9a25..b34019d47 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -115,8 +115,8 @@ 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.
-- 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: drag it and the ground follows the cursor, 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. Ticks on the line show where each unit lands before you let go. 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.
+- 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.
- 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
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
index 18aaf6239..eb0964116 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
@@ -634,7 +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_DO_FORMATION_MOVETO, ///< (location...) spread the selection along a drawn curve (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.h
index 0bfbd3cf4..3f4346604 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -397,12 +397,14 @@ public: // ********************************************************************
// interface for graphical "hints" which provide visual feedback for user-interface commands
virtual 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; }
+ // 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 };
+ void addFormationDragPoint( const ICoord2D& pt );
+ void clearFormationDrag( void ) { m_isFormationDragging = FALSE; m_formationDragPoints.clear(); }
Bool isFormationDragging( void ) const { return m_isFormationDragging; }
- const ICoord2D& getFormationDragAnchor( void ) const { return m_formationDragAnchor; }
- const ICoord2D& getFormationDragCurrent( void ) const { return m_formationDragCurrent; }
+ const std::vector<ICoord2D>& getFormationDragPoints( void ) const { return m_formationDragPoints; }
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"
@@ -808,6 +810,10 @@ public: // ********************************************************************
void setDrawRMBScrollAnchor(Bool b) { m_drawRMBScrollAnchor = b; }
void setMoveRMBScrollAnchor(Bool b) { m_moveRMBScrollAnchor = b; }
+ // The camera scroll moved from the right button to the middle one; the two INI fields keep their
+ // shipped names because InGameUI.ini sets them and an unknown field is a parse error.
+ Bool shouldMoveScrollAnchor( void ) const { return m_moveRMBScrollAnchor; }
+
private:
virtual Int getIdleWorkerCount( void );
virtual Object *findIdleWorker( Object *obj);
@@ -960,8 +966,7 @@ protected:
Bool m_isDragSelecting; ///< If TRUE, an area selection is in progress
IRegion2D 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 pixels
+ std::vector<ICoord2D> m_formationDragPoints; ///< the traced curve, in pixels, first point is where it started
Bool m_displayedMaxWarning; ///< keeps the warning from being shown over and over
MoveHintStruct m_moveHint[ MAX_MOVE_HINTS ];
Int m_nextMoveHint;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
index 0fd21fe3b..eda4a0d0d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
@@ -39,6 +39,8 @@ public:
LookAtTranslator();
~LookAtTranslator();
virtual GameMessageDisposition translateGameMessage(const GameMessage *msg);
+ /// where the middle-button scroll was started from, or NULL if no such scroll is running
+ const ICoord2D* getScrollAnchor( void );
Bool hasMouseMovedRecently( void );
void setCurrentPos( const ICoord2D& pos );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index e426f4556..395360737 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1006,8 +1006,6 @@ 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;
@@ -2593,11 +2591,39 @@ void InGameUI::endAreaSelectHint( const GameMessage *msg )
//-------------------------------------------------------------------------------------------------
/** The player is dragging out the line a formation move will spread along. */
//-------------------------------------------------------------------------------------------------
-void InGameUI::setFormationDrag( const ICoord2D& anchor, const ICoord2D& current )
+void InGameUI::addFormationDragPoint( const ICoord2D& pt )
{
m_isFormationDragging = TRUE;
- m_formationDragAnchor = anchor;
- m_formationDragCurrent = current;
+
+ if( m_formationDragPoints.empty() )
+ {
+ m_formationDragPoints.push_back( pt );
+ 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 )
+ {
+ const Int keptIndex = (Int)m_formationDragPoints.size() - 2;
+ if( keptIndex < 0 )
+ {
+ m_formationDragPoints.push_back( pt );
+ return;
+ }
+
+ 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 );
+ return;
+ }
+ }
+
+ m_formationDragPoints.back() = pt;
}
//-------------------------------------------------------------------------------------------------
@@ -4537,9 +4563,23 @@ void InGameUI::postDraw( void )
}
}
- // The right-button scroll anchor used to be drawn here. The right button does not scroll any
- // more, so there is nothing to mark. DrawRMBScrollAnchor and MoveRMBScrollAnchor stay in the
- // INI table above because shipped InGameUI.ini sets them and an unknown field is a parse error.
+ // draw the scroll anchor, which sits on the middle button now
+ if (TheLookAtTranslator && m_drawRMBScrollAnchor)
+ {
+ const ICoord2D* anchor = TheLookAtTranslator->getScrollAnchor();
+ if (anchor)
+ {
+ static const Int w = 2;
+ static const Int h = 2;
+ static const Int r = 4; // ratio
+ static const Color mainColor = GameMakeColor(0, 255, 0, 255);
+ static const Color dropColor = GameMakeColor(0, 0, 0, 255);
+ TheDisplay->drawFillRect( anchor->x-w*r-1, anchor->y-h-1, w*2*r+3, h*2+3, dropColor );
+ TheDisplay->drawFillRect( anchor->x-w-1, anchor->y-h*r-1, w*2+3, h*2*r+3, dropColor );
+ TheDisplay->drawFillRect( anchor->x-w*r, anchor->y-h, w*2*r+1, h*2+1, mainColor );
+ TheDisplay->drawFillRect( anchor->x-w, anchor->y-h*r, w*2+1, h*2*r+1, mainColor );
+ }
+ }
//draw superweapon ready multipliers
TheControlBar->drawSpecialPowerShortcutMultiplierText();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 75cc0bfab..42fae4d8d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -3890,9 +3890,17 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
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 );
+ if( TheInGameUI->isFormationDragging() )
+ {
+ // once it is a drag, every position message is a point on the curve
+ TheInGameUI->addFormationDragPoint( here );
+ }
+ else if( (UnsignedInt)abs( here.x - m_mouseRightDragAnchor.x ) > TheMouse->m_dragTolerance
+ || (UnsignedInt)abs( here.y - m_mouseRightDragAnchor.y ) > TheMouse->m_dragTolerance )
+ {
+ TheInGameUI->addFormationDragPoint( m_mouseRightDragAnchor );
+ TheInGameUI->addFormationDragPoint( here );
+ }
}
break;
@@ -3909,20 +3917,26 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
{
const Bool wasDrag = TheInGameUI->isFormationDragging();
+ if( wasDrag )
+ TheInGameUI->addFormationDragPoint( m_mouseRightDragLift );
+
+ // copied out before the drag is cleared, which throws the curve away
+ std::vector<ICoord2D> curve = TheInGameUI->getFormationDragPoints();
+
TheInGameUI->clearFormationDrag();
m_formationDragArmed = FALSE;
- if( wasDrag )
+ if( wasDrag && curve.size() >= 2 )
{
- // 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 );
-
+ // 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 );
- newMsg->appendLocationArgument( from );
- newMsg->appendLocationArgument( to );
+ for( std::vector<ICoord2D>::const_iterator it = curve.begin(); it != curve.end(); ++it )
+ {
+ Coord3D world;
+ TheTacticalView->screenToTerrain( &(*it), &world );
+ newMsg->appendLocationArgument( world );
+ }
TheInGameUI->clearAttackMoveToMode();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
index 2b9028244..a7cf0767d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
@@ -137,6 +137,15 @@ LookAtTranslator::~LookAtTranslator()
TheLookAtTranslator = NULL;
}
+const ICoord2D* LookAtTranslator::getScrollAnchor(void)
+{
+ if (m_isScrolling && m_scrollType == SCROLL_MMB)
+ {
+ return &m_anchor;
+ }
+ return NULL;
+}
+
Bool LookAtTranslator::hasMouseMovedRecently( void )
{
if (m_lastMouseMoveFrame > TheGameLogic->getFrame())
@@ -513,11 +522,35 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
{
case SCROLL_MMB:
{
- // straight drag-the-world pan: no anchor chasing and no keyboard minimum,
- // so the map follows the cursor one-to-one.
- offset.x = -TheGlobalData->m_horizontalScrollSpeedFactor * (m_currentPos.x - m_anchor.x);
- offset.y = -TheGlobalData->m_verticalScrollSpeedFactor * (m_currentPos.y - m_anchor.y);
- m_anchor = m_currentPos;
+ // The anchor stays where the button went down and the camera runs away from it,
+ // faster the further the cursor gets. This is what the right button used to do,
+ // and it is what the hand expects; a one-to-one drag of the world is not the same
+ // gesture and reads as sluggish at these scroll factors.
+ if (TheInGameUI->shouldMoveScrollAnchor())
+ {
+ Int maxX = TheDisplay->getWidth()/2;
+ Int maxY = TheDisplay->getHeight()/2;
+
+ if (m_currentPos.x + maxX < m_anchor.x)
+ m_anchor.x = m_currentPos.x + maxX;
+ else if (m_currentPos.x - maxX > m_anchor.x)
+ m_anchor.x = m_currentPos.x - maxX;
+
+ if (m_currentPos.y + maxY < m_anchor.y)
+ m_anchor.y = m_currentPos.y + maxY;
+ else if (m_currentPos.y - maxY > m_anchor.y)
+ m_anchor.y = m_currentPos.y - maxY;
+ }
+
+ offset.x = TheGlobalData->m_horizontalScrollSpeedFactor * (m_currentPos.x - m_anchor.x);
+ offset.y = TheGlobalData->m_verticalScrollSpeedFactor * (m_currentPos.y - m_anchor.y);
+ Coord2D vec;
+ vec.x = offset.x;
+ vec.y = offset.y;
+ vec.normalize();
+ // Add in the window scroll amount as the minimum.
+ offset.x += TheGlobalData->m_horizontalScrollSpeedFactor * vec.x * sqr(TheGlobalData->m_keyboardScrollFactor);
+ offset.y += TheGlobalData->m_verticalScrollSpeedFactor * vec.y * sqr(TheGlobalData->m_keyboardScrollFactor);
}
break;
case SCROLL_KEY:
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
index 21afee1d1..8e3cdcee2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
@@ -236,6 +236,16 @@ GameMessageDisposition WindowTranslator::translateGameMessage(const GameMessage
{
// all window events have the position of the mouse as arg 0
ICoord2D mousePos = msg->getArgument( 0 )->pixel;
+
+ // A formation line owns the mouse until the button comes back up. Without this the
+ // window under the cursor eats the moves and the release, so a line dragged over the
+ // command bar freezes there and never lets go.
+ if( TheInGameUI && TheInGameUI->isFormationDragging()
+ && ( msg->getType() == GameMessage::MSG_RAW_MOUSE_POSITION
+ || msg->getType() == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP ) )
+ {
+ forceKeepMessage = TRUE;
+ }
#if defined(_DEBUG) || defined(_INTERNAL) //debug hack to view object under mouse stats
TheMousePos.x = mousePos.x;
TheMousePos.y = mousePos.y;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index f7a8939b2..1f7bd0756 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -260,6 +260,63 @@ 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
@@ -976,16 +1033,22 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
// 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.
+ // the message is the drawn curve 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;
+ // the curve the cursor traced, however many corners the player's hand put in it
+ std::vector<Coord3D> path;
+ const Int pointCount = msg->getArgumentCount();
+ for (Int p = 0; p < pointCount; p++)
+ path.push_back( msg->getArgument( p )->location );
+
+ if (path.size() < 2)
+ break;
+
std::vector<Object *> movers;
const VecObjectID& ids = currentlySelectedGroup->getAllIDs();
for (VecObjectID::const_iterator it = ids.begin(); it != ids.end(); ++it)
@@ -1001,30 +1064,37 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
if (movers.empty())
break;
- Coord2D along;
- along.x = to.x - from.x;
- along.y = to.y - from.y;
- const Real span = along.length();
+ // 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 size
+ std::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 ) );
+ }
+
+ const Real span = arc.back();
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
+ // 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 = (held->getPosition()->x - from.x) * along.x +
- (held->getPosition()->y - from.y) * along.y;
+ const Real heldKey = distanceAlongPath( path, arc,
+ held->getPosition()->x, held->getPosition()->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;
+ 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 ];
@@ -1038,12 +1108,11 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
const Int count = movers.size();
for (Int i = 0; i < count; i++)
{
- // one unit stands where the line ends, everyone else divides it evenly
+ // one unit stands where the curve 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;
+ pointAlongPath( path, arc, span * t, &station );
station.z = TheTerrainLogic->getGroundHeight( station.x, station.y );
movers[ i ]->getAIUpdateInterface()->aiMoveToPosition( &station, CMD_FROM_PLAYER );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index 9b568cb3a..551e4580f 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -782,29 +782,48 @@ void W3DInGameUI::drawFormationLine( void )
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;
+ const 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( m_formationDragAnchor.x, m_formationDragAnchor.y,
- m_formationDragCurrent.x, m_formationDragCurrent.y,
- width, color );
+ TheDisplay->drawLine( curve[ i - 1 ].x, curve[ i - 1 ].y, curve[ i ].x, curve[ i ].y,
+ width, color );
+ }
const Int count = getSelectCount();
- const Real span = sqrtf( (bx - ax) * (bx - ax) + (by - ay) * (by - ay) );
+ const Real span = arc[ points - 1 ];
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;
-
+ Int seg = 1;
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;
+ 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 ),