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(gameengine): stop filing the first four function keys as command slots
Olcay Seygana7bb308210e3
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ChromaKeyboard.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ChromaKeyboard.hindex a8992c93a..0d3590e23 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ChromaKeyboard.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ChromaKeyboard.h@@ -65,6 +65,17 @@ extern Int chromaCellForKey( char key );* character on a key is not the key. */extern Int chromaCellForMappableKey( Int key );+/** Which command bar slot, or which generals power tray slot, a meta message+ * presses; -1 when it presses neither. Takes the GameMessage::Type as an Int.+ *+ * These exist because the slot cannot be worked out by subtracting the first+ * message of a run and bounding the answer by the size of the array behind the+ * bar. The command bar's array holds eighteen and only fourteen of them have+ * a message, so that sum ran off the end of the command messages and into the+ * shortcut ones, and put the first four function keys on the command bar. */+extern Int chromaCommandSlotForMessage( Int metaMessage );+extern Int chromaShortcutSlotForMessage( Int metaMessage );+/// How many keys the power meter spans, and what it answers once consumption has/// passed production and the whole row goes to blinking red instead.enum { CHROMA_POWER_SEGMENTS = 10, CHROMA_POWER_BROWNOUT = -1 };diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cppindex b164d5d43..13c89da10 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ChromaKeyboard.cpp@@ -1350,8 +1350,34 @@ Int chromaCellForMappableKey( Int key )// cannot be looked up once. Under Legacy nothing is bound to either and every// entry is -1, which is right: there the letters in the labels do the work.//------------------------------------------------------------------------------static Int s_commandSlotCell[ MAX_COMMANDS_PER_SET ];-static Int s_shortcutSlotCell[ MAX_SPECIAL_POWER_SHORTCUTS ];+/// How many slots of each bar a key can actually reach, counted off the messages+/// themselves rather than off the arrays behind the bars. The two do not agree:+/// the command bar holds eighteen slots and only fourteen of them have a key,+/// the rest being for buttons a map script puts up. Reading the slot out of a+/// message and bounding it by eighteen therefore ran four slots past the end of+/// the command messages and into the shortcut ones, and filed the first four+/// function keys as command bar slots.+static const Int COMMAND_SLOTS_WITH_KEYS =+ (Int)GameMessage::MSG_META_SHORTCUT_SLOT01 - (Int)GameMessage::MSG_META_COMMAND_SLOT01;+static const Int SHORTCUT_SLOTS_WITH_KEYS =+ (Int)GameMessage::MSG_META_VIEW_COMMAND_CENTER - (Int)GameMessage::MSG_META_SHORTCUT_SLOT01;++static Int s_commandSlotCell[ COMMAND_SLOTS_WITH_KEYS ];+static Int s_shortcutSlotCell[ SHORTCUT_SLOTS_WITH_KEYS ];++//-----------------------------------------------------------------------------+Int chromaCommandSlotForMessage( Int metaMessage )+{+ const Int slot = metaMessage - (Int)GameMessage::MSG_META_COMMAND_SLOT01;+ return slot >= 0 && slot < COMMAND_SLOTS_WITH_KEYS ? slot : -1;+}++//-----------------------------------------------------------------------------+Int chromaShortcutSlotForMessage( Int metaMessage )+{+ const Int slot = metaMessage - (Int)GameMessage::MSG_META_SHORTCUT_SLOT01;+ return slot >= 0 && slot < SHORTCUT_SLOTS_WITH_KEYS ? slot : -1;+}//-----------------------------------------------------------------------------static void chromaRefreshBoundCells( UnsignedInt frame )@@ -1364,9 +1390,9 @@ static void chromaRefreshBoundCells( UnsignedInt frame )everRefreshed = TRUE;lastRefreshFrame = frame;- for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; ++slot )+ for( Int slot = 0; slot < COMMAND_SLOTS_WITH_KEYS; ++slot )s_commandSlotCell[ slot ] = -1;- for( Int slot = 0; slot < MAX_SPECIAL_POWER_SHORTCUTS; ++slot )+ for( Int slot = 0; slot < SHORTCUT_SLOTS_WITH_KEYS; ++slot )s_shortcutSlotCell[ slot ] = -1;if( TheMetaMap == NULL )return;@@ -1377,12 +1403,12 @@ static void chromaRefreshBoundCells( UnsignedInt frame )if( rec->m_modState != 0 )continue;- const Int commandSlot = (Int)rec->m_meta - (Int)GameMessage::MSG_META_COMMAND_SLOT01;- if( commandSlot >= 0 && commandSlot < MAX_COMMANDS_PER_SET && s_commandSlotCell[ commandSlot ] < 0 )+ const Int commandSlot = chromaCommandSlotForMessage( (Int)rec->m_meta );+ if( commandSlot >= 0 && s_commandSlotCell[ commandSlot ] < 0 )s_commandSlotCell[ commandSlot ] = chromaCellForMappableKey( rec->m_key );- const Int shortcutSlot = (Int)rec->m_meta - (Int)GameMessage::MSG_META_SHORTCUT_SLOT01;- if( shortcutSlot >= 0 && shortcutSlot < MAX_SPECIAL_POWER_SHORTCUTS && s_shortcutSlotCell[ shortcutSlot ] < 0 )+ const Int shortcutSlot = chromaShortcutSlotForMessage( (Int)rec->m_meta );+ if( shortcutSlot >= 0 && s_shortcutSlotCell[ shortcutSlot ] < 0 )s_shortcutSlotCell[ shortcutSlot ] = chromaCellForMappableKey( rec->m_key );}}@@ -1421,7 +1447,7 @@ static void chromaFillLabelHotKeys( Int *cells, Int pressable, Int unavailable )* group's cells the moment the labels on screen do. */static void chromaFillCommandGrid( Int *cells, Int pressable, Int unavailable ){- for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; ++slot )+ for( Int slot = 0; slot < COMMAND_SLOTS_WITH_KEYS; ++slot ){const Int cell = s_commandSlotCell[ slot ];if( cell < 0 )@@ -1457,7 +1483,7 @@ static void chromaFillPowerTray( Int *cells, Int bed, Int factionColor, Unsigned{const Int usable = chromaBlinkIsOn( frame, BLINK_PERIOD_FRAMES ) ? COLOR_WARM_WHITE : COLOR_OFF;- for( Int slot = 0; slot < MAX_SPECIAL_POWER_SHORTCUTS; ++slot )+ for( Int slot = 0; slot < SHORTCUT_SLOTS_WITH_KEYS; ++slot ){const Int cell = s_shortcutSlotCell[ slot ];if( cell < 0 )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 6572a7e99..dd330e874 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -13095,6 +13095,38 @@ TEST(chroma_power_meter_empties_as_the_draw_catches_the_supply)CHECK_EQ(chromaPowerSegments(10, 11), CHROMA_POWER_BROWNOUT);}+// A slot cannot be read out of a meta message by subtracting the first message of its run and+// bounding the answer by the size of the array behind the bar. The command bar's array holds+// eighteen slots and only fourteen of them have a message, so that sum ran four past the end of+// the command messages and straight into the shortcut ones: F1 to F4 were filed as command bar+// slots 14 to 17 and lit from them.+TEST(chroma_slot_messages_do_not_run_into_each_other)+{+ // every command message answers as itself and nothing else+ for (Int slot = 0; slot < 14; ++slot)+ {+ const Int message = (Int)GameMessage::MSG_META_COMMAND_SLOT01 + slot;+ CHECK_EQ(chromaCommandSlotForMessage(message), slot);+ CHECK_EQ(chromaShortcutSlotForMessage(message), -1);+ }+ for (Int slot = 0; slot < 11; ++slot)+ {+ const Int message = (Int)GameMessage::MSG_META_SHORTCUT_SLOT01 + slot;+ CHECK_EQ(chromaShortcutSlotForMessage(message), slot);+ CHECK_EQ(chromaCommandSlotForMessage(message), -1);+ }++ // the runs are exactly as long as the messages, not as long as the arrays+ CHECK_EQ(chromaCommandSlotForMessage((Int)GameMessage::MSG_META_COMMAND_SLOT14), 13);+ CHECK_EQ(chromaShortcutSlotForMessage((Int)GameMessage::MSG_META_SHORTCUT_SLOT11), 10);+ CHECK_EQ(chromaShortcutSlotForMessage((Int)GameMessage::MSG_META_VIEW_COMMAND_CENTER), -1);+ CHECK(MAX_COMMANDS_PER_SET > 14); // the array really is bigger than the keys reach++ // and neither run reaches backwards into whatever sits before it+ CHECK_EQ(chromaCommandSlotForMessage((Int)GameMessage::MSG_META_COMMAND_SLOT01 - 1), -1);+ CHECK_EQ(chromaShortcutSlotForMessage((Int)GameMessage::MSG_META_SHORTCUT_SLOT01 - 1), -1);+}+// The two key maps have to agree. chromaCellForKey knows the typing rows by their characters and// draws the power meter with them; chromaCellForMappableKey knows the whole board by scancode and// places whatever the player has bound. A letter has to come out at the same lamp either way, or a