- Applied latest TEAMINFO patch.

SVN r1400 (trunk)
This commit is contained in:
Randy Heit 2009-02-04 23:14:28 +00:00
parent 403b2c3c56
commit b387752f2f
10 changed files with 343 additions and 163 deletions

View file

@ -55,7 +55,7 @@ void FCajunMaster::ClearPlayer (int i, bool keepTeam)
if (bot) if (bot)
{ {
bot->inuse = false; 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(); players[i].~player_t();
::new(&players[i]) player_t; ::new(&players[i]) player_t;

View file

@ -332,7 +332,7 @@ bool FCajunMaster::SpawnBot (const char *name, int color)
{ {
strcat (concat, colors[bot_next_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 { // Keep the bot on the same team when switching levels
mysnprintf (concat + strlen(concat), countof(concat) - strlen(concat), mysnprintf (concat + strlen(concat), countof(concat) - strlen(concat),
"\\team\\%d\n", thebot->lastteam); "\\team\\%d\n", thebot->lastteam);
@ -374,7 +374,7 @@ void FCajunMaster::DoAddBot (int bnum, char *info)
botingame[bnum] = true; botingame[bnum] = true;
if (teamplay) 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 else
Printf ("%s joined the game\n", players[bnum].userinfo.netname); Printf ("%s joined the game\n", players[bnum].userinfo.netname);
@ -592,17 +592,17 @@ bool FCajunMaster::LoadBots ()
if (IsNum (sc.String)) if (IsNum (sc.String))
{ {
teamnum = atoi (sc.String); teamnum = atoi (sc.String);
if (!TEAMINFO_IsValidTeam (teamnum)) if (!TeamLibrary.IsValidTeam (teamnum))
{ {
teamnum = TEAM_None; teamnum = TEAM_NONE;
} }
} }
else else
{ {
teamnum = TEAM_None; teamnum = TEAM_NONE;
for (int i = 0; i < int(teams.Size()); ++i) 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; teamnum = i;
break; break;
@ -638,7 +638,7 @@ bool FCajunMaster::LoadBots ()
appendinfo (newinfo->info, "255"); appendinfo (newinfo->info, "255");
} }
newinfo->next = bglobal.botinfo; newinfo->next = bglobal.botinfo;
newinfo->lastteam = TEAM_None; newinfo->lastteam = TEAM_NONE;
bglobal.botinfo = newinfo; bglobal.botinfo = newinfo;
bglobal.loaded_bots++; bglobal.loaded_bots++;
} }

View file

@ -2521,9 +2521,9 @@ void D_DoomMain (void)
// Now that all textues have been loaded the crosshair can be initialized. // Now that all textues have been loaded the crosshair can be initialized.
crosshair.Callback (); crosshair.Callback ();
// [CW] Parse any TEAMINFO lumps // [CW] Parse any TEAMINFO lumps.
Printf ("TEAMINFO_Init: Load team definitions.\n"); Printf ("ParseTeamInfo: Load team definitions.\n");
TEAMINFO_Init (); TeamLibrary.ParseTeamInfo ();
FActorInfo::StaticInit (); FActorInfo::StaticInit ();

View file

@ -1963,7 +1963,7 @@ void Net_DoCommand (int type, BYTE **stream, int player)
BYTE who = ReadByte (stream); BYTE who = ReadByte (stream);
s = ReadString (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 { // Said to everyone
if (who & 2) if (who & 2)
{ {

View file

@ -65,7 +65,7 @@ CVAR (Float, autoaim, 5000.f, CVAR_USERINFO | CVAR_ARCHIVE);
CVAR (String, name, "Player", CVAR_USERINFO | CVAR_ARCHIVE); CVAR (String, name, "Player", CVAR_USERINFO | CVAR_ARCHIVE);
CVAR (Color, color, 0x40cf00, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Color, color, 0x40cf00, CVAR_USERINFO | CVAR_ARCHIVE);
CVAR (String, skin, "base", 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 (String, gender, "male", CVAR_USERINFO | CVAR_ARCHIVE);
CVAR (Bool, neverswitchonpickup, false, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Bool, neverswitchonpickup, false, CVAR_USERINFO | CVAR_ARCHIVE);
CVAR (Float, movebob, 0.25f, 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, RGBtoHSV (RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f,
h, s, v); 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 // In team play, force the player to use the team's hue
// and adjust the saturation and value so that the team // and adjust the saturation and value so that the team
// hue is visible in the final color. // hue is visible in the final color.
float ts, tv; 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, RGBtoHSV (RPART(tcolor)/255.f, GPART(tcolor)/255.f, BPART(tcolor)/255.f,
h, &ts, &tv); h, &ts, &tv);
@ -225,10 +225,10 @@ void D_PickRandomTeam (int player)
int D_PickRandomTeam () 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].m_iPresent = 0;
teams[i].ties = 0; Teams[i].m_iTies = 0;
} }
int numTeams = 0; int numTeams = 0;
@ -238,9 +238,9 @@ int D_PickRandomTeam ()
{ {
if (playeringame[i]) 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++; numTeams++;
} }
@ -252,36 +252,37 @@ int D_PickRandomTeam ()
{ {
do do
{ {
team = pr_pickteam() % teams.Size (); team = pr_pickteam() % Teams.Size ();
} while (teams[team].present != 0); } while (Teams[team].m_iPresent != 0);
} }
else 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; 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) if (lowestTie == 0)
{ {
team = teams[0].ties; team = Teams[0].m_iTies;
} }
else 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; 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"); Printf ("Team changing has been disabled!\n");
return; return;
@ -300,21 +301,21 @@ static void UpdateTeam (int pnum, int team, bool update)
int oldteam; int oldteam;
if (!TEAMINFO_IsValidTeam (team)) if (!TeamLibrary.IsValidTeam (team))
{ {
team = TEAM_None; team = TEAM_NONE;
} }
oldteam = info->team; oldteam = info->team;
info->team = team; info->team = team;
if (teamplay && !TEAMINFO_IsValidTeam (info->team)) if (teamplay && !TeamLibrary.IsValidTeam (info->team))
{ // Force players onto teams in teamplay mode { // Force players onto teams in teamplay mode
info->team = D_PickRandomTeam (); info->team = D_PickRandomTeam ();
} }
if (update && oldteam != info->team) if (update && oldteam != info->team)
{ {
if (TEAMINFO_IsValidTeam (info->team)) if (TeamLibrary.IsValidTeam (info->team))
Printf ("%s joined the %s team\n", info->netname, teams[info->team].name.GetChars()); Printf ("%s joined the %s team\n", info->netname, Teams[info->team].GetName ());
else else
Printf ("%s is now a loner\n", info->netname); 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]); StatusBar->AttachToPlayer (&players[pnum]);
} }
if (!TEAMINFO_IsValidTeam (info->team)) if (!TeamLibrary.IsValidTeam (info->team))
info->team = TEAM_None; info->team = TEAM_NONE;
} }
int D_GetFragCount (player_t *player) int D_GetFragCount (player_t *player)
{ {
if (!teamplay || !TEAMINFO_IsValidTeam (player->userinfo.team)) if (!teamplay || !TeamLibrary.IsValidTeam (player->userinfo.team))
{ {
return player->fragcount; return player->fragcount;
} }
@ -360,7 +361,7 @@ void D_SetupUserInfo ()
memset (&players[i].userinfo, 0, sizeof(userinfo_t)); memset (&players[i].userinfo, 0, sizeof(userinfo_t));
strncpy (coninfo->netname, name, MAXPLAYERNAME); strncpy (coninfo->netname, name, MAXPLAYERNAME);
if (teamplay && !TEAMINFO_IsValidTeam (team)) if (teamplay && !TeamLibrary.IsValidTeam (team))
{ {
coninfo->team = D_PickRandomTeam (); coninfo->team = D_PickRandomTeam ();
} }
@ -831,7 +832,7 @@ CCMD (playerinfo)
int i = atoi (argv[1]); int i = atoi (argv[1]);
userinfo_t *ui = &players[i].userinfo; userinfo_t *ui = &players[i].userinfo;
Printf ("Name: %s\n", ui->netname); 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 ("Aimdist: %d\n", ui->aimdist);
Printf ("Color: %06x\n", ui->color); Printf ("Color: %06x\n", ui->color);
Printf ("Skin: %s (%d)\n", skins[ui->skin].name, ui->skin); Printf ("Skin: %s (%d)\n", skins[ui->skin].name, ui->skin);

View file

@ -248,22 +248,22 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER
y = MAX(BigFont->GetHeight() * 4, y); 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].m_iPlayerCount = 0;
teams[i].score = 0; Teams[i].m_iScore = 0;
} }
for (i = 0; i < MAXPLAYERS; ++i) 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++; 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 numscores = 0;
int scorex; 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++; numscores++;
} }
@ -281,14 +281,14 @@ static void HU_DoDrawScores (player_t *player, player_t *sortedplayers[MAXPLAYER
scorex = (SCREENWIDTH - scorexwidth * (numscores - 1)) / 2; 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]; 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, scorex - BigFont->StringWidth(score)*CleanXfac/2, y, score,
DTA_CleanNoMove, true, TAG_DONE); 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, screen->DrawText (SmallFont, color, col4, y, player->userinfo.netname,
DTA_CleanNoMove, true, TAG_DONE); 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, screen->DrawTexture (pic, col1 - (pic->GetWidth() + 2) * CleanXfac, y,
DTA_CleanNoMove, true, TAG_DONE); DTA_CleanNoMove, true, TAG_DONE);
} }
@ -437,8 +437,8 @@ int HU_GetRowColor(player_t *player, bool highlight)
{ {
if (teamplay && deathmatch) if (teamplay && deathmatch)
{ {
if (TEAMINFO_IsValidTeam (player->userinfo.team)) if (TeamLibrary.IsValidTeam (player->userinfo.team))
return teams[player->userinfo.team].GetTextColor(); return Teams[player->userinfo.team].GetTextColor();
else else
return CR_GREY; return CR_GREY;
} }

View file

@ -2164,8 +2164,8 @@ static void M_PlayerSetupDrawer ()
screen->DrawText (SmallFont, label, PSetupDef.x, PSetupDef.y + LINEHEIGHT+yo, "Team", screen->DrawText (SmallFont, label, PSetupDef.x, PSetupDef.y + LINEHEIGHT+yo, "Team",
DTA_Clean, true, TAG_DONE); DTA_Clean, true, TAG_DONE);
screen->DrawText (SmallFont, value, x, PSetupDef.y + LINEHEIGHT+yo, screen->DrawText (SmallFont, value, x, PSetupDef.y + LINEHEIGHT+yo,
!TEAMINFO_IsValidTeam (players[consoleplayer].userinfo.team) ? "None" : !TeamLibrary.IsValidTeam (players[consoleplayer].userinfo.team) ? "None" :
teams[players[consoleplayer].userinfo.team].name, Teams[players[consoleplayer].userinfo.team].GetName (),
DTA_Clean, true, TAG_DONE); DTA_Clean, true, TAG_DONE);
// Draw player character // Draw player character
@ -2640,11 +2640,11 @@ static void M_ChangePlayerTeam (int choice)
{ {
if (team == 0) 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 else
{ {
@ -2653,11 +2653,11 @@ static void M_ChangePlayerTeam (int choice)
} }
else 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; team = 0;
} }

View file

@ -4910,7 +4910,7 @@ bool AActor::IsTeammate (AActor *other)
return false; return false;
if (!deathmatch) if (!deathmatch)
return true; 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) player->userinfo.team == other->player->userinfo.team)
{ {
return true; return true;

View file

@ -1,9 +1,9 @@
/* /*
** teaminfo.cpp ** 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. ** All rights reserved.
** **
** Redistribution and use in source and binary forms, with or without ** Redistribution and use in source and binary forms, with or without
@ -34,12 +34,12 @@
// HEADER FILES ------------------------------------------------------------ // HEADER FILES ------------------------------------------------------------
#include "c_dispatch.h"
#include "gi.h"
#include "i_system.h" #include "i_system.h"
#include "sc_man.h"
#include "teaminfo.h" #include "teaminfo.h"
#include "v_video.h"
#include "v_palette.h"
#include "v_font.h" #include "v_font.h"
#include "v_video.h"
#include "w_wad.h" #include "w_wad.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
@ -50,136 +50,300 @@
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void TEAMINFO_Init ();
void TEAMINFO_ParseTeam (FScanner &sc);
bool TEAMINFO_IsValidTeam (int team);
// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ---------------------------------------------- // EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS ------------------------------------------------- // PUBLIC DATA DEFINITIONS -------------------------------------------------
TArray <TEAMINFO> teams; FTeam TeamLibrary;
TArray<FTeam> Teams;
// PRIVATE DATA DEFINITIONS ------------------------------------------------ // PRIVATE DATA DEFINITIONS ------------------------------------------------
static const char *keywords_teaminfo [] = { static const char *TeamInfoOptions[] =
"PLAYERCOLOR", {
"TEXTCOLOR", "Game",
"LOGO", "PlayerColor",
NULL "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 -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
//========================================================================== //==========================================================================
// //
// TEAMINFO_Init // FTeam :: FTeam
// //
//========================================================================== //==========================================================================
void TEAMINFO_Init () FTeam::FTeam ()
{ {
int lastlump = 0, lump; m_GameFilter = 0;
m_iPlayerColor = 0;
m_iPlayerCount = 0;
m_iScore = 0;
m_iPresent = 0;
m_iTies = 0;
m_bAllowCustomPlayerColor = false;
}
while ((lump = Wads.FindLump ("TEAMINFO", &lastlump)) != -1) //==========================================================================
//
// FTeam :: ParseTeamInfo
//
//==========================================================================
void FTeam::ParseTeamInfo ()
{ {
FScanner sc(lump); int iLump, iLastLump = 0;
while (sc.GetString ())
while ((iLump = Wads.FindLump ("TEAMINFO", &iLastLump)) != -1)
{ {
if (sc.Compare("CLEARTEAMS")) FScanner Scan (iLump);
teams.Clear ();
else if (sc.Compare("TEAM")) while (Scan.GetString ())
TEAMINFO_ParseTeam (sc); {
if (Scan.Compare ("ClearTeams"))
ClearTeams ();
else if (Scan.Compare ("Team"))
ParseTeamDefinition (Scan);
else else
sc.ScriptError ("Unknown command %s in TEAMINFO", sc.String); Scan.ScriptError ("ParseTeamInfo: Unknown team command '%s'.\n", Scan.String);
} }
} }
if (teams.Size () < 2) if (Teams.Size () < 2)
I_FatalError ("At least two teams must be defined in TEAMINFO"); 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);
} }
//========================================================================== //==========================================================================
// //
// TEAMINFO_ParseTeam // FTeam :: ParseTeamDefinition
// //
//========================================================================== //==========================================================================
void TEAMINFO_ParseTeam (FScanner &sc) void FTeam::ParseTeamDefinition (FScanner &Scan)
{ {
TEAMINFO team; FTeam Team;
int i; Scan.MustGetString ();
Team.m_Name = Scan.String;
Scan.MustGetStringName ("{");
sc.MustGetString (); while (!Scan.CheckString ("}"))
team.name = sc.String; {
Scan.MustGetString ();
sc.MustGetStringName("{"); switch (Scan.MatchString (TeamInfoOptions))
while (!sc.CheckString("}"))
{ {
sc.MustGetString(); case TEAMINFO_Game:
switch(i = sc.MatchString (keywords_teaminfo)) Scan.MustGetString ();
{
case 0: if (!stricmp (Scan.String, "Doom"))
sc.MustGetString (); Team.m_GameFilter |= GAME_Doom;
team.playercolor = V_GetColor (NULL, sc.String); 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; break;
case 1: case TEAMINFO_PlayerColor:
sc.MustGetString(); Scan.MustGetString ();
team.textcolor = '['; Team.m_iPlayerColor = V_GetColor (NULL, Scan.String);
team.textcolor << sc.String << ']';
break; break;
case 2: case TEAMINFO_TextColor:
sc.MustGetString (); Scan.MustGetString ();
team.logo = sc.String; 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; break;
default: default:
Scan.ScriptError ("ParseTeamDefinition: Unknown team option '%s'.\n", Scan.String);
break; 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 false;
}
return true; 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; return CR_UNTRANSLATED;
} }
const BYTE *cp = (const BYTE *)textcolor.GetChars();
int color = V_ParseFontColor(cp, 0, 0); return iColor;
if (color == CR_UNDEFINED) }
//==========================================================================
//
// FTeam :: GetLogo
//
//==========================================================================
FString FTeam::GetLogo () const
{ {
Printf("Undefined color '%s' in definition of team %s\n", textcolor.GetChars (), name.GetChars ()); return m_Logo;
color = CR_UNTRANSLATED;
} }
return color;
//==========================================================================
//
// 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");
} }

View file

@ -1,9 +1,9 @@
/* /*
** teaminfo.h ** 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. ** All rights reserved.
** **
** Redistribution and use in source and binary forms, with or without ** Redistribution and use in source and binary forms, with or without
@ -35,28 +35,43 @@
#ifndef __TEAMINFO_H__ #ifndef __TEAMINFO_H__
#define __TEAMINFO_H__ #define __TEAMINFO_H__
#define TEAM_None 255
#include "doomtype.h" #include "doomtype.h"
#include "sc_man.h"
struct TEAMINFO const int TEAM_NONE = 255;
const int TEAM_MAXIMUM = 16;
class FTeam
{ {
FString name; public:
int playercolor; FTeam ();
FString textcolor; void ParseTeamInfo ();
bool IsValidTeam (unsigned int uiTeam);
const char *GetName () const;
int GetPlayerColor () const;
int GetTextColor () const; int GetTextColor () const;
FString logo; FString GetLogo () const;
int players; bool GetAllowCustomPlayerColor () const;
int score;
int present; int m_iPlayerCount;
int ties; 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 <TEAMINFO> teams; extern FTeam TeamLibrary;
extern TArray<FTeam> Teams;
extern void TEAMINFO_Init ();
extern void TEAMINFO_ParseTeam ();
extern bool TEAMINFO_IsValidTeam (int team);
#endif #endif