
.namespace s14_c01_Hotspot

function OnActivate()

	
	
	if self.Name == "Background_hotspot" and deplace==1	then
		if piecedragged.Name=="cale1" then
			piecedragged.Position_X=cale1posinix
			piecedragged.Position_Y=cale1posiniy
		elseif piecedragged.Name=="cale2" then
			piecedragged.Position_X=cale2posinix
			piecedragged.Position_Y=cale2posiniy
		elseif piecedragged.Name=="cale3" then
			piecedragged.Position_X=cale3posinix
			piecedragged.Position_Y=cale3posiniy
		elseif piecedragged.Name=="cale4" then
			piecedragged.Position_X=cale4posinix
			piecedragged.Position_Y=cale4posiniy
		elseif piecedragged.Name=="cale5" then
			piecedragged.Position_X=cale5posinix
			piecedragged.Position_Y=cale5posiniy
		elseif piecedragged.Name=="cale6" then
			piecedragged.Position_X=cale6posinix
			piecedragged.Position_Y=cale6posiniy
		end
	end
	
	if self.Name == "fondcalehotspot" and deplace==1 then
		
		deplace=0
		
		for l=1,13  do 
			if cursorpos.x < fondcale.Position_X + (l*longcarre) and cursorpos.x > fondcale.Position_X + ((l-1)*longcarre)  then
				col=l
			end
			if cursorpos.y < fondcale.Position_Y + (l*longcarre) and cursorpos.y > fondcale.Position_Y + ((l-1)*longcarre)  then
				ligne=l
			end
		end
		
		lastcale=col+12*(ligne-1)
		
		if piecedragged.Name=="cale1" then
			if tabcale[lastcale]~=0 or tabcale[lastcale-12]~=0 then
				piecedragged.Position_X=cale1posinix
				piecedragged.Position_Y=cale1posiniy
				PlaySoundEffect("gmp_forbiddendrop",true)
			else	
				piecedragged.Position_X=fondcale.Position_X + ((col-1)*longcarre) - valdecalage
				piecedragged.Position_Y=fondcale.Position_Y + ((ligne-1-1)*longcarre) - valdecalage
				tabcale[lastcale]=1
				tabcale[lastcale-12]=1
				calestate[1]=1
				s15_c01.gp_calecount=s15_c01.gp_calecount+1
				calepos[1]=lastcale
				PlaySoundEffect("gmp_dropplank",true)
			end
		elseif piecedragged.Name=="cale2" then
			if tabcale[lastcale]~=0 or tabcale[lastcale-1]~=0 or tabcale[lastcale-12-1]~=0 then
				piecedragged.Position_X=cale2posinix
				piecedragged.Position_Y=cale2posiniy
				PlaySoundEffect("gmp_forbiddendrop",true)
			else	
				piecedragged.Position_X=fondcale.Position_X + ((col-1-1)*longcarre) - valdecalage
				piecedragged.Position_Y=fondcale.Position_Y + ((ligne-1-1)*longcarre) - 20
				tabcale[lastcale]=1
				tabcale[lastcale-1]=1
				tabcale[lastcale-12-1]=1
				calestate[2]=1
				s15_c01.gp_calecount=s15_c01.gp_calecount+1
				calepos[2]=lastcale
				PlaySoundEffect("gmp_dropplank",true)
			end
		elseif piecedragged.Name=="cale3" then
			if tabcale[lastcale]~=0 or tabcale[lastcale-1]~=0 or tabcale[lastcale-12-1]~=0 or tabcale[lastcale-12-2]~=0 then
				piecedragged.Position_X=cale3posinix
				piecedragged.Position_Y=cale3posiniy
				PlaySoundEffect("gmp_forbiddendrop",true)
			else	
				piecedragged.Position_X=fondcale.Position_X + ((col-1-2)*longcarre) - valdecalage
				piecedragged.Position_Y=fondcale.Position_Y + ((ligne-1-1)*longcarre) - 20
				tabcale[lastcale]=1
				tabcale[lastcale-1]=1
				tabcale[lastcale-12-1]=1
				tabcale[lastcale-12-2]=1
				calestate[3]=1
				s15_c01.gp_calecount=s15_c01.gp_calecount+1
				calepos[3]=lastcale
				PlaySoundEffect("gmp_dropplank",true)
			end
		elseif piecedragged.Name=="cale4" then
			if tabcale[lastcale]~=0 or tabcale[lastcale-12]~=0 or tabcale[lastcale-24]~=0 or tabcale[lastcale-24-1]~=0 or tabcale[lastcale-24+1]~=0 then
				piecedragged.Position_X=cale4posinix
				piecedragged.Position_Y=cale4posiniy
				PlaySoundEffect("gmp_forbiddendrop",true)
			else	
				piecedragged.Position_X=fondcale.Position_X + ((col-1-1)*longcarre) - valdecalage
				piecedragged.Position_Y=fondcale.Position_Y + ((ligne-1-2)*longcarre) - 20
				tabcale[lastcale]=1
				tabcale[lastcale-12]=1
				tabcale[lastcale-24]=1
				tabcale[lastcale-24-1]=1
				tabcale[lastcale-24+1]=1
				calestate[4]=1
				s15_c01.gp_calecount=s15_c01.gp_calecount+1
				calepos[4]=lastcale
				PlaySoundEffect("gmp_dropplank",true)
			end	
		elseif piecedragged.Name=="cale5" then
			if tabcale[lastcale]~=0 or tabcale[lastcale-12]~=0 or tabcale[lastcale-12-1]~=0 or tabcale[lastcale-12-2]~=0 or tabcale[lastcale-24-2]~=0 then
				piecedragged.Position_X=cale5posinix
				piecedragged.Position_Y=cale5posiniy
				PlaySoundEffect("gmp_forbiddendrop",true)
			else	
				piecedragged.Position_X=fondcale.Position_X + ((col-1-2)*longcarre) - valdecalage
				piecedragged.Position_Y=fondcale.Position_Y + ((ligne-1-2)*longcarre) - valdecalage
				tabcale[lastcale]=1
				tabcale[lastcale-12]=1
				tabcale[lastcale-12-1]=1
				tabcale[lastcale-12-2]=1
				tabcale[lastcale-24-2]=1
				calestate[5]=1
				s15_c01.gp_calecount=s15_c01.gp_calecount+1
				calepos[5]=lastcale
				PlaySoundEffect("gmp_dropplank",true)
			end	
		elseif piecedragged.Name=="cale6" then
			if tabcale[lastcale]~=0 or tabcale[lastcale-1]~=0 or tabcale[lastcale-12]~=0 or tabcale[lastcale-24]~=0 or tabcale[lastcale-24-1]~=0 then
				piecedragged.Position_X=cale6posinix
				piecedragged.Position_Y=cale6posiniy
				PlaySoundEffect("gmp_forbiddendrop",true)
			else	
				piecedragged.Position_X=fondcale.Position_X + ((col-1-1)*longcarre) - valdecalage
				piecedragged.Position_Y=fondcale.Position_Y + ((ligne-1-2)*longcarre) - valdecalage
				tabcale[lastcale]=1
				tabcale[lastcale-1]=1
				tabcale[lastcale-12]=1
				tabcale[lastcale-24]=1
				tabcale[lastcale-24-1]=1
				calestate[6]=1
				s15_c01.gp_calecount=s15_c01.gp_calecount+1
				calepos[6]=lastcale
				PlaySoundEffect("gmp_dropplank",true)
			end	
		end
		
		
		
		
	end
	
end

function OnEnable()
	AreaHotspot.OnEnable()
end

function GetSpecificCursor()
	if self.Name == "fondcalehotspot" then
		return 0
	elseif self.Name == "Background_hotspot" then
		return 0	
	else
		return CURSOR_AREA_HOTSPOT
	end
end

function PrivateCanClickOn()
	return true
end

function OnDropObject()
	OPLog.Log("drop "..self.Name)
	if IsEqualVariables("CurrentObject","InventoryCorde") and (self.Name == "Background_hotspot" or self.Name == "fondcalehotspot") then
		SampleLevel.Set("s15_c01_cale",true)
		PlaySoundEffect("gmp_addplanks")
		InventoryManager.RemoveFromInventory("InventoryCorde")
		gamestart=true
		cale1.Enabled=true
		cale2.Enabled=true
		cale3.Enabled=true
		cale4.Enabled=true
		cale5.Enabled=true
		cale6.Enabled=true
		SequencePlayer.PlaySequence("GP_1505",s15_c01,nil)
		return true
	end
	return false
end

