function OnSceneLoad(screen)
    game_state = {}    
    LoadData(screen)
    local pf = play_field
    local level = pf:GetLevelScreen()
    game_state.custom_cursors = {}
    game_state.locked_objects = {}
    --level:AddTaskSafe(CreateTask('', '', ''))
    --zone = CreateZoomZone('')
    game_state.locker = ReferenceCounter()
    game_state.active_zone = nil
    game_state.inventory_zones = {}
	game_state.active_objects = {}
	
	local object = play_field:GetObject('kryshka_luka');
	inventory_hatch = CreateInventory(object:GetX(),
                                        object:GetY(),
                                        object:GetZ() + 10,
                                        "kryshka_luka",
                                        CreateItem('mask_tool', 'mask_scaled'),
                                        CreateItem('oxygen_cyllinder_tool', 'oxygen_cyllinder_scaled'),
                                        CreateItem('burner_tool', 'burner_scaled'),
                                        play_field:GetTimer(),
										"INVENTORY_TASK_24_1");

	inventory_hatch.state_changer = 'OnHatchDoorComplete'
										
	inventory_hatch.OnComplete = function()
		PlaySound('24_HatchDoorOpen')
		play_field:GetObject('kryshka_luka'):ChangeOpacity(1, 0, 0.3);
		RegisterZoomZone(zoom_hole, 'hatch_active_zone')
	end
	
	zoom_hole = CreateZoomZone('close_zone_hole',
                                 '',
                                 'bak',
                                 'butylka',
								 'sprait_sapoga',
                                 'piece_of_map')
	
	CreateTool('mask', 'mask_scaled')
	CreateTool('oxygen_cyllinder', 'oxygen_cyllinder_scaled')
	CreateTool('burner', 'burner_scaled')
	
	AddRandomTasks(17,
				CreateTask('ANCHOR', '', 'anchor'),
				CreateTask('BALL2', 'BALLS2', 'ball', 'ball2'),
				CreateTask('HAT', '', 'hat'),
				CreateTask('HOOK', '', 'hook'),
				CreateTask('IRON', '', 'iron'),
				CreateTask('HAMMER', '', 'hammer'),
				CreateTask('MEDIKIT', '', 'medikit'),
				CreateTask('MOUSETRAP', '', 'mousetrap'),
				CreateTask('JACKPLANE', '', 'plane'),					
				CreateTask('PLIERS', '', 'pliers'),
				CreateTask('SHIP', '', 'ship'),
				CreateTask('SLEDGEHAMMER', 'SLEDGEHAMMERS', 'sledgehammer2'),
				CreateTask('SPRING', '', 'spring'),
				CreateTask('FLASHLIGHT', '', 'torch'),
				CreateTask('BLACK_PAWN', '', 'chess_piece'),
				CreateTask('INSULATING_TAPE', '', 'insulating_tape'),
				CreateTask('KNIFE', '', 'knife'),
                CreateTask('PEPPER', '', 'pepper') );
				
	level:AddTaskSafe( CreateTask('PIECE_OF_MAP', '', 'piece_of_map') );
	
	InitChain1(screen);
	game_state.chain1.state_changer = 'OnStartingComicsComplete'
	
    InitChain2(screen);
    InitChain3(screen);
	game_state.chain3.final = true
    AddSheriffEyeLogic();
	game_state.meta_object = 'cigar24'
	
	game_state.OnStartingComicsComplete = function()
		inventory_hatch.Unlock()
	end
	
	game_state.OnHatchDoorComplete = function()
		PlaySound('24_HatchDoorOpen')
		play_field:GetObject('kryshka_luka'):SetOpacity(0)
		RegisterZoomZone(zoom_hole, 'hatch_active_zone')
	end
	
	game_state.CheckWinConditions = function()
		if IsNotebookClosed() and ArePanelTasksComplete() then
		    if game_state.chain2_shown then
			    game_state.chain3.Start()
			    return
			end
			game_state.chain2.Start()
		end
	end
	
	game_state.chain2_shown = false
end

function OnMinigameCompleted()
end

function InitChain1(screen)
    local comics1 = CreateComics(screen, 'Sheriff', 'eyes');    
	
	comics1.OnHidden = function()
		comics1.DefaultOnHidden()
		inventory_hatch.Unlock()
	end
    
    game_state.chain1 = CreateChain('pixel_comics_1',
                                    screen,
                                    comics1, GetString("COMICS_24_1"));
end

function InitChain2(screen)
    local comics1 = CreateComics(screen, 'Sheriff', 'eyes');        
    comics1.OnHidden = function()
        comics1.DefaultOnHidden()
        game_state.chain2_shown = true
        game_state.CheckWinConditions()
    end
    
    game_state.chain2 = CreateChain('pixel_comics_2',
                                    screen,
                                    comics1, GetString("COMICS_24_2"));
end

function InitChain3(screen)
    local comics1 = CreateComics(screen, 'Sheriff', 'eyes');    
	
	comics1.OnHidden = function()
		OnWin()
	end
    
    game_state.chain3 = CreateChain('pixel_comics_3',
                                    screen,
                                    comics1, GetString("COMICS_24_3"));
end

function OnSceneFree(screen)
    FreeData(screen)
end

function OnNotebookClosed()
	game_state.chain3.Start()
end

function OnUpdate(dt)
end

function OnScreenShown()
	game_state.chain1.Start()
end

function OnExit()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

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

    is_wrong_click = DefaultOnObjectMouseDown(object)

    if is_wrong_click then
        --pf:ShowWrongObjectEffect()
    end

    return is_wrong_click;    
end

function OnObjectMouseUp(object)
end

function OnObjectWasFound(object)
    if object:GetName() == 'piece_of_map' then
        game_state.chain2.Start()
    end
end

function OnObjectWillBeFound(object)
	if object:GetName() == 'piece_of_map' then
        zoom_hole.SetVisible(false)        
        game_state.locker:Release()
		UnregisterZoomZone(zoom_hole)
    end
    if not play_field:GetLevelScreen():HasTaskObjects() then
		GetProfileManager():GetCurrentProfile():AddStateChanger('CheckWinConditions')
	end
end

function OnToolFound(tool)
end

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

function OnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
end

function CanBeHinted(obj)
    if locked_object[obj] ~= true then
        return true
    else
        return false
    end
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/24_caravan_workers_10/Layers/bg.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bg',anim,512,384,90,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/anchor.png',0,0,58,64,1,0)
	anim:SetHotSpot(29,32)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('anchor',anim,911,160,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/ball2.png',0,0,88,66,1,0)
	anim:SetHotSpot(44,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('ball2',anim,448,729,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/ball.png',0,0,27,27,1,0)
	anim:SetHotSpot(13,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('ball',anim,438,583,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/burner.png',0,0,49,152,1,0)
	anim:SetHotSpot(24,76)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('burner',anim,612,701,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/hat.png',0,0,43,59,1,0)
	anim:SetHotSpot(21,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('hat',anim,746,307,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/hook.png',0,0,37,83,1,0)
	anim:SetHotSpot(18,41)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('hook',anim,325,37,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/iron.png',0,0,42,65,1,0)
	anim:SetHotSpot(21,32)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('iron',anim,607,296,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/mask.png',0,0,93,88,1,0)
	anim:SetHotSpot(46,44)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('mask',anim,242,732,100,0,-1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/medikit.png',0,0,50,38,1,0)
	anim:SetHotSpot(25,19)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('medikit',anim,804,507,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/mousetrap.png',0,0,44,25,1,0)
	anim:SetHotSpot(22,12)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('mousetrap',anim,916,604,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/oxygen_cyllinder.png',0,0,59,200,1,0)
	anim:SetHotSpot(29,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('oxygen_cyllinder',anim,1008,524,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/plane.png',0,0,60,42,1,0)
	anim:SetHotSpot(30,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('plane',anim,943,479,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/pliers.png',0,0,79,44,1,0)
	anim:SetHotSpot(39,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('pliers',anim,973,740,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/ship.png',0,0,58,83,1,0)
	anim:SetHotSpot(29,41)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('ship',anim,704,354,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/sledgehammer2.png',0,0,93,57,1,0)
	anim:SetHotSpot(46,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sledgehammer2',anim,244,622,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/spring.png',0,0,56,158,1,0)
	anim:SetHotSpot(28,79)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('spring',anim,479,175,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/torch.png',0,0,67,47,1,0)
	anim:SetHotSpot(33,23)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('torch',anim,443,467,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Layers/sprait_aptechki.png',0,0,52,28,1,0)
	anim:SetHotSpot(26,14)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sprait_aptechki',anim,807,491,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Layers/sprait_ballona.png',0,0,97,105,1,0)
	anim:SetHotSpot(48,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sprait_ballona',anim,980,593,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Layers/sprait_fonarika.png',0,0,43,93,1,0)
	anim:SetHotSpot(21,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sprait_fonarika',anim,460,455,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Layers/sprait_shlyapy.png',0,0,50,85,1,0)
	anim:SetHotSpot(25,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sprait_shlyapy',anim,765,322,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Layers/kryshka_luka.png',0,0,200,92,1,0)
	anim:SetHotSpot(100,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('kryshka_luka',anim,742,657,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/oxygen_cyllinder.png',0,0,59,200,1,0)
	anim:SetHotSpot(29,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('oxygen_cyllinder_scaled',anim,1008,520,100,0,0.3,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/oxygen_cyllinder.png',0,0,59,200,1,0)
	anim:SetHotSpot(29,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('oxygen_cyllinder_tool',anim,575,114,100,0,0.3,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/burner.png',0,0,49,152,1,0)
	anim:SetHotSpot(24,76)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('burner_scaled',anim,609,712,100,0,0.5,0.5)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/burner.png',0,0,49,152,1,0)
	anim:SetHotSpot(24,76)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('burner_tool',anim,604,119,100,0,0.5,0.5)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/mask.png',0,0,93,88,1,0)
	anim:SetHotSpot(46,44)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('mask_tool',anim,642,123,100,0,-0.8,0.8)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/mask.png',0,0,93,88,1,0)
	anim:SetHotSpot(46,44)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('mask_scaled',anim,243,729,100,0,-0.8,0.8)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Layers/sprait_stula.png',0,0,59,81,1,0)
	anim:SetHotSpot(29,40)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('sprait_stula',anim,666,652,106,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Zoom/bak.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('bak',anim,512,384,350,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('hatch_active_zone',anim,751,661,100,0,18,10)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Zoom/butylka.png',0,0,199,221,1,0)
	anim:SetHotSpot(99,110)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('butylka',anim,583,387,360,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Zoom/sprait_sapoga.png',0,0,182,245,1,0)
	anim:SetHotSpot(91,122)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('sprait_sapoga',anim,516,436,359,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Zoom/piece_of_map.png',0,0,199,176,1,0)
	anim:SetHotSpot(99,88)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('piece_of_map',anim,575,481,351,0,1,1)
	local anim = CreateAnimation('data/Texture/Comics/Sheriff.dds',0,0,530,636,1,0)
	anim:SetHotSpot(266,256)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Sheriff',anim,756,390,400,0,1,1)
	local anim = CreateAnimation('data/Texture/Comics/eyes.png',0,0,79,33,1,0)
	anim:SetHotSpot(39,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('eyes',anim,745,212,500,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('pixel_comics_1',anim,512,384,401,0,128,96)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('pixel_comics_2',anim,512,384,401,0,128,96)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('pixel_comics_3',anim,512,384,401,0,128,96)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/chess_piece.png',0,0,38,27,1,0)
	anim:SetHotSpot(19,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('chess_piece',anim,788,736,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/insulating_tape.png',0,0,32,21,1,0)
	anim:SetHotSpot(16,10)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('insulating_tape',anim,816,452,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/knife.png',0,0,95,27,1,0)
	anim:SetHotSpot(47,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('knife',anim,410,757,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/Items/pepper.png',0,0,40,29,1,0)
	anim:SetHotSpot(20,14)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('pepper',anim,991,716,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/24_caravan_workers_10/cigar24.png',0,0,67,16,1,0)
	anim:SetHotSpot(33,8)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('cigar24',anim,659,451,100,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
