Skip to content

Commit 20f88f4

Browse files
authored
bugfix: Fix effect visibility of contained objects (#1878)
1 parent 5de3d63 commit 20f88f4

File tree

9 files changed

+46
-13
lines changed

9 files changed

+46
-13
lines changed

Generals/Code/GameEngine/Include/GameLogic/Object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ class Object : public Thing, public Snapshot
418418
void onRemovedFrom( Object *removedFrom );
419419
Int getTransportSlotCount() const;
420420
void friend_setContainedBy( Object *containedBy ) { m_containedBy = containedBy; }
421-
Object* getEnclosingContainedBy(); ///< Find the first enclosing container in the containment chain.
421+
const Object* getEnclosingContainedBy() const; ///< Find the first enclosing container in the containment chain.
422+
const Object* getOuterObject() const; ///< Get the top-level object
422423

423424
// Special Powers -------------------------------------------------------------------------------
424425
SpecialPowerModuleInterface *getSpecialPowerModule( const SpecialPowerTemplate *specialPowerTemplate ) const;

Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,9 @@ Int Object::getTransportSlotCount() const
668668
return count;
669669
}
670670

671-
Object* Object::getEnclosingContainedBy()
671+
const Object* Object::getEnclosingContainedBy() const
672672
{
673-
for (Object* child = this, *container = getContainedBy(); container; child = container, container = container->getContainedBy())
673+
for (const Object* child = this, *container = getContainedBy(); container; child = container, container = container->getContainedBy())
674674
{
675675
ContainModuleInterface* containModule = container->getContain();
676676
if (containModule && containModule->isEnclosingContainerFor(child))
@@ -680,6 +680,14 @@ Object* Object::getEnclosingContainedBy()
680680
return NULL;
681681
}
682682

683+
const Object* Object::getOuterObject() const
684+
{
685+
if (const Object* enclosing = getEnclosingContainedBy())
686+
return enclosing;
687+
688+
return this;
689+
}
690+
683691
//-------------------------------------------------------------------------------------------------
684692
/** Run from GameLogic::destroyObject */
685693
//-------------------------------------------------------------------------------------------------
@@ -2830,10 +2838,13 @@ void Object::onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel ne
28302838
break;
28312839
}
28322840

2841+
Drawable* outerDrawable = getOuterObject()->getDrawable();
2842+
28332843
Bool doAnimation = provideFeedback
28342844
&& newLevel > oldLevel
28352845
&& !isKindOf(KINDOF_IGNORED_IN_GUI)
2836-
&& getDrawable()->isVisible();
2846+
&& outerDrawable
2847+
&& outerDrawable->isVisible();
28372848

28382849
if( doAnimation && TheGameLogic->getDrawIconUI() )
28392850
{

Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,10 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
886886

887887
// TheSuperHackers @todo: Remove hardcoded KINDOF_MINE check and apply PlayFXWhenStealthed = Yes to the mine weapons instead.
888888

889-
if(!sourceObj->getDrawable()->isVisible() // if user watching cannot see us
889+
Drawable* outerDrawable = sourceObj->getOuterObject()->getDrawable();
890+
const Bool isVisible = outerDrawable && outerDrawable->isVisible();
891+
892+
if (!isVisible // if user watching cannot see us
890893
&& !sourceObj->isKindOf(KINDOF_MINE) // and not a mine (which always do the FX, even if hidden)...
891894
&& !isPlayFXWhenStealthed() // and not a weapon marked to playwhenstealthed
892895
)

GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ class Object : public Thing, public Snapshot
443443
void onRemovedFrom( Object *removedFrom );
444444
Int getTransportSlotCount() const;
445445
void friend_setContainedBy( Object *containedBy ) { m_containedBy = containedBy; }
446-
Object* getEnclosingContainedBy(); ///< Find the first enclosing container in the containment chain.
446+
const Object* getEnclosingContainedBy() const; ///< Find the first enclosing container in the containment chain.
447+
const Object* getOuterObject() const; ///< Get the top-level object
447448

448449
// Special Powers -------------------------------------------------------------------------------
449450
SpecialPowerModuleInterface *getSpecialPowerModule( const SpecialPowerTemplate *specialPowerTemplate ) const;

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,9 @@ Int Object::getTransportSlotCount() const
732732
return count;
733733
}
734734

735-
Object* Object::getEnclosingContainedBy()
735+
const Object* Object::getEnclosingContainedBy() const
736736
{
737-
for (Object* child = this, *container = getContainedBy(); container; child = container, container = container->getContainedBy())
737+
for (const Object* child = this, *container = getContainedBy(); container; child = container, container = container->getContainedBy())
738738
{
739739
ContainModuleInterface* containModule = container->getContain();
740740
if (containModule && containModule->isEnclosingContainerFor(child))
@@ -744,6 +744,14 @@ Object* Object::getEnclosingContainedBy()
744744
return NULL;
745745
}
746746

747+
const Object* Object::getOuterObject() const
748+
{
749+
if (const Object* enclosing = getEnclosingContainedBy())
750+
return enclosing;
751+
752+
return this;
753+
}
754+
747755
//-------------------------------------------------------------------------------------------------
748756
/** Run from GameLogic::destroyObject */
749757
//-------------------------------------------------------------------------------------------------
@@ -3145,10 +3153,13 @@ void Object::onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel ne
31453153
break;
31463154
}
31473155

3156+
Drawable* outerDrawable = getOuterObject()->getDrawable();
3157+
31483158
Bool doAnimation = provideFeedback
31493159
&& newLevel > oldLevel
31503160
&& !isKindOf(KINDOF_IGNORED_IN_GUI)
3151-
&& getDrawable()->isVisible();
3161+
&& outerDrawable
3162+
&& outerDrawable->isVisible();
31523163

31533164
if( doAnimation && TheGameLogic->getDrawIconUI() )
31543165
{

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ StateReturnType HackInternetState::update()
543543
//Grant the unit some experience for a successful hack.
544544
xp->addExperiencePoints( ai->getXpPerCashUpdate() );
545545

546-
if (owner->getDrawable()->isVisible())
546+
Drawable* outerDrawable = owner->getOuterObject()->getDrawable();
547+
if (outerDrawable && outerDrawable->isVisible())
547548
{
548549
// OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!
549550
//Display cash income floating over the hacker.

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ UpdateSleepTime AutoDepositUpdate::update( void )
173173
getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( modData->m_depositAmount);
174174
}
175175

176-
if (moneyAmount > 0 && getObject()->getDrawable()->isVisible())
176+
Drawable* outerDrawable = getObject()->getOuterObject()->getDrawable();
177+
if (moneyAmount > 0 && outerDrawable && outerDrawable->isVisible())
177178
{
178179

179180
const Object *owner = getObject();

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )
129129
}
130130
}
131131

132-
if (value > 0 && getObject()->getDrawable()->isVisible())
132+
Drawable* outerDrawable = getObject()->getOuterObject()->getDrawable();
133+
if (value > 0 && outerDrawable && outerDrawable->isVisible())
133134
{
134135
// OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!
135136
// Setup info for adding a floating text

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,10 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
917917

918918
// TheSuperHackers @todo: Remove hardcoded KINDOF_MINE check and apply PlayFXWhenStealthed = Yes to the mine weapons instead.
919919

920-
if(!sourceObj->getDrawable()->isVisible() // if user watching cannot see us
920+
Drawable* outerDrawable = sourceObj->getOuterObject()->getDrawable();
921+
const Bool isVisible = outerDrawable && outerDrawable->isVisible();
922+
923+
if (!isVisible // if user watching cannot see us
921924
&& !sourceObj->isKindOf(KINDOF_MINE) // and not a mine (which always do the FX, even if hidden)...
922925
&& !isPlayFXWhenStealthed() // and not a weapon marked to playwhenstealthed
923926
)

0 commit comments

Comments
 (0)