Added metric functions for cruisealt.

Fixed bugs regarding coalitions.
Adjusted gaussian distribution for cruise alt.
This commit is contained in:
funkyfranky 2017-09-15 00:02:29 +02:00
parent 0a2f7c031d
commit 09f61610c1

View File

@ -86,7 +86,7 @@
-- @field #table departure_ports Array containing the names of the destination airports. -- @field #table departure_ports Array containing the names of the destination airports.
-- @field #table destination_ports Array containing the names of the destination airports. -- @field #table destination_ports Array containing the names of the destination airports.
-- @field #table ratcraft Array with the spawned RAT aircraft. -- @field #table ratcraft Array with the spawned RAT aircraft.
-- @field #number Tinactive Time in seconds after which inactive units will be destroyed. Default is 180 seconds. -- @field #number Tinactive Time in seconds after which inactive units will be destroyed. Default is 300 seconds.
-- @field #boolean reportstatus Aircraft report status. -- @field #boolean reportstatus Aircraft report status.
-- @field #number statusinterval Intervall between status checks (and reports if enabled). -- @field #number statusinterval Intervall between status checks (and reports if enabled).
-- @field #boolean placemarkers Place markers of waypoints on F10 map. -- @field #boolean placemarkers Place markers of waypoints on F10 map.
@ -265,7 +265,7 @@ RAT={
departure_ports={}, -- Array containing the names of the departure airports. departure_ports={}, -- Array containing the names of the departure airports.
destination_ports={}, -- Array containing the names of the destination airports. destination_ports={}, -- Array containing the names of the destination airports.
ratcraft={}, -- Array with the spawned RAT aircraft. ratcraft={}, -- Array with the spawned RAT aircraft.
Tinactive=180, -- Time in seconds after which inactive units will be destroyed. Default is 180 seconds. Tinactive=300, -- Time in seconds after which inactive units will be destroyed. Default is 300 seconds.
reportstatus=false, -- Aircraft report status. reportstatus=false, -- Aircraft report status.
statusinterval=30, -- Intervall between status checks (and reports if enabled). statusinterval=30, -- Intervall between status checks (and reports if enabled).
placemarkers=false, -- Place markers of waypoints on F10 map. placemarkers=false, -- Place markers of waypoints on F10 map.
@ -394,7 +394,7 @@ RAT.id="RAT | "
--DONE: Improve behaviour when no destination or departure airports were found. Leads to crash, e.g. 1184: attempt to get length of local 'destinations' (a nil value) --DONE: Improve behaviour when no destination or departure airports were found. Leads to crash, e.g. 1184: attempt to get length of local 'destinations' (a nil value)
--DONE: Check cases where aircraft get shot down. --DONE: Check cases where aircraft get shot down.
--DONE: Handle the case where more than 10 RAT objects are spawned. Likewise, more than 10 groups of one object. Causes problems with the number of menu items! ==> not now! --DONE: Handle the case where more than 10 RAT objects are spawned. Likewise, more than 10 groups of one object. Causes problems with the number of menu items! ==> not now!
--TODO: Add custom livery choice if possible. --DONE: Add custom livery choice if possible.
--TODO: When only a destination is set, it should be checked that the departure is within range. Also, that departure and destination are not the same. --TODO: When only a destination is set, it should be checked that the departure is within range. Also, that departure and destination are not the same.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -557,9 +557,7 @@ function RAT:SetCoalition(friendly)
elseif friendly:lower()=="red" then elseif friendly:lower()=="red" then
self.friendly=RAT.coal.red self.friendly=RAT.coal.red
elseif friendly:lower()=="redonly" then elseif friendly:lower()=="redonly" then
self.friendly=RAT.coal.red self.friendly=RAT.coal.redonly
elseif friendly:lower()=="blue" then
self.friendly=RAT.coal.blue
elseif friendly:lower()=="neutral" then elseif friendly:lower()=="neutral" then
self.friendly=RAT.coal.neutral self.friendly=RAT.coal.neutral
else else
@ -727,7 +725,7 @@ function RAT:RespawnAfterLanding(delay)
self.respawn_delay=delay self.respawn_delay=delay
end end
--- Set the time after which inactive groups will be destroyed. Default is 180 seconds. --- Set the time after which inactive groups will be destroyed. Default is 300 seconds.
-- @param #RAT self -- @param #RAT self
-- @param #number time Time in seconds. -- @param #number time Time in seconds.
function RAT:TimeDestroyInactive(time) function RAT:TimeDestroyInactive(time)
@ -844,6 +842,13 @@ function RAT:SetFLmax(height)
self.FLmaxuser=height*RAT.unit.FL2m self.FLmaxuser=height*RAT.unit.FL2m
end end
--- Set max cruising altitude above sea level.
-- @param #RAT self
-- @param #number alt Altitude ASL in meters.
function RAT:SetMaCruiseAltitude(alt)
self.FLmaxuser=alt
end
--- Set min flight level. Setting this value will overrule all other logic. Aircraft will try to fly at higher than this FL regardless. --- Set min flight level. Setting this value will overrule all other logic. Aircraft will try to fly at higher than this FL regardless.
-- @param #RAT self -- @param #RAT self
-- @param #number height Maximum FL in hundrets of feet. -- @param #number height Maximum FL in hundrets of feet.
@ -851,6 +856,13 @@ function RAT:SetFLmin(height)
self.FLminuser=height*RAT.unit.FL2m self.FLminuser=height*RAT.unit.FL2m
end end
--- Set min cruising altitude above sea level.
-- @param #RAT self
-- @param #number alt Altitude ASL in meters.
function RAT:SetMinCruiseAltitude(alt)
self.FLminuser=alt
end
--- Set flight level of cruising part. This is still be checked for consitancy with selected route and prone to radomization. --- Set flight level of cruising part. This is still be checked for consitancy with selected route and prone to radomization.
-- Default is FL200 for planes and FL005 for helicopters. -- Default is FL200 for planes and FL005 for helicopters.
-- @param #RAT self -- @param #RAT self
@ -859,6 +871,13 @@ function RAT:SetFLcruise(height)
self.aircraft.FLcruise=height*RAT.unit.FL2m self.aircraft.FLcruise=height*RAT.unit.FL2m
end end
--- Set cruising altitude. This is still be checked for consitancy with selected route and prone to radomization.
-- @param #RAT self
-- @param #number alt Cruising altitude ASL in meters.
function RAT:SetCruiseAltitude(alt)
self.aircraft.FLcruise=alt
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Initialize basic parameters of the aircraft based on its (template) group in the mission editor. --- Initialize basic parameters of the aircraft based on its (template) group in the mission editor.
@ -1091,9 +1110,6 @@ function RAT:_SetRoute(takeoff, _departure, _destination)
-- Min cruise speed 70% of max cruise or 600 km/h whichever is lower. -- Min cruise speed 70% of max cruise or 600 km/h whichever is lower.
local VxCruiseMin = math.min(VxCruiseMax*0.70, 166) local VxCruiseMin = math.min(VxCruiseMax*0.70, 166)
-- Cruise speed (randomized).
--local VxCruise = self:_Randomize((VxCruiseMax-VxCruiseMin)/2+VxCruiseMin, 0.3 , VxCruiseMin, VxCruiseMax)
-- Cruise speed (randomized). Expectation value at midpoint between min and max. -- Cruise speed (randomized). Expectation value at midpoint between min and max.
local VxCruise = self:_Random_Gaussian((VxCruiseMax-VxCruiseMin)/2+VxCruiseMin, (VxCruiseMax-VxCruiseMax)/4, VxCruiseMin, VxCruiseMax) local VxCruise = self:_Random_Gaussian((VxCruiseMax-VxCruiseMin)/2+VxCruiseMin, (VxCruiseMax-VxCruiseMax)/4, VxCruiseMin, VxCruiseMax)
@ -1167,6 +1183,13 @@ function RAT:_SetRoute(takeoff, _departure, _destination)
H_departure=Pdeparture.y H_departure=Pdeparture.y
end end
-- Adjust min distance between departure and destination for user set min flight level.
if self.FLminuser then
self.mindist=self:_MinDistance(AlphaClimb, AlphaDescent, self.FLminuser-H_departure)
local text=string.format("Adjusting min distance to %d km (for given min FL%03d)", self.mindist/1000, self.FLminuser/RAT.unit.FL2m)
env.info(RAT.id..text)
end
-- DESTINATION AIRPORT -- DESTINATION AIRPORT
local destination=nil local destination=nil
if _destination then if _destination then
@ -1285,8 +1308,13 @@ function RAT:_SetRoute(takeoff, _departure, _destination)
FLmax=self.FLmaxuser FLmax=self.FLmaxuser
end end
-- Set cruise altitude: default with 100% randomization but limited to FLmin and FLmax. -- Adjust FLcruise to be at leat FLmin and at most FLmax
--local FLcruise=self:_Randomize(self.aircraft.FLcruise, 1.0, FLmin, FLmax) if self.aircraft.FLcruise<FLmin then
self.aircraft.FLcruise=FLmin
end
if self.aircraft.FLcruise>FLmax then
self.aircraft.FLcruise=FLmax
end
-- Set cruise altitude. Selected from Gaussian distribution but limited to FLmin and FLmax. -- Set cruise altitude. Selected from Gaussian distribution but limited to FLmin and FLmax.
local FLcruise=self:_Random_Gaussian(self.aircraft.FLcruise, (FLmax-FLmin)/4, FLmin, FLmax) local FLcruise=self:_Random_Gaussian(self.aircraft.FLcruise, (FLmax-FLmin)/4, FLmin, FLmax)
@ -2363,6 +2391,18 @@ function RAT:_FLmax(alpha, beta, d, phi, h0)
return h3+h0 return h3+h0
end end
--- Calculate min distance between departure and destination for given minimum flight level and climb/decent rates
-- @param #RAT self
-- @param #number alpha Angle of climb [rad].
-- @param #number beta Angle of descent [rad].
-- @param #number h min height AGL.
-- @return #number Minimum distance between departure and destiantion.
function RAT:_MinDistance(alpha, beta, h)
local d1=h/math.tan(alpha)
local d2=h/math.tan(beta)
return d1+d2
end
--- Test if an airport exists on the current map. --- Test if an airport exists on the current map.
-- @param #RAT self -- @param #RAT self
@ -2521,11 +2561,23 @@ function RAT:_Random_Gaussian(x0, sigma, xmin, xmax)
-- Cut-off distribution at xmin. -- Cut-off distribution at xmin.
if xmin then if xmin then
r=math.max(r, xmin) if r<xmin then
if xmax then
r=math.min(math.max(x0,xmin), xmax)
else
r=math.max(x0,xmin)
end
end
end end
-- Cut-off distribution at xmax. -- Cut-off distribution at xmax.
if xmax then if xmax then
r=math.min(r, xmax) if r>xmax then
if xmin then
r=math.max(math.min(x0,xmax),xmin)
else
r=math.min(x0,xmax)
end
end
end end
return r return r
@ -2607,15 +2659,7 @@ function RAT:_ModifySpawnTemplate(waypoints)
if self:_GetSpawnIndex(self.SpawnIndex+1) then if self:_GetSpawnIndex(self.SpawnIndex+1) then
local SpawnTemplate = self.SpawnGroups[self.SpawnIndex].SpawnTemplate
local scratch=false
local SpawnTemplate
if not scratch then
-- Get copy of spawn template.
SpawnTemplate = self.SpawnGroups[self.SpawnIndex].SpawnTemplate
else
SpawnTemplate=self:_InitSpawnTemplate()
end
if SpawnTemplate then if SpawnTemplate then
self:T(SpawnTemplate) self:T(SpawnTemplate)
@ -2637,17 +2681,12 @@ function RAT:_ModifySpawnTemplate(waypoints)
SpawnTemplate.units[UnitID].alt = PointVec3.y SpawnTemplate.units[UnitID].alt = PointVec3.y
SpawnTemplate.units[UnitID].heading = math.rad(heading) SpawnTemplate.units[UnitID].heading = math.rad(heading)
-- Set another livery. -- Set (another) livery.
env.info("Livery template:"..SpawnTemplate.units[UnitID].livery_id)
if self.livery then if self.livery then
local skin=self.livery[math.random(#self.livery)]
if not (skin:lower()=="default" or skin:lower()=="template") then
SpawnTemplate.units[UnitID].livery_id = self.livery[math.random(#self.livery)] SpawnTemplate.units[UnitID].livery_id = self.livery[math.random(#self.livery)]
end end
env.info("Livery modified:"..SpawnTemplate.units[UnitID].livery_id)
end
SpawnTemplate.units[UnitID]["type"] = "Tu-142" --SpawnTemplate.units[UnitID]["type"] = "Tu-142"
-- Set AI skill. -- Set AI skill.
SpawnTemplate.units[UnitID]["skill"] = self.skill SpawnTemplate.units[UnitID]["skill"] = self.skill
@ -2679,62 +2718,4 @@ function RAT:_ModifySpawnTemplate(waypoints)
end end
end end
--- Set up the basic spawn template. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- @param #RAT self
function RAT:_InitSpawnTemplate()
local template =
{
["modulation"] = 0,
["tasks"] = {},
["task"] = "Transport",
["uncontrolled"] = false,
["route"] =
{
["points"] = {},
},
["groupId"] = 1,
["hidden"] = false,
["y"] = 0,
["x"] = 0,
["name"] = "DictKey_GroupName_5",
["communication"] = true,
["start_time"] = 0,
["frequency"] = 251,
["units"] = {}, -- end of ["units"]
}
return template
end
--- Initialize a unit of the spawn template.
-- @param #RAT self
function RAT:_InitSpawnUnit()
local unit =
{
["country"]=country.id.USA,
["name"] = "DictKey_UnitName_6",
["alt"] = 30,
["alt_type"] = "BARO",
["livery_id"] = "Aeroflot",
["skill"] = "High",
["parking"] = "31",
["speed"] = 0,
["type"] = "Yak-40",
["unitId"] = 1,
["psi"] = 0, --3.1270847373636
["parking_id"] = "23",
["x"] = 0,
["y"] = 0,
["heading"] = 0,
["callsign"] = 101,
["onboard_num"] = "010",
["payload"] =
{
["pylons"] = {},
["fuel"] = "3080",
["flare"] = 0,
["chaff"] = 0,
["gun"] = 100,
}, -- end of ["payload"]
}
return unit
end