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): seven from the upstream ledger
Olcay Seygan7a63fca6a681
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex d8b9fe7fe..fc92789ef 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -534,7 +534,7 @@ public:* The selected team is created/augmented with the given team members.* Do not play their selection sounds.*/- MSG_DESTROY_SELECTED_GROUP, ///< (teamID) the given team is no longer valid+ MSG_DESTROY_SELECTED_GROUP, ///< deselect currently selected objects (which can be none)MSG_REMOVE_FROM_SELECTED_GROUP, /**< (objectID1, objectID2, ... objectIDN)* Remove these units from the selected group. (N should almost always be 1)*/diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.hindex 02f2b75bd..57fb5eb9d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h@@ -178,6 +178,7 @@ public:virtual const Object *friend_getRider() const = 0; ///< Damn. The draw order dependency bug for riders means that our draw module needs to cheat to get around it.virtual Real getContainedItemsMass() const = 0;virtual UnsignedInt getStealthUnitsContained() const = 0;+ virtual UnsignedInt getHeroUnitsContained() const = 0;virtual Bool calcBestGarrisonPosition( Coord3D *sourcePos, const Coord3D *targetPos ) = 0;virtual Bool attemptBestFirePointPosition( Object *source, Weapon *weapon, Object *victim ) = 0;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.hindex 3e3ba8dbd..e9fc84b74 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h@@ -177,6 +177,7 @@ public:virtual const Object *friend_getRider() const{return NULL;} ///< Damn. The draw order dependency bug for riders means that our draw module needs to cheat to get around it.virtual Real getContainedItemsMass() const;virtual UnsignedInt getStealthUnitsContained() const { return m_stealthUnitsContained; }+ virtual UnsignedInt getHeroUnitsContained() const { return m_heroUnitsContained; }virtual PlayerMaskType getPlayerWhoEntered(void) const { return m_playerEnteredMask; }@@ -262,6 +263,8 @@ private:ObjectEnterExitMap m_objectEnterExitInfo;UnsignedInt m_stealthUnitsContained; ///< number of stealth units that can't be seen by enemy players.+ UnsignedInt m_heroUnitsContained; ///< how many heroes are inside, kept as a count so isHero costs nothing+ XferVersion m_xferVersion; ///< which save version was loaded, for loadPostProcessInt m_whichExitPath; ///< Cycles from 1 to n and is used only in modules whose data has numberOfExitPaths > 1.UnsignedInt m_doorCloseCountdown; ///< When should I shut my door.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex b15e433cb..16e1e4ca3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -4618,10 +4618,9 @@ void InGameUI::deselectAllDrawables( Bool postMsg )the order of operations of things happening in the code (CBD) */if( postMsg ){- GameMessage *groupMsg = TheMessageStream->appendMessage( GameMessage::MSG_DESTROY_SELECTED_GROUP );-- //True deletes entire group.- groupMsg->appendBooleanArgument( true );+ // The message carried one boolean that nothing on the receiving side ever read: the handler+ // deselects the whole group and always did.+ TheMessageStream->appendMessage( GameMessage::MSG_DESTROY_SELECTED_GROUP );}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cppindex 0a8a234f2..d864a9afe 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp@@ -574,6 +574,7 @@ void FlightDeckBehavior::calcPPInfo( ObjectID id, PPInfo *info )if (it->m_inUseByForTakeoff == id ){info->runwayStart = info->runwayPrep;+ break;}}}@@ -591,6 +592,7 @@ void FlightDeckBehavior::releaseSpace(ObjectID id)if (it->m_objectInSpace == id){it->m_objectInSpace = INVALID_ID;+ break;}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/InstantDeathBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/InstantDeathBehavior.cppindex 1dee7bc88..fa7829e5a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/InstantDeathBehavior.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/InstantDeathBehavior.cpp@@ -158,8 +158,12 @@ void InstantDeathBehavior::onDie( const DamageInfo *damageInfo )ObjectCreationList::create(ocl, getObject(), NULL);}+ /* A building killed while it is still a scaffold has not been paid for and was never armed, so+ the death weapon does not go off. Otherwise cancelling a half-built structure sets off the+ explosion it would have made as a finished one, which damages whatever is standing next to a+ construction site - free artillery, aimed by the dozer. */listSize = d->m_weapons.size();- if (listSize > 0)+ if (listSize > 0 && !getObject()->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION )){idx = GameLogicRandomValue(0, listSize-1);const WeaponTemplateVec& v = d->m_weapons;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cppindex c24c6e3cc..68d7aa635 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp@@ -414,9 +414,13 @@ void ParkingPlaceBehavior::calcPPInfo( ObjectID id, PPInfo *info )for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it){- if (it->m_inUseBy == id && it->m_wasInLine)+ if (it->m_inUseBy == id){- info->runwayStart = info->runwayPrep;+ if (it->m_wasInLine)+ {+ info->runwayStart = info->runwayPrep;+ }+ break;}}}@@ -437,6 +441,7 @@ void ParkingPlaceBehavior::releaseSpace(ObjectID id)it->m_reservedForExit = false;if (pu)pu->setHoldDoorOpen(it->m_door, false);+ break;}}@@ -479,11 +484,15 @@ void ParkingPlaceBehavior::transferRunwayReservationToNextInLineForTakeoff(ObjecpurgeDead();for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it){- if (it->m_inUseBy == id && it->m_nextInLineForTakeoff != INVALID_ID)+ if (it->m_inUseBy == id){- it->m_inUseBy = it->m_nextInLineForTakeoff;- it->m_wasInLine = true;- it->m_nextInLineForTakeoff = INVALID_ID;+ if (it->m_nextInLineForTakeoff != INVALID_ID)+ {+ it->m_inUseBy = it->m_nextInLineForTakeoff;+ it->m_wasInLine = true;+ it->m_nextInLineForTakeoff = INVALID_ID;+ }+ break;}}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cppindex 91a933f00..414612ad9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp@@ -134,6 +134,8 @@ OpenContain::OpenContain( Thing *thing, const ModuleData* moduleData ) : UpdateMm_lastLoadSoundFrame = 0;m_containListSize = 0;m_stealthUnitsContained = 0;+ m_heroUnitsContained = 0;+ m_xferVersion = 1;m_doorCloseCountdown = 0;//Added By Sadullah Nader@@ -380,6 +382,10 @@ void OpenContain::addToContainList( Object *rider ){m_stealthUnitsContained++;}+ if( rider->isKindOf( KINDOF_HERO ) )+ {+ m_heroUnitsContained++;+ }}//-------------------------------------------------------------------------------------------------@@ -663,6 +669,8 @@ void OpenContain::removeFromContainViaIterator( ContainedItemsList::iterator it,m_containListSize--;if( rider->isKindOf( KINDOF_STEALTH_GARRISON ) ){+ DEBUG_ASSERTCRASH( m_stealthUnitsContained > 0,+ ("OpenContain: removing a stealth unit while the count says %d", m_stealthUnitsContained) );m_stealthUnitsContained--;if( exposeStealthUnits ){@@ -673,6 +681,12 @@ void OpenContain::removeFromContainViaIterator( ContainedItemsList::iterator it,}}}+ if( rider->isKindOf( KINDOF_HERO ) )+ {+ DEBUG_ASSERTCRASH( m_heroUnitsContained > 0,+ ("OpenContain: removing a hero while the count says %d", m_heroUnitsContained) );+ m_heroUnitsContained--;+ }if (isEnclosingContainerFor( rider ))@@ -1636,15 +1650,18 @@ void OpenContain::crc( Xfer *xfer )// ------------------------------------------------------------------------------------------------/** Xfer method* Version Info:- * 1: Initial version */+ * 1: Initial version+ * 2: passengers allowed to fire+ * 3: the contained hero count, which used to be recounted on every ask */// ------------------------------------------------------------------------------------------------void OpenContain::xfer( Xfer *xfer ){- // version- const XferVersion currentVersion = 2;+ // version+ const XferVersion currentVersion = 3;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );+ m_xferVersion = version;// extend base classUpdateModule::xfer( xfer );@@ -1720,6 +1737,12 @@ void OpenContain::xfer( Xfer *xfer )// stealth units containedxfer->xferUnsignedInt( &m_stealthUnitsContained );+ // hero units contained; a save written before version 3 recounts them in loadPostProcess+ if( version >= 3 )+ {+ xfer->xferUnsignedInt( &m_heroUnitsContained );+ }+// door close countdownxfer->xferUnsignedInt( &m_doorCloseCountdown );@@ -1859,6 +1882,19 @@ void OpenContain::loadPostProcess( void )} // end for, idIt+ // A save written before version 3 has no hero count in it, so count them now that the contain+ // list has been rebuilt.+ if( m_xferVersion < 3 )+ {+ m_heroUnitsContained = 0;+ for( ContainedItemsList::const_iterator heroIt = m_containList.begin();+ heroIt != m_containList.end(); ++heroIt )+ {+ if( (*heroIt)->isKindOf( KINDOF_HERO ) )+ m_heroUnitsContained++;+ }+ }+// sanityDEBUG_ASSERTCRASH( m_containListSize == m_containList.size(),("OpenContain::loadPostProcess - contain list count mismatch\n") );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cppindex 664f7d21f..21173ecd6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cpp@@ -248,11 +248,17 @@ void RiderChangeContain::onContaining( Object *rider, Bool wasSelected )}}- //Transfer experience from the rider to the bike.+ /* Transfer experience from the rider to the bike, but only onto something the data says+ can hold a rank. A tracker that is not trainable is one whose object was never meant to+ wear a chevron, and handing it a veterancy level does exactly that - and then the level+ comes back to the next rider on the way out. */ExperienceTracker *riderTracker = rider->getExperienceTracker();ExperienceTracker *bikeTracker = obj->getExperienceTracker();- bikeTracker->setVeterancyLevel( riderTracker->getVeterancyLevel(), FALSE );- riderTracker->setExperienceAndLevel( 0, FALSE );+ if( bikeTracker->isTrainable() )+ {+ bikeTracker->setVeterancyLevel( riderTracker->getVeterancyLevel(), FALSE );+ riderTracker->setExperienceAndLevel( 0, FALSE );+ }break;}@@ -303,11 +309,14 @@ void RiderChangeContain::onRemoving( Object *rider )//Wow, completely unforseeable game teardown order crash. SetVeterancyLevel results in a call to player//about upgrade masks. So if we have a null player, it is game teardown, so don't worry about transfering exp.- //Transfer experience from the bike to the rider.+ // Transfer experience from the bike to the rider - same rule as on the way in.ExperienceTracker *riderTracker = rider->getExperienceTracker();ExperienceTracker *bikeTracker = bike->getExperienceTracker();- riderTracker->setVeterancyLevel( bikeTracker->getVeterancyLevel(), FALSE );- bikeTracker->setExperienceAndLevel( 0, FALSE );+ if( riderTracker->isTrainable() )+ {+ riderTracker->setVeterancyLevel( bikeTracker->getVeterancyLevel(), FALSE );+ bikeTracker->setExperienceAndLevel( 0, FALSE );+ }}break;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 64cb3c215..456281d04 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -2044,28 +2044,16 @@ Bool Object::isNonFactionStructure(void) constreturn isStructure() && !isFactionStructure();}-void localIsHero( Object *obj, void* userData )-{- Bool *hero = (Bool*)userData;-- if( obj && obj->isKindOf( KINDOF_HERO ) )- {- *hero = TRUE;- }-}-//-------------------------------------------------------------------------------------------------+/** A transport counts as a hero while it is carrying one, which is what puts the hero's marker on+ the radar. This used to walk the whole contained list on every ask, and the radar asks about+ every object it draws; the container keeps a count now, so the answer costs a comparison. */Bool Object::isHero(void) const{ContainModuleInterface *contain = getContain();- if( contain )+ if( contain && contain->getHeroUnitsContained() > 0 ){- Bool heroInside = FALSE;- contain->iterateContained( localIsHero, (void*)(&heroInside), FALSE );- if( heroInside )- {- return TRUE;- }+ return TRUE;}return isKindOf( KINDOF_HERO );}@@ -2972,14 +2960,38 @@ void Object::scoreTheKill( const Object *victim )controller->doBountyForKill(this, victim);}- // Now handle experience, if we can gain any- if (m_experienceTracker && m_experienceTracker->isAcceptingExperiencePoints())+ /* Now handle experience, if we can gain any.++ A thing made by an ObjectCreationList - the explosion a bomb leaves behind, the fire a molotov+ starts, the wreck a vehicle throws - takes no experience itself, so a kill it made used to be+ worth nothing to anybody. It knows who made it, because ObjectCreationList::create writes the+ source in as the producer, so walk up to whoever can take the points and give them there.++ The walk is a chain and not a single step: a transport makes a payload which makes the thing+ that does the killing. It stops at a fixed depth rather than trusting the data not to contain+ a loop, and it stops at the first owner who can accept points, which is the one that fired. */+ const Int MAX_PRODUCER_HOPS = 4;+ Object *earner = this;+ for( Int hop = 0; hop < MAX_PRODUCER_HOPS; ++hop )+ {+ ExperienceTracker *tracker = earner->getExperienceTracker();+ if (tracker && tracker->isAcceptingExperiencePoints())+ break;++ Object *producer = TheGameLogic->findObjectByID( earner->getProducerID() );+ if (producer == NULL || producer == earner)+ break;+ earner = producer;+ }++ ExperienceTracker *earnerTracker = earner->getExperienceTracker();+ if (earnerTracker && earnerTracker->isAcceptingExperiencePoints()){// srj sez: per dustin, no experience (et al) for killing things under construction.if (!victim->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION)){- Int experienceValue = victim->getExperienceTracker()->getExperienceValue( this );- getExperienceTracker()->addExperiencePoints( experienceValue );+ Int experienceValue = victim->getExperienceTracker()->getExperienceValue( earner );+ earnerTracker->addExperiencePoints( experienceValue );}}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cppindex dd09fb2be..1f6b45728 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp@@ -1400,7 +1400,27 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3// fall into a building. if a vehicle, blow up. then destroy ourself (not die), regardless.if (obj->isKindOf(KINDOF_VEHICLE)){- TheWeaponStore->createAndFireTempWeapon(getPhysicsBehaviorModuleData()->m_vehicleCrashesIntoBuildingWeaponTemplate, obj, obj->getPosition());+ /* The crash weapon used to be fired where the vehicle landed, which gave it the+ weapon's whole blast radius: everything parked near the building took the hit as+ well. A vehicle falling on a building damages that building. Same numbers, same+ fire effect, one target. */+ const WeaponTemplate *crashWeapon =+ getPhysicsBehaviorModuleData()->m_vehicleCrashesIntoBuildingWeaponTemplate;+ if (crashWeapon != NULL)+ {+ WeaponBonus nullBonus;++ DamageInfo damageInfo;+ damageInfo.in.m_damageType = crashWeapon->getDamageType();+ damageInfo.in.m_deathType = crashWeapon->getDeathType();+ damageInfo.in.m_sourceID = obj->getID();+ damageInfo.in.m_sourcePlayerMask =+ obj->getControllingPlayer() ? obj->getControllingPlayer()->getPlayerMask() : 0;+ damageInfo.in.m_amount = crashWeapon->getPrimaryDamage( nullBonus );++ other->attemptDamage( &damageInfo );+ FXList::doFXObj( crashWeapon->getFireFX( obj->getVeterancyLevel() ), obj );+ }}TheGameLogic->destroyObject(obj);return;