diff --git a/Moose Development/Moose/Functional/PseudoATC.lua b/Moose Development/Moose/Functional/PseudoATC.lua index 5ee714705..16c530cf3 100644 --- a/Moose Development/Moose/Functional/PseudoATC.lua +++ b/Moose Development/Moose/Functional/PseudoATC.lua @@ -26,9 +26,9 @@ -- -- === -- --- ### Author: **[funkyfranky](https://forums.eagle.ru/member.php?u=115026)** +-- ### Author: **funkyfranky** -- --- ### Contributions: [FlightControl](https://forums.eagle.ru/member.php?u=89536) +-- ### Contributions: FlightControl, Applevangelist -- -- ==== -- @module Functional.PseudoATC @@ -44,7 +44,7 @@ -- @field #number mrefresh Interval in seconds after which the F10 menu is refreshed. E.g. by the closest airports. Default is 120 sec. -- @field #number talt Interval in seconds between reporting altitude until touchdown. Default 3 sec. -- @field #boolean chatty Display some messages on events like take-off and touchdown. --- @field #boolean eventsmoose If true, events are handled by MOOSE. If false, events are handled directly by DCS eventhandler. +-- @field #boolean eventsmoose [Deprecated] If true, events are handled by MOOSE. If false, events are handled directly by DCS eventhandler. -- @field #boolean reportplayername If true, use playername not callsign on callouts -- @extends Core.Base#BASE @@ -100,13 +100,14 @@ PSEUDOATC.id="PseudoATC | " --- PSEUDOATC version. -- @field #number version -PSEUDOATC.version="0.9.5" +PSEUDOATC.version="0.10.5" ----------------------------------------------------------------------------------------------------------------------------------------- -- TODO list -- DONE: Add takeoff event. -- DONE: Add user functions. +-- DONE: Refactor to use Moose event handling only ----------------------------------------------------------------------------------------------------------------------------------------- @@ -131,23 +132,14 @@ function PSEUDOATC:Start() self:F() -- Debug info - self:E(PSEUDOATC.id.."Starting PseudoATC") + self:I(PSEUDOATC.id.."Starting PseudoATC") -- Handle events. - if self.eventsmoose then - self:T(PSEUDOATC.id.."Events are handled by MOOSE.") - self:HandleEvent(EVENTS.Birth, self._OnBirth) - self:HandleEvent(EVENTS.Land, self._PlayerLanded) - self:HandleEvent(EVENTS.Takeoff, self._PlayerTakeOff) - self:HandleEvent(EVENTS.PlayerLeaveUnit, self._PlayerLeft) - self:HandleEvent(EVENTS.Crash, self._PlayerLeft) - --self:HandleEvent(EVENTS.Ejection, self._PlayerLeft) - --self:HandleEvent(EVENTS.PilotDead, self._PlayerLeft) - else - self:T(PSEUDOATC.id.."Events are handled by DCS.") - -- Events are handled directly by DCS. - world.addEventHandler(self) - end + self:HandleEvent(EVENTS.Birth, self._OnBirth) + self:HandleEvent(EVENTS.Land, self._PlayerLanded) + self:HandleEvent(EVENTS.Takeoff, self._PlayerTakeOff) + self:HandleEvent(EVENTS.PlayerLeaveUnit, self._PlayerLeft) + self:HandleEvent(EVENTS.Crash, self._PlayerLeft) end @@ -199,7 +191,7 @@ function PSEUDOATC:SetMenuRefresh(interval) self.mrefresh=interval or 120 end ---- Enable/disable event handling by MOOSE or DCS. +--- [Deprecated] Enable/disable event handling by MOOSE or DCS. -- @param #PSEUDOATC self -- @param #boolean switch If true, events are handled by MOOSE (default). If false, events are handled directly by DCS. function PSEUDOATC:SetEventsMoose(switch) @@ -216,84 +208,6 @@ end ----------------------------------------------------------------------------------------------------------------------------------------- -- Event Handling ---- Event handler for suppressed groups. ---@param #PSEUDOATC self ---@param #table Event Event data table. Holds event.id, event.initiator and event.target etc. -function PSEUDOATC:onEvent(Event) - if Event == nil or Event.initiator == nil or Unit.getByName(Event.initiator:getName()) == nil then - return true - end - - local DCSiniunit = Event.initiator - local DCSplace = Event.place - local DCSsubplace = Event.subplace - - local EventData={} - local _playerunit=nil - local _playername=nil - - if Event.initiator then - EventData.IniUnitName = Event.initiator:getName() - EventData.IniDCSGroup = Event.initiator:getGroup() - EventData.IniGroupName = Event.initiator:getGroup():getName() - -- Get player unit and name. This returns nil,nil if the event was not fired by a player unit. And these are the only events we are interested in. - _playerunit, _playername = self:_GetPlayerUnitAndName(EventData.IniUnitName) - end - - if Event.place then - EventData.Place=Event.place - EventData.PlaceName=Event.place:getName() - end - if Event.subplace then - EventData.SubPlace=Event.subplace - EventData.SubPlaceName=Event.subplace:getName() - end - - -- Event info. - self:T3(PSEUDOATC.id..string.format("EVENT: Event in onEvent with ID = %s", tostring(Event.id))) - self:T3(PSEUDOATC.id..string.format("EVENT: Ini unit = %s" , tostring(EventData.IniUnitName))) - self:T3(PSEUDOATC.id..string.format("EVENT: Ini group = %s" , tostring(EventData.IniGroupName))) - self:T3(PSEUDOATC.id..string.format("EVENT: Ini player = %s" , tostring(_playername))) - self:T3(PSEUDOATC.id..string.format("EVENT: Place = %s" , tostring(EventData.PlaceName))) - self:T3(PSEUDOATC.id..string.format("EVENT: SubPlace = %s" , tostring(EventData.SubPlaceName))) - - -- Event birth. - if Event.id == world.event.S_EVENT_BIRTH and _playername then - self:_OnBirth(EventData) - end - - -- Event takeoff. - if Event.id == world.event.S_EVENT_TAKEOFF and _playername and EventData.Place then - self:_PlayerTakeOff(EventData) - end - - -- Event land. - if Event.id == world.event.S_EVENT_LAND and _playername and EventData.Place then - self:_PlayerLanded(EventData) - end - - -- Event player left unit - if Event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT and _playername then - self:_PlayerLeft(EventData) - end - - -- Event crash ==> player left unit - if Event.id == world.event.S_EVENT_CRASH and _playername then - self:_PlayerLeft(EventData) - end - ---[[ - -- Event eject ==> player left unit - if Event.id == world.event.S_EVENT_EJECTION and _playername then - self:_PlayerLeft(EventData) - end - - -- Event pilot dead ==> player left unit - if Event.id == world.event.S_EVENT_PILOT_DEAD and _playername then - self:_PlayerLeft(EventData) - end -]] -end --- Function called my MOOSE event handler when a player enters a unit. -- @param #PSEUDOATC self @@ -303,7 +217,9 @@ function PSEUDOATC:_OnBirth(EventData) -- Get unit and player. local _unitName=EventData.IniUnitName - local _unit, _playername=self:_GetPlayerUnitAndName(_unitName) + --local _unit, _playername=self:_GetPlayerUnitAndName(_unitName) + local _unit = EventData.IniUnit + local _playername = EventData.IniPlayerName -- Check if a player entered. if _unit and _playername then @@ -320,7 +236,10 @@ function PSEUDOATC:_PlayerLeft(EventData) -- Get unit and player. local _unitName=EventData.IniUnitName - local _unit, _playername=self:_GetPlayerUnitAndName(_unitName) + --local _unit, _playername=self:_GetPlayerUnitAndName(_unitName) + + local _unit = EventData.IniUnit + local _playername = EventData.IniPlayerName -- Check if a player left. if _unit and _playername then @@ -335,18 +254,16 @@ function PSEUDOATC:_PlayerLanded(EventData) self:F({EventData=EventData}) -- Get unit, player and place. - local _unitName=EventData.IniUnitName - local _unit, _playername=self:_GetPlayerUnitAndName(_unitName) + local _unitName=EventData.IniUnitName + local _unit = EventData.IniUnit + local _playername = EventData.IniPlayerName + --local _unit, _playername=self:_GetPlayerUnitAndName(_unitName) local _base=nil local _baseName=nil if EventData.place then _base=EventData.place _baseName=EventData.place:getName() end --- if EventData.subplace then --- local _subPlace=EventData.subplace --- local _subPlaceName=EventData.subplace:getName() --- end -- Call landed function. if _unit and _playername and _base then @@ -361,8 +278,10 @@ function PSEUDOATC:_PlayerTakeOff(EventData) self:F({EventData=EventData}) -- Get unit, player and place. - local _unitName=EventData.IniUnitName - local _unit,_playername=self:_GetPlayerUnitAndName(_unitName) + local _unitName=EventData.IniUnitName + local _unit = EventData.IniUnit + local _playername = EventData.IniPlayerName + --local _unit,_playername=self:_GetPlayerUnitAndName(_unitName) local _base=nil local _baseName=nil if EventData.place then @@ -450,9 +369,6 @@ function PSEUDOATC:PlayerLanded(unit, place) local group=unit:GetGroup() local GID=group:GetID() local UID=unit:GetDCSObject():getID() - --local PlayerName=self.group[GID].player[UID].playername - --local UnitName=self.group[GID].player[UID].unitname - --local GroupName=self.group[GID].player[UID].groupname local PlayerName = unit:GetPlayerName() or "Ghost" local UnitName = unit:GetName() or "Ghostplane" local GroupName = group:GetName() or "Ghostgroup" @@ -483,12 +399,6 @@ function PSEUDOATC:PlayerTakeOff(unit, place) -- Gather some information. local group=unit:GetGroup() - --local GID=group:GetID() - --local UID=unit:GetDCSObject():getID() - --local PlayerName=self.group[GID].player[UID].playername - --local CallSign=self.group[GID].player[UID].callsign - --local UnitName=self.group[GID].player[UID].unitname - --local GroupName=self.group[GID].player[UID].groupname local PlayerName = unit:GetPlayerName() or "Ghost" local UnitName = unit:GetName() or "Ghostplane" local GroupName = group:GetName() or "Ghostgroup" @@ -926,7 +836,7 @@ function PSEUDOATC:AltitudeTimeStart(GID, UID) self:T(PSEUDOATC.id..string.format("Starting altitude report timer for player ID %d.", UID)) -- Start timer. Altitude is reported every ~3 seconds. - self.group[GID].player[UID].altimer, self.group[GID].player[UID].altimerid=SCHEDULER:New(nil, self.ReportHeight, {self, GID, UID, 0.1, true}, 1, 3) + self.group[GID].player[UID].altimer, self.group[GID].player[UID].altimerid=SCHEDULER:New(nil, self.ReportHeight, {self, GID, UID, 1, true}, 1, 3) end --- Stop/destroy DCS scheduler function for reporting altitude. diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index 9f6a38038..6a0a032d5 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -5826,7 +5826,7 @@ function AIRBOSS:_ScanCarrierZone() if knownflight then -- Check if flight is AI and if we want to handle it at all. - if knownflight.ai and knownflight.flag == -100 and self.handleai and false then --Disabled AI handling because of incorrect OPSGROUP reference! + if knownflight.ai and knownflight.flag == -100 and self.handleai and false then --Disabled AI handling because of incorrect OPSGROUP reference! local putintomarshal = false @@ -8102,7 +8102,7 @@ end -- @param Core.Event#EVENTDATA EventData function AIRBOSS:OnEventBirth( EventData ) self:F3( { eventbirth = EventData } ) - + -- Nil checks. if EventData == nil then self:E( self.lid .. "ERROR: EventData=nil in event BIRTH!" ) @@ -8114,7 +8114,9 @@ function AIRBOSS:OnEventBirth( EventData ) self:E( EventData ) return end - + + if EventData.IniObjectCategory ~= Object.Category.UNIT then return end + local _unitName = EventData.IniUnitName local _unit, _playername = self:_GetPlayerUnitAndName( _unitName ) @@ -9792,23 +9794,23 @@ function AIRBOSS:_Groove( playerData ) end end - - -- Long V/STOL groove time Wave Off over 75 seconds to IC - TOPGUN level Only. --pene testing (WIP)--- Need to think more about this. - + + -- Long V/STOL groove time Wave Off over 75 seconds to IC - TOPGUN level Only. --pene testing (WIP)--- Need to think more about this. + --if rho>=RAR and rho<=RIC and not playerData.waveoff and playerData.difficulty==AIRBOSS.Difficulty.HARD and playerData.actype== AIRBOSS.AircraftCarrier.AV8B then -- Get groove time --local vSlow=groovedata.time -- If too slow wave off. --if vSlow >75 then - + -- LSO Wave off! --self:RadioTransmission(self.LSORadio, self.LSOCall.WAVEOFF, nil, nil, nil, true) --playerData.Tlso=timer.getTime() - + -- Player was waved Off --playerData.waveoff=true --return - --end + --end --end -- Groovedata step. @@ -10162,7 +10164,7 @@ function AIRBOSS:_GetSternCoord() elseif case==2 or case==1 then -- V/Stol: Translate 8 meters port. self.sterncoord:Translate(self.carrierparam.sterndist, hdg, true, true):Translate(8, FB-90, true, true) - end + end elseif self.carriertype==AIRBOSS.CarrierType.STENNIS then -- Stennis: translate 7 meters starboard wrt Final bearing. self.sterncoord:Translate( self.carrierparam.sterndist, hdg, true, true ):Translate( 7, FB + 90, true, true ) @@ -11302,7 +11304,7 @@ function AIRBOSS:_GetOptLandingCoordinate() self.landingcoord:SetAltitude(UTILS.FeetToMeters(120)) end - + else -- Ideally we want to land between 2nd and 3rd wire.