mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Update RAT.lua
This commit is contained in:
parent
1fdb3b7daa
commit
2c67a66d88
@ -866,7 +866,10 @@ function RAT:Spawn(naircraft)
|
|||||||
local Tstop=Tstart+dt*(self.ngroups-1)
|
local Tstop=Tstart+dt*(self.ngroups-1)
|
||||||
|
|
||||||
-- Status check and report scheduler.
|
-- Status check and report scheduler.
|
||||||
SCHEDULER:New(nil, self.Status, {self}, Tstart+1, self.statusinterval)
|
--SCHEDULER:New(nil, self.Status, {self}, Tstart+1, self.statusinterval)
|
||||||
|
--self.sid_Status=self:ScheduleRepeat(Start,Repeat,RandomizeFactor,Stop,SchedulerFunction,...)
|
||||||
|
self.sid_Status=self:ScheduleRepeat(Tstart+1, self.statusinterval, nil, nil, RAT.Status, self)
|
||||||
|
|
||||||
|
|
||||||
-- Handle events.
|
-- Handle events.
|
||||||
self:HandleEvent(EVENTS.Birth, self._OnBirth)
|
self:HandleEvent(EVENTS.Birth, self._OnBirth)
|
||||||
@ -884,13 +887,13 @@ function RAT:Spawn(naircraft)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Start scheduled spawning.
|
-- Start scheduled spawning.
|
||||||
SCHEDULER:New(nil, self._SpawnWithRoute, {self}, Tstart, dt, 0.0, Tstop)
|
--SCHEDULER:New(nil, self._SpawnWithRoute, {self}, Tstart, dt, 0.0, Tstop)
|
||||||
|
self.sid_Spawn=self:ScheduleRepeat(Tstart, dt, 0.0, Tstop, RAT._SpawnWithRoute, self)
|
||||||
--self.sid_spawn=self.Scheduler:Schedule(MasterObject,SchedulerFunction,SchedulerArguments,Start,Repeat,RandomizeFactor,Stop,TraceLevel,Fsm)
|
|
||||||
|
|
||||||
-- Start scheduled activation of uncontrolled groups.
|
-- Start scheduled activation of uncontrolled groups.
|
||||||
if self.uncontrolled and self.activate_uncontrolled then
|
if self.uncontrolled and self.activate_uncontrolled then
|
||||||
SCHEDULER:New(nil, self._ActivateUncontrolled, {self}, self.activate_delay, self.activate_delta, self.activate_frand)
|
--SCHEDULER:New(nil, self._ActivateUncontrolled, {self}, self.activate_delay, self.activate_delta, self.activate_frand)
|
||||||
|
self.sid_Activate=self:ScheduleRepeat(self.activate_delay, self.activate_delta, self.activate_frand, nil, RAT._ActivateUncontrolled, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -1710,7 +1713,7 @@ function RAT:Uncontrolled()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Activate uncontrolled aircraft.
|
--- Define how aircraft that are spawned in uncontrolled state are activate.
|
||||||
-- @param #RAT self
|
-- @param #RAT self
|
||||||
-- @param #number maxactivated Maximal numnber of activated aircraft. Absolute maximum will be the number of spawned groups. Default is 1.
|
-- @param #number maxactivated Maximal numnber of activated aircraft. Absolute maximum will be the number of spawned groups. Default is 1.
|
||||||
-- @param #number delay Time delay in seconds before (first) aircraft is activated. Default is 1 second.
|
-- @param #number delay Time delay in seconds before (first) aircraft is activated. Default is 1 second.
|
||||||
@ -2240,14 +2243,19 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Function called when flight is holding.
|
--- Function called when flight is holding.
|
||||||
function flightgroup.OnAfterHolding(flightgroup, From,Event,To)
|
function flightgroup.OnAfterHolding(Flightgroup, From, Event, To)
|
||||||
|
local flightgroup=Flightgroup --Ops.FlightGroup#FLIGHTGROUP
|
||||||
|
|
||||||
|
if self.ATCswitch then
|
||||||
self:T(self.lid..string.format("RAT group is HOLDING ==> ATCRegisterFlight"))
|
self:T(self.lid..string.format("RAT group is HOLDING ==> ATCRegisterFlight"))
|
||||||
self:_ATCRegisterFlight(groupname, timer.getTime())
|
self:_ATCRegisterFlight(groupname, timer.getTime())
|
||||||
|
end
|
||||||
|
|
||||||
-- Register aircraft at ATC.
|
-- Register aircraft at ATC.
|
||||||
if self.ATCswitch then
|
if self.ATCswitch then
|
||||||
if self.f10menu then
|
if self.f10menu then
|
||||||
MENU_MISSION_COMMAND:New("Clear for landing", self.Menu[self.SubMenuName].groups[self.SpawnIndex], self.ClearForLanding, self, groupname)
|
--MENU_MISSION_COMMAND:New("Clear for landing", self.Menu[self.SubMenuName].groups[self.SpawnIndex], self.ClearForLanding, self, groupname)
|
||||||
|
MENU_MISSION_COMMAND:New("Clear for landing", self.Menu[self.SubMenuName].groups[self.SpawnIndex], flightgroup.ClearToLand, flightgroup)
|
||||||
end
|
end
|
||||||
self:_ATCRegisterFlight(groupname, timer.getTime())
|
self:_ATCRegisterFlight(groupname, timer.getTime())
|
||||||
end
|
end
|
||||||
@ -2453,6 +2461,10 @@ function RAT:_Respawn(group, lastpos, delay)
|
|||||||
|
|
||||||
if self.continuejourney then
|
if self.continuejourney then
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Continue Journey
|
||||||
|
---
|
||||||
|
|
||||||
-- We continue our journey from the old departure airport.
|
-- We continue our journey from the old departure airport.
|
||||||
_departure=destination:GetName()
|
_departure=destination:GetName()
|
||||||
|
|
||||||
@ -2462,7 +2474,7 @@ function RAT:_Respawn(group, lastpos, delay)
|
|||||||
-- Last known position of the aircraft, which should be the sparking spot location.
|
-- Last known position of the aircraft, which should be the sparking spot location.
|
||||||
-- Note: we have to check that it was supposed to land and not respawned directly after landing or after takeoff.
|
-- Note: we have to check that it was supposed to land and not respawned directly after landing or after takeoff.
|
||||||
-- TODO: Need to think if continuejourney with respawn_after_takeoff actually makes sense.
|
-- TODO: Need to think if continuejourney with respawn_after_takeoff actually makes sense.
|
||||||
if landing==RAT.wp.landing and lastpos and not (self.respawn_at_landing or self.respawn_after_takeoff) then
|
if landing==RAT.wp.landing and not (self.respawn_at_landing or self.respawn_after_takeoff) then
|
||||||
-- Check that we have an airport or FARP but not a ship (which would be categroy 1).
|
-- Check that we have an airport or FARP but not a ship (which would be categroy 1).
|
||||||
if destination:GetCategory()==4 then
|
if destination:GetCategory()==4 then
|
||||||
_lastpos=lastpos
|
_lastpos=lastpos
|
||||||
@ -2501,6 +2513,10 @@ function RAT:_Respawn(group, lastpos, delay)
|
|||||||
|
|
||||||
elseif self.commute then
|
elseif self.commute then
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Commute
|
||||||
|
---
|
||||||
|
|
||||||
-- We commute between departure and destination.
|
-- We commute between departure and destination.
|
||||||
|
|
||||||
if self.starshape==true then
|
if self.starshape==true then
|
||||||
@ -2624,38 +2640,13 @@ function RAT:_Despawn(group, delay)
|
|||||||
-- Get ratcraft.
|
-- Get ratcraft.
|
||||||
local ratcraft=self.ratcraft[index] --#RAT.RatCraft
|
local ratcraft=self.ratcraft[index] --#RAT.RatCraft
|
||||||
|
|
||||||
self.ratcraft[index].group=nil
|
-- Despawn flightgroup and stop.
|
||||||
self.ratcraft[index]["status"]="Dead"
|
|
||||||
|
|
||||||
--TODO: Maybe here could be some more arrays deleted? Somehow this causes issues!
|
|
||||||
--[[
|
|
||||||
--self.ratcraft[index]["group"]=group
|
|
||||||
self.ratcraft[index]["destination"]=nil
|
|
||||||
self.ratcraft[index]["departure"]=nil
|
|
||||||
self.ratcraft[index]["waypoints"]=nil
|
|
||||||
self.ratcraft[index]["airborne"]=nil
|
|
||||||
self.ratcraft[index]["Tground"]=nil
|
|
||||||
self.ratcraft[index]["Pground"]=nil
|
|
||||||
self.ratcraft[index]["Tlastcheck"]=nil
|
|
||||||
self.ratcraft[index]["P0"]=nil
|
|
||||||
self.ratcraft[index]["Pnow"]=nil
|
|
||||||
self.ratcraft[index]["Distance"]=nil
|
|
||||||
self.ratcraft[index].takeoff=nil
|
|
||||||
self.ratcraft[index].landing=nil
|
|
||||||
self.ratcraft[index].wpholding=nil
|
|
||||||
self.ratcraft[index].wpfinal=nil
|
|
||||||
self.ratcraft[index].active=false
|
|
||||||
self.ratcraft[index]["status"]=nil
|
|
||||||
self.ratcraft[index].livery=nil
|
|
||||||
self.ratcraft[index].despawnme=nil
|
|
||||||
self.ratcraft[index].nrespawn=nil
|
|
||||||
]]
|
|
||||||
|
|
||||||
--ratcraft.flightgroup:Destroy(0)
|
|
||||||
ratcraft.flightgroup:Despawn()
|
ratcraft.flightgroup:Despawn()
|
||||||
ratcraft.flightgroup:__Stop(0.1)
|
ratcraft.flightgroup:__Stop(0.1)
|
||||||
|
|
||||||
|
-- Nil ratcraft in table.
|
||||||
|
self.ratcraft[index].group=nil
|
||||||
|
self.ratcraft[index]["status"]="Dead"
|
||||||
self.ratcraft[index]=nil
|
self.ratcraft[index]=nil
|
||||||
|
|
||||||
-- Remove submenu for this group.
|
-- Remove submenu for this group.
|
||||||
@ -3916,10 +3907,8 @@ function RAT:_OnBirth(EventData)
|
|||||||
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
||||||
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
||||||
|
|
||||||
if EventPrefix then
|
|
||||||
|
|
||||||
-- Check that the template name actually belongs to this object.
|
-- Check that the template name actually belongs to this object.
|
||||||
if EventPrefix == self.alias then
|
if EventPrefix and EventPrefix == self.alias then
|
||||||
|
|
||||||
local text="Event: Group "..SpawnGroup:GetName().." was born."
|
local text="Event: Group "..SpawnGroup:GetName().." was born."
|
||||||
self:T(self.lid..text)
|
self:T(self.lid..text)
|
||||||
@ -4019,7 +4008,6 @@ function RAT:_OnBirth(EventData)
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
else
|
||||||
self:T2(self.lid.."ERROR: Group does not exist in RAT:_OnBirth().")
|
self:T2(self.lid.."ERROR: Group does not exist in RAT:_OnBirth().")
|
||||||
end
|
end
|
||||||
@ -4040,10 +4028,8 @@ function RAT:_OnEngineStartup(EventData)
|
|||||||
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
||||||
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
||||||
|
|
||||||
if EventPrefix then
|
|
||||||
|
|
||||||
-- Check that the template name actually belongs to this object.
|
-- Check that the template name actually belongs to this object.
|
||||||
if EventPrefix == self.alias then
|
if EventPrefix and EventPrefix == self.alias then
|
||||||
|
|
||||||
local text="Event: Group "..SpawnGroup:GetName().." started engines."
|
local text="Event: Group "..SpawnGroup:GetName().." started engines."
|
||||||
self:T(self.lid..text)
|
self:T(self.lid..text)
|
||||||
@ -4055,8 +4041,9 @@ function RAT:_OnEngineStartup(EventData)
|
|||||||
else
|
else
|
||||||
status=RAT.status.EventEngineStart
|
status=RAT.status.EventEngineStart
|
||||||
end
|
end
|
||||||
|
|
||||||
self:_SetStatus(SpawnGroup, status)
|
self:_SetStatus(SpawnGroup, status)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -4076,10 +4063,8 @@ function RAT:_OnTakeoff(EventData)
|
|||||||
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
||||||
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
||||||
|
|
||||||
if EventPrefix then
|
|
||||||
|
|
||||||
-- Check that the template name actually belongs to this object.
|
-- Check that the template name actually belongs to this object.
|
||||||
if EventPrefix == self.alias then
|
if EventPrefix and EventPrefix == self.alias then
|
||||||
|
|
||||||
local text="Event: Group "..SpawnGroup:GetName().." is airborne."
|
local text="Event: Group "..SpawnGroup:GetName().." is airborne."
|
||||||
self:T(self.lid..text)
|
self:T(self.lid..text)
|
||||||
@ -4097,8 +4082,6 @@ function RAT:_OnTakeoff(EventData)
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
else
|
else
|
||||||
self:T2(self.lid.."ERROR: Group does not exist in RAT:_OnTakeoff().")
|
self:T2(self.lid.."ERROR: Group does not exist in RAT:_OnTakeoff().")
|
||||||
end
|
end
|
||||||
@ -4116,12 +4099,10 @@ function RAT:_OnLand(EventData)
|
|||||||
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
-- Get the template name of the group. This can be nil if this was not a spawned group.
|
||||||
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
local EventPrefix = self:_GetPrefixFromGroup(SpawnGroup)
|
||||||
|
|
||||||
if EventPrefix then
|
|
||||||
|
|
||||||
-- Check that the template name actually belongs to this object.
|
-- Check that the template name actually belongs to this object.
|
||||||
if EventPrefix == self.alias then
|
if EventPrefix and EventPrefix == self.alias then
|
||||||
|
|
||||||
local text="Event: Group "..SpawnGroup:GetName().." landed."
|
local text="Event: Group "..SpawnGroup:GetName().." landed"
|
||||||
self:T(self.lid..text)
|
self:T(self.lid..text)
|
||||||
|
|
||||||
-- Set status.
|
-- Set status.
|
||||||
@ -4134,7 +4115,7 @@ function RAT:_OnLand(EventData)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.respawn_at_landing and not self.norespawn then
|
if self.respawn_at_landing and not self.norespawn then
|
||||||
text="Event: Group "..SpawnGroup:GetName().." will be respawned."
|
text="Event: Group "..SpawnGroup:GetName().." will be respawned"
|
||||||
self:T(self.lid..text)
|
self:T(self.lid..text)
|
||||||
|
|
||||||
-- Respawn group.
|
-- Respawn group.
|
||||||
@ -4142,10 +4123,9 @@ function RAT:_OnLand(EventData)
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
else
|
else
|
||||||
self:T2(self.lid.."ERROR: Group does not exist in RAT:_OnLand().")
|
self:T2(self.lid.."ERROR: Group does not exist in RAT:_OnLand()")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -4192,7 +4172,7 @@ function RAT:_OnEngineShutdown(EventData)
|
|||||||
else
|
else
|
||||||
|
|
||||||
-- Despawn group.
|
-- Despawn group.
|
||||||
text="Event: Group "..SpawnGroup:GetName().." will be destroyed now."
|
text="Event: Group "..SpawnGroup:GetName().." will be destroyed now"
|
||||||
self:T(self.lid..text)
|
self:T(self.lid..text)
|
||||||
self:_Despawn(SpawnGroup)
|
self:_Despawn(SpawnGroup)
|
||||||
|
|
||||||
@ -4702,6 +4682,7 @@ function RAT._WaypointFunction(group, rat, wp)
|
|||||||
-- Register aircraft at ATC.
|
-- Register aircraft at ATC.
|
||||||
if rat.ATCswitch then
|
if rat.ATCswitch then
|
||||||
if rat.f10menu then
|
if rat.f10menu then
|
||||||
|
-- TODO: get index and exchange with flightgroup landing clearance function
|
||||||
MENU_MISSION_COMMAND:New("Clear for landing", rat.Menu[rat.SubMenuName].groups[sdx], rat.ClearForLanding, rat, group:GetName())
|
MENU_MISSION_COMMAND:New("Clear for landing", rat.Menu[rat.SubMenuName].groups[sdx], rat.ClearForLanding, rat, group:GetName())
|
||||||
end
|
end
|
||||||
rat._ATCRegisterFlight(rat, group:GetName(), Tnow)
|
rat._ATCRegisterFlight(rat, group:GetName(), Tnow)
|
||||||
@ -5924,7 +5905,7 @@ function RAT:_ATCFlightLanded(name)
|
|||||||
airport.traffic=airport.traffic+1
|
airport.traffic=airport.traffic+1
|
||||||
|
|
||||||
-- Number of planes landing per hour.
|
-- Number of planes landing per hour.
|
||||||
local TrafficPerHour=aiport.traffic/(timer.getTime()-RAT.ATC.T0)*3600
|
local TrafficPerHour=airport.traffic/(timer.getTime()-RAT.ATC.T0)*3600
|
||||||
|
|
||||||
-- Debug info
|
-- Debug info
|
||||||
BASE:I(RAT.id..string.format("ATC %s: Flight %s landed. Tholding = %i:%02d, Tfinal = %i:%02d.", dest, name, Thold/60, Thold%60, Tfinal/60, Tfinal%60))
|
BASE:I(RAT.id..string.format("ATC %s: Flight %s landed. Tholding = %i:%02d, Tfinal = %i:%02d.", dest, name, Thold/60, Thold%60, Tfinal/60, Tfinal%60))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user