local zoom_shelf;
local zoom_shelf2;
local zoom_under_bed;

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/16_Doctor_Room_HO.lua', 'hidden_object', 'data/Scenes/16_Doctor_Main.lua')
    
    play_field:IgnoreOnTestPoint('fly_anim_1')
    play_field:GetObject('BG_OpenShelf' ):SetOpacity(0);
    play_field:GetObject('BG_OpenShelf2'):SetOpacity(0);
    play_field:GetObject('BG_UnderBed'  ):SetOpacity(0);
    
    AddTask(CreateTask('SCALPEL',     '',             'Scalpel'));
    AddTask(CreateTask('HOURGLASS',   'HOURGLASS',    'Hourglass1', 'Hourglass2'));
    AddTask(CreateTask('KNIFE',       'KNIFES',       'Knife1', 'Knife2'));
    AddTask(CreateTask('CUP',         'CUPS',         'Cup1', 'Cup2'));
    AddTask(CreateTask('SALAD',       '',             'Salad'));
    AddTask(CreateTask('INKPOT',      '',             'Inkpot'));
    AddTask(CreateTask('BOTTLE',      '',             'Bottle'));
    
    AddRandomTasks( CreateTask('BELL',         '', 'Bell'),
                    CreateTask('BROOM',        '', 'Broom'),
                    CreateTask('CROW',         '', 'Crow'),
                    CreateTask('DOLPHIN',      '', 'Dolphin'),
                    CreateTask('FLY_AGARIC',   '', 'FlyAgaric'),
                    CreateTask('HORSESHOE',    '', 'Horseshoe'),
                    CreateTask('KEY',          '', 'Key'),
                    CreateTask('MASK',         '', 'Mask'),
                    CreateTask('PIPE',         '', 'Pipe'),
                    CreateTask('SHELL',        '', 'Shell'),
                    CreateTask('SPOON',        '', 'Spoon'),
                    CreateTask('SYRINGE',      '', 'Syringe'),
                    CreateTask('UNICORN',      '', 'Unicorn'),
                    CreateTask('WATCH',        '', 'Watch'));
    
    RegisterActiveObject('area_shelf',      function(obj_name)
                                                play_field:GetObject(obj_name):SetVisible(false);
                                                play_field:GetObject('BG_OpenShelf'):ChangeOpacity(0, 1, 0.5)
                                                
                                                PlaySound('16_MoveShelf')
                                            end,
                                            function(obj_name)
                                                play_field:GetObject(obj_name):SetVisible(false);
                                                play_field:GetObject('BG_OpenShelf'):SetOpacity(1)
                                            end);
    
    RegisterActiveObject('area_shelf2',     function(obj_name)
                                                play_field:GetObject(obj_name):SetVisible(false);
                                                play_field:GetObject('BG_OpenShelf2'):ChangeOpacity(0, 1, 0.5)
                                                
                                                PlaySound('16_MoveShelf2')
                                            end,
                                            function(obj_name)
                                                play_field:GetObject(obj_name):SetVisible(false);
                                                play_field:GetObject('BG_OpenShelf2'):SetOpacity(1)
                                            end);

    RegisterActiveObject('area_under_bed',  function(obj_name)
                                                play_field:GetObject(obj_name):SetVisible(false);
                                                play_field:GetObject('BG_UnderBed'):ChangeOpacity(0, 1, 0.5)
                                                
                                                PlaySound('16_Counterpane');
                                            end,
                                            function(obj_name)
                                                play_field:GetObject(obj_name):SetVisible(false);
                                                play_field:GetObject('BG_UnderBed'):SetOpacity(1)
                                            end);
    
    zoom_shelf =    CreateZoomZone( 'BG_OpenShelf',
                                    'CloseZoneShelf',
                                    'ZOOM_shelf',       true,
                                    'BG_shelf_layer',   true,
                                    'Salad',            true);
    
    zoom_shelf2 =   CreateZoomZone( 'BG_OpenShelf2',
                                    'CloseZoneShelf2',
                                    'ZOOM_shelf2',     true,
                                    'BG_shelf2_layer', true,
                                    'Inkpot',          true);
                                
    zoom_under_bed = CreateZoomZone('BG_UnderBed',
                                    'CloseZoneUnderBed',
                                    'ZOOM_under_bed',   true,
                                    'Bottle',           true);

    if IsTaskObjectFound_16('Salad') then
        zoom_shelf.Disable();
    end
    
    if IsTaskObjectFound_16('Inkpot') then
        zoom_shelf2.Disable();
    end
    
    if IsTaskObjectFound_16('Bottle') then
        zoom_under_bed.Disable();
    end
    
    RegisterToolFindInfo('16_scalpel')
    
    game_state.disable_close_scene_on_complete = true;
end

function IsTaskObjectFound_16(obj_name)
    local state_value = game_state.scene_path.."("..obj_name..")"
    
    return HasGameState("TaskObjectFound", state_value)
end

function CloseZoom(zoom_name)
    local zone;
    
    if     zoom_name == 'shelf'     then zone = zoom_shelf
    elseif zoom_name == 'shelf2'    then zone = zoom_shelf2
    elseif zoom_name == 'under_bed' then zone = zoom_under_bed
    end
    
    if not zone then
        return;
    end
    
    if zone.IsVisible() then
        zone.SetVisible(false);
    end
    zone.Disable();
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)
    if object:GetName() == 'Salad' then
        TimerDoString("CloseZoom('shelf')", 1, play_field:GetTimer())
    end
    
    if object:GetName() == 'Inkpot' then
        TimerDoString("CloseZoom('shelf2')", 1, play_field:GetTimer())
    end
    
    if object:GetName() == 'Bottle' then
        TimerDoString("CloseZoom('under_bed')", 1, play_field:GetTimer())
    end
    
    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/16_Doctor/Zone_HO_room/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/05_Gendarmery/Zone_wart/Animations/fly_anim.png',0,0,217,217,8,10)
	anim:SetHotSpot(108,108)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fly_anim_1',anim,469,233,105,0,0.9,0.9)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Bell.png',0,0,36,60,1,0)
	anim:SetHotSpot(18,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bell',anim,163,311,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Broom.png',0,0,153,41,1,0)
	anim:SetHotSpot(96,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Broom',anim,798,432,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Crow.png',0,0,96,69,1,0)
	anim:SetHotSpot(48,34)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Crow',anim,259,240,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Cup1.png',0,0,103,68,1,0)
	anim:SetHotSpot(51,34)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Cup1',anim,754,618,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Cup2.png',0,0,75,50,1,0)
	anim:SetHotSpot(37,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Cup2',anim,408,474,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Dolphin.png',0,0,88,47,1,0)
	anim:SetHotSpot(44,23)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Dolphin',anim,646,194,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/FlyAgaric.png',0,0,51,45,1,0)
	anim:SetHotSpot(25,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('FlyAgaric',anim,549,300,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Horseshoe.png',0,0,75,67,1,0)
	anim:SetHotSpot(37,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Horseshoe',anim,799,210,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Hourglass1.png',0,0,69,53,1,0)
	anim:SetHotSpot(34,26)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Hourglass1',anim,403,355,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Hourglass2.png',0,0,85,81,1,0)
	anim:SetHotSpot(42,40)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Hourglass2',anim,120,537,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Key.png',0,0,42,74,1,0)
	anim:SetHotSpot(21,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Key',anim,227,97,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Knife1.png',0,0,94,51,1,0)
	anim:SetHotSpot(47,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Knife1',anim,194,599,102,20,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Knife2.png',0,0,128,38,1,0)
	anim:SetHotSpot(64,19)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Knife2',anim,560,610,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Mask.png',0,0,36,47,1,0)
	anim:SetHotSpot(18,23)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Mask',anim,432,283,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Pipe.png',0,0,73,33,1,0)
	anim:SetHotSpot(36,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Pipe',anim,971,266,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Shell.png',0,0,63,40,1,0)
	anim:SetHotSpot(31,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Shell',anim,493,166,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Spoon.png',0,0,91,33,1,0)
	anim:SetHotSpot(45,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Spoon',anim,734,134,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Syringe.png',0,0,183,40,1,0)
	anim:SetHotSpot(91,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Syringe',anim,927,501,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Unicorn.png',0,0,88,107,1,0)
	anim:SetHotSpot(44,53)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Unicorn',anim,661,475,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Watch.png',0,0,42,37,1,0)
	anim:SetHotSpot(21,18)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Watch',anim,609,541,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_cup01.png',0,0,38,51,1,0)
	anim:SetHotSpot(19,25)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_cup01',anim,744,607,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_cup02.png',0,0,35,32,1,0)
	anim:SetHotSpot(17,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_cup02',anim,429,483,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_koloklchik.png',0,0,48,21,1,0)
	anim:SetHotSpot(24,10)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_koloklchik',anim,166,340,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_metelki.png',0,0,159,45,1,0)
	anim:SetHotSpot(79,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_metelki',anim,775,430,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_pipe.png',0,0,19,19,1,0)
	anim:SetHotSpot(9,9)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_pipe',anim,980,271,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_shprica.png',0,0,107,38,1,0)
	anim:SetHotSpot(53,19)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_shprica',anim,903,503,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_sprajt_pesochnye_chasy02.png',0,0,48,61,1,0)
	anim:SetHotSpot(24,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_sprajt_pesochnye_chasy02',anim,118,545,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_OpenShelf2.png',0,0,72,53,1,0)
	anim:SetHotSpot(36,26)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_OpenShelf2',anim,547,331,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_OpenShelf.png',0,0,181,57,1,0)
	anim:SetHotSpot(90,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_OpenShelf',anim,99,470,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_UnderBed.png',0,0,96,124,1,0)
	anim:SetHotSpot(48,62)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_UnderBed',anim,323,424,101,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_shelf',anim,102,466,102,0,1.5,0.4)
	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_shelf2',anim,543,339,102,0,0.69,0.4)
	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_under_bed',anim,327,416,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Zoom_shelf/ZOOM_shelf.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_shelf',anim,512,384,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Zoom_shelf/BG_shelf_layer.png',0,0,138,78,1,0)
	anim:SetHotSpot(69,39)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_shelf_layer',anim,462,447,152,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Salad.png',0,0,140,121,1,0)
	anim:SetHotSpot(70,60)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Salad',anim,461,401,151,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Zoom_shelf2/ZOOM_shelf2.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_shelf2',anim,512,384,160,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Zoom_shelf2/BG_shelf2_layer.png',0,0,81,58,1,0)
	anim:SetHotSpot(40,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_shelf2_layer',anim,521,486,162,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Inkpot.png',0,0,178,124,1,0)
	anim:SetHotSpot(89,62)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Inkpot',anim,502,437,161,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Zoom_under_bed/ZOOM_under_bed.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_under_bed',anim,512,384,170,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Bottle.png',0,0,325,139,1,0)
	anim:SetHotSpot(162,69)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bottle',anim,539,475,171,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Layers/BG_bulb_layer.png',0,0,17,45,1,0)
	anim:SetHotSpot(8,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_bulb_layer',anim,91,501,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Doctor/Zone_HO_room/Items/Scalpel.png',0,0,96,65,1,0)
	anim:SetHotSpot(48,32)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Scalpel',anim,248,608,101,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
