// Tutorial Elements.
// Worthless Bums 2013.


function tutorialStart ()
{//echo("tutorialStart()");
	if ($gameInProgress)
	{
		return;
	}
	$generateTutorialLevel = true;
	newGameButton(false);
	// Setup squad.
	$playerSquad[0].name = "Maggot";
	$playerSquad[1].name = "Roach";
	$playerSquad[2].name = "Fly";
	$playerSquad[3].name = "Worm";
	$playerSquad[0].characterClass = 0;
	$playerSquad[1].characterClass = 1;
	$playerSquad[2].characterClass = 2;
	$playerSquad[3].characterClass = 3;
	$playerSquad[0].currentActionPoints = 30;
	$playerSquad[1].currentActionPoints = 30;
	$playerSquad[2].currentActionPoints = 30;
	$playerSquad[3].currentActionPoints = 30;
	moveSquadToFreeArea();
	// Spawn immobile Brutes as immobile target practice!
	%flankBrute = spawnMonster(0, 9, 2);
	setMonsterFacing($southDirection, %flankBrute);
	%flankBrute.currentHealth = 1;
	%flankBrute.currentActionPoints = 0;
	%flankBrute.maxActionPoints = 0;
	$MonsterList.add(%flankBrute);
	%rearBrute = spawnMonster(0, 9, 3);
	%rearBrute.currentHealth = 1;
	%rearBrute.currentActionPoints = 0;
	%rearBrute.maxActionPoints = 0;
	setMonsterFacing($eastDirection, %rearBrute);
	$MonsterList.add(%rearBrute);
	updateMonsterFloatingText();
	updatePortraits();
	// Start Tutorial popups!
	$tutorialSection = 0;
	tutorialMessage0();
	//$generateTutorialLevel = false;		// Turn this off after the player finishes/quits the tutorial level!
}
function tutorialMessage0 ()
{
	tutorialPopup.setText("This is the Steam Marines tutorial, Maggot.\n\nThe first thing you'll probably want to do is move around.\n\nSee the bouncing arrow pointing at a marine? That's the active marine you're controlling.\n\nYou can move around with the arrow keys. Try moving to the right!");
	Canvas.pushDialog(tutorial);
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage1 ()
{
	tutorialPopup.setText("Outstanding, Maggot. You're about as smart as a dinosaur.\n\nLet's not leave your other dinosaur friends behind. Cycle to a different marine in your squad with the TAB or CTRL keys.");
	$tutorialSection = 1;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage2 ()
{
	tutorialPopup.setText("I'm glad you didn't shoot yourself instead.\n\nRemember that marines can't stack on top of each other! If you need to move through an occupied tile both marines need at least one Action Point; then moving into an occupied tile will swap both marines.\n\nTry it now.");
	$tutorialSection = 2;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage3 ()
{
	tutorialPopup.setText("Good. Try not to bungle it on the battlefield.\n\nNow try to move down the hall to the right - you'll find some immobilized targets there.");
	$tutorialSection = 3;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage4 ()
{
	tutorialPopup.setText("Hold up, " @ $playerSquad[$activeCharacter].name @ "!\n\nThat's a \"Brute\", a mechanical enemy. This one's pretty busted and immobile. You've automatically targeted it by moving into sight and weapon range.\n\nTargets at max weapon range have a 100% chance to be hit - remember that when positioning your squad!\n\nDestroy that Brute by tapping Z!");
	$tutorialSection = 4;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage5 ()
{
	tutorialPopup.setText("Good job, " @ $playerSquad[$activeCharacter].name @ "!\n\nThat's how the Corps deals with mechanical invaders!\n\nRemember that real threats can move around and are generally hazardous to a marine's health.\n\nIf a marine has Action Points left, Guard Mode (Q) allows automatic fire on enemies that move into sight and weapon range during the enemy turn. This takes all of a marine's remaining Action Points\n\nFinish the last Brute at your leisure, with or without Guarding.");
	$tutorialSection = 5;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
	
	%brute = $MonsterList.getObject(0);
	%brute.currentHealth = 15;
	%brute.currentActionPoints = 2;
	%brute.maxActionPoints = 2;
	updateMonsterFloatingText();
}
function tutorialMessage6 ()
{
	tutorialPopup.setText("Excellent, it only took four of you to kill two of them.\n\nDid you notice you did more damage with each consecutive hit? Armor rating is a flat damage reductor, but it degrades as it gets hit.\n\nAlso remember that ammo is a marine's best friend. Keep an eye on the ammo indicator on the bottom right of the screen.\n\nReload your weapon now by tapping R!");
	$tutorialSection = 6;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage7 ()
{
	tutorialPopup.setText("You're ready to rock, grunt.\n\nI hope you noticed that reloading takes all remaining Action Points. Also note that after a brief delay the next available marine will be selected unless you interrupt by selecting a marine manually.\n\nYour vision is limited by your facing. You can change the direction a marine faces by holding down SHIFT and tapping a movement key.\n\nFace SOUTH, marine!");
	$tutorialSection = 7;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage8 ()
{
	tutorialPopup.setText("Glad that we don't have to cover cardinal directions like in boot.\n\nThe elevator is what allows you to travel between deck levels. It's usually your primary goal - not the enemy! The enemy are obstacles. Destroy or circumvent as you see fit in the field.\n\nExplore and find the elevator!");
	$tutorialSection = 8;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage9 ()
{
	tutorialPopup.setText("We're almost done, marines.\n\nIf your entire squad runs out of Action Points the turn will end and the enemy turn will begin. Assuming you didn't bungle it, any marines alive at the start of the next turn will have their max Action Points restored. You can also hit ENTER to manually end the turn.\n\nManually end the turn now!");
	$tutorialSection = 9;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage10 ()
{
	tutorialPopup.setText("Look at your squad's Action Points. That's more like what you'll experience in the field!\n\nYou can tell where the elevator is from the \"elevator zone\" - green marked tiles on the floor. All you have to do is move your entire squad into the zone to progress. Animations will flash on each marine when the entire squad is in this zone.\n\nGet your squad to the elevator zone!");
	$tutorialSection = 10;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}
function tutorialMessage11 ()
{
	tutorialPopup.setText("This was just a taste of Steam Marines.\n\nWe haven't even touched on enemy abilities, various items, weapons and armor, or Promotions!\n\nRemember that interacting with the environment (like opening doors, meleeing enemies, smashing crates, using consoles/dispensers, picking up items, and smashing walls) is accomplished by simply moving into them.\n\nPress L to use the elevator and complete the tutorial!");
	$tutorialSection = 11;
	playAudio("Audio:tutorialMessage", EffectsAudioVolume.value);
}

function createTutorialLevel ()
{//echo("createTutorialLevel()");
	// Destroy any remnants of the last generated dungeon of this type!
	if (isObject($mazeRoom))
	{
		$mazeRoom.safeDelete();
	}
	
	%levelDimension = 10;
	%row0 = "2 2 2 2 2 2 2 2 2 2";
	%row1 = "2 0 0 4 0 0 0 0 0 2";
	%row2 = "2 0 0 4 0 0 0 0 0 2";
	%row3 = "2 2 2 2 2 4 4 2 2 2";
	%row4 = "2 0 0 0 0 0 0 4 0 2";
	%row5 = "2 0 0 0 0 0 0 2 0 2";
	%row6 = "2 2 4 4 2 2 2 2 4 2";
	%row7 = "2 0 0 0 0 4 0 0 0 2";
	%row8 = "2 0 0 0 0 4 0 0 0 2";
	%row9 = "2 2 2 2 2 2 2 2 2 2";
	for (%i = 0; %i < %levelDimension; %i++)
	{
		for (%j = 0; %j < %levelDimension; %j++)
		{
			switch (%i)
			{
				case 0:	%row = %row0;
				case 1:	%row = %row1;
				case 2:	%row = %row2;
				case 3:	%row = %row3;
				case 4:	%row = %row4;
				case 5:	%row = %row5;
				case 6:	%row = %row6;
				case 7:	%row = %row7;
				case 8:	%row = %row8;
				case 9:	%row = %row9;
			}
			%levelData[%i, %j] = getWord(%row, %j);
		}
	}
	// Fill $mapArr.
	for (%i = 0; %i < %levelDimension; %i++)
	{
		for (%j = 0; %j < %levelDimension; %j++)
		{
			$mapArr[%j + 1, %i + 1] = %levelData[%j, %i];
		}
	}
}