Skip to content

Commit 1b36e51

Browse files
committed
refactor: Use new utility logic for handling observed player behaviour
1 parent 6cfcc7b commit 1b36e51

File tree

10 files changed

+34
-36
lines changed

10 files changed

+34
-36
lines changed

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: 2 additions & 1 deletion
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

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5563,10 +5563,10 @@ void InGameUI::removeIdleWorker( Object *obj, Int playerNumber )
55635563

55645564
void InGameUI::selectNextIdleWorker( void )
55655565
{
5566-
Int index = TheControlBar->getCurrentlyViewedPlayer()->getPlayerIndex();
5566+
Int index = rts::getObservedOrLocalPlayer()->getPlayerIndex();
55675567
if(m_idleWorkers[index].empty())
55685568
{
5569-
DEBUG_ASSERTCRASH(FALSE, ("InGameUI::selectNextIdleWorker We're trying to select a worker when our list is empty for player %ls", ThePlayerList->getLocalPlayer()->getPlayerDisplayName().str()));
5569+
DEBUG_ASSERTCRASH(FALSE, ("InGameUI::selectNextIdleWorker We're trying to select a worker when our list is empty for player %ls", ThePlayerList->getNthPlayer(index)->getPlayerDisplayName().str())); return;
55705570
return;
55715571
}
55725572
Object *selectThisObject = NULL;
@@ -5653,13 +5653,10 @@ ObjectPtrVector InGameUI::getUniqueIdleWorkers(const ObjectList& idleWorkers)
56535653

56545654
Int InGameUI::getIdleWorkerCount( void )
56555655
{
5656-
if (Player* player = TheControlBar->getCurrentlyViewedPlayer())
5657-
{
5658-
Int index = player->getPlayerIndex();
5659-
return m_idleWorkers[index].size();
5660-
}
5656+
Player* player = rts::getObservedOrLocalPlayer();
56615657

5662-
return 0;
5658+
Int index = player->getPlayerIndex();
5659+
return m_idleWorkers[index].size();
56635660
}
56645661

56655662
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/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: 2 additions & 1 deletion
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

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5736,10 +5736,10 @@ void InGameUI::removeIdleWorker( Object *obj, Int playerNumber )
57365736

57375737
void InGameUI::selectNextIdleWorker( void )
57385738
{
5739-
Int index = TheControlBar->getCurrentlyViewedPlayer()->getPlayerIndex();
5739+
Int index = rts::getObservedOrLocalPlayer()->getPlayerIndex();
57405740
if(m_idleWorkers[index].empty())
57415741
{
5742-
DEBUG_ASSERTCRASH(FALSE, ("InGameUI::selectNextIdleWorker We're trying to select a worker when our list is empty for player %ls", ThePlayerList->getLocalPlayer()->getPlayerDisplayName().str()));
5742+
DEBUG_ASSERTCRASH(FALSE, ("InGameUI::selectNextIdleWorker We're trying to select a worker when our list is empty for player %ls", ThePlayerList->getNthPlayer(index)->getPlayerDisplayName().str()));
57435743
return;
57445744
}
57455745
Object *selectThisObject = NULL;
@@ -5826,13 +5826,10 @@ ObjectPtrVector InGameUI::getUniqueIdleWorkers(const ObjectList& idleWorkers)
58265826

58275827
Int InGameUI::getIdleWorkerCount( void )
58285828
{
5829-
if (Player* player = TheControlBar->getCurrentlyViewedPlayer())
5830-
{
5831-
Int index = player->getPlayerIndex();
5832-
return m_idleWorkers[index].size();
5833-
}
5829+
Player* player = rts::getObservedOrLocalPlayer();
58345830

5835-
return 0;
5831+
Int index = player->getPlayerIndex();
5832+
return m_idleWorkers[index].size();
58365833
}
58375834

58385835
void InGameUI::showIdleWorkerLayout( void )

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

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

945945
static void viewCommandCenter( void )
946946
{
947-
Player* localPlayer = TheControlBar->getCurrentlyViewedPlayer();
948-
if (!localPlayer)
947+
Player* localPlayer = rts::getObservedOrLocalPlayer();
948+
if (!localPlayer->isPlayerActive())
949949
return;
950950

951951
CommandCenterLocator ccl;
@@ -986,8 +986,8 @@ void amIAHero(Object* obj, void* heroHolder)
986986

987987
static Object *iNeedAHero( void )
988988
{
989-
Player* localPlayer = TheControlBar->getCurrentlyViewedPlayer();
990-
if (!localPlayer)
989+
Player* localPlayer = rts::getObservedOrLocalPlayer();
990+
if (!localPlayer->isPlayerActive())
991991
return NULL;
992992

993993
HeroHolder heroHolder;

GeneralsMD/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"
@@ -230,7 +231,7 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
230231
Int numPoints = 0;
231232
if( obj )
232233
{
233-
if ( obj->getControllingPlayer() != TheControlBar->getCurrentlyViewedPlayer())
234+
if ( obj->getControllingPlayer() != rts::getObservedOrLocalPlayer())
234235
continue;
235236

236237

0 commit comments

Comments
 (0)