diff --git a/src/d_main.cpp b/src/d_main.cpp index 2d7f20c48..b0d3d88f2 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -3359,7 +3359,7 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector& allw // [CW] Parse any TEAMINFO lumps. if (!batchrun) Printf ("ParseTeamInfo: Load team definitions.\n"); - TeamLibrary.ParseTeamInfo (); + FTeam::ParseTeamInfo (); R_ParseTrnslate(); PClassActor::StaticInit (); diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index ee004505e..bac6eddfe 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -197,7 +197,7 @@ void D_GetPlayerColor (int player, float *h, float *s, float *v, FPlayerColorSet RGBtoHSV (RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f, h, s, v); - if (teamplay && TeamLibrary.IsValidTeam((team = info->GetTeam())) && !Teams[team].GetAllowCustomPlayerColor()) + if (teamplay && FTeam::IsValid((team = info->GetTeam())) && !Teams[team].GetAllowCustomPlayerColor()) { // In team play, force the player to use the team's hue // and adjust the saturation and value so that the team @@ -264,7 +264,7 @@ int D_PickRandomTeam () if (playeringame[i]) { team = players[i].userinfo.GetTeam(); - if (TeamLibrary.IsValidTeam(team)) + if (FTeam::IsValid(team)) { if (Teams[team].m_iPresent++ == 0) { @@ -319,7 +319,7 @@ static void UpdateTeam (int pnum, int team, bool update) { userinfo_t *info = &players[pnum].userinfo; - if ((dmflags2 & DF2_NO_TEAM_SWITCH) && (alwaysapplydmflags || deathmatch) && TeamLibrary.IsValidTeam (info->GetTeam())) + if ((dmflags2 & DF2_NO_TEAM_SWITCH) && (alwaysapplydmflags || deathmatch) && FTeam::IsValid (info->GetTeam())) { Printf ("%s\n", GStrings.GetString("TXT_NO_TEAM_CHANGE")); return; @@ -327,7 +327,7 @@ static void UpdateTeam (int pnum, int team, bool update) int oldteam; - if (!TeamLibrary.IsValidTeam (team)) + if (!FTeam::IsValid (team)) { team = TEAM_NONE; } @@ -337,7 +337,7 @@ static void UpdateTeam (int pnum, int team, bool update) if (update && oldteam != team) { FString message; - if (TeamLibrary.IsValidTeam (team)) + if (FTeam::IsValid (team)) { message = GStrings.GetString("TXT_JOINED_TEAM"); message.Substitute("%t", Teams[team].GetName()); @@ -356,7 +356,7 @@ static void UpdateTeam (int pnum, int team, bool update) StatusBar->AttachToPlayer (&players[pnum]); } // Double-check - if (!TeamLibrary.IsValidTeam (team)) + if (!FTeam::IsValid (team)) { *static_cast((*info)[NAME_Team]) = TEAM_NONE; } @@ -365,7 +365,7 @@ static void UpdateTeam (int pnum, int team, bool update) int D_GetFragCount (player_t *player) { const int team = player->userinfo.GetTeam(); - if (!teamplay || !TeamLibrary.IsValidTeam(team)) + if (!teamplay || !FTeam::IsValid(team)) { return player->fragcount; } @@ -479,7 +479,7 @@ void userinfo_t::Reset(int pnum) int userinfo_t::TeamChanged(int team) { - if (teamplay && !TeamLibrary.IsValidTeam(team)) + if (teamplay && !FTeam::IsValid(team)) { // Force players onto teams in teamplay mode team = D_PickRandomTeam(); } diff --git a/src/gamedata/teaminfo.cpp b/src/gamedata/teaminfo.cpp index 1838d1b39..25ec9dd3b 100644 --- a/src/gamedata/teaminfo.cpp +++ b/src/gamedata/teaminfo.cpp @@ -43,6 +43,7 @@ #include "v_video.h" #include "filesystem.h" #include "vm.h" +#include "d_player.h" // MACROS ------------------------------------------------------------------ @@ -56,9 +57,11 @@ // EXTERNAL DATA DECLARATIONS ---------------------------------------------- +extern bool playeringame[MAXPLAYERS]; +extern player_t players[MAXPLAYERS]; + // PUBLIC DATA DEFINITIONS ------------------------------------------------- -FTeam TeamLibrary; TArray Teams; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -245,7 +248,7 @@ void FTeam::ClearTeams () // //========================================================================== -bool FTeam::IsValidTeam (unsigned int uiTeam) const +bool FTeam::IsValid (unsigned int uiTeam) { if (uiTeam >= Teams.Size ()) return false; @@ -253,6 +256,15 @@ bool FTeam::IsValidTeam (unsigned int uiTeam) const return true; } +bool FTeam::ChangeTeam(unsigned int pNum, unsigned int newTeam) +{ + if (!multiplayer || !teamplay || pNum >= MAXPLAYERS || !playeringame[pNum] || !FTeam::IsValid(newTeam) || players[pNum].userinfo.GetTeam() == newTeam) + return false; + + players[pNum].userinfo.TeamChanged(newTeam); + return true; +} + //========================================================================== // // FTeam :: GetName @@ -342,7 +354,7 @@ DEFINE_FIELD_NAMED(FTeam, m_Name, mName) static int IsValid(unsigned int id) { - return TeamLibrary.IsValidTeam(id); + return FTeam::IsValid(id); } DEFINE_ACTION_FUNCTION_NATIVE(FTeam, IsValid, IsValid) @@ -350,7 +362,21 @@ DEFINE_ACTION_FUNCTION_NATIVE(FTeam, IsValid, IsValid) PARAM_PROLOGUE; PARAM_UINT(id); - ACTION_RETURN_BOOL(TeamLibrary.IsValidTeam(id)); + ACTION_RETURN_BOOL(FTeam::IsValid(id)); +} + +static int ChangeTeam(unsigned int pNum, unsigned int newTeam) +{ + return FTeam::ChangeTeam(pNum, newTeam); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FTeam, ChangeTeam, ChangeTeam) +{ + PARAM_PROLOGUE; + PARAM_UINT(pNum); + PARAM_UINT(newTeam); + + ACTION_RETURN_BOOL(FTeam::ChangeTeam(pNum, newTeam)); } static int GetPlayerColor(FTeam* self) diff --git a/src/gamedata/teaminfo.h b/src/gamedata/teaminfo.h index 1a3db705c..17be9dd46 100644 --- a/src/gamedata/teaminfo.h +++ b/src/gamedata/teaminfo.h @@ -45,8 +45,9 @@ class FTeam { public: FTeam (); - void ParseTeamInfo (); - bool IsValidTeam (unsigned int uiTeam) const; + static void ParseTeamInfo (); + static bool IsValid (unsigned int uiTeam); + static bool ChangeTeam(unsigned int pNum, unsigned int newTeam); const char *GetName () const; int GetPlayerColor () const; @@ -60,8 +61,8 @@ public: int m_iTies; private: - void ParseTeamDefinition (FScanner &Scan); - void ClearTeams (); + static void ParseTeamDefinition (FScanner &Scan); + static void ClearTeams (); public: // needed for script access. FString m_Name; @@ -72,7 +73,6 @@ private: bool m_bAllowCustomPlayerColor; }; -extern FTeam TeamLibrary; extern TArray Teams; #endif diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index 797e222ef..d7cde85fc 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -293,7 +293,7 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER for (i = 0; i < MAXPLAYERS; ++i) { - if (playeringame[sortedplayers[i]-players] && TeamLibrary.IsValidTeam (sortedplayers[i]->userinfo.GetTeam())) + if (playeringame[sortedplayers[i]-players] && FTeam::IsValid (sortedplayers[i]->userinfo.GetTeam())) { if (Teams[sortedplayers[i]->userinfo.GetTeam()].m_iPlayerCount++ == 0) { @@ -485,7 +485,7 @@ int HU_GetRowColor(player_t *player, bool highlight) { if (teamplay && deathmatch) { - if (TeamLibrary.IsValidTeam (player->userinfo.GetTeam())) + if (FTeam::IsValid (player->userinfo.GetTeam())) return Teams[player->userinfo.GetTeam()].GetTextColor(); else return CR_GREY; diff --git a/src/playsim/bots/b_game.cpp b/src/playsim/bots/b_game.cpp index 198692c1f..3863ac923 100644 --- a/src/playsim/bots/b_game.cpp +++ b/src/playsim/bots/b_game.cpp @@ -305,7 +305,7 @@ bool FCajunMaster::SpawnBot (const char *name, int color) { concat << colors[bot_next_color]; } - if (TeamLibrary.IsValidTeam (thebot->lastteam)) + if (FTeam::IsValid (thebot->lastteam)) { // Keep the bot on the same team when switching levels concat.AppendFormat("\\team\\%d\n", thebot->lastteam); } @@ -587,7 +587,7 @@ bool FCajunMaster::LoadBots () if (IsNum (sc.String)) { teamnum = atoi (sc.String); - if (!TeamLibrary.IsValidTeam (teamnum)) + if (!FTeam::IsValid (teamnum)) { teamnum = TEAM_NONE; } diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index e9b25c9b2..05d9e1b1b 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -2989,6 +2989,7 @@ struct Team native native String mName; native static bool IsValid(uint teamIndex); + native static bool ChangeTeam(uint playerNumber, uint newTeamIndex); native Color GetPlayerColor() const; native int GetTextColor() const;