Added player iterators
Allows for easily iterating through players currently in the game.
This commit is contained in:
parent
e981064e5c
commit
1e281bfce2
3 changed files with 41 additions and 0 deletions
|
|
@ -477,6 +477,9 @@ public:
|
|||
bool HasWeaponsInSlot(int slot) const;
|
||||
bool Resurrect();
|
||||
|
||||
static player_t* GetNextPlayer(player_t* p, bool noBots = false);
|
||||
static int GetNextPlayerNumber(int pNum, bool noBots = false);
|
||||
|
||||
// Scaled angle adjustment info. Not for direct manipulation.
|
||||
DRotator angleOffsetTargets;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -746,6 +746,41 @@ DEFINE_ACTION_FUNCTION(_PlayerInfo, Resurrect)
|
|||
ACTION_RETURN_BOOL(self->Resurrect());
|
||||
}
|
||||
|
||||
player_t* player_t::GetNextPlayer(player_t* p, bool noBots)
|
||||
{
|
||||
int pNum = player_t::GetNextPlayerNumber(p == nullptr ? -1 : p - players);
|
||||
return pNum != -1 ? &players[pNum] : nullptr;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_PlayerInfo, GetNextPlayer, player_t::GetNextPlayer)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_POINTER(p, player_t);
|
||||
PARAM_BOOL(noBots);
|
||||
|
||||
ACTION_RETURN_POINTER(player_t::GetNextPlayer(p, noBots));
|
||||
}
|
||||
|
||||
int player_t::GetNextPlayerNumber(int pNum, bool noBots)
|
||||
{
|
||||
int i = max<int>(pNum + 1, 0);
|
||||
for (; i < MaxClients; ++i)
|
||||
{
|
||||
if (playeringame[i] && (!noBots || players[i].Bot == nullptr))
|
||||
break;
|
||||
}
|
||||
|
||||
return i < MaxClients ? i : -1;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_PlayerInfo, GetNextPlayerNumber, player_t::GetNextPlayerNumber)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(pNum);
|
||||
PARAM_BOOL(noBots);
|
||||
|
||||
ACTION_RETURN_INT(player_t::GetNextPlayerNumber(pNum, noBots));
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_PlayerInfo, GetUserName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3004,6 +3004,9 @@ struct PlayerInfo native play // self is what internally is known as player_t
|
|||
|
||||
native clearscope int GetAverageLatency() const;
|
||||
|
||||
native clearscope static PlayerInfo GetNextPlayer(PlayerInfo p, bool noBots = false);
|
||||
native clearscope static int GetNextPlayerNumber(int pNum, bool noBots = false);
|
||||
|
||||
// The actual implementation is on PlayerPawn where it can be overridden. Use that directly in the future.
|
||||
deprecated("3.7", "MorphPlayer() should be used on a PlayerPawn object") bool MorphPlayer(PlayerInfo activator, class<PlayerPawn> spawnType, int duration, EMorphFlags style, class<Actor> enterFlash = "TeleportFog", class<Actor> exitFlash = "TeleportFog")
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue