startlodka=false;
local count=0;
skip_com=false
AddParticleToObject(1,"Highlight");
MoveEmiter("Highlight",460,465);
finish=false
if flags.lodkanameste and  not  flags.sobrana then
AddParticleToObject(214,"lodka");
MoveEmiter("lodka",349,246);
StartEmiter("lodka")
end
takeobj=false
if flags.lodkanameste then
set_visible_object(214,true)
set_visible_object(obj.lodka2.id,false)
end

function motor()

playeffect("074")
end

AddParticleToObject(219,"voda3");
MoveEmiter("voda3",368,354);
StartEmiter("voda3")

StartAnimation(705);
StartTravel(705,1,nil,nil,{"InstantiationOfLine",2,1000,177,870,177,3,false})

myid=-1;

if flags.rentgen then
	StartEmiter("lodka")
end

attached=false;
WaitRender();

function gameinput(sender,obj_id,attachedID)

	if SLevel==1.0 then return; end;
--обработка плашки	
	 if (sender == 1  or sender==5) and not isTimes  and imagetex~=-1 then
			set_visible_object(obj.plashechka.id,false)
			set_visible_object(obj[imagetex].id,false)
			del_object_from_game(5654547)		
			gameinput(26,imageid)		
del_object_from_game(5654547)	
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)
				del_object_from_game(5654547)	
	end
	
	if sender == 2 then
		RemoveFromMouse(object);
		MessageProc(sender,obj_id);
	return;end;	
--наведение на части
	if sender==35 then		
		
		if not glove_on and not canusegadjets and not scaner_on then		
			if obj_id ==( obj.chast1.id and not obj.chast1.is_collapsed) or (obj_id == obj.chast2.id and not obj.chast2.is_collapsed) or (obj_id == obj.chast3.id and not obj.chast3.is_collapsed) or (obj_id == obj.chast4.id and not obj.chast4.is_collapsed) or (obj_id == obj.chast5.id and not obj.chast5.is_collapsed)  then
				if  flags.rentgen then
				set_visible_object(100004,false)
			set_visible_object(333,true)
			StartAnimation(333)	
				end				
			return;end	
	
		end
	return;end
--уведение с частей	
	if sender==39 then		
		set_visible_object(333,false)
		set_visible_object(100004,true)
	return;end
	
	
	
if sender ==41 then	
if obj_id ==obj.dragonfly.id then	
	StartAnimation( 5555555555,1,5 );
	return;end;
if obj_id==705 then
if flags.vlevo then
StartTravel(705,1,nil,nil,{"InstantiationOfLine",2,870,177,1000,177,3,false})
flags.vlevo=false
else
StartTravel(705,1,nil,nil,{"InstantiationOfLine",2,1000,177,870,177,3,false})
flags.vlevo=true
end
return; end;
	RotateHandler(obj_id);		
	return;end;
	
	if sender==26 then	
--старт рендер таргета перед комиксом в конце
	if obj_id ==88 and not startlodka then	
			set_visible_object(5000,false)
			set_visible_object(5001,false)
			set_visible_object(5002,false)
			set_visible_object(obj.plashechka.id,false)
			set_visible_object(obj.goodgirl.id,false)
			del_object_from_game(5654547)	
			
			leafobj={2235}
			GetRenderTarget(2235,"rendertar1");	
		
		function rendertar1(tex_name,tex_id)
			FlipVertical(2235);
			SetAlfa(2235,0,1,0,"vasea3353523")
			SetObjectPosition(2235,0,-256);
			LeaveObjectsOnReder("leafobj");
			ShowMenu(false)
			addstaticobjecttogame(top_plush_id, "plush", 0, 0, "");
			addstaticobjecttogame(bottom_plush_id, "plush", 0, 384, "");	
			takeobjecttohand=true
			addstaticobjecttogame(1025,"sea",0,0,"");
			speciale_action(2,1025)	
			add_animation(706);
			add_animation_frame(706,"lodka_anim",-400,298,0,0,546,124,0.3);-------------------кейс
			AddFrameFunc(706,"motor")
			add_animation_frame(706,"lodka_anim",-400,298,0,124,546,124,0.3);
			add_animation_frame(706,"lodka_anim",-400,298,0,248,546,124,0.3);
			add_animation_frame(706,"lodka_anim",-400,298,0,372,546,124,0.3);
			speciale_action(2,706);
			set_visible_object(top_plush_id,true)
			set_visible_object(bottom_plush_id,true)
			MoveObjectY(top_plush_id, -384, -256, 1.5/2);
			MoveObjectY(bottom_plush_id, 769, 640, 1.5/2);		
			speciale_action(2,1025,true)	
			speciale_action(2,706)				
			speciale_action(4,1025)
			speciale_action(4,706)
			speciale_action(4,bottom_plush_id)	
			speciale_action(4,top_plush_id)
			DrawSkipButton()
			StartAnimation(706);
			StartTravel(706,1,nil,nil,{"InstantiationOfLine",2,-400,350,1024,350,7,false})			
			StartTimer(555,5);
			ShowMenu(false);
			startlodka=true
		end
			
			
			
		
	return;end
	
	return;end;

	if sender ==36 then	
--собрали катер и предметы, говорит что Катер готов к отплытию
	if obj_id ==600 or obj_id==601 and not finish then		
		if not finish then
			CreatePlashechka(88,"71","goodgirl")
			finish=true
			end
		canmenu=true	
		takeobjecttohand=true
		canusegadjets=true			
	return;end;
--таймер после которого коне локации
	if obj_id ==555 and not skip_com then	
			HideSkipButton()
			MoveObjectY(top_plush_id, -256, -384, 1.5/2);
			MoveObjectY(bottom_plush_id, 640, 769, 1.5/2);
			StartTimer(5335,1.5,"lvl88end")		
			function lvl88end()		
			LevelEnd(9)
			flags.finish=true;	
			end
			
				
	return;end	   
	return;end;
	
	
if sender ==15 then
--исчез рентген
		if obj_id ==obj.ray.id then
			xray=false;
			rentgen_is_usable= false;	
			StartEmiter("lodka")
				BlockCursor(false)
				 flags.rentgen=true;   
		return;end;
end;
--коллапс мусора
	if sender == 12 then
		if not flags.items_collected then
		if obj_id == obj.telega.id or obj_id == obj.trubka.id or obj_id == obj.rascheska.id or obj_id == obj.shetka.id or obj_id == obj.galstuk.id or
			obj_id == obj.remen.id or obj_id == obj.cat.id or obj_id == obj.chasi.id or obj_id == obj.botinok.id or obj_id == obj.wlyapa.id or obj_id == obj.karta.id or obj_id == obj.koin1.id or obj_id == obj.koin2.id or obj_id == obj.koin3.id or obj_id == obj.ruchka.id  then
		
			if flags.items == 15 then
				flags.items_collected = true;		
				
				if flags.sobrana then
					flags.comics2= true;	
									
				return; end;
			end;
		end;
		end
		
	return; end;
	
	if sender == 33 then			
		
		if not flags.finish then
		
		flags.finish = false;
			ShowMenu(true);
			SwitchToSheet("re");
		return end
	return;end;

	if sender==777 then
	
		
--старт уровня	
		if flags.comics1 and not flags.finish then			
			StartTimer(43342,0.5,"conv8")
			function conv8()
				CreatePlashechka(66,"53","goodgirl")	
			end		
			
			flags.comics1=false;
			ShowMenu(true)
			SwitchToSheet("re")
		return;end
		
	if top_plush_id then		
		ShowMenu(true)
		SwitchToSheet("re")
		end	
	
	end
	

--обработчик рентгена	
	if sender ==100001 then
	
			speciale_action(2,obj.ray.id,true);
            speciale_action(4,obj.ray.id);           
            xray=true;            
                   
			flags.rentgen_is_usable=false;
			BlockCursor(true)
	
	end	
	
	if sender == 100 then

	if  flags.mini and not flags.mini1_complete then
	        add_free_leaf("mini1",8,10);-------------
			set_satelite_leaf("island");---------------------------
			UpdateStack()
			dofile("./data/8/10/res.lua");--------------
			
			dofile("data\\8\\10\\level.lua");-------------------
			mini_create();
			speciale_action(4,top_plush_id);
			speciale_action(4,bottom_plush_id);				
	end;	
	
	
		
		if flags.first_time_load then
				flags.first_time_load=false
			set_visible_object(obj.intro.id,true);
			-- StartEmiter("Level");
			speciale_action(4,obj.intro.id)
			flags.start_draw = false;
		return; end;
		
		
		
		if flags.start_draw then		
			flags.start_draw = false;			
	return; end;	
				-- First Comics --
	return; end;
		if sender == 8 then

--если аттачен объект к курсора не убираем перчу а только скидываем предмет		
		if attached then
			RemoveFromMouse(myid)
			SetObjectPosition(myid,x,y)
			attached=false;
			
		
			if myid==obj.lodka2.id and not flags.lodkanameste then			
				set_visible_object(214,false)				
			end
			takeobj=false
			takeobjecttohand=false;
			if myid == obj.chast1.id then
					set_visible_object(202,true);
					flags.chast1 = false;

					set_obj_size(obj.chast1.id,523,80)
				end;
				if myid == obj.chast2.id then
					set_visible_object(203,true);
					flags.chast2 = false;
				end;
				if myid == obj.chast3.id then
					set_visible_object(205,true);
					flags.chast3 = false;
				end;
				if myid == obj.chast4.id then
					set_visible_object(207,true);
					flags.chast4 = false;
				end;
				if myid == obj.chast5.id then
					set_visible_object(209,true);
					flags.chast5 = false;
				end;
				myid=-1
		return;end;
		HideGlove();		 
		HideScaner();
		HideRentgen()
		HideNvg();				
	return end;
	
if sender == 16 then
--появился рентген картина
	if obj_id ==obj.ray.id then
	CreatePlashechka(9999,"307","goodgirl")	
	return;end;
	
return; end;
	

if sender == 1 then
--тыкнули на лодку в дали чтоб перенести её		
		if obj_id==obj.lodka2.id and attachedID==-1 and myid==-1  then	
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;	
				
			if not glove_on then CreatePlashechka(9999,"72","goodgirl") return;end;		
						myid=obj_id
						add_to_mouse(obj_id)
						x,y=GetObjectPosition(obj_id)
						attached=true
						takeobjecttohand=true
						set_visible_object(214,true)
						setcolor(214,1,1,1,0.5)
			return;end;
--тыкнули лодкой в руке на лодку полупозрачную и тыкаем потом частями на эту лодку, аттачим!			
			if obj_id == 214  then	
				if scaner_on then
					CreatePlashechka(9999,"70","goodgirl")
				return;end;
				if myid==obj.lodka2.id and attached then	
					setcolor(214,1,1,1,1)	
					flags.lodkanameste=true;
					set_visible_object(obj.lodka2.id,false)					
					AddParticleToObject(214,"lodka");
					MoveEmiter("lodka",349,246);
					StartEmiter("lodka")
					myid=-1;
					attached=false
					takeobjecttohand=false
				end	
				if flags.lodkanameste and myid==-1 and not flags.sobrana then CreatePlashechka(9999,"50","goodgirl") return;end		
				if myid== obj.chast1.id then
						speciale_action(2,212, true)
						playeffect("072")
						flags.sbor1 = true;
					
						RemoveFromMouse(obj.chast1.id);	
						set_visible_object(obj.chast1.id,false)
						myid=-1
						attached=false
				end;	
				if myid== obj.chast2.id then
					speciale_action(2,210, true)
					playeffect("072")
						flags.sbor2 = true;
						RemoveFromMouse(obj.chast2.id);
			        	set_visible_object(obj.chast2.id,false)
						myid=-1 
						attached=false
				end;	
				if myid== obj.chast3.id then
					speciale_action(2,215, true)
					playeffect("072")
						flags.sbor3 = true;
						RemoveFromMouse(obj.chast3.id);
						set_visible_object(obj.chast3.id,false)
						myid=-1
						attached=false
						
				end;	
				if myid== obj.chast4.id then
						flags.sbor4 = true;
						speciale_action(2,221, true)
						playeffect("072")
						RemoveFromMouse(obj.chast4.id);
						set_visible_object(obj.chast4.id,false)
						myid=-1
						speciale_action(2,2000,true)
						attached=false
				 end;
				if myid== obj.chast5.id then
					flags.sbor5 = true;
						speciale_action(2,222, true)
						playeffect("072")
						RemoveFromMouse(obj.chast5.id);
						set_visible_object(obj.chast5.id,false)
						myid=-1
						attached=false
				end;	
				takeobj=false
				takeobjecttohand=false
					if flags.sbor1 and flags.sbor2 and flags.sbor3 and flags.sbor4 and flags.sbor5 then					
						StopEmiter( "lodka" );
						Set_Cursor(214,3);
						flags.sobrana= true;			
						HideGlove();
					
						FreeCustomCursor()						
						if flags.items_collected then
							flags.comics2= true;				
							StartTimer(600,1.5);	
							canmenu=true							
								takeobjecttohand=true
							canusegadjets=true
						else			
						CreatePlashechka(69,"55","goodgirl")	
						return; end;				
			return;end
			
		end
			
--тыкнули на скип в комиксе	
		if obj_id == skip_id then			
			MoveObjectY(top_plush_id, -256, -384, 1.5/2);
			MoveObjectY(bottom_plush_id, 640, 769, 1.5/2);
			HideSkipButton()			
			StartTimer(5335,1.5,"lvl8end")
		skip_com=true
			function lvl8end()			
			LevelEnd(9)
			flags.finish=true;	
			end
			
		end;
		
--тыкаем на картину ренгена и она ругается!	
		if obj_id == obj.ray.id then
		CreatePlashechka(9999,"52","goodgirl")
		return; end;			
				
--тыкаем на мусор
		if obj_id == obj.telega.id or obj_id == obj.trubka.id or obj_id == obj.rascheska.id or obj_id == obj.shetka.id or obj_id == obj.galstuk.id or
			obj_id == obj.remen.id or obj_id == obj.cat.id or obj_id == obj.chasi.id or obj_id == obj.botinok.id or obj_id == obj.wlyapa.id or obj_id == obj.karta.id or obj_id == obj.koin1.id or obj_id == obj.koin2.id or obj_id == obj.koin3.id or obj_id == obj.ruchka.id then
			if takeobjecttohand then return;end
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
			if obj_id == obj.telega.id then
				set_visible_object(216,false);
				flags.telega = true;
			end;
			flags.items = flags.items + 1
			
			if flags.items == 15 then
				flags.items_collected = true	
				
			end
			
			CollapseObj(obj_id);
--предметы собраны и лодка тоже пора комикс врубать
			if flags.items==15 and flags.sobrana then
				StartTimer(600,1.5);	
					canmenu=true	
				canusegadjets=true
				takeobjecttohand=true
				if flags.items_collected then
					
				end
			return;end;
		return; end;
--собираем части корабля	

	if obj_id == obj.chast1.id or obj_id == obj.chast2.id or obj_id == obj.chast3.id or obj_id == obj.chast4.id or obj_id == obj.chast5.id then
			if scaner_on then
				CreatePlashechka(9999,"70","goodgirl")
			return;end;
		if not takeobj and not attached then
			if not flags.rentgen then
			CreatePlashechka(9999,"306","goodgirl")
			return;end;
			if glove_on then			
			if not flags.rentgen then
			CreatePlashechka(9999,"306","goodgirl")
			return;end;
				if obj_id == obj.chast1.id then
					set_visible_object(202,false);
					flags.chast1 = true;
				end;
				if obj_id == obj.chast2.id then
					set_visible_object(203,false);
					flags.chast2 = true;
				end;
				if obj_id == obj.chast3.id then
					set_visible_object(205,false);
					flags.chast3 = true;
				end;
				if obj_id == obj.chast4.id then
					set_visible_object(207,false);
					flags.chast4 = true;
				end;
				if obj_id == obj.chast5.id then
					set_visible_object(209,false);
					flags.chast5 = true;
				end;
				--flags.items = flags.items + 1;
				-- CollapseObj(obj_id);
				
				myid=obj_id
				add_to_mouse(obj_id)
				takeobjecttohand=true
				takeobj=true
				playeffect("031")
				x,y=GetObjectPosition(obj_id)
				if obj_id == obj.chast1.id then
				set_obj_size(obj.chast1.id,320,50)	
				end
				
				
				attached=true
				
			
			return; end;
			CreatePlashechka(9999,"49","goodgirl")
		return; end;
		end	
	return; end;

	
	if sender == 14 then -- Menu click
			if obj_id == obj.chast11.id or obj_id == obj.chast21.id or obj_id == obj.chast31.id or obj_id == obj.chast41.id or obj_id == obj.chast51.id then
			if glove_on then
				addObjectToMouse(obj_id,50,50);
				SetCustomCursor(obj.glove.id);			
				set_obj_size(obj_id,50,50)					
			return; end;
			CreatePlashechka(9999,"49","goodgirl")
		return; end;

	return; end;
return; end; 



function SelectRandom()
local dist=-1;local a=-1;local b=-1;local v=100;local t=-1;local diag=-1;
local width = -1;local height = -1;local radius=1.2;
	c("1\n")
	
	if not  flags.lodkanameste and flags.items_collected then	
		computation(obj.lodka2.id);		
	return end;	
	
	
	
	if not flags.sbor2 and flags.items_collected then		
		computation(obj.chast2.id);		
	return;end
	if not flags.sbor3 and flags.items_collected then	
		computation(obj.chast3.id);		
	return	end
	if not flags.sbor4 and flags.items_collected then		
		computation(obj.chast4.id);		
	return	end
	if not flags.sbor5 and flags.items_collected then		
		computation(obj.chast5.id);			
	return end
	if not flags.sbor1 and flags.items_collected then		
		computation(obj.chast1.id);		
		c("\n chast1")
	return;end
	if flags.items_collected then
	c("2\n")
	return;end
	ok = false
	while not ok do
		help_id = GetRandomObject();
		for i,v in pairs(obj) do
			if v.id == help_id and not v.is_collapsed then
				ok = true
				x,y=GetObjectPosition(v.id);
				x1,y1=GetObjectPosition(obj.dragonfly.id);
				width,height = GetObjectSize(v.id)
				a= (x-x1); b= (y-y1);  dist= math.sqrt (a^2+b^2);				
		        t=dist/400;		
                r = (math.sqrt(width^2+height^2)*0.5);		
				
				if r<50 then	r=75;	radius=4;	end  -- при радиусе меньше 50 определяем время кружения и радиус стрекозы
				
				if r>50 and r <100 then	r=87 radius=2.5;  end  --при радиусе больше 50 и меньше 100
				
				if r>100 then 	r=100 	radius=0.75;  end  -- при радиусе больше 100
				
				StartBigTravel(obj.dragonfly.id, v.id, 0, t, r/90, t, 2 ,radius);
			return end
		end
	end
end;
