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
feat(gameclient): a mod's promotion buttons fill our screen in reading order
Olcay Seygan090722be5ab9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 92e8f1cd4..3b924eb5b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,7 +27,7 @@ found and fixed — EA's own, not port damage.**- Reforged stays on top of every mod. This build's balance, its fixes to EA's data, its AI and its menus load after the mod and win where they touch the same unit, weapon or button, so a mod plays with Reforged's rules. A change that names something the mod renamed or removed is passed over instead of stopping the game, which is how ShockWave starts and plays. A mod's own copy of a file Reforged ships, the skirmish setup screen among them, is ignored, and so are any upscaled art archives it carries. The one exception is the skirmish AI's scripts: a mod's are written for its own generals, so they replace Reforged's, and Reforged's smarter AI plays them.- A `mod.json` in the folder names the mod and its version. The names stand beside the version number in the options menu, in the order the mods were given, and go into every replay you record, so a replay made with mods says which ones, and the replay list marks it as another version when the game is running without them.- Joining a LAN game that runs different mods used to end in a box about a mismatch and nothing else. It names the host's mods now, or tells you the host plays without any.-- Two total conversions in one match. Add `-modfactions` to the mods you give, and each mod's armies join Zero Hour's own instead of replacing them: the faction list reads "ShockWave - USA" and "The End of Days - USA" under plain "USA", and a ShockWave army can fight an End of Days one. Each side builds from its own mod's units, weapons, upgrades and generals' powers, and each looks and sounds like its own mod: a ShockWave tank wears ShockWave's model and textures even where The End of Days replaces the same file, and speaks with ShockWave's voice. Playing a mod's faction, your buttons, build pictures, unit names and tooltips are that mod's, set in our American command bar whichever side you picked. The End of Days' Russia is in the list under its own name. Each mod general's promotion screen holds that mod's own powers, with the mod's pictures, and they unlock with your rank. A mod's faction climbs that mod's own ranks: The End of Days' eight, with its own experience steps and points, where Zero Hour's five used to apply to everyone. ShockWave's and The End of Days' screens used to open empty, because a rank granted only Zero Hour's own rank marks and the mod's powers asked for the mod's. Menus, lobby and colours stay ours whatever mods you load. The skirmish AI lays out a mod's base from the mod's own buildings, but it still trains the army it knows from Zero Hour.+- Two total conversions in one match. Add `-modfactions` to the mods you give, and each mod's armies join Zero Hour's own instead of replacing them: the faction list reads "ShockWave - USA" and "The End of Days - USA" under plain "USA", and a ShockWave army can fight an End of Days one. Each side builds from its own mod's units, weapons, upgrades and generals' powers, and each looks and sounds like its own mod: a ShockWave tank wears ShockWave's model and textures even where The End of Days replaces the same file, and speaks with ShockWave's voice. Playing a mod's faction, your buttons, build pictures, unit names and tooltips are that mod's, set in our American command bar whichever side you picked. The End of Days' Russia is in the list under its own name. Each mod general's promotion screen holds that mod's own powers, with the mod's pictures, and they unlock with your rank. They fill the screen in reading order, row by row, where the mod's own layout used to leave holes between them. A mod's faction climbs that mod's own ranks: The End of Days' eight, with its own experience steps and points, where Zero Hour's five used to apply to everyone. ShockWave's and The End of Days' screens used to open empty, because a rank granted only Zero Hour's own rank marks and the mod's powers asked for the mod's. Menus, lobby and colours stay ours whatever mods you load. The skirmish AI lays out a mod's base from the mod's own buildings, but it still trains the army it knows from Zero Hour.- 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.## One interfacediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 5ee1c1708..5eb0327fa 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -1109,6 +1109,8 @@ protected:// the following methods are for populating the context GUI controls for a particular contextstatic void populateButtonProc( Object *obj, void *userData );void populatePurchaseScience(Player* player);+ /// one rank's section of the promotion screen; compact: a mod's buttons in reading order, no gaps+ void populatePurchaseScienceRank( Player *player, const CommandSet *commandSet, GameWindow **windows, Int windowCount, Bool compact );void populateCommand( Object *obj );void populateMultiSelect( void );void populateMultiSelectUnitList( void );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex 20949a287..1d82a331a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -644,6 +644,94 @@ Player *ControlBar::getWatchedPlayer( void )return local;}+/** True when a compact section gives this button a window: a real purchase the player could ever+ * see. A script-only button, a science a script hid and one whose root prerequisites the player's+ * general never has would leave a hole. */+static Bool isSciencePurchaseShown( const Player *player, const CommandButton *commandButton )+{+ if( commandButton == NULL || BitTest( commandButton->getOptions(), SCRIPT_ONLY ) )+ return FALSE;+ if( commandButton->getScienceVec().empty() )+ return TRUE;+ ScienceType science = commandButton->getScienceVec()[ 0 ];+ return !player->isScienceHidden( science ) && TheScienceStore->playerHasRootPrereqsForScience( player, science );+}++/** Puts one rank's purchase buttons on its windows. The caller has hidden every window. Retail keeps+ * slot i on window i, gaps and all; compact takes the set's shown buttons in slot order and lays them+ * on the windows in reading order, left to right and a row before the next. The windows are fixed+ * by the layout, so a rank with more buttons than windows loses the rest and the log names them. */+void ControlBar::populatePurchaseScienceRank( Player *player, const CommandSet *commandSet, GameWindow **windows, Int windowCount, Bool compact )+{+ const CommandButton *placed[ MAX_COMMANDS_PER_SET ];+ GameWindow *ordered[ MAX_COMMANDS_PER_SET ];+ Int i;++ for( i = 0; i < windowCount; i++ )+ {+ placed[ i ] = commandSet->getCommandButton( i );+ ordered[ i ] = windows[ i ];+ }++ if( compact )+ {+ Int shownCount = 0;+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ {+ const CommandButton *commandButton = commandSet->getCommandButton( i );+ if( !isSciencePurchaseShown( player, commandButton ) )+ continue;+ if( shownCount < windowCount )+ placed[ shownCount ] = commandButton;+ else+ DEBUG_LOG(( "PROMOTION %s has %d windows, no room for %s\n", commandSet->getName().str(), windowCount, commandButton->getName().str() ));+ shownCount++;+ }+ for( i = shownCount; i < windowCount; i++ )+ placed[ i ] = NULL;++ std::stable_sort( ordered, ordered + windowCount, []( GameWindow *a, GameWindow *b )+ {+ Int ax, ay, bx, by;+ a->winGetScreenPosition( &ax, &ay );+ b->winGetScreenPosition( &bx, &by );+ return ay != by ? ay < by : ax < bx;+ } );+ }++ for( i = 0; i < windowCount; i++ )+ {+ const CommandButton *commandButton = placed[ i ];+ GameWindow *window = ordered[ i ];++ if( commandButton == NULL || BitTest( commandButton->getOptions(), SCRIPT_ONLY ) )+ continue;++ window->winHide( FALSE );+ window->winEnable( FALSE );+ setControlCommand( window, commandButton );+ if( commandButton->getScienceVec().empty() )+ continue;++ ScienceType science = commandButton->getScienceVec()[ 0 ];+ if( player->isScienceDisabled( science ) )+ continue;+ if( player->isScienceHidden( science ) )+ {+ window->winHide( TRUE );+ continue;+ }+ if( !player->hasScience( science ) && TheScienceStore->playerHasPrereqsForScience( player, science ) && TheScienceStore->getSciencePurchaseCost( science ) <= player->getSciencePurchasePoints() )+ window->winEnable( TRUE );+ if( player->hasScience( science ) )+ window->winSetStatus( WIN_STATUS_ALWAYS_COLOR );+ else+ window->winClearStatus( WIN_STATUS_ALWAYS_COLOR );+ if( !TheScienceStore->playerHasRootPrereqsForScience( player, science ) )+ window->winHide( TRUE );+ }+}+void ControlBar::populatePurchaseScience( Player* player ){// TheInGameUI->deselectAllDrawables();@@ -677,188 +765,12 @@ void ControlBar::populatePurchaseScience( Player* player )commandSet8 == NULL )return;- // populate the button with commands defined- const CommandButton *commandButton;- for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_1; i++ )- {-- // get command button- commandButton = commandSet1->getCommandButton(i);-- // if button is not present, just hide the window- if( commandButton == NULL || BitTest( commandButton->getOptions(), SCRIPT_ONLY ) )- {- // hide window on interface- m_sciencePurchaseWindowsRank1[ i ]->winHide( TRUE );- } // end if- else- {- // make sure the window is not hidden- m_sciencePurchaseWindowsRank1[ i ]->winHide( FALSE );-- // Disable by default- m_sciencePurchaseWindowsRank1[ i ]->winEnable( FALSE );-- // populate the visible button with data from the command button-- setControlCommand( m_sciencePurchaseWindowsRank1[ i ], commandButton );- if (!commandButton->getScienceVec().empty())- {- ScienceType st = commandButton->getScienceVec()[ 0 ];-- if( player->isScienceDisabled( st ) )- {- //A script has deemed this science disabled.- m_sciencePurchaseWindowsRank1[ i ]->winEnable( FALSE );- }- else if( player->isScienceHidden( st ) )- {- //A script has deemed this science unavailable, thus hidden- m_sciencePurchaseWindowsRank1[ i ]->winHide( TRUE );- }- else- {- //Handle normal game logic cases!- if(!player->hasScience(st) && TheScienceStore->playerHasPrereqsForScience(player, st) && TheScienceStore->getSciencePurchaseCost(st) <= player->getSciencePurchasePoints())- {- m_sciencePurchaseWindowsRank1[ i ]->winEnable( TRUE );- }- if(player->hasScience(st))- {- m_sciencePurchaseWindowsRank1[ i ]->winSetStatus(WIN_STATUS_ALWAYS_COLOR);- }- else- {- m_sciencePurchaseWindowsRank1[ i ]->winClearStatus(WIN_STATUS_ALWAYS_COLOR);- }- if(!TheScienceStore->playerHasRootPrereqsForScience(player, st))- m_sciencePurchaseWindowsRank1[ i ]->winHide(TRUE);- }- }- } // end else-- } // end for-- for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_3; i++ )- {-- // get command button- commandButton = commandSet3->getCommandButton(i);-- // if button is not present, just hide the window- if( commandButton == NULL || BitTest( commandButton->getOptions(), SCRIPT_ONLY ) )- {- // hide window on interface- m_sciencePurchaseWindowsRank3[ i ]->winHide( TRUE );- } // end if- else- {- // make sure the window is not hidden- m_sciencePurchaseWindowsRank3[ i ]->winHide( FALSE );-- // Disable by default- m_sciencePurchaseWindowsRank3[ i ]->winEnable( FALSE );-- // populate the visible button with data from the command button-- setControlCommand( m_sciencePurchaseWindowsRank3[ i ], commandButton );- ScienceType st = SCIENCE_INVALID;- ScienceVec sv = commandButton->getScienceVec();- if (! sv.empty())- {- st = sv[ 0 ];- }-- if( player->isScienceDisabled( st ) )- {- //A script has deemed this science disabled.- m_sciencePurchaseWindowsRank3[ i ]->winEnable( FALSE );- }- else if( player->isScienceHidden( st ) )- {- //A script has deemed this science unavailable, thus hidden- m_sciencePurchaseWindowsRank3[ i ]->winHide( TRUE );- }- else- {- //Handle normal game logic cases!- if(!player->hasScience(st) && TheScienceStore->playerHasPrereqsForScience(player, st) && TheScienceStore->getSciencePurchaseCost(st) <= player->getSciencePurchasePoints())- {- m_sciencePurchaseWindowsRank3[ i ]->winEnable( TRUE );- }- if(player->hasScience(st))- {- m_sciencePurchaseWindowsRank3[ i ]->winSetStatus(WIN_STATUS_ALWAYS_COLOR);- }- else- {- m_sciencePurchaseWindowsRank3[ i ]->winClearStatus(WIN_STATUS_ALWAYS_COLOR);- }- if(!TheScienceStore->playerHasRootPrereqsForScience(player, st))- m_sciencePurchaseWindowsRank3[ i ]->winHide(TRUE);- }-- } // end else-- } // end for-- for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_8; i++ )- {-- // get command button- commandButton = commandSet8->getCommandButton(i);-- // if button is not present, just hide the window- if( commandButton == NULL || BitTest( commandButton->getOptions(), SCRIPT_ONLY ) )- {- // hide window on interface- m_sciencePurchaseWindowsRank8[ i ]->winHide( TRUE );- } // end if- else- {- // make sure the window is not hidden- m_sciencePurchaseWindowsRank8[ i ]->winHide( FALSE );-- // Disable by default- m_sciencePurchaseWindowsRank8[ i ]->winEnable( FALSE );-- // populate the visible button with data from the command button-- setControlCommand( m_sciencePurchaseWindowsRank8[ i ], commandButton );- ScienceType st = SCIENCE_INVALID;- st = commandButton->getScienceVec()[ 0 ];- if( player->isScienceDisabled( st ) )- {- //A script has deemed this science disabled.- m_sciencePurchaseWindowsRank8[ i ]->winEnable( FALSE );- }- else if( player->isScienceHidden( st ) )- {- //A script has deemed this science unavailable, thus hidden- m_sciencePurchaseWindowsRank8[ i ]->winHide( TRUE );- }- else- {- //Handle normal game logic cases!- if(!player->hasScience(st) && TheScienceStore->playerHasPrereqsForScience(player, st) && TheScienceStore->getSciencePurchaseCost(st) <= player->getSciencePurchasePoints())- {- m_sciencePurchaseWindowsRank8[ i ]->winEnable( TRUE );- }- if(player->hasScience(st))- {- m_sciencePurchaseWindowsRank8[ i ]->winSetStatus(WIN_STATUS_ALWAYS_COLOR);- }- else- {- m_sciencePurchaseWindowsRank8[ i ]->winClearStatus(WIN_STATUS_ALWAYS_COLOR);- }- if(!TheScienceStore->playerHasRootPrereqsForScience(player, st))- m_sciencePurchaseWindowsRank8[ i ]->winHide(TRUE);- }-- } // end else-- } // end for+ // a mod's command sets were laid out for the mod's own screen and leave gaps in ours; retail's+ // keep their slots, gaps and all, as Zero Hour shipped them+ const Bool compact = ControlBarIsModFaction( player->getPlayerTemplate() );+ populatePurchaseScienceRank( player, commandSet1, m_sciencePurchaseWindowsRank1, MAX_PURCHASE_SCIENCE_RANK_1, compact );+ populatePurchaseScienceRank( player, commandSet3, m_sciencePurchaseWindowsRank3, MAX_PURCHASE_SCIENCE_RANK_3, compact );+ populatePurchaseScienceRank( player, commandSet8, m_sciencePurchaseWindowsRank8, MAX_PURCHASE_SCIENCE_RANK_8, compact );//// Somebody else's screen is a read-out, not a shop: a watcher sees what that general has bought