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): supply percent, idle combat unit key, alt-drag build grid, ally queue

Olcay Seygan9bd706f80a04
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f0bc5216e..89f6f7553 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -195,6 +195,7 @@ found and fixed — EA's own, not port damage.**
- Attack move stays armed for as long as shift is down, whether you pressed its key or clicked its button on the bar, so every point you queue is an attack move. Orders given on the minimap are the orders they would be on the battlefield: an armed attack move is an attack move there too, and shift adds to the queue. Passing the pointer over the minimap no longer puts an armed attack move down.
- What the circle picks up is what you can see, and a stealthed unit is not that. Shroud was the only test, so a hidden tank parked in ground you had already cleared went on the list like anything else: drag a circle over open country and the group opened fire on air, one order per hidden unit, which is a stealth detector drawn with the mouse. An undetected unit is not in the circle.
- Ctrl+D takes every unit of the kinds you have selected that is on the screen, and pressed twice inside half a second takes them across the whole map. One tank selected and two keystrokes is your whole armour, wherever it is standing. It was on Shift+Ctrl+E, which is three fingers for something you do in every fight, and it only ever reached across the map when the screen had nothing left to give - so the wide selection happened to you instead of being asked for.
+- U takes you to the next combat unit standing with no orders: it is selected and the view centres on it. Press again for the one after. Idle workers stay on I.
## Aircraft, guards, and orders that used to be ignored
@@ -569,6 +570,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- One row above the command bar carries everything your base is building anywhere.
- Ordered by time left, so it reads as the order things arrive.
- Select a building and what it is making moves to the front of that row, ahead of everything else, still soonest first among itself. It used to get a whole second row of its own under the base's, which said the same thing twice and pushed the strip further up the screen; now the head of the strip is the building you are looking at and the tail is the rest of your base.
+- Click an ally's War Factory, Barracks or Airfield and its production queue comes up at the front of your own strip, counting down as it builds. It is there to look at: you cannot cancel anything in it.
- Click a picture to jump the camera there; Ctrl-click cancels it.
- One picture is one order, cut to match the command bar's artwork.
- The strip is half the size it was: it says the same thing and takes back the screen it was eating.
@@ -668,6 +670,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- Holding shift and clicking out a row of buildings no longer stops halfway and selects one.
- 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 runs exactly the way you drag it, at 20 degrees as happily as along the map's edge, and packs the buildings as close as their shape allows: one turned onto the line of the row stands wall to wall with the next, and a factory keeps its door lane clear. A row of Power Plants turned square to the map packs 44 apart; it used to go down on whole grid squares, 50 apart, with a strip of dirt at every joint. It 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.
- While that row is on the cursor, the wheel opens and closes the space between the buildings, one grid square a notch. The one where you pressed and the one under the cursor stay put; what changes is how many stand between them and how far apart those are. It will not pack them any tighter than they already sit against each other, and it will not take either end away to make the gap. Letting go places the row and takes the building off the cursor, so the next click is not another one. Holding shift and clicking them out one at a time still keeps the ghost up.
+- Hold Alt and drag while placing a building, and you lay out a block of them instead of a row. Ghosts stand for as many as your money covers, a blocked spot is skipped, and your builders work through the block in order.
- 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.
@@ -685,7 +688,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
## Where the money is, and where it is coming from
-- Supply piles and docks say what is left in them, in cash, over the pile. No more guessing which expansion is worth taking from the art on the model.
+- Supply piles and docks say what is left in them, in cash, over the pile. No more guessing which expansion is worth taking from the art on the model. Point at a pile and the tooltip puts a percentage beside the cash: what is left of what the pile started with.
- Every build button carries its price in the top right corner, opposite the build time already in the other one. It was only ever in the tooltip, which means hovering one button at a time to compare two of them.
- A structure's button says what it does to the power grid, in the fourth corner: what it draws, or what a plant puts back. Money and time were already on the button and power is the third thing a base spends; it was the one figure you had to hover for, which is the wrong way round for the building you are putting up because the lights went out.
- A worker fetching or handing over a box shows a bar while it works.
diff --git a/GeneralsMD/Code/Data/INI/CommandMapReforged.ini b/GeneralsMD/Code/Data/INI/CommandMapReforged.ini
index 2b9c7bc6c..a7733416b 100644
--- a/GeneralsMD/Code/Data/INI/CommandMapReforged.ini
+++ b/GeneralsMD/Code/Data/INI/CommandMapReforged.ini
@@ -339,6 +339,17 @@ CommandMap SELECT_NEXT_IDLE_WORKER
DisplayName = GUI:SelectNextIdleWorker
End
+; the same cycle for fighting units standing with no order, on the key beside it
+CommandMap SELECT_NEXT_IDLE_UNIT
+ Key = KEY_U
+ Transition = DOWN
+ Modifiers = NONE
+ UseableIn = GAME
+ Category = SELECTION
+ Description = GUI:SelectNextIdleUnitDescription
+ DisplayName = GUI:SelectNextIdleUnit
+End
+
; Attack (A), stop (S), attack move (D), guard (X) and hold position (C) have no
; record of their own any more: they are the grid's places on those keys, and
; the grid posts the same message a record here used to (orderAtPlace in
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 606276fcc..f30335757 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -25,6 +25,14 @@ GUI:SelectNextIdleWorkerDescription
"Selects the next dozer or worker that has nothing to do and centers the view on it."
END
+GUI:SelectNextIdleUnit
+"Select Next Idle Unit"
+END
+
+GUI:SelectNextIdleUnitDescription
+"Selects the next combat unit that has no orders and centers the view on it."
+END
+
GUI:CommandSlot01
"Command Bar Slot 01"
END
@@ -901,6 +909,13 @@ TOOLTIP:Language
"The language of menus, orders, briefings and subtitles. Voices and videos stay as installed. Takes effect the next time the game starts."
END
+// Hovering a supply pile: EA's TOOLTIP:SupplyWarehouse line with the share of the pile's starting
+// cash that is left. The cash first, then the percentage.
+
+TOOLTIP:SupplyWarehousePercent
+"\n $%d remain (%d%%)"
+END
+
// The line under it when the lobby's Pile Limit has the pile closed to the player looking at it.
TOOLTIP:SupplyPileFull
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index 12389d450..2ff7f3457 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -1033,6 +1033,10 @@ TOOLTIP:SupplyWarehouse
"\n $%d kaldı"
END
+TOOLTIP:SupplyWarehousePercent
+"\n $%d kaldı (%d%%)"
+END
+
TOOLTIP:SupplyPileFull
"\n Dolu: yığın sınırı toplayıcılarınızı almıyor"
END
@@ -14633,6 +14637,14 @@ GUI:SelectNextIdleWorkerDescription
"Yapacak işi olmayan sonraki dozeri veya işçiyi seçer ve görüntüyü ona odaklar."
END
+GUI:SelectNextIdleUnit
+"Sonraki Boştaki Birliği Seç"
+END
+
+GUI:SelectNextIdleUnitDescription
+"Emri olmayan sonraki savaş birliğini seçer ve görüntüyü ona odaklar."
+END
+
GUI:CommandSlot01
"Komut Çubuğu Yuvası 01"
END
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
index 1b5121160..0258a79f4 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
@@ -224,6 +224,7 @@ public:
MSG_META_SELECT_NEXT_WORKER, ///< select 'next' worker
MSG_META_SELECT_PREV_WORKER, ///< select 'prev' worker
MSG_META_SELECT_NEXT_IDLE_WORKER, ///< select 'next' idle worker
+ MSG_META_SELECT_NEXT_IDLE_UNIT, ///< select 'next' fighting unit standing with no order
// command-bar grid hot keys: one per place of the 6 x 3 command grid, read along the rows
// (01-06 the top row, 07-12 the middle one, 13-18 the bottom); see CommandPlace
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 63cb76acc..de519dc1c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -741,11 +741,73 @@ public: // ********************************************************************
return count;
}
- /// would dragging the anchor lay a row of the pending structure, rather than aim one?
+ /** An alt-dragged grid, the row's twin in two directions. The anchor and a cursor 'dx'/'dy'
+ * away are opposite corners of a rectangle squared up with the structure's heading, and the
+ * pieces fill it line by line: 'perLine' of them stand along the heading 'alongStep' apart, and
+ * the lines stand 'acrossStep' apart. Piece i is alongStep * ( i % perLine ) + acrossStep *
+ * ( i / perLine ) from the anchor, which is the order they are drawn and ordered in. Each
+ * side packs the way the row does, flush through the face it meets plus 'extraGap', with the
+ * slack spread so the far corner keeps a piece. The one difference: a side shorter than a
+ * step holds one piece, not two, or a drag that is nearly a line would come out as two lines
+ * lying on each other. 'most' caps the total, so the last line can come up short, and the
+ * lines are counted from what it leaves: five pieces three to a line are two lines, the
+ * second on the far side. Never fewer than one. Inline and static for the same test. */
+ static Int placementGrid( Real dx, Real dy, Real headingCos, Real headingSin, Real halfFacing,
+ Real halfSide, Int most, Coord2D *alongStep, Coord2D *acrossStep,
+ Int *perLine, Real extraGap = 0.0f )
+ {
+ alongStep->x = 0.0f;
+ alongStep->y = 0.0f;
+ acrossStep->x = 0.0f;
+ acrossStep->y = 0.0f;
+
+ // the drag, measured along the heading and across it
+ const Real along = dx * headingCos + dy * headingSin;
+ const Real across = dy * headingCos - dx * headingSin;
+
+ const Real gap = extraGap > 0.0f ? extraGap : 0.0f;
+ const Real alongSpan = placementTouchDistance( headingCos, headingSin, headingCos, headingSin,
+ 2.0f * halfFacing, 2.0f * halfSide ) + gap;
+ const Real acrossSpan = placementTouchDistance( -headingSin, headingCos, headingCos, headingSin,
+ 2.0f * halfFacing, 2.0f * halfSide ) + gap;
+
+ if( most < 1 )
+ most = 1;
+
+ // the same hair under a whole number as the row's
+ Int count = REAL_TO_INT_FLOOR( (Real)fabs( along ) / alongSpan + 0.001f ) + 1;
+ if( count > most )
+ count = most;
+
+ Int lines = REAL_TO_INT_FLOOR( (Real)fabs( across ) / acrossSpan + 0.001f ) + 1;
+ const Int linesPaidFor = ( most + count - 1 ) / count;
+ if( lines > linesPaidFor )
+ lines = linesPaidFor;
+
+ if( count >= 2 )
+ {
+ alongStep->x = along * headingCos / (Real)( count - 1 );
+ alongStep->y = along * headingSin / (Real)( count - 1 );
+ }
+ if( lines >= 2 )
+ {
+ acrossStep->x = -across * headingSin / (Real)( lines - 1 );
+ acrossStep->y = across * headingCos / (Real)( lines - 1 );
+ }
+
+ *perLine = count;
+ const Int total = count * lines;
+ return total > most ? most : total;
+ }
+
+ /// would dragging the anchor lay pieces of the pending structure, a row or a grid, rather than aim one?
Bool placesRow( void );
+ /// of those two, the grid: alt is held. Alt with shift is the grid as well
+ Bool placesGrid( void ) const;
/// wheel notches while that row is being drawn: one grid square of gap a notch, never below flush
void adjustPlacementRowGap( Real spin );
- /// the centres of that row from 'start' toward 'end', as many as MaxLineBuildObjects and the money allow
+ /// the centres of that row from 'start' toward 'end', or of the grid between those two corners,
+ /// 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;
@@ -1186,6 +1248,7 @@ public: // ********************************************************************
virtual void addIdleWorker( Object *obj );
virtual void removeIdleWorker( Object *obj, Int playerNumber );
virtual void selectNextIdleWorker( void );
+ void selectNextIdleUnit( void ); ///< the same cycle for fighting units standing with no order
virtual void recreateControlBar( void );
virtual void notifyResolutionChange( void );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.h
index 3aed98ac4..6e972e96e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.h
@@ -85,6 +85,7 @@ public:
virtual Bool action( Object* docker, Object *drone = NULL ); ///<For me, this means identifying who is docking and either taking Boxes away or giving them
Int getBoxesStored() const { return m_boxesStored; }
+ Int getStartingBoxes() const { return getSupplyWarehouseDockUpdateModuleData()->m_startingBoxesData; } ///< what the pile held when the match began
virtual Int getSupplyCashValue( void ) const;
void setCashValue( Int cashValue );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
index c396dc3eb..551d695e6 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
@@ -305,6 +305,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
CHECK_IF(MSG_META_SELECT_NEXT_WORKER)
CHECK_IF(MSG_META_SELECT_PREV_WORKER)
CHECK_IF(MSG_META_SELECT_NEXT_IDLE_WORKER)
+ CHECK_IF(MSG_META_SELECT_NEXT_IDLE_UNIT)
CHECK_IF(MSG_META_COMMAND_SLOT01)
CHECK_IF(MSG_META_COMMAND_SLOT02)
CHECK_IF(MSG_META_COMMAND_SLOT03)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 66673fa12..78d420347 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -6177,7 +6177,18 @@ void InGameUI::createMouseoverHint( const GameMessage *msg )
{
Int boxes = warehouseModule->getBoxesStored();
Int value = boxes * TheGlobalData->m_baseValuePerSupplyBox;
- warehouseFeedback.format(TheGameText->fetch("TOOLTIP:SupplyWarehouse"), value);
+ Int startingBoxes = warehouseModule->getStartingBoxes();
+ if( startingBoxes > 0 )
+ {
+ // what is left against what the pile began the match with; it can be stocked past that
+ Int percent = min( 100, boxes * 100 / startingBoxes );
+ warehouseFeedback.format(TheGameText->fetch("TOOLTIP:SupplyWarehousePercent"), value, percent);
+ }
+ else
+ {
+ // a map or a mod that starts the pile empty gives no total to take a share of: cash alone
+ warehouseFeedback.format(TheGameText->fetch("TOOLTIP:SupplyWarehouse"), value);
+ }
str.concat(warehouseFeedback);
// the lobby's supply pile limit: say so when this player's gatherers would be turned away
if( warehouseModule->isClosedToPlayer( ThePlayerList->getLocalPlayer() ) )
@@ -7087,14 +7098,28 @@ void InGameUI::snapPlacementToGrid( Coord3D *world, const ThingTemplate *what, R
} // end snapPlacementToGrid
//-------------------------------------------------------------------------------------------------
-/** Shift held on the drag: a wall already tiles from any drag, so it is left to do that. */
+/** Shift or alt held on the drag: a wall already tiles from any drag, so it is left to do that.
+ * Everything that asks this wants to know whether the drag lays pieces instead of aiming one, and
+ * that is the same answer for a row and a grid; computePlacementRow is where the two part. */
//-------------------------------------------------------------------------------------------------
Bool InGameUI::placesRow( void )
{
- return m_pendingPlaceType != NULL && TheKeyboard && TheKeyboard->isShift() &&
+ return m_pendingPlaceType != NULL && TheKeyboard &&
+ ( TheKeyboard->isShift() || TheKeyboard->isAlt() ) &&
!TheBuildAssistant->isLineBuildTemplate( m_pendingPlaceType );
}
+//-------------------------------------------------------------------------------------------------
+/** Alt makes it a grid, and wins over shift when both are down: a grid dragged along the
+ * structure's own line is already a row. Let go of alt with shift still held and the same drag
+ * is the shift row again; let go of both and it aims one structure. Asked only once placesRow
+ * has said yes. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::placesGrid( void ) const
+{
+ return TheKeyboard->isAlt();
+}
+
//-------------------------------------------------------------------------------------------------
/** One grid square a notch, added to the packed step. A notch toward the user closes it back,
* and it stops at the buildings touching: tighter than that is two structures on one footprint.
@@ -7154,16 +7179,33 @@ void InGameUI::computePlacementRow( const ThingTemplate *what, Real angle, const
most = affordable;
}
+ // a row is one line of a grid: everything on line 0, and no step to a next one
Coord2D step;
- const Int count = placementRow( end->x - start->x, end->y - start->y, (Real)Cos( angle ),
- (Real)Sin( angle ), halfFacing, minor, most, &step,
- m_placementRowGap );
+ Coord2D lineStep;
+ lineStep.x = 0.0f;
+ lineStep.y = 0.0f;
+ Int count;
+ Int perLine;
+ if( placesGrid() )
+ {
+ count = placementGrid( end->x - start->x, end->y - start->y, (Real)Cos( angle ),
+ (Real)Sin( angle ), halfFacing, minor, most, &step, &lineStep, &perLine,
+ m_placementRowGap );
+ }
+ else
+ {
+ count = placementRow( end->x - start->x, end->y - start->y, (Real)Cos( angle ),
+ (Real)Sin( angle ), halfFacing, minor, most, &step,
+ m_placementRowGap );
+ perLine = count;
+ }
+
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.x = start->x + step.x * ( i % perLine ) + lineStep.x * ( i / perLine );
+ pos.y = start->y + step.y * ( i % perLine ) + lineStep.y * ( i / perLine );
pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y );
positions->push_back( pos );
}
@@ -12818,8 +12860,10 @@ void InGameUI::drawProductionStripColumn( Int left, Int bottomY )
// so: it goes red and wears a minus. Without it a ctrl-click is a guess about which cameo
// the cursor is really on, and an accidental cancel costs the whole item.
//
- // a building already standing on the map is not cancelled from here - it is sold or blown up
- if( !slot->isStructure && TheKeyboard && TheKeyboard->isCtrl() && TheMouse )
+ // a building already standing on the map is not cancelled from here - it is sold or blown up,
+ // and an ally's item is not yours to cancel, so it does not offer to
+ if( !slot->isStructure && producer && producer->isLocallyControlled() &&
+ TheKeyboard && TheKeyboard->isCtrl() && TheMouse )
{
const MouseIO *io = TheMouse->getMouseStatus();
draw->cancelHover = io && io->pos.x >= draw->x && io->pos.x < draw->x + cameoW &&
@@ -13049,11 +13093,17 @@ void InGameUI::drawProductionStrip( void )
// follows it. It goes in before the sweep over everything else, and the sweep skips it, so
// nothing is drawn or counted twice.
//
+ // A mutual ally's building leads it the same way: click his War Factory and what it is turning
+ // out stands ahead of your own queue, to read and nothing else. The cancel is refused twice
+ // over for a cameo that is not yours, in handleProductionStripClick and again in the logic.
+ // An enemy's or a neutral's never gets here, and a watcher left above.
+ //
ObjectID selected = INVALID_ID;
if( getSelectCount() == 1 && !m_selectedDrawables.empty() )
{
Object *sel = m_selectedDrawables.front()->getObject();
- if( sel && sel->getControllingPlayer() == player )
+ if( sel && ( sel->getControllingPlayer() == player ||
+ isAllyOfLocalPlayer( sel->getControllingPlayer()->getPlayerIndex() ) ) )
{
selected = sel->getID();
appendProducerQueue( sel, m_productionStrip, &m_productionStripCount, PRODUCTION_STRIP_ROW_MAX,
@@ -13661,6 +13711,69 @@ void InGameUI::selectNextIdleWorker( void )
}
}
+// A unit of the local player's that is standing on the field with no order: not a dozer, a worker
+// or a supply truck (those have the idle-worker key), not a structure, not riding in anything.
+static Bool isIdleCombatUnit( const Object *obj )
+{
+ if( !obj->isLocallyControlled() || obj->isEffectivelyDead() || obj->isContained() || !obj->isMobile() )
+ return FALSE;
+
+ if( !obj->isKindOf( KINDOF_SELECTABLE ) || obj->isKindOf( KINDOF_NO_SELECT ) || obj->isKindOf( KINDOF_IGNORED_IN_GUI ) )
+ return FALSE;
+
+ if( obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_DOZER ) || obj->isKindOf( KINDOF_HARVESTER ) )
+ return FALSE;
+
+ // a player owns things with no AI module at all
+ const AIUpdateInterface *ai = obj->getAI();
+ return ai && ai->isIdle();
+}
+
+void InGameUI::selectNextIdleUnit( void )
+{
+ // Nothing keeps a list of these the way the dozers keep m_idleWorkers, so the key walks the
+ // object list, which is in creation order and stays put between presses. A lone selected unit
+ // is the place to carry on from; with nothing or a group selected the walk starts over.
+ const Object *current = getSelectCount() == 1 ? getFirstSelectedDrawable()->getObject() : NULL;
+ Object *first = NULL;
+ Object *selectThisObject = NULL;
+ Bool passedCurrent = FALSE;
+
+ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
+ {
+ if( isIdleCombatUnit( obj ) )
+ {
+ if( passedCurrent )
+ {
+ selectThisObject = obj;
+ break;
+ }
+ if( !first )
+ first = obj;
+ }
+ if( obj == current )
+ passedCurrent = TRUE;
+ }
+
+ // past the last one the cycle wraps to the first
+ if( !selectThisObject )
+ selectThisObject = first;
+ if( !selectThisObject )
+ return;
+
+ deselectAllDrawables();
+ GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
+
+ //New group or add to group? Passed in value is true if we are creating a new group.
+ teamMsg->appendBooleanArgument( TRUE );
+ teamMsg->appendObjectIDArgument( selectThisObject->getID() );
+
+ selectDrawable( selectThisObject->getDrawable() );
+
+ // center on the unit
+ TheTacticalView->lookAt(selectThisObject->getPosition());
+}
+
Int InGameUI::getIdleWorkerCount( void )
{
Int index = ThePlayerList->getLocalPlayer()->getPlayerIndex();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index d6c666447..f9915eb0f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -2850,6 +2850,14 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
break;
} // end select next idle worker
+ case GameMessage::MSG_META_SELECT_NEXT_IDLE_UNIT:
+ {
+ TheInGameUI->selectNextIdleUnit();
+
+ disp = DESTROY_MESSAGE;
+ break;
+ } // end select next idle unit
+
case GameMessage::MSG_META_COMMAND_SLOT01:
case GameMessage::MSG_META_COMMAND_SLOT02:
case GameMessage::MSG_META_COMMAND_SLOT03:
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index c51dc11de..887e0e349 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -140,6 +140,7 @@ static const LookupListRec GameMessageMetaTypeNames[] =
{ "SELECT_NEXT_WORKER", GameMessage::MSG_META_SELECT_NEXT_WORKER },
{ "SELECT_PREV_WORKER", GameMessage::MSG_META_SELECT_PREV_WORKER },
{ "SELECT_NEXT_IDLE_WORKER", GameMessage::MSG_META_SELECT_NEXT_IDLE_WORKER },
+ { "SELECT_NEXT_IDLE_UNIT", GameMessage::MSG_META_SELECT_NEXT_IDLE_UNIT },
{ "COMMAND_SLOT01", GameMessage::MSG_META_COMMAND_SLOT01 },
{ "COMMAND_SLOT02", GameMessage::MSG_META_COMMAND_SLOT02 },
{ "COMMAND_SLOT03", GameMessage::MSG_META_COMMAND_SLOT03 },
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
index 4416a9bc2..706bd3e37 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
@@ -390,7 +390,9 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess
if( row )
{
//
- // A shift-dragged row is one order per structure, each asked on its own: a piece
+ // A shift-dragged row, or an alt-dragged grid (computePlacementRow hands back
+ // either, in the order the ghosts were drawn), 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).
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index 75d234a9a..d8babbba2 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -1465,8 +1465,9 @@ void W3DInGameUI::drawPlaceAngle( View *view )
Bool anchorInScene = m_buildingPlacementAnchor->Peek_Scene() != NULL;
Bool arrowInScene = m_buildingPlacementArrow->Peek_Scene() != NULL;
- // get out of here if this display isn't up anyway, and with shift held it is not: that drag
- // lays a row and turns nothing, so an anchor and an arrow would promise a turn it will not make
+ // get out of here if this display isn't up anyway, and with shift or alt held it is not: that
+ // drag lays a row or a grid and turns nothing, so an anchor and an arrow would promise a turn
+ // it will not make
if( isPlacementAnchored() == FALSE || placesRow() )
{
if( anchorInScene )
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 9e3e469d5..512405e86 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -2514,6 +2514,65 @@ TEST(placement_row_pins_both_ends_and_opens_the_middle)
CHECK_NEAR(step.x, 40.5f, 0.0001f);
}
+TEST(placement_grid_fills_the_dragged_rectangle_in_lines)
+{
+ Coord2D along, across;
+ Int perLine = 0;
+ const Real half = 0.70710678f; /* cos and sin of an eighth of a turn */
+
+ /* facing along x, the same 40 by 30 footprint. two exact steps each way: three lines of
+ * three, 40.5 apart along the facing and 30.5 across it */
+ CHECK_EQ(InGameUI::placementGrid(81.0f, 61.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &along, &across, &perLine), 9);
+ CHECK_EQ(perLine, 3);
+ CHECK_NEAR(along.x, 40.5f, 0.0001f);
+ CHECK_NEAR(along.y, 0.0f, 0.0001f);
+ CHECK_NEAR(across.x, 0.0f, 0.0001f);
+ CHECK_NEAR(across.y, 30.5f, 0.0001f);
+
+ /* the order is line by line: piece 5 is the last of the second line */
+ CHECK_NEAR(along.x * (5 % perLine) + across.x * (5 / perLine), 81.0f, 0.0001f);
+ CHECK_NEAR(along.y * (5 % perLine) + across.y * (5 / perLine), 30.5f, 0.0001f);
+
+ /* a rectangle that is not a multiple keeps a piece on the far corner: the spare is spread */
+ CHECK_EQ(InGameUI::placementGrid(90.0f, 70.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &along, &across, &perLine), 9);
+ CHECK_NEAR(along.x * 2.0f, 90.0f, 0.0001f);
+ CHECK_NEAR(across.y * 2.0f, 70.0f, 0.0001f);
+
+ /* dragged up and to the left, it fills up and to the left */
+ CHECK_EQ(InGameUI::placementGrid(-81.0f, 61.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &along, &across, &perLine), 9);
+ CHECK_NEAR(along.x, -40.5f, 0.0001f);
+ CHECK_NEAR(across.y, 30.5f, 0.0001f);
+
+ /* a drag that is nearly a line is one line, not two lying on each other, and no drag is one piece */
+ CHECK_EQ(InGameUI::placementGrid(81.0f, 10.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &along, &across, &perLine), 3);
+ CHECK_EQ(perLine, 3);
+ CHECK_NEAR(across.y, 0.0f, 0.0001f);
+ CHECK_EQ(InGameUI::placementGrid(10.0f, 61.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &along, &across, &perLine), 3);
+ CHECK_EQ(perLine, 1);
+ CHECK_NEAR(along.x, 0.0f, 0.0001f);
+ CHECK_EQ(InGameUI::placementGrid(0.0f, 0.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &along, &across, &perLine), 1);
+
+ /* turned an eighth, the rectangle turns with the structure: the same 81 by 61 measured
+ * along its line and across it is the same three by three */
+ CHECK_EQ(InGameUI::placementGrid((81.0f - 61.0f) * half, (81.0f + 61.0f) * half, half, half,
+ 20.0f, 15.0f, 50, &along, &across, &perLine), 9);
+ CHECK_EQ(perLine, 3);
+ CHECK_NEAR(along.x * along.x + along.y * along.y, 40.5f * 40.5f, 0.01f);
+ CHECK_NEAR(across.x * across.x + across.y * across.y, 30.5f * 30.5f, 0.01f);
+ CHECK(across.x < 0.0f);
+
+ /* money for five: three on the first line, two on a second that stands on the far side */
+ CHECK_EQ(InGameUI::placementGrid(81.0f, 61.0f, 1.0f, 0.0f, 20.0f, 15.0f, 5, &along, &across, &perLine), 5);
+ CHECK_EQ(perLine, 3);
+ CHECK_NEAR(across.y, 61.0f, 0.0001f);
+ CHECK_EQ(InGameUI::placementGrid(81.0f, 61.0f, 1.0f, 0.0f, 20.0f, 15.0f, 0, &along, &across, &perLine), 1);
+
+ /* ten units of wheel gap open both directions: two by two, corners kept */
+ CHECK_EQ(InGameUI::placementGrid(81.0f, 61.0f, 1.0f, 0.0f, 20.0f, 15.0f, 50, &along, &across, &perLine, 10.0f), 4);
+ CHECK_NEAR(along.x, 81.0f, 0.0001f);
+ CHECK_NEAR(across.y, 61.0f, 0.0001f);
+}
+
/* The shipped AIData.ini values, so the numbers below are the ones a real game uses. */
static const Real AIDATA_TEAM_SECONDS = 10.0f;