Skip to content

Commit 8d675a8

Browse files
authored
refactor: Use new utility logic for handling observed player behaviour (#1861)
1 parent 59482a6 commit 8d675a8

File tree

14 files changed

+40
-60
lines changed

14 files changed

+40
-60
lines changed

Generals/Code/GameEngine/Include/GameClient/ControlBar.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,6 @@ class ControlBar : public SubsystemInterface
734734
Player* getCurrentlyViewedPlayer();
735735
/// Returns the relationship with the currently viewed player. May return NEUTRAL if no player is selected while observing.
736736
Relationship getCurrentlyViewedPlayerRelationship(const Team* team);
737-
/// Returns the currently viewed player. Returns "Observer" if no player is selected while observing.
738-
AsciiString getCurrentlyViewedPlayerSide();
739737

740738
// ControlBarResizer *getControlBarResizer( void ) {return m_controlBarResizer;}
741739

Generals/Code/GameEngine/Source/GameClient/Drawable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ Bool Drawable::drawsAnyUIText( void )
22732273
return FALSE;
22742274

22752275
const Object *obj = getObject();
2276-
if ( !obj || obj->getControllingPlayer() != TheControlBar->getCurrentlyViewedPlayer())
2276+
if ( !obj || obj->getControllingPlayer() != rts::getObservedOrLocalPlayer())
22772277
return FALSE;
22782278

22792279
Player *owner = obj->getControllingPlayer();
@@ -2422,7 +2422,7 @@ void Drawable::drawAmmo( const IRegion2D *healthBarRegion )
24222422
if (!(
24232423
TheGlobalData->m_showObjectHealth &&
24242424
(isSelected() || (TheInGameUI && (TheInGameUI->getMousedOverDrawableID() == getID()))) &&
2425-
obj->getControllingPlayer() == TheControlBar->getCurrentlyViewedPlayer()
2425+
obj->getControllingPlayer() == rts::getObservedOrLocalPlayer()
24262426
))
24272427
return;
24282428

@@ -2480,7 +2480,7 @@ void Drawable::drawContained( const IRegion2D *healthBarRegion )
24802480
if (!(
24812481
TheGlobalData->m_showObjectHealth &&
24822482
(isSelected() || (TheInGameUI && (TheInGameUI->getMousedOverDrawableID() == getID()))) &&
2483-
obj->getControllingPlayer() == TheControlBar->getCurrentlyViewedPlayer()
2483+
obj->getControllingPlayer() == rts::getObservedOrLocalPlayer()
24842484
))
24852485
return;
24862486

@@ -2953,7 +2953,7 @@ void Drawable::drawBombed(const IRegion2D* healthBarRegion)
29532953
UnsignedInt now = TheGameLogic->getFrame();
29542954

29552955
if( obj->testWeaponSetFlag( WEAPONSET_CARBOMB ) &&
2956-
obj->getControllingPlayer() == TheControlBar->getCurrentlyViewedPlayer())
2956+
obj->getControllingPlayer() == rts::getObservedOrLocalPlayer())
29572957
{
29582958
if( !getIconInfo()->m_icon[ ICON_CARBOMB ] )
29592959
getIconInfo()->m_icon[ ICON_CARBOMB ] = newInstance(Anim2D)( s_animationTemplates[ ICON_CARBOMB ], TheAnim2DCollection );

Generals/Code/GameEngine/Source/GameClient/Eva.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "GameClient/ControlBar.h"
2929
#include "GameClient/Eva.h"
3030

31+
#include "Common/GameUtility.h"
3132
#include "Common/Player.h"
3233
#include "Common/PlayerList.h"
3334
#include "GameLogic/GameLogic.h"
@@ -212,7 +213,7 @@ void Eva::update()
212213
return;
213214
}
214215

215-
m_localPlayer = TheControlBar->getCurrentlyViewedPlayer();
216+
m_localPlayer = rts::getObservedOrLocalPlayer();
216217
UnsignedInt frame = TheGameLogic->getFrame();
217218

218219
// Don't update for the first few frames. This way, we don't have to deal with our initial power
@@ -429,7 +430,7 @@ void Eva::processPlayingMessages(UnsignedInt currentFrame)
429430
}
430431

431432
// We've got a winner!
432-
AsciiString side = TheControlBar->getCurrentlyViewedPlayerSide();
433+
AsciiString side = rts::getObservedOrLocalPlayer()->getSide();
433434
Int numSides = storedIt->m_evaInfo->m_evaSideSounds.size();
434435

435436
for (Int i = 0; i < numSides; ++i) {

Generals/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,6 @@ Relationship ControlBar::getCurrentlyViewedPlayerRelationship(const Team* team)
173173
return NEUTRAL;
174174
}
175175

176-
AsciiString ControlBar::getCurrentlyViewedPlayerSide()
177-
{
178-
if (Player* player = getCurrentlyViewedPlayer())
179-
player->getSide();
180-
181-
return ThePlayerList->getLocalPlayer()->getSide();
182-
}
183-
184176
void ControlBar::populatePurchaseScience( Player* player )
185177
{
186178
// TheInGameUI->deselectAllDrawables();

Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5562,10 +5562,12 @@ void InGameUI::removeIdleWorker( Object *obj, Int playerNumber )
55625562

55635563
void InGameUI::selectNextIdleWorker( void )
55645564
{
5565-
Int index = TheControlBar->getCurrentlyViewedPlayer()->getPlayerIndex();
5565+
Player* player = rts::getObservedOrLocalPlayer();
5566+
Int index = player->getPlayerIndex();
5567+
55665568
if(m_idleWorkers[index].empty())
55675569
{
5568-
DEBUG_ASSERTCRASH(FALSE, ("InGameUI::selectNextIdleWorker We're trying to select a worker when our list is empty for player %ls", ThePlayerList->getLocalPlayer()->getPlayerDisplayName().str()));
5570+
DEBUG_ASSERTCRASH(FALSE, ("InGameUI::selectNextIdleWorker We're trying to select a worker when our list is empty for player %ls", player->getPlayerDisplayName().str()));
55695571
return;
55705572
}
55715573
Object *selectThisObject = NULL;
@@ -5652,13 +5654,9 @@ ObjectPtrVector InGameUI::getUniqueIdleWorkers(const ObjectList& idleWorkers)
56525654

56535655
Int InGameUI::getIdleWorkerCount( void )
56545656
{
5655-
if (Player* player = TheControlBar->getCurrentlyViewedPlayer())
5656-
{
5657-
Int index = player->getPlayerIndex();
5658-
return m_idleWorkers[index].size();
5659-
}
5660-
5661-
return 0;
5657+
Player* player = rts::getObservedOrLocalPlayer();
5658+
Int index = player->getPlayerIndex();
5659+
return m_idleWorkers[index].size();
56625660
}
56635661

56645662
void InGameUI::showIdleWorkerLayout( void )

Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ void findCommandCenterOrMostExpensiveBuilding(Object* obj, void* vccl)
886886

887887
static void viewCommandCenter( void )
888888
{
889-
Player* localPlayer = TheControlBar->getCurrentlyViewedPlayer();
890-
if (!localPlayer)
889+
Player* localPlayer = rts::getObservedOrLocalPlayer();
890+
if (!localPlayer->isPlayerActive())
891891
return;
892892

893893
CommandCenterLocator ccl;
@@ -928,8 +928,8 @@ void amIAHero(Object* obj, void* heroHolder)
928928

929929
static Object *iNeedAHero( void )
930930
{
931-
Player* localPlayer = TheControlBar->getCurrentlyViewedPlayer();
932-
if (!localPlayer)
931+
Player* localPlayer = rts::getObservedOrLocalPlayer();
932+
if (!localPlayer->isPlayerActive())
933933
return NULL;
934934

935935
HeroHolder heroHolder;

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <assetmgr.h>
5757
#include <texture.h>
5858

59+
#include "Common/GameUtility.h"
5960
#include "Common/GlobalData.h"
6061
#include "Common/RandomValue.h"
6162
#include "Common/ThingFactory.h"
@@ -223,7 +224,7 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
223224
Int numPoints = 0;
224225
if( obj )
225226
{
226-
if ( obj->getControllingPlayer() != TheControlBar->getCurrentlyViewedPlayer())
227+
if ( obj->getControllingPlayer() != rts::getObservedOrLocalPlayer())
227228
continue;
228229

229230
ExitInterface *exitInterface = obj->getObjectExitInterface();

GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,6 @@ class ControlBar : public SubsystemInterface
748748
Player* getCurrentlyViewedPlayer();
749749
/// Returns the relationship with the currently viewed player. May return NEUTRAL if no player is selected while observing.
750750
Relationship getCurrentlyViewedPlayerRelationship(const Team* team);
751-
/// Returns the currently viewed player. Returns "Observer" if no player is selected while observing.
752-
AsciiString getCurrentlyViewedPlayerSide();
753751

754752
// ControlBarResizer *getControlBarResizer( void ) {return m_controlBarResizer;}
755753

GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@ Bool Drawable::drawsAnyUIText( void )
27182718
return FALSE;
27192719

27202720
const Object *obj = getObject();
2721-
if ( !obj || obj->getControllingPlayer() != TheControlBar->getCurrentlyViewedPlayer())
2721+
if ( !obj || obj->getControllingPlayer() != rts::getObservedOrLocalPlayer())
27222722
return FALSE;
27232723

27242724
Player *owner = obj->getControllingPlayer();
@@ -2871,7 +2871,7 @@ void Drawable::drawAmmo( const IRegion2D *healthBarRegion )
28712871
if (!(
28722872
TheGlobalData->m_showObjectHealth &&
28732873
(isSelected() || (TheInGameUI && (TheInGameUI->getMousedOverDrawableID() == getID()))) &&
2874-
obj->getControllingPlayer() == TheControlBar->getCurrentlyViewedPlayer()
2874+
obj->getControllingPlayer() == rts::getObservedOrLocalPlayer()
28752875
))
28762876
return;
28772877

@@ -2929,7 +2929,7 @@ void Drawable::drawContained( const IRegion2D *healthBarRegion )
29292929
if (!(
29302930
TheGlobalData->m_showObjectHealth &&
29312931
(isSelected() || (TheInGameUI && (TheInGameUI->getMousedOverDrawableID() == getID()))) &&
2932-
obj->getControllingPlayer() == TheControlBar->getCurrentlyViewedPlayer()
2932+
obj->getControllingPlayer() == rts::getObservedOrLocalPlayer()
29332933
))
29342934
return;
29352935

@@ -3447,7 +3447,7 @@ void Drawable::drawBombed(const IRegion2D* healthBarRegion)
34473447
UnsignedInt now = TheGameLogic->getFrame();
34483448

34493449
if( obj->testWeaponSetFlag( WEAPONSET_CARBOMB ) &&
3450-
obj->getControllingPlayer() == TheControlBar->getCurrentlyViewedPlayer())
3450+
obj->getControllingPlayer() == rts::getObservedOrLocalPlayer())
34513451
{
34523452
if( !getIconInfo()->m_icon[ ICON_CARBOMB ] )
34533453
getIconInfo()->m_icon[ ICON_CARBOMB ] = newInstance(Anim2D)( s_animationTemplates[ ICON_CARBOMB ], TheAnim2DCollection );

GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "GameClient/ControlBar.h"
2929
#include "GameClient/Eva.h"
3030

31+
#include "Common/GameUtility.h"
3132
#include "Common/Player.h"
3233
#include "Common/PlayerList.h"
3334
#include "GameLogic/GameLogic.h"
@@ -284,7 +285,7 @@ void Eva::update()
284285
return;
285286
}
286287

287-
m_localPlayer = TheControlBar->getCurrentlyViewedPlayer();
288+
m_localPlayer = rts::getObservedOrLocalPlayer();
288289
UnsignedInt frame = TheGameLogic->getFrame();
289290

290291
// Don't update for the first few frames. This way, we don't have to deal with our initial power
@@ -503,7 +504,7 @@ void Eva::processPlayingMessages(UnsignedInt currentFrame)
503504
}
504505

505506
// We've got a winner!
506-
AsciiString side = TheControlBar->getCurrentlyViewedPlayerSide();
507+
AsciiString side = rts::getObservedOrLocalPlayer()->getSide();
507508
Int numSides = storedIt->m_evaInfo->m_evaSideSounds.size();
508509

509510
// clear it. If we can't find the side we want, don't play anything

0 commit comments

Comments
 (0)