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.

fix(gameengine): let every fixed command bar key be rebound

Olcay Seygan356e7f9a2a6c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7939315de..c0ae18c7d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -141,6 +141,7 @@ found and fixed — EA's own, not port damage.**
- A box round your soldiers leaves the worker among them behind again. The rule that a box holding anything military drops the dozers, workers, supply trucks, Chinooks and hackers from it was switched off for the Classic mouse, which is the one every player now runs, so the dozer came along with the tanks. It holds for every box now, a Shift box added to a selection included. A box of workers alone still takes the workers, and a click or a double click on one still takes it.
- 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 all your infantry, vehicles 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 18 letters under your left hand where the bar leaves room (the Avenger is J now), and no bar gained a clash doing it. Those letters are still yours to hand out: the Hotkeys page gives A or H to any other button you pick, and marks the clash. On a bar that has the order as well, the order keeps its key: a Barracks button on A fires from A, and a tank's A is still attack move.
+- Those orders move too. Sell, attack move, stop, guard, rally point, evacuate, combat drop, the mines, camo netting and the fake building switch were locked to their letters: the Hotkeys tab refused to wait for a key on them, and a letter given to one in the file was ignored in the match. Each one now takes the letter you give it, or none, on the Hotkeys tab like any other button, and keeps it after a restart; the letters above are only where they start. A letter you set also beats the one a button had from the game: Sell moved to K on the GLA Command Center used to lose K to the Worker button, and now sells.
- 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.
- Grid keys are gone. The switch that made a button's key its place on the bar, Q for the first button of every building, is off the Hotkeys page, and the game no longer moves buttons around to give them a place's letter. Each button wears the letter you gave it or the game's own, and the fixed keys above still hold. A hotkeys file saved with grid keys on loads as before, with the switch ignored, so a player who had them on finds the letters of their own buttons back on the bar.
diff --git a/GeneralsMD/Code/Data/German/Generals.str b/GeneralsMD/Code/Data/German/Generals.str
index e2380b0c7..bf0bec6d0 100644
--- a/GeneralsMD/Code/Data/German/Generals.str
+++ b/GeneralsMD/Code/Data/German/Generals.str
@@ -15070,7 +15070,7 @@ GUI:HotkeysPressForceAttack
END
GUI:HotkeysClash
-"%s: %s teilen sich diese Taste. Im Spiel bekommt sie nur einer davon, und ein fester Befehl behält seine eigene."
+"%s: %s teilen sich diese Taste. Im Spiel bekommt sie nur einer davon: ein fester Befehl behält seine eigene, und ein Buchstabe von dir schlägt den des Spiels."
END
GUI:HotkeysAlsoOn
@@ -15078,7 +15078,7 @@ GUI:HotkeysAlsoOn
END
GUI:HotkeysFixed
-"Feste Tasten auf jeder Leiste: A Angriffsmarsch, S Stopp, G Bewachen, Y Sammelpunkt, V Evakuieren, C Abseilen, N Verkaufen, H Minen, Tarnnetz und der Wechsel zur Attrappe."
+"Dieselbe Vorgabe auf jeder Leiste: A Angriffsmarsch, S Stopp, G Bewachen, Y Sammelpunkt, V Evakuieren, C Abseilen, N Verkaufen, H Minen, Tarnnetz und der Wechsel zur Attrappe. Ändern verlegt sie."
END
GUI:HotkeysGameKey
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 114e2eb77..bddba7b50 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1429,7 +1429,7 @@ GUI:HotkeysPressForceAttack
END
GUI:HotkeysClash
-"%s: %s share this key. Only one of them gets it in the game, and a fixed order keeps its own."
+"%s: %s share this key. Only one of them gets it in the game: a fixed order keeps its own, and a letter you set beats the game's."
END
GUI:HotkeysAlsoOn
@@ -1437,7 +1437,7 @@ GUI:HotkeysAlsoOn
END
GUI:HotkeysFixed
-"A fixed key on every bar: A attack move, S stop, G guard, Y rally point, V evacuate, C combat drop, N sell, H mines, camo netting and the fake switch."
+"The same default on every bar: A attack move, S stop, G guard, Y rally point, V evacuate, C combat drop, N sell, H mines, camo netting and the fake switch. Change moves it."
END
GUI:HotkeysGameKey
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index 70bd820e3..24cd36afd 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15826,7 +15826,7 @@ GUI:HotkeysPressForceAttack
END
GUI:HotkeysClash
-"%s: %s aynı tuşu kullanıyor. Oyunda tuş yalnızca birinde çalışır, sabit emir kendi tuşunu korur."
+"%s: %s aynı tuşu kullanıyor. Oyunda tuş yalnızca birinde çalışır: sabit emir kendi tuşunu korur, senin verdiğin harf oyununkinden önce gelir."
END
GUI:HotkeysAlsoOn
@@ -15834,7 +15834,7 @@ GUI:HotkeysAlsoOn
END
GUI:HotkeysFixed
-"Her çubukta sabit tuş: A saldırarak ilerle, S dur, G koru, Y toplanma noktası, V boşalt, C çatışma inişi, N sat, H mayın, kamuflaj ağı ve sahte bina geçişi."
+"Her çubukta aynı varsayılan tuş: A saldırarak ilerle, S dur, G koru, Y toplanma noktası, V boşalt, C çatışma inişi, N sat, H mayın, kamuflaj ağı ve sahte bina geçişi. Değiştir ile taşınır."
END
GUI:HotkeysGameKey
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
index ebe66b91b..8c7c951f6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
@@ -115,9 +115,10 @@ public:
/** The key a command button gets: the one the player gave it in Hotkeys.ini (the launcher's
* Hotkeys page writes it, INI::parseCommandButtonHotKeyDefinition reads it), 0 where the player
* took the key away, and labelKey, the letter after the label's '&', where the player left the
- * button alone; upper case. Attack move, stop, guard, rally point, evacuate and sell have their
- * fixed letters; another button gets one only from the player, and loses it to the fixed order
- * on a bar holding both (addHotKey). Force Attack is 0: it is Ctrl, painted on the
+ * button alone; upper case. Attack move, stop, guard, rally point, evacuate and sell have fixed
+ * letters in place of the label's, which the player's own letter still overrides; another button
+ * gets one only from the player, and loses it to the fixed order on a bar holding both
+ * (addHotKey). Force Attack is 0: it is Ctrl, painted on the
* cameo, never a letter. */
static WideChar playerButtonKey( const AsciiString& button, WideChar labelKey, Int commandType );
/// playerButtonKey over `keys` (lower case button name to letter, 0 for none) in place of the file's
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp
index c6192b07b..6e41ec0ad 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp
@@ -536,21 +536,21 @@ void updateNote( void )
else if( s_active == 1 && s_button )
{
const Bool force = s_button->getCommandType() == GUI_COMMAND_FORCE_ATTACK;
- const Bool fixed = !force && HotKeyManager::fixedKey( s_button->getName(), s_button->getCommandType() ) != 0;
+ const WideChar fixed = force ? 0 : HotKeyManager::fixedKey( s_button->getName(), s_button->getCommandType() );
const std::string name = HotKeyManager::fileButtonName( s_button->getName() );
changed = force ? s_file.commands.count( "BEGIN_FORCEATTACK" ) != 0 : s_file.buttons.count( name ) != 0;
- canChange = !fixed;
+ canChange = TRUE;
if( s_capture == CAPTURE_BUTTON )
note = TheGameText->fetch( force ? "GUI:HotkeysPressForceAttack" : "GUI:HotkeysPressLetter" );
- else if( fixed )
- note = TheGameText->fetch( "GUI:HotkeysFixed" );
else if( force )
note = TheGameText->fetch( "GUI:HotkeysForceAttack" );
else if( changed )
{
- const UnicodeString key = letterText( TheGameText->fetchEnglishHotKey( s_button->getTextLabel() ) );
+ const UnicodeString key = letterText( fixed != 0 ? fixed : TheGameText->fetchEnglishHotKey( s_button->getTextLabel() ) );
note.format( TheGameText->fetch( "GUI:HotkeysGameKey" ), key.isEmpty() ? TheGameText->fetch( "GUI:HotkeysNone" ).str() : key.str() );
}
+ else if( fixed != 0 )
+ note = TheGameText->fetch( "GUI:HotkeysFixed" );
else if( s_launcherButtons.count( name ) )
note = TheGameText->fetch( "GUI:HotkeysButtonMoved" );
}
@@ -587,8 +587,7 @@ void startCapture( void )
{
if( s_active == 0 && s_commandRow >= 0 )
s_capture = CAPTURE_COMMAND;
- else if( s_active == 1 && s_button && ( s_button->getCommandType() == GUI_COMMAND_FORCE_ATTACK
- || HotKeyManager::fixedKey( s_button->getName(), s_button->getCommandType() ) == 0 ) )
+ else if( s_active == 1 && s_button )
s_capture = CAPTURE_BUTTON;
else
return;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
index c814ad41e..135a4b1ab 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
@@ -190,7 +190,7 @@ void HotKeyManager::reset( void )
m_hotKeyMap.clear();
}
-static Bool ownsFixedKey( GameWindow *win, const AsciiString& key );
+static Int keyClaim( GameWindow *win, const AsciiString& key );
//-----------------------------------------------------------------------------
void HotKeyManager::addHotKey( GameWindow *win, const AsciiString& keyIn)
@@ -198,9 +198,9 @@ void HotKeyManager::addHotKey( GameWindow *win, const AsciiString& keyIn)
AsciiString key = keyIn;
key.toLower();
HotKeyMap::iterator it = m_hotKeyMap.find(key);
- // two buttons on one letter is the player's choice on the Hotkeys page, which marks it: the
- // first keeps the key, except that a fixed order takes its own letter back
- if( it != m_hotKeyMap.end() && !ownsFixedKey( win, key ) )
+ // two buttons on one letter, which the Hotkeys page marks: a fixed order on its own letter keeps
+ // it, a letter the player gave beats a label's, and between equals the first keeps it
+ if( it != m_hotKeyMap.end() && keyClaim( win, key ) <= keyClaim( it->second.m_win, key ) )
{
DEBUG_LOG(( "HOTKEYS: %s already on %s, not on %s\n", key.str(), it->second.m_win->winGetInstanceData()->m_decoratedNameString.str(), win->winGetInstanceData()->m_decoratedNameString.str() ));
return;
@@ -334,10 +334,11 @@ static std::map< std::string, WideChar > s_playerButtonKeys;
/** The owner's fixed keys, 2026-10-12, 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's fake
- * and real switches, which go by button name. No button keeps one of these letters from its
- * label; the player may give one to any button on the launcher's Hotkeys page, and on a bar where
- * the fixed order stands too, the order gets the key (addHotKey). The launcher holds the same
- * table (hotkeys.js, FIXED_KEYS). */
+ * and real switches, which go by button name. They are defaults: the player may move any of these
+ * orders to another letter, or none, like every other button. No button keeps one of these
+ * letters from its label; the player may give one to any button, and on a bar where the fixed order
+ * stands too, the order gets the key (addHotKey). The launcher holds the same table (hotkeys.js,
+ * FIXED_KEYS). */
static const WideChar FIXED_KEYS[] = { 'A', 'S', 'G', 'Y', 'V', 'N', 'C', 'H' };
static const char *const FIXED_H_BUTTONS[] =
{
@@ -398,16 +399,23 @@ static std::string withoutModPrefix( const char *lowerName, Int *mod )
return tilde + 1;
}
-/** Whether win is a command button whose fixed letter (fixedButtonKey) is key, the map's lower
- * case name. */
-static Bool ownsFixedKey( GameWindow *win, const AsciiString& key )
+static Bool findPlayerKey( const std::map< std::string, WideChar >& keys, const std::string& bare, Int ownMod, WideChar *letter );
+
+/** How strongly the command button win holds key, the map's lower case name: 2 when it is the
+ * button's fixed letter (fixedButtonKey) and the player left the button alone, 1 when the player
+ * gave it that letter in Hotkeys.ini, 0 for the label's. */
+static Int keyClaim( GameWindow *win, const AsciiString& key )
{
const CommandButton *command = (const CommandButton *)GadgetButtonGetData( win );
AsciiString lower = command->getName();
lower.toLower();
Int mod = -1;
- const WideChar fixed = fixedButtonKey( AsciiString( withoutModPrefix( lower.str(), &mod ).c_str() ), command->getCommandType() );
- return fixed != 0 && HotKeyManager::nameOf( fixed ) == key;
+ const std::string bare = withoutModPrefix( lower.str(), &mod );
+ WideChar letter = 0;
+ if( findPlayerKey( s_playerButtonKeys, bare, mod, &letter ) )
+ return letter != 0 && HotKeyManager::nameOf( letter ) == key ? 1 : 0;
+ const WideChar fixed = fixedButtonKey( AsciiString( bare.c_str() ), command->getCommandType() );
+ return fixed != 0 && HotKeyManager::nameOf( fixed ) == key ? 2 : 0;
}
/** The player's key for a button, into *letter; FALSE leaves it alone. A mod's own button (ownMod,
@@ -487,12 +495,15 @@ WideChar HotKeyManager::buttonKeyIn( const AsciiString& button, WideChar labelKe
lower.toLower();
Int ownMod = -1;
const std::string bare = withoutModPrefix( lower.str(), &ownMod );
- const WideChar fixed = fixedButtonKey( AsciiString( bare.c_str() ), commandType );
- if( fixed != 0 )
- return fixed;
-
+ // the player's letter first, a fixed order's included: the fixed letter is only its default
WideChar letter = labelKey;
const Bool chosen = findPlayerKey( keys, bare, ownMod, &letter );
+ if( !chosen )
+ {
+ const WideChar fixed = fixedButtonKey( AsciiString( bare.c_str() ), commandType );
+ if( fixed != 0 )
+ return fixed;
+ }
if( letter >= 'a' && letter <= 'z' )
letter -= 'a' - 'A';
// a label's own fixed letter gives way; one the player chose stays, and the bar's fixed order
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 302d599c6..ccc5d7d6e 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -1900,6 +1900,36 @@ TEST(hotkeys_names_sort_and_chords_read_as_the_launcher_has_them)
CHECK( Hotkeys_isKeyName( "KEY_PGDN" ) && !Hotkeys_isKeyName( "KEY_NONE" ) && !Hotkeys_isKeyName( "KEY_LCTRL" ) );
}
+/* HotKey.cpp: a fixed order's letter is its default, not a lock. Players could not move Sell off N:
+ the fixed letter was returned before Hotkeys.ini was asked, and the Hotkeys tab refused the capture. */
+TEST(hotkeys_every_fixed_order_takes_the_players_letter)
+{
+ static const struct { const char *button; Int type; WideChar fixed; } ORDERS[] =
+ {
+ { "Command_AttackMove", GUI_COMMAND_ATTACK_MOVE, 'A' }, { "Command_Stop", GUI_COMMAND_STOP, 'S' },
+ { "Command_Guard", GUI_COMMAND_GUARD, 'G' }, { "Command_SetRallyPoint", GUI_COMMAND_SET_RALLY_POINT, 'Y' },
+ { "Command_Evacuate", GUI_COMMAND_EVACUATE, 'V' }, { "Command_Sell", GUI_COMMAND_SELL, 'N' },
+ { "Command_CombatDrop", GUI_COMMAND_COMBATDROP, 'C' },
+ { "Command_UpgradeChinaMines", GUI_COMMAND_PLAYER_UPGRADE, 'H' }, { "Command_UpgradeEMPMines", GUI_COMMAND_PLAYER_UPGRADE, 'H' },
+ { "Command_UpgradeCamoNetting", GUI_COMMAND_PLAYER_UPGRADE, 'H' }, { "Command_UpgradeGLACamoNetting", GUI_COMMAND_PLAYER_UPGRADE, 'H' },
+ { "Command_UpgradeGLAWorkerFakeCommandSet", GUI_COMMAND_OBJECT_UPGRADE, 'H' },
+ { "Command_UpgradeGLAWorkerRealCommandSet", GUI_COMMAND_OBJECT_UPGRADE, 'H' },
+ { "Command_BecomeRealGLABarracks", GUI_COMMAND_OBJECT_UPGRADE, 'H' },
+ };
+ for( size_t each = 0; each < sizeof( ORDERS ) / sizeof( ORDERS[ 0 ] ); each++ )
+ {
+ const AsciiString name( ORDERS[ each ].button );
+ AsciiString lower = name;
+ lower.toLower();
+ std::map< std::string, WideChar > keys;
+ CHECK_EQ( HotKeyManager::buttonKeyIn( name, 'Q', ORDERS[ each ].type, keys ), ORDERS[ each ].fixed );
+ keys[ lower.str() ] = 'K';
+ CHECK_EQ( HotKeyManager::buttonKeyIn( name, 'Q', ORDERS[ each ].type, keys ), (WideChar)'K' );
+ keys[ lower.str() ] = 0; // Key = NONE in Hotkeys.ini
+ CHECK_EQ( HotKeyManager::buttonKeyIn( name, 'Q', ORDERS[ each ].type, keys ), 0 );
+ }
+}
+
/* GlobalData.h: which button orders. The classic mouse is 1.04's left button, or the right under EA's
Alternate Mouse Setup (UseAlternateMouse, off out of the box); Reforged is the right whatever Options.ini says. */
TEST(alternate_mouse_moves_the_order_button_in_classic_only)