function add_fibrillation_effector_lamp(obj, delay)
	local duration = 2.20

	eff= CreateAnimationEffector()
	eff:AttachTo(obj)
	eff:SetMode(_ANIM_LOOP)

    local dopacity = -0.55

	eff:SetKey(_TRACK_O, 0.0 + delay, obj:GetOpacity() * 1.0 + dopacity)
	eff:SetKey(_TRACK_O, duration *1.0/4.0 + delay, obj:GetOpacity() * 0.95 + dopacity)
	eff:SetKey(_TRACK_O, duration *2.0/4.0 + delay, obj:GetOpacity() * 1.0 + dopacity)
	eff:SetKey(_TRACK_O, duration *3.0/4.0 + delay, obj:GetOpacity() * 0.89 + dopacity)
	eff:SetKey(_TRACK_O, duration *4.0/4.0 + delay, obj:GetOpacity() * 1.0 + dopacity)
	eff:Play()
end

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/06_Hotel_Street_Evening_Main.lua', 'quest')
    AddSpiderMan(screen)

	RegisterQuestObjects('area_cemetry', 'area_Lock', 'area_library', 'area_museum_street')
	if not HasGameState('ToolFound', '07_mask') then
		game_state.ignore_on_highlight['area_museum_street'] = true
	else
		game_state.ignore_on_highlight['area_cemetry'] = true
	end

	game_screen = screen;
	
    LinkScene('area_metrodotel', 'CursorDoorUp', 'data/Scenes/05_Metrodotel_Hall_Main.lua', false)
    LinkScene('area_cemetry', 'CursorDoorRightUp', 'data/Scenes/07_Cemetry_Main.lua', false)
    LinkScene('area_library', 'CursorDoorUp', 'data/Scenes/08_Library_Main.lua', false)
    LinkScene('area_museum_street', 'CursorDoorLeftUp', 'data/Scenes/09_Museum_Street_Main.lua', false)
	LinkScene('area_Lock', 'CursorGlass', 'data/Scenes/06_Masks_lock.lua', false)

	play_field:IgnoreOnTestPoint('Layer_Light_L_small')
	play_field:IgnoreOnTestPoint('Layer_Light_R_small')
	play_field:IgnoreOnTestPoint('open_door_sss')

	game_screen:GetObject('open_door_sss'):SetOpacity(0.5);
	
	if HasGameState('MiniGameCompleted', 'Masks_Lock') then
		if(MiniGame == true) then
			game_screen:GetObject('open_door'):SetVisible(true);
			game_screen:GetObject('open_door'):SetOpacity(0.0);
			TimerDoString("game_screen:GetObject('open_door'):ChangeOpacity(0.0, 1.0, 0.8)" .. 
                          "PlaySound(\"Door_opening\");", 0.4, game_screen:GetTimer())
                          
			game_screen:GetObject('open_door_sss'):SetVisible(true);
			game_screen:GetObject('open_door_sss'):SetOpacity(0.0);
			TimerDoString("game_screen:GetObject('open_door_sss'):ChangeOpacity(0.0, 0.5, 0.8)", 0.4, game_screen:GetTimer())

			MiniGame = nil;
		else
			game_screen:GetObject('open_door_sss'):SetVisible(true);
			game_screen:GetObject('open_door'):SetVisible(true)
		end
		game_screen:GetObject('area_Lock'):SetVisible(false);
	else
		game_screen:GetObject('open_door_sss'):SetVisible(false);
		game_screen:GetObject('area_library'):SetVisible(false);
		game_screen:GetObject('open_door'):SetVisible(false);
	end

    local hotel_move_condition = function()
        return false
    end
    local hotel_deny_comics = function()
        local replic_index = math.random(1, 2)
        ShowMonolog('06_HotelDeny', 'C_06_HOTEL_DENY'..math.random(1, 3))
    end
    LinkScene('area_hotel', 'CursorDoorLeft', 'data/Scenes/02_Hotel_Reception_Main.lua', false, hotel_move_condition, hotel_deny_comics)
	game_state.ignore_on_highlight['area_hotel'] = true

    local zone_news = CreateZoomZone('Newspaper',
									 'CloseNewspaperZoom_04',
									 'BG_Zoom_Newspaper', true);
	zone_news.on_open = function()
		game_state.ignore_on_highlight['Newspaper'] = true
		AddGameState('IgnoreOnHighlight', 'Newspaper')
	end

    --play_field:GetObject('Clouds'):SetOpacity(0.85)

    add_fibrillation_effector_lamp(play_field:GetObject('Layer_Light_L'), 0.)
    add_fibrillation_effector_lamp(play_field:GetObject('Layer_Light_R'), 0.)
    --add_fibrillation_effector_lamp(play_field:GetObject('Layer_Light_L_small'), 0.5)
    --add_fibrillation_effector_lamp(play_field:GetObject('Layer_Light_R_small'), 0.5)
    --add_fibrillation_effector_lamp(play_field:GetObject('Layer_Refleks_L'), 0.5)
    --add_fibrillation_effector_lamp(play_field:GetObject('Layer_Refleks_R'), 0.5)
    
    local megoLight = MegoLightEffector();
    megoLight:AttachTo(play_field:GetObject('Layer_Light_L_small'));
    megoLight:Play();
    
    local megoLight = MegoLightEffector();
    megoLight:AttachTo(play_field:GetObject('Layer_Refleks_L'));
    megoLight:Play();
    
    local megoLight = MegoLightEffector();
    megoLight:AttachTo(play_field:GetObject('Layer_Light_R_small'));
    megoLight:PlayAt(0.5);
    
    local megoLight = MegoLightEffector();
    megoLight:AttachTo(play_field:GetObject('Layer_Refleks_R'));
    megoLight:PlayAt(0.5);

    MakeSoundEntity("wind"):Play(true);

    game_state.ignore_on_highlight['area_metrodotel'] = true
    if HasGameState('ToolFound', '08_stone') and
       HasGameState('ToolApplied', '08_rag')
    then
        game_state.ignore_on_highlight['area_library'] = true
        play_field:GetObject('open_door_sss'):Hide()
    end
    
    LoadSound('SpiderFromLibrary', 'data/Sound/06_Hotel_Street_Evening/SpiderFromLibrary.ogg');
end

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

function OnUpdate(dt)
    DefaultOnUpdate(dt)

    --play_field:GetObject('Layer_Clouds1'):GetAnimation():ChangeTextureRect(-15. * dt, 0.)
    --play_field:GetObject('Layer_Clouds2'):GetAnimation():ChangeTextureRect(-35. * dt, 0.)
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 AddSpiderMan(scene)

    local state = GetGameManager():GetCurrPlayer().m_gameState;
    if (state:HasState('SpiderManVanished') and state:GetState('SpiderManVanished'):HasValue('6'))
    then
    else
        state:AddState('SpiderManVanished', '6');
        PlaySpiderManFleeingAnimation(scene);
    end
end

--------------------------------------------------------------------------------
function PlaySpiderManFleeingAnimation(scene)

    local zOffset = 100;
    local timeOffset = 1;

    TimerDoString("local res = MakeSoundEntity('06_spider'); res:Play(false);", timeOffset, play_field:GetTimer())

    --------
    local anim = nil;
    local object = nil;
    local effector = nil;
    
    
    -- Layer Spider_man_relaxing
    anim = CreateAnimation("data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Animations/Spider_man_relaxing.png",
                           0, 0, 193, 153, 1, 0);
    anim:SetHotSpot(96.5, 76.5);
    anim:SetBlendMode(2)
    anim:SetColor('0xFFFFFFFF')
    object = scene:CreateObject('SpiderManRelaxing', anim, 465.5, 622.5, zOffset + 4, 0, 1, 1);
    object:SetVisible(false);
    
    effector = CreateAnimationEffector();
    effector:SetLifeTime(timeOffset + 0.75, timeOffset + 1.0);
    effector:SetAnimationTime(timeOffset + 1.5);
    effector:AttachTo(object);
    effector:Play();


    -- Layer Spider_man_fleeing
    anim = CreateAnimation("data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Animations/Spider_man_fleeing.png",
                           0, 0, 522, 117, 20, 15);
    anim:SetHotSpot(260, 57.5);
    anim:SetBlendMode(2)
    anim:SetColor('0xFFFFFFFF')
    object = scene:CreateObject('SpiderManFleeing', anim, 764, 620.5, zOffset + 3, 0, 1, 1);
    object:SetVisible(false);
    
    effector = CreateAnimationEffector();
    effector:SetLifeTime(timeOffset + 4, timeOffset + 5.33333333333333);
    effector:SetAnimationTime(timeOffset + 6);
    effector:AttachTo(object);
    effector:Play();


    -- Layer Spider_man_scouting_area
    anim = CreateAnimation("data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Animations/Spider_man_scouting_area.png",
                           0, 0, 202, 159, 45, 15); -- 45 kadrov
    anim:SetHotSpot(100, 78.5);
    anim:SetBlendMode(2)
    anim:SetColor('0xFFFFFFFF')
    object = scene:CreateObject('SpiderManScoutingArea', anim, 545.5, 624.5, zOffset + 2, 0, 1, 1);
    object:SetVisible(false);
    
    effector = CreateAnimationEffector();
    effector:SetLifeTime(timeOffset + 1, timeOffset + 4);
    effector:SetAnimationTime(timeOffset + 4.5);
    effector:AttachTo(object);
    effector:Play();


    -- Layer Spider_man_appearing
    anim = CreateAnimation("data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Animations/Spider_man_appearing.png",
                           0, 0, 195, 155, 12, 15);
    anim:SetHotSpot(96.5, 76.5);
    anim:SetBlendMode(2)
    anim:SetColor('0xFFFFFFFF')
    object = scene:CreateObject('SpiderManAppearing', anim, 465.5, 622.5, zOffset + 1, 0, 1, 1);
    object:SetVisible(false);
    
    effector = CreateAnimationEffector();
    effector:SetLifeTime(timeOffset + 0, timeOffset + 0.75);
    effector:SetAnimationTime(timeOffset + 1.5);
    effector:AttachTo(object);
    effector:Play();
    
end

--------------------------------------------------------------------------------
function PlaySpiderManHeroicalManuverNearLibrary()

    local state = GetGameManager():GetCurrPlayer().m_gameState;
    if (state:HasState('SpiderManVanished') and state:GetState('SpiderManVanished'):HasValue('6_2'))
    then
    else
        local zOffset = 100;
        
        local fps = 12.0;
        local frames = 21.0;
        
        state:AddState('SpiderManVanished', '6_2');
        anim = CreateAnimation("data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Animations/Spider_man_sneaks_near_library.png",
                           0, 0, 354, 94, frames, fps);
        anim:SetHotSpot(177, 47);
        anim:SetMode(HGEANIM_FWD + HGEANIM_NOLOOP);
        local object = play_field:CreateObject('SpiderManSneakingNearLibrary', anim, 408, 513, zOffset + 1, 0, 1, 1);
        local duration = frames / fps;
        TimerDoString("play_field:DeleteObject('SpiderManSneakingNearLibrary');" ..
                      "ShowMonolog('C_06_SPIDER_NEAR_LIBRARY', 'C_06_SPIDER_NEAR_LIBRARY')",
                      duration, play_field:GetTimer());
                      
        PlaySound('SpiderFromLibrary');
        
    end
end

--------------------------------------------------------------------------------
function LevelLoaded(level)

    local screen = level;

    local anim = screen:CreateAnimation('data/Texture/Scenes/Common/Clouds.png');
	anim:SetPosXY(512, 0);
	anim:SetOpacity(0.6);
	anim:SetScaleXY(1, 1);
	anim:SetPosZ(17);
	
	local effector = CreateTextureEffector();
	effector:AttachToAnimation(anim);
	effector:SetSpeed(-16);
	effector:Play();

    AddFlyingLeavesAnimation(level, 120);
    
    if HasGameState('SceneVisited', 'data/Scenes/08_Library_Main.lua')
    then
        TimerDoString('PlaySpiderManHeroicalManuverNearLibrary()', 0.5, play_field:GetTimer());        
    end
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/06_Hotel_Street_Evening/Zone_Main/Layers/Layer_Top.png',0,0,801,235,1,0)
	anim:SetHotSpot(400,0)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Top',anim,623,0,50,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/BG_Hotel_Street.jpg',0,0,223,768,1,0)
	anim:SetHotSpot(0,0)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Hotel_Street',anim,0,0,75,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/BG_Hotel_Street.jpg',0,230,1024,548,1,0)
	anim:SetHotSpot(0,0)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Hotel_Street_bottom',anim,0,230,80,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_metrodotel',anim,838,471,100,0,8,16)
	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_library',anim,339,415,100,0,7,16)
	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_Lock',anim,350,415,100,0,8,16)
	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_museum_street',anim,213,480,100,0,16,35)
	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_hotel',anim,-8,417,100,0,20,70)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Layer_Light_L.png',0,0,168,193,1,0)
	anim:SetHotSpot(84,96)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Light_L',anim,463,331,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Layer_Light_R.png',0,0,117,118,1,0)
	anim:SetHotSpot(58,59)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Light_R',anim,917,290,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Sky.JPG',0,0,1024,400,1,0)
	anim:SetHotSpot(512,200)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Sky',anim,512,105,10,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Moon.PNG',0,0,340,320,1,0)
	anim:SetHotSpot(170,160)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Moon',anim,540,60,16,0,0.6,0.6)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Layer_Refleks_L.PNG',0,0,176,99,1,0)
	anim:SetHotSpot(88,49)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Refleks_L',anim,309,512,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Layer_Refleks_R.PNG',0,0,161,130,1,0)
	anim:SetHotSpot(80,65)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Refleks_R',anim,835,498,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Layer_Light_L.png',0,0,168,193,1,0)
	anim:SetHotSpot(84,96)
	anim:SetBlendMode(0)
	anim:SetColor('0x88FFFFFF')
	screen:CreateObject('Layer_Light_L_small',anim,319,371,100,0,0.5,0.5)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Layer_Light_R.png',0,0,117,118,1,0)
	anim:SetHotSpot(58,59)
	anim:SetBlendMode(0)
	anim:SetColor('0x88FFFFFF')
	screen:CreateObject('Layer_Light_R_small',anim,839,432,100,0,0.5,0.5)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/open_door.png',0,0,65,149,1,0)
	anim:SetHotSpot(32,74)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('open_door',anim,340,418,90,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/open_door_sss.png',0,0,65,149,1,0)
	anim:SetHotSpot(32,74)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('open_door_sss',anim,342,418,99,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Newspaper.png',0,0,266,85,1,0)
	anim:SetHotSpot(133,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Newspaper',anim,321,662,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/04_Hotel_Street_Sunset/Zoom_newspaper/BG_Zoom_Newspaper.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('BG_Zoom_Newspaper',anim,512,384,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/06_Hotel_Street_Evening/Zone_Main/Layers/Transition_Zone.png',0,0,87,85,1,0)
	anim:SetHotSpot(80,45)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_cemetry',anim,990,568,100,0,5,5)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
