function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/35_Prison_Corridor_Main.lua', 'quest')

	if HasGameState('ToolFound', '35_knife') then
		RegisterMonologObject('area_ho', 'C_35_AFTER_HO', true)
	else
		LinkScene('area_ho', 'CursorGlass', 'data/Scenes/35_Prison_Corridor_HO.lua', true)
	end

	LoadSound('35_Door_open', 'data/Sound/35_Prison_Koridor/Door_open.ogg')
	
	play_field:GetObject('Layer_Door_Opened'):SetOpacity(0.0);
    play_field:GetObject('Layer_Door_Opened_Back'):SetOpacity(0.0);
    play_field:GetObject('Layer_Door_Light'):SetOpacity(0.0);
    
	play_field:GetObject('Layer_Minigame_2'):SetOpacity(0.0);

	if HasGameState('MiniGameCompleted', '35_Manipulator') == false then
		LinkScene('area_mg', 'CursorGlass', 'data/Scenes/35_Manipulator.lua', false);		
	end
	
	if HasGameState('MiniGameCompleted', '35_Numbers_MG') == true then
		if(MiniGameCompleted) then
			MiniGameCompleted = false;
			play_field:GetObject('Layer_Door_Right_Opened'):ChangeOpacity(0.0, 1.0, 0.5);
			play_field:GetObject('Layer_Minigame_2'):ChangeOpacity(0.0, 1.0, 0.5);
			play_field:GetObject('Layer_Minigame'):SetVisible(true);
			MakeSoundEntity('35_Door_open'):Play(false);
		else
			play_field:GetObject('Layer_Minigame_2'):SetOpacity(1.0)
			play_field:GetObject('Layer_Door_Right_Opened'):SetOpacity(1.0)
		end	

		LinkScene('area_doll', 'CursorDoorUp', 'data/Scenes/38_Stairway.lua', false);	
	else
		LinkScene('area_doll', 'CursorGlass', 'data/Scenes/35_Numbers_MG.lua', false);
		play_field:GetObject('Layer_Door_Right_Opened'):SetOpacity(0.0)
	end
	
	play_field:GetObject('Layer_Minigame'):SetVisible(false);
	play_field:GetObject('Layer_Cloth'):SetVisible(false);
	
	if HasGameState('ToolApplied', '35_knife') then
		play_field:GetObject('Layer_Cloth'):SetVisible(true);
	end
	
	if HasGameState('ToolApplied', '37_gas_jet') then
		play_field:GetObject('Layer_Minigame'):SetVisible(true);
	end
	
	RegisterMonologObject('area_hell_system', 'C_35_DOOR_CLOSED');
	
	local on_key_apply = function()
	    OpenDoor(true);
	    MakeSoundEntity('35_Door_open'):Play(false);
	    UnregisterActiveObject('area_hell_system');
	    LinkScene('area_hell_system', 'CursorDoorUp', 'data/Scenes/36_Hell_System_Main.lua', false)
	end
	
	local on_load_when_key_applied = function()
	    OpenDoor(false);
	    UnregisterActiveObject('area_hell_system');
	    LinkScene('area_hell_system', 'CursorDoorUp', 'data/Scenes/36_Hell_System_Main.lua', false)
	end

	if HasGameState('ToolFound', '37_gas_jet') and
	   not HasGameState('TaskCompleted', '39_FreeBoy')
	then
		game_state.ignore_on_highlight['area_hell_system'] = true
	end
	
	RegisterToolApplyInfo('35_key', 'area_hell_system', nil, nil, on_key_apply, on_load_when_key_applied);
	
	if HasGameState('TaskCompleted', '39_FreeBoy') then
		game_state.ignore_on_highlight['area_doll'] = true
	end

	AddRatsComposition()
end

function OpenDoor(dynamically)

    if (dynamically)
    then
        play_field:GetObject('Layer_Door_Opened'):ChangeOpacity(0., 1., 0.2);
        play_field:GetObject('Layer_Door_Opened_Back'):ChangeOpacity(0., 1., 0.2);
        play_field:GetObject('Layer_Door_Light'):ChangeOpacity(0., 1., 0.2);
    else
        play_field:GetObject('Layer_Door_Opened'):SetOpacity(1.0);
        play_field:GetObject('Layer_Door_Opened_Back'):SetOpacity(1.0);
        play_field:GetObject('Layer_Door_Light'):SetOpacity(1.0);
    end
    
end

function AddRatsComposition()

    createComposition17_Theatre_Entrance_rat = function()
    
        local composition17_Theatre_Entrance_rat = CreateCompositionSequence();
        local compositionDuration = 3.5;
        composition17_Theatre_Entrance_rat:SetDuration(compositionDuration);
    
    
        -- Layer Rat_eating
        local element = BuildRatEatingComposition();
        element:SetName("Rat_eating");
        composition17_Theatre_Entrance_rat:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(composition17_Theatre_Entrance_rat);
        element:SetXY(932.217071533203, 647.324676513672);
    
        element:SetScaleX(0.37);
        element:SetScaleY(0.37);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 3.5);
    
    
        effector:Play();
    
    
        composition17_Theatre_Entrance_rat:Play();
    
        return composition17_Theatre_Entrance_rat;
    end
    
    local createCompositionRatRunning1 = function()
    
        local compositionRatRunning1 = CreateCompositionSequence();
        local compositionDuration = 3.5;
        compositionRatRunning1:SetDuration(compositionDuration);
        
        -- Layer Rat_running
        local element = BuildRatRunningComposition();
        element:SetName("Rat_running");
        compositionRatRunning1:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionRatRunning1);
        element:SetScaleX(-0.31);
        element:SetScaleY(0.31);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 5);
    
        effector:SetKey(_TRACK_X, 0, -120.031539916992);
        effector:SetKey(_TRACK_Y, 0, 627.450836181641);
        effector:SetKey(_TRACK_X, 2.41666666666667, 1125);
        effector:SetKey(_TRACK_Y, 2.41666666666667, 714);
    
        effector:Play();
        
        --compositionRatRunning1:Play();
        
        return compositionRatRunning1;
    end
    
    local composes = {};
    composes.ratRunning1 = createCompositionRatRunning1();
    --composes.ratRunning1:SetCyclic(true);
    composes.ratRunning1:SetZ(43);
    composes.ratRunning1:SetSpeed(0.8);
    composes.ratRunning1:AttachTo(play_field);
    composes.ratRunning1:SetDestroysOnEnd(false);
    composes.ratRunning1:SetEndAction("RatRunningEnded");
    RatRunningEnded(composes.ratRunning1);
    
    local compos = createComposition17_Theatre_Entrance_rat();
    compos:SetCyclic(true);
    compos:SetZ(45);
    compos:SetSpeed(0.8);
    compos:AttachTo(play_field);
    compos:SetCyclic(true);

end

function RatRunningEnded(compos)
    compos:PlayAt(math.random(5, 10));
end

function OnSceneFree(screen)
    DefaultOnSceneFree()
    FreeData(screen)
end

function OnUpdate(dt)
    DefaultOnUpdate(dt)
end

function OnAllItemsFound()
    DefaultOnAllItemsFound()
end

function OnLose()
    DefaultOnLose()
end

function OnExit()
    DefaultOnExit()
end

function OnClose()
    DefaultOnClose()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

function OnObjectMouseDown(object)
    local is_wrong_click = not DefaultOnObjectMouseDown(object)
    local obj_name = object:GetName()
    local pf = play_field

    DefaultOnObjectMouseDownProcessed(is_wrong_click);
end

function OnObjectMouseUp(object)
    DefaultOnObjectMouseUp(object)
end

function OnObjectFound(object)
    DefaultOnObjectFound(object)
end

function OnToolFound(tool)
    DefaultOnToolFound(tool)
end

function OnToolApply(tool, object)
    DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
    DefaultOnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
    DefaultOnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
    DefaultOnSetTool(tool)
end

function LevelLoaded(level)
end

function OnSceneDestroy(playfield)
    DefaultOnSceneDestroy(playfield)
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Solution.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Solution',anim,512,384,50,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_ho',anim,180,440,100,0,15,30)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_hell_system',anim,396,430,110,0,20,30)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_doll',anim,878,444,105,0,20,30)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/BG_Prison_Corridor.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Prison_Corridor',anim,511,383,40,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Door_Light.PNG',0,0,212,269,1,0)
	anim:SetHotSpot(106,134)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Door_Light',anim,306,456,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Door_Opened.PNG',0,0,124,220,1,0)
	anim:SetHotSpot(62,110)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Door_Opened',anim,405,451,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Door_Opened_Back.PNG',0,0,207,249,1,0)
	anim:SetHotSpot(103,124)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Door_Opened_Back',anim,342,464,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Door_Right_Close.PNG',0,0,208,270,1,0)
	anim:SetHotSpot(104,135)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Door_Right_Close',anim,897,443,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Door_Right_Opened.PNG',0,0,329,325,1,0)
	anim:SetHotSpot(164,162)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Door_Right_Opened',anim,836,460,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_mg',anim,68,459,101,0,10,25)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Minigame.PNG',0,0,66,69,1,0)
	anim:SetHotSpot(33,34)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Minigame',anim,900,439,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Cloth.PNG',0,0,66,69,1,0)
	anim:SetHotSpot(33,34)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Cloth',anim,900,438,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/35_Prison_Corridor/Zone_Main/Layers/Layer_Minigame.PNG',0,0,66,69,1,0)
	anim:SetHotSpot(33,34)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Minigame_2',anim,900,439,104,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
