function RandomPosition(latitudeMin,latitudeMax,longitudeMin,longitudeMax)
local lat_var = math.random(1,(10^13)) --random number between 1 and 10^13
local lon_var = math.random(1,(10^13)) --random number between 1 and 10^13
local pos_lat = math.random(latitudeMin,latitudeMax) + (lat_var/(10^13)) --latitude;
local pos_lon = math.random(longitudeMin,longitudeMax) + (lon_var/(10^13)) --longitude;
return {latitude=pos_lat,longitude=pos_lon}
end
function CircularRandomPosition(x_latitude, x_longitude, max_radius)
local randomisationCircle = World_GetCircleFromPoint({
latitude=x_latitude,
longitude=x_longitude,
radius=math.random(0.1,max_radius),
numpoints = 72})
local randomisedPoint = randomisationCircle[math.random(1,#randomisationCircle)]
return randomisedPoint
end
function ShuffleTable( t )
local rand = math.random
assert( t, "ShuffleTable() expected a table, got nil" )
local iterations = #t
local j
for i = iterations, 2, -1 do
j = rand(i)
t[i], t[j] = t[j], t[i]
end
end
function ChangeScore(side,amt,reason)
local newScore = ScenEdit_GetScore(side) + amt
ScenEdit_SetScore(side,newScore,reason)
print (side..' score changed to '..newScore)
return newScore
end
function CleanUpIdleCivilianShips()
local unitList = VP_GetSide({side='Civilian'}).units
local numberOfCivilianUnits = #unitList
local numberOfUnitsDeleted = 0
for k,v in ipairs (unitList) do
local unit = ScenEdit_GetUnit({guid=v.guid})
if (unit.course[1] == nil or unit.speed == 0) and
unit.type == 'Ship' then
ScenEdit_DeleteUnit({guid=v.guid})
numberOfUnitsDeleted = numberOfUnitsDeleted + 1
end
end
if DebugModeIsOn() and numberOfUnitsDeleted > 0 then
ScenEdit_SpecialMessage('playerside','Civ_Cleanup fired.
Initial civilian Units: '..numberOfCivilianUnits..'
Civilian units cleaned up: '..numberOfUnitsDeleted)
end
end
function OverWater (latitude, longitude)
local pointElevation = World_GetElevation({
latitude = latitude,
longitude = longitude})
if pointElevation < 0 then
return true
else
return false
end
end
function ConvertDecimalPositionToDegrees(latitude,longitude)
local latitidePrefix, longitudePrefix
if latitude > 0 then
latitidePrefix = "N"
else
latitidePrefix = "S"
latitude = latitude*-1
end
local latitudeDegrees = math.floor(latitude)
local latitudeMinutes = math.floor((latitude - latitudeDegrees)*60)
local latitudeSeconds = (((latitude-latitudeDegrees)*60) - latitudeMinutes)*60
latitudeSeconds = Round(latitudeSeconds, 0)
if longitude > 0 then
longitudePrefix = "E"
else
longitudePrefix = "W"
longitude = longitude*-1
end
local longitudeDegrees = math.floor(longitude)
local longitudeMinutes = math.floor((longitude - longitudeDegrees)*60)
local longitudeSeconds = (((longitude-longitudeDegrees)*60) - longitudeMinutes)*60
longitudeSeconds = Round(longitudeSeconds, 0)
local result = (latitidePrefix..latitudeDegrees .. "°" .. latitudeMinutes .. "'" .. latitudeSeconds .. '", '..
longitudePrefix..longitudeDegrees .. "°" .. longitudeMinutes .. "'" .. longitudeSeconds .. '"')
return result
end
------------------Comms
function DTG(TimeVar)
if TimeVar == nil then
TimeVar = ScenEdit_CurrentTime()
end
local msgtime = os.date("!%d%H%M" .. "Z" .. " " .. "%b %y", TimeVar)
local msgtime = string.upper(msgtime)
return msgtime
end
function GenerateRadioMessageBody(theMessage,callsign)
local result
if callsign == nil then callsign = 'unknown station' end
result = '
'..string.upper(callsign)..'
"'..theMessage..'"
"..DTG..'
'..band..'
'..frequency..'
'..rec_station..'
'..
'DE '..snd_station..'
'..
precedence..' '..dtg..'
'..
'fm '..from..'
'..
'to '..to..'
'..
'wd gr'..gr..'
'..
'bt
'..
classification..'
'..
body..'
'..
'bt
'..
'nnnn