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): build without a selected worker, behind an option
Olcay Seygan9eb23dded705
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d52128a4f..69e34399c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -894,7 +894,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- Hold shift and drag, and the row is one stroke. Press where the first building goes, drag the way the row runs, and a ghost appears for every building that fits end to end along the line, all facing the way the first one was turned. The row runs exactly the way you drag it, at 20 degrees as happily as along the map's edge, and packs the buildings as close as their shape allows: one turned onto the line of the row stands wall to wall with the next, and a factory keeps its door lane clear. A row of Power Plants turned square to the map packs 44 apart; it used to go down on whole grid squares, 50 apart, with a strip of dirt at every joint. It stops at the last building your bank can pay for. A ghost that lands on a rock or someone's tank turns red and is left out when you let go; the rest go up. With two or three workers selected the buildings are shared out to the nearest free one, and the ones nobody is free for wait as plans until a worker comes off its job. A plain drag still turns the building, and walls still tile the way they always did.- While that row is on the cursor, the wheel opens and closes the space between the buildings, one grid square a notch. The one where you pressed and the one under the cursor stay put; what changes is how many stand between them and how far apart those are. It will not pack them any tighter than they already sit against each other, and it will not take either end away to make the gap. Letting go places the row and takes the building off the cursor, so the next click is not another one. Holding shift and clicking them out one at a time still keeps the ghost up.- Hold Alt and drag while placing a building, and you lay out a block of them instead of a row. Ghosts stand for as many as your money covers, a blocked spot is skipped, and your builders work through the block in order.-- With nothing selected the command bar shows your builders' buildings again, and only those: clearing mines and the Demolition worker's suicide charge stay on a worker you actually select. Put one down and the idle worker nearest the spot walks over and builds it; when every worker is busy, the nearest one takes it on after the job in hand. A shift-dragged row placed this way is shared out among your idle workers. The bar keeps showing the same worker while you place, so a GLA worker switched to fake buildings stays on that page, and a fake is only ever handed to a worker who is on it. That last part holds with workers selected too: select a real-page and a fake-page worker together and a building goes to the one that can build it, where it used to go to the nearest and be refused. A replay with such a mixed selection in it plays back differently. The worker lending the bar its buildings no longer shows up beside them: its portrait, name and health filled the selection box, and players took the empty bar for a selected worker. The box stays empty until you select something.+- With nothing selected the command bar shows your builders' buildings again, and only those: clearing mines and the Demolition worker's suicide charge stay on a worker you actually select. Put one down and the idle worker nearest the spot walks over and builds it; when every worker is busy, the nearest one takes it on after the job in hand. A shift-dragged row placed this way is shared out among your idle workers. The bar keeps showing the same worker while you place, so a GLA worker switched to fake buildings stays on that page, and a fake is only ever handed to a worker who is on it. That last part holds with workers selected too: select a real-page and a fake-page worker together and a building goes to the one that can build it, where it used to go to the nearest and be refused. A replay with such a mixed selection in it plays back differently. The worker lending the bar its buildings no longer shows up beside them: its portrait, name and health filled the selection box, and players took the empty bar for a selected worker. The box stays empty until you select something. The one interface took all of this away for everyone; it is back as Build Without A Worker on the launcher's Options page, on unless you untick it, and off the bar stays empty until you select a worker, as in 2003.- Turning a building no longer turns everything you build afterwards. A wheeled heading still carries from one wall to the next, but the next supply centre comes out facing the way it was designed to.- A building you point at blocked ground slides to the nearest spot it fits, and lands there.- The pointer keeps its build cursor while you place, even passing over your own buildings.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 892c8fcf3..cf0d0f7a8 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -446,6 +446,7 @@ public:Bool m_isometricCamera; ///< the tactical view from far off down a narrow cone, near enough orthographicInt m_dragTolerance; ///< pixels the pointer may travel with a button held before the press is a drag; replaces Mouse.ini's DragToleranceBool m_formationDrag; ///< with the move, attack move or guard key armed, a left drag spreads the selection along the line drawn+ Bool m_buildWithoutWorker; ///< with nothing selected the command bar shows a builder's buildings; off, an empty bar as 1.04 had itBool m_chromaLighting; ///< put the state of the match on Razer hardwareInt m_menuTransitionSpeed; ///< percent of the authored speed the menus slide and fade at; 100 = as drawnInt m_textureFilterMode; ///< 0 bilinear, 1 trilinear, 2 anisotropicdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 87e3a983e..fd6152e6f 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -1208,6 +1208,8 @@ public:// get method for list of commandbuttonsconst CommandButton *getCommandButtons( void ) { return m_commandButtons; }+ Drawable *findStandInBuilder( Bool freeOnly ); ///< with BuildWithoutWorker on, the local player's free builder (or, unless freeOnly, any builder) to stand in for an empty selection+protected:ICoord2D m_defaultControlBarPosition; ///< Stored the original position of the control bar on the screen@@ -1226,7 +1228,8 @@ protected:Drawable *m_currentSelectedDrawable; ///< currently selected drawable for the context sensitive interfaceControlBarContext m_currContext; ///< our current displayed context- DrawableID m_rallyPointDrawableID; ///< rally point drawable for visual rally point+ DrawableID m_rallyPointDrawableID; ///< rally point drawable for visual rally point+ DrawableID m_standInBuilderID; ///< with nothing selected, the builder whose command bar is shown (INVALID_DRAWABLE_ID otherwise)Real m_displayedConstructPercent; ///< construct percent last displayed to userUnsignedInt m_displayedOCLTimerSeconds; ///< OCL Timer seconds remaining last displayed to userdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 085a1b0fa..71d6ee0ab 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -1175,6 +1175,7 @@ GlobalData::GlobalData()m_dragTolerance = 25; // what Mouse.ini in INIZH.big says, so nothing moves until the slider does// a left drag with the move, attack move or guard key armed draws a formation linem_formationDrag = TRUE;+ m_buildWithoutWorker = TRUE;m_chromaLighting = TRUE; //costs nothing on a machine with no Razer server: the handshake fails oncem_menuTransitionSpeed = 100;m_textureFilterMode = 2; // anisotropic; retail shipped bilinear on a 2003 fill-rate budgetdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cppindex 2a873c5f6..a5060f8b8 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp@@ -86,6 +86,7 @@ static void set_m_ambientVolume( Int value )TheAudio->setVolume( value / 100.0f, (AudioAffect)(AudioAffect_Ambient | AudioAffect_SystemSetting) );}OPTION_BOOL_ACCESSORS( m_formationDrag )+OPTION_BOOL_ACCESSORS( m_buildWithoutWorker )OPTION_BOOL_ACCESSORS( m_chromaLighting )OPTION_INT_ACCESSORS( m_bloomIntensity )OPTION_INT_ACCESSORS( m_menuTransitionSpeed )@@ -309,6 +310,14 @@ const OptionDef TheOptionCatalog[] =OPTION_BOOL, APPLY_LIVE, 0, 1,get_m_formationDrag, set_m_formationDrag },+ // With nothing selected the command bar shows one of your builders' buildings, and a structure put+ // down from it goes to the idle builder nearest the site. Client only: the logic already hands a+ // placement with no qualifying selected builder to one (MSG_DOZER_CONSTRUCT), so off only takes+ // the bar away, as 1.04 had it. The bar picks it up on its next evaluation.+ { "BuildWithoutWorker", "", "",+ OPTION_BOOL, APPLY_LIVE, 0, 1,+ get_m_buildWithoutWorker, set_m_buildWithoutWorker },+// The match on Razer hardware: the command bar on the letter keys, power on the digits,// superweapons on the numpad, money on the mousepad. Only during a match; off, and in every// menu, the keyboard goes back to whatever Synapse wants to do with it. On Options > Controls.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex f60d808b1..b4427d7d7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -1579,6 +1579,7 @@ ControlBar::ControlBar( void )m_multiSelectGroupCount = 0;m_multiSelectFocus = 0;m_rallyPointDrawableID = INVALID_DRAWABLE_ID;+ m_standInBuilderID = INVALID_DRAWABLE_ID;m_displayedConstructPercent = -1.0f;m_displayedOCLTimerSeconds = 0;m_displayedQueueCount = 0;@@ -2877,6 +2878,7 @@ void ControlBar::reset( void )hideSpecialPowerShortcut();// do not destroy the rally drawable, it will get destroyed with everythign else during a resetm_rallyPointDrawableID = INVALID_DRAWABLE_ID;+ m_standInBuilderID = INVALID_DRAWABLE_ID;m_displayedConstructPercent = -1.0f;m_displayedOCLTimerSeconds = 0;@@ -3146,6 +3148,33 @@ void ControlBar::update( void )elseclearPurchaseScienceColumn();+ //+ // a stand-in builder is not selected, so no deselect event tells us when it dies, when a real+ // selection arrives or when BuildWithoutWorker is switched off; re-evaluate ourselves before+ // anything touches its drawable+ //+ if( m_standInBuilderID != INVALID_DRAWABLE_ID )+ {+ Drawable *standIn = TheGameClient->findDrawableByID( m_standInBuilderID );+ Object *standInObj = standIn ? standIn->getObject() : NULL;+ if( TheInGameUI->getSelectCount() > 0 || standInObj == NULL || standInObj->isEffectivelyDead()+ || !TheGlobalData->m_buildWithoutWorker )+ {+ m_standInBuilderID = INVALID_DRAWABLE_ID;+ m_currentSelectedDrawable = NULL;+ markUIDirty();+ }+ }+ //+ // nothing selected and nothing standing in: a builder that is made or bought later, or the+ // option switched on, gets the bar, which no selection event would announce either+ //+ else if( logicTick && ( logicNow % LOGICFRAMES_PER_SECOND ) == 0 && TheInGameUI->getSelectCount() == 0+ && m_currentSelectedDrawable == NULL && findStandInBuilder( FALSE ) )+ {+ markUIDirty();+ }+//// first, if the UI is dirty repopulate the UI with what the user should see for all the// selected drawables@@ -3389,9 +3418,23 @@ void ControlBar::evaluateContextUI( void )// erase any current state of the GUI by switching out to the empty contextswitchToContext( CB_CONTEXT_NONE, NULL );- // nothing selected is an empty bar, as 1.04 had it+ //+ // nothing selected: with BuildWithoutWorker on, one of the player's builders stands in and its+ // command bar shows, so a structure can be placed without selecting a dozer first - the logic+ // then sends the idle builder nearest the site (MSG_DOZER_CONSTRUCT). Off, an empty bar, as+ // 1.04 had it. m_standInBuilderID is not cleared first: findStandInBuilder reads it to keep+ // the builder it is already showing.+ //if( TheInGameUI->getSelectCount() == 0 && !m_isObserverCommandBar )+ {+ Drawable *builder = findStandInBuilder( FALSE );+ m_standInBuilderID = builder ? builder->getID() : INVALID_DRAWABLE_ID;+ if( builder )+ switchToContext( CB_CONTEXT_COMMAND, builder );return;+ }++ m_standInBuilderID = INVALID_DRAWABLE_ID;// get the list of drawable IDs from the in game UIconst DrawableList *selectedDrawables = TheInGameUI->getAllSelectedDrawables();@@ -3938,6 +3981,78 @@ Bool ControlBar::cancelLastQueuedUnit( const ThingTemplate *thing )} // end cancelLastQueuedUnit+//-------------------------------------------------------------------------------------------------+/** The local player's builder that stands in for an empty selection: an idle one if there is+ * one, else any live one. (Player::iterateObjects callback + driver.) */+//-------------------------------------------------------------------------------------------------+struct StandInBuilderSearch+{+ Object *idle;+ Object *any;+};++static void findStandInBuilderProc( Object *obj, void *userData )+{+ StandInBuilderSearch *s = (StandInBuilderSearch *)userData;+ if( obj->isEffectivelyDead() || obj->getDrawable() == NULL )+ return;+ if( obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) || obj->testStatus( OBJECT_STATUS_SOLD ) )+ return;+ AIUpdateInterface *ai = obj->getAI();+ DozerAIInterface *dozer = ai ? ai->getDozerAIInterface() : NULL;+ if( dozer == NULL )+ return;+ if( s->any == NULL )+ s->any = obj;+ // free = no build/repair task and not hauling supplies; walking somewhere does not count+ const SupplyTruckAIInterface *supply = ai->getSupplyTruckAIInterface();+ if( s->idle == NULL && !dozer->isAnyTaskPending() && !( supply && supply->isCurrentlyFerryingSupplies() ) )+ s->idle = obj;+}++Drawable *ControlBar::findStandInBuilder( Bool freeOnly )+{+ // off, the bar is 1.04's: nothing selected is an empty bar, and a build needs a selected worker+ if( !TheGlobalData->m_buildWithoutWorker )+ return NULL;++ Player *player = ThePlayerList->getLocalPlayer();+ if( player == NULL )+ return NULL;++ //+ // The builder already standing in keeps the bar for as long as it is still a builder. The+ // sweep below answers "the first idle one", and idleness changes on its own: a dozer somewhere+ // across the base finishing a building goes idle and used to take the bar off the one you were+ // working with. That drops the page you were on and takes the structure off your cursor, in+ // the middle of placing it, because something happened somewhere else. For a GLA worker it+ // also keeps the fake-structure page it was switched to.+ //+ if( m_standInBuilderID != INVALID_DRAWABLE_ID )+ {+ Drawable *held = TheGameClient->findDrawableByID( m_standInBuilderID );+ Object *obj = held ? held->getObject() : NULL;+ if( obj && obj->getControllingPlayer() == player )+ {+ StandInBuilderSearch check;+ check.idle = NULL;+ check.any = NULL;+ findStandInBuilderProc( obj, &check );+ if( check.any && ( !freeOnly || check.idle ) )+ return held;+ }+ }++ StandInBuilderSearch s;+ s.idle = NULL;+ s.any = NULL;+ player->iterateObjects( findStandInBuilderProc, &s );++ Object *pick = s.idle ? s.idle : ( freeOnly ? NULL : s.any );+ return pick ? pick->getDrawable() : NULL;++} // end findStandInBuilder+//-------------------------------------------------------------------------------------------------/** Press the index'th general's power shortcut button, as a mouse click would *///-------------------------------------------------------------------------------------------------@@ -4599,6 +4714,12 @@ void ControlBar::setPortraitByImage( const Image *image )//-------------------------------------------------------------------------------------------------void ControlBar::setPortraitByObject( Object *obj ){+ // a builder standing in for an empty selection lends the bar its buildings and nothing else: its+ // portrait, name and health beside it read as that worker being selected, so the well stays empty+ if( obj && m_standInBuilderID != INVALID_DRAWABLE_ID && obj->getDrawable()+ && obj->getDrawable()->getID() == m_standInBuilderID )+ obj = NULL;+// the multi-select unit grid lives over this same HUD; a plain portrait means it must// go, and so must the selection-count badge a one-type selection put on the portrait.// updateMultiSelectStrip re-applies its own look right after calling in here.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cppindex 8d2542ee1..542ec41d5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -433,6 +433,16 @@ void ControlBar::populateCommand( Object *obj )slot[ i ] = shown[ i ] >= 0 ? set[ shown[ i ] ] : NULL;}+ // a builder standing in for an empty selection offers its buildings, not its orders: nobody+ // asked that dozer to go and clear mines+ if( m_standInBuilderID != INVALID_DRAWABLE_ID && obj->getDrawable()+ && obj->getDrawable()->getID() == m_standInBuilderID )+ {+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ if( slot[ i ] && ControlBar_namedCommandPlace( slot[ i ]->getName().str() ) == COMMAND_PLACE_CLEAR_MINES )+ slot[ i ] = NULL;+ }+// populate the button with commands definedconst CommandButton *commandButton;for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cppindex 1db911167..015db7819 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp@@ -90,13 +90,21 @@ static Bool getPlacementDrag( ICoord2D *start, ICoord2D *end )} // end getPlacementDrag//--------------------------------------------------------------------------------------------------/** The object that is to do the building, the one the placement was started from; NULL once it is- * dead, which ends the placement. */+/** The object that is to do the building. Normally the one the placement was started from, but+ * with nothing selected the command bar is being driven by a stand-in builder that is not part of+ * any selection, and that one is free to die between two clicks of a shift-held run of structures.+ * When it is gone the command bar's current stand-in keeps the ghost on the cursor: the logic picks+ * the idle builder nearest the site anyway (MSG_DOZER_CONSTRUCT). With BuildWithoutWorker off+ * there is no stand-in, and a dead builder ends the placement as it always did. *///-------------------------------------------------------------------------------------------------static Object *resolvePlacementBuilder( void ){Object *builder = TheGameLogic->findObjectByID( TheInGameUI->getPendingPlaceSourceObjectID() );- return ( builder != NULL && !builder->isEffectivelyDead() ) ? builder : NULL;+ if( builder != NULL && !builder->isEffectivelyDead() )+ return builder;++ Drawable *standIn = TheControlBar->findStandInBuilder( FALSE );+ return standIn ? standIn->getObject() : NULL;}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 7535648b4..4b44fc8ca 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -5382,6 +5382,37 @@ TEST(particlesys_debris_trails_option_destroys_only_marked_systems)TheWritableGlobalData = savedData;}+/* BuildWithoutWorker, on by default, is a live bool row with no control in the game's menu (the+ launcher writes it), and it round-trips through Options.ini. */+TEST(options_build_without_worker_row_defaults_on_and_round_trips)+{+ const OptionDef *def = findOptionDef( "BuildWithoutWorker" );+ CHECK( def != NULL );+ CHECK_EQ( (Int)def->kind, (Int)OPTION_BOOL );+ CHECK_EQ( (Int)def->apply, (Int)APPLY_LIVE );+ CHECK( def->widgetName == NULL || def->widgetName[ 0 ] == '\0' );++ GlobalData *savedData = TheWritableGlobalData;+ TheWritableGlobalData = NEW GlobalData;+ CHECK( TheGlobalData->m_buildWithoutWorker );+ CHECK_EQ( def->get(), 1 );++ UserPreferences pref;+ TheWritableGlobalData->m_buildWithoutWorker = FALSE;+ saveOptionsToPreferences( pref );+ CHECK_STR( pref[ AsciiString( "BuildWithoutWorker" ) ].str(), "no" );+ TheWritableGlobalData->m_buildWithoutWorker = TRUE;+ loadOptionsFromPreferences( pref );+ CHECK( !TheGlobalData->m_buildWithoutWorker );++ pref[ AsciiString( "BuildWithoutWorker" ) ] = AsciiString( "yes" );+ loadOptionsFromPreferences( pref );+ CHECK( TheGlobalData->m_buildWithoutWorker );++ delete TheWritableGlobalData;+ TheWritableGlobalData = savedData;+}+/* Loading a save has to put each system back under the id it was saved with. It used to build thesystem through createParticleSystem, which hands out the next id in sequence and files the systemunder it, and only then read the saved id over the top - so the manager's index pointed at the