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): mod buttons past our 14 slots move onto the bar
Olcay Seygan69c78400207a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2223bb307..63fd24bc0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -31,6 +31,7 @@ found and fixed — EA's own, not port damage.**- A patch for a mod stays with that mod. Give it with `-modpatch` right after the mod it changes, and its files replace that mod's one for one, even beside a second total conversion: a ShockWave balance patch reaches ShockWave's armies and leaves The End of Days alone. Given first, a patch changes Zero Hour's own files. The launcher's MODS page marks each mod a patch or a full mod, and a `mod.json` can say `"patch": true`. With two full mods switched on the launcher now plays them side by side; before, ShockWave and The End of Days together stopped the game at startup.- Contra and The Power of the West start and play now, The Power of the West beside ShockWave too; every one of those used to crash while loading. Contra's China base fell over the carpet bombers it never had, and one misspelt armour line in The Power of the West stopped the game where Zero Hour itself had shrugged it off. A mod's patch archive named to sort first, like Contra's `!!` one, wins over the rest of the mod again, as it always did in Zero Hour.- No empty slots in a mod general's power tray. Mods give unrelated powers the same few types, Contra's small Scud Storm counting as a carpet bomb, so a Contra Cybernetic player's tray picked up another faction's button for a power he only held one of the same type as, then hid it, and an empty frame stood where it had been. The tray offers a button now only for the very power you hold, and a slot whose button goes away takes its frame with it.+- Contra's units have their attack move, guard and stop buttons again, and A, G and S press them. Contra draws its command bar with eighteen buttons and keeps those three in the last row, which our fourteen-button bar does not have, so they went missing on every Contra unit, the Cybernetic general's cyborgs among them. A button a mod puts past the end of our bar now moves to an empty one, the three orders to the places Zero Hour gives them.## One interfacediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 38c26f92b..556029512 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -499,6 +499,14 @@ Int ControlBar_commandGroup( const class CommandButton *command );* what does not fit goes on in the next row down with room, then in the rows above. */Bool ControlBar_commandPlaces( const Int *types, const Int *groups, const Int *pinned, Int count, Int *places );+/** Which command set slot each of `count` bar windows shows, -1 for none: `types` is what each slot+ * holds, GUI_COMMAND_NONE for an empty one, and `windowed` whether ControlBar.wnd has that slot's+ * window. A slot with a window shows itself. A mod drawn for a bigger bar (Contra's eighteen, whose+ * units keep attack move, guard and stop in 15, 17 and 18) names slots our fourteen have no window+ * for; such a button moves to an empty window, the three orders to Zero Hour's own 11, 13 and 14+ * when free, anything else to the first empty one. */+void ControlBar_fitCommandSlots( const Int *types, const Bool *windowed, 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/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex f38b84375..6b37b40e9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -378,6 +378,43 @@ Bool ControlBar_commandPlaces( const Int *types, const Int *groups, const Int *preturn fights;}+//-------------------------------------------------------------------------------------------------+void ControlBar_fitCommandSlots( const Int *types, const Bool *windowed, Int count, Int *shown )+{+ for( Int slot = 0; slot < count; slot++ )+ shown[ slot ] = ( windowed[ slot ] && types[ slot ] != GUI_COMMAND_NONE ) ? slot : -1;++ // the shared orders first, so a mod's own button past the bar cannot take their Zero Hour slot+ for( Int pass = 0; pass < 2; pass++ )+ {+ for( Int slot = 0; slot < count; slot++ )+ {+ if( windowed[ slot ] || types[ slot ] == GUI_COMMAND_NONE )+ continue;+ Int to = -1;+ switch( types[ slot ] )+ {+ case GUI_COMMAND_ATTACK_MOVE: to = 10; break;+ case GUI_COMMAND_GUARD:+ case GUI_COMMAND_GUARD_WITHOUT_PURSUIT:+ case GUI_COMMAND_GUARD_FLYING_UNITS_ONLY: to = 12; break;+ case GUI_COMMAND_STOP: to = 13; break;+ }+ if( ( to >= 0 ) != ( pass == 0 ) )+ continue;+ if( to < 0 || to >= count || !windowed[ to ] || shown[ to ] >= 0 )+ {+ to = -1;+ for( Int each = 0; each < count && to < 0; each++ )+ if( windowed[ each ] && shown[ each ] < 0 )+ to = each;+ }+ if( to >= 0 )+ shown[ to ] = slot;+ }+ }+}+//-------------------------------------------------------------------------------------------------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 45137c835..7b9b98083 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -382,10 +382,24 @@ void ControlBar::populateCommand( Object *obj )if( obj->getContain() && obj->getContain()->isDisplayedOnControlBar() )doTransportInventoryUI( obj, commandSet );- // what goes in each slot: the command set, slot for slot+ // what goes in each slot: the command set, slot for slot, and a button in a slot past our bar's+ // windows into an empty one (ControlBar_fitCommandSlots)const CommandButton *slot[ MAX_COMMANDS_PER_SET ];- for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )- slot[ i ] = commandSet->getCommandButton( i );+ {+ const CommandButton *set[ MAX_COMMANDS_PER_SET ];+ Int types[ MAX_COMMANDS_PER_SET ];+ Bool windowed[ MAX_COMMANDS_PER_SET ];+ Int shown[ MAX_COMMANDS_PER_SET ];+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ {+ set[ i ] = commandSet->getCommandButton( i );+ types[ i ] = ( set[ i ] && !BitTest( set[ i ]->getOptions(), SCRIPT_ONLY ) ) ? set[ i ]->getCommandType() : GUI_COMMAND_NONE;+ windowed[ i ] = m_commandWindows[ i ] != NULL;+ }+ ControlBar_fitCommandSlots( types, windowed, MAX_COMMANDS_PER_SET, shown );+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ slot[ i ] = shown[ i ] >= 0 ? set[ shown[ i ] ] : set[ i ];+ }// populate the button with commands definedconst CommandButton *commandButton;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex a085ac9a8..f72e8cfd3 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -3874,6 +3874,42 @@ TEST(controlbar_command_places_go_in_rows_by_what_they_are_for)CHECK_EQ( places[ slot ], manyPlaces[ slot ] );}+TEST(controlbar_mod_slots_past_the_bar_fit_its_windows)+{+ enum { SLOTS = MAX_COMMANDS_PER_SET, WINDOWS = 14 };+ const Int N = GUI_COMMAND_NONE, U = GUI_COMMAND_OBJECT_UPGRADE, W = GUI_COMMAND_SWITCH_WEAPON;+ Bool windowed[ SLOTS ];+ for( Int slot = 0; slot < SLOTS; slot++ )+ windowed[ slot ] = slot < WINDOWS;+ Int shown[ SLOTS ];++ /* Contra's Cybr_AmericaInfantryRangerCommandSet: five drones, capture, two weapon switches, and+ attack move, guard and stop in 15, 17 and 18, which our fourteen windows lack. The orders go to+ Zero Hour's 11, 13 and 14, the rest stay put */+ const Int ranger[ SLOTS ] = { U, U, U, U, U, N, GUI_COMMAND_SPECIAL_POWER, W, N, W, N, N, N, N,+ GUI_COMMAND_ATTACK_MOVE, N, GUI_COMMAND_GUARD, GUI_COMMAND_STOP };+ ControlBar_fitCommandSlots( ranger, windowed, SLOTS, shown );+ const Int rangerShown[ SLOTS ] = { 0, 1, 2, 3, 4, -1, 6, 7, -1, 9, 14, -1, 16, 17, -1, -1, -1, -1 };+ for( Int slot = 0; slot < SLOTS; slot++ )+ CHECK_EQ( shown[ slot ], rangerShown[ slot ] );++ /* 11 taken by the mod's own button: attack move takes the first empty window, and a stray button+ past the bar comes after the orders */+ const Int busy[ SLOTS ] = { U, N, N, N, N, N, N, N, N, N, U, N, N, N, U, GUI_COMMAND_ATTACK_MOVE, N, N };+ ControlBar_fitCommandSlots( busy, windowed, SLOTS, shown );+ CHECK_EQ( shown[ 0 ], 0 );+ CHECK_EQ( shown[ 10 ], 10 );+ CHECK_EQ( shown[ 1 ], 15 );+ CHECK_EQ( shown[ 2 ], 14 );++ /* a retail set never goes past fourteen and comes back slot for slot */+ const Int humvee[ SLOTS ] = { U, U, U, N, N, N, N, N, GUI_COMMAND_EVACUATE, N, GUI_COMMAND_ATTACK_MOVE, N,+ GUI_COMMAND_GUARD, GUI_COMMAND_STOP, N, N, N, N };+ ControlBar_fitCommandSlots( humvee, windowed, SLOTS, shown );+ for( Int slot = 0; slot < SLOTS; slot++ )+ CHECK_EQ( shown[ slot ], humvee[ slot ] != N && slot < WINDOWS ? slot : -1 );+}+TEST(controlbar_stance_key_takes_what_the_buttons_leave){enum { SLOTS = 14 };