// Copyright (C) 1999-2000 Id Software, Inc.
//
#ifndef _G_TEAM_H_
#define _G_TEAM_H_


#ifdef MISSIONPACK

#define CTF_CAPTURE_BONUS		100		// what you get for capture
#define CTF_TEAM_BONUS			25		// what your team gets for capture
#define CTF_RECOVERY_BONUS		10		// what you get for recovery
#define CTF_FLAG_BONUS			10		// what you get for picking up enemy flag
#define CTF_FRAG_CARRIER_BONUS	20		// what you get for fragging enemy flag carrier
#define CTF_FLAG_RETURN_TIME	40000	// seconds until auto return

#define CTF_CARRIER_DANGER_PROTECT_BONUS	5	// bonus for fraggin someone who has recently hurt your flag carrier
#define CTF_CARRIER_PROTECT_BONUS			2	// bonus for fraggin someone while either you or your target are near your flag carrier
#define CTF_FLAG_DEFENSE_BONUS				10	// bonus for fraggin someone while either you or your target are near your flag
#define CTF_RETURN_FLAG_ASSIST_BONUS		10	// awarded for returning a flag that causes a capture to happen almost immediately
#define CTF_FRAG_CARRIER_ASSIST_BONUS		10	// award for fragging a flag carrier if a capture happens almost immediately

#else

#define CTF_CAPTURE_BONUS		5		// what you get for capture
#define CTF_TEAM_BONUS			1		// what your team gets for capture
#define CTF_RECOVERY_BONUS		2		// what you get for recovery
#define CTF_FLAG_BONUS			1		// what you get for picking up enemy flag
#define CTF_FRAG_CARRIER_BONUS	3		// what you get for fragging enemy flag carrier
#define CTF_FLAG_RETURN_TIME	40000	// seconds until auto return

#define CTF_CARRIER_DANGER_PROTECT_BONUS	2	// bonus for fraggin someone who has recently hurt your flag carrier
#define CTF_CARRIER_PROTECT_BONUS			1	// bonus for fraggin someone while either you or your target are near your flag carrier
#define CTF_FLAG_DEFENSE_BONUS				1	// bonus for fraggin someone while either you or your target are near your flag
#define CTF_RETURN_FLAG_ASSIST_BONUS		1	// awarded for returning a flag that causes a capture to happen almost immediately
#define CTF_FRAG_CARRIER_ASSIST_BONUS		2	// award for fragging a flag carrier if a capture happens almost immediately

#endif

#define BONUS_STRING         S_COLOR_CYAN "BONUS" S_COLOR_WHITE
#define PENALTY_STRING       S_COLOR_YELLOW "PENALTY" S_COLOR_WHITE

//BB SCORING
// Normal frag scaled up to match CTF points
#define CTF_FRAG_POINTS                           1
// Basic CTF events
//#define CTF_CAPTURE_BONUS		                  9
#define CTF_FLAG_RETURN_BONUS		              1
#define RTF_FLAG_RETURN_BONUS		              2
// Bonuses
#define CTF_BASE_DEFENSE_BONUS                    1
#define CTF_BATTLE_FLAG_DEFENSE_BONUS             2
#define CTF_CARRIER_KILL_BONUS_RATE	            0.2 // per second
#define CTF_CARRIER_KILL_BONUS_MAX		         10
#define CTF_CARRIER_KILL_BONUS_PER_DISTANCE       2
#define CTF_FLAG_HOLDING_BONUS                    1
#define CTF_BATTLE_CARRIER_PROTECT_BONUS          1
#define CTF_TARGET_PROTECT_RADIUS			   1000
#define CTF_ATTACKER_PROTECT_RADIUS			   1000
#define CTF_BATTLE_CARRIER_DANGER_PROTECT_BONUS   3
#define CTF_CARRIER_DANGER_PROTECT_TIMEOUT	   8000
#define CTF_DEFENDER_KILL_BONUS                   1
#define CTF_RETURN_FLAG_ASSIST_TIMEOUT		  10000
//BB END SCORING

#define CTF_TARGET_PROTECT_RADIUS			1000	// the radius around an object being defended where a target will be worth extra frags
#define CTF_ATTACKER_PROTECT_RADIUS			1000	// the radius around an object being defended where an attacker will get extra frags when making kills

#define CTF_CARRIER_DANGER_PROTECT_TIMEOUT	8000
#define CTF_FRAG_CARRIER_ASSIST_TIMEOUT		10000
#define CTF_RETURN_FLAG_ASSIST_TIMEOUT		10000

#define CTF_GRAPPLE_SPEED					750 // speed of grapple in flight
#define CTF_GRAPPLE_PULL_SPEED				750	// speed player is pulled at

#define OVERLOAD_ATTACK_BASE_SOUND_TIME		20000


// BB: new spawning rules
// The point of killing someone in CTF is to take them out of the action for
// some amount of time.  This means when we respawn a player we want to place
// them somewhere that avoids CTF hot spots: flags, carriers and bases.

//INCIN moved it back -- duplicastes removed and less overhead calls
//Combined battlespawning with team games and move the memset teamgame stuff
// to Initgame area.. it will be initialized regardless of team game or not, 
// but it will help collect spawns easier this way


#define MAX_SPAWNS           48
#define	MAX_SPAWN_POINTS	128

//BB moved from g_team.c

typedef struct teamgame_s {
    float			last_flag_capture;
    int				last_capture_team;
    flagStatus_t	redStatus;				// CTF
    flagStatus_t	blueStatus;				// CTF
#ifdef MISSIONPACK
    flagStatus_t	flagStatus;				// One Flag CTF
    int				redObeliskAttackedTime;
    int				blueObeliskAttackedTime;
	gentity_t		*neutralObelisk;
#endif
    int				redTakenTime;
    int				blueTakenTime;
    float			lastCarrierDeath[TEAM_BLUE + 1];
    gentity_t		*baseFlag[TEAM_BLUE + 2];
    gentity_t		*touchableFlag[TEAM_BLUE + 1];
    gentity_t		*carrier[TEAM_BLUE + 1];
	
	int				numSpawns;					//Battle Spawning Rules
	gentity_t		*teamSpawns[MAX_SPAWNS];	//Battle Spawning Rules
//	gentity_t		*spawnLocs[MAX_SPAWNS];		//Battle Spawning Rules
	team_t			spawnTeams[MAX_SPAWNS];		//Battle Spawning Rules
	
}
teamgame_t;


extern teamgame_t teamgame;
//BB

// Prototypes

int OtherTeam(int team);
const char *TeamName(int team);
const char *OtherTeamName(int team);
const char *TeamColorString(int team);
void AddTeamScore(vec3_t origin, int team, int score);

void Team_DroppedFlagThink(gentity_t *ent);
void Team_FragBonuses(gentity_t *targ, gentity_t *inflictor, gentity_t *attacker);
void Team_CheckHurtCarrier(gentity_t *targ, gentity_t *attacker);
void Team_InitGame(void);
void Team_ReturnFlag(gentity_t *flag, int team);
void Team_FreeEntity(gentity_t *ent);
//diordna
void Team_DropFlags(gentity_t  *ent);

gentity_t *SelectCTFSpawnPoint ( team_t team, int teamstate, vec3_t origin, vec3_t angles );

gentity_t *BattleSpawnPoint(int teamstate, team_t team);

gentity_t *Team_GetLocation(gentity_t *ent);
qboolean Team_GetLocationMsg(gentity_t *ent, char *loc, int loclen);
void TeamplayInfoMessage( gentity_t *ent );
void CheckTeamStatus(void);

int Pickup_Team( gentity_t *ent, gentity_t *other );

void Team_SetFlagStatus( int team, flagStatus_t status );
void BattleSpawnInit(gentity_t *spot);

#endif //_G_TEAM_H_

