From 3c8244b2aaae85331a36c7d0609270185b84b642 Mon Sep 17 00:00:00 2001 From: funkyfranky Date: Fri, 24 Nov 2017 22:34:09 +0100 Subject: [PATCH] Fixed "debug" problem Changed RAT.debug to RAT.Debug Added switch for ATC messages --- Moose Development/Moose/Functional/RAT.lua | 72 +++++++++++++--------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/Moose Development/Moose/Functional/RAT.lua b/Moose Development/Moose/Functional/RAT.lua index ab553a06f..6ce41a6b6 100644 --- a/Moose Development/Moose/Functional/RAT.lua +++ b/Moose Development/Moose/Functional/RAT.lua @@ -63,7 +63,7 @@ --- RAT class -- @type RAT -- @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 #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. @@ -282,7 +282,7 @@ -- @field #RAT RAT={ 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. 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. @@ -448,6 +448,7 @@ RAT.ATC={ onfinal=-100, Nclearance=2, delay=240, + messages=true, } --- Running number of placed markers on the F10 map. @@ -464,7 +465,7 @@ RAT.id="RAT | " --- RAT 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 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! -- @param #RAT self -- @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 switch=true end - self.debug=switch + self.Debug=switch end --- Aircraft report status update messages along the route. @@ -1381,7 +1392,7 @@ function RAT:_InitAircraft(DCSgroup) local DCStype=DCSunit:getTypeName() -- Descriptors table of unit. - if self.debug then + if self.Debug then self:E({"DCSdesc", DCSdesc}) end @@ -1710,7 +1721,7 @@ function RAT:_Respawn(group) _lastwp=lastwp 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.landing, landing, _landing = %s, %s, %s", tostring(self.landing), tostring(landing), tostring(_landing))) 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 climb = %6.2f Deg\n", math.deg(phi_climb)) 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. local h_climb_max = FLmax - H_departure local h_descent_max = FLmax - Hh_holding @@ -2405,7 +2416,7 @@ function RAT:_PickDeparture(takeoff) text="Chosen departure airport: "..departure:GetName().." (ID "..departure:GetID()..")" end env.info(RAT.id..text) - if self.debug then + if self.Debug then MESSAGE:New(text, 30):ToAll() end 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()) end env.info(RAT.id..text) - if self.debug then + if self.Debug then MESSAGE:New(text, 30):ToAll() end @@ -2621,7 +2632,7 @@ function RAT:_GetAirportsOfMap() -- Add airport to table. 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 text2="DCS : Airport ID = "..airbase:getID().." and Name = "..airbase:getName()..", Category = "..airbase:getCategory()..", TypeName = "..airbase:getTypeName() 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("Position change = %8.1f m since %3.0f seconds.", Dg, dTlast) end - if self.debug then + if self.Debug then env.info(RAT.id..text) end if message then @@ -2816,7 +2827,7 @@ function RAT:Status(message, forID) end end else - if self.debug then + if self.Debug then local text=string.format("Group %i does not exist.", i) env.info(RAT.id..text) end @@ -2842,12 +2853,12 @@ function RAT:_GetLife(group) if unit then life=unit:GetLife()/unit:GetLife0()*100 else - if self.debug then + if self.Debug then env.error(RAT.id.."Unit does not exist in RAT_Getlife(). Returning zero.") end end else - if self.debug then + if self.Debug then env.error(RAT.id.."Group does not exist in RAT_Getlife(). Returning zero.") end end @@ -2913,7 +2924,7 @@ function RAT:_OnBirth(EventData) end end else - if self.debug then + if self.Debug then env.error("Group does not exist in RAT:_OnBirthDay().") end end @@ -2952,7 +2963,7 @@ function RAT:_EngineStartup(EventData) end else - if self.debug then + if self.Debug then env.error("Group does not exist in RAT:_EngineStartup().") end end @@ -2994,7 +3005,7 @@ function RAT:_OnTakeoff(EventData) end else - if self.debug then + if self.Debug then env.error("Group does not exist in RAT:_OnTakeoff().") end end @@ -3041,7 +3052,7 @@ function RAT:_OnLand(EventData) end else - if self.debug then + if self.Debug then env.error("Group does not exist in RAT:_OnLand().") end end @@ -3088,7 +3099,7 @@ function RAT:_OnEngineShutdown(EventData) end else - if self.debug then + if self.Debug then env.error("Group does not exist in RAT:_OnEngineShutdown().") end end @@ -3122,7 +3133,7 @@ function RAT:_OnDead(EventData) end else - if self.debug then + if self.Debug then env.error("Group does not exist in RAT:_OnDead().") end end @@ -3162,7 +3173,7 @@ function RAT:_OnCrash(EventData) end else - if self.debug then + if self.Debug then env.error("Group does not exist in RAT:_OnCrash().") end end @@ -3293,7 +3304,7 @@ function RAT:_Waypoint(index, Type, Coord, Speed, Altitude, Airport) text=text..string.format("No airport/zone specified\n") end text=text.."******************************************************\n" - if self.debug then + if self.Debug then env.info(RAT.id..text) end @@ -3400,7 +3411,7 @@ function RAT:_Routeinfo(waypoints, comment) text=text..string.format("******************************************************\n") -- send message - if self.debug then + if self.Debug then --env.info(RAT.id..text) end env.info(RAT.id..text) @@ -3514,7 +3525,7 @@ function RAT._WaypointFunction(group, rat, wp) if landing==RAT.wp.air then 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) -- Enable despawn switch. Next time the status function is called, the aircraft will be despawned. 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) 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) - if self.debug then + if self.Debug then env.info(RAT.id..text) end return h3+h0 @@ -3782,7 +3793,7 @@ function RAT:_Randomize(value, fac, lower, upper) local r=math.random(min, max) -- 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) env.info(RAT.id..text) end @@ -3830,7 +3841,7 @@ end function RAT:_PlaceMarkers(waypoints, index) for i=1,#waypoints do 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) env.info(RAT.id..text) end @@ -3846,7 +3857,7 @@ end function RAT:_SetMarker(text, wp, index) RAT.markerid=RAT.markerid+1 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) end -- 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 text2=string.format("ATC %s: Flight %s you are cleared for landing.", airport, flight) env.info( RAT.id..text1) - MESSAGE:New(text2, 10):ToAll() + MESSAGE:New(text2, 10):ToAllIf(RAT.ATC.messages) end --- 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..text2) env.info(RAT.id..text3) - MESSAGE:New(text4, 10):ToAll() + MESSAGE:New(text4, 10):ToAllIf(RAT.ATC.messages) end end @@ -4270,3 +4281,4 @@ function RAT:_ATCQueue() end ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +