// Handles Character/Squad Creation (on new game).
// Worthless Bums 2012.


function acceptSquadCreationButton ()
{//echo("acceptSquadCreationButton()");
	clearSaveFile();
	Canvas.popDialog(squadCreationGui);
	updateLeaderCreationPanel();
	updateScoutCreationPanel();
	updateGrenadierCreationPanel();
	updateSupportCreationPanel();
	pushStartingTextSequence();
}
function leaderRandomNameButton ()
{//echo("leaderRandomNameButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	$leaderStartName = generateRandomCallsign();
	leaderName.setText($leaderStartName);
}
function scoutRandomNameButton ()
{//echo("scoutRandomNameButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	$scoutStartName = generateRandomCallsign();
	scoutName.setText($scoutStartName);
}
function grenadierRandomNameButton ()
{//echo("grenadierRandomNameButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	$grenadierStartName = generateRandomCallsign();
	grenadierName.setText($grenadierStartName);
}
function supportRandomNameButton ()
{//echo("supportRandomNameButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	$supportStartName = generateRandomCallsign();
	supportName.setText($supportStartName);
}
function initializeSquadCreationGui ()
{//echo("initializeSquadCreationGui()");
	// Set default values.
	// Perk descriptions.
	$sweeperPerkText = 		"\n\n\"Sweeper\"\nLaser Sight grants +2 damage. Cycling attachments costs 0 AP.";
	$spotterPerkText = 		"\n\n\"Spotter\"\nGrants +1 experience per enemy if actively spotting.";
	$fireHazardPerkText = 	"\n\n\"Fire Hazard\"\nUsing a Hulk Suit's ranged flamethrower only costs 1 AP.";
	$closeCombatPerkText = 	"\n\n\"Close Combat\"\nRanged attacks have a 100% chance to hit adjacent targets.";
	$techMongerPerkText = 	"\n\n\"Tech Monger\"\nGrants a +10% chance to find high tech loot in lockers.";
	$bombastPerkText = 		"\n\n\"Bombast\"\nNon-Grenadiers entering Guard Mode grant Grenadiers +1 AP.";
	
	// Class descriptions.
	$leaderClassText 	= "Uses a shotgun for knockback. Force multiplier to strengthen positions or salvage bad ones.";
	$scoutClassText		= "Uses a long rifle that penetrates multiple enemies. When far away things need to stay that way.";
	$grenadierClassText = "Uses a grenade launcher with splash damage. Beware friendly fire. Splash cannot kill outright.";
	$supportClassText 	= "Uses a machine gun for rapid destruction of targets. When targets need to get off your lawn.";
	$engineerClassText 	= "Uses a rapid fire submachine gun with large magazine capacity. Tech support with attitude.";
	
	// Name and Class for each squad member.
	// Leader slot.
	$leaderStartName = generateRandomCallsign();//"Ares";
	$leaderStartGender = "Male";
	$leaderStartClass = "Leader";
	$leaderStartPerk = $sweeperPerkText;
	$leaderPerks = getPerkShorthand($leaderStartPerk);
	// Scout slot.
	$scoutStartName = generateRandomCallsign();//"Athena";
	$scoutStartGender = "Female";
	$scoutStartClass = "Scout";
	$scoutStartPerk = $spotterPerkText;
	$scoutPerks = getPerkShorthand($scoutStartPerk);
	// Grenadier slot.
	$grenadierStartName = generateRandomCallsign();//"Calypso";
	$grenadierStartGender = "Female";
	$grenadierStartClass = "Grenadier";
	$grenadierStartPerk = $fireHazardPerkText;
	$grenadierPerks = getPerkShorthand($grenadierStartPerk);
	// Support slot.
	$supportStartName = generateRandomCallsign();//"Zeus";
	$supportStartGender = "Male";
	$supportStartClass = "Support";
	$supportStartPerk = $closeCombatPerkText;
	$supportPerks = getPerkShorthand($supportStartPerk);
	// Set avatars.
	leaderAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/LeaderPortrait");
	scoutAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/ScoutPortrait");
	grenadierAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/GrenadierPortrait");
	supportAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/SupportPortrait");
	// Set editable name text fields.
	leaderName.setText($leaderStartName);
	scoutName.setText($scoutStartName);
	grenadierName.setText($grenadierStartName);
	supportName.setText($supportStartName);
	// Set classes.
	leaderClass.setText("Leader");
	scoutClass.setText("Scout");
	grenadierClass.setText("Grenadier");
	supportClass.setText("Support");
	
	leaderInfo.setText($leaderClassText @ $sweeperPerkText);
	scoutInfo.setText($scoutClassText @ $spotterPerkText);
	grenadierInfo.setText($grenadierClassText @ $fireHazardPerkText);
	supportInfo.setText($supportClassText @ $closeCombatPerkText);
	Canvas.pushDialog(squadCreationGui);
}
function getPerkShorthand (%perkText)
{
	switch$ (%perkText)
	{
		case $sweeperPerkText:		return "Sweeper";
		case $spotterPerkText:		return "Spotter";
		case $fireHazardPerkText:	return "FireHazard";
		case $closeCombatPerkText:	return "CloseCombat";
		case $techMongerPerkText:	return "TechMonger";
	}
}
function updateLeaderCreationPanel ()
{//echo("updateLeaderCreationPanel()");
	$leaderStartName = strreplace(leaderName.getText(), " ", "");		// Strip white spaces!
	leaderName.setText($leaderStartName);
	leaderClass.setText($leaderStartClass);
	switch$ ($leaderStartClass)
	{
		case "Leader":
			leaderAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/LeaderPortrait");
			leaderInfo.setText($leaderClassText @ $leaderStartPerk);
		case "Scout":
			leaderAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/ScoutPortrait");
			leaderInfo.setText($scoutClassText @ $leaderStartPerk);
		case "Grenadier":
			leaderAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/GrenadierPortrait");
			leaderInfo.setText($grenadierClassText @ $leaderStartPerk);
		case "Support":
			leaderAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/SupportPortrait");
			leaderInfo.setText($supportClassText @ $leaderStartPerk);
		case "Engineer":
			leaderAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/EngineerPortrait");
			leaderInfo.setText($engineerClassText @ $leaderStartPerk);
	}
	$leaderPerks = getPerkShorthand($leaderStartPerk);
}
function updateScoutCreationPanel ()
{//echo("updateScoutCreationPanel()");
	$scoutStartName = strreplace(scoutName.getText(), " ", "");		// Strip white spaces!
	scoutName.setText($scoutStartName);
	scoutClass.setText($scoutStartClass);
	switch$ ($scoutStartClass)
	{
		case "Leader":
			scoutAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/LeaderPortrait");
			scoutInfo.setText($leaderClassText @ $scoutStartPerk);
		case "Scout":
			scoutAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/ScoutPortrait");
			scoutInfo.setText($scoutClassText @ $scoutStartPerk);
		case "Grenadier":
			scoutAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/GrenadierPortrait");
			scoutInfo.setText($grenadierClassText @ $scoutStartPerk);
		case "Support":
			scoutAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/SupportPortrait");
			scoutInfo.setText($supportClassText @ $scoutStartPerk);
		case "Engineer":
			scoutAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/EngineerPortrait");
			scoutInfo.setText($engineerClassText @ $scoutStartPerk);
	}
	$scoutPerks = getPerkShorthand($scoutStartPerk);
}
function updateGrenadierCreationPanel ()
{//echo("updateGrenadierCreationPanel()");
	$grenadierStartName = strreplace(grenadierName.getText(), " ", "");		// Strip white spaces!
	grenadierName.setText($grenadierStartName);
	grenadierClass.setText($grenadierStartClass);
	switch$ ($grenadierStartClass)
	{
		case "Leader":
			grenadierAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/LeaderPortrait");
			grenadierInfo.setText($leaderClassText @ $grenadierStartPerk);
		case "Scout":
			grenadierAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/ScoutPortrait");
			grenadierInfo.setText($scoutClassText @ $grenadierStartPerk);
		case "Grenadier":
			grenadierAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/GrenadierPortrait");
			grenadierInfo.setText($grenadierClassText @ $grenadierStartPerk);
		case "Support":
			grenadierAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/SupportPortrait");
			grenadierInfo.setText($supportClassText @ $grenadierStartPerk);
		case "Engineer":
			grenadierAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/EngineerPortrait");
			grenadierInfo.setText($engineerClassText @ $grenadierStartPerk);
	}
	$grenadierPerks = getPerkShorthand($grenadierStartPerk);
}
function updateSupportCreationPanel ()
{//echo("updateSupportCreationPanel()");
	$supportStartName = strreplace(supportName.getText(), " ", "");		// Strip white spaces!
	supportName.setText($supportStartName);
	supportClass.setText($supportStartClass);
	switch$ ($supportStartClass)
	{
		case "Leader":
			supportAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/LeaderPortrait");
			supportInfo.setText($leaderClassText @ $supportStartPerk);
		case "Scout":
			supportAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/ScoutPortrait");
			supportInfo.setText($scoutClassText @ $supportStartPerk);
		case "Grenadier":
			supportAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/GrenadierPortrait");
			supportInfo.setText($grenadierClassText @ $supportStartPerk);
		case "Support":
			supportAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/SupportPortrait");
			supportInfo.setText($supportClassText @ $supportStartPerk);
		case "Engineer":
			supportAvatar.setBitmap("../../../Sprites/1/assets/images/UI/Explore/EngineerPortrait");
			supportInfo.setText($engineerClassText @ $supportStartPerk);
	}
	$supportPerks = getPerkShorthand($supportStartPerk);
}
function leaderCycleClassButton ()
{//echo("leaderCycleClassButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($leaderStartClass)
	{
		case "Leader":		$leaderStartClass = "Scout";
		case "Scout":		$leaderStartClass = "Grenadier";
		case "Grenadier":	$leaderStartClass = "Support";
		case "Support":		$leaderStartClass = "Engineer";
		case "Engineer":	$leaderStartClass = "Leader";
	}
	updateLeaderCreationPanel();
}
function scoutCycleClassButton ()
{//echo("scoutCycleClassButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($scoutStartClass)
	{
		case "Leader":		$scoutStartClass = "Scout";
		case "Scout":		$scoutStartClass = "Grenadier";
		case "Grenadier":	$scoutStartClass = "Support";
		case "Support":		$scoutStartClass = "Engineer";
		case "Engineer":	$scoutStartClass = "Leader";
	}
	updateScoutCreationPanel();
}
function grenadierCycleClassButton ()
{//echo("grenadierCycleClassButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($grenadierStartClass)
	{
		case "Leader":		$grenadierStartClass = "Scout";
		case "Scout":		$grenadierStartClass = "Grenadier";
		case "Grenadier":	$grenadierStartClass = "Support";
		case "Support":		$grenadierStartClass = "Engineer";
		case "Engineer":	$grenadierStartClass = "Leader";
	}
	updateGrenadierCreationPanel();
}
function supportCycleClassButton ()
{//echo("supportCycleClassButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($supportStartClass)
	{
		case "Leader":		$supportStartClass = "Scout";
		case "Scout":		$supportStartClass = "Grenadier";
		case "Grenadier":	$supportStartClass = "Support";
		case "Support":		$supportStartClass = "Engineer";
		case "Engineer":	$supportStartClass = "Leader";
	}
	updateSupportCreationPanel();
}
function leaderCyclePerkButton ()
{//echo("leaderCyclePerkButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($leaderStartPerk)
	{
		case $sweeperPerkText:		$leaderStartPerk = $spotterPerkText;
		case $spotterPerkText:		$leaderStartPerk = $fireHazardPerkText;
		case $fireHazardPerkText:	$leaderStartPerk = $closeCombatPerkText;
		case $closeCombatPerkText:	$leaderStartPerk = $techMongerPerkText;
		case $techMongerPerkText:	$leaderStartPerk = $sweeperPerkText;
	}
	updateLeaderCreationPanel();
}
function scoutCyclePerkButton ()
{//echo("scoutCyclePerkButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($scoutStartPerk)
	{
		case $sweeperPerkText:		$scoutStartPerk = $spotterPerkText;
		case $spotterPerkText:		$scoutStartPerk = $fireHazardPerkText;
		case $fireHazardPerkText:	$scoutStartPerk = $closeCombatPerkText;
		case $closeCombatPerkText:	$scoutStartPerk = $techMongerPerkText;
		case $techMongerPerkText:	$scoutStartPerk = $sweeperPerkText;
	}
	updateScoutCreationPanel();
}
function grenadierCyclePerkButton ()
{//echo("grenadierCyclePerkButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($grenadierStartPerk)
	{
		case $sweeperPerkText:		$grenadierStartPerk = $spotterPerkText;
		case $spotterPerkText:		$grenadierStartPerk = $fireHazardPerkText;
		case $fireHazardPerkText:	$grenadierStartPerk = $closeCombatPerkText;
		case $closeCombatPerkText:	$grenadierStartPerk = $techMongerPerkText;
		case $techMongerPerkText:	$grenadierStartPerk = $sweeperPerkText;
	}
	updateGrenadierCreationPanel();
}
function supportCyclePerkButton ()
{//echo("supportCyclePerkButton()");
	playAudio("Audio:randomName", EffectsAudioVolume.value);
	switch$ ($supportStartPerk)
	{
		case $sweeperPerkText:		$supportStartPerk = $spotterPerkText;
		case $spotterPerkText:		$supportStartPerk = $fireHazardPerkText;
		case $fireHazardPerkText:	$supportStartPerk = $closeCombatPerkText;
		case $closeCombatPerkText:	$supportStartPerk = $techMongerPerkText;
		case $techMongerPerkText:	$supportStartPerk = $sweeperPerkText;
	}
	updateSupportCreationPanel();
}
function squadCreationClose ()
{//echo("squadCreationClose()");
	Canvas.popDialog(squadCreationGui);
}