Core code formatting and typo fixes. (#1669)

* Update Beacon.lua

Code formatting and minor typo/text fixes.

* Update Database.lua

Code formatting and minor typo/text fixes.

* Update Event.lua

Code formatting and minor typo/text fixes.
This commit is contained in:
TommyC81 2021-12-19 11:47:07 +04:00 committed by GitHub
parent 607c52c0b7
commit 55cee46a8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 571 additions and 635 deletions

View File

@ -95,11 +95,11 @@ BEACON.Type={
-- @field #number TACAN TACtical Air Navigation system on ground.
-- @field #number TACAN_TANKER_X TACtical Air Navigation system for tankers on X band.
-- @field #number TACAN_TANKER_Y TACtical Air Navigation system for tankers on Y band.
-- @field #number VOR Very High Frequency Omni-Directional Range
-- @field #number VOR Very High Frequency Omnidirectional Range
-- @field #number ILS_LOCALIZER ILS localizer
-- @field #number ILS_GLIDESLOPE ILS glideslope.
-- @field #number ILS_GLIDESLOPE ILS glide slope.
-- @field #number PRGM_LOCALIZER PRGM localizer.
-- @field #number PRGM_GLIDESLOPE PRGM glideslope.
-- @field #number PRGM_GLIDESLOPE PRGM glide slope.
-- @field #number BROADCAST_STATION Broadcast station.
-- @field #number VORTAC Radio-based navigational aid for aircraft pilots consisting of a co-located VHF omnidirectional range (VOR) beacon and a tactical air navigation system (TACAN) beacon.
-- @field #number TACAN_AA_MODE_X TACtical Air Navigation for aircraft on X band.
@ -131,28 +131,27 @@ BEACON.System={
-- If you want to create a BEACON, you probably should use @{Wrapper.Positionable#POSITIONABLE.GetBeacon}() instead.
-- @param #BEACON self
-- @param Wrapper.Positionable#POSITIONABLE Positionable The @{Positionable} that will receive radio capabilities.
-- @return #BEACON Beacon object or #nil if the positionable is invalid.
function BEACON:New(Positionable)
-- @return #BEACON Beacon object or #nil if the POSITIONABLE is invalid.
function BEACON:New( Positionable )
-- Inherit BASE.
local self=BASE:Inherit(self, BASE:New()) --#BEACON
local self = BASE:Inherit( self, BASE:New() ) -- #BEACON
-- Debug.
self:F(Positionable)
self:F( Positionable )
-- Set positionable.
if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid
if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure POSITIONABLE is valid
self.Positionable = Positionable
self.name=Positionable:GetName()
self:I(string.format("New BEACON %s", tostring(self.name)))
self.name = Positionable:GetName()
self:I( string.format( "New BEACON %s", tostring( self.name ) ) )
return self
end
self:E({"The passed positionable is invalid, no BEACON created", Positionable})
self:E( { "The passed POSITIONABLE is invalid, no BEACON created", Positionable } )
return nil
end
--- Activates a TACAN BEACON.
-- @param #BEACON self
-- @param #number Channel TACAN channel, i.e. the "10" part in "10Y".
@ -162,51 +161,53 @@ end
-- @param #number Duration How long will the beacon last in seconds. Omit for forever.
-- @return #BEACON self
-- @usage
--
-- -- Let's create a TACAN Beacon for a tanker
-- local myUnit = UNIT:FindByName("MyUnit")
-- local myBeacon = myUnit:GetBeacon() -- Creates the beacon
--
-- myBeacon:ActivateTACAN(20, "Y", "TEXACO", true) -- Activate the beacon
function BEACON:ActivateTACAN(Channel, Mode, Message, Bearing, Duration)
self:T({channel=Channel, mode=Mode, callsign=Message, bearing=Bearing, duration=Duration})
--
function BEACON:ActivateTACAN( Channel, Mode, Message, Bearing, Duration )
self:T( { channel = Channel, mode = Mode, callsign = Message, bearing = Bearing, duration = Duration } )
-- Get frequency.
local Frequency=UTILS.TACANToFrequency(Channel, Mode)
local Frequency = UTILS.TACANToFrequency( Channel, Mode )
-- Check.
if not Frequency then
self:E({"The passed TACAN channel is invalid, the BEACON is not emitting"})
self:E( { "The passed TACAN channel is invalid, the BEACON is not emitting" } )
return self
end
-- Beacon type.
local Type=BEACON.Type.TACAN
local Type = BEACON.Type.TACAN
-- Beacon system.
local System=BEACON.System.TACAN
local System = BEACON.System.TACAN
-- Check if unit is an aircraft and set system accordingly.
local AA=self.Positionable:IsAir()
local AA = self.Positionable:IsAir()
if AA then
System=5 --NOTE: 5 is how you cat the correct tanker behaviour! --BEACON.System.TACAN_TANKER
System = 5 -- NOTE: 5 is how you cat the correct tanker behaviour! --BEACON.System.TACAN_TANKER
-- Check if "Y" mode is selected for aircraft.
if Mode~="Y" then
self:E({"WARNING: The POSITIONABLE you want to attach the AA Tacan Beacon is an aircraft: Mode should Y !The BEACON is not emitting.", self.Positionable})
if Mode ~= "Y" then
self:E( { "WARNING: The POSITIONABLE you want to attach the AA TACAN Beacon is an aircraft: Mode should Y! The BEACON is not emitting.", self.Positionable } )
end
end
-- Attached unit.
local UnitID=self.Positionable:GetID()
local UnitID = self.Positionable:GetID()
-- Debug.
self:I({string.format("BEACON Activating TACAN %s: Channel=%d%s, Morse=%s, Bearing=%s, Duration=%s!", tostring(self.name), Channel, Mode, Message, tostring(Bearing), tostring(Duration))})
self:I( { string.format( "BEACON Activating TACAN %s: Channel=%d%s, Morse=%s, Bearing=%s, Duration=%s!", tostring( self.name ), Channel, Mode, Message, tostring( Bearing ), tostring( Duration ) ) } )
-- Start beacon.
self.Positionable:CommandActivateBeacon(Type, System, Frequency, UnitID, Channel, Mode, AA, Message, Bearing)
self.Positionable:CommandActivateBeacon( Type, System, Frequency, UnitID, Channel, Mode, AA, Message, Bearing )
-- Stop sheduler.
-- Stop scheduler.
if Duration then
self.Positionable:DeactivateBeacon(Duration)
self.Positionable:DeactivateBeacon( Duration )
end
return self
@ -218,21 +219,21 @@ end
-- @param #string Callsign The Message that is going to be coded in Morse and broadcasted by the beacon.
-- @param #number Duration How long will the beacon last in seconds. Omit for forever.
-- @return #BEACON self
function BEACON:ActivateICLS(Channel, Callsign, Duration)
self:F({Channel=Channel, Callsign=Callsign, Duration=Duration})
function BEACON:ActivateICLS( Channel, Callsign, Duration )
self:F( { Channel = Channel, Callsign = Callsign, Duration = Duration } )
-- Attached unit.
local UnitID=self.Positionable:GetID()
local UnitID = self.Positionable:GetID()
-- Debug
self:T2({"ICLS BEACON started!"})
self:T2( { "ICLS BEACON started!" } )
-- Start beacon.
self.Positionable:CommandActivateICLS(Channel, UnitID, Callsign)
self.Positionable:CommandActivateICLS( Channel, UnitID, Callsign )
-- Stop sheduler
-- Stop scheduler
if Duration then -- Schedule the stop of the BEACON if asked by the MD
self.Positionable:DeactivateBeacon(Duration)
self.Positionable:DeactivateBeacon( Duration )
end
return self
@ -246,24 +247,26 @@ end
-- @param #number BeaconDuration How long will the beacon last in seconds. Omit for forever.
-- @return #BEACON self
-- @usage
--
-- -- Let's create a TACAN Beacon for a tanker
-- local myUnit = UNIT:FindByName("MyUnit")
-- local myBeacon = myUnit:GetBeacon() -- Creates the beacon
--
-- myBeacon:AATACAN(20, "TEXACO", true) -- Activate the beacon
function BEACON:AATACAN(TACANChannel, Message, Bearing, BeaconDuration)
self:F({TACANChannel, Message, Bearing, BeaconDuration})
--
function BEACON:AATACAN( TACANChannel, Message, Bearing, BeaconDuration )
self:F( { TACANChannel, Message, Bearing, BeaconDuration } )
local IsValid = true
if not self.Positionable:IsAir() then
self:E({"The POSITIONABLE you want to attach the AA Tacan Beacon is not an aircraft ! The BEACON is not emitting", self.Positionable})
self:E( { "The POSITIONABLE you want to attach the AA TACAN Beacon is not an aircraft! The BEACON is not emitting", self.Positionable } )
IsValid = false
end
local Frequency = self:_TACANToFrequency(TACANChannel, "Y")
local Frequency = self:_TACANToFrequency( TACANChannel, "Y" )
if not Frequency then
self:E({"The passed TACAN channel is invalid, the BEACON is not emitting"})
self:E( { "The passed TACAN channel is invalid, the BEACON is not emitting" } )
IsValid = false
end
@ -277,22 +280,21 @@ function BEACON:AATACAN(TACANChannel, Message, Bearing, BeaconDuration)
end
if IsValid then -- Starts the BEACON
self:T2({"AA TACAN BEACON started !"})
self.Positionable:SetCommand({
self:T2( { "AA TACAN BEACON started !" } )
self.Positionable:SetCommand( {
id = "ActivateBeacon",
params = {
type = 4,
system = System,
callsign = Message,
frequency = Frequency,
}
})
},
} )
if BeaconDuration then -- Schedule the stop of the BEACON if asked by the MD
SCHEDULER:New(nil,
function()
SCHEDULER:New( nil, function()
self:StopAATACAN()
end, {}, BeaconDuration)
end, {}, BeaconDuration )
end
end
@ -305,18 +307,16 @@ end
function BEACON:StopAATACAN()
self:F()
if not self.Positionable then
self:E({"Start the beacon first before stoping it !"})
self:E( { "Start the beacon first before stopping it!" } )
else
self.Positionable:SetCommand({
self.Positionable:SetCommand( {
id = 'DeactivateBeacon',
params = {
}
})
params = {},
} )
end
end
--- Activates a general pupose Radio Beacon
--- Activates a general purpose Radio Beacon
-- This uses the very generic singleton function "trigger.action.radioTransmission()" provided by DCS to broadcast a sound file on a specific frequency.
-- Although any frequency could be used, only 2 DCS Modules can home on radio beacons at the time of writing : the Huey and the Mi-8.
-- They can home in on these specific frequencies :
@ -342,53 +342,52 @@ end
--
-- -- Set the beacon and start it
-- UnitBeacon:RadioBeacon("MySoundFileSOS.ogg", 40, radio.modulation.FM, 20, 5*60)
function BEACON:RadioBeacon(FileName, Frequency, Modulation, Power, BeaconDuration)
self:F({FileName, Frequency, Modulation, Power, BeaconDuration})
function BEACON:RadioBeacon( FileName, Frequency, Modulation, Power, BeaconDuration )
self:F( { FileName, Frequency, Modulation, Power, BeaconDuration } )
local IsValid = false
-- Check the filename
if type(FileName) == "string" then
if FileName:find(".ogg") or FileName:find(".wav") then
if not FileName:find("l10n/DEFAULT/") then
if type( FileName ) == "string" then
if FileName:find( ".ogg" ) or FileName:find( ".wav" ) then
if not FileName:find( "l10n/DEFAULT/" ) then
FileName = "l10n/DEFAULT/" .. FileName
end
IsValid = true
end
end
if not IsValid then
self:E({"File name invalid. Maybe something wrong with the extension ? ", FileName})
self:E( { "File name invalid. Maybe something wrong with the extension? ", FileName } )
end
-- Check the Frequency
if type(Frequency) ~= "number" and IsValid then
self:E({"Frequency invalid. ", Frequency})
if type( Frequency ) ~= "number" and IsValid then
self:E( { "Frequency invalid. ", Frequency } )
IsValid = false
end
Frequency = Frequency * 1000000 -- Conversion to Hz
-- Check the modulation
if Modulation ~= radio.modulation.AM and Modulation ~= radio.modulation.FM and IsValid then --TODO Maybe make this future proof if ED decides to add an other modulation ?
self:E({"Modulation is invalid. Use DCS's enum radio.modulation.", Modulation})
if Modulation ~= radio.modulation.AM and Modulation ~= radio.modulation.FM and IsValid then -- TODO: Maybe make this future proof if ED decides to add an other modulation ?
self:E( { "Modulation is invalid. Use DCS's enum radio.modulation.", Modulation } )
IsValid = false
end
-- Check the Power
if type(Power) ~= "number" and IsValid then
self:E({"Power is invalid. ", Power})
if type( Power ) ~= "number" and IsValid then
self:E( { "Power is invalid. ", Power } )
IsValid = false
end
Power = math.floor(math.abs(Power)) --TODO Find what is the maximum power allowed by DCS and limit power to that
Power = math.floor( math.abs( Power ) ) -- TODO: Find what is the maximum power allowed by DCS and limit power to that
if IsValid then
self:T2({"Activating Beacon on ", Frequency, Modulation})
self:T2( { "Activating Beacon on ", Frequency, Modulation } )
-- Note that this is looped. I have to give this transmission a unique name, I use the class ID
trigger.action.radioTransmission(FileName, self.Positionable:GetPositionVec3(), Modulation, true, Frequency, Power, tostring(self.ID))
trigger.action.radioTransmission( FileName, self.Positionable:GetPositionVec3(), Modulation, true, Frequency, Power, tostring( self.ID ) )
if BeaconDuration then -- Schedule the stop of the BEACON if asked by the MD
SCHEDULER:New( nil,
function()
SCHEDULER:New( nil, function()
self:StopRadioBeacon()
end, {}, BeaconDuration)
end, {}, BeaconDuration )
end
end
end
@ -399,7 +398,7 @@ end
function BEACON:StopRadioBeacon()
self:F()
-- The unique name of the transmission is the class ID
trigger.action.stopRadioTransmission(tostring(self.ID))
trigger.action.stopRadioTransmission( tostring( self.ID ) )
return self
end
@ -407,19 +406,19 @@ end
-- @param #BEACON self
-- @param #number TACANChannel
-- @param #string TACANMode
-- @return #number Frequecy
-- @return #number Frequency
-- @return #nil if parameters are invalid
function BEACON:_TACANToFrequency(TACANChannel, TACANMode)
self:F3({TACANChannel, TACANMode})
function BEACON:_TACANToFrequency( TACANChannel, TACANMode )
self:F3( { TACANChannel, TACANMode } )
if type(TACANChannel) ~= "number" then
if type( TACANChannel ) ~= "number" then
if TACANMode ~= "X" and TACANMode ~= "Y" then
return nil -- error in arguments
end
end
-- This code is largely based on ED's code, in DCS World\Scripts\World\Radio\BeaconTypes.lua, line 137.
-- I have no idea what it does but it seems to work
-- This code is largely based on ED's code, in DCS World\Scripts\World\Radio\BeaconTypes.lua, line 137.
-- I have no idea what it does but it seems to work
local A = 1151 -- 'X', channel >= 64
local B = 64 -- channel >= 64

View File

@ -31,7 +31,6 @@
-- @module Core.Database
-- @image Core_Database.JPG
--- @type DATABASE
-- @field #string ClassName Name of the class.
-- @field #table Templates Templates: Units, Groups, Statics, ClientsByName, ClientsByID.
@ -51,7 +50,7 @@
-- * PLAYERS
-- * CARGOS
--
-- On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.
-- On top, for internal MOOSE administration purposes, the DATABASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.
--
-- The singleton object **_DATABASE** is automatically created by MOOSE, that administers all objects within the mission.
-- Moose refers to **_DATABASE** within the framework extensively, but you can also refer to the _DATABASE object within your missions if required.
@ -90,22 +89,19 @@ DATABASE = {
FLIGHTCONTROLS = {},
}
local _DATABASECoalition =
{
local _DATABASECoalition = {
[1] = "Red",
[2] = "Blue",
[3] = "Neutral",
}
}
local _DATABASECategory =
{
local _DATABASECategory = {
["plane"] = Unit.Category.AIRPLANE,
["helicopter"] = Unit.Category.HELICOPTER,
["vehicle"] = Unit.Category.GROUND_UNIT,
["ship"] = Unit.Category.SHIP,
["static"] = Unit.Category.STRUCTURE,
}
}
--- Creates a new DATABASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
-- @param #DATABASE self
@ -129,15 +125,15 @@ function DATABASE:New()
self:HandleEvent( EVENTS.DeleteCargo )
self:HandleEvent( EVENTS.NewZone )
self:HandleEvent( EVENTS.DeleteZone )
--self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit ) -- This is not working anymore!, handling this through the birth event.
-- self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit ) -- This is not working anymore!, handling this through the birth event.
self:HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
self:_RegisterTemplates()
self:_RegisterGroupsAndUnits()
self:_RegisterClients()
self:_RegisterStatics()
--self:_RegisterAirbases()
--self:_RegisterPlayers()
-- self:_RegisterAirbases()
-- self:_RegisterPlayers()
self.UNITS_Position = 0
@ -154,7 +150,6 @@ function DATABASE:FindUnit( UnitName )
return UnitFound
end
--- Adds a Unit based on the Unit Name in the DATABASE.
-- @param #DATABASE self
-- @param #string DCSUnitName Unit name.
@ -166,19 +161,18 @@ function DATABASE:AddUnit( DCSUnitName )
-- Debug info.
self:T( { "Add UNIT:", DCSUnitName } )
--local UnitRegister = UNIT:Register( DCSUnitName )
-- local UnitRegister = UNIT:Register( DCSUnitName )
-- Register unit
self.UNITS[DCSUnitName]=UNIT:Register(DCSUnitName)
self.UNITS[DCSUnitName] = UNIT:Register( DCSUnitName )
-- This is not used anywhere in MOOSE as far as I can see so I remove it until there comes an error somewhere.
--table.insert(self.UNITS_Index, DCSUnitName )
-- table.insert(self.UNITS_Index, DCSUnitName )
end
return self.UNITS[DCSUnitName]
end
--- Deletes a Unit from the DATABASE based on the Unit Name.
-- @param #DATABASE self
function DATABASE:DeleteUnit( DCSUnitName )
@ -200,7 +194,6 @@ function DATABASE:AddStatic( DCSStaticName )
return nil
end
--- Deletes a Static from the DATABASE based on the Static Name.
-- @param #DATABASE self
function DATABASE:DeleteStatic( DCSStaticName )
@ -240,7 +233,6 @@ function DATABASE:AddAirbase( AirbaseName )
return self.AIRBASES[AirbaseName]
end
--- Deletes a Airbase from the DATABASE based on the Airbase Name.
-- @param #DATABASE self
-- @param #string AirbaseName The name of the airbase
@ -259,7 +251,6 @@ function DATABASE:FindAirbase( AirbaseName )
return AirbaseFound
end
do -- Zones
--- Finds a @{Zone} based on the zone name.
@ -283,7 +274,6 @@ do -- Zones
end
end
--- Deletes a @{Zone} from the DATABASE based on the zone name.
-- @param #DATABASE self
-- @param #string ZoneName The name of the zone.
@ -292,30 +282,29 @@ do -- Zones
self.ZONES[ZoneName] = nil
end
--- Private method that registers new ZONE_BASE derived objects within the DATABASE Object.
-- @param #DATABASE self
-- @return #DATABASE self
function DATABASE:_RegisterZones()
for ZoneID, ZoneData in pairs(env.mission.triggers.zones) do
for ZoneID, ZoneData in pairs( env.mission.triggers.zones ) do
local ZoneName = ZoneData.name
-- Color
local color=ZoneData.color or {1, 0, 0, 0.15}
local color = ZoneData.color or { 1, 0, 0, 0.15 }
-- Create new Zone
local Zone=nil --Core.Zone#ZONE_BASE
local Zone = nil -- Core.Zone#ZONE_BASE
if ZoneData.type==0 then
if ZoneData.type == 0 then
---
-- Circular zone
---
self:I(string.format("Register ZONE: %s (Circular)", ZoneName))
self:I( string.format( "Register ZONE: %s (Circular)", ZoneName ) )
Zone=ZONE:New(ZoneName)
Zone = ZONE:New( ZoneName )
else
@ -323,27 +312,27 @@ do -- Zones
-- Quad-point zone
---
self:I(string.format("Register ZONE: %s (Polygon, Quad)", ZoneName))
self:I( string.format( "Register ZONE: %s (Polygon, Quad)", ZoneName ) )
Zone=ZONE_POLYGON_BASE:New(ZoneName, ZoneData.verticies)
Zone = ZONE_POLYGON_BASE:New( ZoneName, ZoneData.verticies )
--for i,vec2 in pairs(ZoneData.verticies) do
-- for i,vec2 in pairs(ZoneData.verticies) do
-- local coord=COORDINATE:NewFromVec2(vec2)
-- coord:MarkToAll(string.format("%s Point %d", ZoneName, i))
--end
-- end
end
if Zone then
-- Store color of zone.
Zone.Color=color
Zone.Color = color
-- Store in DB.
self.ZONENAMES[ZoneName] = ZoneName
-- Add zone.
self:AddZone(ZoneName, Zone)
self:AddZone( ZoneName, Zone )
end
@ -351,20 +340,20 @@ do -- Zones
-- Polygon zones defined by late activated groups.
for ZoneGroupName, ZoneGroup in pairs( self.GROUPS ) do
if ZoneGroupName:match("#ZONE_POLYGON") then
if ZoneGroupName:match( "#ZONE_POLYGON" ) then
local ZoneName1 = ZoneGroupName:match("(.*)#ZONE_POLYGON")
local ZoneName2 = ZoneGroupName:match(".*#ZONE_POLYGON(.*)")
local ZoneName = ZoneName1 .. ( ZoneName2 or "" )
local ZoneName1 = ZoneGroupName:match( "(.*)#ZONE_POLYGON" )
local ZoneName2 = ZoneGroupName:match( ".*#ZONE_POLYGON(.*)" )
local ZoneName = ZoneName1 .. (ZoneName2 or "")
-- Debug output
self:I(string.format("Register ZONE: %s (Polygon)", ZoneName))
self:I( string.format( "Register ZONE: %s (Polygon)", ZoneName ) )
-- Create a new polygon zone.
local Zone_Polygon = ZONE_POLYGON:New( ZoneName, ZoneGroup )
-- Set color.
Zone_Polygon:SetColor({1, 0, 0}, 0.15)
Zone_Polygon:SetColor( { 1, 0, 0 }, 0.15 )
-- Store name in DB.
self.ZONENAMES[ZoneName] = ZoneName
@ -376,7 +365,6 @@ do -- Zones
end
end -- zone
do -- Zone_Goal
@ -402,7 +390,6 @@ do -- Zone_Goal
end
end
--- Deletes a @{Zone} from the DATABASE based on the zone name.
-- @param #DATABASE self
-- @param #string ZoneName The name of the zone.
@ -424,7 +411,6 @@ do -- cargo
end
end
--- Deletes a Cargo from the DATABASE based on the Cargo Name.
-- @param #DATABASE self
-- @param #string CargoName The name of the airbase
@ -466,38 +452,38 @@ do -- cargo
for CargoGroupName, CargoGroup in pairs( Groups ) do
if self:IsCargo( CargoGroupName ) then
local CargoInfo = CargoGroupName:match("#CARGO(.*)")
local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)")
local CargoName1 = CargoGroupName:match("(.*)#CARGO%(.*%)")
local CargoName2 = CargoGroupName:match(".*#CARGO%(.*%)(.*)")
local CargoName = CargoName1 .. ( CargoName2 or "" )
local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?")
local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") or CargoName
local LoadRadius = CargoParam and tonumber( CargoParam:match( "RR=([%a%d]+),?") )
local NearRadius = CargoParam and tonumber( CargoParam:match( "NR=([%a%d]+),?") )
local CargoInfo = CargoGroupName:match( "#CARGO(.*)" )
local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)" )
local CargoName1 = CargoGroupName:match( "(.*)#CARGO%(.*%)" )
local CargoName2 = CargoGroupName:match( ".*#CARGO%(.*%)(.*)" )
local CargoName = CargoName1 .. (CargoName2 or "")
local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?" )
local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?" ) or CargoName
local LoadRadius = CargoParam and tonumber( CargoParam:match( "RR=([%a%d]+),?" ) )
local NearRadius = CargoParam and tonumber( CargoParam:match( "NR=([%a%d]+),?" ) )
self:I({"Register CargoGroup:",Type=Type,Name=Name,LoadRadius=LoadRadius,NearRadius=NearRadius})
self:I( { "Register CargoGroup:", Type = Type, Name = Name, LoadRadius = LoadRadius, NearRadius = NearRadius } )
CARGO_GROUP:New( CargoGroup, Type, Name, LoadRadius, NearRadius )
end
end
for CargoStaticName, CargoStatic in pairs( self.STATICS ) do
if self:IsCargo( CargoStaticName ) then
local CargoInfo = CargoStaticName:match("#CARGO(.*)")
local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)")
local CargoName = CargoStaticName:match("(.*)#CARGO")
local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?")
local Category = CargoParam and CargoParam:match( "C=([%a%d ]+),?")
local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") or CargoName
local LoadRadius = CargoParam and tonumber( CargoParam:match( "RR=([%a%d]+),?") )
local NearRadius = CargoParam and tonumber( CargoParam:match( "NR=([%a%d]+),?") )
local CargoInfo = CargoStaticName:match( "#CARGO(.*)" )
local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)" )
local CargoName = CargoStaticName:match( "(.*)#CARGO" )
local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?" )
local Category = CargoParam and CargoParam:match( "C=([%a%d ]+),?" )
local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?" ) or CargoName
local LoadRadius = CargoParam and tonumber( CargoParam:match( "RR=([%a%d]+),?" ) )
local NearRadius = CargoParam and tonumber( CargoParam:match( "NR=([%a%d]+),?" ) )
if Category == "SLING" then
self:I({"Register CargoSlingload:",Type=Type,Name=Name,LoadRadius=LoadRadius,NearRadius=NearRadius})
self:I( { "Register CargoSlingload:", Type = Type, Name = Name, LoadRadius = LoadRadius, NearRadius = NearRadius } )
CARGO_SLINGLOAD:New( CargoStatic, Type, Name, LoadRadius, NearRadius )
else
if Category == "CRATE" then
self:I({"Register CargoCrate:",Type=Type,Name=Name,LoadRadius=LoadRadius,NearRadius=NearRadius})
self:I( { "Register CargoCrate:", Type = Type, Name = Name, LoadRadius = LoadRadius, NearRadius = NearRadius } )
CARGO_CRATE:New( CargoStatic, Type, Name, LoadRadius, NearRadius )
end
end
@ -518,7 +504,6 @@ function DATABASE:FindClient( ClientName )
return ClientFound
end
--- Adds a CLIENT based on the ClientName in the DATABASE.
-- @param #DATABASE self
-- @param #string ClientName Name of the Client unit.
@ -532,7 +517,6 @@ function DATABASE:AddClient( ClientName )
return self.CLIENTS[ClientName]
end
--- Finds a GROUP based on the GroupName.
-- @param #DATABASE self
-- @param #string GroupName
@ -543,7 +527,6 @@ function DATABASE:FindGroup( GroupName )
return GroupFound
end
--- Adds a GROUP based on the GroupName in the DATABASE.
-- @param #DATABASE self
function DATABASE:AddGroup( GroupName )
@ -591,7 +574,6 @@ function DATABASE:GetPlayers()
return self.PLAYERS
end
--- Get the player table from the DATABASE, which contains all UNIT objects.
-- The player table contains all UNIT objects of the player with the key the name of the player (PlayerName).
-- @param #DATABASE self
@ -604,7 +586,6 @@ function DATABASE:GetPlayerUnits()
return self.PLAYERUNITS
end
--- Get the player table from the DATABASE which have joined in the mission historically.
-- The player table contains all UNIT objects with the key the name of the player (PlayerName).
-- @param #DATABASE self
@ -617,7 +598,6 @@ function DATABASE:GetPlayersJoined()
return self.PLAYERSJOINED
end
--- Instantiate new Groups within the DCSRTE.
-- This method expects EXACTLY the same structure as a structure within the ME, and needs 2 additional fields defined:
-- SpawnCountryID, SpawnCategoryID
@ -722,7 +702,7 @@ function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, Category
for unit_num, UnitTemplate in pairs( GroupTemplate.units ) do
UnitTemplate.name = env.getValueDictByKey(UnitTemplate.name)
UnitTemplate.name = env.getValueDictByKey( UnitTemplate.name )
self.Templates.Units[UnitTemplate.name] = {}
self.Templates.Units[UnitTemplate.name].UnitName = UnitTemplate.name
@ -742,7 +722,7 @@ function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, Category
self.Templates.ClientsByID[UnitTemplate.unitId] = UnitTemplate
end
UnitNames[#UnitNames+1] = self.Templates.Units[UnitTemplate.name].UnitName
UnitNames[#UnitNames + 1] = self.Templates.Units[UnitTemplate.name].UnitName
end
-- Debug info.
@ -750,9 +730,8 @@ function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, Category
Coalition = self.Templates.Groups[GroupTemplateName].CoalitionID,
Category = self.Templates.Groups[GroupTemplateName].CategoryID,
Country = self.Templates.Groups[GroupTemplateName].CountryID,
Units = UnitNames
}
)
Units = UnitNames,
} )
end
--- Get group template.
@ -778,7 +757,7 @@ function DATABASE:_RegisterStaticTemplate( StaticTemplate, CoalitionID, Category
local StaticTemplate = UTILS.DeepCopy( StaticTemplate )
local StaticTemplateName = env.getValueDictByKey(StaticTemplate.name)
local StaticTemplateName = env.getValueDictByKey( StaticTemplate.name )
self.Templates.Statics[StaticTemplateName] = self.Templates.Statics[StaticTemplateName] or {}
@ -797,9 +776,8 @@ function DATABASE:_RegisterStaticTemplate( StaticTemplate, CoalitionID, Category
self:T( { Static = self.Templates.Statics[StaticTemplateName].StaticName,
Coalition = self.Templates.Statics[StaticTemplateName].CoalitionID,
Category = self.Templates.Statics[StaticTemplateName].CategoryID,
Country = self.Templates.Statics[StaticTemplateName].CountryID
}
)
Country = self.Templates.Statics[StaticTemplateName].CountryID,
} )
self:AddStatic( StaticTemplateName )
@ -815,7 +793,7 @@ function DATABASE:GetStaticGroupTemplate( StaticName )
local StaticTemplate = self.Templates.Statics[StaticName].GroupTemplate
return StaticTemplate, self.Templates.Statics[StaticName].CoalitionID, self.Templates.Statics[StaticName].CategoryID, self.Templates.Statics[StaticName].CountryID
else
self:E("ERROR: Static group template does NOT exist for static "..tostring(StaticName))
self:E( "ERROR: Static group template does NOT exist for static " .. tostring( StaticName ) )
return nil
end
end
@ -829,7 +807,7 @@ function DATABASE:GetStaticUnitTemplate( StaticName )
local UnitTemplate = self.Templates.Statics[StaticName].UnitTemplate
return UnitTemplate, self.Templates.Statics[StaticName].CoalitionID, self.Templates.Statics[StaticName].CategoryID, self.Templates.Statics[StaticName].CountryID
else
self:E("ERROR: Static unit template does NOT exist for static "..tostring(StaticName))
self:E( "ERROR: Static unit template does NOT exist for static " .. tostring( StaticName ) )
return nil
end
end
@ -842,7 +820,7 @@ function DATABASE:GetGroupNameFromUnitName( UnitName )
if self.Templates.Units[UnitName] then
return self.Templates.Units[UnitName].GroupName
else
self:E("ERROR: Unit template does not exist for unit "..tostring(UnitName))
self:E( "ERROR: Unit template does not exist for unit " .. tostring( UnitName ) )
return nil
end
end
@ -855,7 +833,7 @@ function DATABASE:GetGroupTemplateFromUnitName( UnitName )
if self.Templates.Units[UnitName] then
return self.Templates.Units[UnitName].GroupTemplate
else
self:E("ERROR: Unit template does not exist for unit "..tostring(UnitName))
self:E( "ERROR: Unit template does not exist for unit " .. tostring( UnitName ) )
return nil
end
end
@ -902,8 +880,6 @@ function DATABASE:GetCategoryFromAirbase( AirbaseName )
return self.AIRBASES[AirbaseName]:GetCategory()
end
--- Private method that registers all alive players in the mission.
-- @param #DATABASE self
-- @return #DATABASE self
@ -927,7 +903,6 @@ function DATABASE:_RegisterPlayers()
return self
end
--- Private method that registers all Groups and Units within in the mission.
-- @param #DATABASE self
-- @return #DATABASE self
@ -945,7 +920,7 @@ function DATABASE:_RegisterGroupsAndUnits()
local DCSGroupName = DCSGroup:getName()
-- Add group.
self:I(string.format("Register Group: %s", tostring(DCSGroupName)))
self:I( string.format( "Register Group: %s", tostring( DCSGroupName ) ) )
self:AddGroup( DCSGroupName )
-- Loop over units in group.
@ -955,12 +930,12 @@ function DATABASE:_RegisterGroupsAndUnits()
local DCSUnitName = DCSUnit:getName()
-- Add unit.
self:I(string.format("Register Unit: %s", tostring(DCSUnitName)))
self:I( string.format( "Register Unit: %s", tostring( DCSUnitName ) ) )
self:AddUnit( DCSUnitName )
end
else
self:E({"Group does not exist: ", DCSGroup})
self:E( { "Group does not exist: ", DCSGroup } )
end
end
@ -975,7 +950,7 @@ end
function DATABASE:_RegisterClients()
for ClientName, ClientTemplate in pairs( self.Templates.ClientsByName ) do
self:I(string.format("Register Client: %s", tostring(ClientName)))
self:I( string.format( "Register Client: %s", tostring( ClientName ) ) )
self:AddClient( ClientName )
end
@ -985,7 +960,7 @@ end
--- @param #DATABASE self
function DATABASE:_RegisterStatics()
local CoalitionsData={GroupsRed=coalition.getStaticObjects(coalition.side.RED), GroupsBlue=coalition.getStaticObjects(coalition.side.BLUE), GroupsNeutral=coalition.getStaticObjects(coalition.side.NEUTRAL)}
local CoalitionsData = { GroupsRed = coalition.getStaticObjects( coalition.side.RED ), GroupsBlue = coalition.getStaticObjects( coalition.side.BLUE ), GroupsNeutral = coalition.getStaticObjects( coalition.side.NEUTRAL ) }
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
for DCSStaticId, DCSStatic in pairs( CoalitionData ) do
@ -993,7 +968,7 @@ function DATABASE:_RegisterStatics()
if DCSStatic:isExist() then
local DCSStaticName = DCSStatic:getName()
self:I(string.format("Register Static: %s", tostring(DCSStaticName)))
self:I( string.format( "Register Static: %s", tostring( DCSStaticName ) ) )
self:AddStatic( DCSStaticName )
else
self:E( { "Static does not exist: ", DCSStatic } )
@ -1009,33 +984,33 @@ end
-- @return #DATABASE self
function DATABASE:_RegisterAirbases()
for DCSAirbaseId, DCSAirbase in pairs(world.getAirbases()) do
for DCSAirbaseId, DCSAirbase in pairs( world.getAirbases() ) do
-- Get the airbase name.
local DCSAirbaseName = DCSAirbase:getName()
-- This gave the incorrect value to be inserted into the airdromeID for DCS 2.5.6. Is fixed now.
local airbaseID=DCSAirbase:getID()
local airbaseID = DCSAirbase:getID()
-- Add and register airbase.
local airbase=self:AddAirbase( DCSAirbaseName )
local airbase = self:AddAirbase( DCSAirbaseName )
-- Unique ID.
local airbaseUID=airbase:GetID(true)
local airbaseUID = airbase:GetID( true )
-- Debug output.
local text=string.format("Register %s: %s (ID=%d UID=%d), parking=%d [", AIRBASE.CategoryName[airbase.category], tostring(DCSAirbaseName), airbaseID, airbaseUID, airbase.NparkingTotal)
for _,terminalType in pairs(AIRBASE.TerminalType) do
local text = string.format( "Register %s: %s (ID=%d UID=%d), parking=%d [", AIRBASE.CategoryName[airbase.category], tostring( DCSAirbaseName ), airbaseID, airbaseUID, airbase.NparkingTotal )
for _, terminalType in pairs( AIRBASE.TerminalType ) do
if airbase.NparkingTerminal and airbase.NparkingTerminal[terminalType] then
text=text..string.format("%d=%d ", terminalType, airbase.NparkingTerminal[terminalType])
text = text .. string.format( "%d=%d ", terminalType, airbase.NparkingTerminal[terminalType] )
end
end
text=text.."]"
self:I(text)
text = text .. "]"
self:I( text )
-- Check for DCS bug IDs.
if airbaseID~=airbase:GetID() then
--self:E("WARNING: :getID does NOT match :GetID!")
if airbaseID ~= airbase:GetID() then
-- self:E("WARNING: :getID does NOT match :GetID!")
end
end
@ -1043,7 +1018,6 @@ function DATABASE:_RegisterAirbases()
return self
end
--- Events
--- Handles the OnBirth event for the alive units set.
@ -1066,10 +1040,10 @@ function DATABASE:_EventOnBirth( Event )
self:AddGroup( Event.IniDCSGroupName )
-- Add airbase if it was spawned later in the mission.
local DCSAirbase = Airbase.getByName(Event.IniDCSUnitName)
local DCSAirbase = Airbase.getByName( Event.IniDCSUnitName )
if DCSAirbase then
self:I(string.format("Adding airbase %s", tostring(Event.IniDCSUnitName)))
self:AddAirbase(Event.IniDCSUnitName)
self:I( string.format( "Adding airbase %s", tostring( Event.IniDCSUnitName ) ) )
self:AddAirbase( Event.IniDCSUnitName )
end
end
@ -1081,7 +1055,7 @@ function DATABASE:_EventOnBirth( Event )
Event.IniGroup = self:FindGroup( Event.IniDCSGroupName )
-- Client
local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
local client = self.CLIENTS[Event.IniDCSUnitName] -- Wrapper.Client#CLIENT
if client then
-- TODO: create event ClientAlive
@ -1093,15 +1067,15 @@ function DATABASE:_EventOnBirth( Event )
if PlayerName then
-- Debug info.
self:I(string.format("Player '%s' joint unit '%s' of group '%s'", tostring(PlayerName), tostring(Event.IniDCSUnitName), tostring(Event.IniDCSGroupName)))
self:I( string.format( "Player '%s' joint unit '%s' of group '%s'", tostring( PlayerName ), tostring( Event.IniDCSUnitName ), tostring( Event.IniDCSGroupName ) ) )
-- Add client in case it does not exist already.
if not client then
client=self:AddClient(Event.IniDCSUnitName)
client = self:AddClient( Event.IniDCSUnitName )
end
-- Add player.
client:AddPlayer(PlayerName)
client:AddPlayer( PlayerName )
-- Add player.
if not self.PLAYERS[PlayerName] then
@ -1110,10 +1084,10 @@ function DATABASE:_EventOnBirth( Event )
-- Player settings.
local Settings = SETTINGS:Set( PlayerName )
Settings:SetPlayerMenu(Event.IniUnit)
Settings:SetPlayerMenu( Event.IniUnit )
-- Create an event.
self:CreateEventPlayerEnterAircraft(Event.IniUnit)
self:CreateEventPlayerEnterAircraft( Event.IniUnit )
end
@ -1123,7 +1097,6 @@ function DATABASE:_EventOnBirth( Event )
end
--- Handles the OnDead or OnCrash event for alive units set.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
@ -1131,7 +1104,7 @@ function DATABASE:_EventOnDeadOrCrash( Event )
if Event.IniDCSUnit then
local name=Event.IniDCSUnitName
local name = Event.IniDCSUnitName
if Event.IniObjectCategory == 3 then
@ -1153,11 +1126,11 @@ function DATABASE:_EventOnDeadOrCrash( Event )
-- Delete unit.
if self.UNITS[Event.IniDCSUnitName] then
self:DeleteUnit(Event.IniDCSUnitName)
self:DeleteUnit( Event.IniDCSUnitName )
end
-- Remove client players.
local client=self.CLIENTS[name] --Wrapper.Client#CLIENT
local client = self.CLIENTS[name] -- Wrapper.Client#CLIENT
if client then
client:RemovePlayers()
@ -1167,9 +1140,9 @@ function DATABASE:_EventOnDeadOrCrash( Event )
end
-- Add airbase if it was spawned later in the mission.
local airbase=self.AIRBASES[Event.IniDCSUnitName] --Wrapper.Airbase#AIRBASE
local airbase = self.AIRBASES[Event.IniDCSUnitName] -- Wrapper.Airbase#AIRBASE
if airbase and (airbase:IsHelipad() or airbase:IsShip()) then
self:DeleteAirbase(Event.IniDCSUnitName)
self:DeleteAirbase( Event.IniDCSUnitName )
end
end
@ -1178,7 +1151,6 @@ function DATABASE:_EventOnDeadOrCrash( Event )
self:AccountDestroys( Event )
end
--- Handles the OnPlayerEnterUnit event to fill the active players table (with the unit filter applied).
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
@ -1210,13 +1182,12 @@ function DATABASE:_EventOnPlayerEnterUnit( Event )
Settings:SetPlayerMenu( Event.IniUnit )
else
self:E("ERROR: getPlayerName() returned nil for event PlayerEnterUnit")
self:E( "ERROR: getPlayerName() returned nil for event PlayerEnterUnit" )
end
end
end
end
--- Handles the OnPlayerLeaveUnit event to clean the active players table.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
@ -1230,22 +1201,22 @@ function DATABASE:_EventOnPlayerLeaveUnit( Event )
-- Try to get the player name. This can be buggy for multicrew aircraft!
local PlayerName = Event.IniUnit:GetPlayerName()
if PlayerName then --and self.PLAYERS[PlayerName] then
if PlayerName then -- and self.PLAYERS[PlayerName] then
-- Debug info.
self:I(string.format("Player '%s' left unit %s", tostring(PlayerName), tostring(Event.IniUnitName)))
self:I( string.format( "Player '%s' left unit %s", tostring( PlayerName ), tostring( Event.IniUnitName ) ) )
-- Remove player menu.
local Settings = SETTINGS:Set( PlayerName )
Settings:RemovePlayerMenu(Event.IniUnit)
Settings:RemovePlayerMenu( Event.IniUnit )
-- Delete player.
self:DeletePlayer(Event.IniUnit, PlayerName)
self:DeletePlayer( Event.IniUnit, PlayerName )
-- Client stuff.
local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
local client = self.CLIENTS[Event.IniDCSUnitName] -- Wrapper.Client#CLIENT
if client then
client:RemovePlayer(PlayerName)
client:RemovePlayer( PlayerName )
end
end
@ -1268,19 +1239,19 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
self:T2( Object )
IteratorFunction( Object, unpack( arg ) )
Count = Count + 1
-- if Count % 100 == 0 then
-- coroutine.yield( false )
-- end
-- if Count % 100 == 0 then
-- coroutine.yield( false )
-- end
end
return true
end
-- local co = coroutine.create( CoRoutine )
-- local co = coroutine.create( CoRoutine )
local co = CoRoutine
local function Schedule()
-- local status, res = coroutine.resume( co )
-- local status, res = coroutine.resume( co )
local status, res = co()
self:T3( { status, res } )
@ -1296,18 +1267,17 @@ function DATABASE:ForEach( IteratorFunction, FinalizeFunction, arg, Set )
return false
end
--local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
-- local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
Schedule()
return self
end
--- Iterate the DATABASE and call an iterator function for each **alive** STATIC, providing the STATIC and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called for each object in the database. The function needs to accept a STATIC parameter.
-- @return #DATABASE self
function DATABASE:ForEachStatic( IteratorFunction, FinalizeFunction, ... ) --R2.1
function DATABASE:ForEachStatic( IteratorFunction, FinalizeFunction, ... ) -- R2.1
self:F2( arg )
self:ForEach( IteratorFunction, FinalizeFunction, arg, self.STATICS )
@ -1315,7 +1285,6 @@ function DATABASE:ForEachStatic( IteratorFunction, FinalizeFunction, ... ) --R2
return self
end
--- Iterate the DATABASE and call an iterator function for each **alive** UNIT, providing the UNIT and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called for each object in the database. The function needs to accept a UNIT parameter.
@ -1328,7 +1297,6 @@ function DATABASE:ForEachUnit( IteratorFunction, FinalizeFunction, ... )
return self
end
--- Iterate the DATABASE and call an iterator function for each **alive** GROUP, providing the GROUP and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called for each object in the database. The function needs to accept a GROUP parameter.
@ -1341,7 +1309,6 @@ function DATABASE:ForEachGroup( IteratorFunction, FinalizeFunction, ... )
return self
end
--- Iterate the DATABASE and call an iterator function for each **ALIVE** player, providing the player name and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called for each object in the database. The function needs to accept the player name.
@ -1354,7 +1321,6 @@ function DATABASE:ForEachPlayer( IteratorFunction, FinalizeFunction, ... )
return self
end
--- Iterate the DATABASE and call an iterator function for each player who has joined the mission, providing the Unit of the player and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called for each object in the database. The function needs to accept a UNIT parameter.
@ -1379,7 +1345,6 @@ function DATABASE:ForEachPlayerUnit( IteratorFunction, FinalizeFunction, ... )
return self
end
--- Iterate the DATABASE and call an iterator function for each CLIENT, providing the CLIENT to the function and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called object in the database. The function needs to accept a CLIENT parameter.
@ -1404,7 +1369,6 @@ function DATABASE:ForEachCargo( IteratorFunction, ... )
return self
end
--- Handles the OnEventNewCargo event.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA EventData
@ -1416,7 +1380,6 @@ function DATABASE:OnEventNewCargo( EventData )
end
end
--- Handles the OnEventDeleteCargo.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA EventData
@ -1428,7 +1391,6 @@ function DATABASE:OnEventDeleteCargo( EventData )
end
end
--- Handles the OnEventNewZone event.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA EventData
@ -1440,7 +1402,6 @@ function DATABASE:OnEventNewZone( EventData )
end
end
--- Handles the OnEventDeleteZone.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA EventData
@ -1452,8 +1413,6 @@ function DATABASE:OnEventDeleteZone( EventData )
end
end
--- Gets the player settings
-- @param #DATABASE self
-- @param #string PlayerName
@ -1463,7 +1422,6 @@ function DATABASE:GetPlayerSettings( PlayerName )
return self.PLAYERSETTINGS[PlayerName]
end
--- Sets the player settings
-- @param #DATABASE self
-- @param #string PlayerName
@ -1477,21 +1435,21 @@ end
--- Add a flight group to the data base.
-- @param #DATABASE self
-- @param Ops.FlightGroup#FLIGHTGROUP flightgroup
function DATABASE:AddFlightGroup(flightgroup)
self:I({NewFlightGroup=flightgroup.groupname})
self.FLIGHTGROUPS[flightgroup.groupname]=flightgroup
function DATABASE:AddFlightGroup( flightgroup )
self:I( { NewFlightGroup = flightgroup.groupname } )
self.FLIGHTGROUPS[flightgroup.groupname] = flightgroup
end
--- Get a flight group from the data base.
-- @param #DATABASE self
-- @param #string groupname Group name of the flight group. Can also be passed as GROUP object.
-- @return Ops.FlightGroup#FLIGHTGROUP Flight group object.
function DATABASE:GetFlightGroup(groupname)
function DATABASE:GetFlightGroup( groupname )
-- Get group and group name.
if type(groupname)=="string" then
if type( groupname ) == "string" then
else
groupname=groupname:GetName()
groupname = groupname:GetName()
end
return self.FLIGHTGROUPS[groupname]
@ -1500,16 +1458,16 @@ end
--- Add a flight control to the data base.
-- @param #DATABASE self
-- @param Ops.FlightControl#FLIGHTCONTROL flightcontrol
function DATABASE:AddFlightControl(flightcontrol)
function DATABASE:AddFlightControl( flightcontrol )
self:F2( { flightcontrol } )
self.FLIGHTCONTROLS[flightcontrol.airbasename]=flightcontrol
self.FLIGHTCONTROLS[flightcontrol.airbasename] = flightcontrol
end
--- Get a flight control object from the data base.
-- @param #DATABASE self
-- @param #string airbasename Name of the associated airbase.
-- @return Ops.FlightControl#FLIGHTCONTROL The FLIGHTCONTROL object.s
function DATABASE:GetFlightControl(airbasename)
function DATABASE:GetFlightControl( airbasename )
return self.FLIGHTCONTROLS[airbasename]
end
@ -1519,29 +1477,29 @@ function DATABASE:_RegisterTemplates()
self.Navpoints = {}
self.UNITS = {}
--Build routines.db.units and self.Navpoints
for CoalitionName, coa_data in pairs(env.mission.coalition) do
self:T({CoalitionName=CoalitionName})
-- Build routines.db.units and self.Navpoints
for CoalitionName, coa_data in pairs( env.mission.coalition ) do
self:T( { CoalitionName = CoalitionName } )
if (CoalitionName == 'red' or CoalitionName == 'blue' or CoalitionName == 'neutrals') and type(coa_data) == 'table' then
--self.Units[coa_name] = {}
if (CoalitionName == 'red' or CoalitionName == 'blue' or CoalitionName == 'neutrals') and type( coa_data ) == 'table' then
-- self.Units[coa_name] = {}
local CoalitionSide = coalition.side[string.upper(CoalitionName)]
if CoalitionName=="red" then
CoalitionSide=coalition.side.RED
elseif CoalitionName=="blue" then
CoalitionSide=coalition.side.BLUE
local CoalitionSide = coalition.side[string.upper( CoalitionName )]
if CoalitionName == "red" then
CoalitionSide = coalition.side.RED
elseif CoalitionName == "blue" then
CoalitionSide = coalition.side.BLUE
else
CoalitionSide=coalition.side.NEUTRAL
CoalitionSide = coalition.side.NEUTRAL
end
-- build nav points DB
self.Navpoints[CoalitionName] = {}
if coa_data.nav_points then --navpoints
for nav_ind, nav_data in pairs(coa_data.nav_points) do
if coa_data.nav_points then -- navpoints
for nav_ind, nav_data in pairs( coa_data.nav_points ) do
if type(nav_data) == 'table' then
self.Navpoints[CoalitionName][nav_ind] = routines.utils.deepCopy(nav_data)
if type( nav_data ) == 'table' then
self.Navpoints[CoalitionName][nav_ind] = routines.utils.deepCopy( nav_data )
self.Navpoints[CoalitionName][nav_ind]['name'] = nav_data.callsignStr -- name is a little bit more self-explanatory.
self.Navpoints[CoalitionName][nav_ind]['point'] = {} -- point is used by SSE, support it.
@ -1553,58 +1511,58 @@ function DATABASE:_RegisterTemplates()
end
-------------------------------------------------
if coa_data.country then --there is a country table
for cntry_id, cntry_data in pairs(coa_data.country) do
if coa_data.country then -- there is a country table
for cntry_id, cntry_data in pairs( coa_data.country ) do
local CountryName = string.upper(cntry_data.name)
local CountryName = string.upper( cntry_data.name )
local CountryID = cntry_data.id
self.COUNTRY_ID[CountryName] = CountryID
self.COUNTRY_NAME[CountryID] = CountryName
--self.Units[coa_name][countryName] = {}
--self.Units[coa_name][countryName]["countryId"] = cntry_data.id
-- self.Units[coa_name][countryName] = {}
-- self.Units[coa_name][countryName]["countryId"] = cntry_data.id
if type(cntry_data) == 'table' then --just making sure
if type( cntry_data ) == 'table' then -- just making sure
for obj_type_name, obj_type_data in pairs(cntry_data) do
for obj_type_name, obj_type_data in pairs( cntry_data ) do
if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then --should be an unncessary check
if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then -- should be an unncessary check
local CategoryName = obj_type_name
if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then --there's a group!
if ((type( obj_type_data ) == 'table') and obj_type_data.group and (type( obj_type_data.group ) == 'table') and (#obj_type_data.group > 0)) then -- there's a group!
--self.Units[coa_name][countryName][category] = {}
-- self.Units[coa_name][countryName][category] = {}
for group_num, Template in pairs(obj_type_data.group) do
for group_num, Template in pairs( obj_type_data.group ) do
if obj_type_name ~= "static" and Template and Template.units and type(Template.units) == 'table' then --making sure again- this is a valid group
if obj_type_name ~= "static" and Template and Template.units and type( Template.units ) == 'table' then -- making sure again- this is a valid group
self:_RegisterGroupTemplate(Template, CoalitionSide, _DATABASECategory[string.lower(CategoryName)], CountryID)
self:_RegisterGroupTemplate( Template, CoalitionSide, _DATABASECategory[string.lower( CategoryName )], CountryID )
else
self:_RegisterStaticTemplate(Template, CoalitionSide, _DATABASECategory[string.lower(CategoryName)], CountryID)
self:_RegisterStaticTemplate( Template, CoalitionSide, _DATABASECategory[string.lower( CategoryName )], CountryID )
end --if GroupTemplate and GroupTemplate.units then
end --for group_num, GroupTemplate in pairs(obj_type_data.group) do
end --if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then
end --if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then
end --for obj_type_name, obj_type_data in pairs(cntry_data) do
end --if type(cntry_data) == 'table' then
end --for cntry_id, cntry_data in pairs(coa_data.country) do
end --if coa_data.country then --there is a country table
end --if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
end --for coa_name, coa_data in pairs(mission.coalition) do
end -- if GroupTemplate and GroupTemplate.units then
end -- for group_num, GroupTemplate in pairs(obj_type_data.group) do
end -- if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then
end -- if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then
end -- for obj_type_name, obj_type_data in pairs(cntry_data) do
end -- if type(cntry_data) == 'table' then
end -- for cntry_id, cntry_data in pairs(coa_data.country) do
end -- if coa_data.country then --there is a country table
end -- if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
end -- for coa_name, coa_data in pairs(mission.coalition) do
return self
end
--- Account the Hits of the Players.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
function DATABASE:AccountHits( Event )
--- Account the Hits of the Players.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
function DATABASE:AccountHits( Event )
self:F( { Event } )
if Event.IniPlayerName ~= nil then -- It is a player that is hitting something
@ -1641,12 +1599,12 @@ end
end
end
end
end
end
--- Account the destroys.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
function DATABASE:AccountDestroys( Event )
--- Account the destroys.
-- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event
function DATABASE:AccountDestroys( Event )
self:F( { Event } )
local TargetUnit = nil
@ -1670,8 +1628,8 @@ end
TargetPlayerName = Event.IniPlayerName
TargetCoalition = Event.IniCoalition
--TargetCategory = TargetUnit:getCategory()
--TargetCategory = TargetUnit:getDesc().category -- Workaround
-- TargetCategory = TargetUnit:getCategory()
-- TargetCategory = TargetUnit:getDesc().category -- Workaround
TargetCategory = Event.IniCategory
TargetType = Event.IniTypeName
@ -1687,4 +1645,4 @@ end
self.DESTROYS[Event.IniUnitName] = self.DESTROYS[Event.IniUnitName] or {}
self.DESTROYS[Event.IniUnitName] = true
end
end
end

View File

@ -14,7 +14,7 @@
-- ![Objects](..\Presentations\EVENT\Dia2.JPG)
--
-- Within a running mission, various DCS events occur. Units are dynamically created, crash, die, shoot stuff, get hit etc.
-- This module provides a mechanism to dispatch those events occuring within your running mission, to the different objects orchestrating your mission.
-- This module provides a mechanism to dispatch those events occurring within your running mission, to the different objects orchestrating your mission.
--
-- ![Objects](..\Presentations\EVENT\Dia3.JPG)
--
@ -141,7 +141,6 @@
-- EventData.IniUnit:SmokeGreen()
-- end
--
--
-- Find below an overview which events populate which information categories:
--
-- ![Objects](..\Presentations\EVENT\Dia14.JPG)
@ -172,7 +171,6 @@
-- @module Core.Event
-- @image Core_Event.JPG
--- @type EVENT
-- @field #EVENT.Events Events
-- @extends Core.Base#BASE
@ -194,7 +192,6 @@ world.event.S_EVENT_DELETE_ZONE_GOAL = world.event.S_EVENT_MAX + 1005
world.event.S_EVENT_REMOVE_UNIT = world.event.S_EVENT_MAX + 1006
world.event.S_EVENT_PLAYER_ENTER_AIRCRAFT = world.event.S_EVENT_MAX + 1007
--- The different types of events supported by MOOSE.
-- Use this structure to subscribe to events using the @{Core.Base#BASE.HandleEvent}() method.
-- @type EVENTS
@ -304,8 +301,6 @@ EVENTS = {
-- @field Core.ZONE#ZONE Zone The zone object.
-- @field #string ZoneName The name of the zone.
local _EVENTMETA = {
[world.event.S_EVENT_SHOT] = {
Order = 1,
@ -562,7 +557,6 @@ local _EVENTMETA = {
},
}
--- The Events structure
-- @type EVENT.Events
-- @field #number IniUnit
@ -576,12 +570,11 @@ function EVENT:New()
local self = BASE:Inherit( self, BASE:New() )
-- Add world event handler.
self.EventHandler = world.addEventHandler(self)
self.EventHandler = world.addEventHandler( self )
return self
end
--- Initializes the Events structure for the event.
-- @param #EVENT self
-- @param DCS#world.event EventID Event ID.
@ -595,7 +588,7 @@ function EVENT:Init( EventID, EventClass )
self.Events[EventID] = {}
end
-- Each event has a subtable of EventClasses, ordered by EventPriority.
-- Each event has a sub-table of EventClasses, ordered by EventPriority.
local EventPriority = EventClass:GetEventPriority()
if not self.Events[EventID][EventPriority] then
@ -638,7 +631,7 @@ end
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param DCS#world.event EventID Event ID.
-- @return #EVENT.Events
function EVENT:Reset( EventObject ) --R2.1
function EVENT:Reset( EventObject ) -- R2.1
self:F( { "Resetting subscriptions for class: ", EventObject:GetClassNameAndID() } )
@ -657,12 +650,11 @@ function EVENT:Reset( EventObject ) --R2.1
end
end
--- Clears all event subscriptions for a @{Core.Base#BASE} derived object.
-- @param #EVENT self
-- @param Core.Base#BASE EventClass The self class object for which the events are removed.
-- @return #EVENT self
function EVENT:RemoveAll(EventClass)
function EVENT:RemoveAll( EventClass )
local EventClassName = EventClass:GetClassNameAndID()
@ -676,8 +668,6 @@ function EVENT:RemoveAll(EventClass)
return self
end
--- Create an OnDead event handler for a group
-- @param #EVENT self
-- @param #table EventTemplate
@ -709,7 +699,6 @@ function EVENT:OnEventGeneric( EventFunction, EventClass, EventID )
return self
end
--- Set a new listener for an `S_EVENT_X` event for a UNIT.
-- @param #EVENT self
-- @param #string UnitName The name of the UNIT.
@ -797,7 +786,6 @@ do -- OnDead
end
do -- OnLand
--- Create an OnLand event handler for a group
@ -929,7 +917,6 @@ do -- Event Creation
world.onEvent( Event )
end
--- Creation of a ZoneGoal Deletion Event.
-- @param #EVENT self
-- @param Core.ZoneGoal#ZONE_GOAL ZoneGoal The ZoneGoal created.
@ -945,7 +932,6 @@ do -- Event Creation
world.onEvent( Event )
end
--- Creation of a S_EVENT_PLAYER_ENTER_UNIT Event.
-- @param #EVENT self
-- @param Wrapper.Unit#UNIT PlayerUnit.
@ -955,7 +941,7 @@ do -- Event Creation
local Event = {
id = EVENTS.PlayerEnterUnit,
time = timer.getTime(),
initiator = PlayerUnit:GetDCSObject()
initiator = PlayerUnit:GetDCSObject(),
}
world.onEvent( Event )
@ -970,7 +956,7 @@ do -- Event Creation
local Event = {
id = EVENTS.PlayerEnterAircraft,
time = timer.getTime(),
initiator = PlayerUnit:GetDCSObject()
initiator = PlayerUnit:GetDCSObject(),
}
world.onEvent( Event )
@ -993,14 +979,13 @@ function EVENT:onEvent( Event )
return errmsg
end
-- Get event meta data.
local EventMeta = _EVENTMETA[Event.id]
-- Check if this is a known event?
if EventMeta then
if self and self.Events and self.Events[Event.id] and self.MissionEnd==false and (Event.initiator~=nil or (Event.initiator==nil and Event.id~=EVENTS.PlayerLeaveUnit)) then
if self and self.Events and self.Events[Event.id] and self.MissionEnd == false and (Event.initiator ~= nil or (Event.initiator == nil and Event.id ~= EVENTS.PlayerLeaveUnit)) then
if Event.id and Event.id == EVENTS.MissionEnd then
self.MissionEnd = true
@ -1024,9 +1009,9 @@ function EVENT:onEvent( Event )
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
--if Event.IniGroup then
-- if Event.IniGroup then
Event.IniGroupName = Event.IniDCSGroupName
--end
-- end
end
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
@ -1036,20 +1021,20 @@ function EVENT:onEvent( Event )
if Event.IniObjectCategory == Object.Category.STATIC then
if Event.id==31 then
if Event.id == 31 then
-- Event.initiator is a Static object representing the pilot. But getName() errors due to DCS bug.
Event.IniDCSUnit = Event.initiator
local ID=Event.initiator.id_
Event.IniDCSUnitName = string.format("Ejected Pilot ID %s", tostring(ID))
local ID = Event.initiator.id_
Event.IniDCSUnitName = string.format( "Ejected Pilot ID %s", tostring( ID ) )
Event.IniUnitName = Event.IniDCSUnitName
Event.IniCoalition = 0
Event.IniCategory = 0
Event.IniTypeName = "Ejected Pilot"
elseif Event.id == 33 then -- ejection seat discarded
Event.IniDCSUnit = Event.initiator
local ID=Event.initiator.id_
Event.IniDCSUnitName = string.format("Ejection Seat ID %s", tostring(ID))
local ID = Event.initiator.id_
Event.IniDCSUnitName = string.format( "Ejection Seat ID %s", tostring( ID ) )
Event.IniUnitName = Event.IniDCSUnitName
Event.IniCoalition = 0
Event.IniCategory = 0
@ -1088,7 +1073,7 @@ function EVENT:onEvent( Event )
Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = AIRBASE:FindByName(Event.IniDCSUnitName)
Event.IniUnit = AIRBASE:FindByName( Event.IniDCSUnitName )
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniCategory = Event.IniDCSUnit:getDesc().category
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
@ -1109,9 +1094,9 @@ function EVENT:onEvent( Event )
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
--if Event.TgtGroup then
-- if Event.TgtGroup then
Event.TgtGroupName = Event.TgtDCSGroupName
--end
-- end
end
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
@ -1130,18 +1115,18 @@ function EVENT:onEvent( Event )
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()
else
Event.TgtDCSUnitName = string.format("No target object for Event ID %s", tostring(Event.id))
Event.TgtDCSUnitName = string.format( "No target object for Event ID %s", tostring( Event.id ) )
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = nil
Event.TgtCoalition = 0
Event.TgtCategory = 0
if Event.id == 6 then
Event.TgtTypeName = "Ejected Pilot"
Event.TgtDCSUnitName = string.format("Ejected Pilot ID %s", tostring(Event.IniDCSUnitName))
Event.TgtDCSUnitName = string.format( "Ejected Pilot ID %s", tostring( Event.IniDCSUnitName ) )
Event.TgtUnitName = Event.TgtDCSUnitName
elseif Event.id == 33 then
Event.TgtTypeName = "Ejection Seat"
Event.TgtDCSUnitName = string.format("Ejection Seat ID %s", tostring(Event.IniDCSUnitName))
Event.TgtDCSUnitName = string.format( "Ejection Seat ID %s", tostring( Event.IniDCSUnitName ) )
Event.TgtUnitName = Event.TgtDCSUnitName
else
Event.TgtTypeName = "Static"
@ -1167,29 +1152,29 @@ function EVENT:onEvent( Event )
Event.WeaponCoalition = Event.WeaponUNIT and Event.Weapon:getCoalition()
Event.WeaponCategory = Event.WeaponUNIT and Event.Weapon:getDesc().category
Event.WeaponTypeName = Event.WeaponUNIT and Event.Weapon:getTypeName()
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
-- Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
end
-- Place should be given for takeoff and landing events as well as base captured. It should be a DCS airbase.
if Event.place then
if Event.id==EVENTS.LandingAfterEjection then
if Event.id == EVENTS.LandingAfterEjection then
-- Place is here the UNIT of which the pilot ejected.
--local name=Event.place:getName() -- This returns a DCS error "Airbase doesn't exit" :(
-- local name=Event.place:getName() -- This returns a DCS error "Airbase doesn't exit" :(
-- However, this is not a big thing, as the aircraft the pilot ejected from is usually long crashed before the ejected pilot touches the ground.
--Event.Place=UNIT:Find(Event.place)
-- Event.Place=UNIT:Find(Event.place)
else
Event.Place=AIRBASE:Find(Event.place)
Event.PlaceName=Event.Place:GetName()
Event.Place = AIRBASE:Find( Event.place )
Event.PlaceName = Event.Place:GetName()
end
end
-- Mark points.
if Event.idx then
Event.MarkID=Event.idx
Event.MarkVec3=Event.pos
Event.MarkCoordinate=COORDINATE:NewFromVec3(Event.pos)
Event.MarkText=Event.text
Event.MarkCoalition=Event.coalition
Event.MarkID = Event.idx
Event.MarkVec3 = Event.pos
Event.MarkCoordinate = COORDINATE:NewFromVec3( Event.pos )
Event.MarkText = Event.text
Event.MarkCoalition = Event.coalition
Event.MarkGroupID = Event.groupID
end
@ -1218,9 +1203,9 @@ function EVENT:onEvent( Event )
-- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called.
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
--if Event.IniObjectCategory ~= Object.Category.STATIC then
-- if Event.IniObjectCategory ~= Object.Category.STATIC then
-- self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } )
--end
-- end
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
@ -1237,8 +1222,8 @@ function EVENT:onEvent( Event )
local UnitName = EventClass:GetName()
if ( EventMeta.Side == "I" and UnitName == Event.IniDCSUnitName ) or
( EventMeta.Side == "T" and UnitName == Event.TgtDCSUnitName ) then
if (EventMeta.Side == "I" and UnitName == Event.IniDCSUnitName) or
(EventMeta.Side == "T" and UnitName == Event.TgtDCSUnitName) then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.EventFunction then
@ -1247,15 +1232,14 @@ function EVENT:onEvent( Event )
self:F( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
end
local Result, Value = xpcall(
function()
local Result, Value = xpcall( function()
return EventData.EventFunction( EventClass, Event )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ EventMeta.Event ]
local EventFunction = EventClass[EventMeta.Event]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
@ -1263,8 +1247,7 @@ function EVENT:onEvent( Event )
self:F( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
local Result, Value = xpcall( function()
return EventFunction( EventClass, Event )
end, ErrorHandler )
end
@ -1290,8 +1273,8 @@ function EVENT:onEvent( Event )
-- We can get the name of the EventClass, which is now always a GROUP object.
local GroupName = EventClass:GetName()
if ( EventMeta.Side == "I" and GroupName == Event.IniDCSGroupName ) or
( EventMeta.Side == "T" and GroupName == Event.TgtDCSGroupName ) then
if (EventMeta.Side == "I" and GroupName == Event.IniDCSGroupName) or
(EventMeta.Side == "T" and GroupName == Event.TgtDCSGroupName) then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.EventFunction then
@ -1300,15 +1283,14 @@ function EVENT:onEvent( Event )
self:F( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
end
local Result, Value = xpcall(
function()
local Result, Value = xpcall( function()
return EventData.EventFunction( EventClass, Event, unpack( EventData.Params ) )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ EventMeta.Event ]
local EventFunction = EventClass[EventMeta.Event]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
@ -1316,8 +1298,7 @@ function EVENT:onEvent( Event )
self:F( { "Calling " .. EventMeta.Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
local Result, Value = xpcall( function()
return EventFunction( EventClass, Event, unpack( EventData.Params ) )
end, ErrorHandler )
end
@ -1325,7 +1306,7 @@ function EVENT:onEvent( Event )
end
else
-- The EventClass is not alive anymore, we remove it from the EventHandlers...
--self:RemoveEvent( EventClass, Event.id )
-- self:RemoveEvent( EventClass, Event.id )
end
else
@ -1340,14 +1321,13 @@ function EVENT:onEvent( Event )
if Event.IniObjectCategory ~= 3 then
self:F2( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
local Result, Value = xpcall( function()
return EventData.EventFunction( EventClass, Event )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ EventMeta.Event ]
local EventFunction = EventClass[EventMeta.Event]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
@ -1355,8 +1335,7 @@ function EVENT:onEvent( Event )
self:F2( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
local Result, Value = xpcall( function()
local Result, Value = EventFunction( EventClass, Event )
return Result, Value
end, ErrorHandler )
@ -1383,7 +1362,7 @@ function EVENT:onEvent( Event )
self:T( { EventMeta.Text, Event } )
end
else
self:E(string.format("WARNING: Could not get EVENTMETA data for event ID=%d! Is this an unknown/new DCS event?", tostring(Event.id)))
self:E( string.format( "WARNING: Could not get EVENTMETA data for event ID=%d! Is this an unknown/new DCS event?", tostring( Event.id ) ) )
end
Event = nil