local zoom_boat;
local zoom_funnel;
local zoom_faucet;

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/22_RiverPort_Deck2.lua', 'quest', 'data/Scenes/22_RiverPort_Deck1.lua')
    
    CreateAmbientComposition();
    CreateChaykaComposition();
    
    StopMusic("22_RiverPortInterNoiseDeck2", false)
    PlayAmbientMusic("22_RiverPortInterNoiseDeck2", true);
    
    play_field:GetObject('area_stateroom'):SetVisible(false);
    play_field:GetObject('Layer_open_door'):SetOpacity(0.);
    play_field:GetObject('Layer_kettle_small'):SetOpacity(0.);
    play_field:IgnoreOnTestPoint('Fill_water_anim');
    
    if not HasGameState('ToolApplied', '22_kettle_full') then
        play_field:GetObject('area_boat'):SetVisible(false);
    end
    
    LinkScene('area_stateroom',
              'CursorUpRight',
              'data/Scenes/23_Stateroom_Main.lua',
              false)
    
    zoom_boat = CreateZoomZone('area_boat',
                               'CloseZoneBoat',
                               'ZOOM_boat',             true,
                               'Layer_butterfly_nut',   true,
                               'area_butterfly_nut',    true);

    zoom_funnel = CreateZoomZone('area_funnel',
                                 'CloseZoneFunnel',
                                 'ZOOM_funnel',         true,
                                 'Layer_grating',       true,
                                 'Layer_gorilla',       true,
                                 'Nut_anim',            true,
                                 'area_monkey',         false,
                                 'Layer_nut',           false);
    
    zoom_faucet = CreateZoomZone('area_faucet',
                                 'CloseZoneFaucet',
                                 'ZOOM_faucet',         true,
                                 'Layer_faucet_cover',  true,
                                 'Layer_kettle',        false,
                                 'Layer_lever_open',    false,
                                 'area_kettle_place',   true,
                                 'Fill_water_anim',     false,
                                 'area_lever',          false);
    
    zoom_faucet.on_close = function()
        if zoom_faucet.IsObjectVisible('Layer_lever_open') then
            play_field:GetObject('Layer_lever_open'):DestroyChildren();
            play_field:GetObject('Layer_lever_open'):SetOpacity(1);
        end
    end
    
    play_field:GetObject('Fill_water_anim'):GetAnimation():SetMode(HGEANIM_FWD + HGEANIM_NOLOOP);
    play_field:GetObject('Fill_water_anim'):GetAnimation():Stop();
    
    play_field:GetObject('Layer_nut'):SetClipping(512-320, 384-240, 640, 480);
    
    zoom_funnel.on_open = function()
        if game_state.nut_animating
        then
            game_state.nut_animating = false;
            zoom_funnel.SetObjectVisible('Layer_grating', false, ZOOM_ZONE_APPEARING_TIME);
            zoom_funnel.SetObjectVisible('area_monkey',   true);
            
        elseif game_state.nut_falling
        then
            game_state.nut_falling = false
            zoom_funnel.SetObjectVisible('Layer_nut',     false, ZOOM_ZONE_APPEARING_TIME);
            zoom_funnel.SetObjectVisible('Layer_grating', false, ZOOM_ZONE_APPEARING_TIME);
            zoom_funnel.SetObjectVisible('area_monkey',   true);
        end
    end
    
    play_field:GetObject('Nut_anim'):GetAnimation():SetMode(HGEANIM_FWD + HGEANIM_NOLOOP);
    play_field:GetObject('Nut_anim'):GetAnimation():Stop();
    
    RegisterToolFindInfo('22_butterfly_nut', 'area_butterfly_nut',  function(tool_name)
                                                                        zoom_boat.Disable();
                                                                    end,
                                                                    function(tool_name)
                                                                        zoom_boat.Disable();
                                                                    end);
    
    RegisterToolApplyInfo('23_wrench', 'Nut_anim', nil, nil,        function(tool_name)
                                                                        game_state.nut_animating = true;
                                                                        
                                                                        local nut_anim = play_field:GetObject('Nut_anim'):GetAnimation();
                                                                        
                                                                        nut_anim:Play();
                                                                        play_field:TimerDoString("OnNutTurnOff()", GetAnimationLength(nut_anim))
                                                                        
                                                                        PlaySound('22_WrenchApply');
                                                                    end,
                                                                    function(tool_name)
                                                                        zoom_funnel.SetObjectVisible('Nut_anim',      false);
                                                                        zoom_funnel.SetObjectVisible('Layer_grating', false);
                                                                    end,
                                                                    function()
                                                                        ShowMonolog('C_22_WRENCH_APPLY_HINT', 'C_22_WRENCH_APPLY_HINT');
                                                                    end);
    
    RegisterToolFindInfo('23_monkey', 'area_monkey',                function(tool_name)
                                                                        zoom_funnel.Disable();
                                                                    end,
                                                                    function(tool_name)
                                                                        zoom_funnel.Disable();
                                                                    end);
    
    RegisterActiveObject('area_door',                               function(obj_name)
                                                                        play_field:GetObject(obj_name):SetVisible(false);
                                                                        play_field:GetObject('area_stateroom'):SetVisible(true);
                                                                        
                                                                        play_field:GetObject('Layer_open_door'):ChangeOpacity(0, 1, OPEN_DOOR_TIME);
                                                                        
                                                                        PlaySound('22_OpenDoor');
                                                                    end,
                                                                    function(obj_name)
                                                                        play_field:GetObject(obj_name):SetVisible(false);
                                                                        play_field:GetObject('area_stateroom'):SetVisible(true);
                                                                        
                                                                        play_field:GetObject('Layer_open_door'):SetOpacity(1.);
                                                                    end);
    
    RegisterToolApplyInfo('21_kettle', 'area_kettle_place', nil, nil,   function(tool_name)
                                                                            play_field:GetObject('area_kettle_place'):SetVisible(false);
                                                                            
                                                                            zoom_faucet.SetObjectVisible('Layer_kettle', true);
                                                                            zoom_faucet.SetObjectVisible('area_lever',   true);
                                                                            play_field:GetObject('Layer_kettle_small'):ChangeOpacity(0., 1., 0.1);
                                                                            
                                                                            PlaySound('22_KettlePlaced');
                                                                        end,
                                                                        function(tool_name)
                                                                            play_field:GetObject('area_kettle_place'):SetVisible(false);
                                                                            
                                                                            zoom_faucet.SetObjectVisible('Layer_kettle', true);
                                                                            zoom_faucet.SetObjectVisible('area_lever',   true);
                                                                            
                                                                            play_field:GetObject('Layer_kettle_small'):SetOpacity(1);
                                                                        end,
                                                                        function()
                                                                            ShowMonolog('C_22_HINT_KETTLE_APPLY', 'C_22_HINT_KETTLE_APPLY')
                                                                        end);
    
    RegisterActiveObject('area_lever',                                  function(obj_name)
                                                                            zoom_faucet.SetObjectVisible('area_lever', false);
                                                                            zoom_faucet.SetObjectVisible('Layer_lever_open', true, 0.5);
                                                                            zoom_faucet.SetObjectVisible('Fill_water_anim',  true);
                                                                            
                                                                            local anim = play_field:GetObject('Fill_water_anim'):GetAnimation();
                                                                            anim:Play();
                                                                            PlaySound('22_Effluent');
                                                                            
                                                                            play_field:TimerDoString("RegisterKettleFull();", GetAnimationLength(anim));
                                                                        end,
                                                                        function(obj_name)
                                                                            zoom_faucet.SetObjectVisible('area_lever', false);
                                                                            zoom_faucet.SetObjectVisible('Layer_lever_open', true);
                                                                            zoom_faucet.SetObjectVisible('Fill_water_anim',  true);
                                                                            
                                                                            local anim = play_field:GetObject('Fill_water_anim'):GetAnimation();
                                                                            anim:SetFrame(anim:GetFrames() - 1);
                                                                            
                                                                            RegisterKettleFull();
                                                                        end);
end

function RegisterKettleFull()
    RegisterToolFindInfo('22_kettle_full', 'Layer_kettle',  function(tool_name)
                                                                zoom_faucet.Disable();
                                                                
                                                                play_field:GetObject('Layer_kettle_small'):ChangeOpacity(1., 0., 0.1);
                                                            end,
                                                            function(tool_name)
                                                                zoom_faucet.Disable();
                                                                
                                                                play_field:GetObject('Layer_kettle_small'):SetOpacity(0.);
                                                            end);
end

function OnNutTurnOff()
    if not game_state.nut_animating then
        return;
    end
    
    game_state.nut_animating = false;
    game_state.nut_falling   = true;
    
    zoom_funnel.SetObjectVisible('Nut_anim', false);
    zoom_funnel.SetObjectVisible('Layer_nut', true);
    
    local nut = play_field:GetObject('Layer_nut');
    local anim_time = 0.5;
    
    local eff = CreateAnimationEffector();
    eff:AttachTo(nut);
    eff:SetMode(_ANIM_FWD + _ANIM_NOLOOP);
    eff:SetKey(_TRACK_Y, 0, nut:GetY());
    eff:SetKey(_TRACK_Y, anim_time, 624 + nut:GetAnimation():GetHeight());
    eff:Play();
    
    play_field:TimerDoString("OnNutFallen()", anim_time);
end

function OnNutFallen()
    if not game_state.nut_falling then
        return;
    end
    
    game_state.nut_falling = false;
    
    zoom_funnel.SetObjectVisible('Layer_nut',     false);
    zoom_funnel.SetObjectVisible('Layer_grating', false, 1);
    zoom_funnel.SetObjectVisible('area_monkey',   true);
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

function CreateChaykaComposition()
    createCompositionChayka_cycle = function()
    
        local compositionChayka_cycle = CreateCompositionSequence();
        local compositionDuration = 0.70833333333333;
        compositionChayka_cycle:SetDuration(compositionDuration);
        compositionChayka_cycle:SetCyclic(true);
    
        -- Layer Layer_1
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/ch_5.png");
        element:SetName("Layer_1");
        compositionChayka_cycle:AddElement(element);
        element:SetHotSpot(36.5, 78.5);
        compositionChayka_cycle:RegisterParentInfo("Layer_1", "Layer_3");
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 60);
        effector:SetKey(_TRACK_X, 0, 168.5);
        effector:SetKey(_TRACK_Y, 0, -22.5);
        effector:SetKey(_TRACK_X, 0.33333333333333, 159.5);
        effector:SetKey(_TRACK_Y, 0.33333333333333, 14.5);
        effector:SetKey(_TRACK_X, 0.5, 169.5);
        effector:SetKey(_TRACK_Y, 0.5, -7.5);
        effector:SetKey(_TRACK_X, 0.66666666666667, 169.5);
        effector:SetKey(_TRACK_Y, 0.66666666666667, -23.5);
        effector:SetKey(_TRACK_SX, 0, 1);
        effector:SetKey(_TRACK_SY, 0, 0.55414012738854);
        effector:SetKey(_TRACK_SX, 0.16666666666667, 1);
        effector:SetKey(_TRACK_SY, 0.16666666666667, 1.1656050955414);
        effector:SetKey(_TRACK_SX, 0.5, 0.84561403508772);
        effector:SetKey(_TRACK_SY, 0.5, -0.6687898089172);
        effector:SetKey(_TRACK_SX, 0.66666666666667, 1);
        effector:SetKey(_TRACK_SY, 0.66666666666667, 0.55414012738854);
    
        effector:Play();
    
    
        -- Layer Layer_2
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/ch_4.png");
        element:SetName("Layer_2");
        compositionChayka_cycle:AddElement(element);
        element:SetHotSpot(86.5, 69);
        compositionChayka_cycle:RegisterParentInfo("Layer_2", "Layer_3");
        element:SetXY(149, 20.5);
    
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 60);
    
        effector:SetKey(_TRACK_SX, 0, 1);
        effector:SetKey(_TRACK_SY, 0, 1);
        effector:SetKey(_TRACK_SX, 0.33333333333333, 1);
        effector:SetKey(_TRACK_SY, 0.33333333333333, 0.20289855072464);
        effector:SetKey(_TRACK_SX, 0.66666666666667, 1);
        effector:SetKey(_TRACK_SY, 0.66666666666667, 1);
        effector:SetKey(_TRACK_A, 0, 0);
        effector:SetKey(_TRACK_A, 0.33333333333333, -0.07841033864904);
        effector:SetKey(_TRACK_A, 0.66666666666667, 0);
    
        effector:Play();
    
    
        -- Layer Layer_3
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/ch_3.png");
        element:SetName("Layer_3");
        compositionChayka_cycle:AddElement(element);
        element:SetHotSpot(120.5, 33);
        element:SetParentElement(compositionChayka_cycle);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 60);
    
        effector:SetKey(_TRACK_X, 0, 388.5);
        effector:SetKey(_TRACK_Y, 0, 470.5);
        effector:SetKey(_TRACK_X, 0.5, 388.5);
        effector:SetKey(_TRACK_Y, 0.5, 466.5);
        effector:SetKey(_TRACK_X, 0.66666666666667, 388.5);
        effector:SetKey(_TRACK_Y, 0.66666666666667, 470.5);
        effector:SetKey(_TRACK_A, 0, 0);
        effector:SetKey(_TRACK_A, 0.125, 0.02641463678402);
        effector:SetKey(_TRACK_A, 0.5, -0.03557266710542);
        effector:SetKey(_TRACK_A, 0.66666666666667, 0);
    
        effector:Play();
    
    
        -- Layer Layer_4
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/ch_2.png");
        element:SetName("Layer_4");
        compositionChayka_cycle:AddElement(element);
        element:SetHotSpot(125.5, 86.5);
        compositionChayka_cycle:RegisterParentInfo("Layer_4", "Layer_3");
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 60);
    
        effector:SetKey(_TRACK_X, 0, 155.5);
        effector:SetKey(_TRACK_Y, 0, 10.5);
        effector:SetKey(_TRACK_X, 0.33333333333333, 155.5);
        effector:SetKey(_TRACK_Y, 0.33333333333333, 14.5);
        effector:SetKey(_TRACK_X, 0.66666666666667, 155.5);
        effector:SetKey(_TRACK_Y, 0.66666666666667, 10.5);
        effector:SetKey(_TRACK_SX, 0, 1);
        effector:SetKey(_TRACK_SY, 0, 1);
        effector:SetKey(_TRACK_SX, 0.33333333333333, 1);
        effector:SetKey(_TRACK_SY, 0.33333333333333, 0.28323699421965);
        effector:SetKey(_TRACK_SX, 0.66666666666667, 1);
        effector:SetKey(_TRACK_SY, 0.66666666666667, 1);
    
        effector:Play();
    
    
        -- Layer Layer_5
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/ch_1.png");
        element:SetName("Layer_5");
        compositionChayka_cycle:AddElement(element);
        element:SetHotSpot(165.5, 79.5);
        compositionChayka_cycle:RegisterParentInfo("Layer_5", "Layer_3");
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 60);
    
        effector:SetKey(_TRACK_X, 0, 112.5);
        effector:SetKey(_TRACK_Y, 0, -69.5);
        effector:SetKey(_TRACK_X, 0.33333333333333, 112.5);
        effector:SetKey(_TRACK_Y, 0.33333333333333, -8.5);
        effector:SetKey(_TRACK_X, 0.5, 108.5);
        effector:SetKey(_TRACK_Y, 0.5, -37.5);
        effector:SetKey(_TRACK_X, 0.66666666666667, 112.5);
        effector:SetKey(_TRACK_Y, 0.66666666666667, -69.5);
        effector:SetKey(_TRACK_SX, 0, 1);
        effector:SetKey(_TRACK_SY, 0, 0.58490566037736);
        effector:SetKey(_TRACK_SX, 0.16666666666667, 1);
        effector:SetKey(_TRACK_SY, 0.16666666666667, 1.21383647798742);
        effector:SetKey(_TRACK_SX, 0.5, 1);
        effector:SetKey(_TRACK_SY, 0.5, -0.73584905660377);
        effector:SetKey(_TRACK_SX, 0.66666666666667, 1);
        effector:SetKey(_TRACK_SY, 0.66666666666667, 0.58490566037736);
    
        effector:Play();
    
        compositionChayka_cycle:Play();
    
        return compositionChayka_cycle;
    end
    
    local compos = CreateCompositionSequence();
    local composDuration = 3.92 * 2.5;
    compos:SetDuration(composDuration);
    compos:SetCyclic(true);
    compos:AttachTo(play_field);
    compos:SetZ(102);
    
    -- Layer Layer_1
    local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/mask2.png");
    element:SetName("Layer_1");
    compos:AddElement(element);
    element:SetHotSpot(7.5, 56);
    element:SetParentElement(compositionPaluba2);
    element:SetXY(255.911041259766, 55.5338134765625);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);


    -- Layer Layer_2
    local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/mask.jpg");
    element:SetName("Layer_2");
    compos:AddElement(element);
    element:SetHotSpot(60, 40);
    element:SetParentElement(compositionPaluba2);
    element:SetXY(661, 40);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    -- Layer Layer_16
    local element = createCompositionChayka_cycle();
    element:SetName("Layer_16");
    compos:AddElement(element);
    element:SetHotSpot(417, 453);
    element:SetParentElement(compositionPaluba2);
    element:SetScaleX(-0.12905700963721);
    element:SetScaleY(0.12333333333333);
    element:SetAngle(-0.33705436026479);
    element:SetOpacity(1);

    effector = element:GetEffector();
    --effector:SetLifeTime(0, 60);
    effector:SetKey(_TRACK_X, 0, 1062.9903717041);
    effector:SetKey(_TRACK_Y, 0, 19.0807189941406);
    effector:SetKey(_TRACK_X, 3.4166796875, -24.2897644042969);
    effector:SetKey(_TRACK_Y, 3.4166796875, 82.3130950927734);
    effector:Play();
    
    compos:Play();
    return compos;
end

function CreateAmbientComposition()
    
    createCompositionPaluba2 = function()
        local compositionPaluba2 = CreateCompositionSequence();
        local compositionDuration = 3.92;
        compositionPaluba2:SetDuration(compositionDuration);
        compositionPaluba2:SetCyclic(true);
        compositionPaluba2:AttachTo(play_field);
        compositionPaluba2:SetZ(101);
    
    
        -- Layer Layer_3
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/sea3_1.png");
        element:SetName("Layer_3");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(60.5, 49);
        element:SetParentElement(compositionPaluba2);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 2);
    
        effector:SetKey(_TRACK_X, 0, 266.476867675781);
        effector:SetKey(_TRACK_Y, 0, 313.29284134375);
        effector:SetKey(_TRACK_X, 1.96, 266.476867675781);
        effector:SetKey(_TRACK_Y, 1.96, 317.839859008789);
        effector:SetKey(_TRACK_O, 0, 1);
        effector:SetKey(_TRACK_O, 1.96, 0);
    
        effector:Play();
    
    
        -- Layer Layer_4
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/sea3_1.png");
        element:SetName("Layer_4");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(60.5, 49);
        element:SetParentElement(compositionPaluba2);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(1.92, 5.84);
    
        effector:SetKey(_TRACK_X, 1.92, 266.476867675781);
        effector:SetKey(_TRACK_Y, 1.92, 308.839859008789);
        effector:SetKey(_TRACK_X, 3.84, 266.476867675781);
        effector:SetKey(_TRACK_Y, 3.84, 313.29284134375);
        effector:SetKey(_TRACK_X, 5.8, 266.476867675781);
        effector:SetKey(_TRACK_Y, 5.8, 317.839859008789);
        effector:SetKey(_TRACK_O, 1.92, 0);
        effector:SetKey(_TRACK_O, 3.84, 1);
        effector:SetKey(_TRACK_O, 5.8, 0);
    
        effector:Play();
    
    
        -- Layer Layer_5
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/sea3_1.png");
        element:SetName("Layer_5");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(60.5, 49);
        element:SetParentElement(compositionPaluba2);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 3.92);
    
        effector:SetKey(_TRACK_X, 0, 266.476867675781);
        effector:SetKey(_TRACK_Y, 0, 308.839859008789);
        effector:SetKey(_TRACK_X, 1.92, 266.476867675781);
        effector:SetKey(_TRACK_Y, 1.92, 313.29284134375);
        effector:SetKey(_TRACK_X, 3.88, 266.476867675781);
        effector:SetKey(_TRACK_Y, 3.88, 317.839859008789);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 1.92, 1);
        effector:SetKey(_TRACK_O, 3.88, 0);
    
        effector:Play();
    
    
        -- Layer Layer_6
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/sea3.png");
        element:SetName("Layer_6");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(75.5, 168.5);
        element:SetParentElement(compositionPaluba2);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(1.92, 5.84);
    
        effector:SetKey(_TRACK_X, 1.92, 65.5943145751953);
        effector:SetKey(_TRACK_Y, 1.92, 605.380783081055);
        effector:SetKey(_TRACK_X, 5.8, 75.2277679443359);
        effector:SetKey(_TRACK_Y, 5.8, 629.480422973633);
        effector:SetKey(_TRACK_O, 1.92, 0);
        effector:SetKey(_TRACK_O, 3.88, 1);
        effector:SetKey(_TRACK_O, 5.8, 0);
    
        effector:Play();
    
    
        -- Layer Layer_7
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/sea3.png");
        element:SetName("Layer_7");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(75.5, 168.5);
        element:SetParentElement(compositionPaluba2);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 1.96);
    
        effector:SetKey(_TRACK_X, 0, 70.4613682023966);
        effector:SetKey(_TRACK_Y, 0, 617.55650400468);
        effector:SetKey(_TRACK_X, 1.92, 75.2277679443359);
        effector:SetKey(_TRACK_Y, 1.92, 629.480422973633);
        effector:SetKey(_TRACK_O, 0, 1);
        effector:SetKey(_TRACK_O, 1.92, 0);
    
        effector:Play();
    
    
        -- Layer Layer_8
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/sea3.png");
        element:SetName("Layer_8");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(75.5, 168.5);
        element:SetParentElement(compositionPaluba2);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 3.92);
    
        effector:SetKey(_TRACK_X, 0, 65.5943145751953);
        effector:SetKey(_TRACK_Y, 0, 605.380783081055);
        effector:SetKey(_TRACK_X, 3.88, 75.2277679443359);
        effector:SetKey(_TRACK_Y, 3.88, 629.480422973633);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 1.96, 1);
        effector:SetKey(_TRACK_O, 3.88, 0);
    
        effector:Play();
    
    
        -- Layer Layer_9
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/sea3.png");
        element:SetName("Layer_9");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(75.5, 168.5);
        element:SetParentElement(compositionPaluba2);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 3.92);
    
        effector:SetKey(_TRACK_X, 0, 65.5943145751953);
        effector:SetKey(_TRACK_Y, 0, 605.380783081055);
        effector:SetKey(_TRACK_X, 3.88, 75.2277679443359);
        effector:SetKey(_TRACK_Y, 3.88, 629.480422973633);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 1.96, 1);
        effector:SetKey(_TRACK_O, 3.88, 0);
    
        effector:Play();
    
    
        -- Layer Layer_10
        local element = createCompositionVolnapngComp1();
        element:SetName("Layer_10");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionPaluba2);
        element:SetXY(809.795227050781, 347.066434003548);
    
        element:SetScaleX(0.34130155451967);
        element:SetScaleY(0.34130155451967);
        element:SetAngle(-0.04301376180723);
        element:SetOpacity(0.63);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0.225, 2.18333333333333);
    
    
        effector:Play();
    
    
        -- Layer Layer_11
        local element = createCompositionVolnapngComp1();
        element:SetName("Layer_11");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionPaluba2);
        element:SetXY(257.709823608398, 296.504162885384);
    
        element:SetScaleX(0.34130155451967);
        element:SetScaleY(0.34130155451967);
        element:SetAngle(-0.04301376180723);
        element:SetOpacity(0.63);
    
        effector = element:GetEffector();
        effector:SetLifeTime(1.305, 3.26333333333333);
    
    
        effector:Play();
    
    
        -- Layer Layer_12
        local element = createCompositionVolnapngComp1();
        element:SetName("Layer_12");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionPaluba2);
        element:SetXY(362.934020996094, 349.799542524056);
    
        element:SetScaleX(0.34130155451967);
        element:SetScaleY(0.34130155451967);
        element:SetAngle(-0.04301376180723);
        element:SetOpacity(0.63);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0.505, 2.46333333333333);
    
    
        effector:Play();
    
    
        -- Layer Layer_13
        local element = createCompositionVolnapngComp1();
        element:SetName("Layer_13");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionPaluba2);
        element:SetXY(300.072814941406, 311.536191083626);
    
        element:SetScaleX(0.34130155451967);
        element:SetScaleY(0.34130155451967);
        element:SetAngle(-0.04301376180723);
        element:SetOpacity(0.63);
    
        effector = element:GetEffector();
        effector:SetLifeTime(1.585, 3.54333333333333);
    
    
        effector:Play();
    
    
        -- Layer Layer_14
        local element = createCompositionVolnapngComp1();
        element:SetName("Layer_14");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionPaluba2);
        element:SetXY(157.951812744141, 310.169644452767);
    
        element:SetScaleX(0.30172626486491);
        element:SetScaleY(0.30172626486491);
        element:SetAngle(-0.04301376180723);
        element:SetOpacity(0.63);
    
        effector = element:GetEffector();
        effector:SetLifeTime(1.985, 3.94333333333333);
    
    
        effector:Play();
    
    
        -- Layer Layer_15
        local element = createCompositionSplash();
        element:SetName("Layer_15");
        compositionPaluba2:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionPaluba2);
        element:SetXY(160.28825378418, 240.569396972656);
    
        element:SetScaleX(0.20126984128669);
        element:SetScaleY(0.5504499279688);
        element:SetAngle(1.76611329320541);
        element:SetOpacity(0.51);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0.98166666666667, 2.94);
        effector:Play();
    
        compositionPaluba2:Play();
    
        return compositionPaluba2;
    end
    
    createCompositionSplash = function()
    
        local compositionSplash = CreateCompositionSequence();
        local compositionDuration = 3.91666666666667;
        compositionSplash:SetDuration(compositionDuration);
    
    
        -- Layer Layer_1
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/splash.png");
        element:SetName("Layer_1");
        compositionSplash:AddElement(element);
        element:SetHotSpot(61, 49);
        element:SetParentElement(compositionSplash);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0.60425701185287);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 60);
    
        effector:SetKey(_TRACK_X, 0, 826);
        effector:SetKey(_TRACK_Y, 0, 478);
        effector:SetKey(_TRACK_X, 1.91666666666667, 852);
        effector:SetKey(_TRACK_Y, 1.91666666666667, 471);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 1.04166666666667, 1);
        effector:SetKey(_TRACK_O, 1.91666666666667, 0);
    
        effector:Play();
    
        compositionSplash:Play();
    
        return compositionSplash;
    end
    
    createCompositionVolnapngComp1 = function()
    
        local compositionVolnapngComp1 = CreateCompositionSequence();
        local compositionDuration = 3.95833333333333;
        compositionVolnapngComp1:SetDuration(compositionDuration);
    
    
        -- Layer Layer_1
        local element = CreateCompositionElement("data/Texture/Scenes/22_RiverPort/Zone_deck2/Animations/Ambient/volna.png");
        element:SetName("Layer_1");
        compositionVolnapngComp1:AddElement(element);
        element:SetHotSpot(103.5, -1);
        element:SetParentElement(compositionVolnapngComp1);
        element:SetAngle(0.06294875518289);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 60);
    
        effector:SetKey(_TRACK_X, 0, 332);
        effector:SetKey(_TRACK_Y, 0, 304.739549694588);
        effector:SetKey(_TRACK_X, 1.91666666666667, 314.5);
        effector:SetKey(_TRACK_Y, 1.91666666666667, 312.239549694588);
        effector:SetKey(_TRACK_SX, 0, 0.51123276172277);
        effector:SetKey(_TRACK_SY, 0, 0.49614960528354);
        effector:SetKey(_TRACK_SX, 1.91666666666667, 0.55901029017331);
        effector:SetKey(_TRACK_SY, 1.91666666666667, 0.586120091993);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 0.79166666666667, 1);
        effector:SetKey(_TRACK_O, 1.875, 0);
    
        effector:Play();
    
        compositionVolnapngComp1:Play();
    
        return compositionVolnapngComp1;
    end
    
    return createCompositionPaluba2();
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/22_RiverPort/Zone_deck2/Layers/background.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('background',anim,512,384,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_boat',anim,400,554,103,0,2.5,1.2)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_boat/ZOOM_boat.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_boat',anim,512,384,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_boat/Layer_butterfly_nut.png',0,0,75,48,1,0)
	anim:SetHotSpot(37,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_butterfly_nut',anim,482,487,151,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_butterfly_nut',anim,479,480,152,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_funnel/Layers/ZOOM_funnel.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_funnel',anim,512,384,160,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_funnel/Layers/Layer_grating.png',0,0,417,366,1,0)
	anim:SetHotSpot(208,183)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Layer_grating',anim,498,364,163,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_funnel/Layers/Layer_gorilla.png',0,0,99,66,1,0)
	anim:SetHotSpot(49,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_gorilla',anim,531,471,162,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_funnel/Animations/Nut_anim.png',0,0,50,50,10,10)
	anim:SetHotSpot(25,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Nut_anim',anim,466,212,164,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_funnel/Layers/Layer_nut.png',0,0,41,43,1,0)
	anim:SetHotSpot(20,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_nut',anim,462,213,165,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_funnel',anim,766,278,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_monkey',anim,533,469,163,0,0.8,0.8)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Layers/Layer_open_door.jpg',0,0,50,97,1,0)
	anim:SetHotSpot(25,48)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_open_door',anim,382,425,103,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_door',anim,383,430,104,0,8,13)
	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_stateroom',anim,383,430,104,0,8,13)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_faucet/ZOOM_faucet.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_faucet',anim,512,384,170,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_faucet/Layer_faucet_cover.png',0,0,33,48,1,0)
	anim:SetHotSpot(16,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_faucet_cover',anim,542,307,174,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_faucet/Layer_kettle.png',0,0,381,411,1,0)
	anim:SetHotSpot(190,205)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_kettle',anim,528,382,173,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_faucet/Layer_lever_open.jpg',0,0,212,137,1,0)
	anim:SetHotSpot(106,68)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_lever_open',anim,527,284,171,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_faucet',anim,917,568,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_kettle_place',anim,562,421,175,0,3,3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_lever',anim,565,267,176,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Zoom_faucet/Fill_water_anim.png',0,0,159,79,72,12)
	anim:SetHotSpot(79,39)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Fill_water_anim',anim,571,349,174,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/22_RiverPort/Zone_deck2/Layers/Layer_kettle_small.png',0,0,39,41,1,0)
	anim:SetHotSpot(19,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_kettle_small',anim,904,608,103,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
