From e5fbaeafcdaadb81765200687b82a03a05b36507 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 3 Jan 2024 18:03:53 +0100 Subject: [PATCH] xxx --- Moose Development/Moose/Core/Set.lua | 31 ++++++++++++++++++++--- Moose Development/Moose/Modules_local.lua | 1 + Moose Setup/Moose.files | 2 ++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index f4e5a0ed7..1ad9bdea6 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -455,7 +455,7 @@ do -- SET_BASE --- Gets a random object from the @{Core.Set#SET_BASE} and derived classes. -- @param #SET_BASE self - -- @return Core.Base#BASE + -- @return Core.Base#BASE or nil if none found or the SET is empty! function SET_BASE:GetRandom() local tablemax = 0 for _,_ind in pairs(self.Index) do @@ -466,6 +466,23 @@ do -- SET_BASE self:T3( { RandomItem } ) return RandomItem end + + --- Gets a random object from the @{Core.Set#SET_BASE} and derived classes. A bit slower than @{#SET_BASE.GetRandom}() but tries to ensure you get an object back if the SET is not empty. + -- @param #SET_BASE self + -- @return Core.Base#BASE or nil if the SET is empty! + function SET_BASE:GetRandomSurely() + local tablemax = 0 + local sorted = {} + for _,_obj in pairs(self.Set) do + tablemax = tablemax + 1 + sorted[tablemax] = _obj + end + --local tablemax = table.maxn(self.Index) + --local RandomItem = self.Set[self.Index[math.random(1,tablemax)]] + local RandomItem = sorted[math.random(1,tablemax)] + self:T3( { RandomItem } ) + return RandomItem + end --- Retrieves the amount of objects in the @{Core.Set#SET_BASE} and derived classes. -- @param #SET_BASE self @@ -8215,9 +8232,15 @@ do -- SET_SCENERY -- @param #SET_SCENERY self -- @return Core.Point#COORDINATE The center coordinate of all the objects in the set. function SET_SCENERY:GetCoordinate() - - local Coordinate = self:GetRandom():GetCoordinate() - + + local Coordinate = COORDINATE:New({0,0,0}) + + local Item = self:GetRandomSurely() + + if Item then + Coordinate:GetCoordinate() + end + local x1 = Coordinate.x local x2 = Coordinate.x local y1 = Coordinate.y diff --git a/Moose Development/Moose/Modules_local.lua b/Moose Development/Moose/Modules_local.lua index 7a9c03cf2..b9aa9b0ab 100644 --- a/Moose Development/Moose/Modules_local.lua +++ b/Moose Development/Moose/Modules_local.lua @@ -80,6 +80,7 @@ __Moose.Include( 'Functional\\Autolase.lua' ) __Moose.Include( 'Functional\\AICSAR.lua' ) __Moose.Include( 'Functional\\AmmoTruck.lua' ) __Moose.Include( 'Functional\\Tiresias.lua' ) +__Moose.Include( 'Functional\\Stratego.lua' ) __Moose.Include( 'Ops\\Airboss.lua' ) __Moose.Include( 'Ops\\RecoveryTanker.lua' ) diff --git a/Moose Setup/Moose.files b/Moose Setup/Moose.files index 6aae29e92..9410d551e 100644 --- a/Moose Setup/Moose.files +++ b/Moose Setup/Moose.files @@ -71,6 +71,8 @@ Functional/Autolase.lua Functional/AICSAR.lua Functional/AmmoTruck.lua Functional/ZoneGoalCargo.lua +Functional/Stratego.lua +Functional/Tiresias.lua Ops/Airboss.lua Ops/RecoveryTanker.lua