// Handle Camera Movements.
// Worthless Bums 2012.


// Updates camera position.
function updateCameraPosition ()
{//echo("updateCameraPosition()");
	if (isWidescreen())
	{
		%horizontalResolution = getWord($Game::Resolution, 0);
		if (%horizontalResolution >= 1366	||
			%horizontalResolution <= 1680)
		{//echo("1");
			sceneWindow2D.position = "0 120";
		}
		else if (%horizontalResolution > 1680)
		{//echo("2");
			sceneWindow2D.position = "-30 140";
		}
		else
		{//echo("3");
			%resolutionRatio = 1280 / getWord($Game::Resolution, 0);
			%horizontalShift = -120 * %resolutionRatio + 120;
			%verticalShift = 120 * %resolutionRatio;
			sceneWindow2D.position = %horizontalShift SPC %verticalShift;
		}
	}
	else
	{
		sceneWindow2D.position = "0 0";
	}
	return true;
}

// Updates camera track speed.
function updateCameraTrackSpeed (%cameraTrackSpeed)
{//echo("updateCameraTrackSpeed()");
	$cameraMountForce = %cameraTrackSpeed;
	$autoTargetCameraMountForce = $cameraMountForce;
	$Game::CameraTrackSpeed = %cameraTrackSpeed;		// Redundant...
	playAudio("Audio:cameraTrackTick", EffectsAudioVolume.value);
}

// Zooms camera to indicate descending stairs.
function zoomCamera (%zoom)
{//echo("zoomCamera()");
	sceneWindow2D.dismount();
	sceneWindow2D.setTargetCameraPosition($playerSquad[$activeCharacter].getPosition());
	sceneWindow2D.setCameraInterpolationMode("LINEAR");
	sceneWindow2D.setTargetCameraZoom(%zoom);
	sceneWindow2D.startCameraMove(0.0);
}

// Zooms camera very fast.
function zoomCameraFast (%zoom)
{//echo("zoomCameraFast()");
	sceneWindow2D.setCameraZoom(%zoom);
}

// Zooms camera to indicate descending stairs.
function descendStairsCamera ()
{//echo("descendStairsCamera()");
	sceneWindow2D.dismount();
	sceneWindow2D.setTargetCameraPosition($playerSquad[$activeCharacter].getPosition());
	sceneWindow2D.setCameraInterpolationMode("LINEAR");
	sceneWindow2D.setTargetCameraZoom(8);
	sceneWindow2D.startCameraMove(1.8);
}

// Zooms camera to indicate descending stairs (from the Overworld).
function descendStairsFromOverworldCamera (%position)
{//echo("descendStairsFromOverworldCamera()");
	sceneWindow2D.dismount();
	sceneWindow2D.setTargetCameraPosition(%position);
	sceneWindow2D.setCameraInterpolationMode("LINEAR");
	sceneWindow2D.setTargetCameraZoom(8);
	sceneWindow2D.startCameraMove(1.8);
}

// Resets camera position.
function cameraReset ()
{//echo("cameraReset()");
	sceneWindow2D.dismount();
	sceneWindow2D.setTargetCameraPosition($playerSquad[$activeCharacter].getPosition());
	sceneWindow2D.setCameraInterpolationMode("LINEAR");
	sceneWindow2D.setTargetCameraZoom(1);
	sceneWindow2D.startCameraMove(0);
}

// Pushes loadingDungeonScreen gui.
function pushLoadingDungeon ()
{//echo("pushLoadingDungeon()");
	Canvas.pushDialog(loadingDungeonScreen);
	$YelizavetaAlexandrovnaShulyayeva = 2;		// Set function rw() test flag!
}

// Pops loadingDungeonScreen gui.
function popLoadingDungeon ()
{//echo("popLoadingDungeon()");
	Canvas.popDialog(loadingDungeonScreen);
}

// Dispatches camera shake based on active character firing.
function dispatchSquadMemberCameraShake ()
{//echo("dispatchSquadMemberCameraShake()");
	switch ($playerSquad[$activeCharacter].characterClass)
	{
		case 0:	leaderFireCameraShake();
		case 1:	scoutFireCameraShake();
		case 2:	grenadierFireCameraShake();
		case 3: supportFireCameraShake();
		case 4: engineerFireCameraShake();
	}
	if ($playerSquad[$activeCharacter].weapon.projectileType == $weaponProjectileBallisticType)
	{
		switch ($playerSquad[$activeCharacter].characterClass)
		{
			case 0:	createCasingEjectionAnimation($playerSquad[$activeCharacter]);
			case 1:	createCasingEjectionAnimation($playerSquad[$activeCharacter]);
			case 2:	
			case 3:
				createCasingEjectionAnimation($playerSquad[$activeCharacter]);
				schedule(100, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
				schedule(200, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
			case 4:
				createCasingEjectionAnimation($playerSquad[$activeCharacter]);
				schedule(100, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
				schedule(200, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
		}
	}
}
function dispatchHulkRangedCameraShake ()
{//echo("dispatchHulkRangedCameraShake()");
	sceneWindow2D.startCameraShake(20, 1.2);
	
	createCasingEjectionAnimation($playerSquad[$activeCharacter]);
	schedule(100, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
	schedule(200, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
	schedule(300, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
	schedule(400, 0 , "createCasingEjectionAnimation", $playerSquad[$activeCharacter]);
}

// Shakes the camera for Leader firing.
function leaderFireCameraShake ()
{//echo("leaderFireCameraShake()");
	sceneWindow2D.startCameraShake(12, 0.2);
}
// Shakes the camera for Scout firing.
function scoutFireCameraShake ()
{//echo("scoutFireCameraShake()");
	sceneWindow2D.startCameraShake(22, 0.1);
}
// Shakes the camera for Grenadier firing.
function grenadierFireCameraShake ()
{//echo("grenadierFireCameraShake()");
	sceneWindow2D.startCameraShake(8, 0.3);
}
// Shakes the camera for Support firing.
function supportFireCameraShake ()
{//echo("supportFireCameraShake()");
	sceneWindow2D.startCameraShake(13, 0.5);
}
// Shakes the camera for Engineer firing.
function engineerFireCameraShake ()
{//echo("engineerFireCameraShake()");
	sceneWindow2D.startCameraShake(15, 0.6);
}

// Shakes the camera for UI tweening.
function uiTweenCameraShake ()
{//echo("uiTweenCameraShake()");
	sceneWindow2D.startCameraShake(13, 0.25);
	playAudio("Audio:uiCrash", EffectsAudioVolume.value);
}

// Shakes the camera for unit knock back.
function knockBackCameraShake ()
{//echo("knockBackCameraShake()");
	sceneWindow2D.startCameraShake(30, 0.05);
}

// Camera locking functions.
function lockCameraForMonster ()
{
	$MonsterCameraLock = true;
}
function unlockCameraForMonster ()
{
	$MonsterCameraLock = false;
}
function isCameraMonsterLocked ()
{
	return $MonsterCameraLock;
}