diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 807f57f98..ea60abe46 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -3918,7 +3918,7 @@ end -- @param #string assignment A free to choose string specifying an assignment for the asset. This can be used with the @{#WAREHOUSE.OnAfterNewAsset} function. -- @param #table other (Optional) Table of other useful data. Can be collected via WAREHOUSE.OnAfterNewAsset() function for example function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribute, forcecargobay, forceweight, loadradius, skill, liveries, assignment, other) - self:T({group=group, ngroups=ngroups, forceattribute=forceattribute, forcecargobay=forcecargobay, forceweight=forceweight}) + --self:T({group=group:GetName(), ngroups=ngroups, forceattribute=forceattribute, forcecargobay=forcecargobay, forceweight=forceweight}) -- Set default. local n=ngroups or 1 @@ -6154,7 +6154,7 @@ function WAREHOUSE:_SpawnAssetAircraft(alias, asset, request, parking, uncontrol template.uncontrolled=uncontrolled -- Debug info. - self:T2({airtemplate=template}) + --self:T2({airtemplate=template}) -- Spawn group. local group=_DATABASE:Spawn(template) --Wrapper.Group#GROUP diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index e5c822ed3..9e21b02af 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -1571,7 +1571,7 @@ end -- @param Core.Zone#ZONE Zone The zone to return to. -- @param #number Formation Formation of the group. function ARMYGROUP:onafterRTZ(From, Event, To, Zone, Formation) - self:T2(self.lid.."onafterRTZ") + self:T(self.lid.."onafterRTZ") -- Zone. local zone=Zone or self.homezone diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index a425eacae..111543919 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -4440,7 +4440,7 @@ function AUFTRAG:Evaluate() local owndamage=self.Ncasualties/self.Nelements*100 -- Current number of mission targets. - local Ntargets=self:CountMissionTargets() + local Ntargets=self:CountMissionTargets(true) local Ntargets0=self:GetTargetInitialNumber() local Life=self:GetTargetLife() @@ -4891,16 +4891,25 @@ function AUFTRAG:CheckGroupsDone() self:T2(self.lid..string.format("CheckGroupsDone: Mission is still in state %s [FSM=%s] and reinfoce=%d. Mission NOT DONE!", self.status, self:GetState(), self.reinforce)) return false end + + local NopsgroupsAlive=self:CountOpsGroups() + local NopsgroupsDone=self:CountOpsGroupsInStatus(AUFTRAG.GroupStatus.DONE)+self:CountOpsGroupsInStatus(AUFTRAG.GroupStatus.CANCELLED) -- It could be that all groups were destroyed on the way to the mission execution waypoint. -- TODO: would be better to check if everybody is dead by now. - if self:IsStarted() and self:CountOpsGroups()==0 then + if self:IsStarted() and NopsgroupsAlive==0 then self:T(self.lid..string.format("CheckGroupsDone: Mission is STARTED state %s [FSM=%s] but count of alive OPSGROUP is zero. Mission DONE!", self.status, self:GetState())) return true end - if (self:IsStarted() or self:IsExecuting()) and (fsmState == AUFTRAG.Status.STARTED or fsmState == AUFTRAG.Status.EXECUTING) and self:CountOpsGroups()>0 then - self:T(self.lid..string.format("CheckGroupsDone: Mission is STARTED state %s [FSM=%s] and count of alive OPSGROUP > zero. Mission NOT DONE!", self.status, self:GetState())) + -- Every group alive is done or cancelled + if NopsgroupsAlive==NopsgroupsDone then + self:T(self.lid..string.format("CheckGroupsDone: Mission is in state %s [FSM=%s] but all groups [=%d] are done or cancelled. Mission DONE!", self.status, self:GetState(), NopsgroupsAlive)) + return true + end + + if (self:IsStarted() or self:IsExecuting()) and (fsmState == AUFTRAG.Status.STARTED or fsmState == AUFTRAG.Status.EXECUTING) and NopsgroupsAlive>0 then + self:T(self.lid..string.format("CheckGroupsDone: Mission is in state %s [FSM=%s] and count of alive OPSGROUP > zero. Mission NOT DONE!", self.status, self:GetState())) return false end @@ -5494,8 +5503,9 @@ end --- Count alive mission targets. -- @param #AUFTRAG self +-- @param #boolean OnlyReallyAlive (Optional) If `true`, count only really alive targets (units, groups) but not coordinates or zones. -- @return #number Number of alive target units. -function AUFTRAG:CountMissionTargets() +function AUFTRAG:CountMissionTargets(OnlyReallyAlive) local N=0 @@ -5503,7 +5513,7 @@ function AUFTRAG:CountMissionTargets() local Coalitions=self.coalition and UTILS.GetCoalitionEnemy(self.coalition, true) or nil if self.engageTarget then - N=self.engageTarget:CountTargets(Coalitions) + N=self.engageTarget:CountTargets(Coalitions, OnlyReallyAlive) end return N diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 8e3a3f10c..513ed07f0 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -1901,7 +1901,7 @@ function LEGION:_TacticalOverview() for _,mtype in pairs(AUFTRAG.Type) do local n=self:CountMissionsInQueue(mtype) if n>0 then - local N=self:CountMissionsInQueue(mtype) + local N=self:CountMissionsInQueue(mtype, true) text=text..string.format(" - %s: %d [Running=%d]\n", mtype, n, N) end end @@ -2057,18 +2057,23 @@ end --- Count missions in mission queue. -- @param #LEGION self -- @param #table MissionTypes Types on mission to be checked. Default *all* possible types `AUFTRAG.Type`. +-- @param #boolean OnlyRunning If `true`, only count running missions. -- @return #number Number of missions that are not over yet. -function LEGION:CountMissionsInQueue(MissionTypes) +function LEGION:CountMissionsInQueue(MissionTypes, OnlyRunning) MissionTypes=MissionTypes or AUFTRAG.Type local N=0 for _,_mission in pairs(self.missionqueue) do local mission=_mission --Ops.Auftrag#AUFTRAG + + if (not OnlyRunning) or (mission.statusLegion~=AUFTRAG.Status.PLANNED) then - -- Check if this mission type is requested. - if mission:IsNotOver() and AUFTRAG.CheckMissionType(mission.type, MissionTypes) then - N=N+1 + -- Check if this mission type is requested. + if mission:IsNotOver() and AUFTRAG.CheckMissionType(mission.type, MissionTypes) then + N=N+1 + end + end end diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 24fc98f2d..ab20523d1 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -5718,7 +5718,7 @@ end function OPSGROUP:onafterMissionDone(From, Event, To, Mission) -- Debug info. - local text=string.format("Mission %s DONE!", Mission.name) + local text=string.format("Mission DONE %s!", Mission.name) self:T(self.lid..text) -- Set group status. @@ -6231,11 +6231,12 @@ function OPSGROUP:RouteToMission(mission, delay) self:T(self.lid.."Already in mission zone ==> TaskExecute()") self:TaskExecute(waypointtask) -- TODO: Calling PassingWaypoint here is probably better as it marks the mission waypoint as passed! - --self:PassingWaypoint(waypoint) + self:PassingWaypoint(waypoint) return elseif d<25 then self:T(self.lid.."Already within 25 meters of mission waypoint ==> TaskExecute()") self:TaskExecute(waypointtask) + self:PassingWaypoint(waypoint) return end @@ -7850,7 +7851,7 @@ function OPSGROUP:_Spawn(Delay, Template) self:ScheduleOnce(Delay, OPSGROUP._Spawn, self, 0, Template) else -- Debug output. - self:T2({Template=Template}) + --self:T2({Template=Template}) if self:IsArmygroup() and self.ValidateAndRepositionGroundUnits then UTILS.ValidateAndRepositionGroundUnits(Template.units) diff --git a/Moose Development/Moose/Ops/Target.lua b/Moose Development/Moose/Ops/Target.lua index 4863f5202..5a3b75464 100644 --- a/Moose Development/Moose/Ops/Target.lua +++ b/Moose Development/Moose/Ops/Target.lua @@ -2006,9 +2006,10 @@ end --- Count alive objects. -- @param #TARGET self -- @param #TARGET.Object Target Target objective. --- @param #table Coalitions (Optional) Only count targets of the given coalition(s). +-- @param #table Coalitions (Optional) Only count targets of the given coalition(s). +-- @param #boolean OnlyReallyAlive (Optional) If `true`, count only really alive targets (units, groups) but not coordinates or zones. -- @return #number Number of alive target objects. -function TARGET:CountObjectives(Target, Coalitions) +function TARGET:CountObjectives(Target, Coalitions, OnlyReallyAlive) local N=0 @@ -2067,13 +2068,17 @@ function TARGET:CountObjectives(Target, Coalitions) -- No target, where we can check the alive status, so we assume it is alive. Changed this because otherwise target count is 0 if we pass a coordinate. -- This is also more consitent with the life and is alive status. - N=N+1 + if not OnlyReallyAlive then + N=N+1 + end elseif Target.Type==TARGET.ObjectType.ZONE then -- No target, where we can check the alive status, so we assume it is alive. Changed this because otherwise target count is 0 if we pass a coordinate. -- This is also more consitent with the life and is alive status. - N=N+1 + if not OnlyReallyAlive then + N=N+1 + end elseif Target.Type==TARGET.ObjectType.OPSZONE then @@ -2093,15 +2098,16 @@ end --- Count alive targets. -- @param #TARGET self -- @param #table Coalitions (Optional) Only count targets of the given coalition(s). +-- @param #boolean OnlyReallyAlive (Optional) If `true`, count only really alive targets (units, groups) but not coordinates or zones. -- @return #number Number of alive target objects. -function TARGET:CountTargets(Coalitions) +function TARGET:CountTargets(Coalitions, OnlyReallyAlive) local N=0 for _,_target in pairs(self.targets) do local Target=_target --#TARGET.Object - N=N+self:CountObjectives(Target, Coalitions) + N=N+self:CountObjectives(Target, Coalitions, OnlyReallyAlive) end