function init_steams()
	game_state.steams = {}

	table.insert(game_state.steams, create_steam(900., 310., 1., 235. * M_PI / 180.))
	table.insert(game_state.steams, create_steam(400., 160., 1., 45. * M_PI / 180.))

	do_steam_pseudo_recursive_iteration()
end

function create_steam(x, y, scale, angle)
    scale = (scale ~= nil and scale or 1.0)
	angle = (angle ~= nil and angle or 1.0)

	local ps = CreateParticleSystemEntity('data/ParticleSystem/Steam.psi', 'SmokeParticle')
	ps:AttachTo(play_field)
	ps:SetXY(x, y)
	ps:SetZ(130.0)
	ps:SetScale(scale)
	ps:GetParticleSystem().info.fDirection = angle
	ps:GetParticleSystem():Stop(true)
	return ps
end

function do_steam_pseudo_recursive_iteration()
	start_random_steam()
	TimerDoString("do_steam_pseudo_recursive_iteration()", math.random(0.1, 1.), play_field:GetTimer())
end

function start_random_steam()
	if game_state.steams ~= nil and table.getn(game_state.steams) > 0 then
		local i = math.random(1, table.getn(game_state.steams))
		game_state.steams[i]:GetParticleSystem():Fire()
	end
end

-- copy paste
function create_steam(x, y, scale, angle)
    scale = (scale ~= nil and scale or 1.0)
	angle = (angle ~= nil and angle or 1.0)

	local ps = CreateParticleSystemEntity('data/ParticleSystem/Steam.psi', 'SmokeParticle')
	ps:AttachTo(play_field)
	ps:SetXY(x, y)
	ps:SetZ(130.0)
	ps:SetScale(scale)
	ps:GetParticleSystem().info.fDirection = angle
	ps:GetParticleSystem():Stop(true)
	return ps
end

function start_steam_and_delay_next_start()
	game_state.steam:GetParticleSystem():Fire()
	TimerDoString("start_steam_and_delay_next_start()", math.random(0.8, 3.), play_field:GetTimer())
end

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/20_Boiler_Room_HO.lua', 'hidden_object', 'data/Scenes/20_Boiler_Room_Main.lua')

    local level = play_field:GetLevelScreen()
    level:AddTask(CreateTask('BALL', 'BALLS', 'Ball', 'Bilyardny sharik1', 'Bilyardny sharik2', 'Bilyardny sharik3'))
    --level:AddTask(CreateTask('BAT', '', 'Bat'))
    level:AddTask(CreateTask('BELL', '', 'Bell'))
    level:AddTask(CreateTask('BRAZING_TORCH', '', 'Brazing_torch'))
    level:AddTask(CreateTask('BROOM', '', 'Broom'))
    level:AddTask(CreateTask('ELECRODE', '', 'Elecrode'))
    level:AddTask(CreateTask('ENVELOPE', '', 'Envelope'))
    level:AddTask(CreateTask('FISH', '', 'Fish'))
    level:AddTask(CreateTask('GEAR', '', 'Gear'))
    --level:AddTask(CreateTask('HOOK', '', 'Hook'))
    level:AddTask(CreateTask('KEROSENE_LAMP', '', 'Kerosene_Lamp'))
    level:AddTask(CreateTask('SKELETON', '', 'Skeleton'))
    level:AddTask(CreateTask('SLUG', '', 'Slug'))
    level:AddTask(CreateTask('STAR', 'STARS', 'Star', 'Zvezda1', 'Zvezda2', 'Zvezda3'))
    --level:AddTask(CreateTask('TANKARD', '', 'Tankard'))

	RegisterToolFindInfo('20_electrode')

	init_steams()

	local compilation = BuildKotelnyaCompilation();
	compilation:SetZ(50);
	compilation:AttachTo(screen);
	compilation:Play();
	
	LoadSound("BoilerWorking", "data/Sound/20_Boiler_Room/Boiler_working.ogg");
	MakeSoundEntity("BoilerWorking"):Play(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 BuildKotelnyaCompilation()

    createCompositionkotelna_zoom1 = function()
    
        local compositionkotelna_zoom1 = CreateCompositionSequence();
        local compositionDuration = 0.76;
        compositionkotelna_zoom1:SetDuration(compositionDuration);
    
    
        -- Layer Arrow
        local element = CreateCompositionElement("data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers/Arrow_L.PNG");
        element:SetName("Arrow");
        compositionkotelna_zoom1:AddElement(element);
        element:SetHotSpot(4, 20);
        element:SetParentElement(compositionkotelna_zoom1);
        element:SetXY(626, 152.875);
    
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 2.25);
    
        effector:SetKey(_TRACK_A, 0, 0);
        effector:SetKey(_TRACK_A, 0.04, -0.20015561291354);
        effector:SetKey(_TRACK_A, 0.12, 0.2706361759092);
        effector:SetKey(_TRACK_A, 0.24, -0.14775708157317);
        effector:SetKey(_TRACK_A, 0.36, 0.09737155051356);
        effector:SetKey(_TRACK_A, 0.48, -0.02497481242755);
        effector:SetKey(_TRACK_A, 0.64, 0.0631993169737);
        effector:SetKey(_TRACK_A, 0.76, 0);
    
        effector:Play();
    
    
        -- Layer Mask_1
        local element = CreateCompositionElement("data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers/kotel_mask_1.png");
        element:SetName("Mask_1");
        compositionkotelna_zoom1:AddElement(element);
        element:SetHotSpot(28.5, 23.5);
        element:SetParentElement(compositionkotelna_zoom1);
        element:SetXY(638.5, 318.5);
    
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 0.76);
    
    
        effector:Play();
    
    
        -- Layer Mask_2
        local element = CreateCompositionElement("data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers/kotel_mask_2.png");
        element:SetName("Mask_2");
        compositionkotelna_zoom1:AddElement(element);
        element:SetHotSpot(35.5, 30.5);
        element:SetParentElement(compositionkotelna_zoom1);
        element:SetXY(933.5, 317.5);
    
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 0.76);
    
    
        effector:Play();
    
    
        -- Layer Pendulum
        local element = CreateCompositionElement("data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers/kotel_shtrunya.png");
        element:SetName("Pendulum");
        compositionkotelna_zoom1:AddElement(element);
        element:SetHotSpot(154.5, 59);
        element:SetParentElement(compositionkotelna_zoom1);
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 0.76);
    
        effector:SetKey(_TRACK_X, 0, 765);
        effector:SetKey(_TRACK_Y, 0, 316);
        effector:SetKey(_TRACK_X, 0.19999217987061, 812);
        effector:SetKey(_TRACK_Y, 0.19999217987061, 316);
        effector:SetKey(_TRACK_X, 0.55999999046326, 765);
        effector:SetKey(_TRACK_Y, 0.55999999046326, 316);
        effector:SetKey(_TRACK_X, 0.68001168966293, 768.616648517281);
        effector:SetKey(_TRACK_Y, 0.68001168966293, 316);
        effector:SetKey(_TRACK_X, 0.71998828649521, 765);
        effector:SetKey(_TRACK_Y, 0.71998828649521, 316);
    
        effector:Play();
    
    
        -- Layer Pendulum_shadow
        local element = CreateCompositionElement("data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers/kotel_shtrunya_shadow.png");
        element:SetName("Pendulum_shadow");
        compositionkotelna_zoom1:AddElement(element);
        element:SetHotSpot(175, 70);
        compositionkotelna_zoom1:RegisterParentInfo("Pendulum_shadow", "Pendulum");
        element:SetXY(154.5, 64);
    
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
        element:SetOpacity(1.0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 0.76);
    
    
        effector:Play();
        
    
        return compositionkotelna_zoom1;
    end
    
    local result = createCompositionkotelna_zoom1();
    result:SetCyclic(true);
    return result;

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/20_Boiler_Room/Zone_HO/Layers/BG_BoilerRoom_HO.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_BoilerRoom_HO',anim,512,384,45,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Ball.PNG',0,0,55,55,1,0)
	anim:SetHotSpot(27,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Ball',anim,447,549,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Bat.PNG',0,0,92,99,1,0)
	anim:SetHotSpot(46,49)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bat',anim,950,59,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Bell.PNG',0,0,77,143,1,0)
	anim:SetHotSpot(38,71)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bell',anim,319,323,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Brazing_torch.PNG',0,0,114,85,1,0)
	anim:SetHotSpot(57,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Brazing_torch',anim,370,109,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Broom.PNG',0,0,87,337,1,0)
	anim:SetHotSpot(43,168)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Broom',anim,710,558,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Elecrode.PNG',0,0,53,119,1,0)
	anim:SetHotSpot(26,59)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Elecrode',anim,858,465,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Envelope.PNG',0,0,93,83,1,0)
	anim:SetHotSpot(46,41)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Envelope',anim,943,291,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Fish.PNG',0,0,65,85,1,0)
	anim:SetHotSpot(32,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Fish',anim,584,218,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Gear.PNG',0,0,64,68,1,0)
	anim:SetHotSpot(32,34)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Gear',anim,582,114,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Hook.PNG',0,0,126,77,1,0)
	anim:SetHotSpot(63,38)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Hook',anim,478,512,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Kerosene_Lamp.PNG',0,0,57,93,1,0)
	anim:SetHotSpot(28,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Kerosene_Lamp',anim,361,516,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Skeleton.PNG',0,0,80,101,1,0)
	anim:SetHotSpot(40,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Skeleton',anim,186,142,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Slug.PNG',0,0,133,67,1,0)
	anim:SetHotSpot(66,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Slug',anim,219,591,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Star.PNG',0,0,66,61,1,0)
	anim:SetHotSpot(33,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Star',anim,643,423,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items/Tankard.PNG',0,0,90,74,1,0)
	anim:SetHotSpot(45,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Tankard',anim,227,371,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers/Layer_envelopes_Over.PNG',0,0,129,78,1,0)
	anim:SetHotSpot(64,39)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_envelopes_Over',anim,946,319,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Animations/kotel_mask_1.png',0,0,57,47,1,0)
	anim:SetHotSpot(28,23)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('kotel_mask_1',anim,638,318,50,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items_add/Bilyardny sharik1.png',0,0,39,38,1,0)
	anim:SetHotSpot(19,19)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bilyardny sharik1',anim,249,42,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items_add/Bilyardny sharik2.png',0,0,42,43,1,0)
	anim:SetHotSpot(21,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bilyardny sharik2',anim,922,468,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items_add/Bilyardny sharik3.png',0,0,34,35,1,0)
	anim:SetHotSpot(17,17)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bilyardny sharik3',anim,12,483,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items_add/Zvezda1.png',0,0,44,53,1,0)
	anim:SetHotSpot(22,26)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Zvezda1',anim,57,480,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items_add/Zvezda2.png',0,0,30,30,1,0)
	anim:SetHotSpot(15,15)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Zvezda2',anim,761,27,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Items_add/Zvezda3.png',0,0,41,34,1,0)
	anim:SetHotSpot(20,17)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Zvezda3',anim,114,23,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers_add/Layer_Bell_Over.png',0,0,38,55,1,0)
	anim:SetHotSpot(19,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Bell_Over_add',anim,319,287,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/20_Boiler_Room/Zone_HO/Layers_add/Layer_Bilyardny sharik1_Over.png',0,0,45,52,1,0)
	anim:SetHotSpot(22,26)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Bilyardny sharik1_Over',anim,242,47,105,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
