From 89845883d02951f9f3caa7a4467aa4c934f750aa Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 4 Apr 2022 12:57:04 +0200 Subject: [PATCH] Some nil checks to the A2A dispatcher, keeping it from detecting nil units, added locale to Settings and use of it to TextAndSound --- .../Moose/AI/AI_A2A_Dispatcher.lua | 20 ++++++++++++++++--- Moose Development/Moose/Core/Settings.lua | 17 +++++++++++++++- Moose Development/Moose/Core/TextAndSound.lua | 4 ++-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua index bf9bc3256..a4ad52423 100644 --- a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua @@ -884,8 +884,9 @@ do -- AI_A2A_DISPATCHER --- Enumerator for spawns at airbases -- @type AI_A2A_DISPATCHER.Takeoff -- @extends Wrapper.Group#GROUP.Takeoff - - --- @field #AI_A2A_DISPATCHER.Takeoff Takeoff + + --- + -- @field #AI_A2A_DISPATCHER.Takeoff Takeoff AI_A2A_DISPATCHER.Takeoff = GROUP.Takeoff --- Defnes Landing location. @@ -3048,7 +3049,20 @@ do -- AI_A2A_DISPATCHER for FriendlyDistance, AIFriendly in UTILS.spairs( DefenderFriendlies or {} ) do -- We only allow to ENGAGE targets as long as the Units on both sides are balanced. if AttackerCount > DefenderCount then - local Friendly = AIFriendly:GetGroup() -- Wrapper.Group#GROUP + --self:I("***** AI_A2A_DISPATCHER:CountDefendersToBeEngaged() *****\nThis is supposed to be a UNIT:") + if AIFriendly then + local classname = AIFriendly.ClassName or "No Class Name" + local unitname = AIFriendly.IdentifiableName or "No Unit Name" + --self:I("Class Name: " .. classname) + --self:I("Unit Name: " .. unitname) + --self:I({AIFriendly}) + end + local Friendly = nil + if AIFriendly and AIFriendly:IsAlive() then + --self:I("AIFriendly alive, getting GROUP") + Friendly = AIFriendly:GetGroup() -- Wrapper.Group#GROUP + end + if Friendly and Friendly:IsAlive() then -- Ok, so we have a friendly near the potential target. -- Now we need to check if the AIGroup has a Task. diff --git a/Moose Development/Moose/Core/Settings.lua b/Moose Development/Moose/Core/Settings.lua index 74b5fa54b..209bb3beb 100644 --- a/Moose Development/Moose/Core/Settings.lua +++ b/Moose Development/Moose/Core/Settings.lua @@ -253,6 +253,7 @@ do -- SETTINGS self:SetMessageTime( MESSAGE.Type.Overview, 60 ) self:SetMessageTime( MESSAGE.Type.Update, 15 ) self:SetEraModern() + self:SetLocale("en") return self else local Settings = _DATABASE:GetPlayerSettings( PlayerName ) @@ -284,7 +285,21 @@ do -- SETTINGS function SETTINGS:SetMetric() self.Metric = true end - + + --- Sets the SETTINGS default text locale. + -- @param #SETTINGS self + -- @param #string Locale + function SETTINGS:SetLocale(Locale) + self.Locale = Locale or "en" + end + + --- Gets the SETTINGS text locale. + -- @param #SETTINGS self + -- @return #string + function SETTINGS:GetLocale() + return self.Locale or _SETTINGS:GetLocale() + end + --- Gets if the SETTINGS is metric. -- @param #SETTINGS self -- @return #boolean true if metric. diff --git a/Moose Development/Moose/Core/TextAndSound.lua b/Moose Development/Moose/Core/TextAndSound.lua index 25cb8f9af..edd4a79d8 100644 --- a/Moose Development/Moose/Core/TextAndSound.lua +++ b/Moose Development/Moose/Core/TextAndSound.lua @@ -60,14 +60,14 @@ TEXTANDSOUND = { --- Instantiate a new object -- @param #TEXTANDSOUND self -- @param #string ClassName Name of the class this instance is providing texts for. --- @param #string Defaultlocale Default locale of this instance, e.g. "en". +-- @param #string Defaultlocale (Optional) Default locale of this instance, defaults to "en". -- @return #TEXTANDSOUND self function TEXTANDSOUND:New(ClassName,Defaultlocale) -- Inherit everything from BASE class. local self=BASE:Inherit(self, BASE:New()) -- Set some string id for output to DCS.log file. self.lid=string.format("%s (%s) | ", self.ClassName, self.version) - self.locale = Defaultlocale or "en" + self.locale = Defaultlocale or (_SETTINGS:GetLocale() or "en") self.textclass = ClassName or "none" self.entries = {} local initentry = {} -- #TEXTANDSOUND.Entry