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.

feat(gameengine): shift-drag lays a row of structures, no build without a selected worker

Olcay Seyganb402154ad93d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 646edb40f..6699adb62 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -555,7 +555,8 @@ found and fixed — EA's own, not port damage.**
- Unbuildable ground is a soft red wash, crossed out square by square.
- Running out of money no longer strands the ghost on the map.
- Holding shift and clicking out a row of buildings no longer stops halfway and selects one.
-- That row keeps going with no worker selected, too, instead of ending after the first building.
+- Hold shift and drag, and the row is one stroke. Press where the first building goes, drag the way the row runs, and a ghost appears for every building that fits end to end along the line, all facing the way the first one was turned. The row goes straight or on the diagonal, flush on the build grid, and stops at the last building your bank can pay for. A ghost that lands on a rock or someone's tank turns red and is left out when you let go; the rest go up. With two or three workers selected the buildings are shared out to the nearest free one, and the ones nobody is free for wait as plans until a worker comes off its job. A plain drag still turns the building, and walls still tile the way they always did.
+- Buildings need a worker selected. With nothing selected the command bar used to borrow one of your dozers and offer its buildings anyway. It stays empty now until you pick a worker, and a replay recorded with a building placed that way plays back without it.
- Turning a building no longer turns everything you build afterwards. A wheeled heading still carries from one wall to the next, but the next supply centre comes out facing the way it was designed to.
- A building you point at blocked ground slides to the nearest spot it fits, and lands there.
- The pointer keeps its build cursor while you place, even passing over your own buildings.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index c3e83559c..6156134b0 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -1206,8 +1206,6 @@ public:
// get method for list of commandbuttons
const CommandButton *getCommandButtons( void ) { return m_commandButtons; }
- Drawable *findStandInBuilder( Bool freeOnly ); ///< the local player's free builder (or, unless freeOnly, any builder) to stand in for an empty selection
-
protected:
ICoord2D m_defaultControlBarPosition; ///< Stored the original position of the control bar on the screen
@@ -1307,7 +1305,6 @@ protected:
Int m_chordGroup; ///< -1, or the structure group (0 = Q, 1 = W) armed by the first chord key
UnsignedInt m_chordStartMs; ///< millisecond the chord was armed on, for CHORD_TIMEOUT_MS
DrawableID m_chordDrawableID; ///< builder the armed chord addresses; the chord dies if the bar moves to another one
- DrawableID m_standInBuilderID; ///< with nothing selected, the builder whose command bar is shown (INVALID_DRAWABLE_ID otherwise)
/** A player upgrade is researched once, so it goes to exactly one of the selected buildings -
* and the bar cannot see the queue an earlier click in this same frame just filled, because
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 2c67ed78f..1fdfc1421 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -641,6 +641,48 @@ public: // ********************************************************************
return ((Real)REAL_TO_INT_FLOOR( (v - offset) / cell + 0.5f )) * cell + offset;
}
+
+ /** A shift-dragged row: the step from one structure to the next, and how many fit between the
+ * anchor and a cursor 'dx'/'dy' away. The row runs along the nearest eighth of a turn - a
+ * component counts once it is more than tan 22.5 degrees of the other - and a step is the
+ * footprint's whole size, 'sizeX'/'sizeY' with the bib, along each axis it moves on, so
+ * neighbours stand flush. On the build grid that size goes up to whole cells, which keeps every
+ * piece on the grid the first one was snapped to. Never fewer than one, never more than
+ * 'most'. Inline and static so a test can reach it without linking the whole in-game UI. */
+ static Int placementRow( Real dx, Real dy, Real sizeX, Real sizeY, Bool grid, Int most,
+ Coord2D *step )
+ {
+ const Real slope = 0.41421356f; // tan 22.5 degrees
+ const Real cell = (Real)PLACEMENT_CELL;
+ const Real slack = 0.01f; // Cos of a quarter turn is a hair off zero, not a cell's worth
+
+ if( grid )
+ {
+ sizeX = (Real)REAL_TO_INT_CEIL( sizeX / cell - slack ) * cell;
+ sizeY = (Real)REAL_TO_INT_CEIL( sizeY / cell - slack ) * cell;
+ }
+
+ step->x = fabs( dx ) > fabs( dy ) * slope ? ( dx < 0.0f ? -sizeX : sizeX ) : 0.0f;
+ step->y = fabs( dy ) > fabs( dx ) * slope ? ( dy < 0.0f ? -sizeY : sizeY ) : 0.0f;
+
+ Int count = 1;
+ const Real stepSqr = step->x * step->x + step->y * step->y;
+ if( stepSqr > 0.0f )
+ count += REAL_TO_INT_FLOOR( ( dx * step->x + dy * step->y ) / stepSqr );
+
+ if( count > most )
+ count = most;
+ if( count < 1 )
+ count = 1;
+ return count;
+ }
+
+ /// would dragging the anchor lay a row of the pending structure, rather than aim one?
+ Bool placesRow( void );
+ /// the centres of that row from 'start' toward 'end', as many as MaxLineBuildObjects and the money allow
+ void computePlacementRow( const ThingTemplate *what, Real angle, const Coord3D *start,
+ const Coord3D *end, std::vector<Coord3D> *positions ) const;
+
/** NudgeBuildPlacement: when the spot under the cursor is blocked, slide the structure to the
* nearest one it does fit and show it there, so the ghost answers "here, then" instead of just
* going red. Moves 'world' and returns TRUE if it found somewhere; leaves it alone otherwise. */
@@ -662,7 +704,7 @@ public: // ********************************************************************
// It is a client-side courtesy, not the rule: the rule is re-asked on the logic side, where the
// first structure really does exist by the time the second order arrives.
//
- enum { PENDING_PLACEMENTS = 8 }; ///< orders in flight at once; the oldest is overwritten
+ enum { PENDING_PLACEMENTS = 64 }; ///< orders in flight at once, a whole shift-dragged row among them; the oldest is overwritten
enum { PENDING_PLACEMENT_FRAMES = 60 }; ///< logic frames one is remembered for - two seconds,
/// comfortably longer than any network delay
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 533338949..c68cbcc4e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -61,8 +61,6 @@
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/DozerAIUpdate.h"
#include "GameLogic/Module/SupplyTruckAIUpdate.h"
-
-static Bool builderIsFree( AIUpdateInterface *ai, DozerAIInterface *dozer ); // defined with findStandInBuilder
#include "GameLogic/Module/ProductionUpdate.h"
#include "GameLogic/Module/OCLUpdate.h"
#include "GameLogic/Module/ContainModule.h"
@@ -1351,7 +1349,6 @@ ControlBar::ControlBar( void )
m_chordGroup = -1;
m_chordStartMs = 0;
m_chordDrawableID = INVALID_DRAWABLE_ID;
- m_standInBuilderID = INVALID_DRAWABLE_ID;
m_upgradeSpreadFrame = 0;
m_upgradeSpreadEntries = 0;
for( i = 0; i < UPGRADE_SPREAD_MAX; i++ )
@@ -3278,22 +3275,6 @@ void ControlBar::update( void )
else
clearPurchaseScienceColumn();
- //
- // a stand-in builder is not selected, so no deselect event tells us when it dies or when a
- // real selection arrives; re-evaluate ourselves before anything touches its drawable
- //
- if( m_standInBuilderID != INVALID_DRAWABLE_ID )
- {
- Drawable *standIn = TheGameClient->findDrawableByID( m_standInBuilderID );
- Object *standInObj = standIn ? standIn->getObject() : NULL;
- if( TheInGameUI->getSelectCount() > 0 || standInObj == NULL || standInObj->isEffectivelyDead() )
- {
- m_standInBuilderID = INVALID_DRAWABLE_ID;
- m_currentSelectedDrawable = NULL;
- markUIDirty();
- }
- }
-
//
// first, if the UI is dirty repopulate the UI with what the user should see for all the
// selected drawables
@@ -3558,23 +3539,6 @@ void ControlBar::evaluateContextUI( void )
// erase any current state of the GUI by switching out to the empty context
switchToContext( CB_CONTEXT_NONE, NULL );
- //
- // nothing selected: one of the player's builders stands in and its command bar shows, so
- // a structure can be placed without selecting a dozer first - the logic then sends the
- // idle builder nearest the site (MSG_DOZER_CONSTRUCT). m_standInBuilderID is not cleared
- // first: findStandInBuilder reads it to keep the builder it is already showing.
- //
- if( TheInGameUI->getSelectCount() == 0 )
- {
- Drawable *builder = findStandInBuilder( FALSE );
- m_standInBuilderID = builder ? builder->getID() : INVALID_DRAWABLE_ID;
- if( builder )
- switchToContext( CB_CONTEXT_COMMAND, builder );
- return;
- }
-
- m_standInBuilderID = INVALID_DRAWABLE_ID;
-
// get the list of drawable IDs from the in game UI
const DrawableList *selectedDrawables = TheInGameUI->getAllSelectedDrawables();
@@ -4094,83 +4058,6 @@ Bool ControlBar::cancelLastQueuedUnit( const ThingTemplate *thing )
} // end cancelLastQueuedUnit
-//-------------------------------------------------------------------------------------------------
-/** The local player's builder that stands in for an empty selection: an idle one if there is
- * one, else any live one. (Player::iterateObjects callback + driver.) */
-//-------------------------------------------------------------------------------------------------
-struct StandInBuilderSearch
-{
- Object *idle;
- Object *any;
-};
-
-/** a builder is free for a job when it has no build/repair task and is not hauling supplies -
- walking somewhere on a plain move order does not make it busy */
-static Bool builderIsFree( AIUpdateInterface *ai, DozerAIInterface *dozer )
-{
- if( dozer->isAnyTaskPending() )
- return FALSE;
- const SupplyTruckAIInterface *supply = ai->getSupplyTruckAIInterface();
- if( supply && supply->isCurrentlyFerryingSupplies() )
- return FALSE;
- return TRUE;
-}
-
-static void findStandInBuilderProc( Object *obj, void *userData )
-{
- StandInBuilderSearch *s = (StandInBuilderSearch *)userData;
- if( obj == NULL || obj->isEffectivelyDead() || obj->getDrawable() == NULL )
- return;
- if( obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) || obj->testStatus( OBJECT_STATUS_SOLD ) )
- return;
- AIUpdateInterface *ai = obj->getAI();
- DozerAIInterface *dozer = ai ? ai->getDozerAIInterface() : NULL;
- if( dozer == NULL )
- return;
- if( s->any == NULL )
- s->any = obj;
- if( s->idle == NULL && builderIsFree( ai, dozer ) )
- s->idle = obj;
-}
-
-Drawable *ControlBar::findStandInBuilder( Bool freeOnly )
-{
- Player *player = ThePlayerList ? ThePlayerList->getLocalPlayer() : NULL;
- if( player == NULL )
- return NULL;
-
- //
- // The builder already standing in keeps the bar for as long as it is still a builder. The
- // sweep below answers "the first idle one", and idleness changes on its own: a dozer somewhere
- // across the base finishing a building goes idle and used to take the bar off the one you were
- // working with. That drops a half-typed chord and takes the structure off your cursor, in the
- // middle of placing it, because something happened somewhere else.
- //
- if( m_standInBuilderID != INVALID_DRAWABLE_ID && TheGameClient )
- {
- Drawable *held = TheGameClient->findDrawableByID( m_standInBuilderID );
- Object *obj = held ? held->getObject() : NULL;
- if( obj && obj->getControllingPlayer() == player )
- {
- StandInBuilderSearch check;
- check.idle = NULL;
- check.any = NULL;
- findStandInBuilderProc( obj, &check );
- if( check.any && ( !freeOnly || check.idle ) )
- return held;
- }
- }
-
- StandInBuilderSearch s;
- s.idle = NULL;
- s.any = NULL;
- player->iterateObjects( findStandInBuilderProc, &s );
-
- Object *pick = s.idle ? s.idle : ( freeOnly ? NULL : s.any );
- return pick ? pick->getDrawable() : NULL;
-
-} // end findStandInBuilder
-
//-------------------------------------------------------------------------------------------------
/** Press the index'th general's power shortcut button, as a mouse click would */
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 08501a072..c151a8cee 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -3390,18 +3390,22 @@ void InGameUI::handleBuildPlacements( void )
// update the angle of the icon to match any placement angle and pick the
// location the icon will be at (anchored is the start, otherwise it's the mouse)
+ Bool row = FALSE;
if( isPlacementAnchored() )
{
ICoord2D start, end;
-
- // get the placement arrow points
+
+ // get the placement arrow points
getPlacementPoints( &start, &end );
// set icon to anchor point
loc = start;
- // only adjust angle if we've actually moved the mouse
- if( start.x != end.x || start.y != end.y )
+ // only adjust angle if we've actually moved the mouse, and not into a row: that drag
+ // lays structures, the heading stays the one they had
+ const Bool dragged = start.x != end.x || start.y != end.y;
+ row = dragged && placesRow();
+ if( dragged && !row )
angle = computePlacementAngle( &start, &end );
} // end if
@@ -3430,6 +3434,11 @@ void InGameUI::handleBuildPlacements( void )
// walk away from the mouse; the ghost is at most one frame behind it.
//
const Coord3D cursorWorld = world;
+
+ // a row starts where it was anchored; each piece is judged where it stands, not nudged
+ if( row )
+ m_placementNudge.zero();
+
if( m_placementNudge.x != 0.0f || m_placementNudge.y != 0.0f )
{
world.x += m_placementNudge.x;
@@ -3449,7 +3458,7 @@ void InGameUI::handleBuildPlacements( void )
// delay time between checks or we need to come up with a way of recording what is
// valid and what isn't or "fudge" the results to feel "ok"
//
- if( TheGameClient->getFrame() & 0x1 )
+ if( ( TheGameClient->getFrame() & 0x1 ) && !row )
{
TheTerrainVisual->removeAllBibs();
@@ -3526,10 +3535,13 @@ void InGameUI::handleBuildPlacements( void )
//
// we have additional place icons when we're placing down a line of walls or other
- // similarly placed object ... for those we will have them be oriented the same way
- // as the first one, but we'll set their positions so that they "tile" end to end
+ // similarly placed object, or a shift-dragged row of structures ... for those we will
+ // have them be oriented the same way as the first one, but we'll set their positions so
+ // that they "tile" end to end
//
- if( isPlacementAnchored() && TheBuildAssistant->isLineBuildTemplate( m_pendingPlaceType ) )
+ const Bool lineBuild = isPlacementAnchored() && TheBuildAssistant->isLineBuildTemplate( m_pendingPlaceType );
+ Int iconsUsed = 1;
+ if( lineBuild || row )
{
Int i;
@@ -3550,29 +3562,40 @@ void InGameUI::handleBuildPlacements( void )
snapPlacementToGrid( &worldStart, m_pendingPlaceType, angle );
snapPlacementToGrid( &worldEnd, m_pendingPlaceType, angle );
- // how big are each of our objects
- Real objectSize = m_pendingPlaceType->getTemplateGeometryInfo().getMajorRadius() * 2.0f;
-
- // what is our max tiling length we can make
- Int maxObjects = TheGlobalData->m_maxLineBuildObjects;
-
// get the builder object that will be constructing things
Object *builderObject = TheGameLogic->findObjectByID( TheInGameUI->getPendingPlaceSourceObjectID() );
- //
- // given the start/end points in the world and the the angle of the wall, fill
- // out an array of positions that "tile" this wall across the landscape
- //
- BuildAssistant::TileBuildInfo *tileBuildInfo;
- tileBuildInfo = TheBuildAssistant->buildTiledLocations( m_pendingPlaceType, angle,
- &worldStart, &worldEnd,
- objectSize, maxObjects,
- builderObject );
+ const Coord3D *positions;
+ std::vector<Coord3D> rowPositions;
+ if( lineBuild )
+ {
+ // how big are each of our objects
+ Real objectSize = m_pendingPlaceType->getTemplateGeometryInfo().getMajorRadius() * 2.0f;
+
+ //
+ // given the start/end points in the world and the the angle of the wall, fill
+ // out an array of positions that "tile" this wall across the landscape
+ //
+ BuildAssistant::TileBuildInfo *tileBuildInfo;
+ tileBuildInfo = TheBuildAssistant->buildTiledLocations( m_pendingPlaceType, angle,
+ &worldStart, &worldEnd,
+ objectSize,
+ TheGlobalData->m_maxLineBuildObjects,
+ builderObject );
+ positions = tileBuildInfo->positions;
+ iconsUsed = tileBuildInfo->tilesUsed;
+ }
+ else
+ {
+ computePlacementRow( m_pendingPlaceType, angle, &worldStart, &worldEnd, &rowPositions );
+ positions = &rowPositions[ 0 ];
+ iconsUsed = (Int)rowPositions.size();
+ }
// create any necessary drawables we need to "fill out" the line
- for( i = 0; i < tileBuildInfo->tilesUsed; i++ )
+ for( i = 0; i < iconsUsed; i++ )
{
-
+
if( m_placeIcon[ i ] == NULL )
m_placeIcon[ i ] = TheThingFactory->newDrawable( m_pendingPlaceType,
DRAWABLE_STATUS_NO_STATE_PARTICLES );
@@ -3580,27 +3603,25 @@ void InGameUI::handleBuildPlacements( void )
} // end for i
//
- // destroy any drawables that we're not using anymore because a previous
- // line length was longer
+ // A row is judged piece by piece, on the frames the single ghost would have been: red
+ // where the click will leave a gap, and the cursor says yes while any piece can go up.
//
- for( i = tileBuildInfo->tilesUsed; i < maxObjects; i++ )
+ const Bool judgeRow = row && ( TheGameClient->getFrame() & 0x1 );
+ if( judgeRow )
{
-
- if( m_placeIcon[ i ] != NULL )
- TheGameClient->destroyDrawable( m_placeIcon[ i ] );
- m_placeIcon[ i ] = NULL;
-
- } // end for i
+ TheTerrainVisual->removeAllBibs();
+ m_placementLegal = FALSE;
+ }
//
// march down each drawable and set the position based on its position in the
// line and set their angles all the same
//
- for( i = 0; i < tileBuildInfo->tilesUsed; i++ )
+ for( i = 0; i < iconsUsed; i++ )
{
// set the drawble position
- m_placeIcon[ i ]->setPosition( &tileBuildInfo->positions[ i ] );
+ m_placeIcon[ i ]->setPosition( &positions[ i ] );
// set opacity and shadowing for the drawble
dressPlacementPreview( m_placeIcon[ i ] );
@@ -3608,10 +3629,35 @@ void InGameUI::handleBuildPlacements( void )
// set the drawable angle
m_placeIcon[ i ]->setOrientation( angle );
+ if( judgeRow )
+ {
+ const Bool legal =
+ TheBuildAssistant->isLocationLegalToBuild( &positions[ i ], m_pendingPlaceType, angle,
+ placementCheckOptions(), builderObject,
+ NULL ) == LBC_OK &&
+ !overlapsPendingPlacement( &positions[ i ], m_pendingPlaceType, angle );
+ m_placeIcon[ i ]->colorTint( legal ? NULL : &illegalBuildColor );
+ if( legal )
+ m_placementLegal = TRUE;
+ }
+
} // end for i
} // end if
+ //
+ // destroy any drawables that we're not using anymore because a previous line length was
+ // longer, or the row was let go of
+ //
+ for( Int i = iconsUsed; i < TheGlobalData->m_maxLineBuildObjects; i++ )
+ {
+
+ if( m_placeIcon[ i ] != NULL )
+ TheGameClient->destroyDrawable( m_placeIcon[ i ] );
+ m_placeIcon[ i ] = NULL;
+
+ } // end for i
+
} // end if
} // end handleBuildPlacements
@@ -6847,11 +6893,8 @@ Real InGameUI::computePlacementAngle( const ICoord2D *start, const ICoord2D *end
* box is major along its facing and minor across it, and anything round is its bounding circle.
* At 45 degrees the axis-aligned extents grow, which is right - that is the ground it covers. */
//-------------------------------------------------------------------------------------------------
-void InGameUI::snapPlacementToGrid( Coord3D *world, const ThingTemplate *what, Real angle ) const
+static void placementHalfExtents( const ThingTemplate *what, Real angle, Real *halfX, Real *halfY )
{
- if( world == NULL || what == NULL || TheGlobalData->m_gridBuildPlacement == FALSE )
- return;
-
const GeometryInfo &geom = what->getTemplateGeometryInfo();
Real major = geom.getMajorRadius();
Real minor = geom.getMinorRadius();
@@ -6869,11 +6912,70 @@ void InGameUI::snapPlacementToGrid( Coord3D *world, const ThingTemplate *what, R
const Real c = (Real)fabs( Cos( angle ) );
const Real sn = (Real)fabs( Sin( angle ) );
- world->x = snapPlacementAxis( world->x, major * c + minor * sn );
- world->y = snapPlacementAxis( world->y, major * sn + minor * c );
+ *halfX = major * c + minor * sn;
+ *halfY = major * sn + minor * c;
+}
+
+void InGameUI::snapPlacementToGrid( Coord3D *world, const ThingTemplate *what, Real angle ) const
+{
+ if( world == NULL || what == NULL || TheGlobalData->m_gridBuildPlacement == FALSE )
+ return;
+
+ Real halfX, halfY;
+ placementHalfExtents( what, angle, &halfX, &halfY );
+
+ world->x = snapPlacementAxis( world->x, halfX );
+ world->y = snapPlacementAxis( world->y, halfY );
} // end snapPlacementToGrid
+//-------------------------------------------------------------------------------------------------
+/** Shift held on the drag: a wall already tiles from any drag, so it is left to do that. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::placesRow( void )
+{
+ return m_pendingPlaceType != NULL && TheKeyboard && TheKeyboard->isShift() &&
+ !TheBuildAssistant->isLineBuildTemplate( m_pendingPlaceType );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Every piece faces 'angle', the heading on the ghost before the drag began: the drag is spent on
+ * the row, so it cannot aim as well. The row stops where the money does, which is what the logic
+ * would do to the orders past it anyway (canMakeUnit per MSG_DOZER_CONSTRUCT); the player sees the
+ * row that will go up. Legality is not asked here - the ghost and the click each ask it per piece. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::computePlacementRow( const ThingTemplate *what, Real angle, const Coord3D *start,
+ const Coord3D *end, std::vector<Coord3D> *positions ) const
+{
+ Real halfX, halfY;
+ placementHalfExtents( what, angle, &halfX, &halfY );
+
+ Int most = TheGlobalData->m_maxLineBuildObjects;
+ Player *player = ThePlayerList->getLocalPlayer();
+ const Int cost = what->calcCostToBuild( player );
+ if( cost > 0 )
+ {
+ const Int affordable = (Int)( player->getMoney()->countMoney() / cost );
+ if( affordable < most )
+ most = affordable;
+ }
+
+ Coord2D step;
+ const Int count = placementRow( end->x - start->x, end->y - start->y, 2.0f * halfX, 2.0f * halfY,
+ TheGlobalData->m_gridBuildPlacement, most, &step );
+
+ positions->clear();
+ for( Int i = 0; i < count; i++ )
+ {
+ Coord3D pos;
+ pos.x = start->x + step.x * i;
+ pos.y = start->y + step.y * i;
+ pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y );
+ positions->push_back( pos );
+ }
+
+} // end computePlacementRow
+
//-------------------------------------------------------------------------------------------------
/** The legality question asked of the spot under the ghost, in one place - the nudge search asks it
* of every candidate too. IGNORE_STEALTHED is deliberate: a structure you cannot put down is a
@@ -6916,7 +7018,7 @@ Bool InGameUI::footprintsOverlap( const Region2D *a, const Region2D *b )
//-------------------------------------------------------------------------------------------------
/** Remember a structure just ordered, so the click after it knows the ground is spoken for. Round
- * a ring: the oldest of the eight goes, which is the one most likely to be standing by now. */
+ * a ring: the oldest goes, which is the one most likely to be standing by now. */
//-------------------------------------------------------------------------------------------------
void InGameUI::recordPendingPlacement( const ThingTemplate *what, const Coord3D *world, Real angle )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
index 2a8853246..5b016fe61 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
@@ -89,12 +89,7 @@ static Bool getPlacementDrag( ICoord2D *start, ICoord2D *end )
} // end getPlacementDrag
//-------------------------------------------------------------------------------------------------
-/** The object that is to do the building. Normally the one the placement was started from, but
- * with nothing selected the command bar is being driven by a stand-in builder that is not part of
- * any selection - and that one is free to die, finish its job or be replaced between two clicks of
- * a shift-held run of structures. When it is gone, ask the command bar for the current stand-in
- * rather than dropping out of placement mode: the logic picks the idle builder nearest the site
- * anyway (MSG_DOZER_CONSTRUCT), so any builder will do to keep the ghost on the cursor. */
+/** The object that is to do the building: the one the placement was started from, while it lives. */
//-------------------------------------------------------------------------------------------------
static Object *resolvePlacementBuilder( void )
{
@@ -102,8 +97,7 @@ static Object *resolvePlacementBuilder( void )
if( builder != NULL && !builder->isEffectivelyDead() )
return builder;
- Drawable *standIn = TheControlBar ? TheControlBar->findStandInBuilder( FALSE ) : NULL;
- return standIn ? standIn->getObject() : NULL;
+ return NULL;
}
//-------------------------------------------------------------------------------------------------
@@ -294,10 +288,13 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess
// the message stream is propagated and off an anchor end that is itself a frame
// behind, so a quick drag-and-release used to build the structure facing two frames
// of mouse travel back. A press that never left the anchor is not aiming at
- // anything, so that one keeps the heading already on the ghost.
+ // anything, so that one keeps the heading already on the ghost, and neither does a
+ // shift-drag, which lays a row (see InGameUI::placesRow).
//
angle = TheInGameUI->getPlacementAngle();
- if( getPlacementDrag( &anchorStart, &anchorEnd ) )
+ const Bool dragged = getPlacementDrag( &anchorStart, &anchorEnd );
+ const Bool row = dragged && TheInGameUI->placesRow();
+ if( dragged && !row )
{
angle = TheInGameUI->computePlacementAngle( &anchorStart, &anchorEnd );
@@ -369,25 +366,64 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess
const UnsignedInt placeOptions = InGameUI::placementCheckOptions() |
BuildAssistant::FAIL_STEALTHED_WITHOUT_FEEDBACK;
LegalBuildCode lbc;
- lbc = TheBuildAssistant->isLocationLegalToBuild( &world, build, angle, placeOptions,
- builderObj, NULL );
+ std::vector<Coord3D> placements;
+ if( row )
+ {
+ //
+ // A shift-dragged row is one order per structure, each asked on its own: a piece
+ // that lands on a rock is left out and the rest still go up. The logic hands each
+ // order to the idle selected builder nearest it, and once they are all busy the rest
+ // stand at 0% for whichever comes free first (BuildAssistant::buildObjectNow).
+ //
+ Coord3D worldEnd;
+ TheTacticalView->screenToTerrain( &anchorEnd, &worldEnd );
+ TheInGameUI->snapPlacementToGrid( &worldEnd, build, angle );
- // plus the ground your own last click already spent - see recordPendingPlacement
- if( lbc == LBC_OK && TheInGameUI->overlapsPendingPlacement( &world, build, angle ) )
- lbc = LBC_OBJECTS_IN_THE_WAY;
+ std::vector<Coord3D> pieces;
+ TheInGameUI->computePlacementRow( build, angle, &world, &worldEnd, &pieces );
- //
- // NudgeBuildPlacement: blocked where they clicked, so build at the nearest spot that
- // is not - the same search the ghost was already showing them (InGameUI::update ->
- // handleBuildPlacements), so the structure goes down where they were looking. The
- // verdict is taken again at the new spot rather than assumed: this check is the
- // stricter one, it fails on a stealthed unit the ghost is told to ignore.
- //
- if( lbc != LBC_OK && lbc != LBC_SHROUD &&
- TheInGameUI->nudgePlacementToLegal( &world, build, angle, builderObj ) )
+ lbc = LBC_OK;
+ for( size_t i = 0; i < pieces.size(); i++ )
+ {
+ LegalBuildCode piece = TheBuildAssistant->isLocationLegalToBuild( &pieces[ i ], build, angle,
+ placeOptions, builderObj,
+ NULL );
+ if( piece == LBC_OK && TheInGameUI->overlapsPendingPlacement( &pieces[ i ], build, angle ) )
+ piece = LBC_OBJECTS_IN_THE_WAY;
+
+ if( piece == LBC_OK )
+ placements.push_back( pieces[ i ] );
+ else
+ lbc = piece;
+ }
+
+ // the row goes ahead on any piece that can; the reason is only for a row with none
+ if( !placements.empty() )
+ lbc = LBC_OK;
+ }
+ else
{
lbc = TheBuildAssistant->isLocationLegalToBuild( &world, build, angle, placeOptions,
builderObj, NULL );
+
+ // plus the ground your own last click already spent - see recordPendingPlacement
+ if( lbc == LBC_OK && TheInGameUI->overlapsPendingPlacement( &world, build, angle ) )
+ lbc = LBC_OBJECTS_IN_THE_WAY;
+
+ //
+ // NudgeBuildPlacement: blocked where they clicked, so build at the nearest spot that
+ // is not - the same search the ghost was already showing them (InGameUI::update ->
+ // handleBuildPlacements), so the structure goes down where they were looking. The
+ // verdict is taken again at the new spot rather than assumed: this check is the
+ // stricter one, it fails on a stealthed unit the ghost is told to ignore.
+ //
+ if( lbc != LBC_OK && lbc != LBC_SHROUD &&
+ TheInGameUI->nudgePlacementToLegal( &world, build, angle, builderObj ) )
+ {
+ lbc = TheBuildAssistant->isLocationLegalToBuild( &world, build, angle, placeOptions,
+ builderObj, NULL );
+ }
+ placements.push_back( world );
}
if( lbc == LBC_OK )
{
@@ -422,45 +458,43 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess
}
}
- // create the right kind of message
- if( isLineBuild )
- placeMsg = TheMessageStream->appendMessage( GameMessage::MSG_DOZER_CONSTRUCT_LINE );
- else
- placeMsg = TheMessageStream->appendMessage( GameMessage::MSG_DOZER_CONSTRUCT );
-
- placeMsg->appendIntegerArgument(build->getTemplateID());
- placeMsg->appendLocationArgument(world);
- placeMsg->appendRealArgument(angle);
- if( isLineBuild )
+ for( size_t i = 0; i < placements.size(); i++ )
{
- Coord3D worldEnd;
+ // create the right kind of message
+ if( isLineBuild )
+ placeMsg = TheMessageStream->appendMessage( GameMessage::MSG_DOZER_CONSTRUCT_LINE );
+ else
+ placeMsg = TheMessageStream->appendMessage( GameMessage::MSG_DOZER_CONSTRUCT );
+
+ placeMsg->appendIntegerArgument(build->getTemplateID());
+ placeMsg->appendLocationArgument(placements[ i ]);
+ placeMsg->appendRealArgument(angle);
+ if( isLineBuild )
+ {
+ Coord3D worldEnd;
- TheTacticalView->screenToTerrain( &anchorEnd, &worldEnd );
- TheInGameUI->snapPlacementToGrid( &worldEnd, build, angle );
- placeMsg->appendLocationArgument( worldEnd );
+ TheTacticalView->screenToTerrain( &anchorEnd, &worldEnd );
+ TheInGameUI->snapPlacementToGrid( &worldEnd, build, angle );
+ placeMsg->appendLocationArgument( worldEnd );
- } // end if
+ } // end if
- //
- // The order is on its way; the structure will not be on the ground for another
- // few frames, and on a network game that is however long the link takes. Hold on
- // to the spot so the next click in a shift-held run does not put a second
- // structure on top of this one.
- //
- TheInGameUI->recordPendingPlacement( build, &world, angle );
+ //
+ // The order is on its way; the structure will not be on the ground for another
+ // few frames, and on a network game that is however long the link takes. Hold on
+ // to the spot so the next click in a shift-held run does not put a second
+ // structure on top of this one.
+ //
+ TheInGameUI->recordPendingPlacement( build, &placements[ i ], angle );
+ }
pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), placeMsg->getType() );
//
// get out of pending placement mode, this will also clear the arrow anchor status -
// unless shift is held, which keeps placing the same structure until released.
- // The builder it re-arms on is whatever resolvePlacementBuilder found, so a run of
- // structures placed with nothing selected carries on across the stand-in builder
- // going off to build the one just ordered.
//
Drawable *nextBuilder = builderObj ? builderObj->getDrawable() : NULL;
- if( TheKeyboard && TheKeyboard->isShift() && nextBuilder == NULL && TheControlBar )
- nextBuilder = TheControlBar->findStandInBuilder( FALSE );
if( TheKeyboard && TheKeyboard->isShift() && nextBuilder )
TheInGameUI->placeBuildAvailable( build, nextBuilder );
else
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index 6056f6bdb..b1ed47712 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -68,8 +68,7 @@
//-------------------------------------------------------------------------------------------------
/** Which builder takes a structure job: the free one nearest the site, or failing that the
* nearest one at all. Free = no build/repair task and not hauling supplies; a builder that
- * is merely walking somewhere counts. Fed from the selection, or from every builder of the
- * player when nothing is selected (the control bar's stand-in builder context). */
+ * is merely walking somewhere counts. Fed from the selection. */
//-------------------------------------------------------------------------------------------------
struct BuilderPick
{
@@ -107,11 +106,6 @@ static void considerBuilder( Object *candidate, BuilderPick *pick )
pick->idleDistSqr = distSqr;
}
}
-
-static void considerBuilderProc( Object *obj, void *userData )
-{
- considerBuilder( obj, (BuilderPick *)userData );
-}
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/OpenContain.h"
#include "GameLogic/Module/ProductionUpdate.h"
@@ -1620,10 +1614,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
// bar now sends one message per building it wants it on, so the group-wide path must
// not fire for those either - it would queue N messages on N buildings each.
// The named object is authorized by the ownership check below and the revalidation
- // after it, not by being in the selection: the bar also sends this from the stand-in
- // builder's bar, where nothing is selected at all - which is where the GLA worker's
- // fake-buildings toggle lives, so requiring a selection left the worker stuck on
- // whichever page it was last put on.
+ // after it, not by being in the selection.
//
Object *producer = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
@@ -1773,34 +1764,26 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
Real angle;
// get player, what to place, and location
- Object *constructorObject = getSingleObjectFromSelection(currentlySelectedGroup);
place = TheThingFactory->findByTemplateID( msg->getArgument( 0 )->integer );
loc = msg->getArgument( 1 )->location;
angle = msg->getArgument( 2 )->real;
//
- // the job goes to the idle builder nearest the site - among the selected builders,
- // or, with nothing selected (stand-in builder command bar), among all the player's
- // builders. A builder already on a job is only taken when no idle one exists.
+ // the job goes to the idle selected builder nearest the site. A builder already on a
+ // job is only taken when no idle one is selected, and with no builder selected at all
+ // nothing is built.
//
+ BuilderPick pick;
+ pick.loc = loc;
+ pick.idle = pick.any = NULL;
+ pick.idleDistSqr = pick.anyDistSqr = 1e30f;
+ if( currentlySelectedGroup )
{
- BuilderPick pick;
- pick.loc = loc;
- pick.idle = pick.any = NULL;
- pick.idleDistSqr = pick.anyDistSqr = 1e30f;
- if( currentlySelectedGroup )
- {
- const VecObjectID& ids = currentlySelectedGroup->getAllIDs();
- for( VecObjectID::const_iterator it = ids.begin(); it != ids.end(); ++it )
- considerBuilder( TheGameLogic->findObjectByID( *it ), &pick );
- }
- if( pick.any == NULL && thisPlayer )
- thisPlayer->iterateObjects( considerBuilderProc, &pick );
-
- Object *chosen = pick.idle ? pick.idle : pick.any;
- if( chosen )
- constructorObject = chosen;
+ const VecObjectID& ids = currentlySelectedGroup->getAllIDs();
+ for( VecObjectID::const_iterator it = ids.begin(); it != ids.end(); ++it )
+ considerBuilder( TheGameLogic->findObjectByID( *it ), &pick );
}
+ Object *constructorObject = pick.idle ? pick.idle : pick.any;
if( place == NULL || constructorObject == NULL )
break; //These are not crashes, as the object may have died before this message came in
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 8015d0d39..474311461 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -2265,6 +2265,45 @@ TEST(placement_grid_snap_puts_footprint_edges_on_cell_lines)
CHECK_NEAR(InGameUI::snapPlacementAxis(13.0f, 0.0f), 14.5f, 0.0001f);
}
+TEST(placement_row_steps_flush_along_the_nearest_eighth)
+{
+ Coord2D step;
+
+ /* straight along x, a 40 by 30 footprint: one piece per 40 dragged, the first free */
+ CHECK_EQ(InGameUI::placementRow(119.0f, 0.0f, 40.0f, 30.0f, TRUE, 50, &step), 3);
+ CHECK_NEAR(step.x, 40.0f, 0.0001f);
+ CHECK_NEAR(step.y, 0.0f, 0.0001f);
+ CHECK_EQ(InGameUI::placementRow(120.0f, 0.0f, 40.0f, 30.0f, TRUE, 50, &step), 4);
+
+ /* a hand-drawn line 20 degrees off still runs straight, and backwards runs backwards */
+ CHECK_EQ(InGameUI::placementRow(-100.0f, 36.0f, 40.0f, 30.0f, TRUE, 50, &step), 3);
+ CHECK_NEAR(step.x, -40.0f, 0.0001f);
+ CHECK_NEAR(step.y, 0.0f, 0.0001f);
+
+ /* along y the step is the footprint's other side */
+ InGameUI::placementRow(0.0f, -90.0f, 40.0f, 30.0f, TRUE, 50, &step);
+ CHECK_NEAR(step.x, 0.0f, 0.0001f);
+ CHECK_NEAR(step.y, -30.0f, 0.0001f);
+
+ /* a diagonal steps corner to corner */
+ CHECK_EQ(InGameUI::placementRow(80.0f, 60.0f, 40.0f, 30.0f, TRUE, 50, &step), 3);
+ CHECK_NEAR(step.x, 40.0f, 0.0001f);
+ CHECK_NEAR(step.y, 30.0f, 0.0001f);
+
+ /* on the grid a size goes up to whole cells, a turned footprint's float dust does not */
+ InGameUI::placementRow(100.0f, 0.0f, 42.0f, 30.0f, TRUE, 50, &step);
+ CHECK_NEAR(step.x, 50.0f, 0.0001f);
+ InGameUI::placementRow(100.0f, 0.0f, 40.00002f, 30.0f, TRUE, 50, &step);
+ CHECK_NEAR(step.x, 40.0f, 0.0001f);
+ InGameUI::placementRow(100.0f, 0.0f, 42.0f, 30.0f, FALSE, 50, &step);
+ CHECK_NEAR(step.x, 42.0f, 0.0001f);
+
+ /* never more than the cap, never fewer than one, and no drag is one piece */
+ CHECK_EQ(InGameUI::placementRow(1000.0f, 0.0f, 40.0f, 30.0f, TRUE, 5, &step), 5);
+ CHECK_EQ(InGameUI::placementRow(1000.0f, 0.0f, 40.0f, 30.0f, TRUE, 0, &step), 1);
+ CHECK_EQ(InGameUI::placementRow(0.0f, 0.0f, 40.0f, 30.0f, TRUE, 50, &step), 1);
+}
+
/* The shipped AIData.ini values, so the numbers below are the ones a real game uses. */
static const Real AIDATA_TEAM_SECONDS = 10.0f;