From 5353be482e984e08936f3fde961e0ee921517514 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 16 Nov 2023 22:32:01 +0100 Subject: [PATCH] getCategory behaviour - Fixed several classes for new `getCategory` behaviour (should be backwards compatible to earlier DCS versions). --- Moose Development/Moose/Core/Database.lua | 2 -- Moose Development/Moose/Core/Event.lua | 6 ++--- Moose Development/Moose/Core/Point.lua | 2 +- Moose Development/Moose/Core/Zone.lua | 9 +++----- Moose Development/Moose/Functional/Sead.lua | 2 +- Moose Development/Moose/Functional/Shorad.lua | 2 +- Moose Development/Moose/Wrapper/Object.lua | 22 ++++++++++++------- Moose Development/Moose/Wrapper/Weapon.lua | 2 +- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 75f7be002..e3e7c17c1 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -2023,8 +2023,6 @@ end TargetPlayerName = Event.IniPlayerName TargetCoalition = Event.IniCoalition - --TargetCategory = TargetUnit:getCategory() - --TargetCategory = TargetUnit:getDesc().category -- Workaround TargetCategory = Event.IniCategory TargetType = Event.IniTypeName diff --git a/Moose Development/Moose/Core/Event.lua b/Moose Development/Moose/Core/Event.lua index 27c569c8c..b32b723c7 100644 --- a/Moose Development/Moose/Core/Event.lua +++ b/Moose Development/Moose/Core/Event.lua @@ -1083,7 +1083,7 @@ function EVENT:onEvent( Event ) if Event.initiator then - Event.IniObjectCategory = Object.getCategory(Event.initiator) --Event.initiator:getCategory() + Event.IniObjectCategory = Object.getCategory(Event.initiator) if Event.IniObjectCategory == Object.Category.STATIC then --- @@ -1208,7 +1208,7 @@ function EVENT:onEvent( Event ) --- -- Target category. - Event.TgtObjectCategory = Object.getCategory(Event.target) --Event.target:getCategory() + Event.TgtObjectCategory = Object.getCategory(Event.target) if Event.TgtObjectCategory == Object.Category.UNIT then --- @@ -1302,7 +1302,7 @@ function EVENT:onEvent( Event ) -- 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) else - if Event.place:isExist() and Event.place:getCategory() ~= Object.Category.SCENERY then + if Event.place:isExist() and Object.getCategory(Event.place) ~= Object.Category.SCENERY then Event.Place=AIRBASE:Find(Event.place) Event.PlaceName=Event.Place:GetName() end diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index da8ed7835..8a811e19f 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -544,7 +544,7 @@ do -- COORDINATE if ZoneObject then -- Get category of scanned object. - local ObjectCategory = ZoneObject:getCategory() + local ObjectCategory = Object.getCategory(ZoneObject) -- Check for unit or static objects if ObjectCategory==Object.Category.UNIT and ZoneObject:isExist() then diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 1760a1f76..aaff86ce7 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -1093,11 +1093,8 @@ function ZONE_RADIUS:Scan( ObjectCategories, UnitCategories ) --if ZoneObject:isExist() then --FF: isExist always returns false for SCENERY objects since DCS 2.2 and still in DCS 2.5 if ZoneObject then - local ObjectCategory = ZoneObject:getCategory() - - --local name=ZoneObject:getName() - --env.info(string.format("Zone object %s", tostring(name))) - --self:E(ZoneObject) + -- Get object category. + local ObjectCategory = Object.getCategory(ZoneObject) if ( ObjectCategory == Object.Category.UNIT and ZoneObject:isExist() and ZoneObject:isActive() ) or (ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then @@ -2801,7 +2798,7 @@ function ZONE_POLYGON:Scan( ObjectCategories, UnitCategories ) if ZoneObject then - local ObjectCategory = ZoneObject:getCategory() + local ObjectCategory = Object.getCategory(ZoneObject) if ( ObjectCategory == Object.Category.UNIT and ZoneObject:isExist() and ZoneObject:isActive() ) or (ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then diff --git a/Moose Development/Moose/Functional/Sead.lua b/Moose Development/Moose/Functional/Sead.lua index d2f03703f..07fb312c5 100644 --- a/Moose Development/Moose/Functional/Sead.lua +++ b/Moose Development/Moose/Functional/Sead.lua @@ -484,7 +484,7 @@ function SEAD:HandleEventShot( EventData ) end return self end - local targetcat = _target:getCategory() -- Identify category + local targetcat = Object.getCategory(_target) -- Identify category local _targetUnit = nil -- Wrapper.Unit#UNIT local _targetgroup = nil -- Wrapper.Group#GROUP self:T(string.format("*** Targetcat = %d",targetcat)) diff --git a/Moose Development/Moose/Functional/Shorad.lua b/Moose Development/Moose/Functional/Shorad.lua index ff341ddbb..3ba433296 100644 --- a/Moose Development/Moose/Functional/Shorad.lua +++ b/Moose Development/Moose/Functional/Shorad.lua @@ -673,7 +673,7 @@ do return self end - local targetcat = targetdata:getCategory() -- Identify category + local targetcat = Object.getCategory(targetdata) -- Identify category self:T(string.format("Target Category (3=STATIC, 1=UNIT)= %s",tostring(targetcat))) self:T({targetdata}) local targetunit = nil diff --git a/Moose Development/Moose/Wrapper/Object.lua b/Moose Development/Moose/Wrapper/Object.lua index 4488141fa..bc082f71b 100644 --- a/Moose Development/Moose/Wrapper/Object.lua +++ b/Moose Development/Moose/Wrapper/Object.lua @@ -4,7 +4,7 @@ -- -- ### Author: **FlightControl** -- --- ### Contributions: +-- ### Contributions: **funkyfranky -- -- === -- @@ -12,12 +12,13 @@ -- @image MOOSE.JPG ---- @type OBJECT +--- OBJECT class. +-- @type OBJECT -- @extends Core.Base#BASE -- @field #string ObjectName The name of the Object. ---- Wrapper class to hendle the DCS Object objects. +--- Wrapper class to handle the DCS Object objects. -- -- * Support all DCS Object APIs. -- * Enhance with Object specific APIs not in the DCS Object API set. @@ -43,9 +44,15 @@ OBJECT = { -- @param #OBJECT self -- @param DCS#Object ObjectName The Object name -- @return #OBJECT self -function OBJECT:New( ObjectName, Test ) +function OBJECT:New( ObjectName) + + -- Inherit BASE class. local self = BASE:Inherit( self, BASE:New() ) + + -- Debug output. self:F2( ObjectName ) + + -- Set object name. self.ObjectName = ObjectName return self @@ -64,15 +71,14 @@ function OBJECT:GetID() return ObjectID end - BASE:E( { "Cannot GetID", Name = self.ObjectName, Class = self:GetClassName() } ) + self:E( { "Cannot GetID", Name = self.ObjectName, Class = self:GetClassName() } ) return nil end --- Destroys the OBJECT. -- @param #OBJECT self --- @return #boolean true if the object is destroyed. --- @return #nil The DCS Unit is not existing or alive. +-- @return #boolean Returns `true` if the object is destroyed or #nil if the object is nil. function OBJECT:Destroy() local DCSObject = self:GetDCSObject() @@ -83,7 +89,7 @@ function OBJECT:Destroy() return true end - BASE:E( { "Cannot Destroy", Name = self.ObjectName, Class = self:GetClassName() } ) + self:E( { "Cannot Destroy", Name = self.ObjectName, Class = self:GetClassName() } ) return nil end diff --git a/Moose Development/Moose/Wrapper/Weapon.lua b/Moose Development/Moose/Wrapper/Weapon.lua index 6f56ceb99..7317d53fd 100644 --- a/Moose Development/Moose/Wrapper/Weapon.lua +++ b/Moose Development/Moose/Wrapper/Weapon.lua @@ -367,7 +367,7 @@ function WEAPON:GetTarget() if object then -- Get object category. - local category=object:getCategory() + local category=Object.getCategory(object) --Target name local name=object:getName()