Fixed "debug" problem

Changed RAT.debug to RAT.Debug
Added switch for ATC messages
This commit is contained in:
funkyfranky
2017-11-24 22:34:09 +01:00
parent 057e528947
commit 3c8244b2aa

View File

@@ -63,7 +63,7 @@
--- RAT class --- RAT class
-- @type RAT -- @type RAT
-- @field #string ClassName Name of the Class. -- @field #string ClassName Name of the Class.
-- @field #boolean debug Turn debug messages on or off. -- @field #boolean Debug Turn debug messages on or off.
-- @field Core.Group#GROUP templategroup Group serving as template for the RAT aircraft. -- @field Core.Group#GROUP templategroup Group serving as template for the RAT aircraft.
-- @field #string alias Alias for spawned group. -- @field #string alias Alias for spawned group.
-- @field #boolean spawninitialized If RAT:Spawn() was already called this RAT object is set to true to prevent users to call it again. -- @field #boolean spawninitialized If RAT:Spawn() was already called this RAT object is set to true to prevent users to call it again.
@@ -282,7 +282,7 @@
-- @field #RAT -- @field #RAT
RAT={ RAT={
ClassName = "RAT", -- Name of class: RAT = Random Air Traffic. ClassName = "RAT", -- Name of class: RAT = Random Air Traffic.
debug=false, -- Turn debug messages on or off. Debug=false, -- Turn debug messages on or off.
templategroup=nil, -- Template group for the RAT aircraft. templategroup=nil, -- Template group for the RAT aircraft.
alias=nil, -- Alias for spawned group. alias=nil, -- Alias for spawned group.
spawninitialized=false, -- If RAT:Spawn() was already called this is set to true to prevent users to call it again. spawninitialized=false, -- If RAT:Spawn() was already called this is set to true to prevent users to call it again.
@@ -448,6 +448,7 @@ RAT.ATC={
onfinal=-100, onfinal=-100,
Nclearance=2, Nclearance=2,
delay=240, delay=240,
messages=true,
} }
--- Running number of placed markers on the F10 map. --- Running number of placed markers on the F10 map.
@@ -464,7 +465,7 @@ RAT.id="RAT | "
--- RAT version. --- RAT version.
-- @field #string version -- @field #string version
RAT.version="2.0.1" RAT.version="2.0.2"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -1255,6 +1256,16 @@ function RAT:EnableATC(switch)
self.ATCswitch=switch self.ATCswitch=switch
end end
--- Turn messages from ATC on or off. Default is on. This setting effects all RAT objects and groups!
-- @param #RAT self
-- @param #boolean switch Enable (true) or disable (false) messages from ATC.
function RAT:ATC_Messages(switch)
if switch==nil then
switch=true
end
RAT.ATC.messages=switch
end
--- Max number of planes that get landing clearance of the RAT ATC. This setting effects all RAT objects and groups! --- Max number of planes that get landing clearance of the RAT ATC. This setting effects all RAT objects and groups!
-- @param #RAT self -- @param #RAT self
-- @param #number n Number of aircraft that are allowed to land simultaniously. Default is 2. -- @param #number n Number of aircraft that are allowed to land simultaniously. Default is 2.
@@ -1293,7 +1304,7 @@ function RAT:_Debug(switch)
if switch==nil then if switch==nil then
switch=true switch=true
end end
self.debug=switch self.Debug=switch
end end
--- Aircraft report status update messages along the route. --- Aircraft report status update messages along the route.
@@ -1381,7 +1392,7 @@ function RAT:_InitAircraft(DCSgroup)
local DCStype=DCSunit:getTypeName() local DCStype=DCSunit:getTypeName()
-- Descriptors table of unit. -- Descriptors table of unit.
if self.debug then if self.Debug then
self:E({"DCSdesc", DCSdesc}) self:E({"DCSdesc", DCSdesc})
end end
@@ -1710,7 +1721,7 @@ function RAT:_Respawn(group)
_lastwp=lastwp _lastwp=lastwp
end end
if self.debug then if self.Debug then
env.info(RAT.id..string.format("self.takeoff, takeoff, _takeoff = %s, %s, %s", tostring(self.takeoff), tostring(takeoff), tostring(_takeoff))) env.info(RAT.id..string.format("self.takeoff, takeoff, _takeoff = %s, %s, %s", tostring(self.takeoff), tostring(takeoff), tostring(_takeoff)))
env.info(RAT.id..string.format("self.landing, landing, _landing = %s, %s, %s", tostring(self.landing), tostring(landing), tostring(_landing))) env.info(RAT.id..string.format("self.landing, landing, _landing = %s, %s, %s", tostring(self.landing), tostring(landing), tostring(_landing)))
end end
@@ -2164,7 +2175,7 @@ function RAT:_SetRoute(takeoff, landing, _departure, _destination, _waypoint)
text=text..string.format("Phi (slope) = %6.2f Deg\n", math.deg(phi)) text=text..string.format("Phi (slope) = %6.2f Deg\n", math.deg(phi))
text=text..string.format("Phi climb = %6.2f Deg\n", math.deg(phi_climb)) text=text..string.format("Phi climb = %6.2f Deg\n", math.deg(phi_climb))
text=text..string.format("Phi descent = %6.2f Deg\n", math.deg(phi_descent)) text=text..string.format("Phi descent = %6.2f Deg\n", math.deg(phi_descent))
if self.debug then if self.Debug then
-- Max heights and distances if we would travel at FLmax. -- Max heights and distances if we would travel at FLmax.
local h_climb_max = FLmax - H_departure local h_climb_max = FLmax - H_departure
local h_descent_max = FLmax - Hh_holding local h_descent_max = FLmax - Hh_holding
@@ -2405,7 +2416,7 @@ function RAT:_PickDeparture(takeoff)
text="Chosen departure airport: "..departure:GetName().." (ID "..departure:GetID()..")" text="Chosen departure airport: "..departure:GetName().." (ID "..departure:GetID()..")"
end end
env.info(RAT.id..text) env.info(RAT.id..text)
if self.debug then if self.Debug then
MESSAGE:New(text, 30):ToAll() MESSAGE:New(text, 30):ToAll()
end end
else else
@@ -2531,7 +2542,7 @@ function RAT:_PickDestination(departure, q, minrange, maxrange, random, landing)
text=string.format("Chosen destination airport: %s (ID %d).", destination:GetName(), destination:GetID()) text=string.format("Chosen destination airport: %s (ID %d).", destination:GetName(), destination:GetID())
end end
env.info(RAT.id..text) env.info(RAT.id..text)
if self.debug then if self.Debug then
MESSAGE:New(text, 30):ToAll() MESSAGE:New(text, 30):ToAll()
end end
@@ -2621,7 +2632,7 @@ function RAT:_GetAirportsOfMap()
-- Add airport to table. -- Add airport to table.
table.insert(self.airports_map, _myab) table.insert(self.airports_map, _myab)
if self.debug then if self.Debug then
local text1="MOOSE: Airport ID = ".._myab:GetID().." and Name = ".._myab:GetName()..", Category = ".._myab:GetCategory()..", TypeName = ".._myab:GetTypeName() local text1="MOOSE: Airport ID = ".._myab:GetID().." and Name = ".._myab:GetName()..", Category = ".._myab:GetCategory()..", TypeName = ".._myab:GetTypeName()
--local text2="DCS : Airport ID = "..airbase:getID().." and Name = "..airbase:getName()..", Category = "..airbase:getCategory()..", TypeName = "..airbase:getTypeName() --local text2="DCS : Airport ID = "..airbase:getID().." and Name = "..airbase:getName()..", Category = "..airbase:getCategory()..", TypeName = "..airbase:getTypeName()
env.info(RAT.id..text1) env.info(RAT.id..text1)
@@ -2783,7 +2794,7 @@ function RAT:Status(message, forID)
text=text..string.format("\nTime on ground = %6.0f seconds\n", Tg) text=text..string.format("\nTime on ground = %6.0f seconds\n", Tg)
text=text..string.format("Position change = %8.1f m since %3.0f seconds.", Dg, dTlast) text=text..string.format("Position change = %8.1f m since %3.0f seconds.", Dg, dTlast)
end end
if self.debug then if self.Debug then
env.info(RAT.id..text) env.info(RAT.id..text)
end end
if message then if message then
@@ -2816,7 +2827,7 @@ function RAT:Status(message, forID)
end end
end end
else else
if self.debug then if self.Debug then
local text=string.format("Group %i does not exist.", i) local text=string.format("Group %i does not exist.", i)
env.info(RAT.id..text) env.info(RAT.id..text)
end end
@@ -2842,12 +2853,12 @@ function RAT:_GetLife(group)
if unit then if unit then
life=unit:GetLife()/unit:GetLife0()*100 life=unit:GetLife()/unit:GetLife0()*100
else else
if self.debug then if self.Debug then
env.error(RAT.id.."Unit does not exist in RAT_Getlife(). Returning zero.") env.error(RAT.id.."Unit does not exist in RAT_Getlife(). Returning zero.")
end end
end end
else else
if self.debug then if self.Debug then
env.error(RAT.id.."Group does not exist in RAT_Getlife(). Returning zero.") env.error(RAT.id.."Group does not exist in RAT_Getlife(). Returning zero.")
end end
end end
@@ -2913,7 +2924,7 @@ function RAT:_OnBirth(EventData)
end end
end end
else else
if self.debug then if self.Debug then
env.error("Group does not exist in RAT:_OnBirthDay().") env.error("Group does not exist in RAT:_OnBirthDay().")
end end
end end
@@ -2952,7 +2963,7 @@ function RAT:_EngineStartup(EventData)
end end
else else
if self.debug then if self.Debug then
env.error("Group does not exist in RAT:_EngineStartup().") env.error("Group does not exist in RAT:_EngineStartup().")
end end
end end
@@ -2994,7 +3005,7 @@ function RAT:_OnTakeoff(EventData)
end end
else else
if self.debug then if self.Debug then
env.error("Group does not exist in RAT:_OnTakeoff().") env.error("Group does not exist in RAT:_OnTakeoff().")
end end
end end
@@ -3041,7 +3052,7 @@ function RAT:_OnLand(EventData)
end end
else else
if self.debug then if self.Debug then
env.error("Group does not exist in RAT:_OnLand().") env.error("Group does not exist in RAT:_OnLand().")
end end
end end
@@ -3088,7 +3099,7 @@ function RAT:_OnEngineShutdown(EventData)
end end
else else
if self.debug then if self.Debug then
env.error("Group does not exist in RAT:_OnEngineShutdown().") env.error("Group does not exist in RAT:_OnEngineShutdown().")
end end
end end
@@ -3122,7 +3133,7 @@ function RAT:_OnDead(EventData)
end end
else else
if self.debug then if self.Debug then
env.error("Group does not exist in RAT:_OnDead().") env.error("Group does not exist in RAT:_OnDead().")
end end
end end
@@ -3162,7 +3173,7 @@ function RAT:_OnCrash(EventData)
end end
else else
if self.debug then if self.Debug then
env.error("Group does not exist in RAT:_OnCrash().") env.error("Group does not exist in RAT:_OnCrash().")
end end
end end
@@ -3293,7 +3304,7 @@ function RAT:_Waypoint(index, Type, Coord, Speed, Altitude, Airport)
text=text..string.format("No airport/zone specified\n") text=text..string.format("No airport/zone specified\n")
end end
text=text.."******************************************************\n" text=text.."******************************************************\n"
if self.debug then if self.Debug then
env.info(RAT.id..text) env.info(RAT.id..text)
end end
@@ -3400,7 +3411,7 @@ function RAT:_Routeinfo(waypoints, comment)
text=text..string.format("******************************************************\n") text=text..string.format("******************************************************\n")
-- send message -- send message
if self.debug then if self.Debug then
--env.info(RAT.id..text) --env.info(RAT.id..text)
end end
env.info(RAT.id..text) env.info(RAT.id..text)
@@ -3514,7 +3525,7 @@ function RAT._WaypointFunction(group, rat, wp)
if landing==RAT.wp.air then if landing==RAT.wp.air then
text=string.format("Activating despawn switch for flight %s! Group will be detroyed soon.", group:GetName()) text=string.format("Activating despawn switch for flight %s! Group will be detroyed soon.", group:GetName())
MESSAGE:New(text, 30):ToAllIf(rat.debug) MESSAGE:New(text, 30):ToAllIf(rat.Debug)
env.info(RAT.id..text) env.info(RAT.id..text)
-- Enable despawn switch. Next time the status function is called, the aircraft will be despawned. -- Enable despawn switch. Next time the status function is called, the aircraft will be despawned.
rat.ratcraft[sdx].despawnme=true rat.ratcraft[sdx].despawnme=true
@@ -3592,7 +3603,7 @@ function RAT:_FLmax(alpha, beta, d, phi, h0)
local text=string.format("\nFLmax = FL%3.0f = %6.1f m.\n", h1/RAT.unit.FL2m, h1) local text=string.format("\nFLmax = FL%3.0f = %6.1f m.\n", h1/RAT.unit.FL2m, h1)
text=text..string.format( "FLmax = FL%3.0f = %6.1f m.\n", h2/RAT.unit.FL2m, h2) text=text..string.format( "FLmax = FL%3.0f = %6.1f m.\n", h2/RAT.unit.FL2m, h2)
text=text..string.format( "FLmax = FL%3.0f = %6.1f m.", h3/RAT.unit.FL2m, h3) text=text..string.format( "FLmax = FL%3.0f = %6.1f m.", h3/RAT.unit.FL2m, h3)
if self.debug then if self.Debug then
env.info(RAT.id..text) env.info(RAT.id..text)
end end
return h3+h0 return h3+h0
@@ -3782,7 +3793,7 @@ function RAT:_Randomize(value, fac, lower, upper)
local r=math.random(min, max) local r=math.random(min, max)
-- debug info -- debug info
if self.debug then if self.Debug then
local text=string.format("Random: value = %6.2f, fac = %4.2f, min = %6.2f, max = %6.2f, r = %6.2f", value, fac, min, max, r) local text=string.format("Random: value = %6.2f, fac = %4.2f, min = %6.2f, max = %6.2f, r = %6.2f", value, fac, min, max, r)
env.info(RAT.id..text) env.info(RAT.id..text)
end end
@@ -3830,7 +3841,7 @@ end
function RAT:_PlaceMarkers(waypoints, index) function RAT:_PlaceMarkers(waypoints, index)
for i=1,#waypoints do for i=1,#waypoints do
self:_SetMarker(self.waypointdescriptions[i], waypoints[i], index) self:_SetMarker(self.waypointdescriptions[i], waypoints[i], index)
if self.debug then if self.Debug then
local text=string.format("Marker at waypoint #%d: %s for flight #%d", i, self.waypointdescriptions[i], index) local text=string.format("Marker at waypoint #%d: %s for flight #%d", i, self.waypointdescriptions[i], index)
env.info(RAT.id..text) env.info(RAT.id..text)
end end
@@ -3846,7 +3857,7 @@ end
function RAT:_SetMarker(text, wp, index) function RAT:_SetMarker(text, wp, index)
RAT.markerid=RAT.markerid+1 RAT.markerid=RAT.markerid+1
self.markerids[#self.markerids+1]=RAT.markerid self.markerids[#self.markerids+1]=RAT.markerid
if self.debug then if self.Debug then
env.info(RAT.id..self.SpawnTemplatePrefix..": placing marker with ID "..RAT.markerid..": "..text) env.info(RAT.id..self.SpawnTemplatePrefix..": placing marker with ID "..RAT.markerid..": "..text)
end end
-- Convert to coordinate. -- Convert to coordinate.
@@ -4173,7 +4184,7 @@ function RAT:_ATCClearForLanding(airport, flight)
local text1=string.format("ATC %s: Flight %s cleared for landing (flag=%d).", airport, flight, flagvalue) local text1=string.format("ATC %s: Flight %s cleared for landing (flag=%d).", airport, flight, flagvalue)
local text2=string.format("ATC %s: Flight %s you are cleared for landing.", airport, flight) local text2=string.format("ATC %s: Flight %s you are cleared for landing.", airport, flight)
env.info( RAT.id..text1) env.info( RAT.id..text1)
MESSAGE:New(text2, 10):ToAll() MESSAGE:New(text2, 10):ToAllIf(RAT.ATC.messages)
end end
--- Takes care of organisational stuff after a plane has landed. --- Takes care of organisational stuff after a plane has landed.
@@ -4217,7 +4228,7 @@ function RAT:_ATCFlightLanded(name)
env.info(RAT.id..text1) env.info(RAT.id..text1)
env.info(RAT.id..text2) env.info(RAT.id..text2)
env.info(RAT.id..text3) env.info(RAT.id..text3)
MESSAGE:New(text4, 10):ToAll() MESSAGE:New(text4, 10):ToAllIf(RAT.ATC.messages)
end end
end end
@@ -4270,3 +4281,4 @@ function RAT:_ATCQueue()
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------