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(gamelogic): historic bonus weapons, observer EVA, unpausing on load
Olcay Seygan8acdf9f11551
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.hindex 7c5c878ef..838f7f42c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h@@ -325,9 +325,10 @@ struct HistoricWeaponDamageInfo// The time and location this weapon was firedUnsignedInt frame;Coord3D location;+ UnsignedInt triggerId; ///< which firing of the bonus weapon this entry was counted towardsHistoricWeaponDamageInfo(UnsignedInt f, const Coord3D& l) :- frame(f), location(l)+ frame(f), location(l), triggerId(0){}};@@ -474,6 +475,8 @@ protected:// actually deal out the damage.void dealDamageInternal(ObjectID sourceID, ObjectID victimID, const Coord3D *pos, const WeaponBonus& bonus, Bool isProjectileDetonation) const;void trimOldHistoricDamage() const;+ void trimTriggeredHistoricDamage() const;+ void processHistoricDamage(const Object* source, const Coord3D* pos) const;private:@@ -558,6 +561,7 @@ private:Bool m_dieOnDetonate;mutable HistoricWeaponDamageList m_historicDamage;+ mutable UnsignedInt m_historicDamageTriggerId; ///< bumped every time the bonus weapon is considered};// ---------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 2ae5ebbef..52b5f1751 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -705,6 +705,12 @@ void Object::onContainedBy( Object *containedBy )m_containedBy = containedBy;m_containedByFrame = TheGameLogic->getFrame();+ // Going into something that is already on its way out leaves this object holding a pointer that+ // is about to be freed, and onDestroy then walks a contain list that no longer exists. That is+ // the shape of the Reinforcement Pad crash; say so loudly while there is still a stack to read.+ DEBUG_ASSERTCRASH( containedBy == NULL || !containedBy->isDestroyed(),+ ("Object::onContainedBy - going into a container that is already destroyed") );+handlePartitionCellMaintenance(); // which should unlook me now that I am contained}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cppindex edbc45e5e..ff734030a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp@@ -558,7 +558,18 @@ void SpecialPowerModule::aboutToDoSpecialPower( const Coord3D *location )// Let EVA do her thingSpecialPowerType type = getSpecialPowerModuleData()->m_specialPowerTemplate->getSpecialPowerType();+ /* An observer is not an active player, so every one of the tests below fell through to "enemy"+ and an observer heard the enemy warning for everything anybody launched. Watch whoever is+ being watched, the way the audio manager already does for the same reason. */Player *localPlayer = ThePlayerList->getLocalPlayer();+ if( localPlayer && !localPlayer->isPlayerActive() )+ {+ Player *observed = TheControlBar ? TheControlBar->getObserverLookAtPlayer() : NULL;+ if( observed )+ localPlayer = observed;+ }+ if( localPlayer == NULL )+ return;// Only play the EVA sounds if this is not the local player, and the local player doesn't consider the// person an enemy.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cppindex a031dcca6..da4c3ce6b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp@@ -329,6 +329,7 @@ WeaponTemplate::WeaponTemplate() : m_nextTemplate(NULL)m_damageStatusType = OBJECT_STATUS_NONE;m_suspendFXDelay = 0;m_dieOnDetonate = FALSE;+ m_historicDamageTriggerId = 0;}//-------------------------------------------------------------------------------------------------@@ -1221,24 +1222,87 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate}//-------------------------------------------------------------------------------------------------+static Bool is2DDistSquaredLessThan(const Coord3D& a, const Coord3D& b, Real distSqr);++//-------------------------------------------------------------------------------------------------+/** Drop the hits that are too old to count towards this weapon's bonus.+ *+ * The window is this weapon's own HistoricBonusTime, not the global historic damage limit: the+ * global one is longer, so hits that could never contribute were kept and counted, and a second+ * volley landing near the wreckage of the first set the bonus off again. */void WeaponTemplate::trimOldHistoricDamage() const{- UnsignedInt expirationDate = TheGameLogic->getFrame() - TheGlobalData->m_historicDamageLimit;- while (m_historicDamage.size() > 0)+ if (m_historicDamage.empty())+ return;++ const UnsignedInt expirationFrame = TheGameLogic->getFrame() - m_historicBonusTime;++ HistoricWeaponDamageList::iterator it = m_historicDamage.begin();+ while (it != m_historicDamage.end()){- HistoricWeaponDamageInfo& h = m_historicDamage.front();- if (h.frame <= expirationDate)- {- m_historicDamage.pop_front();- continue;- }+ if (it->frame <= expirationFrame)+ it = m_historicDamage.erase(it);else+ break; // they are in strict chronological order, so the rest are younger still+ }+}++//-------------------------------------------------------------------------------------------------+/** Drop only the hits that were counted towards the firing that just happened.+ *+ * This replaces an old "E3 hack" that emptied the whole list on success, with a comment saying it+ * was a plug and not a fix. Emptying it threw away hits from other places on the map that had+ * nothing to do with this bonus, so the next one needed a full count again from nothing. */+void WeaponTemplate::trimTriggeredHistoricDamage() const+{+ HistoricWeaponDamageList::iterator it = m_historicDamage.begin();+ while (it != m_historicDamage.end())+ {+ if (it->triggerId == m_historicDamageTriggerId)+ it = m_historicDamage.erase(it);+ else+ ++it;+ }+}++//-------------------------------------------------------------------------------------------------+/** Count the recent hits near this one and fire the bonus weapon when there are enough. */+void WeaponTemplate::processHistoricDamage(const Object *source, const Coord3D *pos) const+{+ if (m_historicBonusCount <= 0 || m_historicBonusWeapon == this)+ return;++ trimOldHistoricDamage();++ ++m_historicDamageTriggerId;++ const Int requiredCount = m_historicBonusCount - 1; // minus 1 since we include ourselves implicitly+ if ((Int)m_historicDamage.size() >= requiredCount)+ {+ const Real radSqr = m_historicBonusRadius * m_historicBonusRadius;+ Int count = 0;++ for (HistoricWeaponDamageList::iterator it = m_historicDamage.begin();+ it != m_historicDamage.end(); ++it){- // since they are in strict chronological order,- // stop as soon as we get to a nonexpired one- break;+ if (is2DDistSquaredLessThan( *pos, it->location, radSqr ))+ {+ // close enough in time (the trim above saw to that) and in distance, so mark it as+ // having gone towards this firing+ it->triggerId = m_historicDamageTriggerId;++ if (++count == requiredCount)+ {+ TheWeaponStore->createAndFireTempWeapon( m_historicBonusWeapon, source, pos );+ trimTriggeredHistoricDamage();+ return;+ }+ }}}++ // add AFTER checking for historic stuff+ m_historicDamage.push_back( HistoricWeaponDamageInfo( TheGameLogic->getFrame(), *pos ) );}//-------------------------------------------------------------------------------------------------@@ -1266,44 +1330,7 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co// firestorms (CBD) *///- trimOldHistoricDamage();-- if( m_historicBonusCount > 0 && m_historicBonusWeapon != this )- {- Real radSqr = m_historicBonusRadius * m_historicBonusRadius;- Int count = 0;- UnsignedInt frameNow = TheGameLogic->getFrame();- UnsignedInt oldestThatWillCount = frameNow - m_historicBonusTime; // Anything before this frame is "more than two seconds ago" eg- for( HistoricWeaponDamageList::const_iterator it = m_historicDamage.begin(); it != m_historicDamage.end(); ++it )- {- if( it->frame >= oldestThatWillCount &&- is2DDistSquaredLessThan( *pos, it->location, radSqr ) )- {- // This one is close enough in time and distance, so count it. This is tracked by template since it applies- // across units, so don't try to clear historicDamage on success in here.- ++count;- }- }-- if( count >= m_historicBonusCount - 1 ) // minus 1 since we include ourselves implicitly- {- TheWeaponStore->createAndFireTempWeapon(m_historicBonusWeapon, source, pos);-- /** @todo E3 hack! Clear the list for now to make sure we don't have multiple firestorms- * remove this when the branches merge back into one. What is causing the- * multiple firestorms, who is to say ... this is a plug, not a fix! */- m_historicDamage.clear();-- }- else- {-- // add AFTER checking for historic stuff- m_historicDamage.push_back( HistoricWeaponDamageInfo(frameNow, *pos) );-- } // end else-- } // if historic bonuses+ processHistoricDamage( source, pos );//DEBUG_LOG(("WeaponTemplate::dealDamageInternal: dealing damage %s at frame %d\n",m_name.str(),TheGameLogic->getFrame()));diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex b4430471d..c897f9b7f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -428,7 +428,12 @@ void GameLogic::reset( void )m_objVector.clear();m_objVector.resize(OBJ_HASH_SIZE, NULL);- m_gamePaused = FALSE;+ /* Unpause properly rather than just clearing the flag. Loading a save from the in-game menu+ resets while the game is paused, and setGamePaused is where the mouse comes back, the audio+ restarts and input is handed back to the player - clearing the flag by hand skips all of it,+ which is why the camera would not scroll at the screen edge after such a load. */+ setGamePaused( FALSE );+m_inputEnabledMemory = TRUE;m_mouseVisibleMemory = TRUE;setFPMode();