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(gameengine): build the builder's own reskin, not the one asked for
Olcay Seyganc3a6776f8825
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.hindex 113650441..298cb4efa 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h@@ -197,6 +197,11 @@ public:/// are all the requirements for making this unit (except available cash) are satisfiedvirtual Bool isPossibleToMakeUnit( Object *builder, const ThingTemplate *whatToBuild ) const;+ /** The template the builder's own build button names for whatToBuild, which differs from it when+ the two are reskins of each other: asked for an AmericaVehicleChinook, a Turkey Supply Center+ makes its TurkeyVehicleChinook. NULL when no button builds it. */+ const ThingTemplate *findBuildButtonTemplate( Object *builder, const ThingTemplate *whatToBuild ) const;+/// sell an objectvirtual void sellObject( Object *obj );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cppindex 1eb2fa1fc..ca9421c69 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp@@ -356,6 +356,10 @@ Object *BuildAssistant::buildObjectNow( Object *constructorObject, const ThingTe// A NULL constructor Object means a script built building so let it slide.if( (constructorObject != NULL) && !isPossibleToMakeUnit(constructorObject, what) )return NULL;+ // the dozer puts up its own side's building: a Turkey dozer the AI asks for an AmericaBarracks+ // builds a TurkeyBarracks, and an American one never a Turkish reskin+ if( constructorObject != NULL )+ what = findBuildButtonTemplate( constructorObject, what );// clear out any objects from the building area that are "auto-clearable" when buildingclearRemovableForConstruction( what, pos, angle );@@ -1382,6 +1386,24 @@ Bool BuildAssistant::isPossibleToMakeUnit( Object *builder, const ThingTemplateif( builder == NULL || whatToBuild == NULL )return FALSE;+ const ThingTemplate *buttonTemplate = findBuildButtonTemplate( builder, whatToBuild );+ if( buttonTemplate == NULL )+ return FALSE;++ // make sure that the player can actually make this unit by checking prereqs and such+ Player *player = builder->getControllingPlayer();+ if( player->canBuild( buttonTemplate ) == FALSE )+ return FALSE;++ // all is well+ return TRUE;++}++//-------------------------------------------------------------------------------------------------+const ThingTemplate *BuildAssistant::findBuildButtonTemplate( Object *builder, const ThingTemplate *whatToBuild ) const+{+// get the command set for the producer objectconst CommandSet *commandSet = TheControlBar->findCommandSet( builder->getCommandSetString() );@@ -1393,40 +1415,34 @@ Bool BuildAssistant::isPossibleToMakeUnit( Object *builder, const ThingTemplatewhatToBuild->getName().str(),builder->getTemplate()->getName().str(),builder->getTemplate()->getName().str()) );- return FALSE;+ return NULL;} // end if//// scan the command set, we must find whatToBuild as one of the "build" commands available// in the command set. We want to have all players run this logic on all their machines- // so that nobody can hack one game and cheat to make stuff that they can't usually make+ // so that nobody can hack one game and cheat to make stuff that they can't usually make.+ // A button naming whatToBuild itself wins over one naming a reskin of it.//- const CommandButton *commandButton;- const CommandButton *foundCommand = NULL;- Int i;- for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ const ThingTemplate *found = NULL;+ for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ ){-+// get this button- commandButton = commandSet->getCommandButton(i);+ const CommandButton *commandButton = commandSet->getCommandButton(i);if( commandButton &&(commandButton->getCommandType() == GUI_COMMAND_UNIT_BUILD ||commandButton->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT) &&commandButton->getThingTemplate()->isEquivalentTo(whatToBuild) )- foundCommand = commandButton;+ {+ found = commandButton->getThingTemplate();+ if( found == whatToBuild )+ break;+ }} // end for i- if( foundCommand == NULL )- return FALSE;-- // make sure that the player can actually make this unit by checking prereqs and such- Player *player = builder->getControllingPlayer();- if( player->canBuild( foundCommand->getThingTemplate() ) == FALSE )- return FALSE;-- // all is well- return TRUE;+ return found;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 27b77c53f..ddeb3d4e3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -919,6 +919,22 @@ void AIPlayer::clearTeamsInQueue( void )Object *AIPlayer::buildStructureNow(const ThingTemplate *bldgPlan, BuildListInfo *info){+ /* No builder here to pick the side's own building, so pick it from the side. Turkey's build list+ names AmericaCommandCenter (the skirmish scripts ask for it by that name), and the command+ center adjustBuildList puts up in place of the starting one came out American, with American+ dozers that built an American base. */+ if (bldgPlan->getDefaultOwningSide() != m_player->getSide())+ {+ for (const ThingTemplate *t = TheThingFactory->firstTemplate(); t; t = t->friend_getNextTemplate())+ {+ if (t->getDefaultOwningSide() == m_player->getSide() && t->isEquivalentTo(bldgPlan))+ {+ bldgPlan = t;+ break;+ }+ }+ }+// inst-construct the buildingObject *bldg = TheBuildAssistant->buildObjectNow( NULL,bldgPlan,diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cppindex b91362e0c..544eef6ca 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp@@ -424,6 +424,12 @@ Bool ProductionUpdate::queueCreateUnit( const ThingTemplate *unitType, Productio// if we can't create the unit do nothingif( TheBuildAssistant->canMakeUnit( getObject(), unitType ) != CANMAKE_OK )return FALSE;+ // the factory makes its own side's unit: asked by the AI for an AmericaVehicleChinook, a Turkey+ // Supply Center makes a TurkeyVehicleChinook, and an American one never a Turkish reskin. A+ // special power's construction (canMakeUnit's first OK) has no build button to read.+ const ThingTemplate *buttonType = TheBuildAssistant->findBuildButtonTemplate( getObject(), unitType );+ if( buttonType != NULL )+ unitType = buttonType;ExitDoorType exitDoor = DOOR_NONE_AVAILABLE;