Skip to content

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.

fix(gameengine): captured builders make their own side's objects

Olcay Seyganf78ded5eb8c8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 15983c7a6..bd1c68ef2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -939,6 +939,7 @@ found and fixed, EA's own, not port damage.**
- The Aurora's bomb goes off like the strike it is. It hits for 400 where a Scud Launcher's missile hits for 300, and buildings take one and a half to three times that, yet it blew up with one carpet bomb's puff, smaller than the missile's. The blast is now two to two and a half times the Scud's across: arms of fire flung twice as far, four big napalm fireballs, a shock ring 210 wide where the carpet bomb's stops near 90, a rolling dust ring, fourteen clods of dirt and a column of smoke, with a hard shake, a wide scorch and a bend in the picture on Direct3D 11. It is over in about two seconds. Its damage is unchanged. This is the Aurora of every American general; the Alpha Aurora keeps its fuel-air blast.
- The Toxin and Stealth Generals get their Technicals again. Since v3.3.0 the Arms Dealer took the 500, ran the build timer and let nothing out, and the queue moved on to the next unit. EA has both generals roll the plain GLA Technical, and the code that hands Turkiye its own copies of American units mistook the general's Technical button for a copy of that truck, so it built the button instead of the truck. In a test queue of six, none came out before and all six do now. The plain GLA and the Demolition General were never hit. Replays recorded with a Toxin or Stealth Technical before this change play out differently.
+- A Turkiye player's captured buildings and builders make their own side's things again, as in the original game. A captured China dozer told to put up an Airfield built the Kargu drone base, Turkiye's superweapon, for the Airfield's 1000 instead of 5000, and a captured GLA Command Center trained Turkiye Engineers when you paid for Workers. Now the dozer builds a China Airfield and the Command Center a GLA Worker, each at its own price. Turkiye's own buildings and units are unchanged.
- The Dragon Tank's Fire Wall burns where you put it again. An earlier change in this build handed each patch of the wall the full speed of the flame that lit it, so the fire slid off across the map: in one test the patches came to rest anywhere from 155 to 1,050 away from the tank, 800 on average, setting fire to whatever stood in the way. They now stop 120 to 180 from the tank, a little past where the flames land, as they did in the original game. Napalm bombs and the wrecks of shot-down planes and drones keep their original drift too. Replays recorded before this change play out differently.
- A bunker buster shot down on the way in no longer clears out the building it was aimed at. It emptied the bunker from wherever it happened to be destroyed - a Point Defence Laser did not save you, it just moved the explosion.
- A Battle Bus in its wrecked form takes attack orders again. Every order you gave it was dropped on the way, because the crew inside are 'held' and held units were skipped.
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 27e61bf3f..837e0b218 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -265,6 +265,7 @@ Data/Scenarios/blastcheck.txt
Data/Scenarios/bridgecross.txt
Data/Scenarios/bridgelong.txt
Data/Scenarios/broadcastend.txt
+Data/Scenarios/capturedbuild.txt
Data/Scenarios/cargocrash.txt
Data/Scenarios/chokeprobe.txt
Data/Scenarios/comanchehill.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/capturedbuild.txt b/GeneralsMD/Code/Data/Scenarios/capturedbuild.txt
new file mode 100644
index 000000000..e56277782
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/capturedbuild.txt
@@ -0,0 +1,34 @@
+# A Turkiye player building with another side's builders, as after capturing a China and a GLA base.
+#
+# Seat 0 plays Turkiye and owns a China dozer and supply center and a GLA Command Center, the way a
+# capture leaves them. The dozer is told to put up a China Airfield and the Command Center to train a
+# Worker; then Turkiye's own Command Center trains an Engineer and an Engineer puts up a Power Plant.
+# Read the tallies: before the fix the Airfield came out as the Kargu superweapon (TurkiyeKarguBase)
+# for an Airfield's $1000 and the Worker as a TurkiyeInfantryEngineer. After it the China dozer makes
+# a ChinaAirfield and the GLA Command Center a GLAInfantryWorker, each for its own price, and
+# Turkiye's own builds come out as before.
+#
+# generals.exe -headless -quickstart -noshellmap -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionTurkiye -side 1 FactionGLA -seed 7 -maxframes 5200
+# -scenario capturedbuild -logPrefix capbuild_
+#
+# Seat 0 starts at 537,3188; every spot below was accepted by the spawn check on that map.
+
+60 spawn 0 ChinaVehicleDozer 1 800 3050
+60 spawn 0 ChinaSupplyCenter 1 697 2868
+60 spawn 0 GLACommandCenter 1 377 2868
+90 tally 0 *
+100 construct 0 ChinaAirfield 880 3220
+110 tally 0 *
+120 produce 0 GLACommandCenter GLAInfantryWorker 1
+130 tally 0 *
+140 produce 0 TurkiyeCommandCenter TurkiyeInfantryEngineer 1
+150 tally 0 *
+600 construct 0 TurkiyePowerPlant 257 3188
+610 tally 0 *
+2500 tally 0 ChinaAirfield
+2500 tally 0 TurkiyeKarguBase
+2500 tally 0 GLAInfantryWorker
+2500 tally 0 TurkiyeInfantryEngineer
+2500 tally 0 TurkiyePowerPlant
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ThingFactory.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingFactory.h
index df9cad9fb..7a2cbf23a 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/ThingFactory.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingFactory.h
@@ -86,8 +86,11 @@ public:
/** request a new object using the given template.
this will throw an exception on failure; it will never return null.
+ producer is the factory, builder or hole making it, when there is one: the object comes out as the
+ producer's side builds it, not as the owner's side would, so a captured China Airfield's MiG or a
+ captured GLA Command Center's Worker stays China's or GLA's for a Turkiye player.
*/
- Object *newObject( const ThingTemplate *tmplate, Team *team, ObjectStatusMaskType statusMask = OBJECT_STATUS_MASK_NONE );
+ Object *newObject( const ThingTemplate *tmplate, Team *team, ObjectStatusMaskType statusMask = OBJECT_STATUS_MASK_NONE, const Object *producer = NULL );
/** The reskin of tmplate that belongs to side, when tmplate belongs to another: TurkiyeInfantryPilot
for an AmericaInfantryPilot made for a Turkiye player. NULL when there is none. newObject makes
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
index bf4596de3..dd2d6beb0 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
@@ -420,7 +420,7 @@ Object *BuildAssistant::buildObjectNow( Object *constructorObject, const ThingTe
if( what->isKindOf( KINDOF_STRUCTURE ) )
startingStatus.set( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_UNDER_CONSTRUCTION ) );
- Object *obj = TheThingFactory->newObject( what, owningPlayer->getDefaultTeam(), startingStatus );
+ Object *obj = TheThingFactory->newObject( what, owningPlayer->getDefaultTeam(), startingStatus, constructorObject );
obj->setProducer(constructorObject);
// place on terrain surface
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
index a0e57e5c0..0533b6c2a 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp
@@ -325,7 +325,7 @@ ThingTemplate *ThingFactory::findTemplateInternal( const AsciiString& name, Bool
} // end getTemplate
//=============================================================================
-Object *ThingFactory::newObject( const ThingTemplate *tmplate, Team *team, ObjectStatusMaskType statusBits )
+Object *ThingFactory::newObject( const ThingTemplate *tmplate, Team *team, ObjectStatusMaskType statusBits, const Object *producer )
{
if (tmplate == NULL)
throw ERROR_BAD_ARG;
@@ -339,11 +339,15 @@ Object *ThingFactory::newObject( const ThingTemplate *tmplate, Team *team, Objec
tmplate = tmp;
}
- // a side's own reskin in place of another side's template: Turkiye is built on the American data
+ // a side's own reskin in place of another side's template: Turkiye is built on the American data.
+ // The side is the producer's when there is one. Taken from the owner, a Turkiye player's captured
+ // China dozer put up the Kargu superweapon for an Airfield's 1000, because TurkiyeKarguBase is a
+ // reskin of ChinaAirfield, and a captured GLA Command Center trained Turkiye engineers for Workers.
const Player *owner = team ? team->getControllingPlayer() : NULL;
if (owner != NULL)
{
- const ThingTemplate *own = findSideReskin( tmplate, owner->getSide() );
+ const AsciiString &side = producer ? producer->getTemplate()->getDefaultOwningSide() : owner->getSide();
+ const ThingTemplate *own = findSideReskin( tmplate, side );
if (own != NULL)
tmplate = own;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/RebuildHoleBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/RebuildHoleBehavior.cpp
index 54b01c3fd..afa2a176d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/RebuildHoleBehavior.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/RebuildHoleBehavior.cpp
@@ -237,7 +237,7 @@ UpdateSleepTime RebuildHoleBehavior::update( void )
m_workerTemplate = TheThingFactory->findTemplate( modData->m_workerTemplateName );
// create a worker
- worker = TheThingFactory->newObject( m_workerTemplate, hole->getTeam() );
+ worker = TheThingFactory->newObject( m_workerTemplate, hole->getTeam(), OBJECT_STATUS_MASK_NONE, hole );
if( worker )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
index 94e05cf72..284ae0319 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
@@ -1883,7 +1883,7 @@ Object *DozerAIUpdate::construct( const ThingTemplate *what,
statusBits.set( OBJECT_STATUS_RECONSTRUCTING );
// create an object at the destination location
- Object *obj = TheThingFactory->newObject( what, owningPlayer->getDefaultTeam(), statusBits );
+ Object *obj = TheThingFactory->newObject( what, owningPlayer->getDefaultTeam(), statusBits, getObject() );
// even though we haven't actually built anything yet, this keeps things tidy
obj->setProducer( getObject() );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp
index bf5cdd0a7..8a8e3449b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp
@@ -954,7 +954,8 @@ UpdateSleepTime ProductionUpdate::update( void )
if( d->m_numDoorAnimations == 0 || door == NULL || door->m_doorWaitOpenFrame != 0 )
{
Object *newObj = TheThingFactory->newObject( production->m_objectToProduce,
- creationBuilding->getControllingPlayer()->getDefaultTeam() );
+ creationBuilding->getControllingPlayer()->getDefaultTeam(),
+ OBJECT_STATUS_MASK_NONE, creationBuilding );
newObj->setProducer(creationBuilding);