From c4738b24ebc5dd7132eeda4ce6b7d3dc48ef31dc Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Tue, 16 Jul 2024 16:02:33 +0200 Subject: [PATCH] fixes and additions --- Moose Development/Moose/Core/Database.lua | 9 ++-- Moose Development/Moose/DCS.lua | 1 + Moose Development/Moose/Wrapper/Client.lua | 8 +++- .../Moose/Wrapper/Controllable.lua | 42 +++++++++++++++++++ Moose Development/Moose/Wrapper/Storage.lua | 26 ++++++++++-- 5 files changed, 78 insertions(+), 8 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index ed1271037..184525502 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -815,10 +815,11 @@ end --- Adds a CLIENT based on the ClientName in the DATABASE. -- @param #DATABASE self -- @param #string ClientName Name of the Client unit. +-- @param #boolean Force (optional) Force registration of client. -- @return Wrapper.Client#CLIENT The client object. -function DATABASE:AddClient( ClientName ) +function DATABASE:AddClient( ClientName, Force ) - if not self.CLIENTS[ClientName] then + if not self.CLIENTS[ClientName] or Force == true then self.CLIENTS[ClientName] = CLIENT:Register( ClientName ) end @@ -1579,8 +1580,8 @@ function DATABASE:_EventOnBirth( Event ) self:I(string.format("Player '%s' joined 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) + if client == nil or (client and client:CountPlayers() == 0) then + client=self:AddClient(Event.IniDCSUnitName, true) end -- Add player. diff --git a/Moose Development/Moose/DCS.lua b/Moose Development/Moose/DCS.lua index c9af9b5b7..ad702a851 100644 --- a/Moose Development/Moose/DCS.lua +++ b/Moose Development/Moose/DCS.lua @@ -1695,6 +1695,7 @@ do -- AI -- @field ALARM_STATE @{#AI.Option.Ground.val.ALARM_STATE} -- @field ENGAGE_AIR_WEAPONS -- @field AC_ENGAGEMENT_RANGE_RESTRICTION + -- @field EVASION_OF_ARM --- -- @type AI.Option.Ground.mid -- Moose added diff --git a/Moose Development/Moose/Wrapper/Client.lua b/Moose Development/Moose/Wrapper/Client.lua index 3fb20deba..d39f0bb30 100644 --- a/Moose Development/Moose/Wrapper/Client.lua +++ b/Moose Development/Moose/Wrapper/Client.lua @@ -201,6 +201,13 @@ function CLIENT:AddPlayer(PlayerName) return self end +--- Get number of associated players. +-- @param #CLIENT self +-- @return #number Count +function CLIENT:CountPlayers() + return #self.Players or 0 +end + --- Get player name(s). -- @param #CLIENT self -- @return #table List of player names or an empty table `{}`. @@ -608,4 +615,3 @@ function CLIENT:GetPlayerInfo(Attribute) return nil end end - diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 365a201d6..77700891e 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -3811,6 +3811,48 @@ function CONTROLLABLE:OptionProhibitAfterburner( Prohibit ) return self end +--- [Ground] Allows AI radar units to take defensive actions to avoid anti radiation missiles. Units are allowed to shut radar off and displace. +-- @param #CONTROLLABLE self +-- @param #number Seconds Can be - nil, 0 or false = switch off this option, any positive number = number of seconds the escape sequency runs. +-- @return #CONTROLLABLE self +function CONTROLLABLE:OptionEvasionOfARM(Seconds) + self:F2( { self.ControllableName } ) + + local DCSControllable = self:GetDCSObject() + if DCSControllable then + local Controller = self:_GetController() + + if self:IsGround() then + if Seconds == nil then Seconds = false end + Controller:setOption( AI.Option.Ground.id.EVASION_OF_ARM, Seconds) + end + + end + + return self +end + +--- [Ground] Option that defines the vehicle spacing when in an on road and off road formation. +-- @param #CONTROLLABLE self +-- @param #number meters Can be zero to 100 meters. Defaults to 50 meters. +-- @return #CONTROLLABLE self +function CONTROLLABLE:OptionFormationInterval(meters) + self:F2( { self.ControllableName } ) + + local DCSControllable = self:GetDCSObject() + if DCSControllable then + local Controller = self:_GetController() + + if self:IsGround() then + if meters == nil or meters > 100 or meters < 0 then meters = 50 end + Controller:setOption( 30, meters) + end + + end + + return self +end + --- [Air] Defines the usage of Electronic Counter Measures by airborne forces. -- @param #CONTROLLABLE self -- @param #number ECMvalue Can be - 0=Never on, 1=if locked by radar, 2=if detected by radar, 3=always on, defaults to 1 diff --git a/Moose Development/Moose/Wrapper/Storage.lua b/Moose Development/Moose/Wrapper/Storage.lua index 8e45df179..6f154c575 100644 --- a/Moose Development/Moose/Wrapper/Storage.lua +++ b/Moose Development/Moose/Wrapper/Storage.lua @@ -149,7 +149,7 @@ STORAGE.Liquid = { --- STORAGE class version. -- @field #string version -STORAGE.version="0.0.1" +STORAGE.version="0.0.2" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -162,7 +162,7 @@ STORAGE.version="0.0.1" -- Constructor ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- Create a new STORAGE object from the DCS weapon object. +--- Create a new STORAGE object from the DCS airbase object. -- @param #STORAGE self -- @param #string AirbaseName Name of the airbase. -- @return #STORAGE self @@ -182,8 +182,28 @@ function STORAGE:New(AirbaseName) return self end +--- Create a new STORAGE object from an DCS static cargo object. +-- @param #STORAGE self +-- @param #string StaticCargoName Unit name of the static. +-- @return #STORAGE self +function STORAGE:NewFromStaticCargo(StaticCargoName) ---- Find a STORAGE in the **_DATABASE** using the name associated airbase. + -- Inherit everything from BASE class. + local self=BASE:Inherit(self, BASE:New()) -- #STORAGE + + self.airbase=StaticObject.getByName(StaticCargoName) + + if Airbase.getWarehouse then + self.warehouse=Warehouse.getCargoAsWarehouse(self.airbase) + end + + self.lid = string.format("STORAGE %s", StaticCargoName) + + return self +end + + +--- Airbases only - Find a STORAGE in the **_DATABASE** using the name associated airbase. -- @param #STORAGE self -- @param #string AirbaseName The Airbase Name. -- @return #STORAGE self