share/hedgewars/Data/Scripts/SimpleMission.lua
changeset 14811 d65e25e211d4
parent 14484 764ba6182389
child 14812 16d5951d4044
equal deleted inserted replaced
14810:583d8b96fb30 14811:d65e25e211d4
    25 
    25 
    26 ]=]
    26 ]=]
    27 
    27 
    28 HedgewarsScriptLoad("/Scripts/Locale.lua")
    28 HedgewarsScriptLoad("/Scripts/Locale.lua")
    29 HedgewarsScriptLoad("/Scripts/Tracker.lua")
    29 HedgewarsScriptLoad("/Scripts/Tracker.lua")
       
    30 HedgewarsScriptLoad("/Scripts/Utils.lua")
    30 
    31 
    31 --[[
    32 --[[
    32 SimpleMission(params)
    33 SimpleMission(params)
    33 
    34 
    34 This function sets up the *entire* mission and needs one argument: params.
    35 This function sets up the *entire* mission and needs one argument: params.
   219 	else
   220 	else
   220 		return value
   221 		return value
   221 	end
   222 	end
   222 end
   223 end
   223 
   224 
   224 -- Get hypotenuse of a triangle with legs x and y
       
   225 local function hypot(x, y)
       
   226 	local t
       
   227 	x = math.abs(x)
       
   228 	y = math.abs(y)
       
   229 	t = math.min(x, y)
       
   230 	x = math.max(x, y)
       
   231 	if x == 0 then
       
   232 		return 0
       
   233 	end
       
   234 	t = t / x
       
   235 	return x * math.sqrt(1 + t * t)
       
   236 end
       
   237 
       
   238 local errord = false
   225 local errord = false
   239 
   226 
   240 -- This function generates the mission. See above for the meaning of params.
   227 -- This function generates the mission. See above for the meaning of params.
   241 function SimpleMission(params)
   228 function SimpleMission(params)
   242 	if params.missionTitle == nil then
   229 	if params.missionTitle == nil then
   364 				end
   351 				end
   365 				gX, gY = GetGearPosition(_G.sm.goalGears[goal.id1])
   352 				gX, gY = GetGearPosition(_G.sm.goalGears[goal.id1])
   366 				tX, tY = GetGearPosition(_G.sm.goalGears[goal.id2])
   353 				tX, tY = GetGearPosition(_G.sm.goalGears[goal.id2])
   367 			end
   354 			end
   368 
   355 
   369 			local h = hypot(gX - tX, gY - tY)
   356 			local h = integerHypotenuse(gX - tX, gY - tY)
   370 			if goal.relationship == "smallerThan" then
   357 			if goal.relationship == "smallerThan" then
   371 				return h < goal.distance
   358 				return h < goal.distance
   372 			elseif goal.relationship == "greaterThan" then
   359 			elseif goal.relationship == "greaterThan" then
   373 				return h > goal.distance
   360 				return h > goal.distance
   374 			end
   361 			end