/* 

  [BC] 7/16/2000

  t_info.cpp - Team info

  These two files (t_info.cpp and t_info.h) contain
  all the information 

*/

#include "d_items.h"
#include "info.h"
#include "t_info.h"
#include "v_text.h"
#include "doomstat.h"
#include "d_player.h"
#include "cmdlib.h"
#include "m_argv.h"

#include "c_dispatch.h"
#include "doomstat.h"
#include "p_local.h"
#include "cmdlib.h"
#include "p_lnspec.h"

int P_CountBluePlayers ()
{
	int count = 0;

	for (int i=0; i < MAXPLAYERS; i++)
	{
		if (!playeringame[i] || !players[i].team)
			continue;
		if (players[i].team == TM_BLUE)
			count++;
	}
	
	return count;
}

int P_CountRedPlayers ()
{
	int count = 0;

	for (int i=0; i<MAXPLAYERS; i++)
	{
		if (!playeringame[i] || !players[i].team)
			continue;
		if (players[i].team == TM_RED)
			count++;
	}
	
	return count;
}

BEGIN_COMMAND (switchteams)
{
	AActor *mo = players[consoleplayer].mo;

	if (dmflags2 & DF2_NO_SWITCH || !teamgame.value)
		return;

	if (players[consoleplayer].team == TM_RED)
	{
		players[consoleplayer].team = TM_BLUE;
		if (netstate == NS_CLIENT)
		{
			MSG_WriteByte (&net_buffer, clc_changeplayerteam);
			MSG_WriteByte (&net_buffer, consoleplayer);
			MSG_WriteByte (&net_buffer, (byte)TM_BLUE);
		}
		else
		{
			P_DamageMobj (mo, NULL, NULL, mo->health+mo->info->spawnhealth, MOD_UNKNOWN, DMG_NO_INVUL|DMG_NO_ARMOR);
			Printf (PRINT_HIGH, TEXTCOLOR_NORMAL "%s joined the " TEXTCOLOR_BLUE "%s" TEXTCOLOR_NORMAL " team\n", players[consoleplayer].userinfo.netname, teams[TM_BLUE].name);
		}
	}
	else if (players[consoleplayer].team == TM_BLUE)
	{
		players[consoleplayer].team = TM_RED;
		if (netstate == NS_CLIENT)
		{
			MSG_WriteByte (&net_buffer, clc_changeplayerteam);
			MSG_WriteByte (&net_buffer, consoleplayer);
			MSG_WriteByte (&net_buffer, (byte)TM_RED);
		}
		else
		{
			P_DamageMobj (mo, NULL, NULL, mo->health+mo->info->spawnhealth, MOD_UNKNOWN, DMG_NO_INVUL|DMG_NO_ARMOR);
			Printf (PRINT_HIGH, TEXTCOLOR_NORMAL "%s joined the " TEXTCOLOR_RED  "%s" TEXTCOLOR_NORMAL " team\n", players[consoleplayer].userinfo.netname, teams[TM_RED].name);
		}
	}
}
END_COMMAND (switchteams)

BEGIN_COMMAND (changeteams)
{
	AddCommandString ("switchteams");
}
END_COMMAND (changeteams)

teaminfo_s teams[NUMTEAMS] =
{
	{	// TM_DUMMY
		"GOOFBALL",
		NULL,
		"00 00 bf",
		0,
		0,
		CR_BLUE,
		MT_RSKU,
		MT_BSKU,
		SPR_RSKU,
		SPR_BSKU,
		it_blueskull,
		it_blueskull,
		S_RSKULL,
		S_RSKULL,
		0,
		0,
		P_StartTeam1ReturnScripts
	},

	{	// TM_BLUE
		"Blue",
		NULL,
		"00 00 bf",
		0,
		0,
		CR_BLUE,
		MT_RSKU,
		MT_BSKU,
		SPR_RSKU,
		SPR_BSKU,
		it_redskull,
		it_blueskull,
		S_RSKULL,
		S_BSKULL,
		0,
		0,
		P_StartTeam1ReturnScripts
	},
	{	// TM_RED
		"Red",
		NULL,
		"bf 00 00",
		0,
		0,
		CR_RED,
		MT_BSKU,
		MT_RSKU,
		SPR_BSKU,
		SPR_RSKU,
		it_blueskull,
		it_redskull,
		S_BSKULL,
		S_RSKULL,
		0,
		1,
		P_StartTeam2ReturnScripts
	}
};