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): grid keyless places borrow unused fixed letters

Olcay Seygand81a31eecaf1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5496b7938..843ddf161 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,7 +54,7 @@ found and fixed — EA's own, not port damage.**
- Every key is yours to move. The launcher's Hotkeys page draws the command bar of every building and unit each general can field, cameos and letters as the game shows them, and a click and a keypress gives any button a new letter or none. Two buttons on one bar that would share a letter are marked before you play. The keyboard commands are there too, from bookmarks and team keys to the camera, along with the ones Zero Hour never bound: select every fighting unit, vehicle or aircraft, every barracks, war factory or airfield, the next idle worker or unit, pause, the general's promotions, the three signals to your allies and the general's powers. Your keys are yours alone; the other players in a match keep theirs, and a match never refuses you for them. Every mod you install brings its own generals to the page, ShockWave's fifteen next to Zero Hour's thirteen, and a key you give a ShockWave button stays with ShockWave.
- Some keys now mean one thing on every bar: A attack move, S stop, G guard, Y rally point, V evacuate, N sell, C combat drop, and H for land mines, camo netting and the GLA worker's switch to fake buildings. Sell sits on its own key, so emptying a bunker can never sell it. The 188 buttons Zero Hour had put on one of those letters take another, kept off the grid keys where the bar leaves room (the Avenger is J now), and no bar gained a clash doing it.
- Export and Import on the Hotkeys page take your keys to a file and back, for another PC or a fresh install. Before an import the page tells you how many keys it changes and how many would clash; a file with a line it cannot read changes nothing and quotes that line. Keys for a mod you have not installed come along and wait for it.
-- Grid keys, one switch on the Hotkeys page: a button's key is its place on the bar, so the first button of a Command Center is Q and so is the first of a Barracks, a War Factory or a dozer. Every key on the bar sits in the 18-key block under your left hand, Q W E R T Y over A S D F G H over Z X C V B N. Attack move, stop, guard, rally point, evacuate and combat drop keep A, S, G, Y, V and C wherever they stand; the other twelve letters are places, Q W E R T along the top with Z X D F B under them, H in the sixth column and N, still sell, in the last. The places attack move and rally point usually hold have no letter of their own, so any other button there moves to the leftmost free place that has one: the American War Factory's TOW upgrade goes from the top of the sixth column to B, and every button on the bar has a key whenever a keyed place is free. The letter on each button changes to match, and type select, select all, scatter and the rest that sat on those letters step aside to P and the keys right of the letters, with the page showing where each went.
+- Grid keys, one switch on the Hotkeys page: a button's key is its place on the bar, so the first button of a Command Center is Q and so is the first of a Barracks, a War Factory or a dozer. Every key on the bar sits in the 18-key block under your left hand, Q W E R T Y over A S D F G H over Z X C V B N. Attack move, stop, guard, rally point, evacuate and combat drop keep A, S, G, Y, V and C wherever they stand; the other twelve letters are places, Q W E R T along the top with Z X D F B under them, H in the sixth column and N, still sell, in the last. The places attack move and rally point usually hold have no letter of their own. On a bar without those orders they borrow the free ones: a building has no attack move, so the American War Factory's TOW upgrade at the top of the sixth column is A, and any other button at the top of the seventh column, where a rally point usually stands, is G. A unit's attack move and guard keep A and G as before. A button that still finds no letter there moves to the leftmost free place that has one, so every button on the bar has a key whenever a keyed place is free. The letter on each button changes to match, and type select, select all, scatter and the rest that sat on those letters step aside to P and the keys right of the letters, with the page showing where each went.
## The command bar moves to the middle
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
index 8577a9174..930e1d905 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
@@ -120,9 +120,18 @@ public:
Int commandType );
/** The key command bar slot barSlot gives a button with grid keys on, 0 for a slot without one or
- * with grid keys off. */
+ * with grid keys off. The two keyless places take what lendFixedKeys lent them. */
static WideChar gridSlotKey( Int barSlot );
+ /** The bar about to show these `count` buttons (an empty name for none) lends the keyless places
+ * the fixed letters it has no order for: 11 attack move's A, 13 guard's G or the rally point's Y,
+ * then any of A S G Y V C still free, so a building's bar keys those places too. NULL buttons,
+ * which reset() passes, takes them back. */
+ static void lendFixedKeys( const AsciiString *buttons, const Int *types, Int count );
+
+ /** lendFixedKeys' choice into lent, one letter or 0 per grid place. */
+ static void gridLentKeys( const AsciiString *buttons, const Int *types, Int count, WideChar *lent );
+
private:
typedef std::map<AsciiString, HotKey> HotKeyMap;
HotKeyMap m_hotKeyMap;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
index 8082aedc4..0634dcadd 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
@@ -379,6 +379,20 @@ void ControlBar::populateCommand( Object *obj )
} // end if
+ // with grid keys on, the fixed letters this bar has no order for key its two keyless places
+ {
+ AsciiString names[ MAX_COMMANDS_PER_SET ];
+ Int types[ MAX_COMMANDS_PER_SET ];
+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
+ {
+ const CommandButton *button = commandSet->getCommandButton( i );
+ const Bool shows = button && !BitTest( button->getOptions(), SCRIPT_ONLY );
+ names[ i ] = shows ? button->getName() : AsciiString::TheEmptyString;
+ types[ i ] = shows ? button->getCommandType() : GUI_COMMAND_NONE;
+ }
+ HotKeyManager::lendFixedKeys( names, types, MAX_COMMANDS_PER_SET );
+ }
+
// transports do extra special things with the user interface buttons
if( obj->getContain() && obj->getContain()->isDisplayedOnControlBar() )
doTransportInventoryUI( obj, commandSet );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
index ca256aa8e..7c6a08981 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
@@ -165,6 +165,7 @@ void HotKeyManager::init( void )
void HotKeyManager::reset( void )
{
m_hotKeyMap.clear();
+ lendFixedKeys( NULL, NULL, 0 );
}
//-----------------------------------------------------------------------------
@@ -310,8 +311,9 @@ static std::map< std::string, WideChar > s_playerButtonKeys;
* Y / A S D F G H / Z X C V B N block that are no GRID_FIXED_KEYS. Q W E R T top the first five
* columns, Z X D F B under them, each under its own column where the fixed A, S and G leave a gap;
* the sixth column is H under attack move's place (slot 11) and the seventh N, sell's key, under
- * the rally point's (slot 13). Those two places have no key: a fixed order standing there shows
- * its own letter, any other button none. The launcher's Hotkeys page draws the same table
+ * the rally point's (slot 13). Those two places have no key of their own: a fixed order standing
+ * there shows its own letter, and on a bar without such an order the place borrows the free fixed
+ * letter (HotKeyManager::lendFixedKeys). The launcher's Hotkeys page draws the same table
* (hotkeys.js, GRID_KEYS). */
static const WideChar GRID_KEYS[] = { 'Q', 'Z', 'W', 'X', 'E', 'D', 'R', 'F', 'T', 'B', 0, 'H', 0, 'N' };
static const Int GRID_KEY_COUNT = sizeof( GRID_KEYS ) / sizeof( GRID_KEYS[ 0 ] );
@@ -433,7 +435,7 @@ WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar lab
{
if( fixed != 0 && isOneOf( fixed, GRID_FIXED_KEYS, (Int)( sizeof( GRID_FIXED_KEYS ) / sizeof( GRID_FIXED_KEYS[ 0 ] ) ) ) )
return fixed;
- return barSlot < GRID_KEY_COUNT ? GRID_KEYS[ barSlot ] : 0;
+ return gridSlotKey( barSlot );
}
if( fixed != 0 )
return fixed;
@@ -451,9 +453,64 @@ WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar lab
}
//-----------------------------------------------------------------------------
+/** What the bar on show lends the two keyless places, see lendFixedKeys. */
+static WideChar s_lentKeys[ GRID_KEY_COUNT ] = { 0 };
+
WideChar HotKeyManager::gridSlotKey( Int barSlot )
{
- return s_commandGrid && barSlot >= 0 && barSlot < GRID_KEY_COUNT ? GRID_KEYS[ barSlot ] : 0;
+ if( !s_commandGrid || barSlot < 0 || barSlot >= GRID_KEY_COUNT )
+ return 0;
+ return GRID_KEYS[ barSlot ] != 0 ? GRID_KEYS[ barSlot ] : s_lentKeys[ barSlot ];
+}
+
+//-----------------------------------------------------------------------------
+void HotKeyManager::gridLentKeys( const AsciiString *buttons, const Int *types, Int count, WideChar *lent )
+{
+ const Int fixedCount = (Int)( sizeof( GRID_FIXED_KEYS ) / sizeof( GRID_FIXED_KEYS[ 0 ] ) );
+ WideChar used[ MAX_COMMANDS_PER_SET + GRID_KEY_COUNT ];
+ Int usedCount = 0;
+ for( Int each = 0; each < count; each++ )
+ {
+ if( buttons[ each ].isEmpty() )
+ continue;
+ AsciiString lower = buttons[ each ];
+ lower.toLower();
+ Int mod = -1;
+ const WideChar fixed = fixedButtonKey( AsciiString( withoutModPrefix( lower.str(), &mod ).c_str() ), types[ each ] );
+ if( isOneOf( fixed, GRID_FIXED_KEYS, fixedCount ) )
+ used[ usedCount++ ] = fixed;
+ }
+
+ for( Int slot = 0; slot < GRID_KEY_COUNT; slot++ )
+ lent[ slot ] = 0;
+ // a place takes the order's letter that usually stands there first: attack move's A, then guard's
+ // G or the rally point's Y; then any fixed letter still free, in GRID_FIXED_KEYS' order
+ static const struct { Int slot; WideChar letter; } OWN[] = { { 10, 'A' }, { 12, 'G' }, { 12, 'Y' } };
+ for( Int pass = 0; pass < 2; pass++ )
+ {
+ const Int choices = pass == 0 ? (Int)( sizeof( OWN ) / sizeof( OWN[ 0 ] ) ) : GRID_KEY_COUNT * fixedCount;
+ for( Int each = 0; each < choices; each++ )
+ {
+ const Int slot = pass == 0 ? OWN[ each ].slot : each / fixedCount;
+ const WideChar letter = pass == 0 ? OWN[ each ].letter : GRID_FIXED_KEYS[ each % fixedCount ];
+ if( GRID_KEYS[ slot ] != 0 || lent[ slot ] != 0 || isOneOf( letter, used, usedCount ) )
+ continue;
+ lent[ slot ] = letter;
+ used[ usedCount++ ] = letter;
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+void HotKeyManager::lendFixedKeys( const AsciiString *buttons, const Int *types, Int count )
+{
+ if( buttons == NULL )
+ {
+ for( Int slot = 0; slot < GRID_KEY_COUNT; slot++ )
+ s_lentKeys[ slot ] = 0;
+ return;
+ }
+ gridLentKeys( buttons, types, count, s_lentKeys );
}
//-----------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 4964ebb36..4d85f2280 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -4167,6 +4167,43 @@ TEST(controlbar_grid_packs_keyless_buttons_into_keyed_windows)
CHECK_EQ( shown[ slot ], slot );
}
+/* A bar without attack move, guard or rally point lends their letters to the keyless places 11 and
+ 13; a unit's bar, which has them, keeps A and G on its own orders */
+TEST(grid_keyless_places_borrow_the_fixed_letters_a_bar_has_no_order_for)
+{
+ enum { SLOTS = MAX_COMMANDS_PER_SET, PLACES = 14 };
+ AsciiString names[ SLOTS ];
+ Int types[ SLOTS ];
+ WideChar lent[ PLACES ];
+ for( Int slot = 0; slot < SLOTS; slot++ )
+ types[ slot ] = GUI_COMMAND_NONE;
+
+ // War Factory: units, TOW, rally point, sell
+ names[ 0 ] = "Command_ConstructAmericaTankCrusader"; types[ 0 ] = GUI_COMMAND_UNIT_BUILD;
+ names[ 10 ] = "Command_UpgradeAmericaTOWMissile"; types[ 10 ] = GUI_COMMAND_OBJECT_UPGRADE;
+ names[ 12 ] = "Command_SetRallyPoint"; types[ 12 ] = GUI_COMMAND_SET_RALLY_POINT;
+ names[ 13 ] = "Command_Sell"; types[ 13 ] = GUI_COMMAND_SELL;
+ HotKeyManager::gridLentKeys( names, types, SLOTS, lent );
+ CHECK_EQ( (Int)lent[ 10 ], (Int)'A' );
+ CHECK_EQ( (Int)lent[ 12 ], (Int)'G' );
+ for( Int slot = 0; slot < PLACES; slot++ )
+ if( slot != 10 && slot != 12 )
+ CHECK_EQ( (Int)lent[ slot ], 0 );
+
+ // a unit with attack move, guard and stop: A and G are its own, the places borrow what is left
+ for( Int slot = 0; slot < SLOTS; slot++ )
+ {
+ names[ slot ].clear();
+ types[ slot ] = GUI_COMMAND_NONE;
+ }
+ names[ 10 ] = "Command_AttackMove"; types[ 10 ] = GUI_COMMAND_ATTACK_MOVE;
+ names[ 12 ] = "Command_Guard"; types[ 12 ] = GUI_COMMAND_GUARD;
+ names[ 13 ] = "Command_Stop"; types[ 13 ] = GUI_COMMAND_STOP;
+ HotKeyManager::gridLentKeys( names, types, SLOTS, lent );
+ CHECK_EQ( (Int)lent[ 12 ], (Int)'Y' );
+ CHECK_EQ( (Int)lent[ 10 ], (Int)'V' );
+}
+
TEST(controlbar_stance_key_takes_what_the_buttons_leave)
{
enum { SLOTS = 14 };