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(gameengine): key the promotion screen by column, and close it on escape
Olcay Seygana0cc94ca5f87
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3715afdc4..10f12bc26 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -282,7 +282,7 @@ found and fixed — EA's own, not port damage.**- The countdown inside a strip picture lost its black backing plate. On a picture that small the plate was most of the picture; the number now sits straight on the sweeping clock.- A game opens with nothing selected, so your first click is not a rally point.- Your general's powers no longer climb the right hand edge of the screen. They sit three abreast, filling from the bottom corner where the first one has always been and wrapping upward, so a general holding eleven of them still reads as a block instead of a ladder from the radar to the sky. The keys follow the same shape: the first press picks a row, the second picks the power in it, so every power is two keys away - F1 F1 for the one in the corner, F2 F1 for the row above it. Only the keys you can press next are written on the pictures, so you are never reading eleven labels to find one, and Escape drops a row you thought better of - so does clicking a power with the mouse, and so does a couple of seconds' pause, so a key hit by mistake in a fight never turns your next one into a superweapon. Rows with nothing in them yet cannot be picked at all: early on, when you hold three powers, only the row you have answers a key.-- The tilde key opens the general's promotions.+- The tilde key opens the general's promotions, and Escape closes them - Escape used to bring up the pause menu on top of the open screen, leaving the small exit button in its corner as the only way out. The screen is five columns wide and 1 to 5 now name them: each number sits in the corner of the science that column would sell you next, and pressing it twice buys that one - once to mark, once to spend, so a point is never gone to a key hit in a hurry. Buy the top of a chain and the number drops onto the next rung down, so a whole column goes in with one finger while the fight carries on behind you.- `S` stops your units again; the key was simply never bound.- Every button carries its build, research or cooldown time in the corner.- A single selected unit wears a gold bar filling toward its next rank.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex eab53b17e..caf2d2c03 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -417,6 +417,15 @@ enum {MAX_PURCHASE_SCIENCE_RANK_3 = 15,MAX_PURCHASE_SCIENCE_RANK_8 = 4,};+//+// GeneralsExpPoints.wnd lays the promotion screen out in five columns: the 1 point row across the+// top (x 247, 315, 383, 451), the 3 point block three deep under it (the same four x plus 520) and+// the 5 point row along the bottom. So Rank3Number0..2 sit in the first column, 3..5 in the+// second, and a column is one science chain read top to bottom.+//+enum { PURCHASE_SCIENCE_COLUMNS = 5 };+enum { PURCHASE_SCIENCE_RANK_3_PER_COLUMN = 3 };+enum { PURCHASE_SCIENCE_COLUMN_DEPTH = 1 + PURCHASE_SCIENCE_RANK_3_PER_COLUMN + 1 };enum { MAX_STRUCTURE_INVENTORY_BUTTONS = 10 }; // there are this many physical buttons in "inventory" windows for structuresenum { MAX_BUILD_QUEUE_BUTTONS = 9 };// physical button count for the build queueenum { MAX_SPECIAL_POWER_SHORTCUTS = 11};@@ -706,6 +715,15 @@ public:TRUE when there was one to forget. */Bool clearSpecialPowerShortcutRow( void );+ /** The promotion screen answers the group keys while it is open: 1 to 5 name its five columns.+ A promotion point is spent for good, so it takes two presses like the general's powers do -+ the first marks the next science the column will sell you, the same key again buys it. A+ different number marks that column instead, and CHORD_TIMEOUT_MS of nothing drops the mark. */+ void pressPurchaseScienceColumn( Int column );++ /** forget a marked column. TRUE when there was one to forget. */+ Bool clearPurchaseScienceColumn( void );+/** A builder with more structures than BUILD_PAGE_ONE_SIZE does not show them all at once.The command bar opens on two menu buttons instead - Q and W - and each one opens itsown page of structures, so a structure is two keystrokes away (Q-Q, Q-A, ... W-Q, ...)@@ -753,6 +771,7 @@ public:void showPurchaseScience( void );void hidePurchaseScience( void );void togglePurchaseScience( void );+ Bool isPurchaseScienceVisible( void );void showSpecialPowerShortcut( void );void hideSpecialPowerShortcut( void );@@ -1008,6 +1027,19 @@ protected:Int m_specialPowerShortcutRow; ///< row a first key press picked, -1 when none is pendingUnsignedInt m_specialPowerShortcutRowMs; ///< millisecond that row was picked on, for CHORD_TIMEOUT_MS+ Int m_purchaseScienceColumn; ///< promotion screen column a first key press marked, -1 when none+ UnsignedInt m_purchaseScienceColumnMs; ///< millisecond it was marked on, for CHORD_TIMEOUT_MS++ /** the window a press on that column would buy from: the topmost science in it that is on+ screen and can be bought right now. NULL when the column has nothing to sell. */+ GameWindow *purchaseScienceCandidate( Int column );++ /** the window sitting 'depth' rows down column 'column', NULL where the layout has no button */+ GameWindow *purchaseScienceWindow( Int column, Int depth );++ /** paint the column numbers onto the sciences those keys would buy, and mark the armed one */+ void updatePurchaseScienceHotKeys( void );+WindowLayout *m_specialPowerLayout;GameWindow *m_specialPowerShortcutParent;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex d0aacc0d0..0d7ba8141 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -1090,6 +1090,8 @@ ControlBar::ControlBar( void )m_specialPowerShortcutParent = NULL;m_specialPowerShortcutRow = -1;m_specialPowerShortcutRowMs = 0;+ m_purchaseScienceColumn = -1;+ m_purchaseScienceColumnMs = 0;m_specialPowerLayout = NULL;m_scienceLayout = NULL;m_rightHUDWindow = NULL;@@ -1780,7 +1782,12 @@ void ControlBar::update( void )}if(!m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())+ {updateContextPurchaseScience();+ updatePurchaseScienceHotKeys();+ }+ else+ clearPurchaseScienceColumn();//// a stand-in builder is not selected, so no deselect event tells us when it dies or when a@@ -3703,6 +3710,8 @@ void ControlBar::showPurchaseScience( void )void ControlBar::hidePurchaseScience( void ){+ clearPurchaseScienceColumn();+if(m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())return;@@ -3726,6 +3735,214 @@ void ControlBar::hidePurchaseScience( void )// }}+Bool ControlBar::isPurchaseScienceVisible( void )+{+ return m_contextParent[ CP_PURCHASE_SCIENCE ] && !m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden();+}++//-------------------------------------------------------------------------------------------------+/** The button 'depth' rows down a promotion screen column: the 1 point science on top, the three+ * 3 point ones under it, the 5 point one at the bottom. The 3 point block is the only one five+ * columns wide, so the fifth column has a top and a bottom that do not exist. */+//-------------------------------------------------------------------------------------------------+/** Which of the screen's three rows a column and depth land in - 1, 3 or 8 for the point cost the+ * row sells, 0 where the layout has no button - and the index inside that row's window array.+ * A free function so the mapping can be checked without standing a ControlBar up. */+Int ControlBar_purchaseScienceRank( Int column, Int depth, Int *indexOut )+{+ if( indexOut )+ *indexOut = -1;++ if( column < 0 || column >= PURCHASE_SCIENCE_COLUMNS || depth < 0 )+ return 0;++ if( depth == 0 )+ {+ if( column >= MAX_PURCHASE_SCIENCE_RANK_1 )+ return 0;+ if( indexOut )+ *indexOut = column;+ return 1;+ }++ if( depth <= PURCHASE_SCIENCE_RANK_3_PER_COLUMN )+ {+ const Int slot = column * PURCHASE_SCIENCE_RANK_3_PER_COLUMN + ( depth - 1 );+ if( slot >= MAX_PURCHASE_SCIENCE_RANK_3 )+ return 0;+ if( indexOut )+ *indexOut = slot;+ return 3;+ }++ if( depth == PURCHASE_SCIENCE_COLUMN_DEPTH - 1 )+ {+ if( column >= MAX_PURCHASE_SCIENCE_RANK_8 )+ return 0;+ if( indexOut )+ *indexOut = column;+ return 8;+ }++ return 0;++} // end ControlBar_purchaseScienceRank++GameWindow *ControlBar::purchaseScienceWindow( Int column, Int depth )+{+ Int index = -1;+ switch( ControlBar_purchaseScienceRank( column, depth, &index ) )+ {+ case 1: return m_sciencePurchaseWindowsRank1[ index ];+ case 3: return m_sciencePurchaseWindowsRank3[ index ];+ case 8: return m_sciencePurchaseWindowsRank8[ index ];+ }++ return NULL;++} // end purchaseScienceWindow++//-------------------------------------------------------------------------------------------------+/** What a press on that column would buy: the topmost science in it that is on screen and can be+ * bought this instant. populatePurchaseScience() has already done that arithmetic - it enables+ * exactly the ones the player has the prerequisites and the points for - so a science already+ * owned, still locked, or too expensive is skipped and the key reaches the next one down. */+//-------------------------------------------------------------------------------------------------+GameWindow *ControlBar::purchaseScienceCandidate( Int column )+{+ for( Int depth = 0; depth < PURCHASE_SCIENCE_COLUMN_DEPTH; depth++ )+ {+ GameWindow *win = purchaseScienceWindow( column, depth );+ if( win == NULL || win->winIsHidden() )+ continue;+ if( BitTest( win->winGetStatus(), WIN_STATUS_ENABLED ) )+ return win;+ }++ return NULL;++} // end purchaseScienceCandidate++//-------------------------------------------------------------------------------------------------+/** forget a marked column, so the next number marks one again */+//-------------------------------------------------------------------------------------------------+Bool ControlBar::clearPurchaseScienceColumn( void )+{+ if( m_purchaseScienceColumn < 0 )+ return FALSE;++ m_purchaseScienceColumn = -1;+ m_purchaseScienceColumnMs = 0;+ return TRUE;++} // end clearPurchaseScienceColumn++//-------------------------------------------------------------------------------------------------+/** Paint the column numbers onto the promotion screen. With nothing marked every column wears its+ * key on the science that key would buy next; once a column is marked it is the only number left+ * on the screen, which is what says the same key again spends the point. */+//-------------------------------------------------------------------------------------------------+void ControlBar::updatePurchaseScienceHotKeys( void )+{+ if( !isPurchaseScienceVisible() )+ {+ clearPurchaseScienceColumn();+ return;+ }++ // a column marked and then thought better of expires on its own, like an armed builder chord+ if( m_purchaseScienceColumn >= 0+ && timeGetTime() - m_purchaseScienceColumnMs > CHORD_TIMEOUT_MS )+ clearPurchaseScienceColumn();++ // the promotion screen ships its own big yellow font; the key reads like a command bar label+ GameWindow *model = m_commandWindows[ 0 ];++ for( Int column = 0; column < PURCHASE_SCIENCE_COLUMNS; column++ )+ {+ GameWindow *candidate = purchaseScienceCandidate( column );++ UnicodeString label;+ if( m_purchaseScienceColumn < 0 || m_purchaseScienceColumn == column )+ label = getMetaKeyLabel( (GameMessage::Type)( GameMessage::MSG_META_SELECT_TEAM1 + column ) );++ for( Int depth = 0; depth < PURCHASE_SCIENCE_COLUMN_DEPTH; depth++ )+ {+ GameWindow *win = purchaseScienceWindow( column, depth );+ if( win == NULL )+ continue;++ if( win == candidate && label.isEmpty() == FALSE )+ {+ if( model )+ {+ win->winSetFont( model->winGetFont() );+ win->winSetEnabledTextColors( model->winGetEnabledTextColor(), model->winGetEnabledTextBorderColor() );+ win->winSetHiliteTextColors( model->winGetHiliteTextColor(), model->winGetHiliteTextBorderColor() );+ }++ // the shortcut flag is what puts the label in the corner instead of the middle+ win->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );+ GadgetButtonSetText( win, label );+ }+ else+ {+ win->winClearStatus( WIN_STATUS_SHORTCUT_BUTTON );+ GadgetButtonSetText( win, UnicodeString( L"" ) );+ }+ }+ }++} // end updatePurchaseScienceHotKeys++//-------------------------------------------------------------------------------------------------+/** A promotion point is spent for good, so the number keys buy in two presses like the general's+ * powers fire in two: the first press marks the next science that column will sell you, the same+ * key again buys it. Another number marks that column instead, Escape closes the screen, and a+ * mark left alone for CHORD_TIMEOUT_MS drops by itself. */+//-------------------------------------------------------------------------------------------------+void ControlBar::pressPurchaseScienceColumn( Int column )+{+ if( !isPurchaseScienceVisible() || column < 0 || column >= PURCHASE_SCIENCE_COLUMNS )+ return;++ GameWindow *win = purchaseScienceCandidate( column );++ // a first press, or a press on some other column: this one only marks+ if( m_purchaseScienceColumn != column )+ {+ m_purchaseScienceColumn = column;+ m_purchaseScienceColumnMs = timeGetTime();+ updatePurchaseScienceHotKeys();++ // a column with nothing left to sell says so rather than sitting there armed+ if( win == NULL && TheAudio )+ {+ AudioEventRTS disabledClick( "GUIClickDisabled" );+ TheAudio->addAudioEvent( &disabledClick );+ clearPurchaseScienceColumn();+ }+ return;+ }++ // the same key again: buy what it marked+ clearPurchaseScienceColumn();+ if( win == NULL )+ return;++ // GenExpParent runs GeneralsExpPointsSystem, the callback a real click on the cameo reaches+ TheWindowManager->winSendSystemMsg( m_contextParent[ CP_PURCHASE_SCIENCE ], GBM_SELECTED,+ (WindowMsgData)win, win->winGetWindowId() );+ if( TheAudio )+ {+ AudioEventRTS buttonClick( "GUIGenShortcutClick" );+ TheAudio->addAudioEvent( &buttonClick );+ }++ updatePurchaseScienceHotKeys();++} // end pressPurchaseScienceColumn+void ControlBar::togglePurchaseScience( void ){if(m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex be10aab4b..3da66b318 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -3225,6 +3225,13 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage//Bool cancelledSomething = FALSE;+ // the general's promotion screen closes on escape like every other overlay in the game+ if( TheControlBar && TheControlBar->isPurchaseScienceVisible() )+ {+ TheControlBar->hidePurchaseScience();+ cancelledSomething = TRUE;+ }+if( TheControlBar && TheControlBar->isChordArmed() ){TheControlBar->dropChord();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex 6745f19a5..66a303a43 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -1110,6 +1110,21 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessacase GameMessage::MSG_META_SELECT_TEAM9:{Int group = t - GameMessage::MSG_META_SELECT_TEAM0;++ //+ // while the general's promotion screen is open the number keys belong to it: 1 to 5 are+ // its five columns, and the science a key would buy wears that number in its corner.+ // A screen that fills the middle of the display and answers nothing on the keyboard is+ // the thing being fixed, so group selection gives way for as long as it is up.+ //+ if( TheControlBar && TheControlBar->isPurchaseScienceVisible()+ && group >= 1 && group <= PURCHASE_SCIENCE_COLUMNS )+ {+ TheControlBar->pressPurchaseScienceColumn( group - 1 );+ disp = DESTROY_MESSAGE;+ break;+ }+if ( isValidHotkeySquadIndex( group ) ){DEBUG_LOG(("META: select team %d\n",group));diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 02d489ed4..bbaa29a09 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -2354,6 +2354,62 @@ TEST(pathfind_zone_flatten_collapses_a_deep_chain_in_one_pass)extern Int ControlBar_secondsFromFrames( Real frames );extern Int ControlBar_secondsFromFramesAt( Real frames, Int logicFps );extern Int ControlBar_experiencePercent( Int currentExp, Int levelExp, Int nextLevelExp );+extern Int ControlBar_purchaseScienceRank( Int column, Int depth, Int *indexOut );++TEST(controlbar_promotion_columns_map_to_the_screens_three_rows)+{+ Int index = -1;++ /* GeneralsExpPoints.wnd puts the 1 point row across the top: one button per column, and the+ fifth column - the one only the 3 point block is wide enough to have - has none */+ CHECK_EQ( ControlBar_purchaseScienceRank( 0, 0, &index ), 1 );+ CHECK_EQ( index, 0 );+ CHECK_EQ( ControlBar_purchaseScienceRank( 3, 0, &index ), 1 );+ CHECK_EQ( index, 3 );+ CHECK_EQ( ControlBar_purchaseScienceRank( 4, 0, &index ), 0 );+ CHECK_EQ( index, -1 );++ /* the 3 point block is filled down each column in turn - Rank3Number0..2 are the first+ column, 3..5 the second - which is the whole reason a column is a chain and not a row */+ CHECK_EQ( ControlBar_purchaseScienceRank( 0, 1, &index ), 3 );+ CHECK_EQ( index, 0 );+ CHECK_EQ( ControlBar_purchaseScienceRank( 0, 3, &index ), 3 );+ CHECK_EQ( index, 2 );+ CHECK_EQ( ControlBar_purchaseScienceRank( 1, 1, &index ), 3 );+ CHECK_EQ( index, 3 );+ CHECK_EQ( ControlBar_purchaseScienceRank( 4, 3, &index ), 3 );+ CHECK_EQ( index, MAX_PURCHASE_SCIENCE_RANK_3 - 1 );++ /* the 5 point row along the bottom, four wide like the top one */+ CHECK_EQ( ControlBar_purchaseScienceRank( 0, PURCHASE_SCIENCE_COLUMN_DEPTH - 1, &index ), 8 );+ CHECK_EQ( index, 0 );+ CHECK_EQ( ControlBar_purchaseScienceRank( 4, PURCHASE_SCIENCE_COLUMN_DEPTH - 1, &index ), 0 );++ /* every column reaches exactly the depths the layout has, and nothing past them */+ CHECK_EQ( ControlBar_purchaseScienceRank( 0, PURCHASE_SCIENCE_COLUMN_DEPTH, &index ), 0 );+ CHECK_EQ( ControlBar_purchaseScienceRank( PURCHASE_SCIENCE_COLUMNS, 0, &index ), 0 );+ CHECK_EQ( ControlBar_purchaseScienceRank( -1, 0, &index ), 0 );+ CHECK_EQ( ControlBar_purchaseScienceRank( 0, -1, &index ), 0 );++ /* no two cells name the same button: the mapping is a bijection onto the 23 windows */+ Int seen1 = 0, seen3 = 0, seen8 = 0;+ for( Int column = 0; column < PURCHASE_SCIENCE_COLUMNS; column++ )+ {+ for( Int depth = 0; depth < PURCHASE_SCIENCE_COLUMN_DEPTH; depth++ )+ {+ Int slot = -1;+ switch( ControlBar_purchaseScienceRank( column, depth, &slot ) )+ {+ case 1: CHECK( (seen1 & (1 << slot)) == 0 ); seen1 |= (1 << slot); break;+ case 3: CHECK( (seen3 & (1 << slot)) == 0 ); seen3 |= (1 << slot); break;+ case 8: CHECK( (seen8 & (1 << slot)) == 0 ); seen8 |= (1 << slot); break;+ }+ }+ }+ CHECK_EQ( seen1, (1 << MAX_PURCHASE_SCIENCE_RANK_1) - 1 );+ CHECK_EQ( seen3, (1 << MAX_PURCHASE_SCIENCE_RANK_3) - 1 );+ CHECK_EQ( seen8, (1 << MAX_PURCHASE_SCIENCE_RANK_8) - 1 );+}TEST(controlbar_seconds_round_up_and_never_reach_zero_early){