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): group-select structures, spread unit builds over factories
Olcay Seygan75261acc107a
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cppindex 8516d1354..a75a2fa93 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp@@ -396,8 +396,30 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,//const ThingTemplate *whatToBuild = commandButton->getThingTemplate();- // get the "factory" object that is going to make the thing+ // get the "factory" object that is going to make the thing. With several factories+ // selected (multi-select context) use the one with the fewest queued items that can+ // actually make it, so repeated clicks spread the work over all selected factoriesObject *factory = obj;+ if( factory == NULL && m_currContext == CB_CONTEXT_MULTI_SELECT )+ {+ UnsignedInt bestCount = 0;+ const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();+ for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )+ {+ Object *candidate = (*it)->getObject();+ ProductionUpdateInterface *cpu = candidate ? candidate->getProductionUpdateInterface() : NULL;+ if( cpu == NULL || TheBuildAssistant->canMakeUnit( candidate, whatToBuild ) != CANMAKE_OK )+ continue;+ if( factory == NULL || cpu->getProductionCount() < bestCount )+ {+ factory = candidate;+ bestCount = cpu->getProductionCount();+ }+ }+ // nothing can take it: fall back to the first factory so the usual messages fire+ if( factory == NULL && !selected->empty() )+ factory = selected->front()->getObject();+ }if( factory == NULL )break;@@ -458,6 +480,7 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_QUEUE_UNIT_CREATE );msg->appendIntegerArgument( whatToBuild->getTemplateID() );msg->appendIntegerArgument( productionID );+ msg->appendObjectIDArgument( factory->getID() ); // which of the selected factories builds itbreak;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cppindex 579ab8ba0..3bae57445 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp@@ -127,8 +127,12 @@ void ControlBar::addCommonCommands( Drawable *draw, Bool firstDrawable )// get commandcommand = commandSet->getCommandButton(i);- // add if present and can be used in a multi select- if( command && BitTest( command->getOptions(), OK_FOR_MULTI_SELECT ) == TRUE )+ // add if present and can be used in a multi select. Unit builds are allowed too: the+ // later drawables only keep a slot whose button is identical, so they survive only+ // when every selected factory shares the same command set (processCommandUI then+ // routes the build to the selected factory with the shortest queue)+ if( command && ( BitTest( command->getOptions(), OK_FOR_MULTI_SELECT ) == TRUE ||+ command->getCommandType() == GUI_COMMAND_UNIT_BUILD ) ){// put it in the common command setdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex 82be60e10..15b92162f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -533,7 +533,8 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessaselectMore->appendBooleanArgument(FALSE);for (DrawableListIt it = listOfSelectedDrawables.begin(); it != listOfSelectedDrawables.end(); ++it) {Drawable *draw = *it;- if (draw && draw->isSelectable()) {+ // buildings and units stay in separate selections+ if (draw && draw->isSelectable() && draw->isKindOf( KINDOF_STRUCTURE ) == picked->isKindOf( KINDOF_STRUCTURE )) {TheInGameUI->selectDrawable(draw);selectMore->appendObjectIDArgument(draw->getObject()->getID());}@@ -642,8 +643,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessaif (si.currentCountEnemies > 0 ||si.currentCountCivilians > 0 ||- si.currentCountFriends > 0 ||- si.currentCountMineBuildings > 0)+ si.currentCountFriends > 0){// force a new group creationaddToGroup = FALSE;@@ -654,46 +654,21 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa{si.selectMine = TRUE;- // EXACTLY ONE CLICKED OR DRAGGED BUILDING- if ( si.newCountMineBuildings == 1 && si.newCountMine == 1 )+ //+ // Buildings can be group-selected (click, drag, shift-add) like units, but buildings and+ // units never share one selection: a pick of one kind replaces a selection of the other.+ // A pick containing both keeps only the units, as it always did.+ //+ if ( si.newCountMine == si.newCountMineBuildings ){- addToGroup = FALSE;si.selectMineBuildings = TRUE;- }- else if ( si.newCountMineBuildings > 0 )////////////// SO SORRY, I KNOW THIS IS MICKEY MOUSE ///////////////////- { // What we are after here is to allow the drag select to get the building,- // if the other things in the list are going to be ignored anyway- // so we find out whether the other things are not selectible- // this came up with the new AmericaBuildingFireBase, which shows its contained- // but does not let you select them. The selection is propagated to the container- // in new code in SelectionInfo.cpp, in the static addDrawableToList();- // -Mark Lorenzen, 6/12/03- Bool onlyTheOneBuildingIsSelectableAnyway = TRUE;- DrawableID buildingID = INVALID_DRAWABLE_ID;- for (DrawableListIt it = drawablesThatWillSelect.begin(); it != drawablesThatWillSelect.end(); ++it)- {- const Drawable *d = *it;- if ( d->isKindOf( KINDOF_STRUCTURE ) )- {// make sure there is really only the one building in the list, as it may be multiply listed-- if ( buildingID == INVALID_DRAWABLE_ID ) // this is the first building- buildingID = d->getID();- else if ( buildingID != d->getID() )//oops, more than one building!- onlyTheOneBuildingIsSelectableAnyway = FALSE;- }- else if ( d->isSelectable() )- onlyTheOneBuildingIsSelectableAnyway = FALSE;-- if ( ! onlyTheOneBuildingIsSelectableAnyway )- break;- }- if ( onlyTheOneBuildingIsSelectableAnyway )- {- addToGroup = FALSE;- si.selectMineBuildings = TRUE;- }+ if ( si.currentCountMine > si.currentCountMineBuildings )+ addToGroup = FALSE;+ }+ else if ( si.currentCountMineBuildings > 0 )+ {+ addToGroup = FALSE;}-}else if (si.newCountEnemies > 0 && si.newCountCivilians > 0 && si.newCountFriends > 0){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 0182d5695..389e64abc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -3047,7 +3047,8 @@ Bool Object::isSelectable() const//-------------------------------------------------------------------------------------------------Bool Object::isMassSelectable() const{- return isSelectable() && !isKindOf(KINDOF_STRUCTURE);+ // structures are group-selectable too (SelectionXlat keeps them apart from units)+ return isSelectable();}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 632d43fbc..a77d4bca1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -1327,7 +1327,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )//---------------------------------------------------------------------------------------------case GameMessage::MSG_QUEUE_UNIT_CREATE:{- Object *producer = getSingleObjectFromSelection(currentlySelectedGroup);+ Object *producer = NULL;const ThingTemplate *whatToCreate;ProductionID productionID;@@ -1335,6 +1335,17 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )whatToCreate = TheThingFactory->findByTemplateID( msg->getArgument( 0 )->integer );productionID = (ProductionID)msg->getArgument( 1 )->integer;+ // an explicit producer (multi-select build) must be one of the selected objects+ if( msg->getArgumentCount() > 2 && currentlySelectedGroup )+ {+ ObjectID producerID = msg->getArgument( 2 )->objectID;+ const VecObjectID& ids = currentlySelectedGroup->getAllIDs();+ if( std::find( ids.begin(), ids.end(), producerID ) != ids.end() )+ producer = TheGameLogic->findObjectByID( producerID );+ }+ else+ producer = getSingleObjectFromSelection(currentlySelectedGroup);+// sanityif ( producer == NULL || whatToCreate == NULL )break;