Astro Update

**COORDINATE**
* Added functions to get sunrise and sunset times.

**UTILS**
* Added functions to calculate sunset and sunrise
* Added function to replace illegal characters.

**AIRBOSS v1.1.5**
* Fixed wrong function name when recovery is resumed.
* Replace illegcal characters in player names when writing trapsheet.
This commit is contained in:
Frank
2020-05-24 23:33:21 +02:00
parent 21652de804
commit 61bb59d8b3
3 changed files with 498 additions and 6 deletions

View File

@@ -1969,6 +1969,240 @@ do -- COORDINATE
return InSphere
end
--- Get sun rise time for a specific date at the coordinate.
-- @param #COORDINATE self
-- @param #number Day The day.
-- @param #number Month The month.
-- @param #number Year The year.
-- @param #boolean InSeconds If true, return the sun rise time in seconds.
-- @return #string Sunrise time, e.g. "05:41".
function COORDINATE:GetSunriseAtDate(Day, Month, Year, InSeconds)
-- Day of the year.
local DayOfYear=UTILS.GetDayOfYear(Year, Month, Day)
local Latitude, Longitude=self:GetLLDDM()
local Tdiff=UTILS.GMTToLocalTimeDifference()
local sunrise=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, true, Tdiff)
if InSeconds then
return sunrise
else
return UTILS.SecondsToClock(sunrise, true)
end
end
--- Get todays sun rise time.
-- @param #COORDINATE self
-- @param #boolean InSeconds If true, return the sun rise time in seconds.
-- @return #string Sunrise time, e.g. "05:41".
function COORDINATE:GetSunrise(InSeconds)
-- Get current day of the year.
local DayOfYear=UTILS.GetMissionDayOfYear()
-- Lat and long at this point.
local Latitude, Longitude=self:GetLLDDM()
-- GMT time diff.
local Tdiff=UTILS.GMTToLocalTimeDifference()
-- Sunrise in seconds of the day.
local sunrise=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, true, Tdiff)
-- Debug output.
--self:I(string.format("Sun rise at lat=%.3f long=%.3f on %s + %d days (DayOfYear=%d): %s (GMT %d)", Latitude, Longitude, date, x, DayOfYear, UTILS.SecondsToClock(sunrise), Tdiff))
if InSeconds then
return sunrise
else
return UTILS.SecondsToClock(sunrise, true)
end
end
--- Get minutes until the next sun rise at this coordinate.
-- @param #COORDINATE self
-- @param OnlyToday If true, only calculate the sun rise of today. If sun has already risen, the time in negative minutes since sunrise is reported.
-- @return #number Minutes to the next sunrise.
function COORDINATE:GetMinutesToSunrise(OnlyToday)
-- Seconds of today
local time=UTILS.SecondsOfToday()
-- Next Sunrise in seconds.
local sunrise=nil
-- Time to sunrise.
local delta=nil
if OnlyToday then
---
-- Sunrise of today
---
sunrise=self:GetSunrise(true)
delta=sunrise-time
else
---
-- Sunrise of tomorrow
---
-- Tomorrows day of the year.
local DayOfYear=UTILS.GetMissionDayOfYear()+1
local Latitude, Longitude=self:GetLLDDM()
local Tdiff=UTILS.GMTToLocalTimeDifference()
sunrise=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, true, Tdiff)
delta=sunrise+UTILS.SecondsToMidnight()
end
return delta/60
end
--- Check if it is day, i.e. if the sun has risen about the horizon at this coordinate.
-- @param #COORDINATE self
-- @return #boolean If true, it is day. If false, it is night time.
function COORDINATE:IsDay()
-- Todays sun rise in sec.
local sunrise=self:GetSunrise(true)
-- Todays sun set in sec.
local sunset=self:GetSunset(true)
-- Seconds passed since midnight.
local time=UTILS.SecondsOfToday()
-- Check if time is between sunrise and sunset.
if time>sunrise and time<=sunset then
return true
else
return false
end
end
--- Check if it is night, i.e. if the sun has set below the horizon at this coordinate.
-- @param #COORDINATE self
-- @return #boolean If true, it is night. If false, it is day time.
function COORDINATE:IsNight()
return not self:IsDay()
end
--- Get sun set time for a specific date at the coordinate.
-- @param #COORDINATE self
-- @param #number Day The day.
-- @param #number Month The month.
-- @param #number Year The year.
-- @param #boolean InSeconds If true, return the sun rise time in seconds.
-- @return #string Sunset time, e.g. "20:41".
function COORDINATE:GetSunsetAtDate(Day, Month, Year, InSeconds)
-- Day of the year.
local DayOfYear=UTILS.GetDayOfYear(Year, Month, Day)
local Latitude, Longitude=self:GetLLDDM()
local Tdiff=UTILS.GMTToLocalTimeDifference()
local sunset=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, false, Tdiff)
if InSeconds then
return sunset
else
return UTILS.SecondsToClock(sunset, true)
end
end
--- Get todays sun set time.
-- @param #COORDINATE self
-- @param #boolean InSeconds If true, return the sun set time in seconds.
-- @return #string Sunrise time, e.g. "20:41".
function COORDINATE:GetSunset(InSeconds)
-- Get current day of the year.
local DayOfYear=UTILS.GetMissionDayOfYear()
-- Lat and long at this point.
local Latitude, Longitude=self:GetLLDDM()
-- GMT time diff.
local Tdiff=UTILS.GMTToLocalTimeDifference()
-- Sunrise in seconds of the day.
local sunrise=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, false, Tdiff)
-- Debug output.
--self:I(string.format("Sun rise at lat=%.3f long=%.3f on %s + %d days (DayOfYear=%d): %s (GMT %d)", Latitude, Longitude, date, x, DayOfYear, UTILS.SecondsToClock(sunrise), Tdiff))
if InSeconds then
return sunrise
else
return UTILS.SecondsToClock(sunrise, true)
end
end
--- Get minutes until the next sun set at this coordinate.
-- @param #COORDINATE self
-- @param OnlyToday If true, only calculate the sun set of today. If sun has already set, the time in negative minutes since sunset is reported.
-- @return #number Minutes to the next sunrise.
function COORDINATE:GetMinutesToSunset(OnlyToday)
-- Seconds of today
local time=UTILS.SecondsOfToday()
-- Next Sunset in seconds.
local sunset=nil
-- Time to sunrise.
local delta=nil
if OnlyToday then
---
-- Sunset of today
---
sunset=self:GetSunset(true)
delta=sunset-time
else
---
-- Sunset of tomorrow
---
-- Tomorrows day of the year.
local DayOfYear=UTILS.GetMissionDayOfYear()+1
local Latitude, Longitude=self:GetLLDDM()
local Tdiff=UTILS.GMTToLocalTimeDifference()
sunset=UTILS.GetSunRiseAndSet(DayOfYear, Latitude, Longitude, false, Tdiff)
delta=sunset+UTILS.SecondsToMidnight()
end
return delta/60
end
--- Return a BR string from a COORDINATE to the COORDINATE.
-- @param #COORDINATE self
@@ -2036,6 +2270,14 @@ do -- COORDINATE
return ""
end
--- Get Latitude and Longitude in Degrees Decimal Minutes (DDM).
-- @param #COORDINATE self
-- @return #number Latitude in DDM.
-- @return #number Lontitude in DDM.
function COORDINATE:GetLLDDM()
return coord.LOtoLL( self:GetVec3() )
end
--- Provides a Lat Lon string in Degree Minute Second format.
-- @param #COORDINATE self
-- @param Core.Settings#SETTINGS Settings (optional) The settings. Can be nil, and in this case the default settings are used. If you want to specify your own settings, use the _SETTINGS object.