Added option to respawn after landing.

Changed default to respawn after engine shut-down.
This commit is contained in:
funkyfranky
2017-09-08 00:33:31 +02:00
parent f79143095e
commit e4e1990657

View File

@@ -47,6 +47,8 @@
-- @field #number alive -- @field #number alive
-- @field #boolean f10menu -- @field #boolean f10menu
-- @field #table Menu -- @field #table Menu
-- @field #boolean respawn_after_landing
-- @field #number respawn_delay
-- @field #table RAT -- @field #table RAT
-- @extends Functional.Spawn#SPAWN -- @extends Functional.Spawn#SPAWN
@@ -92,6 +94,8 @@ RAT={
alive=0, -- Number of groups which are alive. alive=0, -- Number of groups which are alive.
f10menu=true, -- Add an F10 menu for RAT. f10menu=true, -- Add an F10 menu for RAT.
Menu={}, -- F10 menu for this RAT object. Menu={}, -- F10 menu for this RAT object.
respawn_at_landing=false, -- Respawn aircraft the moment they land rather than at engine shutdown.
respawn_delay=nil, -- Delay in seconds until repawn happens after landing.
} }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -436,6 +440,15 @@ function RAT:SetSpawnInterval(interval)
self.spawninterval=math.max(0.5, interval) self.spawninterval=math.max(0.5, interval)
end end
--- Make aircraft respawn the moment they land rather than at engine shut down.
-- @param #RAT self
-- @param #number delay (Optional) Delay in seconds until respawn happens after landing. Default is 180 seconds.
function RAT:RespawnAfterLanding(delay)
delay = delay or 180
self.respawn_after_landing=true
self.respawn_delay=delay
end
--- Set the maximum cruise speed of the aircraft. --- Set the maximum cruise speed of the aircraft.
-- @param #RAT self -- @param #RAT self
-- @param #number speed Speed in km/h. -- @param #number speed Speed in km/h.
@@ -451,11 +464,6 @@ function RAT:SetClimbRate(rate)
-- Convert from ft/min to m/s. -- Convert from ft/min to m/s.
self.Vclimb=rate --*RAT.unit.ft2m/60 self.Vclimb=rate --*RAT.unit.ft2m/60
-- Climb rate in m/s. Max is aircraft specific.
--self.aircraft.Vclimb=math.min(self.Vclimb, self.aircraft.Vymax)
-- Climb angle in rad.
--self.aircraft.AlphaClimb=math.asin(self.aircraft.Vclimb/self.aircraft.Vmax)
end end
--- Set the angle of descent. Default is 3.6 degrees, which corresponds to 3000 ft descent after one mile of travel. --- Set the angle of descent. Default is 3.6 degrees, which corresponds to 3000 ft descent after one mile of travel.
@@ -723,11 +731,15 @@ function RAT:_Respawn(group)
_destination=departure:GetName() _destination=departure:GetName()
end end
-- Spawn new group after 180 seconds. -- Spawn new group.
--self:_SpawnWithRoute(_departure, _destination) if self.respawn_delay then
SCHEDULER:New(nil, self._SpawnWithRoute, {self, _departure, _destination}, 180) SCHEDULER:New(nil, self._SpawnWithRoute, {self, _departure, _destination}, self.respawn_delay)
else
self:_SpawnWithRoute(_departure, _destination)
end
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Set the route of the AI plane. Due to DCS landing bug, this has to be done before the unit is spawned. --- Set the route of the AI plane. Due to DCS landing bug, this has to be done before the unit is spawned.
@@ -905,16 +917,13 @@ function RAT:_SetRoute(_departure, _destination)
-- Overrule setting if user specified min/max flight level explicitly. -- Overrule setting if user specified min/max flight level explicitly.
if self.FLminuser then if self.FLminuser then
FLmin=self.FLminuser FLmin=self.FLminuser
env.info(myid.."FLmin user = "..FLmin)
end end
if self.FLmaxuser then if self.FLmaxuser then
FLmax=self.FLmaxuser FLmax=self.FLmaxuser
env.info(myid.."FLmax user = "..FLmax)
end end
-- Set cruise altitude: default with 100% randomization but limited to FLmin and FLmax. -- Set cruise altitude: default with 100% randomization but limited to FLmin and FLmax.
local FLcruise=self:_Randomize(self.aircraft.FLcruise, 1.0, FLmin, FLmax) local FLcruise=self:_Randomize(self.aircraft.FLcruise, 1.0, FLmin, FLmax)
env.info(myid.."FLcruise = "..FLcruise)
-- Overrule setting if user specified a flight level explicitly. -- Overrule setting if user specified a flight level explicitly.
if self.FLuser then if self.FLuser then
@@ -1513,11 +1522,14 @@ function RAT:_OnLand(EventData)
-- Set status. -- Set status.
self:_SetStatus(SpawnGroup, "Taxiing (after landing)") self:_SetStatus(SpawnGroup, "Taxiing (after landing)")
text="Event: Group "..SpawnGroup:GetName().." will be respawned."
env.info(myid..text)
-- Respawn group. if self.respawn_after_landing then
self:_Respawn(SpawnGroup) text="Event: Group "..SpawnGroup:GetName().." will be respawned."
env.info(myid..text)
-- Respawn group.
self:_Respawn(SpawnGroup)
end
end end
end end
@@ -1550,11 +1562,18 @@ function RAT:_OnEngineShutdown(EventData)
-- Set status. -- Set status.
self:_SetStatus(SpawnGroup, "Parking (shutting down engines)") self:_SetStatus(SpawnGroup, "Parking (shutting down engines)")
text="Event: Group "..SpawnGroup:GetName().." will be destroyed now." if not self.respawn_after_landing then
env.info(myid..text) text="Event: Group "..SpawnGroup:GetName().." will be respawned."
env.info(myid..text)
-- Respawn group.
self:_Respawn(SpawnGroup)
end
-- Despawn group. -- Despawn group.
text="Event: Group "..SpawnGroup:GetName().." will be destroyed now."
env.info(myid..text)
self:_Despawn(SpawnGroup) self:_Despawn(SpawnGroup)
end end