From 888734b7d169a2b11d123413e55f1bdcc4a98f5d Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 18 Jul 2022 22:59:49 +0200 Subject: [PATCH] OPS - Fixed bug in parking spot distance for ships. - Added enroute anti-ship task for anti-ship missions. --- Moose Development/Moose/Ops/Auftrag.lua | 6 +- Moose Development/Moose/Ops/FlightGroup.lua | 61 ++++++++++++++++--- Moose Development/Moose/Ops/OpsGroup.lua | 3 +- Moose Development/Moose/Wrapper/Airbase.lua | 1 + .../Moose/Wrapper/Controllable.lua | 21 +++++++ 5 files changed, 81 insertions(+), 11 deletions(-) diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index c89e9c3a7..69b9a7fd6 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -5282,6 +5282,10 @@ function AUFTRAG:GetDCSMissionTask() -- ANTISHIP Mission -- ---------------------- + -- Add enroute anti-ship task. + local DCStask=CONTROLLABLE.EnRouteTaskAntiShip(nil) + table.insert(self.enrouteTasks, DCStask) + self:_GetDCSAttackTask(self.engageTarget, DCStasks) elseif self.type==AUFTRAG.Type.AWACS then @@ -5620,8 +5624,6 @@ function AUFTRAG:GetDCSMissionTask() end - --table.insert(DCStasks, DCStask) - elseif self.type==AUFTRAG.Type.BARRAGE then --------------------- diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index a1182ed7d..6bc993d13 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -875,16 +875,14 @@ function FLIGHTGROUP:Status() if element.parking then -- Get distance to assigned parking spot. - local dist=element.unit:GetCoord():Get2DDistance(element.parking.Coordinate) + local dist=self:_GetDistToParking(element.parking, element.unit:GetCoord()) - --env.info(string.format("FF dist to parking spot %d = %.1f meters", element.parking.TerminalID, dist)) - - -- If distance >10 meters, we consider the unit as taxiing. - -- At least for fighters, the initial distance seems to be around 1.8 meters. + -- Debug info. + self:T(self.lid..string.format("Distance to parking spot %d = %.1f meters", element.parking.TerminalID, dist)) + + -- If distance >10 meters, we consider the unit as taxiing. At least for fighters, the initial distance seems to be around 1.8 meters. if dist>12 and element.engineOn then - --if element.status==OPSGROUP.ElementStatus.ENGINEON then - self:ElementTaxiing(element) - --end + self:ElementTaxiing(element) end else @@ -4604,6 +4602,53 @@ function FLIGHTGROUP:_GetPlayerData() return nil end +--- Get distance to parking spot. Takes extra care of ships. +-- @param #FLIGHTGROUP self +-- @param Wrapper.Airbase#AIRBASE.ParkingSpot Spot Parking Spot. +-- @param Core.Point#COORDINATE Coordinate Reference coordinate. +-- @return #number Distance to parking spot in meters. +function FLIGHTGROUP:_GetDistToParking(Spot, Coordinate) + + local dist=99999 + + if Spot then + + -- Get the airbase this spot belongs to. + local airbase=AIRBASE:FindByName(Spot.AirbaseName) + + + if airbase:IsShip() then --or airbase:IsHelipad() then + + -- Vec2 of airbase. + local a=airbase:GetVec2() + + -- Vec2 of parking spot. + local b=Spot.Coordinate:GetVec2() + + -- Vec2 of ref coordinate. + local c=Coordinate:GetVec2() + + -- Vector from ref coord to airbase. This still needs to be rotated. + local t=UTILS.Vec2Substract(c,a) + + -- Get the heading of the unit. + local unit=UNIT:FindByName(Spot.AirbaseName) + local hdg=unit:GetHeading() + + -- Rotate the vector so that it corresponds to facing "North". + t=UTILS.Vec2Rotate2D(t, -hdg) + + -- Distance from spot to ref coordinate. + dist=UTILS.VecDist2D(b,t) + else + -- Normal case. + dist=Coordinate:Get2DDistance(Spot.Coordinate) + end + + end + + return dist +end ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 56f8eab4b..840911bfd 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3595,7 +3595,7 @@ function OPSGROUP:PushTask(DCSTask) text=text..string.format("\n[%d] %s", i, tostring(task.id)) end end - self:T(self.lid..text) + self:T(self.lid..text) end return self @@ -3756,6 +3756,7 @@ function OPSGROUP:AddTaskEnroute(task) end if not gotit then + self:T(self.lid..string.format("Adding enroute task")) table.insert(self.taskenroute, task) end diff --git a/Moose Development/Moose/Wrapper/Airbase.lua b/Moose Development/Moose/Wrapper/Airbase.lua index 53113da33..c21fb28f1 100644 --- a/Moose Development/Moose/Wrapper/Airbase.lua +++ b/Moose Development/Moose/Wrapper/Airbase.lua @@ -1105,6 +1105,7 @@ function AIRBASE:_InitParkingSpots() park.TerminalType=spot.Term_Type park.TOAC=spot.TO_AC park.ClientSpot, park.ClientName=isClient(park.Coordinate) + park.AirbaseName=self.AirbaseName self.NparkingTotal=self.NparkingTotal+1 diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index b27f74903..9cf3fc341 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -1557,6 +1557,27 @@ function CONTROLLABLE:EnRouteTaskEngageTargetsInZone( Vec2, Radius, TargetTypes, return DCSTask end +--- (AIR) Enroute anti-ship task. +-- @param #CONTROLLABLE self +-- @param DCS#AttributeNameArray TargetTypes Array of target categories allowed to engage. Default `{"Ships"}`. +-- @param #number Priority (Optional) All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first. Default 0. +-- @return DCS#Task The DCS task structure. +function CONTROLLABLE:EnRouteTaskAntiShip(TargetTypes, Priority) + + local DCSTask = { + id = 'EngageTargets', + key = "AntiShip", + --auto = false, + --enabled = true, + params = { + targetTypes = TargetTypes or {"Ships"}, + priority = Priority or 0 + } + } + + return DCSTask +end + --- (AIR) Engaging a controllable. The task does not assign the target controllable to the unit/controllable to attack now; it just allows the unit/controllable to engage the target controllable as well as other assigned targets. -- @param #CONTROLLABLE self