From 5146106885fda9f144424892e19432e9690f7314 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 19 Jan 2021 16:56:26 +0100 Subject: [PATCH 1/8] Update Controllable.lua --- Moose Development/Moose/Wrapper/Controllable.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index d46e62dd1..526a184a4 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -1897,7 +1897,7 @@ do -- Patrol methods local ToCoord = COORDINATE:NewFromVec2( { x = Waypoint.x, y = Waypoint.y } ) -- Create a "ground route point", which is a "point" structure that can be given as a parameter to a Task local Route = {} - Route[#Route+1] = FromCoord:WaypointGround( 0 ) + Route[#Route+1] = FromCoord:WaypointGround( Speed, Formation ) Route[#Route+1] = ToCoord:WaypointGround( Speed, Formation ) @@ -1950,7 +1950,7 @@ do -- Patrol methods -- Create a "ground route point", which is a "point" structure that can be given as a parameter to a Task local Route = {} - Route[#Route+1] = FromCoord:WaypointGround( 20 ) + Route[#Route+1] = FromCoord:WaypointGround( Speed, Formation ) Route[#Route+1] = ToCoord:WaypointGround( Speed, Formation ) From 89aa08829eab164dc0ae7afd4806f4e736275a4a Mon Sep 17 00:00:00 2001 From: Applevangelist <72444570+Applevangelist@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:05:14 +0100 Subject: [PATCH 2/8] Update ATIS.lua Fix time to be negative if early AM when using time to ZULU or time to GMT difference --- Moose Development/Moose/Ops/ATIS.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Moose Development/Moose/Ops/ATIS.lua b/Moose Development/Moose/Ops/ATIS.lua index 29b2918b2..688b743b7 100644 --- a/Moose Development/Moose/Ops/ATIS.lua +++ b/Moose Development/Moose/Ops/ATIS.lua @@ -1318,6 +1318,10 @@ function ATIS:onafterBroadcast(From, Event, To) time=time-UTILS.GMTToLocalTimeDifference()*60*60 end + if time < 0 then + time = 24*60*60 - time --avoid negative time around midnight + end + local clock=UTILS.SecondsToClock(time) local zulu=UTILS.Split(clock, ":") local ZULU=string.format("%s%s", zulu[1], zulu[2]) From a6ff84c09a1d2715f7549c6354c16547dd5b2e0a Mon Sep 17 00:00:00 2001 From: Applevangelist <72444570+Applevangelist@users.noreply.github.com> Date: Thu, 21 Jan 2021 15:34:50 +0100 Subject: [PATCH 3/8] ATIS.lua update time calculation over midnight (logic error) Actually line 1322 + time here, sind it's negative ... :) --- Moose Development/Moose/Ops/ATIS.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Ops/ATIS.lua b/Moose Development/Moose/Ops/ATIS.lua index 688b743b7..044963a28 100644 --- a/Moose Development/Moose/Ops/ATIS.lua +++ b/Moose Development/Moose/Ops/ATIS.lua @@ -1319,7 +1319,7 @@ function ATIS:onafterBroadcast(From, Event, To) end if time < 0 then - time = 24*60*60 - time --avoid negative time around midnight + time = 24*60*60 + time --avoid negative time around midnight end local clock=UTILS.SecondsToClock(time) From e9f92d225033d5cd6ee45a63660307fdc166bcd9 Mon Sep 17 00:00:00 2001 From: Applevangelist <72444570+Applevangelist@users.noreply.github.com> Date: Fri, 22 Jan 2021 18:34:05 +0100 Subject: [PATCH 4/8] Update Set.lua Break loop after x tries --- Moose Development/Moose/Core/Set.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 41261abcc..87bcf9e4a 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -5411,10 +5411,12 @@ do -- SET_ZONE --- Get a random zone from the set. -- @param #SET_ZONE self + -- @param #number margin Number of tries to find a zone -- @return Core.Zone#ZONE_BASE The random Zone. -- @return #nil if no zone in the collection. - function SET_ZONE:GetRandomZone() - + function SET_ZONE:GetRandomZone(margin) + + local margin = margin or 100 if self:Count() ~= 0 then local Index = self.Index @@ -5423,9 +5425,11 @@ do -- SET_ZONE -- Loop until a zone has been found. -- The :GetZoneMaybe() call will evaluate the probability for the zone to be selected. -- If the zone is not selected, then nil is returned by :GetZoneMaybe() and the loop continues! - while not ZoneFound do + local counter = 0 + while (not ZoneFound) or (counter < margin) do local ZoneRandom = math.random( 1, #Index ) ZoneFound = self.Set[Index[ZoneRandom]]:GetZoneMaybe() + counter = counter + 1 end return ZoneFound From 5a43936e359e1d4029802b0618057bb18e7416c9 Mon Sep 17 00:00:00 2001 From: Wingthor Date: Fri, 22 Jan 2021 23:10:22 +0100 Subject: [PATCH 5/8] Added a table shuffler using Fisher Yeates algorithm in Utilities/Utils.lua --- Moose Development/Moose/Utilities/Utils.lua | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index 182537ce6..2ca10e6f9 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -1500,4 +1500,24 @@ function UTILS.GetOSTime() end return nil -end \ No newline at end of file +end + +--- Shuffle a table accoring to Fisher Yeates algorithm +--@param #table table to be shuffled +--@return #table +function UTILS.ShuffleTable(t) + if t == nil or type(t) ~= "table" then + BASE:I("Error in ShuffleTable: Missing or wrong tyƄe of Argument") + return + end + math.random() + math.random() + math.random() + local TempTable = {} + for i = 1, #t do + local r = math.random(1,#t) + TempTable[i] = t[r] + table.remove(t,r) + end + return TempTable +end From 6baf85d42963b95c1e4836e5ec4569bb0fae3395 Mon Sep 17 00:00:00 2001 From: Applevangelist <72444570+Applevangelist@users.noreply.github.com> Date: Tue, 26 Jan 2021 09:26:39 +0100 Subject: [PATCH 6/8] Update Mantis.lua Some Doc corrections --- Moose Development/Moose/Functional/Mantis.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Functional/Mantis.lua b/Moose Development/Moose/Functional/Mantis.lua index a4ca58c19..78f7bc0a5 100644 --- a/Moose Development/Moose/Functional/Mantis.lua +++ b/Moose Development/Moose/Functional/Mantis.lua @@ -1,4 +1,4 @@ - --- **Functional** -- Modular, Automatic and Network capable Targeting and Interception System for Air Defenses +--- **Functional** -- Modular, Automatic and Network capable Targeting and Interception System for Air Defenses -- -- === -- @@ -96,7 +96,7 @@ -- -- # 2. Start up your MANTIS with a basic setting -- --- `myredmantis = MANTIS:New("myredmantis","Red SAM","Red EWR",nil,"red",false)` +-- `myredmantis = MANTIS:New("myredmantis","Red SAM","Red EWR",nil,"red",false)` -- `myredmantis:Start()` -- -- [optional] Use @@ -111,7 +111,7 @@ -- -- If you want to use a separate AWACS unit (default detection range: 250km) to support your EWR system, use e.g. the following setup: -- --- `mybluemantis = MANTIS:New("bluemantis","Blue SAM","Blue EWR",nil,"blue",false,"Blue Awacs")` +-- `mybluemantis = MANTIS:New("bluemantis","Blue SAM","Blue EWR",nil,"blue",false,"Blue Awacs")` -- `mybluemantis:Start()` -- -- # 3. Default settings From 7a07e15032eb8cd603f27550444d7ccb379542cb Mon Sep 17 00:00:00 2001 From: Applevangelist <72444570+Applevangelist@users.noreply.github.com> Date: Tue, 26 Jan 2021 11:06:08 +0100 Subject: [PATCH 7/8] Update Mantis.lua --- Moose Development/Moose/Functional/Mantis.lua | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Moose Development/Moose/Functional/Mantis.lua b/Moose Development/Moose/Functional/Mantis.lua index 78f7bc0a5..a06b5ccc2 100644 --- a/Moose Development/Moose/Functional/Mantis.lua +++ b/Moose Development/Moose/Functional/Mantis.lua @@ -37,7 +37,7 @@ -- @field #table SAM_Table Table of SAM sites -- @field #string lid Prefix for logging -- @field @{#Functional.Detection#DETECTION_AREAS} Detection The #DETECTION_AREAS object for EWR --- @field @{Functional.Detection#DETECTION_AREAS} AWACS_Detection The #DETECTION_AREAS object for AWACS +-- @field @{#Functional.Detection#DETECTION_AREAS} AWACS_Detection The #DETECTION_AREAS object for AWACS -- @field #boolean debug Switch on extra messages -- @field #boolean verbose Switch on extra logging -- @field #number checkradius Radius of the SAM sites @@ -181,6 +181,26 @@ do --@param #boolean dynamic Use constant (true) filtering or just filter once (false, default) (optional) --@param #string awacs Group name of your Awacs (optional) --@return #MANTIS self + --@usage Start up your MANTIS with a basic setting + -- + -- `myredmantis = MANTIS:New("myredmantis","Red SAM","Red EWR",nil,"red",false)` + -- `myredmantis:Start()` + -- + -- [optional] Use + -- + -- * `MANTIS:SetEWRGrouping(radius)` + -- * `MANTIS:SetEWRRange(radius)` + -- * `MANTIS:SetSAMRadius(radius)` + -- * `MANTIS:SetDetectInterval(interval)` + -- * `MANTIS:SetAutoRelocate(hq, ewr)` + -- + -- before starting #MANTIS to fine-tune your setup. + -- + -- If you want to use a separate AWACS unit (default detection range: 250km) to support your EWR system, use e.g. the following setup: + -- + -- `mybluemantis = MANTIS:New("bluemantis","Blue SAM","Blue EWR",nil,"blue",false,"Blue Awacs")` + -- `mybluemantis:Start()` + -- function MANTIS:New(name,samprefix,ewrprefix,hq,coaltion,dynamic,awacs) -- DONE: Create some user functions for these @@ -307,7 +327,7 @@ do self.engagerange = range end - --- Function to set a new SAM firing engage range, use this method to adjust range while running MANTIS, e.g. for different setups day and night + --- Function to set a new SAM firing engage range, use this method to adjust range while running MANTIS, e.g. for different setups day and night -- @param #MANTIS self -- @param #number range Percent of the max fire range function MANTIS:SetNewSAMRangeWhileRunning(range) @@ -535,7 +555,7 @@ do end end - --- Function to check if any object is in the given SAM zone + --- (Internal) Function to check if any object is in the given SAM zone -- @param #MANTIS self -- @param #table dectset Table of coordinates of detected items -- @param samcoordinate Core.Point#COORDINATE Coordinate object. @@ -562,7 +582,7 @@ do return false end - --- Function to start the detection via EWR groups + --- (Internal) Function to start the detection via EWR groups -- @param #MANTIS self -- @return Functional.Detection #DETECTION_AREAS The running detection set function MANTIS:StartDetection() @@ -593,7 +613,7 @@ do return _MANTISdetection end - --- Function to start the detection via AWACS if defined as separate + --- (Internal) Function to start the detection via AWACS if defined as separate -- @param #MANTIS self -- @return Functional.Detection #DETECTION_AREAS The running detection set function MANTIS:StartAwacsDetection() @@ -625,7 +645,7 @@ do return _MANTISAwacs end - --- Function to set the SAM start state + --- (Internal) Function to set the SAM start state -- @param #MANTIS self -- @return #MANTIS self function MANTIS:SetSAMStartState() From fe55555c67552c9c73cd1f1c48162cce61bf53de Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 30 Jan 2021 23:28:07 +0100 Subject: [PATCH 8/8] OPS - Fixed inAir check for spawned groups - Reduced SCHEDULER min delay to 0.001 sec (was 0.1 sec) --- Moose Development/Moose/AI/AI_Formation.lua | 4 ++-- Moose Development/Moose/Core/ScheduleDispatcher.lua | 2 +- Moose Development/Moose/Ops/FlightGroup.lua | 7 ++++--- Moose Development/Moose/Ops/OpsGroup.lua | 2 +- Moose Development/Moose/Wrapper/Unit.lua | 7 ++++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Formation.lua b/Moose Development/Moose/AI/AI_Formation.lua index 17c1b5345..aaf4fbe54 100644 --- a/Moose Development/Moose/AI/AI_Formation.lua +++ b/Moose Development/Moose/AI/AI_Formation.lua @@ -1140,8 +1140,8 @@ end -- @param DCS#Vec3 CV2 Vec3 function AI_FORMATION:FollowMe(FollowGroup, ClientUnit, CT1, CV1, CT2, CV2) - if FollowGroup:GetState( FollowGroup, "Mode" ) == self.__Enum.Mode.Formation then - + if FollowGroup:GetState( FollowGroup, "Mode" ) == self.__Enum.Mode.Formation and not self:Is("Stopped") then + self:T({Mode=FollowGroup:GetState( FollowGroup, "Mode" )}) FollowGroup:OptionROTEvadeFire() diff --git a/Moose Development/Moose/Core/ScheduleDispatcher.lua b/Moose Development/Moose/Core/ScheduleDispatcher.lua index bfd1dabb4..db04a1500 100644 --- a/Moose Development/Moose/Core/ScheduleDispatcher.lua +++ b/Moose Development/Moose/Core/ScheduleDispatcher.lua @@ -122,7 +122,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr self.Schedule[Scheduler][CallID].Function = ScheduleFunction self.Schedule[Scheduler][CallID].Arguments = ScheduleArguments self.Schedule[Scheduler][CallID].StartTime = timer.getTime() + ( Start or 0 ) - self.Schedule[Scheduler][CallID].Start = Start + 0.1 + self.Schedule[Scheduler][CallID].Start = Start + 0.001 self.Schedule[Scheduler][CallID].Repeat = Repeat or 0 self.Schedule[Scheduler][CallID].Randomize = Randomize or 0 self.Schedule[Scheduler][CallID].Stop = Stop diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index ce641b949..ad0f1a6ce 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -1169,7 +1169,8 @@ function FLIGHTGROUP:OnEventBirth(EventData) -- Set element to spawned state. self:T(self.lid..string.format("EVENT: Element %s born at airbase %s==> spawned", element.name, self.homebase and self.homebase:GetName() or "unknown")) - self:ElementSpawned(element) + -- This is delayed by a millisec because inAir check for units spawned in air failed (returned false even though the unit was spawned in air). + self:__ElementSpawned(0.0, element) end @@ -1436,7 +1437,7 @@ function FLIGHTGROUP:onafterElementSpawned(From, Event, To, Element) -- Set element status. self:_UpdateStatus(Element, OPSGROUP.ElementStatus.SPAWNED) - if Element.unit:InAir() then + if Element.unit:InAir(true) then -- Trigger ElementAirborne event. Add a little delay because spawn is also delayed! self:__ElementAirborne(0.11, Element) else @@ -2008,7 +2009,7 @@ function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n) if #wp>1 then -- Route group to all defined waypoints remaining. - self:Route(wp, 1) + self:Route(wp) else diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index c202ab0ff..b8f52b52e 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -2223,7 +2223,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) local TaskFinal=self.group:TaskCombo({TaskControlled, TaskDone}) -- Set task for group. - self:SetTask(TaskFinal, 1) + self:SetTask(TaskFinal) end diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 705e29303..beb43fc4c 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -1174,8 +1174,9 @@ end --- Returns true if the UNIT is in the air. -- @param #UNIT self +-- @param #boolean NoHeloCheck If true, no additonal checks for helos are performed. -- @return #boolean Return true if in the air or #nil if the UNIT is not existing or alive. -function UNIT:InAir() +function UNIT:InAir(NoHeloCheck) self:F2( self.UnitName ) -- Get DCS unit object. @@ -1185,14 +1186,14 @@ function UNIT:InAir() -- Get DCS result of whether unit is in air or not. local UnitInAir = DCSUnit:inAir() - + -- Get unit category. local UnitCategory = DCSUnit:getDesc().category -- If DCS says that it is in air, check if this is really the case, since we might have landed on a building where inAir()=true but actually is not. -- This is a workaround since DCS currently does not acknoledge that helos land on buildings. -- Note however, that the velocity check will fail if the ground is moving, e.g. on an aircraft carrier! - if UnitInAir==true and UnitCategory == Unit.Category.HELICOPTER then + if UnitInAir==true and UnitCategory == Unit.Category.HELICOPTER and (not NoHeloCheck) then local VelocityVec3 = DCSUnit:getVelocity() local Velocity = UTILS.VecNorm(VelocityVec3) local Coordinate = DCSUnit:getPoint()