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(gameclient): batch build clicks and box select modifiers

Olcay Seygan51a753982026
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8839a6200..cbd18d759 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -114,6 +114,7 @@ found and fixed — EA's own, not port damage.**
- Your own right-click orders always win, however much fire is already inbound.
- 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.
- 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
@@ -266,6 +267,7 @@ found and fixed — EA's own, not port damage.**
- A unit finishes walking out of its factory before it takes an order.
- An upgrade stays available if any selected building can still buy it.
- One right click cancels one thing, counted the moment you press.
+- A build button takes a batch: Shift queues five, Ctrl twenty, both together as many as the queue will hold and the bank will pay for. Right-click with the same keys and the same number comes back out. Ten tanks used to be ten clicks.
- Buying an upgrade for a group starts it in all of them.
- The progress clock over a picture is steady at any frame rate.
- A group's upgrade shows its progress, whichever building is paying for it.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index a93fec8ff..6b3b3e6b7 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -406,8 +406,18 @@ private:
/** Command sets are collections of configurable command buttons. They are used in the
* command context sensitive window in the battle user interface */
//-------------------------------------------------------------------------------------------------
-// how many units a shift-click on a build button queues at once, and a shift-right-click cancels
+//
+// How many units one click on a build button queues, and how many a right-click takes back out.
+// Shift is five, control is twenty, the two together mean "as many as will go" - the queue is nine
+// deep by default and the batch loop stops on its own at a full queue or an empty bank, so the
+// third rung fills every selected factory and spends whatever is left.
+//
enum { SHIFT_BUILD_QUEUE_COUNT = 5 };
+enum { CTRL_BUILD_QUEUE_COUNT = 20 };
+enum { CTRL_SHIFT_BUILD_QUEUE_COUNT = 100 };
+
+// the count the modifiers currently held ask for; 1 with nothing held
+Int getBuildBatchCount( void );
enum { MAX_COMMANDS_PER_SET = 18 }; // user interface max is 14 (but internally it's 18 for script only buttons!)
enum { MAX_RIGHT_HUD_UPGRADE_CAMEOS = 5};
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 55805835a..a5714cdb0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -2852,6 +2852,22 @@ CommandSet *ControlBar::newCommandSetOverride( CommandSet *setToOverride )
return set;
}
+//-------------------------------------------------------------------------------------------------
+/** How many units this click on a build button is worth. Three rungs, taken from Beyond All
+ Reason's build menu, which is the only RTS that treats the batch size as a first class thing:
+ shift is a squad, control is a queue, both together is everything the bank will pay for. The
+ same number runs the right button, so whatever a click queued, one right-click of the same
+ shape takes back out. */
+//-------------------------------------------------------------------------------------------------
+Int getBuildBatchCount( void )
+{
+ if( TheKeyboard->isCtrl() )
+ return TheKeyboard->isShift() ? CTRL_SHIFT_BUILD_QUEUE_COUNT : CTRL_BUILD_QUEUE_COUNT;
+
+ return TheKeyboard->isShift() ? SHIFT_BUILD_QUEUE_COUNT : 1;
+
+} // end getBuildBatchCount
+
//-------------------------------------------------------------------------------------------------
/** Process a button click for the context sensitive GUI */
//-------------------------------------------------------------------------------------------------
@@ -2879,8 +2895,8 @@ CBCommandStatus ControlBar::processContextSensitiveButtonClick( GameWindow *butt
if( command->getCommandType() == GUI_COMMAND_UNIT_BUILD )
{
- // holding shift takes a whole batch back out, mirroring the shift-click that queued one
- Int wanted = (TheKeyboard && TheKeyboard->isShift()) ? SHIFT_BUILD_QUEUE_COUNT : 1;
+ // a modifier takes the same batch back out that it would have queued
+ Int wanted = getBuildBatchCount();
while( wanted-- > 0 && cancelLastQueuedUnit( command->getThingTemplate() ) )
;
return CBC_COMMAND_USED;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
index 51e6565c0..b9ef4ab0b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
@@ -529,8 +529,8 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,
DEBUG_ASSERTCRASH( whatToBuild, ("Undefined BUILD command for object '%s'\n",
commandButton->getThingTemplate()->getName().str()) );
- // holding shift queues a whole batch with one click
- Int wanted = TheKeyboard->isShift() ? SHIFT_BUILD_QUEUE_COUNT : 1;
+ // shift, control or both queue a whole batch with one click
+ Int wanted = getBuildBatchCount();
// gather the "factory" objects that could make the thing. With several factories
// selected (multi-select context) every one that can make it is a candidate, and each
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
index ff6d6b29d..985b81b97 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
@@ -645,11 +645,75 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
// if there were drawables in the region, then we should determine if there is a context
// sensitive command that should take place. If there is, then this isn't a selection thing
const DrawableList *currentList = TheInGameUI->getAllSelectedDrawables();
- if (!currentlyLookingForSelection())
+ if (!currentlyLookingForSelection())
{
break;
}
+ /* Box select modifiers, taken from Beyond All Reason, where they are the difference
+ between a selection and the right selection. Shift already adds, so what was missing
+ was a way to take things back out and a way to leave the base staff behind: Alt keeps
+ only what can shoot, Ctrl removes the box from the selection instead of replacing it.
+ Both are drag-only. A point click has to stay exactly what it was - a filter that eats
+ single clicks reads as a broken mouse, and Ctrl on a point click is force fire. */
+ if (!isPoint)
+ {
+ if (TheKeyboard->isAlt())
+ {
+ DrawableListIt fit = drawablesThatWillSelect.begin();
+ while (fit != drawablesThatWillSelect.end())
+ {
+ Object *candidate = (*fit) ? (*fit)->getObject() : NULL;
+ const Bool fights = candidate && candidate->hasAnyWeapon() &&
+ !candidate->isKindOf(KINDOF_STRUCTURE);
+ if (fights)
+ ++fit;
+ else
+ fit = drawablesThatWillSelect.erase(fit);
+ }
+
+ // a box with nothing armed in it is a miss, not an order to select the base
+ if (drawablesThatWillSelect.empty())
+ {
+ disp = DESTROY_MESSAGE;
+ break;
+ }
+ }
+
+ if (TheKeyboard->isCtrl())
+ {
+ GameMessage *removeMsg = NULL;
+ DrawableListIt rit;
+ for (rit = drawablesThatWillSelect.begin(); rit != drawablesThatWillSelect.end(); ++rit)
+ {
+ Drawable *draw = *rit;
+ if (draw == NULL || !draw->isSelected())
+ {
+ continue;
+ }
+
+ Object *objToDeselect = draw->getObject();
+ if (objToDeselect == NULL)
+ {
+ continue;
+ }
+
+ // the message is only worth making once something is actually coming out
+ if (removeMsg == NULL)
+ {
+ removeMsg = TheMessageStream->appendMessage(GameMessage::MSG_REMOVE_FROM_SELECTED_GROUP);
+ }
+
+ removeMsg->appendObjectIDArgument(objToDeselect->getID());
+ TheInGameUI->deselectDrawable(draw);
+ }
+
+ m_lastGroupSelGroup = -1;
+ disp = DESTROY_MESSAGE;
+ break;
+ }
+ }
+
SelectionInfo si;
if (contextCommandForNewSelection(currentList, &drawablesThatWillSelect, &si, isPoint))
{