//============================================================
// TTFProfile_Generic.uc	- An object for storing multiple configuration profiles
//============================================================
//	TitanTeamFix
//		- A modular team balancing tool initially coded for the Titan servers:
//			http://ut2004.titaninternet.co.uk/
//
//	Copyright (C) 2007-2008 John "Shambler" Barrett (JBarrett847@Gmail.com or Shambler@OldUnreal.com)
//
//	This program is free software; you can redistribute and/or modify
//	it under the terms of the Open Unreal Mod License version 1.1.
//
//============================================================
//
// This profile class is only compatable with the 
// TTeamFixGeneric balancing class.
//
//============================================================
class TTFProfile_Generic extends TTeamFixConfigProfile
	PerObjectConfig		// Do I need these two class flags here? Maybe they are inherited?
	config(TitanTeamFix);


var config bool					bCheckTeamsOnExit;
var config bool					bCheckTeamsOnDeath;
var config TTeamFixGeneric.EImbalanceAction	ImbalanceAction;
var config int					BalanceCountdown;
var config bool					bAnnounceSwitch;
var config bool					bAnnounceImbalance;
var config bool					bAnnounceSlotOpened;
var config TTeamFixGeneric.EPreferredTeams	PreferredTeams;
var config TTeamFixGeneric.EShuffleTeams	ShuffleTeams;
var config bool					bBotsBalanceTeams;
var config int					BotBalanceCutoff;


function TransferProperties(TTeamFix Owner)
{
	local TTeamFixGeneric TTFG;

	TTFG = TTeamFixGeneric(Owner);

	if (TTFG == none)
	{
		WarnInternal("Config profile attatched to invalid owner");
		return;
	}

	ValidateProperties(Owner);


	TTFG.bCheckTeamsOnExit		= bCheckTeamsOnExit;
	TTFG.bCheckTeamsOnDeath		= bCheckTeamsOnDeath;
	TTFG.ImbalanceAction		= ImbalanceAction;
	TTFG.BalanceCountdown		= BalanceCountdown;
	TTFG.bAnnounceSwitch		= bAnnounceSwitch;
	TTFG.bAnnounceImbalance		= bAnnounceImbalance;
	TTFG.bAnnounceSlotOpened	= bAnnounceSlotOpened;
	TTFG.PreferredTeams		= PreferredTeams;
	TTFG.ShuffleTeams		= ShuffleTeams;
	TTFG.bBotsBalanceTeams		= bBotsBalanceTeams;
	TTFG.BotBalanceCutoff		= BotBalanceCutoff;
}

function SaveProperties(TTeamFix Owner)
{
	local TTeamFixGeneric TTFG;

	TTFG = TTeamFixGeneric(Owner);

	if (TTFG == none)
	{
		WarnInternal("Config profile attatched to invalid owner");
		return;
	}


	bCheckTeamsOnExit	= TTFG.bCheckTeamsOnExit;
	bCheckTeamsOnDeath	= TTFG.bCheckTeamsOnDeath;
	ImbalanceAction		= TTFG.ImbalanceAction;
	BalanceCountdown	= TTFG.BalanceCountdown;
	bAnnounceSwitch		= TTFG.bAnnounceSwitch;
	bAnnounceImbalance	= TTFG.bAnnounceImbalance;
	bAnnounceSlotOpened	= TTFG.bAnnounceSlotOpened;
	PreferredTeams		= TTFG.PreferredTeams;
	ShuffleTeams		= TTFG.ShuffleTeams;
	bBotsBalanceTeams	= TTFG.bBotsBalanceTeams;
	BotBalanceCutoff	= TTFG.BotBalanceCutoff;

	ValidateProperties(Owner);

	SaveConfig();
}

function ValidateProperties(TTeamFix Owner)
{
	bCheckTeamsOnDeath = (bCheckTeamsOnDeath || ImbalanceAction == IA_DeathEvent || ImbalanceAction == IA_CountdownOrDeath || ImbalanceAction == IA_TeamDeath);

	// BotBalanceCutoff should always be an even number
	if ((BotBalanceCutoff % 2) != 0)
		BotBalanceCutoff++;

	// Make sure it doesn't surpass the maxplayer count
	if (BotBalanceCutoff > Owner.WorldInfo.Game.MaxPlayers)
		BotBalanceCutOff = ((Owner.WorldInfo.Game.MaxPlayers % 2) == 0 ? Owner.WorldInfo.Game.MaxPlayers : Owner.WorldInfo.Game.MaxPlayers-1);
}

defaultproperties
{
	// REMEMBER: If you update a default property here, make sure you do it in ALL OTHER TTFProfile_Generic subclasses too!

	bCheckTeamsOnExit=True
	bCheckTeamsOnDeath=False
	ImbalanceAction=IA_CountdownOrDeath
	BalanceCountdown=15
	PreferredTeams=PT_PreferLosingTeam
	bAnnounceSwitch=True
	bAnnounceImbalance=True
	bAnnounceSlotOpened=True
	ShuffleTeams=ST_MatchStart
	bBotsBalanceTeams=False
	BotBalanceCutoff=0
}