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..'"

' return result end function RadioMessage(band,frequency,theMessage,location) assert(theMessage,'RadioMessage(): No message passed!') local DTG = DTG() local theMessage = "

"..DTG..'
'..band..'
'..frequency..'

'..theMessage if location ~= nil then ScenEdit_SpecialMessage('playerside',theMessage,{latitude=location.latitude,longitude=location.longitude}) else ScenEdit_SpecialMessage('playerside',theMessage) end end function ACP126(rec_station,snd_station,precedence,from,to,classification,body) --rec_station --4 letter code (e.g. YDCX) --snd_station --4 letter code +/- NR 3 number (e.g. YBDN NR 270) --precedence --Flash (Z), Immediate (O), Priority (P), Routine (R), Flash Override (Y) local dtg = DTG() --from --e.g. MET FLT OPS --to --e.g. SSN 21 SEAWOLF --classification --Unclass +/- SBU / FOUO / NOFORN (Restricted), Confidential, Secret, Top Secret --body _,gr = body:gsub("%S+","") local sig_string = string.upper('

'..rec_station..'
'.. 'DE '..snd_station..'
'.. precedence..' '..dtg..'
'.. 'fm '..from..'
'.. 'to '..to..'
'.. 'wd gr'..gr..'
'.. 'bt
'.. classification..'
'.. body..'
'.. 'bt
'.. 'nnnn

') return sig_string end function TelexMessageToPlayer(rec_station, snd_station, precedence, from, to, classification, body, location) local theMessage = ACP126(rec_station, snd_station, precedence, from, to, classification, body) if location ~= nil then ScenEdit_SpecialMessage('playerside',theMessage,{latitude=location.latitude,longitude=location.longitude}) else ScenEdit_SpecialMessage('playerside',theMessage) end end ------------Weather function GenerateRainDescriptor(rain) local result if rain == 0 then result = 'nil' elseif rain < 5 then result = 'very light' elseif rain < 11 then result = 'light' elseif rain < 20 then result = 'moderate' elseif rain < 30 then result = 'heavy' elseif rain < 40 then result = 'very heavy' else result = 'extreme' end return result end function GenerateCloudDescriptor(cloud) local result if cloud == 0 then result = 'clear skies' elseif cloud < 0.2 then result = 'light low clouds' elseif cloud < 0.3 then result = 'light middle clouds' elseif cloud < 0.4 then result = 'light high clouds' elseif cloud < 0.5 then result = 'moderate low clouds' elseif cloud < 0.6 then result = 'moderate middle clouds' elseif cloud < 0.7 then result = 'moderate high clouds' elseif cloud < 0.8 then result = 'moderate middle clouds & light high clouds' elseif cloud < 0.9 then result = 'solid middle clouds & moderate high clouds' elseif cloud < 1.0 then result = 'thin fog & solid cloud cover' else result = 'thick fog & solid cloud cover' end return result end function ConvertTempCtoF(temp) local result = Round((temp*1.8) + 32,0) return result end function WeatherReport(outlook) if outlook == nil then outlook = 'next forecast at '..DTG(ScenEdit_CurrentTime()+21600) end local weather, DTG = ScenEdit_GetWeather(), DTG() local tempC, tempF, cloud, rain, sea = weather.temp, ConvertTempCtoF(weather.temp), GenerateCloudDescriptor(weather.undercloud), GenerateRainDescriptor(weather.rainfall), weather.seastate TelexMessageToPlayer( 'ALL', 'METOc', 'r', 'Naval Meteorology and Oceanography Command', 'ALL STATIONS', 'unclass', 'WX REPORT '..DTG..' - strait of hormuz
AVERAGE TEMP '..tempC..'°C / '..tempF..'°F
SEA STATE '..sea..'
'..rain..' PRECIPITATION
'..cloud..'
'..outlook, nil ) end function WeatherDrift() local weatherBaseline = { seastate = 1, temp = 23, undercloud = 0.30000000, rainfall = 0 } local seastateVariability = math.random(0,2) local undercloudVariability = 0 local tempVariability = math.random(-1,4) local rainfallVariability = 0 local newTemp = weatherBaseline.temp + tempVariability local newRainfall = weatherBaseline.rainfall + rainfallVariability local newUndercloud = weatherBaseline.undercloud + undercloudVariability local newSeastate = weatherBaseline.seastate + seastateVariability ScenEdit_SetWeather( newTemp, --temp newRainfall, --rainfall newUndercloud, --undercloud newSeastate --seastate ) end function TimeIs(timeVar) if timeVar == nil then timeVar = ScenEdit_CurrentTime() end local timeStampTable = os.date("!*t",timeVar) local timeTable = {day = timeStampTable.day, hour = timeStampTable.hour, minute = timeStampTable.min} return timeTable end function WeatherReportIsDue() local result = false local hourZulu = TimeIs().hour local hourLocal = hourZulu + scenarioZuluOffset if hourLocal %6 == 0 then result = true end return result end