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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameclient): grid keys pack keyless bar buttons into keyed places
Olcay Seyganbaaa9eaa8f2b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d26c229cb..5496b7938 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 a button that lands there has no key. 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, 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.## The command bar moves to the middlediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 556029512..a6ea9fd0d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -507,6 +507,12 @@ Bool ControlBar_commandPlaces( const Int *types, const Int *groups, const Int *p* when free, anything else to the first empty one. */void ControlBar_fitCommandSlots( const Int *types, const Bool *windowed, Int count, Int *shown );+/** Grid keys' second pass over ControlBar_fitCommandSlots' `shown`: a button in window w with no key+ * there (`unkeyed[ w ]`) moves to the first empty window, leftmost first, whose place has a key+ * (`keyed`), so a set that leaves the keyless top of the last two columns busy and a keyed window+ * free gets a key for every button. A button with nowhere to go stays put. */+void ControlBar_packKeyedSlots( const Bool *keyed, const Bool *unkeyed, Int count, Int *shown );+/** The page's keys past attack, hold position and move, which no command set has a button for either. */enum OrderKeyExtra{diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.hindex 3472b6d55..8577a9174 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h@@ -119,6 +119,10 @@ public:static WideChar playerButtonKey( const AsciiString& button, WideChar labelKey, Int barSlot,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. */+ static WideChar gridSlotKey( Int barSlot );+private:typedef std::map<AsciiString, HotKey> HotKeyMap;HotKeyMap m_hotKeyMap;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex c05cfc5b8..f60d808b1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -415,6 +415,25 @@ void ControlBar_fitCommandSlots( const Int *types, const Bool *windowed, Int cou}}+//-------------------------------------------------------------------------------------------------+void ControlBar_packKeyedSlots( const Bool *keyed, const Bool *unkeyed, Int count, Int *shown )+{+ for( Int from = 0; from < count; from++ )+ {+ if( !unkeyed[ from ] || shown[ from ] < 0 )+ continue;+ for( Int to = 0; to < count; to++ )+ {+ if( keyed[ to ] && shown[ to ] < 0 )+ {+ shown[ to ] = shown[ from ];+ shown[ from ] = -1;+ break;+ }+ }+ }+}+//-------------------------------------------------------------------------------------------------void ControlBar_orderKeyPlaces( const Int *places, Int count, Bool fights, Int *keys ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cppindex c76e579d2..8082aedc4 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -62,6 +62,7 @@#include "GameClient/GameWindow.h"#include "GameClient/GameWindowManager.h"#include "GameClient/GadgetPushButton.h"+#include "GameClient/HotKey.h"#include "GameClient/Image.h"#ifdef _INTERNAL@@ -397,8 +398,25 @@ void ControlBar::populateCommand( Object *obj )windowed[ i ] = m_commandWindows[ i ] != NULL;}ControlBar_fitCommandSlots( types, windowed, MAX_COMMANDS_PER_SET, shown );++ // with grid keys on a button on a keyless place moves to a free keyed one, so the right of the+ // bar does not keep buttons without a key. A passenger's way out stays where the transport+ // code put it. Client side only: the bar's layout reaches no logic+ Bool keyed[ MAX_COMMANDS_PER_SET ];+ Bool unkeyed[ MAX_COMMANDS_PER_SET ];+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ {+ keyed[ i ] = windowed[ i ] && HotKeyManager::gridSlotKey( i ) != 0;+ const CommandButton *button = shown[ i ] >= 0 ? set[ shown[ i ] ] : NULL;+ unkeyed[ i ] = keyed[ i ] == FALSE && button && button->getCommandType() != GUI_COMMAND_EXIT_CONTAINER &&+ HotKeyManager::playerButtonKey( button->getName(), 0, i, button->getCommandType() ) == 0;+ }+ ControlBar_packKeyedSlots( keyed, unkeyed, MAX_COMMANDS_PER_SET, shown );++ // a window nothing is fitted to stays empty: its own slot is empty or script only, or its+ // button was just packed awayfor( i = 0; i < MAX_COMMANDS_PER_SET; i++ )- slot[ i ] = shown[ i ] >= 0 ? set[ shown[ i ] ] : set[ i ];+ slot[ i ] = shown[ i ] >= 0 ? set[ shown[ i ] ] : NULL;}// populate the button with commands defineddiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cppindex b0a560db9..ca256aa8e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp@@ -450,6 +450,12 @@ WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar labreturn letter;}+//-----------------------------------------------------------------------------+WideChar HotKeyManager::gridSlotKey( Int barSlot )+{+ return s_commandGrid && barSlot >= 0 && barSlot < GRID_KEY_COUNT ? GRID_KEYS[ barSlot ] : 0;+}+//-----------------------------------------------------------------------------/** CommandBarGrid, Enabled = Yes or No, End. Only the player's own Hotkeys.ini carries it, and* nothing in it reaches the INI CRC. */diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 3c0cadbac..4964ebb36 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -4132,6 +4132,41 @@ TEST(controlbar_mod_slots_past_the_bar_fit_its_windows)CHECK_EQ( shown[ slot ], humvee[ slot ] != N && slot < WINDOWS ? slot : -1 );}+/* Grid keys leave windows 11 and 13 keyless. The USA War Factory's TOW upgrade in 11 moves to the+ first free keyed window, leftmost first; attack move in 11 has its own A and is never unkeyed */+TEST(controlbar_grid_packs_keyless_buttons_into_keyed_windows)+{+ enum { SLOTS = MAX_COMMANDS_PER_SET, WINDOWS = 14 };+ Bool keyed[ SLOTS ];+ Bool unkeyed[ SLOTS ];+ Int shown[ SLOTS ];+ for( Int slot = 0; slot < SLOTS; slot++ )+ {+ keyed[ slot ] = slot < WINDOWS && slot != 10 && slot != 12;+ unkeyed[ slot ] = FALSE;+ shown[ slot ] = -1;+ }+ // eight units in 1-8, TOW in 11, rally point in 13 (its own Y), sell in 14+ for( Int slot = 0; slot < 8; slot++ )+ shown[ slot ] = slot;+ shown[ 10 ] = 10;+ shown[ 12 ] = 12;+ shown[ 13 ] = 13;+ unkeyed[ 10 ] = TRUE;+ ControlBar_packKeyedSlots( keyed, unkeyed, SLOTS, shown );+ CHECK_EQ( shown[ 8 ], 10 );+ CHECK_EQ( shown[ 10 ], -1 );+ CHECK_EQ( shown[ 12 ], 12 );+ CHECK_EQ( shown[ 13 ], 13 );++ // a full keyed block leaves the button where it is+ for( Int slot = 0; slot < WINDOWS; slot++ )+ shown[ slot ] = slot;+ ControlBar_packKeyedSlots( keyed, unkeyed, SLOTS, shown );+ for( Int slot = 0; slot < WINDOWS; slot++ )+ CHECK_EQ( shown[ slot ], slot );+}+TEST(controlbar_stance_key_takes_what_the_buttons_leave){enum { SLOTS = 14 };