Skip to content

Commit ec1984d

Browse files
committed
feat(asw_player): add concommand for setting spectate order
preparation for next commit
1 parent b1c11db commit ec1984d

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

src/game/server/swarm/asw_player.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,79 @@ HSCRIPT CASW_Player::ScriptGetNPC() const
21732173
return ToHScript( GetNPC() );
21742174
}
21752175

2176+
CON_COMMAND( rd_set_spectate_order, "Space separated list of marine profile numbers. List can be partial. No args for unset." )
2177+
{
2178+
CASW_Player *pPlayer = ToASW_Player( UTIL_GetCommandClient() );
2179+
if ( !pPlayer )
2180+
{
2181+
Warning( "rd_set_spectate_order: No Player (not connected to server?)\n" );
2182+
return;
2183+
}
2184+
2185+
const int nProfiles = args.ArgC() - 1;
2186+
2187+
if ( nProfiles == 0 )
2188+
{
2189+
Msg("rd_set_spectate_order: unset\n");
2190+
pPlayer->UnsetSpectatingOrder();
2191+
return;
2192+
}
2193+
if ( nProfiles > ASW_NUM_MARINE_PROFILES )
2194+
{
2195+
Warning( "rd_set_spectate_order: Incorrect number of profiles (%d > %d)\n", nProfiles, ASW_NUM_MARINE_PROFILES );
2196+
return;
2197+
}
2198+
2199+
int iProfiles[ASW_NUM_MARINE_PROFILES];
2200+
2201+
// parse input
2202+
for ( int i = 0; i < nProfiles; i++ )
2203+
{
2204+
const int iProfile = atoi( args[i + 1] );
2205+
2206+
if ( iProfile < 0 || iProfile >= ASW_NUM_MARINE_PROFILES )
2207+
{
2208+
Warning( "rd_set_spectate_order: Incorrect profile number (#%d: %s)\n", i + 1, args[i + 1] );
2209+
return;
2210+
}
2211+
2212+
for ( int j = 0; j < i; j++ )
2213+
{
2214+
if ( iProfiles[j] == iProfile )
2215+
{
2216+
Warning( "rd_set_spectate_order: Duplicate profile number (#%d: %d)\n", i + 1, iProfile );
2217+
return;
2218+
}
2219+
}
2220+
2221+
iProfiles[i] = iProfile;
2222+
}
2223+
2224+
pPlayer->SetSpectatingOrder( iProfiles, nProfiles );
2225+
}
2226+
2227+
// Don't need all marine profiles; rest will have worst priority
2228+
void CASW_Player::SetSpectatingOrder( const int* iProfiles, int nProfiles )
2229+
{
2230+
// Prefill with worst priority in case a profile is not in the list or is invalid
2231+
for ( int i = 0; i < ASW_NUM_MARINE_PROFILES; i++ )
2232+
{
2233+
m_iSpectatingMapping[i] = INT_MAX;
2234+
}
2235+
2236+
nProfiles = MIN( nProfiles, ASW_NUM_MARINE_PROFILES );
2237+
for ( int i = 0; i < nProfiles; i++ )
2238+
{
2239+
const int iProfile = iProfiles[i];
2240+
if ( iProfiles[i] >= 0 && iProfiles[i] < ASW_NUM_MARINE_PROFILES )
2241+
{
2242+
m_iSpectatingMapping[iProfiles[i]] = i;
2243+
}
2244+
}
2245+
2246+
m_bSpectatingInOrder = true;
2247+
}
2248+
21762249
void CASW_Player::SpectateNextMarine()
21772250
{
21782251
CASW_Game_Resource* pGameResource = ASWGameResource();

src/game/server/swarm/asw_player.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ class CASW_Player : public CBaseMultiplayerPlayer, public IASWPlayerAnimStateHel
8686
virtual bool ASWAnim_CanMove();
8787

8888
// spectating
89+
private:
90+
bool m_bSpectatingInOrder = false;
91+
int m_iSpectatingMapping[ASW_NUM_MARINE_PROFILES];
92+
public:
93+
void UnsetSpectatingOrder() { m_bSpectatingInOrder = false; }
94+
void SetSpectatingOrder( const int* iProfiles, int nProfiles );
8995
void SpectateNextMarine();
9096
void SetSpectatingNPC( CASW_Inhabitable_NPC *pSpectating );
9197
CASW_Inhabitable_NPC *GetSpectatingNPC() const;

0 commit comments

Comments
 (0)