diff --git a/src/b_bot.cpp b/src/b_bot.cpp index be43f2b18..b03c067f7 100644 --- a/src/b_bot.cpp +++ b/src/b_bot.cpp @@ -55,7 +55,7 @@ void FCajunMaster::ClearPlayer (int i, bool keepTeam) if (bot) { bot->inuse = false; - bot->lastteam = keepTeam ? players[i].userinfo.team : TEAM_None; + bot->lastteam = keepTeam ? players[i].userinfo.team : TEAM_NONE; } players[i].~player_t(); ::new(&players[i]) player_t; diff --git a/src/b_game.cpp b/src/b_game.cpp index 9a6b618fd..f517f27ee 100644 --- a/src/b_game.cpp +++ b/src/b_game.cpp @@ -332,7 +332,7 @@ bool FCajunMaster::SpawnBot (const char *name, int color) { strcat (concat, colors[bot_next_color]); } - if (TEAMINFO_IsValidTeam (thebot->lastteam)) + if (TeamLibrary.IsValidTeam (thebot->lastteam)) { // Keep the bot on the same team when switching levels mysnprintf (concat + strlen(concat), countof(concat) - strlen(concat), "\\team\\%d\n", thebot->lastteam); @@ -374,7 +374,7 @@ void FCajunMaster::DoAddBot (int bnum, char *info) botingame[bnum] = true; if (teamplay) - Printf ("%s joined the %s team\n", players[bnum].userinfo.netname, teams[players[bnum].userinfo.team].name.GetChars ()); + Printf ("%s joined the %s team\n", players[bnum].userinfo.netname,Teams[players[bnum].userinfo.team].GetName ()); else Printf ("%s joined the game\n", players[bnum].userinfo.netname); @@ -592,17 +592,17 @@ bool FCajunMaster::LoadBots () if (IsNum (sc.String)) { teamnum = atoi (sc.String); - if (!TEAMINFO_IsValidTeam (teamnum)) + if (!TeamLibrary.IsValidTeam (teamnum)) { - teamnum = TEAM_None; + teamnum = TEAM_NONE; } } else { - teamnum = TEAM_None; - for (int i = 0; i < int(teams.Size()); ++i) + teamnum = TEAM_NONE; + for (unsigned int i = 0; i < Teams.Size(); ++i) { - if (stricmp (teams[i].name, sc.String) == 0) + if (stricmp (Teams[i].GetName (), sc.String) == 0) { teamnum = i; break; @@ -638,7 +638,7 @@ bool FCajunMaster::LoadBots () appendinfo (newinfo->info, "255"); } newinfo->next = bglobal.botinfo; - newinfo->lastteam = TEAM_None; + newinfo->lastteam = TEAM_NONE; bglobal.botinfo = newinfo; bglobal.loaded_bots++; } diff --git a/src/d_main.cpp b/src/d_main.cpp index 7599cdde4..8512252e9 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2521,9 +2521,9 @@ void D_DoomMain (void) // Now that all textues have been loaded the crosshair can be initialized. crosshair.Callback (); - // [CW] Parse any TEAMINFO lumps - Printf ("TEAMINFO_Init: Load team definitions.\n"); - TEAMINFO_Init (); + // [CW] Parse any TEAMINFO lumps. + Printf ("ParseTeamInfo: Load team definitions.\n"); + TeamLibrary.ParseTeamInfo (); FActorInfo::StaticInit (); diff --git a/src/d_net.cpp b/src/d_net.cpp index 9c4363082..ed98a1a69 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -1963,7 +1963,7 @@ void Net_DoCommand (int type, BYTE **stream, int player) BYTE who = ReadByte (stream); s = ReadString (stream); - if (((who & 1) == 0) || players[player].userinfo.team == TEAM_None) + if (((who & 1) == 0) || players[player].userinfo.team == TEAM_NONE) { // Said to everyone if (who & 2) { diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index cb097d593..5ed0a9ac5 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -65,7 +65,7 @@ CVAR (Float, autoaim, 5000.f, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (String, name, "Player", CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Color, color, 0x40cf00, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (String, skin, "base", CVAR_USERINFO | CVAR_ARCHIVE); -CVAR (Int, team, TEAM_None, CVAR_USERINFO | CVAR_ARCHIVE); +CVAR (Int, team, TEAM_NONE, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (String, gender, "male", CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Bool, neverswitchonpickup, false, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Float, movebob, 0.25f, CVAR_USERINFO | CVAR_ARCHIVE); @@ -191,13 +191,13 @@ void D_GetPlayerColor (int player, float *h, float *s, float *v) RGBtoHSV (RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f, h, s, v); - if (teamplay && TEAMINFO_IsValidTeam(info->team)) + if (teamplay && TeamLibrary.IsValidTeam(info->team) && !Teams[info->team].GetAllowCustomPlayerColor ()) { // In team play, force the player to use the team's hue // and adjust the saturation and value so that the team // hue is visible in the final color. float ts, tv; - int tcolor = teams[info->team].playercolor; + int tcolor = Teams[info->team].GetPlayerColor (); RGBtoHSV (RPART(tcolor)/255.f, GPART(tcolor)/255.f, BPART(tcolor)/255.f, h, &ts, &tv); @@ -225,10 +225,10 @@ void D_PickRandomTeam (int player) int D_PickRandomTeam () { - for (int i = 0; i < (signed)teams.Size (); i++) + for (unsigned int i = 0; i < Teams.Size (); i++) { - teams[i].present = 0; - teams[i].ties = 0; + Teams[i].m_iPresent = 0; + Teams[i].m_iTies = 0; } int numTeams = 0; @@ -238,9 +238,9 @@ int D_PickRandomTeam () { if (playeringame[i]) { - if (TEAMINFO_IsValidTeam (players[i].userinfo.team)) + if (TeamLibrary.IsValidTeam (players[i].userinfo.team)) { - if (teams[players[i].userinfo.team].present++ == 0) + if (Teams[players[i].userinfo.team].m_iPresent++ == 0) { numTeams++; } @@ -252,36 +252,37 @@ int D_PickRandomTeam () { do { - team = pr_pickteam() % teams.Size (); - } while (teams[team].present != 0); + team = pr_pickteam() % Teams.Size (); + } while (Teams[team].m_iPresent != 0); } else { - int lowest = INT_MAX, lowestTie = 0, i; + int lowest = INT_MAX, lowestTie = 0; + unsigned int i; - for (i = 0; i < (signed)teams.Size (); ++i) + for (i = 0; i < Teams.Size (); ++i) { - if (teams[i].present > 0) + if (Teams[i].m_iPresent > 0) { - if (teams[i].present < lowest) + if (Teams[i].m_iPresent < lowest) { - lowest = teams[i].present; + lowest = Teams[i].m_iPresent; lowestTie = 0; - teams[0].ties = i; + Teams[0].m_iTies = i; } - else if (teams[i].present == lowest) + else if (Teams[i].m_iPresent == lowest) { - teams[++lowestTie].ties = i; + Teams[++lowestTie].m_iTies = i; } } } if (lowestTie == 0) { - team = teams[0].ties; + team = Teams[0].m_iTies; } else { - team = teams[pr_pickteam() % (lowestTie+1)].ties; + team = Teams[pr_pickteam() % (lowestTie+1)].m_iTies; } } @@ -292,7 +293,7 @@ static void UpdateTeam (int pnum, int team, bool update) { userinfo_t *info = &players[pnum].userinfo; - if ((dmflags2 & DF2_NO_TEAM_SWITCH) && (alwaysapplydmflags || deathmatch) && TEAMINFO_IsValidTeam (info->team)) + if ((dmflags2 & DF2_NO_TEAM_SWITCH) && (alwaysapplydmflags || deathmatch) && TeamLibrary.IsValidTeam (info->team)) { Printf ("Team changing has been disabled!\n"); return; @@ -300,21 +301,21 @@ static void UpdateTeam (int pnum, int team, bool update) int oldteam; - if (!TEAMINFO_IsValidTeam (team)) + if (!TeamLibrary.IsValidTeam (team)) { - team = TEAM_None; + team = TEAM_NONE; } oldteam = info->team; info->team = team; - if (teamplay && !TEAMINFO_IsValidTeam (info->team)) + if (teamplay && !TeamLibrary.IsValidTeam (info->team)) { // Force players onto teams in teamplay mode info->team = D_PickRandomTeam (); } if (update && oldteam != info->team) { - if (TEAMINFO_IsValidTeam (info->team)) - Printf ("%s joined the %s team\n", info->netname, teams[info->team].name.GetChars()); + if (TeamLibrary.IsValidTeam (info->team)) + Printf ("%s joined the %s team\n", info->netname, Teams[info->team].GetName ()); else Printf ("%s is now a loner\n", info->netname); } @@ -324,13 +325,13 @@ static void UpdateTeam (int pnum, int team, bool update) { StatusBar->AttachToPlayer (&players[pnum]); } - if (!TEAMINFO_IsValidTeam (info->team)) - info->team = TEAM_None; + if (!TeamLibrary.IsValidTeam (info->team)) + info->team = TEAM_NONE; } int D_GetFragCount (player_t *player) { - if (!teamplay || !TEAMINFO_IsValidTeam (player->userinfo.team)) + if (!teamplay || !TeamLibrary.IsValidTeam (player->userinfo.team)) { return player->fragcount; } @@ -360,7 +361,7 @@ void D_SetupUserInfo () memset (&players[i].userinfo, 0, sizeof(userinfo_t)); strncpy (coninfo->netname, name, MAXPLAYERNAME); - if (teamplay && !TEAMINFO_IsValidTeam (team)) + if (teamplay && !TeamLibrary.IsValidTeam (team)) { coninfo->team = D_PickRandomTeam (); } @@ -831,7 +832,7 @@ CCMD (playerinfo) int i = atoi (argv[1]); userinfo_t *ui = &players[i].userinfo; Printf ("Name: %s\n", ui->netname); - Printf ("Team: %s (%d)\n", ui->team == TEAM_None ? "None" : teams[ui->team].name.GetChars(), ui->team); + Printf ("Team: %s (%d)\n", ui->team == TEAM_NONE ? "None" : Teams[ui->team].GetName (), ui->team); Printf ("Aimdist: %d\n", ui->aimdist); Printf ("Color: %06x\n", ui->color); Printf ("Skin: %s (%d)\n", skins[ui->skin].name, ui->skin); diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index efaba1693..456652bc7 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -248,22 +248,22 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER y = MAX(BigFont->GetHeight() * 4, y); } - for (i = 0; i < teams.Size (); i++) + for (i = 0; i < Teams.Size (); i++) { - teams[i].players = 0; - teams[i].score = 0; + Teams[i].m_iPlayerCount = 0; + Teams[i].m_iScore = 0; } for (i = 0; i < MAXPLAYERS; ++i) { - if (playeringame[sortedplayers[i]-players] && TEAMINFO_IsValidTeam (sortedplayers[i]->userinfo.team)) + if (playeringame[sortedplayers[i]-players] && TeamLibrary.IsValidTeam (sortedplayers[i]->userinfo.team)) { - if (teams[sortedplayers[i]->userinfo.team].players++ == 0) + if (Teams[sortedplayers[i]->userinfo.team].m_iPlayerCount++ == 0) { numTeams++; } - teams[sortedplayers[i]->userinfo.team].score += sortedplayers[i]->fragcount; + Teams[sortedplayers[i]->userinfo.team].m_iScore += sortedplayers[i]->fragcount; } } @@ -271,9 +271,9 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER int numscores = 0; int scorex; - for (i = 0; i < teams.Size(); ++i) + for (i = 0; i < Teams.Size(); ++i) { - if (teams[i].players) + if (Teams[i].m_iPlayerCount) { numscores++; } @@ -281,14 +281,14 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER scorex = (SCREENWIDTH - scorexwidth * (numscores - 1)) / 2; - for (i = 0; i < teams.Size(); ++i) + for (i = 0; i < Teams.Size(); ++i) { - if (teams[i].players) + if (Teams[i].m_iPlayerCount) { char score[80]; - mysnprintf (score, countof(score), "%d", teams[i].score); + mysnprintf (score, countof(score), "%d", Teams[i].m_iScore); - screen->DrawText (BigFont, teams[i].GetTextColor(), + screen->DrawText (BigFont, Teams[i].GetTextColor(), scorex - BigFont->StringWidth(score)*CleanXfac/2, y, score, DTA_CleanNoMove, true, TAG_DONE); @@ -400,9 +400,9 @@ static void HU_DrawPlayer (player_t *player, bool highlight, int col1, int col2, screen->DrawText (SmallFont, color, col4, y, player->userinfo.netname, DTA_CleanNoMove, true, TAG_DONE); - if (teamplay && teams[player->userinfo.team].logo.IsNotEmpty()) + if (teamplay && Teams[player->userinfo.team].GetLogo ().IsNotEmpty ()) { - FTexture *pic = TexMan[teams[player->userinfo.team].logo]; + FTexture *pic = TexMan[Teams[player->userinfo.team].GetLogo ().GetChars ()]; screen->DrawTexture (pic, col1 - (pic->GetWidth() + 2) * CleanXfac, y, DTA_CleanNoMove, true, TAG_DONE); } @@ -437,8 +437,8 @@ int HU_GetRowColor(player_t *player, bool highlight) { if (teamplay && deathmatch) { - if (TEAMINFO_IsValidTeam (player->userinfo.team)) - return teams[player->userinfo.team].GetTextColor(); + if (TeamLibrary.IsValidTeam (player->userinfo.team)) + return Teams[player->userinfo.team].GetTextColor(); else return CR_GREY; } diff --git a/src/m_menu.cpp b/src/m_menu.cpp index 96b69e8a1..45f82a1a1 100644 --- a/src/m_menu.cpp +++ b/src/m_menu.cpp @@ -2164,8 +2164,8 @@ static void M_PlayerSetupDrawer () screen->DrawText (SmallFont, label, PSetupDef.x, PSetupDef.y + LINEHEIGHT+yo, "Team", DTA_Clean, true, TAG_DONE); screen->DrawText (SmallFont, value, x, PSetupDef.y + LINEHEIGHT+yo, - !TEAMINFO_IsValidTeam (players[consoleplayer].userinfo.team) ? "None" : - teams[players[consoleplayer].userinfo.team].name, + !TeamLibrary.IsValidTeam (players[consoleplayer].userinfo.team) ? "None" : + Teams[players[consoleplayer].userinfo.team].GetName (), DTA_Clean, true, TAG_DONE); // Draw player character @@ -2640,11 +2640,11 @@ static void M_ChangePlayerTeam (int choice) { if (team == 0) { - team = TEAM_None; + team = TEAM_NONE; } - else if (team == TEAM_None) + else if (team == TEAM_NONE) { - team = teams.Size () - 1; + team = Teams.Size () - 1; } else { @@ -2653,11 +2653,11 @@ static void M_ChangePlayerTeam (int choice) } else { - if (team == int(teams.Size () - 1)) + if (team == int(Teams.Size () - 1)) { - team = TEAM_None; + team = TEAM_NONE; } - else if (team == TEAM_None) + else if (team == TEAM_NONE) { team = 0; } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 0c67306f1..2df277d24 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -4910,7 +4910,7 @@ bool AActor::IsTeammate (AActor *other) return false; if (!deathmatch) return true; - if (teamplay && other->player->userinfo.team != TEAM_None && + if (teamplay && other->player->userinfo.team != TEAM_NONE && player->userinfo.team == other->player->userinfo.team) { return true; diff --git a/src/teaminfo.cpp b/src/teaminfo.cpp index 0e6e3da95..39fe58ee3 100644 --- a/src/teaminfo.cpp +++ b/src/teaminfo.cpp @@ -1,9 +1,9 @@ /* ** teaminfo.cpp -** Implementation of the TEAMINFO lump. +** Parses TEAMINFO and manages teams. ** **--------------------------------------------------------------------------- -** Copyright 2007-2008 Christopher Westley +** Copyright 2007-2009 Christopher Westley ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -34,12 +34,12 @@ // HEADER FILES ------------------------------------------------------------ +#include "c_dispatch.h" +#include "gi.h" #include "i_system.h" -#include "sc_man.h" #include "teaminfo.h" -#include "v_video.h" -#include "v_palette.h" #include "v_font.h" +#include "v_video.h" #include "w_wad.h" // MACROS ------------------------------------------------------------------ @@ -50,136 +50,300 @@ // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- -void TEAMINFO_Init (); -void TEAMINFO_ParseTeam (FScanner &sc); - -bool TEAMINFO_IsValidTeam (int team); - // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // EXTERNAL DATA DECLARATIONS ---------------------------------------------- // PUBLIC DATA DEFINITIONS ------------------------------------------------- -TArray teams; +FTeam TeamLibrary; +TArray Teams; // PRIVATE DATA DEFINITIONS ------------------------------------------------ -static const char *keywords_teaminfo [] = { - "PLAYERCOLOR", - "TEXTCOLOR", - "LOGO", - NULL +static const char *TeamInfoOptions[] = +{ + "Game", + "PlayerColor", + "TextColor", + "Logo", + "AllowCustomPlayerColor", + "RailColor", + "FlagItem", + "SkullItem", + "PlayerStartThingNumber", + "SmallFlagHUDIcon", + "SmallSkullHUDIcon", + "LargeFlagHUDIcon", + "LargeSkullHUDIcon", + "WinnerPic", + "LoserPic", + "WinnerTheme", + "LoserTheme", +}; + +enum ETeamOptions +{ + TEAMINFO_Game, + TEAMINFO_PlayerColor, + TEAMINFO_TextColor, + TEAMINFO_Logo, + TEAMINFO_AllowCustomPlayerColor, + TEAMINFO_RailColor, + TEAMINFO_FlagItem, + TEAMINFO_SkullItem, + TEAMINFO_PlayerStartThingNumber, + TEAMINFO_SmallFlagHUDIcon, + TEAMINFO_SmallSkullHUDIcon, + TEAMINFO_LargeFlagHUDIcon, + TEAMINFO_LargeSkullHUDIcon, + TEAMINFO_WinnerPic, + TEAMINFO_LoserPic, + TEAMINFO_WinnerTheme, + TEAMINFO_LoserTheme, }; // CODE -------------------------------------------------------------------- //========================================================================== // -// TEAMINFO_Init +// FTeam :: FTeam // //========================================================================== -void TEAMINFO_Init () +FTeam::FTeam () { - int lastlump = 0, lump; - - while ((lump = Wads.FindLump ("TEAMINFO", &lastlump)) != -1) - { - FScanner sc(lump); - while (sc.GetString ()) - { - if (sc.Compare("CLEARTEAMS")) - teams.Clear (); - else if (sc.Compare("TEAM")) - TEAMINFO_ParseTeam (sc); - else - sc.ScriptError ("Unknown command %s in TEAMINFO", sc.String); - } - } - - if (teams.Size () < 2) - I_FatalError ("At least two teams must be defined in TEAMINFO"); + m_GameFilter = 0; + m_iPlayerColor = 0; + m_iPlayerCount = 0; + m_iScore = 0; + m_iPresent = 0; + m_iTies = 0; + m_bAllowCustomPlayerColor = false; } //========================================================================== // -// TEAMINFO_ParseTeam +// FTeam :: ParseTeamInfo // //========================================================================== -void TEAMINFO_ParseTeam (FScanner &sc) +void FTeam::ParseTeamInfo () { - TEAMINFO team; - int i; + int iLump, iLastLump = 0; - sc.MustGetString (); - team.name = sc.String; - - sc.MustGetStringName("{"); - while (!sc.CheckString("}")) + while ((iLump = Wads.FindLump ("TEAMINFO", &iLastLump)) != -1) { - sc.MustGetString(); - switch(i = sc.MatchString (keywords_teaminfo)) + FScanner Scan (iLump); + + while (Scan.GetString ()) { - case 0: - sc.MustGetString (); - team.playercolor = V_GetColor (NULL, sc.String); + if (Scan.Compare ("ClearTeams")) + ClearTeams (); + else if (Scan.Compare ("Team")) + ParseTeamDefinition (Scan); + else + Scan.ScriptError ("ParseTeamInfo: Unknown team command '%s'.\n", Scan.String); + } + } + + if (Teams.Size () < 2) + I_FatalError ("ParseTeamInfo: At least two teams must be defined in TEAMINFO."); + else if (Teams.Size () > TEAM_MAXIMUM) + I_FatalError ("ParseTeamInfo: Too many teams defined. (Maximum: %d)", TEAM_MAXIMUM); +} + +//========================================================================== +// +// FTeam :: ParseTeamDefinition +// +//========================================================================== + +void FTeam::ParseTeamDefinition (FScanner &Scan) +{ + FTeam Team; + Scan.MustGetString (); + Team.m_Name = Scan.String; + Scan.MustGetStringName ("{"); + + while (!Scan.CheckString ("}")) + { + Scan.MustGetString (); + + switch (Scan.MatchString (TeamInfoOptions)) + { + case TEAMINFO_Game: + Scan.MustGetString (); + + if (!stricmp (Scan.String, "Doom")) + Team.m_GameFilter |= GAME_Doom; + else if (!stricmp (Scan.String, "Heretic")) + Team.m_GameFilter |= GAME_Heretic; + else if (!stricmp (Scan.String, "Hexen")) + Team.m_GameFilter |= GAME_Hexen; + else if (!stricmp (Scan.String, "Raven")) + Team.m_GameFilter |= GAME_Raven; + else if (!stricmp (Scan.String, "Strife")) + Team.m_GameFilter |= GAME_Strife; + else if (!stricmp (Scan.String, "Chex")) + Team.m_GameFilter |= GAME_Chex; + else if (!stricmp (Scan.String, "Any")) + Team.m_GameFilter |= GAME_Any; + else + Scan.ScriptError ("ParseTeamDefinition: Unknown game type '%s'.\n", Scan.String); break; - case 1: - sc.MustGetString(); - team.textcolor = '['; - team.textcolor << sc.String << ']'; + case TEAMINFO_PlayerColor: + Scan.MustGetString (); + Team.m_iPlayerColor = V_GetColor (NULL, Scan.String); break; - case 2: - sc.MustGetString (); - team.logo = sc.String; + case TEAMINFO_TextColor: + Scan.MustGetString (); + Team.m_TextColor.AppendFormat ("[%s]", Scan.String); + break; + + case TEAMINFO_Logo: + Scan.MustGetString (); + Team.m_Logo = Scan.String; + break; + + case TEAMINFO_AllowCustomPlayerColor: + Team.m_bAllowCustomPlayerColor = true; + break; + + case TEAMINFO_PlayerStartThingNumber: + Scan.MustGetNumber (); + break; + + case TEAMINFO_RailColor: + case TEAMINFO_FlagItem: + case TEAMINFO_SkullItem: + case TEAMINFO_SmallFlagHUDIcon: + case TEAMINFO_SmallSkullHUDIcon: + case TEAMINFO_LargeFlagHUDIcon: + case TEAMINFO_LargeSkullHUDIcon: + case TEAMINFO_WinnerPic: + case TEAMINFO_LoserPic: + case TEAMINFO_WinnerTheme: + case TEAMINFO_LoserTheme: + Scan.MustGetString (); break; default: + Scan.ScriptError ("ParseTeamDefinition: Unknown team option '%s'.\n", Scan.String); break; } } - teams.Push (team); + if (Team.m_GameFilter == 0 || Team.m_GameFilter & gameinfo.gametype) + Teams.Push (Team); } //========================================================================== // -// TEAMINFO_IsValidTeam +// FTeam :: ClearTeams // //========================================================================== -bool TEAMINFO_IsValidTeam (int team) +void FTeam::ClearTeams () { - if (team < 0 || team >= (signed)teams.Size ()) - { + Teams.Clear (); +} + +//========================================================================== +// +// FTeam :: IsValidTeam +// +//========================================================================== + +bool FTeam::IsValidTeam (unsigned int uiTeam) +{ + if (uiTeam < 0 || uiTeam >= Teams.Size ()) return false; - } return true; } //========================================================================== // -// TEAMINFO :: GetTextColor +// FTeam :: GetName // //========================================================================== -int TEAMINFO::GetTextColor () const +const char *FTeam::GetName () const { - if (textcolor.IsEmpty()) + return m_Name; +} + +//========================================================================== +// +// FTeam :: GetPlayerColor +// +//========================================================================== + +int FTeam::GetPlayerColor () const +{ + return m_iPlayerColor; +} + +//========================================================================== +// +// FTeam :: GetTextColor +// +//========================================================================== + +int FTeam::GetTextColor () const +{ + if (m_TextColor.IsEmpty ()) + return CR_UNTRANSLATED; + + const BYTE *pColor = (const BYTE *)m_TextColor.GetChars (); + int iColor = V_ParseFontColor (pColor, 0, 0); + + if (iColor == CR_UNDEFINED) { + Printf ("GetTextColor: Undefined color '%s' in definition of team '%s'.\n", m_TextColor.GetChars (), m_Name.GetChars ()); return CR_UNTRANSLATED; } - const BYTE *cp = (const BYTE *)textcolor.GetChars(); - int color = V_ParseFontColor(cp, 0, 0); - if (color == CR_UNDEFINED) - { - Printf("Undefined color '%s' in definition of team %s\n", textcolor.GetChars (), name.GetChars ()); - color = CR_UNTRANSLATED; - } - return color; + + return iColor; +} + +//========================================================================== +// +// FTeam :: GetLogo +// +//========================================================================== + +FString FTeam::GetLogo () const +{ + return m_Logo; +} + +//========================================================================== +// +// FTeam :: GetAllowCustomPlayerColor +// +//========================================================================== + +bool FTeam::GetAllowCustomPlayerColor () const +{ + return m_bAllowCustomPlayerColor; +} + +//========================================================================== +// +// CCMD teamlist +// +//========================================================================== + +CCMD (teamlist) +{ + Printf ("Defined teams are as follows:\n"); + + for (unsigned int uiTeam = 0; uiTeam < Teams.Size (); uiTeam++) + Printf ("%d : %s\n", uiTeam, Teams[uiTeam].GetName ()); + + Printf ("End of team list.\n"); } diff --git a/src/teaminfo.h b/src/teaminfo.h index cacf69fdc..f18d63d0d 100644 --- a/src/teaminfo.h +++ b/src/teaminfo.h @@ -1,9 +1,9 @@ /* ** teaminfo.h -** Implementation of the TEAMINFO lump. +** Parses TEAMINFO and manages teams. ** **--------------------------------------------------------------------------- -** Copyright 2007-2008 Christopher Westley +** Copyright 2007-2009 Christopher Westley ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -35,28 +35,43 @@ #ifndef __TEAMINFO_H__ #define __TEAMINFO_H__ -#define TEAM_None 255 - #include "doomtype.h" +#include "sc_man.h" -struct TEAMINFO +const int TEAM_NONE = 255; +const int TEAM_MAXIMUM = 16; + +class FTeam { - FString name; - int playercolor; - FString textcolor; - int GetTextColor () const; - FString logo; - int players; - int score; - int present; - int ties; +public: + FTeam (); + void ParseTeamInfo (); + bool IsValidTeam (unsigned int uiTeam); + + const char *GetName () const; + int GetPlayerColor () const; + int GetTextColor () const; + FString GetLogo () const; + bool GetAllowCustomPlayerColor () const; + + int m_iPlayerCount; + int m_iScore; + int m_iPresent; + int m_iTies; + +private: + void ParseTeamDefinition (FScanner &Scan); + void ClearTeams (); + + FString m_Name; + BYTE m_GameFilter; + int m_iPlayerColor; + FString m_TextColor; + FString m_Logo; + bool m_bAllowCustomPlayerColor; }; -extern TArray teams; - -extern void TEAMINFO_Init (); -extern void TEAMINFO_ParseTeam (); - -extern bool TEAMINFO_IsValidTeam (int team); +extern FTeam TeamLibrary; +extern TArray Teams; #endif