From 835041e5f6e225eef4ffc66d19bf86f3f842016e Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 14 Jul 2021 21:00:34 +0200 Subject: [PATCH] OPS --- Moose Development/Moose/Ops/ArmyGroup.lua | 25 ++-- Moose Development/Moose/Ops/FlightGroup.lua | 79 ++++------ Moose Development/Moose/Ops/NavyGroup.lua | 21 +-- Moose Development/Moose/Ops/OpsGroup.lua | 149 +++++++++++++------ Moose Development/Moose/Ops/OpsTransport.lua | 37 +++-- Moose Development/Moose/Wrapper/Group.lua | 10 +- 6 files changed, 190 insertions(+), 131 deletions(-) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index 301cd48f1..9506a270b 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -345,10 +345,10 @@ end function ARMYGROUP:onbeforeStatus(From, Event, To) if self:IsDead() then - self:I(self.lid..string.format("Onbefore Status DEAD ==> false")) + self:T(self.lid..string.format("Onbefore Status DEAD ==> false")) return false elseif self:IsStopped() then - self:I(self.lid..string.format("Onbefore Status STOPPED ==> false")) + self:T(self.lid..string.format("Onbefore Status STOPPED ==> false")) return false end @@ -567,16 +567,19 @@ function ARMYGROUP:onafterSpawned(From, Event, To) if not self.option.Formation then self.option.Formation=self.optionDefault.Formation end + + -- Update route. + if #self.waypoints>1 then + self:Cruise(nil, self.option.Formation or self.optionDefault.Formation) + else + self:FullStop() + end + + -- Update status. + self:__Status(-0.1) end - -- Update route. - if #self.waypoints>1 then - self:Cruise(nil, self.option.Formation or self.optionDefault.Formation) - else - self:FullStop() - end - end --- On before "UpdateRoute" event. @@ -1117,7 +1120,7 @@ function ARMYGROUP:_InitGroup() -- First check if group was already initialized. if self.groupinitialized then - self:E(self.lid.."WARNING: Group was already initialized!") + self:T(self.lid.."WARNING: Group was already initialized! Will NOT do it again!") return end @@ -1177,7 +1180,7 @@ function ARMYGROUP:_InitGroup() self.actype=units[1]:GetTypeName() -- Debug info. - if self.verbose>=0 then + if self.verbose>=1 then local text=string.format("Initialized Army Group %s:\n", self.groupname) text=text..string.format("Unit type = %s\n", self.actype) text=text..string.format("Speed max = %.1f Knots\n", UTILS.KmphToKnots(self.speedMax)) diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 19d6d061d..5b15572ee 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -2191,7 +2191,7 @@ function FLIGHTGROUP:_CheckGroupDone(delay, waittime) end -- Group is waiting. - if self.Twaiting then + if self:IsWaiting() then self:T(self.lid.."Waiting! Group NOT done...") return end @@ -2531,37 +2531,31 @@ end -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. --- @param Core.Point#COORDINATE Coord Coordinate where to orbit. Default current position. --- @param #number Altitude Altitude in feet. Default 10000 ft. --- @param #number Speed Speed in knots. Default 250 kts. -function FLIGHTGROUP:onbeforeWait(From, Event, To, Coord, Altitude, Speed) +-- @param #number Duration Duration how long the group will be waiting in seconds. Default `nil` (=forever). +-- @param #number Altitude Altitude in feet. Default 10,000 ft for airplanes and 1,000 feet for helos. +-- @param #number Speed Speed in knots. Default 250 kts for airplanes and 20 kts for helos. +function FLIGHTGROUP:onbeforeWait(From, Event, To, Duration, Altitude, Speed) local allowed=true local Tsuspend=nil - -- Check if there are remaining tasks. - local Ntot,Nsched, Nwp=self:CountRemainingTasks() - + -- Check for a current task. if self.taskcurrent>0 then - self:I(self.lid..string.format("WARNING: Got current task ==> WAIT event is suspended for 10 sec.")) - Tsuspend=-10 + self:I(self.lid..string.format("WARNING: Got current task ==> WAIT event is suspended for 30 sec!")) + Tsuspend=-30 allowed=false end - - if Nsched>0 then - --self:I(self.lid..string.format("WARNING: Still got %d SCHEDULED tasks in the queue ==> WAIT event is suspended for 10 sec.", Nsched)) - --Tsuspend=-10 - --allowed=false - end - - if Nwp>0 then - --self:I(self.lid..string.format("WARNING: Still got %d WAYPOINT tasks in the queue ==> WAIT event is suspended for 10 sec.", Nwp)) - --Tsuspend=-10 - --allowed=false + + -- Check for a current transport assignment. + if self.cargoTransport then + self:I(self.lid..string.format("WARNING: Got current TRANSPORT assignment ==> WAIT event is suspended for 30 sec!")) + Tsuspend=-30 + allowed=false end + -- Call wait again. if Tsuspend and not allowed then - self:__Wait(Tsuspend, Coord, Altitude, Speed) + self:__Wait(Tsuspend, Duration, Altitude, Speed) end return allowed @@ -2574,14 +2568,18 @@ end -- @param #string Event Event. -- @param #string To To state. -- @param #number Duration Duration how long the group will be waiting in seconds. Default `nil` (=forever). --- @param Core.Point#COORDINATE Coord Coordinate where to orbit. Default current position. --- @param #number Altitude Altitude in feet. Default 10000 ft. --- @param #number Speed Speed in knots. Default 250 kts. -function FLIGHTGROUP:onafterWait(From, Event, To, Duration, Coord, Altitude, Speed) +-- @param #number Altitude Altitude in feet. Default 10,000 ft for airplanes and 1,000 feet for helos. +-- @param #number Speed Speed in knots. Default 250 kts for airplanes and 20 kts for helos. +function FLIGHTGROUP:onafterWait(From, Event, To, Duration, Altitude, Speed) - Coord=Coord or self.group:GetCoordinate() + -- Group will orbit at its current position. + local Coord=self.group:GetCoordinate() + + -- Set altitude: 1000 ft for helos and 10,000 ft for panes. Altitude=Altitude or (self.isHelo and 1000 or 10000) - Speed=Speed or (self.isHelo and 80 or 250) + + -- Set speed. + Speed=Speed or (self.isHelo and 20 or 250) -- Debug message. local text=string.format("Flight group set to wait/orbit at altitude %d m and speed %.1f km/h", Altitude, Speed) @@ -3009,7 +3007,7 @@ function FLIGHTGROUP:_InitGroup() -- First check if group was already initialized. if self.groupinitialized then - self:E(self.lid.."WARNING: Group was already initialized!") + self:T(self.lid.."WARNING: Group was already initialized! Will NOT do it again!") return end @@ -3106,7 +3104,7 @@ function FLIGHTGROUP:_InitGroup() self.refueltype=select(2, unit:IsRefuelable()) -- Debug info. - if self.verbose>=0 then + if self.verbose>=1 then local text=string.format("Initialized Flight Group %s:\n", self.groupname) text=text..string.format("Unit type = %s\n", self.actype) text=text..string.format("Speed max = %.1f Knots\n", UTILS.KmphToKnots(self.speedMax)) @@ -3606,27 +3604,6 @@ function FLIGHTGROUP:AddWaypointLanding(Airbase, Speed, AfterWaypointWithID, Alt end - ---- Check if a unit is an element of the flightgroup. --- @param #FLIGHTGROUP self --- @param #string unitname Name of unit. --- @return #boolean If true, unit is element of the flight group or false if otherwise. -function FLIGHTGROUP:_IsElement(unitname) - - for _,_element in pairs(self.elements) do - local element=_element --Ops.OpsGroup#OPSGROUP.Element - - if element.name==unitname then - return true - end - - end - - return false -end - - - --- Set parking spot of element. -- @param #FLIGHTGROUP self -- @param Ops.OpsGroup#OPSGROUP.Element Element The element. diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index 5284cec36..204792dcf 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -693,16 +693,19 @@ function NAVYGROUP:onafterSpawned(From, Event, To) else self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, false) end + + -- Update route. + if #self.waypoints>1 then + self:Cruise() + else + self:FullStop() + end + + -- Update status. + self:__Status(-0.1) end - -- Update route. - if #self.waypoints>1 then - self:Cruise() - else - self:FullStop() - end - end --- On before "UpdateRoute" event. @@ -1132,7 +1135,7 @@ function NAVYGROUP:_InitGroup() -- First check if group was already initialized. if self.groupinitialized then - self:E(self.lid.."WARNING: Group was already initialized!") + self:T(self.lid.."WARNING: Group was already initialized! Will NOT do it again!") return end @@ -1197,7 +1200,7 @@ function NAVYGROUP:_InitGroup() self.actype=units[1]:GetTypeName() -- Debug info. - if self.verbose>=0 then + if self.verbose>=1 then local text=string.format("Initialized Navy Group %s:\n", self.groupname) text=text..string.format("Unit type = %s\n", self.actype) text=text..string.format("Speed max = %.1f Knots\n", UTILS.KmphToKnots(self.speedMax)) diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 0d686919d..69b5c1d01 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -373,6 +373,7 @@ OPSGROUP.TaskType={ -- @field #number MissilesAS Amount of anti-ship missiles. -- @field #number MissilesCR Amount of cruise missiles. -- @field #number MissilesBM Amount of ballistic missiles. +-- @field #number MissilesSA Amount of surfe-to-air missiles. --- Waypoint data. -- @type OPSGROUP.Waypoint @@ -1695,6 +1696,12 @@ end -- @return #boolean If true, the group exists or false if the group does not exist. If nil, the DCS group could not be found. function OPSGROUP:IsActive() + if self.group then + local active=self.group:IsActive() + return active + end + + return nil end --- Check if group is alive. @@ -1737,7 +1744,6 @@ end -- @param #OPSGROUP self -- @return #boolean If true, all units/elements of the group are dead. function OPSGROUP:IsDead() - --env.info("FF IsDead") if self.isDead then return true else @@ -1806,6 +1812,16 @@ function OPSGROUP:IsEngaging() return is end +--- Check if group is currently waiting. +-- @param #OPSGROUP self +-- @return #boolean If true, group is currently waiting. +function OPSGROUP:IsWaiting() + if self.Twaiting then + return true + end + return false +end + --- Check if the group is not a carrier yet. -- @param #OPSGROUP self -- @return #boolean If true, group is not a carrier. @@ -1902,14 +1918,6 @@ function OPSGROUP:IsLoaded(CarrierGroupName) return self.cargoStatus==OPSGROUP.CargoStatus.LOADED end ---- Check if the group is cargo and waiting for a carrier to pick it up. --- @param #OPSGROUP self --- @return #boolean If true, group is waiting for a carrier. -function OPSGROUP:IsWaitingAsCargo() - return self.cargoStatus==OPSGROUP.CargoStatus.WAITING -end - - ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Waypoint Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -3872,14 +3880,37 @@ end -- FSM Events ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- Check if group is currently waiting. --- @param #OPSGROUP self --- @param #boolean If true, group is currently waiting. -function OPSGROUP:IsWaiting() - if self.Twaiting then - return true +--- On before "Wait" event. +-- @param #FLIGHTGROUP self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param #number Duration Duration how long the group will be waiting in seconds. Default `nil` (=forever). +function OPSGROUP:onbeforeWait(From, Event, To, Duration) + + local allowed=true + local Tsuspend=nil + + -- Check for a current task. + if self.taskcurrent>0 then + self:I(self.lid..string.format("WARNING: Got current task ==> WAIT event is suspended for 30 sec!")) + Tsuspend=-30 + allowed=false end - return false + + -- Check for a current transport assignment. + if self.cargoTransport then + self:I(self.lid..string.format("WARNING: Got current TRANSPORT assignment ==> WAIT event is suspended for 30 sec!")) + Tsuspend=-30 + allowed=false + end + + -- Call wait again. + if Tsuspend and not allowed then + self:__Wait(Tsuspend, Duration) + end + + return allowed end --- On after "Wait" event. @@ -3991,7 +4022,6 @@ function OPSGROUP:_SetWaypointTasks(Waypoint) -- Check if there is mission task if missiontask then - env.info("FF executing mission task") self:TaskExecute(missiontask) return 1 end @@ -4038,7 +4068,7 @@ function OPSGROUP:onafterGotoWaypoint(From, Event, To, UID) if n then - -- TODO: switch to re-enable waypoint tasks. + -- TODO: Switch to re-enable waypoint tasks? if false then local tasks=self:GetTasksWaypoint(n) @@ -4213,7 +4243,7 @@ function OPSGROUP:onbeforeLaserOn(From, Event, To, Target) self:LaserGotLOS() else -- Try to switch laser on again in 10 sec. - self:I(self.lid.."LASER got no LOS currently. Trying to switch the laser on again in 10 sec") + self:T(self.lid.."LASER got no LOS currently. Trying to switch the laser on again in 10 sec") self:__LaserOn(-10, Target) return false end @@ -4697,7 +4727,6 @@ function OPSGROUP:onafterElementDead(From, Event, To, Element) -- Clear cargo bay of element. - --for _,_cargo in pairs(Element.cargoBay) do for i=#Element.cargoBay,1,-1 do local cargo=Element.cargoBay[i] --#OPSGROUP.MyCargo @@ -4809,6 +4838,13 @@ function OPSGROUP:_Respawn(Delay, Template, Reset) -- Group is DESPAWNED --- + -- Ensure elements in utero. + for _,_element in pairs(self.elements) do + local element=_element --#OPSGROUP.Element + self:ElementInUtero(element) + end + + --[[ -- Loop over template units. @@ -4845,7 +4881,10 @@ function OPSGROUP:_Respawn(Delay, Template, Reset) -- Not dead or destroyed any more. self.isDead=false self.isDestroyed=false - self.Ndestroyed=0 + self.Ndestroyed=0 + + self:InitWaypoints() + self:_InitGroup() -- Reset events. --self:ResetEvents() @@ -4919,10 +4958,17 @@ function OPSGROUP:onafterDead(From, Event, To) for i,_transport in pairs(self.cargoqueue) do local transport=_transport --Ops.OpsTransport#OPSTRANSPORT transport:__DeadCarrierGroup(1, self) - end + end + + -- Cargo queue empty + self.cargoqueue={} + + -- No current cargo transport. + self.cargoTransport=nil + -- Stop in a sec. - self:__Stop(-5) + --self:__Stop(-5) end --- On before "Stop" event. @@ -5343,6 +5389,7 @@ function OPSGROUP:_CheckDelivered(CargoTransport) elseif cargo.opsgroup==nil or cargo.opsgroup:IsDead() or cargo.opsgroup:IsStopped() then -- This one is dead. else + --env.info(string.format()) done=false --Someone is not done! end @@ -5378,14 +5425,14 @@ end -- @param #OPSGROUP self -- @param Ops.OpsTransport#OPSTRANSPORT CargoTransport Cargo transport do be deleted. -- @return #OPSGROUP self -function OPSGROUP:DelCargoTransport(CargoTransport) - - for i,_transport in pairs(self.cargoqueue) do - local transport=_transport --Ops.OpsTransport#OPSTRANSPORT +function OPSGROUP:DelOpsTransport(CargoTransport) + + for i=#self.cargoqueue,1,-1 do + local transport=self.cargoqueue[i] --Ops.OpsTransport#OPSTRANSPORT if transport.uid==CargoTransport.uid then table.remove(self.cargoqueue, i) return self - end + end end return self @@ -5574,7 +5621,7 @@ function OPSGROUP:AddWeightCargo(UnitName, Weight) local element=self:GetElementByName(UnitName) - if element and element.unit and element.unit:IsAlive() then + if element then --we do not check if the element is actually alive because we need to remove cargo from dead units -- Add weight. element.weightCargo=element.weightCargo+Weight @@ -5767,7 +5814,7 @@ function OPSGROUP:onafterPickup(From, Event, To) -- We are already in the pickup zone ==> wait and initiate loading. if (self:IsArmygroup() or self:IsNavygroup()) and not self:IsHolding() then - self:Wait() + self:FullStop() end -- Start loading. @@ -5992,7 +6039,7 @@ end function OPSGROUP:_TransferCargo(CargoGroup, CarrierGroup, CarrierElement) -- Debug info. - self:I(self.lid..string.format("Transferring cargo %s to new carrier group %s", CargoGroup:GetName(), CarrierGroup:GetName())) + self:T(self.lid..string.format("Transferring cargo %s to new carrier group %s", CargoGroup:GetName(), CarrierGroup:GetName())) -- Unload from this and directly load into the other carrier. self:Unload(CargoGroup) @@ -6136,7 +6183,7 @@ function OPSGROUP:onafterTransport(From, Event, To) -- We are already in the pickup zone ==> wait and initiate unloading. if (self:IsArmygroup() or self:IsNavygroup()) and not self:IsHolding() then - self:Wait() + self:FullStop() end -- Start loading. @@ -6440,10 +6487,12 @@ function OPSGROUP:onafterUnload(From, Event, To, OpsGroup, Coordinate, Activated -- Add current waypoint. These have been cleard on loading. if OpsGroup:IsNavygroup() then + OpsGroup:ClearWaypoints() OpsGroup.currentwp=1 OpsGroup.passedfinalwp=true NAVYGROUP.AddWaypoint(OpsGroup, Coordinate, nil, nil, nil, false) elseif OpsGroup:IsArmygroup() then + OpsGroup:ClearWaypoints() OpsGroup.currentwp=1 OpsGroup.passedfinalwp=true ARMYGROUP.AddWaypoint(OpsGroup, Coordinate, nil, nil, nil, false) @@ -6555,7 +6604,7 @@ function OPSGROUP:onafterDelivered(From, Event, To, CargoTransport) end -- Remove cargo transport from cargo queue. - self:DelCargoTransport(CargoTransport) + self:DelOpsTransport(CargoTransport) end @@ -6860,8 +6909,6 @@ function OPSGROUP:_CheckGroupDone(delay) -- Get current waypoint. local waypoint=self:GetWaypoint(self.currentwp) - --env.info("FF CheckGroupDone") - if waypoint then -- Number of tasks remaining for this waypoint. @@ -7437,7 +7484,7 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid) else -- Wait and load cargo. - opsgroup:Wait() + opsgroup:FullStop() opsgroup:__Loading(-5) end @@ -7450,7 +7497,7 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid) else -- Stop and unload. - opsgroup:Wait() + opsgroup:FullStop() opsgroup:Unloading() end @@ -8521,7 +8568,7 @@ function OPSGROUP:_UpdateStatus(element, newstatus, airbase) --- if self:_AllSimilarStatus(newstatus) then - self:__Dead(-1) + self:Dead() end end @@ -8678,8 +8725,6 @@ function OPSGROUP:_GetElementZoneLoader(Element, Zone, Loader) -- Heading in deg. local heading=math.deg(math.atan2(X.z, X.x)) - --env.info(string.format("FF l=%d w=%d h=%d", l, w, heading)) - -- Bounding box at the origin of the map facing "North". local b={} @@ -9035,6 +9080,24 @@ function OPSGROUP:_CoordinateFromObject(Object) return nil end +--- Check if a unit is an element of the flightgroup. +-- @param #OPSGROUP self +-- @param #string unitname Name of unit. +-- @return #boolean If true, unit is element of the flight group or false if otherwise. +function OPSGROUP:_IsElement(unitname) + + for _,_element in pairs(self.elements) do + local element=_element --Ops.OpsGroup#OPSGROUP.Element + + if element.name==unitname then + return true + end + + end + + return false +end + --- Add a unit/element to the OPS group. -- @param #OPSGROUP self -- @param #string unitname Name of unit. @@ -9095,7 +9158,7 @@ function OPSGROUP:_AddElementByName(unitname) element.weight=element.weightEmpty+element.weightCargo -- Looks like only aircraft have a massMax value in the descriptors. - element.weightMaxTotal=element.descriptors.massMax or element.weightEmpty+2*95 --If max mass is not given, we assume 10 soldiers. + element.weightMaxTotal=element.descriptors.massMax or element.weightEmpty+8*95 --If max mass is not given, we assume 8 soldiers. if self.isArmygroup then @@ -9141,7 +9204,9 @@ function OPSGROUP:_AddElementByName(unitname) self:T(self.lid..text) -- Add element to table. - table.insert(self.elements, element) + if not self:_IsElement(unitname) then + table.insert(self.elements, element) + end -- Trigger spawned event if alive. if unit:IsAlive() then diff --git a/Moose Development/Moose/Ops/OpsTransport.lua b/Moose Development/Moose/Ops/OpsTransport.lua index bea743fe7..61bd09885 100644 --- a/Moose Development/Moose/Ops/OpsTransport.lua +++ b/Moose Development/Moose/Ops/OpsTransport.lua @@ -208,8 +208,8 @@ function OPSTRANSPORT:New(GroupSet, Pickupzone, Deployzone) -- PLANNED --> SCHEDULED --> EXECUTING --> DELIVERED self:AddTransition("*", "Planned", OPSTRANSPORT.Status.PLANNED) -- Cargo transport was planned. self:AddTransition(OPSTRANSPORT.Status.PLANNED, "Scheduled", OPSTRANSPORT.Status.SCHEDULED) -- Cargo is queued at at least one carrier. - self:AddTransition(OPSTRANSPORT.Status.SCHEDULED, "Executing", OPSTRANSPORT.Status.EXECUTING) -- Cargo is being transported. - self:AddTransition(OPSTRANSPORT.Status.EXECUTING, "Delivered", OPSTRANSPORT.Status.DELIVERED) -- Cargo was delivered. + self:AddTransition(OPSTRANSPORT.Status.SCHEDULED, "Executing", OPSTRANSPORT.Status.EXECUTING) -- Cargo is being transported. + self:AddTransition("*", "Delivered", OPSTRANSPORT.Status.DELIVERED) -- Cargo was delivered. self:AddTransition("*", "Status", "*") self:AddTransition("*", "Stop", "*") @@ -885,7 +885,7 @@ end -- @param #string Event Event. -- @param #string To To state. function OPSTRANSPORT:onafterPlanned(From, Event, To) - self:I(self.lid..string.format("New status %s", OPSTRANSPORT.Status.PLANNED)) + self:T(self.lid..string.format("New status: %s-->%s", From, To)) end --- On after "Scheduled" event. @@ -894,7 +894,7 @@ end -- @param #string Event Event. -- @param #string To To state. function OPSTRANSPORT:onafterScheduled(From, Event, To) - self:I(self.lid..string.format("New status %s", OPSTRANSPORT.Status.SCHEDULED)) + self:T(self.lid..string.format("New status: %s-->%s", From, To)) end --- On after "Executing" event. @@ -903,7 +903,22 @@ end -- @param #string Event Event. -- @param #string To To state. function OPSTRANSPORT:onafterExecuting(From, Event, To) - self:I(self.lid..string.format("New status %s", OPSTRANSPORT.Status.EXECUTING)) + self:T(self.lid..string.format("New status: %s-->%s", From, To)) +end + +--- On before "Delivered" event. +-- @param #OPSTRANSPORT self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +function OPSTRANSPORT:onbeforeDelivered(From, Event, To) + + -- Check that we do not call delivered again. + if From==OPSTRANSPORT.Status.DELIVERED then + return false + end + + return true end --- On after "Delivered" event. @@ -912,7 +927,7 @@ end -- @param #string Event Event. -- @param #string To To state. function OPSTRANSPORT:onafterDelivered(From, Event, To) - self:I(self.lid..string.format("New status %s", OPSTRANSPORT.Status.DELIVERED)) + self:T(self.lid..string.format("New status: %s-->%s", From, To)) -- Inform all assigned carriers that cargo was delivered. They can have this in the queue or are currently processing this transport. for _,_carrier in pairs(self.carriers) do @@ -941,7 +956,7 @@ end -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. --- @param Ops.OpsGroup#OPSGROUP OpsGroupCargo OPSGROUP that was unloaded from a carrier. +-- @param Ops.OpsGroup#OPSGROUP OpsGroupCargo Cargo OPSGROUP that was unloaded from a carrier. -- @param Ops.OpsGroup#OPSGROUP OpsGroupCarrier Carrier OPSGROUP that unloaded the cargo. function OPSTRANSPORT:onafterUnloaded(From, Event, To, OpsGroupCargo, OpsGroupCarrier) self:I(self.lid..string.format("Unloaded OPSGROUP %s", OpsGroupCargo:GetName())) @@ -966,6 +981,7 @@ end -- @param #string To To state. function OPSTRANSPORT:onafterDeadCarrierAll(From, Event, To) self:I(self.lid..string.format("ALL Carrier OPSGROUPs are dead! Setting stage to PLANNED if not all cargo was delivered.")) + self:_CheckDelivered() if not self:IsDelivered() then self:Planned() end @@ -997,7 +1013,6 @@ function OPSTRANSPORT:_CheckDelivered() -- This one was destroyed. elseif cargo.opsgroup:IsDead() then -- This one is dead. - dead=false elseif cargo.opsgroup:IsStopped() then -- This one is stopped. dead=false @@ -1089,7 +1104,7 @@ function OPSTRANSPORT:FindTransferCarrierForCargo(CargoGroup, Zone) local carrierGroup=_carrier --Ops.OpsGroup#OPSGROUP -- First check if carrier is alive and loading cargo. - if carrierGroup and carrierGroup:IsAlive() and carrierGroup:IsLoading() then + if carrierGroup and carrierGroup:IsAlive() and (carrierGroup:IsLoading() or self.deployzone:IsInstanceOf("ZONE_AIRBASE")) then -- Find an element of the group that has enough free space. carrier=carrierGroup:FindCarrierForCargo(CargoGroup) @@ -1098,10 +1113,10 @@ function OPSTRANSPORT:FindTransferCarrierForCargo(CargoGroup, Zone) if Zone==nil or Zone:IsCoordinateInZone(carrier.unit:GetCoordinate()) then return carrier, carrierGroup else - self:T3(self.lid.."Got transfer carrier but carrier not in zone (yet)!") + self:T2(self.lid.."Got transfer carrier but carrier not in zone (yet)!") end else - self:T3(self.lid.."No transfer carrier available!") + self:T2(self.lid.."No transfer carrier available!") end end diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index a9c678ab5..f844a8ad2 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -310,8 +310,7 @@ end --- Returns the @{DCS#Position3} position vectors indicating the point and direction vectors in 3D of the POSITIONABLE within the mission. -- @param Wrapper.Positionable#POSITIONABLE self --- @return DCS#Position The 3D position vectors of the POSITIONABLE. --- @return #nil The POSITIONABLE is not existing or alive. +-- @return DCS#Position The 3D position vectors of the POSITIONABLE or #nil if the groups not existing or alive. function GROUP:GetPositionVec3() -- Overridden from POSITIONABLE:GetPositionVec3() self:F2( self.PositionableName ) @@ -340,8 +339,7 @@ end -- -- @param #GROUP self -- @return #boolean true if the group is alive and active. --- @return #boolean false if the group is alive but inactive. --- @return #nil if the group does not exist anymore. +-- @return #boolean false if the group is alive but inactive or #nil if the group does not exist anymore. function GROUP:IsAlive() self:F2( self.GroupName ) @@ -363,8 +361,7 @@ end --- Returns if the group is activated. -- @param #GROUP self --- @return #boolean true if group is activated. --- @return #nil The group is not existing or alive. +-- @return #boolean true if group is activated or #nil The group is not existing or alive. function GROUP:IsActive() self:F2( self.GroupName ) @@ -412,7 +409,6 @@ function GROUP:Destroy( GenerateEvent, delay ) self:F2( self.GroupName ) if delay and delay>0 then - --SCHEDULER:New(nil, GROUP.Destroy, {self, GenerateEvent}, delay) self:ScheduleOnce(delay, GROUP.Destroy, self, GenerateEvent) else