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): hotkeys page lists the wide bar's eighteen windows
Olcay Seygan58629ee0ed6f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f224afd6f..779f07371 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -419,7 +419,7 @@ found and fixed, EA's own, not port damage.**- The Hotkeys page is in the game as well, as the last tab of the options screen, so a key can move without quitting to the launcher: from the main menu, or from Esc in the middle of a match. Every command sits on the left with its key. On the right you pick a general and one of his buildings or units, and its command bar is listed button by button, each with its cameo and its letter. Double-click a line, or press Enter or Change, and then the key; Esc lets go. Two buttons of one bar on one letter, or two commands on one key, turn red, and the line under the lists names them. Accept writes the file the launcher writes, so a key set in either place is there in the other, and a key changed in a match works from the next press.- 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.- The arrow keys scroll the camera in the German game, as they do in English. German Zero Hour put next and previous unit and worker on the bare arrows, so the arrows picked units and only Ctrl and an arrow moved the camera; those four now sit on Ctrl and an arrow, as the English game ships them. Any language that puts a command on a bare arrow gets the same, and an arrow you gave a command yourself on the Hotkeys page stays where you put it.-- Grid keys are back, keyed by the cell a button sits in. The first grid moved buttons around to give them a place's letter and still left two places without one; this one moves nothing. With the grid on, the top row of the bar is Q W E R T Y U and the bottom row A S D F G H J, column by column, so the first cell is Q on a Barracks, a War Factory and a tank alike, and the cell under it A. A mod's nine-column bar adds I O over K L. Upgrades take X C V B N in the order they stand on the bar, so the first upgrade of any building is X. The fixed keys step aside on the bar: attack move and stop take their cells' letters like every other button, while Ctrl still forces an attack. A letter you give a button still beats its cell, and a letter can now go to one cell alone, which is what a transport needs: its passengers' exit buttons are all one button, and with a key per cell the third passenger out can be M while the rest keep the grid. Accept on the in-game Hotkeys tab keeps the grid and every per-cell key, and the tab's list shows the grid's letters.+- Grid keys are back, keyed by the cell a button sits in. The first grid moved buttons around to give them a place's letter and still left two places without one; this one moves nothing. With the grid on, the top row of the bar is Q W E R T Y U and the bottom row A S D F G H J, column by column, so the first cell is Q on a Barracks, a War Factory and a tank alike, and the cell under it A. A mod's nine-column bar adds I O over K L. Upgrades take X C V B N in the order they stand on the bar, so the first upgrade of any building is X. The fixed keys step aside on the bar: attack move and stop take their cells' letters like every other button, while Ctrl still forces an attack. A letter you give a button still beats its cell, and a letter can now go to one cell alone, which is what a transport needs: its passengers' exit buttons are all one button, and with a key per cell the third passenger out can be M while the rest keep the grid. Accept on the in-game Hotkeys tab keeps the grid and every per-cell key, and the tab's list shows the grid's letters. On a mod's nine-column bar it now lists every cell the bar has, up to eighteen, each button on the letter the bar gives it, I O K L included. It used to squeeze the bar into fourteen, so an order the bar keeps in the last column was listed on another letter, and a key you gave one of the last four cells never showed.- W no longer starts a War Factory. The launcher had moved China's War Factory onto W, which Zero Hour already gives to Select all aircraft. With a tank selected and no aircraft on the map, W dropped the tank, the idle worker's bar took its place, and the same press let go on that bar's War Factory. The launcher now keeps the buttons it moves off every letter a keyboard command holds on its own, W, Q and the idle worker's I among them, and China's War Factory sits on D. Start the launcher once and it rewrites its part of the file. A letter you picked yourself stays where you put it. The game now settles it for any letter, yours and the grid's included: a key press does one thing. If a button on the bar wears the letter when the key goes down, the button gets it and the keyboard command on that letter waits; if none does, the command fires and the bar that comes up after it is left alone. A button that loses its letter to another, on the bar or the strip of general's powers, shows no letter instead of one that does nothing. With nothing selected, the worker's buildings that the bar shows anyway step off any letter a keyboard command uses on its own: on the grid, Q selects everything and W every aircraft again instead of putting down a Power Plant or a Barracks, and the buildings on free letters keep them.## The command bar moves to the middlediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 5a7c36070..712d961e7 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -525,6 +525,11 @@ enum* only one of Zero Hour's with a slot past 14, is laid out on its own screen and never counts. */Bool ControlBar_needsWideCommandGrid( const Int *types, Int count );+/** Whether the bar uses its window for `slot`. spareWindows: our layout's 15 to 18 stand hidden past+ * the plate, which a mod's own ControlBar.wnd does not do; wide: ControlBar::isCommandGridWide. Our+ * narrow bar is the only one that leaves windows out. */+Bool ControlBar_usesCommandWindow( Int slot, Bool spareWindows, Bool wide );+/** Slot 12 (0-based 11) when the set already has Attack Move and that hole is empty: left of Stop,* under Attack Move. An object ControlBar_forceFires names takes 12 too, or 11 above it when 12 is* taken (Gattling Cannon's mines, Stinger Site's camo net, Fire Base's Sell). -1 when neither@@ -1073,6 +1078,9 @@ public:* scheme draws its painting's <name>Wide copy. Fixed when the windows are looked up. */Bool isCommandGridWide( void ) const { return m_commandGridWide; }+ /// Whether command set slot `slot` has a window on this bar, for what lays a set out without an object.+ Bool hasCommandWindow( Int slot ) const { return m_commandWindows[ slot ] != NULL; }+/// top edge of the highest visible window the bar owns, and where MoneyDisplay is; see -uidrillvoid forEachPlacedWindow( Int *topOut, Int *moneyOut );ControlBarContext getCurrentContext( void ) const { return m_currContext; } ///< for -uidrill's logdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex b3cf6347e..fd05b6745 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -485,6 +485,12 @@ Bool ControlBar_needsWideCommandGrid( const Int *types, Int count )return buttons > COMMAND_GRID_NARROW_SLOTS;}+//-------------------------------------------------------------------------------------------------+Bool ControlBar_usesCommandWindow( Int slot, Bool spareWindows, Bool wide )+{+ return !spareWindows || wide || slot < COMMAND_GRID_NARROW_SLOTS;+}+//-------------------------------------------------------------------------------------------------Int ControlBar_forceAttackSlot( const Int *types, Int count, Bool forceFires ){@@ -2692,8 +2698,8 @@ void ControlBar::initWindows( void )} // end for i// the narrow grid leaves our spare four hidden and out of the bar's reach, the bar it always was- if( spareWindows && !m_commandGridWide )- for( i = COMMAND_GRID_NARROW_SLOTS; i < MAX_COMMANDS_PER_SET; i++ )+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ if( !ControlBar_usesCommandWindow( i, spareWindows, m_commandGridWide ) )m_commandWindows[ i ] = NULL;Int windowCount = 0;for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cppindex 56494f7d9..8e7791916 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp@@ -52,7 +52,7 @@namespace{-enum { BAR_SLOTS = 14 }; ///< ControlBar.wnd's ButtonCommand01 to 14; 15 to 18 are for scripts+enum { BAR_SLOTS = MAX_COMMANDS_PER_SET }; ///< ButtonCommand01 to 18; which of them the bar uses is ControlBar::hasCommandWindowstruct BarObject{@@ -303,11 +303,11 @@ void findBars( void )}// the windows as the bar fills them (ControlBar::populateCommand), so a slot here is the// slot a Name@slot key and the grid's letters mean: a set's button past the bar's- // windows moves into an empty one+ // windows moves into an empty one. A mod's wide bar has all eighteen.Bool windowed[ MAX_COMMANDS_PER_SET ];Int shown[ MAX_COMMANDS_PER_SET ];for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )- windowed[ slot ] = slot < BAR_SLOTS;+ windowed[ slot ] = TheControlBar->hasCommandWindow( slot );ControlBar_fitCommandSlots( types, windowed, MAX_COMMANDS_PER_SET, shown );BarObject object;object.building = thing->isKindOf( KINDOF_STRUCTURE );@@ -463,10 +463,10 @@ void fillButtons( void )}const std::map< std::string, WideChar > keys = buttonKeys();const std::map< KeyText, std::vector< UnicodeString > > clashes = barClashes( object );- // a cameo is 61 by 48 on the bar; a third of that keeps fourteen rows to a short scroll+ // a cameo is 61 by 48 on the bar; a third of that keeps a bar's rows, eighteen on a mod's wide one, to a short scrollconst Int height = 22;Int selectedRow = -1;- // the bar's own order: two rows of seven read down each column, 1 over 2+ // the bar's own order: two rows, seven or nine across, read down each column, 1 over 2for( Int slot = 0; slot < BAR_SLOTS; slot++ ){const CommandButton *button = object->slots[ slot ];diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 6fc87ec77..189299ac7 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -5415,6 +5415,80 @@ TEST(controlbar_wide_grid_only_for_a_set_past_fourteen)CHECK( ControlBar_needsWideCommandGrid( full, SLOTS ) );}+/* What the options menu's Hotkeys page lists for a set: each window's letter, in the steps findBars and+ buttonKeyText take, on the windows the game's decision leaves the bar. 0 for an empty window. */+static void hotkeysPageLetters( const Int *types, Bool spareWindows, Bool wide,+ const std::map< std::string, WideChar >& keys, WideChar *letters )+{+ enum { SLOTS = MAX_COMMANDS_PER_SET };+ Bool windowed[ SLOTS ];+ Int shown[ SLOTS ], windowTypes[ SLOTS ], ranks[ SLOTS ];+ for( Int slot = 0; slot < SLOTS; slot++ )+ windowed[ slot ] = ControlBar_usesCommandWindow( slot, spareWindows, wide );+ ControlBar_fitCommandSlots( types, windowed, SLOTS, shown );+ for( Int slot = 0; slot < SLOTS; slot++ )+ windowTypes[ slot ] = shown[ slot ] >= 0 ? types[ shown[ slot ] ] : GUI_COMMAND_NONE;+ HotKeyManager::commandBarUpgradeRanks( windowTypes, SLOTS, ranks );+ for( Int slot = 0; slot < SLOTS; slot++ )+ letters[ slot ] = shown[ slot ] >= 0+ ? HotKeyManager::buttonKeyIn( AsciiString( "Command_Synthetic" ), 'Z', windowTypes[ slot ], keys, slot, ranks[ slot ] ) : 0;+}++/* The expected letters, one a window, '.' for an empty one */+static void checkHotkeysPageLetters( const WideChar *letters, const char *expected )+{+ for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )+ CHECK_EQ( letters[ slot ], (WideChar)( expected[ slot ] == '.' ? 0 : expected[ slot ] ) );+}++/* A synthetic mod. Its sets are made up for this test, shaped like a mod drawn for eighteen windows;+ no mod's data is read here */+TEST(hotkeys_page_shows_the_wide_bar_windows_and_letters)+{+ enum { SLOTS = MAX_COMMANDS_PER_SET };+ const Int N = GUI_COMMAND_NONE, B = GUI_COMMAND_UNIT_BUILD, U = GUI_COMMAND_OBJECT_UPGRADE, W = GUI_COMMAND_SWITCH_WEAPON;+ const Int A = GUI_COMMAND_ATTACK_MOVE, G = GUI_COMMAND_GUARD, S = GUI_COMMAND_STOP, P = GUI_COMMAND_SPECIAL_POWER;+ std::map< std::string, WideChar > keys;+ WideChar letters[ SLOTS ];++ // the set that makes the bar wide: seventeen buttons, the columns' letters past fourteen+ const Int factory[ SLOTS ] = { B, B, B, B, B, B, B, B, B, B, B, B, B, B, A, N, G, S };+ CHECK( ControlBar_needsWideCommandGrid( factory, SLOTS ) );+ // a bar is wide for all its sets: this one needs no wide bar and still stands on one+ const Int soldier[ SLOTS ] = { U, U, U, U, U, N, P, W, N, W, N, N, N, N, A, N, G, S };+ CHECK( !ControlBar_needsWideCommandGrid( soldier, SLOTS ) );++ HotKeyManager::setCommandBarGrid( TRUE );+ hotkeysPageLetters( factory, TRUE, TRUE, keys, letters );+ checkHotkeysPageLetters( letters, "QAWSEDRFTGYHUJI.OL" );+ hotkeysPageLetters( soldier, TRUE, TRUE, keys, letters );+ checkHotkeysPageLetters( letters, "XCVBN.RF.G....I.OL" );++ // the same sets on fourteen windows: the orders move, and three of the factory's seventeen have no window+ hotkeysPageLetters( factory, TRUE, FALSE, keys, letters );+ checkHotkeysPageLetters( letters, "QAWSEDRFTGYHUJ...." );+ hotkeysPageLetters( soldier, TRUE, FALSE, keys, letters );+ checkHotkeysPageLetters( letters, "XCVBN.RF.GY.UJ...." );++ // a mod's own ControlBar.wnd keeps all it drew, whatever the sets need+ hotkeysPageLetters( soldier, FALSE, FALSE, keys, letters );+ checkHotkeysPageLetters( letters, "XCVBN.RF.G....I.OL" );++ // a key for a window past fourteen counts on the wide bar alone+ keys[ "command_synthetic@15" ] = 'M';+ hotkeysPageLetters( soldier, TRUE, TRUE, keys, letters );+ CHECK_EQ( letters[ 14 ], (WideChar)'M' );+ hotkeysPageLetters( soldier, TRUE, FALSE, keys, letters );+ checkHotkeysPageLetters( letters, "XCVBN.RF.GY.UJ...." );+ keys.clear();+ HotKeyManager::setCommandBarGrid( FALSE );++ // a set of Zero Hour's on its bar: every button stays in its window, the fixed letters on the orders+ const Int humvee[ SLOTS ] = { U, U, U, N, N, N, N, N, GUI_COMMAND_EVACUATE, N, A, N, G, S, N, N, N, N };+ hotkeysPageLetters( humvee, TRUE, FALSE, keys, letters );+ checkHotkeysPageLetters( letters, "ZZZ.....V.A.GS...." );+}+TEST(controlbar_force_attack_slot_is_under_attack_move){enum { SLOTS = MAX_COMMANDS_PER_SET, WINDOWS = 14 };