From 67af073b9517904629abf700c3ce8e249ae3bcf7 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 30 Dec 2022 22:08:27 +0100 Subject: [PATCH] OPS Capture --- Moose Development/Moose/Core/Set.lua | 43 ++++++++++---------- Moose Development/Moose/Ops/ArmyGroup.lua | 27 +++++-------- Moose Development/Moose/Ops/Auftrag.lua | 7 ++-- Moose Development/Moose/Ops/Legion.lua | 2 +- Moose Development/Moose/Ops/OpsGroup.lua | 48 ++++++++++++++++------- Moose Development/Moose/Ops/OpsZone.lua | 22 +++++++++-- Moose Development/Moose/Ops/Target.lua | 2 +- 7 files changed, 91 insertions(+), 60 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 014e5cda1..a4a3384cb 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -1935,7 +1935,7 @@ do -- SET_GROUP for GroupID, GroupData in pairs( Set ) do -- For each GROUP in SET_GROUP local group=GroupData --Wrapper.Group#GROUP - if Coalitions==nil or UTILS.IsAnyInTable(Coalitions, group:GetCoalition()) then + if group and group:IsAlive() and (Coalitions==nil or UTILS.IsAnyInTable(Coalitions, group:GetCoalition())) then local coord=group:GetCoord() @@ -6255,18 +6255,18 @@ do -- SET_OPSZONE --- Add an OPSZONE to set. -- @param Core.Set#SET_OPSZONE self -- @param Ops.OpsZone#OPSZONE Zone The OPSZONE object. - -- @return self + -- @return #SET_OPSZONE self function SET_OPSZONE:AddZone( Zone ) self:Add( Zone:GetName(), Zone ) return self - end + end --- Remove ZONEs from SET_OPSZONE. -- @param Core.Set#SET_OPSZONE self -- @param #table RemoveZoneNames A single name or an array of OPSZONE names. - -- @return self + -- @return #SET_OPSZONE self function SET_OPSZONE:RemoveZonesByName( RemoveZoneNames ) local RemoveZoneNamesArray = (type( RemoveZoneNames ) == "table") and RemoveZoneNames or { RemoveZoneNames } @@ -6570,6 +6570,21 @@ do -- SET_OPSZONE end end end + + --- Start all opszones of the set. + -- @param #SET_OPSZONE self + -- @return #SET_OPSZONE self + function SET_OPSZONE:Start() + + for _,_Zone in pairs( self:GetSet() ) do + local Zone = _Zone --Ops.OpsZone#OPSZONE + if Zone:IsStopped() then + Zone:Start() + end + end + + return self + end --- Validate if a coordinate is in one of the zones in the set. -- Returns the ZONE object where the coordiante is located. @@ -6591,16 +6606,14 @@ do -- SET_OPSZONE end - --- Get the closest OPSZONE from a given reference coordinate. + --- Get the closest OPSZONE from a given reference coordinate. Only started zones are considered. -- @param #SET_OPSZONE self -- @param Core.Point#COORDINATE Coordinate The reference coordinate from which the closest zone is determined. -- @param #table Coalitions Only consider the given coalition(s), *e.g.* `{coaliton.side.RED}` to find the closest red zone. -- @return Ops.OpsZone#OPSZONE The closest OPSZONE (if any). -- @return #number Distance to ref coordinate in meters. function SET_OPSZONE:GetClosestZone( Coordinate, Coalitions ) - - env.info("FF 100",showMessageBox) - + Coalitions=UTILS.EnsureTable(Coalitions, true) local dmin=math.huge --#number @@ -6611,22 +6624,12 @@ do -- SET_OPSZONE local coal=opszone:GetOwner() - env.info("FF 200",showMessageBox) - - env.info("In table="..tostring(UTILS.IsInTable(Coalitions, coal))) - BASE:I(Coalitions) - BASE:I(coal) - - if Coalitions==nil or (Coalitions and UTILS.IsInTable(Coalitions, coal)) then - - env.info("FF 300",showMessageBox) + if opszone:IsStarted() and (Coalitions==nil or (Coalitions and UTILS.IsInTable(Coalitions, coal))) then -- Get 2D distance. local d=opszone:GetZone():Get2DDistance(Coordinate) - if d Find next zone or call it a day! + -- Debug info. self:T(self.lid..string.format("Zone %s captured ==> Task DONE!", zoneCurr:GetName())) + -- Task done. self:TaskDone(Task) else -- Current zone NOT captured yet ==> Find Target + -- Debug info. + self:T(self.lid..string.format("Zone %s NOT captured!", zoneCurr:GetName())) + if Mission:GetGroupStatus(self)==AUFTRAG.GroupStatus.EXECUTING then + + -- Debug info. + self:T(self.lid..string.format("Zone %s NOT captured and EXECUTING ==> Find target", zoneCurr:GetName())) + -- Get closest target. local targetgroup=zoneCurr:GetScannedGroupSet():GetClosestGroup(self.coordinate, Coalitions) if targetgroup then + -- Debug info. + self:T(self.lid..string.format("Zone %s NOT captured: engaging target %s", zoneCurr:GetName(), targetgroup:GetName())) + + -- Engage target group. self:EngageTarget(targetgroup) else @@ -4428,10 +4442,11 @@ function OPSGROUP:_UpdateTask(Task, Mission) self:E(self.lid..string.format("ERROR: Current zone not captured but no target group could be found. This should NOT happen!")) end - end - - end - + else + self:T(self.lid..string.format("Zone %s NOT captured and NOT EXECUTING", zoneCurr:GetName())) + end + + end else self:T(self.lid..string.format("NO Current target zone=%s")) @@ -4727,11 +4742,14 @@ function OPSGROUP:onafterTaskDone(From, Event, To, Task) if Mission.type==AUFTRAG.Type.CAPTUREZONE and Mission:CountMissionTargets()>0 then - env.info("FF task done route to mission 1000") - self:RouteToMission(Mission) - - return + -- Remove mission waypoints. + self:T(self.lid.."Remove mission waypoints") + self:_RemoveMissionWaypoints(Mission, false) + self:T(self.lid.."Task done ==> Route to mission for next opszone") + self:MissionStart(Mission) + + return end -- Get egress waypoint uid. diff --git a/Moose Development/Moose/Ops/OpsZone.lua b/Moose Development/Moose/Ops/OpsZone.lua index 5fdb8edf8..6a4749248 100644 --- a/Moose Development/Moose/Ops/OpsZone.lua +++ b/Moose Development/Moose/Ops/OpsZone.lua @@ -86,16 +86,16 @@ OPSZONE = { --- OPSZONE class version. -- @field #string version -OPSZONE.version="0.3.2" +OPSZONE.version="0.4.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- ToDo list ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- TODO: Capturing based on (total) threat level threshold. Unarmed units do not pose a threat and should not be able to hold a zone. -- TODO: Pause/unpause evaluations. --- TODO: Capture time, i.e. time how long a single coalition has to be inside the zone to capture it. -- TODO: Differentiate between ground attack and boming by air or arty. +-- DONE: Capture time, i.e. time how long a single coalition has to be inside the zone to capture it. +-- DONE: Capturing based on (total) threat level threshold. Unarmed units do not pose a threat and should not be able to hold a zone. -- DONE: Can neutrals capture? No, since they are _neutral_! -- DONE: Capture airbases. -- DONE: Can statics capture or hold a zone? No, unless explicitly requested by mission designer. @@ -613,6 +613,22 @@ function OPSZONE:IsCoalition(Coalition) return is end +--- Check if zone is started (not stopped). +-- @param #OPSZONE self +-- @return #boolean If `true`, zone is started. +function OPSZONE:IsStarted() + local is=not self:IsStopped() + return is +end + +--- Check if zone is stopped. +-- @param #OPSZONE self +-- @return #boolean If `true`, zone is stopped. +function OPSZONE:IsStopped() + local is=self:is("Stopped") + return is +end + --- Check if zone is guarded. -- @param #OPSZONE self -- @return #boolean If `true`, zone is guarded. diff --git a/Moose Development/Moose/Ops/Target.lua b/Moose Development/Moose/Ops/Target.lua index e9c77e08b..7eb7eb5be 100644 --- a/Moose Development/Moose/Ops/Target.lua +++ b/Moose Development/Moose/Ops/Target.lua @@ -153,7 +153,7 @@ _TARGETID=0 --- TARGET class version. -- @field #string version -TARGET.version="0.5.6" +TARGET.version="0.6.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list