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): what a watcher can actually see, in one place
Olcay Seygan59bf4cac6801
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex a6fe71111..a6e7bba8e 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -475,6 +475,9 @@ public:void onRemovedFrom( Object *removedFrom );Int getTransportSlotCount() const;void friend_setContainedBy( Object *containedBy ) { m_containedBy = containedBy; }+ const Object* getEnclosingContainedBy() const; ///< the first container up the chain that hides what is inside it+ const Object* getOuterObject() const; ///< that container, or this object when nothing hides it+ Bool isLogicallyVisible() const; ///< can the watching player see this at all, shroud aside// Special Powers -------------------------------------------------------------------------------SpecialPowerModuleInterface *getSpecialPowerModule( const SpecialPowerTemplate *specialPowerTemplate ) const;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cppindex 8064f4b8d..7d3a6f2d7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp@@ -243,18 +243,18 @@ void TunnelContain::onRemoving( Object *obj )// object is no longer held inside a garrisoned buildingobj->clearDisabled( DISABLED_HELD );- /// place the object in the world at position of the container m_object- ThePartitionManager->registerObject( obj );+ /* Put the object back in the world at the tunnel's position.++ This used to register it with the partition manager and unhide its drawable by hand, which+ does most of what is needed and skips the rest: whatever the object had attached to it - the+ flame on a flame trooper, a rider's own drawable - stayed hidden, so a unit that came out of a+ tunnel inside the fog carried invisible attachments around with it. addOrRemoveObjFromWorld+ is the one that puts every piece of an object back. */obj->setPosition( getObject()->getPosition() );- if( obj->getDrawable() )- {- obj->setSafeOcclusionFrame(TheGameLogic->getFrame()+obj->getTemplate()->getOcclusionDelay());- obj->getDrawable()->setDrawableHidden( false );- }+ obj->setSafeOcclusionFrame( TheGameLogic->getFrame() + obj->getTemplate()->getOcclusionDelay() );+ addOrRemoveObjFromWorld( obj, TRUE );doUnloadSound();--}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 456281d04..2ae5ebbef 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -743,6 +743,61 @@ Int Object::getTransportSlotCount() constreturn count;}+//-------------------------------------------------------------------------------------------------+/** The first container up the chain that visibly encloses what is inside it. A man in a Humvee is+ * enclosed; a man riding a bike is not. NULL when nothing hides this object. */+//-------------------------------------------------------------------------------------------------+const Object* Object::getEnclosingContainedBy() const+{+ for (const Object *child = this, *container = getContainedBy(); container;+ child = container, container = container->getContainedBy())+ {+ ContainModuleInterface *containModule = container->getContain();+ if (containModule && containModule->isEnclosingContainerFor( child ))+ return container;+ }+ return NULL;+}++//-------------------------------------------------------------------------------------------------+/** Whatever the watching player would actually be looking at: the transport if this is inside one,+ * otherwise this object. */+//-------------------------------------------------------------------------------------------------+const Object* Object::getOuterObject() const+{+ const Object *enclosing = getEnclosingContainedBy();+ return enclosing ? enclosing : this;+}++//-------------------------------------------------------------------------------------------------+/** Whether the watching player can see this at all, leaving the shroud out of it.+ *+ * Client-side feedback - the rank-up animation, the floating cash, a weapon's muzzle flash - used+ * to ask the object's own drawable whether it was visible. A passenger inside a transport has a+ * drawable that is hidden, so a man who ranked up in a Humvee got no chevron; and a unit that had+ * left a tunnel had a visible drawable while it was still stealthed, so it announced itself.+ * Ask about the thing the player is looking at, and ask about stealth rather than about a+ * drawable's hidden flag. */+//-------------------------------------------------------------------------------------------------+Bool Object::isLogicallyVisible() const+{+ const Object *obj = getOuterObject();++ // A disguised unit is meant to be seen by everybody, and the disguise status is briefly absent+ // while the disguise is being put on, so ask what it is rather than what it is doing.+ if (obj->isKindOf( KINDOF_DISGUISER ))+ return TRUE;++ if (obj->testStatus( OBJECT_STATUS_STEALTHED ) && !obj->testStatus( OBJECT_STATUS_DETECTED ))+ {+ const Player *player = ThePlayerList->getLocalPlayer();+ if (player && player->isPlayerActive() && player->getRelationship( getTeam() ) != ALLIES)+ return FALSE;+ }++ return TRUE;+}+//-------------------------------------------------------------------------------------------------/** Run from GameLogic::destroyObject *///-------------------------------------------------------------------------------------------------@@ -3211,8 +3266,10 @@ void Object::onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel ne// the same for a player but is wrong for everyone else at the table: an ally who shares your// sight, and an observer who sees everything, both got nothing. The drawable already answers// the question for whoever is watching.- const Drawable *draw = getDrawable();- Bool hideAnimationForStealth = ( draw == NULL || !((Drawable *)draw)->isVisible() );+ // And "this watcher can see the unit" means the thing on screen, which for a passenger is the+ // transport it is riding in - a man who ranks up inside a Humvee has a hidden drawable of his+ // own and used to get no chevron at all.+ Bool hideAnimationForStealth = !isLogicallyVisible();Bool doAnimation = ( ! hideAnimationForStealth&& (newLevel > oldLevel)diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cppindex a61671bcf..d37fea73c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp@@ -558,11 +558,10 @@ StateReturnType HackInternetState::update()//// A hacker working from inside an Internet Center has no drawable on screen at all -// a garrisoned unit is hidden by its container - so asking the hacker whether it can- // be seen answered no for the whole time the money was coming in. The thing on- // screen is the building, so it is the building that gets asked.+ // be seen answered no for the whole time the money was coming in. isLogicallyVisible+ // asks about the thing on screen, which is the building.Object *internetCenter = owner->getContainedBy();- Drawable *ownerDraw = internetCenter ? internetCenter->getDrawable() : owner->getDrawable();- Bool displayMoney = ( ownerDraw != NULL && ownerDraw->isVisible() );+ Bool displayMoney = owner->isLogicallyVisible();if( displayMoney ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cppindex d2a7b8f2f..d990d6a7a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp@@ -212,8 +212,7 @@ UpdateSleepTime AutoDepositUpdate::update( void )// OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!// The figure shows if this watcher can see the building - which covers an ally sharing the// sight and an observer, both of whom the old spelled-out rule left out.- Drawable *depositDraw = getObject()->getDrawable();- Bool displayMoney = ( moneyAmount > 0 && depositDraw != NULL && depositDraw->isVisible() );+ Bool displayMoney = ( moneyAmount > 0 && getObject()->isLogicallyVisible() );if( displayMoney ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cppindex 62775f39f..6322e5c75 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp@@ -147,8 +147,7 @@ Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )// OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!// The figure shows if this watcher can see the centre - an ally sharing the sight and an// observer both got nothing from the old spelled-out rule.- Drawable *centerDraw = getObject()->getDrawable();- Bool displayMoney = ( value > 0 && centerDraw != NULL && centerDraw->isVisible() );+ Bool displayMoney = ( value > 0 && getObject()->isLogicallyVisible() );if( displayMoney ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cppindex b4d60fe9e..a031dcca6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp@@ -941,8 +941,10 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate// used to be spelled out as "not mine, and stealthed, and not detected, and not disguised",// which reads the same for a player but hid the shot from an ally who shares your sight and// from an observer who sees everything.- Drawable *sourceDraw = sourceObj->getDrawable();- if((sourceDraw == NULL || !sourceDraw->isVisible()) // if the watcher cannot see us+ // And it asks about stealth rather than about a drawable's hidden flag: a unit that has just+ // left a tunnel has a visible drawable while it is still stealthed, and used to give itself+ // away with its own muzzle flash.+ if(!sourceObj->isLogicallyVisible() // if the watcher cannot see us&& !sourceObj->isKindOf(KINDOF_MINE) // and not a mine (which always do the FX, even if hidden)...&& !isPlayFXWhenStealthed() // and not a weapon marked to playwhenstealthed)