dofile('data/Scripts/Scenes/Common.lua');
dofile('data/Scripts/Scenes/Animations/18_AncientTeleportPortal_Animations.lua');
dofile('data/Scripts/Scenes/Animations/18_AncientTeleportLogic_Animations.lua');

------------------------------------------------------------------------------
--
function OnSceneLoad(restoringFromSave)
	InitGameState();

	play_field = playField;
    LoadData();
	play_field = nil;

    RootZoomZone = CreateZoomZone('RootZoomZone', nil, 
                                   nil, 0.0, 
                                   nil, 0.0,
							{'RootBackground',
							 'actZoneNearTeleport',
							 'actZoneTortoiseStatue',

							 'animalSkull',
							 'ape',
							 'barrow',
							 'blackPearl',
							 'box',
							 'cake',
							 'cheetah',
							 'clock',
							 'coconut',
							 'column',
							 'corn',
							 'crown',
							 'earring',
							 'egg',
							 'elephant',
							 'emerald',
							 'feather',
							 'flowerpot',
							 'frog',
							 'goose',
							 'jug',
							 'knife',
							 'lantern',
							 'leaf',
							 'lily',
							 'mask',
							 'mortar',
							 'mug',
							 'mushroom',
							 'parrot',
							 'pattern',
							 'pipe',
							 'pot',
							 'ring',
							 'seashell',
							 'snake',
							 'sunflower',
							 'tulip',
							 'vase',
							 'watermelon',

							 'LayerOverCorn',
							 'LayerOverElephant',
							 'LayerOverKnife',
							 'LayerOverWatermelon',
							 'LayerOverBlueCrystal',

							 'turtleShellOpened',
							 'turtleShellClosed',
							 'platform',
							 'waterfallAnimation',

							 'BlueCrystal',
							 'Lever',
							 'Pinion',
							 'PortalSign',
							 'TeleportSphere',
							 'TortoiseShellPart',

							 'Lever_onPlace',
							 'PortalSign_onPlaceGen',
							 'TeleportSphere_onPlaceGen',
							 'TortoiseShellPart_onPlace',


							 'actZoneTeleport',
							 'actZoneTortoiseShellPart',
							 'actZoneLever',
							 'actZoneNearTeleport'},

							{'Lever_onPlace',
							 'PortalSign_onPlaceGen',
							 'TeleportSphere_onPlaceGen',
							 'TortoiseShellPart_onPlace',
							 'turtleShellOpened',
							 'platform'});

    NearTeleportZoomZone = CreateZoomZone('NearTeleportZoomZone', RootZoomZone, 
                                   'actZoneNearTeleport', 0.0, 
                                   nil, 0.0,
							{'ZoomNearTeleportBackground',

							 'PortalSign_onPlace',
							 'TeleportSphere_onPlace',

							 'actZonePortalSign',
							 'actZoneTeleportSphere'},

							{'PortalSign_onPlace',
							 'TeleportSphere_onPlace'});

    TortoiseStatueZoomZone = CreateZoomZone('TortoiseStatueZoomZone', RootZoomZone, 
                                   'actZoneTortoiseStatue', 0.0, 
                                   nil, 0.0,
							{'ZoomTortoiseStatueBackground',

							 'part1',
							 'part2',
							 'smallPinion1',
							 'smallPinion2',
							 'redCrystal',

							 'BlueCrystal_onPlace',
							 'Pinion_onPlace',

							 'actZonePinion',
							 'actZoneBlueCrystal'},

							{'BlueCrystal_onPlace',
							 'Pinion_onPlace'});


if (restoringFromSave == false) then
    AddRandomTasks(true, MISC_TASK_COUNT_24,
		CreateTask('animalSkull'),
		CreateTask('ape'),
		CreateTask('barrow'),
		CreateTask('blackPearl'),
		CreateTask('box'),
		CreateTask('cake'),
		CreateTask('cheetah'),
		CreateTask('clock'),
		CreateTask('coconut'),
		CreateTask('column'),
		CreateTask('corn'),
		CreateTask('crown'),
		CreateTask('earring'),
		CreateTask('egg'),
		CreateTask('elephant'),
		CreateTask('emerald'),
		CreateTask('feather'),
		CreateTask('flowerpot'),
		CreateTask('frog'),
		CreateTask('goose'),
		CreateTask('jug'),
		CreateTask('knife'),
		CreateTask('lantern'),
		CreateTask('leaf'),
		CreateTask('lily'),
		CreateTask('mask'),
		CreateTask('mortar'),
		CreateTask('mug'),
		CreateTask('mushroom'),
		CreateTask('parrot'),
		CreateTask('pattern'),
		CreateTask('pipe'),
		CreateTask('pot'),
		CreateTask('ring'),
		CreateTask('seashell'),
		CreateTask('snake'),
		CreateTask('sunflower'),
		CreateTask('tulip'),
		CreateTask('vase'),
		CreateTask('watermelon')
	);

    playField:GetLevelScreen():AddTaskSafe(CreateTask('BlueCrystal'));
    playField:GetLevelScreen():AddTaskSafe(CreateTask('Lever'));
    playField:GetLevelScreen():AddTaskSafe(CreateTask('Pinion'));
    playField:GetLevelScreen():AddTaskSafe(CreateTask('PortalSign'));
    playField:GetLevelScreen():AddTaskSafe(CreateTask('TeleportSphere'));
    playField:GetLevelScreen():AddTaskSafe(CreateTask('TortoiseShellPart'));
end

	CreateToolMap(	{'BlueCrystal',			'actZoneBlueCrystal'},
					{'Lever',				'actZoneLever'},
					{'Pinion',				'actZonePinion'},
					{'PortalSign',   		'actZonePortalSign'},
					{'TeleportSphere',  	'actZoneTeleportSphere'},
					{'TortoiseShellPart',	'actZoneTortoiseShellPart'});

	SetIconForGameObject(playField:GetObject('animalSkull'),'data/Texture/Scenes/18_AncientTeleport/Items/Misc/animalSkull_icon.png');
	SetIconForGameObject(playField:GetObject('ape'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/ape_icon.png');
	SetIconForGameObject(playField:GetObject('barrow'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/barrow_icon.png');
	SetIconForGameObject(playField:GetObject('blackPearl'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/blackPearl_icon.png');
	SetIconForGameObject(playField:GetObject('box'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/box_icon.png');
	SetIconForGameObject(playField:GetObject('cake'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/cake_icon.png');
	SetIconForGameObject(playField:GetObject('cheetah'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/cheetah_icon.png');
	SetIconForGameObject(playField:GetObject('clock'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/clock_icon.png');
	SetIconForGameObject(playField:GetObject('coconut'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/coconut_icon.png');
	SetIconForGameObject(playField:GetObject('column'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/column_icon.png');
	SetIconForGameObject(playField:GetObject('corn'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/corn_icon.png');
	SetIconForGameObject(playField:GetObject('crown'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/crown_icon.png');
	SetIconForGameObject(playField:GetObject('earring'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/earring_icon.png');
	SetIconForGameObject(playField:GetObject('egg'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/egg_icon.png');
	SetIconForGameObject(playField:GetObject('elephant'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/elephant_icon.png');
	SetIconForGameObject(playField:GetObject('emerald'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/emerald_icon.png');
	SetIconForGameObject(playField:GetObject('feather'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/feather_icon.png');
	SetIconForGameObject(playField:GetObject('flowerpot'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/flowerpot_icon.png');
	SetIconForGameObject(playField:GetObject('frog'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/frog_icon.png');
	SetIconForGameObject(playField:GetObject('goose'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/goose_icon.png');
	SetIconForGameObject(playField:GetObject('jug'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/jug_icon.png');
	SetIconForGameObject(playField:GetObject('knife'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/knife_icon.png');
	SetIconForGameObject(playField:GetObject('lantern'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/lantern_icon.png');
	SetIconForGameObject(playField:GetObject('leaf'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/leaf_icon.png');
	SetIconForGameObject(playField:GetObject('lily'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/lily_icon.png');
	SetIconForGameObject(playField:GetObject('mask'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/mask_icon.png');
	SetIconForGameObject(playField:GetObject('mortar'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/mortar_icon.png');
	SetIconForGameObject(playField:GetObject('mug'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/mug_icon.png');
	SetIconForGameObject(playField:GetObject('mushroom'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/mushroom_icon.png');
	SetIconForGameObject(playField:GetObject('parrot'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/parrot_icon.png');
	SetIconForGameObject(playField:GetObject('pattern'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/pattern_icon.png');
	SetIconForGameObject(playField:GetObject('pipe'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/pipe_icon.png');
	SetIconForGameObject(playField:GetObject('pot'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/pot_icon.png');
	SetIconForGameObject(playField:GetObject('ring'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/ring_icon.png');
	SetIconForGameObject(playField:GetObject('seashell'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/seashell_icon.png');
	SetIconForGameObject(playField:GetObject('snake'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/snake_icon.png');
	SetIconForGameObject(playField:GetObject('sunflower'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/sunflower_icon.png');
	SetIconForGameObject(playField:GetObject('tulip'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/tulip_icon.png');
	SetIconForGameObject(playField:GetObject('vase'),		'data/Texture/Scenes/18_AncientTeleport/Items/Misc/vase_icon.png');
	SetIconForGameObject(playField:GetObject('watermelon'),	'data/Texture/Scenes/18_AncientTeleport/Items/Misc/watermelon_icon.png');

	SetIconForGameObject(playField:GetObject('BlueCrystal'),'data/Texture/Scenes/18_AncientTeleport/Items/BlueCrystal_icon.png');
	SetIconForGameObject(playField:GetObject('Lever'),		'data/Texture/Scenes/18_AncientTeleport/Items/Lever_icon.png');
	SetIconForGameObject(playField:GetObject('Pinion'),		'data/Texture/Scenes/18_AncientTeleport/Items/Pinion_icon.png');
	SetIconForGameObject(playField:GetObject('PortalSign'),	'data/Texture/Scenes/18_AncientTeleport/Items/PortalSign_icon.png');
	SetIconForGameObject(playField:GetObject('TeleportSphere'),'data/Texture/Scenes/18_AncientTeleport/Items/TeleportSphere_icon.png');
	SetIconForGameObject(playField:GetObject('TortoiseShellPart'),'data/Texture/Scenes/18_AncientTeleport/Items/TortoiseShellPart_icon.png');

if (restoringFromSave == false) then
	gameState.finalZoomInPos = {playField:GetObject('actZoneNearTeleport'):GetScrX(), playField:GetObject('actZoneNearTeleport'):GetScrY()};

	gameState.nextAnimationDelay = 0;

	gameState.blueCrystalOnPlace = false;
	gameState.leverOnPlace = false;
	gameState.pinionOnPlace = false;
	gameState.portalSignOnPlace = false;
	gameState.teleportSphereOnPlace = false;
	gameState.shellPartOnPlace = false;

	gameState.minigameDone = false;
	gameState.clickedOnPortal = false;
	gameState.pinionIsTurned = false;
	gameState.pinionIsTurning = false;

	gameState.allToolsApplied = false;
	gameState.levelCompleted = false;
end

	AssignActiveZonesGlow({function() return gameState.blueCrystalOnPlace; end,		'actZoneBlueCrystal',		'BlueCrystal_ghost'},
						  {function() return gameState.leverOnPlace or
											 not gameState.shellPartOnPlace; end,	'actZoneLever',				'Lever_ghost'},
					      {function() return gameState.pinionOnPlace; end,			'actZonePinion',			'Pinion_ghost'},
						  {function() return gameState.portalSignOnPlace; end,		'actZonePortalSign',		'PortalSign_ghost'},
						  {function() return gameState.teleportSphereOnPlace; end,	'actZoneTeleportSphere',	'TeleportSphere_ghost'},
						  {function() return gameState.shellPartOnPlace; end,		'actZoneTortoiseShellPart',	'TortoiseShellPart_ghost'});


    ApplyLevelDump(restoringFromSave);
	SetZoneVisible(RootZoomZone, true, false);

	auxSceneInit(restoringFromSave);
	auxProcessToolObjectStateAnCursorType();
end

------------------------------------------------------------------------------
--
function OnSceneFree()
    FreeData()

	StopSound('L18S10');
	StopSound('L18S11');
	StopSound('L18S12');
	StopSound('L18S13');
	StopSound('L18S14');
	StopSound('L18S15');
end

--// Local auxiliary functions - - - - - - - - - - - - - - - - - - - - - - - -
function auxSceneInit(restoringFromSave)
    local initialActions = function()
		ShowLevelIntro(18);
    end
	local regularActions = function()
		PlaySound('L18S12', true);

		if (gameState.minigameDone) then
			PlaySound('L18S15', true);
		end
		if (gameState.blueCrystalOnPlace and gameState.pinionOnPlace) then
			PlaySound('L18S10', true);
		end

--		gameState.customCursors['actZoneNearTeleport'] = {'CursorZoom'};
--		gameState.customCursors['actZoneTortoiseStatue'] = {'CursorZoom'};

		auxAttachInPlace(playField:GetObject('TortoiseShellPart_onPlace'), playField:GetObject('turtleShellClosed'));

		auxCreateAncientTeleportPortalAnimations(playField:GetObject('RootBackground'));
		auxPlayAncientTeleportPortalAnimation('PortalAnimation');
		auxCreateAncientTeleportLogicAnimations(playField:GetObject('RootBackground'));
		auxPlayAncientTeleportLogicAnimation('Env');

--		playField:IgnoreOnTestPoint('');

		gameState.pinionIsTurning = false;
	end

    if (restoringFromSave == false) then
        initialActions();
	else
    end	
    regularActions();

	if (gameState.levelCompleted == true) then
		gameState.levelCompleted = false;
		auxTestLevelCompleteCondition();
	end
end


function auxProcessToolObjectStateAnCursorType()
    assert( gameState.blueCrystalOnPlace ~= nil and
			gameState.leverOnPlace ~= nil and
			gameState.pinionOnPlace ~= nil and
			gameState.portalSignOnPlace ~= nil and
			gameState.teleportSphereOnPlace ~= nil and
			gameState.shellPartOnPlace ~= nil and

			gameState.pinionIsTurned ~= nil and
			gameState.pinionIsTurning ~= nil);

	if (gameState.blueCrystalOnPlace == true) then
		TortoiseStatueZoomZone.UnhideObject('BlueCrystal_onPlace');
		gameState.customCursors['actZoneBlueCrystal'] = nil;
	else
		TortoiseStatueZoomZone.HideObject('BlueCrystal_onPlace');
		gameState.customCursors['actZoneBlueCrystal'] = {'CursorArms'};
	end

	if (gameState.leverOnPlace == true) then
		RootZoomZone.UnhideObject('Lever_onPlace');
		RootZoomZone.UnhideObject('turtleShellOpened');
		RootZoomZone.HideObject('turtleShellClosed');
		gameState.customCursors['actZoneLever'] = nil;

        if (gameState.blueCrystalOnPlace == true and gameState.pinionOnPlace == true) then
			if (gameState.pinionIsTurning == false) then
				gameState.customCursors['actZoneTortoiseStatue'] = nil;
				gameState.lockedObjects['actZoneTortoiseStatue'] = true;
			end
		else
			gameState.customCursors['actZoneTortoiseStatue'] = {'CursorZoom'};
			gameState.lockedObjects['actZoneTortoiseStatue'] = nil;
		end
	else
		RootZoomZone.HideObject('Lever_onPlace');
		RootZoomZone.HideObject('turtleShellOpened');
		RootZoomZone.UnhideObject('turtleShellClosed');
		if (gameState.shellPartOnPlace == false) then
			gameState.customCursors['actZoneLever'] = nil;
			gameState.lockedObjects['actZoneLever'] = true;
		else
			gameState.customCursors['actZoneLever'] = {'CursorArms'};
			gameState.lockedObjects['actZoneLever'] = nil;
		end
		gameState.customCursors['actZoneTortoiseStatue'] = nil;
		gameState.lockedObjects['actZoneTortoiseStatue'] = true;
	end

	if (gameState.pinionIsTurning == false) then
		if (gameState.pinionOnPlace == true) then
			TortoiseStatueZoomZone.UnhideObject('Pinion_onPlace');
			if (gameState.pinionIsTurned == true) then
				gameState.customCursors['actZonePinion'] = nil;
			else
				gameState.customCursors['actZonePinion'] = {'CursorArms'};
			end
		else
			TortoiseStatueZoomZone.HideObject('Pinion_onPlace');
			gameState.customCursors['actZonePinion'] = {'CursorArms'};
		end
	end

	if (gameState.portalSignOnPlace == true) then
		RootZoomZone.UnhideObject('PortalSign_onPlaceGen');
		NearTeleportZoomZone.UnhideObject('PortalSign_onPlace');
		gameState.customCursors['actZonePortalSign'] = nil;
	else
		RootZoomZone.HideObject('PortalSign_onPlaceGen');
		NearTeleportZoomZone.HideObject('PortalSign_onPlace');
		gameState.customCursors['actZonePortalSign'] = {'CursorArms'};
	end

	if (gameState.teleportSphereOnPlace == true) then
		RootZoomZone.UnhideObject('TeleportSphere_onPlaceGen');
		NearTeleportZoomZone.UnhideObject('TeleportSphere_onPlace');
		gameState.customCursors['actZoneTeleportSphere'] = nil;
	else
		RootZoomZone.HideObject('TeleportSphere_onPlaceGen');
		NearTeleportZoomZone.HideObject('TeleportSphere_onPlace');
		gameState.customCursors['actZoneTeleportSphere'] = {'CursorArms'};
	end

	if (gameState.shellPartOnPlace == true) then
		RootZoomZone.UnhideObject('TortoiseShellPart_onPlace');
		RootZoomZone.UnhideObject('platform');
		gameState.customCursors['actZoneTortoiseShellPart'] = nil;
	else
		RootZoomZone.HideObject('TortoiseShellPart_onPlace');
		RootZoomZone.HideObject('platform');
		gameState.customCursors['actZoneTortoiseShellPart'] = {'CursorArms'};
	end

	if (gameState.allToolsApplied == true) then
		if (gameState.minigameDone == true) then
			if (auxGetAncientTeleportPortalAnimation('PortalAnimation'):IsVisible() == false) then
				auxPlayAncientTeleportPortalAnimation('PortalAnimation');
			end
			gameState.customCursors['actZoneTeleport'] = {'CursorNavigation', -95.0 /180.0*M_PI};
		else
			gameState.customCursors['actZoneTeleport'] = {'CursorZoom'};
		end
		playField:GetObject('actZoneTeleport'):SetVisible(true);
	else
		if (auxGetAncientTeleportPortalAnimation('PortalAnimation'):IsVisible() == true) then
			auxHideAncientTeleportPortalAnimation('PortalAnimation');
		end
		playField:GetObject('actZoneTeleport'):SetVisible(false);

		if (gameState.portalSignOnPlace == false or
			gameState.teleportSphereOnPlace == false) then

			gameState.customCursors['actZoneNearTeleport'] = {'CursorZoom'};
			gameState.lockedObjects['actZoneNearTeleport'] = nil;
		else
			gameState.customCursors['actZoneNearTeleport'] = nil;
			gameState.lockedObjects['actZoneNearTeleport'] = true;
		end
	end

	if (gameState.pinionOnPlace == true and gameState.blueCrystalOnPlace == true) then
		if (auxGetAncientTeleportLogicAnimation('EyesGlow'):IsVisible() == false) then
			auxPlayAncientTeleportLogicAnimation('EyesGlow');
		end
	else
		if (auxGetAncientTeleportLogicAnimation('EyesGlow'):IsVisible() == true) then
			auxHideAncientTeleportLogicAnimation('EyesGlow');
		end
	end

	if (gameState.portalSignOnPlace == true and gameState.teleportSphereOnPlace == true) then
		if (auxGetAncientTeleportLogicAnimation('Lightning'):IsVisible() == false) then
			auxPlayAncientTeleportLogicAnimation('Lightning');
		end
	else
		if (auxGetAncientTeleportLogicAnimation('Lightning'):IsVisible() == true) then
			auxHideAncientTeleportLogicAnimation('Lightning');
		end
	end
end

function auxRotatePinions()
	local duration = 1.0;

	gameState.pinionIsTurned = true;
	local objPinion = playField:GetObject('Pinion_onPlace');

	objPinion:SetAngle(0.0);
	objPinion:Rotate(45.0 /180.0*M_PI, duration);
end

--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function auxUpdatePeriodicAnimations(dt)
	if (gameState.nextAnimationDelay == 0.0) then
		local animations = {};

		for compositionName, composition in pairs(ancientTeleportLogicCompositions) do
			if (composition:IsCyclic() == false) then
				table.insert(animations, composition:GetName());
			end
		end

		local animName = animations[math.random(1, table.getn(animations))];
		if (animName ~= nil) then
			local composition = auxGetAncientTeleportLogicAnimation(animName);

            if (composition ~= nil and composition:IsPaused() == true) then
				auxPlayAncientTeleportLogicAnimation(animName);
			end
		end
		gameState.nextAnimationDelay = math.random(8, 14);
	else
		gameState.nextAnimationDelay = (gameState.nextAnimationDelay - dt >= 0.0 and gameState.nextAnimationDelay - dt or 0.0);
	end
end

--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function auxTestLevelCompleteCondition()
	if (gameState.pinionIsTurned == true and
		gameState.clickedOnPortal == true and

		gameState.allToolsApplied == true and
		gameState.levelCompleted == false and
		playField:GetLevelScreen():HasUncompletedTask() == false) then

		gameState.levelCompleted = true;
		TimerDoString('OnWin();', 2.0, playField:GetTimer());
	end
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

------------------------------------------------------------------------------
--
function OnDialogButtonPress(name, param)
	if (gameState.minigameDone == true and 
		(param == 'MSG_MINIGAME_SKIPPED' or param == 'MSG_MINIGAME_DONE')) then
		PlaySound('L18S15', true);
	end
end

------------------------------------------------------------------------------
--
function OnUpdate(dt)
	auxUpdatePeriodicAnimations(dt);

    DefaultOnUpdate(dt);
end

------------------------------------------------------------------------------
--
function OnWin()
	DefaultOnWin();
end

------------------------------------------------------------------------------
--
function OnObjectMouseEnter(object)
    local objectName = object:GetName();

    DefaultOnObjectMouseEnter(object);
	ActivateActiveZoneGlow(objectName);
end

------------------------------------------------------------------------------
--
function OnObjectMouseLeave(object)
    local objectName = object:GetName();

    DefaultOnObjectMouseLeave(object);
    DeactivateActiveZoneGlow(objectName);
end

------------------------------------------------------------------------------
--
function OnObjectMouseDown(object)
    local objectName = object:GetName();
    local isWrongClick = true;

	assert(gameState.activeZone ~= nil and gameState.locker:GetNReferences() > 0);

    if (gameState.lockedObjects[objectName] ~= true) then
        if (gameState.activeZone.HasObject(objectName)) then
            isWrongClick = DefaultOnZoomZoneActiveObjectClick(objectName);

			--// ...
			if (objectName == 'actZoneTeleport') then
				if (gameState.minigameDone == false) then
					gameState.minigameDone = true;
					playField:GetLevelScreen():RunMiniGame('data/Scripts/Minigames/Teleport.lua');
					auxProcessToolObjectStateAnCursorType();
				elseif (gameState.clickedOnPortal == false and gameState.allToolsApplied == true) then
					gameState.clickedOnPortal = true;
					auxTestLevelCompleteCondition();
				end
			end

--[[ -- (!) DEBUG zoom-in/out
if (objectName == 'RootBackground') then
	local duration = 0.75;
	local scale = 3.0;

	if (playField:GetScale() == 1.0) then
		auxZoomPlayFieldIn(2.0, gameState.finalZoomInPos, duration);
	else
		auxZoomPlayFieldOut(duration);
	end
end
--]]
	        if (isWrongClick == true and playField:GetLevelScreen():IsTaskObject(objectName)) then
	            auxAttachInPlace(object, playField);
				object:ResetClippingRect();
				--// remove object from zoom-zone which contents it
				assert(gameState.activeZone.objects[objectName] ~= nil);
				gameState.activeZone.objects[objectName] = nil;

                playField:OnObjectFound(object);
                isWrongClick = false;
            end
        else
--			assert(gameState.activeZone ~= RootZoomZone and 
--				   gameState.locker:GetNReferences() > 1 and
--				   'Attempt to close root scene - you have clicked on an object which hasn`t been added to any zoom-zone');
            if (gameState.activeZone ~= RootZoomZone and gameState.locker:GetNReferences() > 1) then
                if (gameState.lockedObjects[gameState.activeZone.activeObject] == nil) then
                    SetZoneVisible(gameState.activeZone, false);
                end
            else
                Log('Lua: OnObjectMouseDown(\''..objectName..'\'): Was made click on object which hasn`t been attached to any zoom-zone');
            end
        end --// if (gameState.activeZone.HasObject(...
    end --// if (gameState.lockedObjects[...

	--// Tips - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	if (objectName == 'actZoneTortoiseShellPart' and gameState.shellPartOnPlace == false) then
	    playField:GetLevelScreen():ShowTip(GetTextString('LEVEL18_SHELLPART_TIP1'));
	elseif (objectName == 'actZonePortalSign' and gameState.portalSignOnPlace == false) then
	    playField:GetLevelScreen():ShowTip(GetTextString('LEVEL18_PORTALSIGN_TIP1'));
	elseif (objectName == 'actZoneBlueCrystal' and gameState.blueCrystalOnPlace == false) then
	    playField:GetLevelScreen():ShowTip(GetTextString('LEVEL18_BLUECRYSTAL_TIP1'));
	elseif (objectName == 'actZonePinion' and gameState.pinionOnPlace == false) then
	    playField:GetLevelScreen():ShowTip(GetTextString('LEVEL18_PINION_TIP1'));
	elseif (objectName == 'actZoneLever' and gameState.leverOnPlace == false) then
	    playField:GetLevelScreen():ShowTip(GetTextString('LEVEL18_LEVER_TIP1'));
	elseif (objectName == 'actZoneTeleportSphere' and gameState.teleportSphereOnPlace == false) then
	    playField:GetLevelScreen():ShowTip(GetTextString('LEVEL18_SPHERE_TIP1'));
	else
	    playField:GetLevelScreen():HideTip();
	end
	--//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    DefaultOnObjectClick(object, isWrongClick, not playField:GetLevelScreen():IsTipShown());
    DefaultOnObjectMouseEnter(object);
end

------------------------------------------------------------------------------
--
function OnObjectMouseUp(object)
end

------------------------------------------------------------------------------
--
function OnObjectFound(object)
    local objectName = object:GetName();
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	local objectMustBeHighlighted = DefaultOnObjectFound(object);
	return objectMustBeHighlighted;
end

------------------------------------------------------------------------------
--
function OnToolFound(tool)
end

------------------------------------------------------------------------------
--
function CanToolBeApplied(tool, object)
	local toolName = tool:GetName();
	local objName = object:GetName();
    local canToolBeApplied = true;
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	canToolBeApplied = DefaultCanToolBeApplied(tool, object);
	return canToolBeApplied;
end

------------------------------------------------------------------------------
--
function OnToolApply(tool, object)
	local toolName = tool:GetName();
	local objName = object:GetName();
    local toolApplied = false;

	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if (toolName == 'BlueCrystal' and objName == gameState.toolMap[toolName]) then
		gameState.blueCrystalOnPlace = true;
		toolApplied = true;
	end
	if (toolName == 'Lever' and objName == gameState.toolMap[toolName] and 
		gameState.shellPartOnPlace == true) then
		gameState.leverOnPlace = true;
		toolApplied = true;

		PlaySound('L18S14');
	end
	if (toolName == 'Pinion' and objName == gameState.toolMap[toolName]) then
		gameState.pinionOnPlace = true;
		toolApplied = true;
	end
	if (toolName == 'PortalSign' and objName == gameState.toolMap[toolName]) then
		gameState.portalSignOnPlace = true;
		toolApplied = true;
	end
	if (toolName == 'TeleportSphere' and objName == gameState.toolMap[toolName]) then
		gameState.teleportSphereOnPlace = true;
		toolApplied = true;
	end
	if (toolName == 'TortoiseShellPart' and objName == gameState.toolMap[toolName]) then
		gameState.shellPartOnPlace = true;
		toolApplied = true;

		PlaySound('L18S11');
	end
	if (not toolApplied) then
	    playField:GetLevelScreen():ShowTip(GetTextString('WRONG_ITEM_APPLIED_TIP1'),
										   GetTextString('WRONG_ITEM_APPLIED_TIP2'));
	end

    assert(gameState.activeZone ~= nil);
    if (gameState.activeZone == NearTeleportZoomZone and 
		(toolName == 'PortalSign' or toolName == 'TeleportSphere') and
		gameState.portalSignOnPlace == true and gameState.teleportSphereOnPlace == true and
		toolApplied == true) then

		PlaySound('L18S13');
		CloseAndBlockActiveZone();
    end
    if (gameState.activeZone == TortoiseStatueZoomZone and 
		(toolName == 'BlueCrystal' or toolName == 'Pinion') and
		gameState.blueCrystalOnPlace == true and gameState.pinionOnPlace == true and
		toolApplied == true) then

		PlaySound('L18S10', true);
		auxRotatePinions();
		CloseAndBlockActiveZone();
    end


	if (gameState.blueCrystalOnPlace == true and
		gameState.leverOnPlace == true and
		gameState.pinionOnPlace == true and
		gameState.portalSignOnPlace == true and
		gameState.teleportSphereOnPlace == true and
		gameState.shellPartOnPlace == true and
		gameState.allToolsApplied == false) then

		gameState.allToolsApplied = true;
		if (playField:GetLevelScreen():HasUncompletedTask() == true) then
		    playField:GetLevelScreen():ShowTip(GetTextString('HAVE_TO_FIND_ITEMS_MSG1'),
											   GetTextString('HAVE_TO_FIND_ITEMS_MSG2'));
		else
			auxTestLevelCompleteCondition();
		end
	end

	auxProcessToolObjectStateAnCursorType();
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    DefaultOnObjectMouseEnter(object);
	if (toolApplied == true) then
	    DeactivateActiveZoneDeactivatedGlow(object:GetName());
	end
	return toolApplied;
end

------------------------------------------------------------------------------
--
function OnObjectReachPanel(object)
    local objectName = object:GetName();
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	auxTestLevelCompleteCondition();
end

------------------------------------------------------------------------------
--
function OnButtonPress(zoneName)
    DefaultOnButtonPress(zoneName);
end

------------------------------------------------------------------------------
--
function OnMouseMove(prevMousePos, currentMousePos)
end

------------------------------------------------------------------------------
--
function OnSetTool(tool)
end

------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData()
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/background.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('RootBackground',anim,512,384,98,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/animalSkull.png',0,0,77,93,1,0)
	anim:SetHotSpot(38,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('animalSkull',anim,415,48,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/ape.png',0,0,116,129,1,0)
	anim:SetHotSpot(58,64)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('ape',anim,667,512,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/barrow.png',0,0,155,97,1,0)
	anim:SetHotSpot(77,48)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('barrow',anim,588,430,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/blackPearl.png',0,0,52,76,1,0)
	anim:SetHotSpot(26,38)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('blackPearl',anim,473,169,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/box.png',0,0,112,91,1,0)
	anim:SetHotSpot(56,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('box',anim,466,669,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/cake.png',0,0,81,74,1,0)
	anim:SetHotSpot(40,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('cake',anim,203,732,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/cheetah.png',0,0,76,92,1,0)
	anim:SetHotSpot(38,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('cheetah',anim,708,67,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/clock.png',0,0,79,70,1,0)
	anim:SetHotSpot(39,35)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('clock',anim,564,50,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/coconut.png',0,0,124,87,1,0)
	anim:SetHotSpot(62,43)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('coconut',anim,665,611,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/column.png',0,0,89,111,1,0)
	anim:SetHotSpot(44,55)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('column',anim,610,203,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/corn.png',0,0,104,70,1,0)
	anim:SetHotSpot(52,35)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('corn',anim,781,608,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/crown.png',0,0,63,59,1,0)
	anim:SetHotSpot(31,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('crown',anim,158,449,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/earring.png',0,0,65,109,1,0)
	anim:SetHotSpot(32,54)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('earring',anim,265,157,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/egg.png',0,0,68,75,1,0)
	anim:SetHotSpot(34,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('egg',anim,360,198,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/elephant.png',0,0,89,107,1,0)
	anim:SetHotSpot(44,53)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('elephant',anim,147,358,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/emerald.png',0,0,79,46,1,0)
	anim:SetHotSpot(39,23)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('emerald',anim,588,698,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/feather.png',0,0,162,74,1,0)
	anim:SetHotSpot(81,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('feather',anim,659,729,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/flowerpot.png',0,0,106,92,1,0)
	anim:SetHotSpot(53,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('flowerpot',anim,363,725,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/frog.png',0,0,123,58,1,0)
	anim:SetHotSpot(61,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('frog',anim,311,653,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/goose.png',0,0,72,73,1,0)
	anim:SetHotSpot(36,36)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('goose',anim,449,493,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/jug.png',0,0,90,117,1,0)
	anim:SetHotSpot(45,58)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('jug',anim,142,613,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/knife.png',0,0,87,96,1,0)
	anim:SetHotSpot(43,48)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('knife',anim,543,584,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/lantern.png',0,0,68,101,1,0)
	anim:SetHotSpot(34,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('lantern',anim,295,385,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/leaf.png',0,0,92,92,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('leaf',anim,146,18,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/lily.png',0,0,65,76,1,0)
	anim:SetHotSpot(32,38)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('lily',anim,379,112,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/mask.png',0,0,61,129,1,0)
	anim:SetHotSpot(30,64)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('mask',anim,993,67,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/mortar.png',0,0,95,124,1,0)
	anim:SetHotSpot(47,62)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('mortar',anim,390,570,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/mug.png',0,0,100,93,1,0)
	anim:SetHotSpot(50,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('mug',anim,383,453,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/mushroom.png',0,0,68,62,1,0)
	anim:SetHotSpot(34,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('mushroom',anim,718,317,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/parrot.png',0,0,100,95,1,0)
	anim:SetHotSpot(50,47)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('parrot',anim,851,88,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/pattern.png',0,0,77,53,1,0)
	anim:SetHotSpot(38,26)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('pattern',anim,871,711,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/pipe.png',0,0,112,60,1,0)
	anim:SetHotSpot(56,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('pipe',anim,340,492,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/pot.png',0,0,83,56,1,0)
	anim:SetHotSpot(41,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('pot',anim,302,439,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/ring.png',0,0,79,38,1,0)
	anim:SetHotSpot(39,19)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('ring',anim,562,723,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/seashell.png',0,0,63,60,1,0)
	anim:SetHotSpot(31,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('seashell',anim,215,253,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/snake.png',0,0,133,105,1,0)
	anim:SetHotSpot(66,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('snake',anim,957,189,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/sunflower.png',0,0,82,89,1,0)
	anim:SetHotSpot(41,44)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('sunflower',anim,168,142,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/tulip.png',0,0,64,77,1,0)
	anim:SetHotSpot(32,38)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('tulip',anim,997,587,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/vase.png',0,0,112,147,1,0)
	anim:SetHotSpot(56,73)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('vase',anim,951,702,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Misc/watermelon.png',0,0,90,71,1,0)
	anim:SetHotSpot(45,35)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('watermelon',anim,484,740,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/LayerOverCorn.png',0,0,131,64,1,0)
	anim:SetHotSpot(65,32)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('LayerOverCorn',anim,803,630,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/LayerOverElephant.png',0,0,117,78,1,0)
	anim:SetHotSpot(58,39)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('LayerOverElephant',anim,123,419,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/LayerOverKnife.png',0,0,101,58,1,0)
	anim:SetHotSpot(50,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('LayerOverKnife',anim,558,625,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/LayerOverWatermelon.png',0,0,57,60,1,0)
	anim:SetHotSpot(28,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('LayerOverWatermelon',anim,527,740,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/turtleShellOpened.png',0,0,239,256,1,0)
	anim:SetHotSpot(119,128)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('turtleShellOpened',anim,904,342,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/turtleShellClosed.png',0,0,273,230,1,0)
	anim:SetHotSpot(136,115)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('turtleShellClosed',anim,888,439,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/platform.png',0,0,104,62,1,0)
	anim:SetHotSpot(52,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('platform',anim,804,555,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/LayerOverBlueCrystal.png',0,0,80,80,1,0)
	anim:SetHotSpot(40,40)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('LayerOverBlueCrystal',anim,906,71,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Layers/waterfallAnimation.png',0,0,270,429,3,9)
	anim:SetHotSpot(135,214)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('waterfallAnimation',anim,813,212,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/BlueCrystal.png',0,0,50,108,1,0)
	anim:SetHotSpot(25,54)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('BlueCrystal',anim,911,37,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Lever.png',0,0,49,91,1,0)
	anim:SetHotSpot(24,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Lever',anim,300,53,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Lever_onPlace.png',0,0,47,80,1,0)
	anim:SetHotSpot(23,40)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Lever_onPlace',anim,795,525,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Pinion.png',0,0,100,50,1,0)
	anim:SetHotSpot(50,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pinion',anim,588,549,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/PortalSign.png',0,0,52,49,1,0)
	anim:SetHotSpot(26,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('PortalSign',anim,1003,739,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/PortalSign_onPlaceGen.png',0,0,47,48,1,0)
	anim:SetHotSpot(23,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('PortalSign_onPlaceGen',anim,483,221,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/TeleportSphere.png',0,0,51,53,1,0)
	anim:SetHotSpot(25,26)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('TeleportSphere',anim,139,549,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/TeleportSphere_onPlaceGen.png',0,0,20,20,1,0)
	anim:SetHotSpot(10,10)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('TeleportSphere_onPlaceGen',anim,463,293,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/TortoiseShellPart.png',0,0,100,80,1,0)
	anim:SetHotSpot(50,40)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('TortoiseShellPart',anim,772,689,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/TortoiseShellPart_onPlace.png',0,0,80,42,1,0)
	anim:SetHotSpot(40,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('TortoiseShellPart_onPlace',anim,923,372,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZoneTortoiseShellPart',anim,929,352,106,0,1,0.8)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZoneLever',anim,799,525,105,0,0.8,0.9)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZoneTeleport',anim,483,313,103,0,2,2)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZoneNearTeleport',anim,483,313,102,0,2,2)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Zones/NearTeleport/Layers/background.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('ZoomNearTeleportBackground',anim,547,306,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/PortalSign_onPlace.png',0,0,80,80,1,0)
	anim:SetHotSpot(40,40)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('PortalSign_onPlace',anim,552,158,204,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/TeleportSphere_onPlace.png',0,0,40,40,1,0)
	anim:SetHotSpot(20,20)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('TeleportSphere_onPlace',anim,512,277,204,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZonePortalSign',anim,553,153,205,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZoneTeleportSphere',anim,513,278,205,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZoneTortoiseStatue',anim,923,442,102,5,1.5,0.6)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Zones/TortoiseStatue/Layers/background.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('ZoomTortoiseStatueBackground',anim,652,422,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/BlueCrystal_onPlace.png',0,0,117,277,1,0)
	anim:SetHotSpot(58,138)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('BlueCrystal_onPlace',anim,844,406,203,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Pinion_onPlace.png',0,0,258,246,1,0)
	anim:SetHotSpot(129,123)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('Pinion_onPlace',anim,659,415,203,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Zones/TortoiseStatue/Layers/part1.png',0,0,134,94,1,0)
	anim:SetHotSpot(67,47)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('part1',anim,758,534,204,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Zones/TortoiseStatue/Layers/part2.png',0,0,137,95,1,0)
	anim:SetHotSpot(68,47)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('part2',anim,541,312,204,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Zones/TortoiseStatue/Layers/smallPinion1.png',0,0,104,104,1,0)
	anim:SetHotSpot(52,52)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('smallPinion1',anim,730,503,202,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Zones/TortoiseStatue/Layers/smallPinion2.png',0,0,102,102,1,0)
	anim:SetHotSpot(51,51)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('smallPinion2',anim,563,338,202,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Zones/TortoiseStatue/Layers/redCrystal.png',0,0,112,252,1,0)
	anim:SetHotSpot(56,126)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	play_field:CreateObject('redCrystal',anim,455,421,204,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZonePinion',anim,640,422,204,-45,2.09,1.7)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('actZoneBlueCrystal',anim,841,417,204,0,1.2,2)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Lever_ghost.png',0,0,60,90,1,0)
	anim:SetHotSpot(30,45)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Lever_ghost',anim,796,525,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/TortoiseShellPart_ghost.png',0,0,100,80,1,0)
	anim:SetHotSpot(50,40)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('TortoiseShellPart_ghost',anim,925,368,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/PortalSign_ghost.png',0,0,104,104,1,0)
	anim:SetHotSpot(52,52)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('PortalSign_ghost',anim,553,157,210,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/TeleportSphere_ghost.png',0,0,50,50,1,0)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('TeleportSphere_ghost',anim,512,277,210,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/BlueCrystal_ghost.png',0,0,140,300,1,0)
	anim:SetHotSpot(70,150)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('BlueCrystal_ghost',anim,844,407,210,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/18_AncientTeleport/Items/Pinion_ghost.png',0,0,300,300,1,0)
	anim:SetHotSpot(150,150)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pinion_ghost',anim,653,422,210,0,1,1)
end

function FreeData()
end
-- CLEAR_ON_SAVE_END
