Skip to content

Commit 7f06777

Browse files
committed
refactor: Implement cleaner solution
1 parent 1501134 commit 7f06777

File tree

9 files changed

+26
-19
lines changed

9 files changed

+26
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class Object : public Thing, public Snapshot
418418
Int getTransportSlotCount() const;
419419
void friend_setContainedBy( Object *containedBy ) { m_containedBy = containedBy; }
420420
const Object* getEnclosingContainedBy() const; ///< Find the first enclosing container in the containment chain.
421-
Bool isSelfOrEnclosingContainedByVisible() const; ///< Is this object or its top-level container visible?
421+
const Object* getOuterObject() const; ///< Get the top-level object
422422

423423
// Special Powers -------------------------------------------------------------------------------
424424
SpecialPowerModuleInterface *getSpecialPowerModule( const SpecialPowerTemplate *specialPowerTemplate ) const;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,12 @@ const Object* Object::getEnclosingContainedBy() const
679679
return NULL;
680680
}
681681

682-
Bool Object::isSelfOrEnclosingContainedByVisible() const
682+
const Object* Object::getOuterObject() const
683683
{
684-
if (getDrawable() && getDrawable()->isVisible())
685-
return TRUE;
684+
if (const Object* enclosing = getEnclosingContainedBy())
685+
return enclosing;
686686

687-
const Object* container = getEnclosingContainedBy();
688-
return container && container->getDrawable() && container->getDrawable()->isVisible();
687+
return this;
689688
}
690689

691690
//-------------------------------------------------------------------------------------------------
@@ -2833,7 +2832,8 @@ void Object::onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel ne
28332832
Bool doAnimation = provideFeedback
28342833
&& newLevel > oldLevel
28352834
&& !isKindOf(KINDOF_IGNORED_IN_GUI)
2836-
&& isSelfOrEnclosingContainedByVisible();
2835+
&& getOuterObject()->getDrawable()
2836+
&& getOuterObject()->getDrawable()->isVisible();
28372837

28382838
if( doAnimation && TheGameLogic->getDrawIconUI() )
28392839
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,8 @@ 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->isSelfOrEnclosingContainedByVisible() // if user watching cannot see us
889+
Drawable* outerDrawable = sourceObj->getOuterObject()->getDrawable();
890+
if ((!outerDrawable || !outerDrawable->isVisible()) // if user watching cannot see us
890891
&& !sourceObj->isKindOf(KINDOF_MINE) // and not a mine (which always do the FX, even if hidden)...
891892
&& !isPlayFXWhenStealthed() // and not a weapon marked to playwhenstealthed
892893
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ class Object : public Thing, public Snapshot
443443
Int getTransportSlotCount() const;
444444
void friend_setContainedBy( Object *containedBy ) { m_containedBy = containedBy; }
445445
const Object* getEnclosingContainedBy() const; ///< Find the first enclosing container in the containment chain.
446-
Bool isSelfOrEnclosingContainedByVisible() const; ///< Is this object or its top-level container visible?
446+
const Object* getOuterObject() const; ///< Get the top-level object
447447

448448
// Special Powers -------------------------------------------------------------------------------
449449
SpecialPowerModuleInterface *getSpecialPowerModule( const SpecialPowerTemplate *specialPowerTemplate ) const;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,12 @@ const Object* Object::getEnclosingContainedBy() const
743743
return NULL;
744744
}
745745

746-
Bool Object::isSelfOrEnclosingContainedByVisible() const
746+
const Object* Object::getOuterObject() const
747747
{
748-
if (getDrawable() && getDrawable()->isVisible())
749-
return TRUE;
748+
if (const Object* enclosing = getEnclosingContainedBy())
749+
return enclosing;
750750

751-
const Object* container = getEnclosingContainedBy();
752-
return container && container->getDrawable() && container->getDrawable()->isVisible();
751+
return this;
753752
}
754753

755754
//-------------------------------------------------------------------------------------------------
@@ -3148,7 +3147,8 @@ void Object::onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel ne
31483147
Bool doAnimation = provideFeedback
31493148
&& newLevel > oldLevel
31503149
&& !isKindOf(KINDOF_IGNORED_IN_GUI)
3151-
&& isSelfOrEnclosingContainedByVisible();
3150+
&& getOuterObject()->getDrawable()
3151+
&& getOuterObject()->getDrawable()->isVisible();
31523152

31533153
if( doAnimation && TheGameLogic->getDrawIconUI() )
31543154
{

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->isSelfOrEnclosingContainedByVisible())
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "GameLogic/Module/AutoDepositUpdate.h"
6464
#include "GameLogic/Module/AIUpdate.h"
6565
#include "GameLogic/Object.h"
66+
#include "GameClient/Drawable.h"
6667
#include "GameClient/InGameUI.h"
6768
#include "GameClient/Color.h"
6869
#include "GameClient/GameText.h"
@@ -172,7 +173,8 @@ UpdateSleepTime AutoDepositUpdate::update( void )
172173
getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( modData->m_depositAmount);
173174
}
174175

175-
if (moneyAmount > 0 && getObject()->isSelfOrEnclosingContainedByVisible())
176+
Drawable* outerDrawable = getObject()->getOuterObject()->getDrawable();
177+
if (moneyAmount > 0 && outerDrawable && outerDrawable->isVisible())
176178
{
177179

178180
const Object *owner = getObject();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "GameLogic/Module/SupplyCenterDockUpdate.h"
3535
#include "GameLogic/Module/SupplyTruckAIUpdate.h"
3636
#include "GameClient/Color.h"
37+
#include "GameClient/Drawable.h"
3738
#include "GameClient/InGameUI.h"
3839
#include "GameClient/GameText.h"
3940

@@ -128,7 +129,8 @@ Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )
128129
}
129130
}
130131

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,8 @@ 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->isSelfOrEnclosingContainedByVisible() // if user watching cannot see us
920+
Drawable* outerDrawable = sourceObj->getOuterObject()->getDrawable();
921+
if ((!outerDrawable || !outerDrawable->isVisible()) // if user watching cannot see us
921922
&& !sourceObj->isKindOf(KINDOF_MINE) // and not a mine (which always do the FX, even if hidden)...
922923
&& !isPlayFXWhenStealthed() // and not a weapon marked to playwhenstealthed
923924
)

0 commit comments

Comments
 (0)