From 359429b17eb3b75c8af61a9f32bb129ebb275c12 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sun, 15 Dec 2024 13:34:13 +0100 Subject: [PATCH 1/2] #GROUP added `Teleport(Coordinate)` function leveraging `Respawn()`. Now also translate routes if there are any. --- Moose Development/Moose/Wrapper/Group.lua | 60 +++++++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 7be201af0..3760a84fc 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -1989,15 +1989,11 @@ end -- - @{#GROUP.InitHeight}: Set the height for the units in meters for the respawned group. (This is applicable for air units). -- - @{#GROUP.InitRandomizeHeading}: Randomize the headings for the units within the respawned group. -- - @{#GROUP.InitZone}: Set the respawn @{Core.Zone} for the respawned group. --- - @{#GROUP.InitRandomizeZones}: Randomize the respawn @{Core.Zone} between one of the @{Core.Zone}s given for the respawned group. -- - @{#GROUP.InitRandomizePositionZone}: Randomize the positions of the units of the respawned group within the @{Core.Zone}. -- - @{#GROUP.InitRandomizePositionRadius}: Randomize the positions of the units of the respawned group in a circle band. --- - @{#GROUP.InitRandomizeTemplates}: Randomize the Template for the respawned group. --- -- -- Notes: -- --- - When InitZone or InitRandomizeZones is not used, the position of the respawned group will be its current position. -- - The current alive group will always be destroyed and respawned using the template definition. -- -- @param Wrapper.Group#GROUP self @@ -2019,10 +2015,24 @@ function GROUP:Respawn( Template, Reset ) end return h end + + local function TransFormRoute(Template,OldPos,NewPos) + if Template.route and Template.route.points then + for _,_point in ipairs(Template.route.points) do + --self:I(string.format("Point x = %f Point y = %f",_point.x,_point.y)) + _point.x = _point.x - OldPos.x + NewPos.x + _point.y = _point.y - OldPos.y + NewPos.y + --self:I(string.format("Point x = %f Point y = %f",_point.x,_point.y)) + end + end + return Template + end -- First check if group is alive. if self:IsAlive() then - + + local OldPos = self:GetVec2() + -- Respawn zone. local Zone = self.InitRespawnZone -- Core.Zone#ZONE @@ -2035,6 +2045,8 @@ function GROUP:Respawn( Template, Reset ) -- X, Y Template.x = Vec3.x Template.y = Vec3.z + + local NewPos = { x = Vec3.x, y = Vec3.z } --Template.x = nil --Template.y = nil @@ -2089,11 +2101,13 @@ function GROUP:Respawn( Template, Reset ) -- Set heading. Template.units[UnitID].heading = _Heading(self.InitRespawnHeading and self.InitRespawnHeading or GroupUnit:GetHeading()) Template.units[UnitID].psi = -Template.units[UnitID].heading - + -- Debug. --self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } ) end end + + Template = TransFormRoute(Template,OldPos,NewPos) elseif Reset==false then -- Reset=false or nil @@ -2132,11 +2146,13 @@ function GROUP:Respawn( Template, Reset ) -- Heading Template.units[UnitID].heading = self.InitRespawnHeading and self.InitRespawnHeading or TemplateUnitData.heading - + -- Debug. --self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } ) end - + + Template = TransFormRoute(Template,OldPos,NewPos) + else local units=self:GetUnits() @@ -2185,10 +2201,11 @@ function GROUP:Respawn( Template, Reset ) -- Destroy old group. Dont trigger any dead/crash events since this is a respawn. self:Destroy(false) - --self:T({Template=Template}) + --UTILS.PrintTableToLog(Template) -- Spawn new group. - _DATABASE:Spawn(Template) + self:ScheduleOnce(0.1,_DATABASE.Spawn,_DATABASE,Template) + --_DATABASE:Spawn(Template) -- Reset events. self:ResetEvents() @@ -2196,6 +2213,29 @@ function GROUP:Respawn( Template, Reset ) return self end +--- Respawn the @{Wrapper.Group} at a @{Core.Point#COORDINATE}. +-- The method will setup the new group template according the Init(Respawn) settings provided for the group. +-- These settings can be provided by calling the relevant Init...() methods of the Group prior. +-- +-- - @{#GROUP.InitHeading}: Set the heading for the units in degrees within the respawned group. +-- - @{#GROUP.InitHeight}: Set the height for the units in meters for the respawned group. (This is applicable for air units). +-- - @{#GROUP.InitRandomizeHeading}: Randomize the headings for the units within the respawned group. +-- - @{#GROUP.InitRandomizePositionZone}: Randomize the positions of the units of the respawned group within the @{Core.Zone}. +-- - @{#GROUP.InitRandomizePositionRadius}: Randomize the positions of the units of the respawned group in a circle band. +-- +-- Notes: +-- +-- - When no coordinate is given, the position of the respawned group will be its current position. +-- - The current alive group will always be destroyed first. +-- - The new group will have all of its original units and health restored. +-- +-- @param Wrapper.Group#GROUP self +-- @param Core.Point#COORDINATE Coordinate Where to respawn the group. Can be handed as a @{Core.Zone#ZONE_BASE} object. +-- @return Wrapper.Group#GROUP self +function GROUP:Teleport(Coordinate) + self:InitZone(Coordinate) + return self:Respawn(nil,false) +end --- Respawn a group at an airbase. -- Note that the group has to be on parking spots at the airbase already in order for this to work. From e4bbfce3147798cb7c2e83fa7426b0d8b9c5a7cd Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Tue, 17 Dec 2024 12:45:45 +0100 Subject: [PATCH 2/2] #MANTIS - Better status overview - Some fixes for SHORAD setup --- Moose Development/Moose/Functional/Mantis.lua | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Functional/Mantis.lua b/Moose Development/Moose/Functional/Mantis.lua index 860e2fe2e..a48828973 100644 --- a/Moose Development/Moose/Functional/Mantis.lua +++ b/Moose Development/Moose/Functional/Mantis.lua @@ -663,7 +663,7 @@ do -- TODO Version -- @field #string version - self.version="0.8.19" + self.version="0.8.20" self:I(string.format("***** Starting MANTIS Version %s *****", self.version)) --- FSM Functions --- @@ -1511,6 +1511,9 @@ do elseif not found then self:E(self.lid .. string.format("*****Could not match radar data for %s! Will default to midrange values!",grpname)) end + if string.find(grpname,"SHORAD",1,true) then + type = MANTIS.SamType.SHORT -- force short on match + end return range, height, type, blind end @@ -1674,6 +1677,10 @@ do function MANTIS:_CheckLoop(samset,detset,dlink,limit) self:T(self.lid .. "CheckLoop " .. #detset .. " Coordinates") local switchedon = 0 + local statusreport = REPORT:New("\nMANTIS Status") + local instatusred = 0 + local instatusgreen = 0 + local SEADactive = 0 for _,_data in pairs (samset) do local samcoordinate = _data[2] local name = _data[1] @@ -1696,7 +1703,7 @@ do elseif (not self.UseEmOnOff) and switchedon < limit then samgroup:OptionAlarmStateRed() switchedon = switchedon + 1 - switch = true + switch = true end if self.SamStateTracker[name] ~= "RED" and switch then self:__RedState(1,samgroup) @@ -1714,7 +1721,7 @@ do -- debug output if (self.debug or self.verbose) and switch then local text = string.format("SAM %s in alarm state RED!", name) - local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug) + --local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug if self.verbose then self:I(self.lid..text) end end end --end alive @@ -1732,12 +1739,26 @@ do end if self.debug or self.verbose then local text = string.format("SAM %s in alarm state GREEN!", name) - local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug) + --local m=MESSAGE:New(text,10,"MANTIS"):ToAllIf(self.debug) if self.verbose then self:I(self.lid..text) end end end --end alive - end --end check - end --for for loop + end --end check + end --for loop + if self.debug then + for _,_status in pairs(self.SamStateTracker) do + if _status == "GREEN" then + instatusgreen=instatusgreen+1 + elseif _status == "RED" then + instatusred=instatusred+1 + end + end + statusreport:Add("+-----------------------------+") + statusreport:Add(string.format("+ SAM in RED State: %2d",instatusred)) + statusreport:Add(string.format("+ SAM in GREEN State: %2d",instatusgreen)) + statusreport:Add("+-----------------------------+") + MESSAGE:New(statusreport:Text(),10,nil,true):ToAll():ToLog() + end return self end @@ -1851,7 +1872,7 @@ do end --]] if self.autoshorad then - self.Shorad = SHORAD:New(self.name.."-SHORAD",self.name.."-SHORAD",self.SAM_Group,self.ShoradActDistance,self.ShoradTime,self.coalition,self.UseEmOnOff) + self.Shorad = SHORAD:New(self.name.."-SHORAD","SHORAD",self.SAM_Group,self.ShoradActDistance,self.ShoradTime,self.coalition,self.UseEmOnOff) self.Shorad:SetDefenseLimits(80,95) self.ShoradLink = true self.Shorad.Groupset=self.ShoradGroupSet