diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 6a76b5349..42e8d61cb 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -4220,7 +4220,7 @@ function WAREHOUSE:_AssetItemInfo(asset) text=text..string.format("Cargo bay max = %5.2f kg\n", asset.cargobaymax) text=text..string.format("Load radius = %s m\n", tostring(asset.loadradius)) text=text..string.format("Skill = %s\n", tostring(asset.skill)) - text=text..string.format("Livery = %s", tostring(asset.livery)) + text=text..string.format("Livery = %s", tostring(asset.livery)) self:I(self.lid..text) self:T({DCSdesc=asset.DCSdesc}) self:T3({Template=asset.template}) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index 8e330e9f8..98d2992a2 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -896,10 +896,13 @@ function ARMYGROUP:onafterSpawned(From, Event, To) -- Will be set in update route. --self.option.Formation=self.optionDefault.Formation end + + -- Number of waypoints. + local Nwp=#self.waypoints -- Update route. - if #self.waypoints>1 then - self:T(self.lid.."Got waypoints on spawn ==> Cruise in -0.1 sec!") + if Nwp>1 and self.isMobile then + self:T(self.lid..string.format("Got %d waypoints on spawn ==> Cruise in -1.0 sec!", Nwp)) self:__Cruise(-1, nil, self.option.Formation) else self:T(self.lid.."No waypoints on spawn ==> Full Stop!") @@ -920,8 +923,13 @@ end -- @param #number Speed Speed in knots. Default cruise speed. -- @param #number Formation Formation of the group. function ARMYGROUP:onbeforeUpdateRoute(From, Event, To, n, N, Speed, Formation) + + -- Is transition allowed? We assume yes until proven otherwise. + local allowed=true + local trepeat=nil + if self:IsWaiting() then - self:T(self.lid.."Update route denied. Group is WAIRING!") + self:T(self.lid.."Update route denied. Group is WAITING!") return false elseif self:IsInUtero() then self:T(self.lid.."Update route denied. Group is INUTERO!") @@ -936,7 +944,54 @@ function ARMYGROUP:onbeforeUpdateRoute(From, Event, To, n, N, Speed, Formation) self:T(self.lid.."Update route denied. Group is holding position!") return false end - return true + + -- Check for a current task. + if self.taskcurrent>0 then + + -- Get the current task. Must not be executing already. + local task=self:GetTaskByID(self.taskcurrent) + + if task then + if task.dcstask.id=="PatrolZone" then + -- For patrol zone, we need to allow the update as we insert new waypoints. + self:T2(self.lid.."Allowing update route for Task: PatrolZone") + elseif task.dcstask.id=="ReconMission" then + -- For recon missions, we need to allow the update as we insert new waypoints. + self:T2(self.lid.."Allowing update route for Task: ReconMission") + elseif task.dcstask.id==AUFTRAG.SpecialTask.RELOCATECOHORT then + -- For relocate + self:T2(self.lid.."Allowing update route for Task: Relocate Cohort") + else + local taskname=task and task.description or "No description" + self:T(self.lid..string.format("WARNING: Update route denied because taskcurrent=%d>0! Task description = %s", self.taskcurrent, tostring(taskname))) + allowed=false + end + else + -- Now this can happen, if we directly use TaskExecute as the task is not in the task queue and cannot be removed. Therefore, also directly executed tasks should be added to the queue! + self:T(self.lid..string.format("WARNING: before update route taskcurrent=%d (>0!) but no task?!", self.taskcurrent)) + -- Anyhow, a task is running so we do not allow to update the route! + allowed=false + end + end + + -- Not good, because mission will never start. Better only check if there is a current task! + --if self.currentmission then + --end + + -- Only AI flights. + if not self.isAI then + allowed=false + end + + -- Debug info. + self:T2(self.lid..string.format("Onbefore Updateroute in state %s: allowed=%s (repeat in %s)", self:GetState(), tostring(allowed), tostring(trepeat))) + + -- Try again? + if trepeat then + self:__UpdateRoute(trepeat, n) + end + + return allowed end --- On after "UpdateRoute" event. @@ -1239,6 +1294,33 @@ function ARMYGROUP:onafterRearmed(From, Event, To) self:_CheckGroupDone(1) end +--- On before "RTZ" event. +-- @param #ARMYGROUP self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param Core.Zone#ZONE Zone The zone to return to. +-- @param #number Formation Formation of the group. +function ARMYGROUP:onbeforeRTZ(From, Event, To, Zone, Formation) + + -- Zone. + local zone=Zone or self.homezone + + if zone then + + if (not self.isMobile) and (not self:IsInZone(zone)) then + self:Teleport(zone:GetCoordinate(), 0, true) + self:__RTZ(-1, Zone, Formation) + return false + end + + else + return false + end + + return true +end + --- On after "RTZ" event. -- @param #ARMYGROUP self -- @param #string From From state. @@ -1618,8 +1700,12 @@ function ARMYGROUP:onafterCruise(From, Event, To, Speed, Formation) -- Not waiting anymore. self.Twaiting=nil self.dTwait=nil + + -- Debug info. + self:T(self.lid.."Cruise ==> Update route in 0.01 sec") - self:__UpdateRoute(-0.1, nil, nil, Speed, Formation) + -- Update route. + self:__UpdateRoute(-0.01, nil, nil, Speed, Formation) end @@ -1712,6 +1798,13 @@ function ARMYGROUP:_InitGroup(Template) -- Max speed in km/h. self.speedMax=self.group:GetSpeedMax() + -- Is group mobile? + if self.speedMax>3.6 then + self.isMobile=true + else + self.isMobile=false + end + -- Cruise speed in km/h self.speedCruise=self.speedMax*0.7 diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 6cc77618f..35276066f 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -3097,6 +3097,13 @@ function FLIGHTGROUP:_InitGroup(Template) -- Max speed in km/h. self.speedMax=group:GetSpeedMax() + + -- Is group mobile? + if self.speedMax>3.6 then + self.isMobile=true + else + self.isMobile=false + end -- Cruise speed limit 350 kts for fixed and 80 knots for rotary wings. local speedCruiseLimit=self.isHelo and UTILS.KnotsToKmph(80) or UTILS.KnotsToKmph(350) diff --git a/Moose Development/Moose/Ops/Intelligence.lua b/Moose Development/Moose/Ops/Intelligence.lua index 79e94f341..48cbfc739 100644 --- a/Moose Development/Moose/Ops/Intelligence.lua +++ b/Moose Development/Moose/Ops/Intelligence.lua @@ -154,7 +154,7 @@ INTEL.Ctype={ --- INTEL class version. -- @field #string version -INTEL.version="0.3.2" +INTEL.version="0.3.3" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- ToDo list @@ -1894,27 +1894,37 @@ function INTEL:GetClusterCoordinate(Cluster, Update) local vec3=nil --DCS#Vec3 - if Update and contact.group:IsAlive() then + if Update and contact.group and contact.group:IsAlive() then vec3 = contact.group:GetVec3() - else - vec3 = contact.position end - -- Sum up posits. - x=x+vec3.x - y=y+vec3.y - z=z+vec3.z + if not vec3 then + vec3=contact.position + end - -- Increase counter. - n=n+1 + if vec3 then + + -- Sum up posits. + x=x+vec3.x + y=y+vec3.y + z=z+vec3.z + + -- Increase counter. + n=n+1 + + end end + + if n>0 then - -- Average. - local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3 - - -- Update cluster coordinate. - Cluster.coordinate:UpdateFromVec3(Vec3) + -- Average. + local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3 + + -- Update cluster coordinate. + Cluster.coordinate:UpdateFromVec3(Vec3) + + end return Cluster.coordinate end diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 5479e94f2..2acd1c706 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -83,7 +83,6 @@ function LEGION:New(WarehouseName, LegionName) self.lid=string.format("LEGION %s | ", self.alias) -- Defaults: - -- TODO: What? self:SetMarker(false) -- Dead and crash events are handled via opsgroups. diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index a770297b0..5c1cd9781 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -1021,23 +1021,75 @@ end -- @param #number Speed Speed in knots to the next waypoint. -- @param #number Depth Depth in meters to the next waypoint. function NAVYGROUP:onbeforeUpdateRoute(From, Event, To, n, Speed, Depth) + -- Is transition allowed? We assume yes until proven otherwise. + local allowed=true + local trepeat=nil + if self:IsWaiting() then - self:E(self.lid.."Update route denied. Group is WAITING!") + self:T(self.lid.."Update route denied. Group is WAITING!") return false elseif self:IsInUtero() then - self:E(self.lid.."Update route denied. Group is INUTERO!") + self:T(self.lid.."Update route denied. Group is INUTERO!") return false elseif self:IsDead() then - self:E(self.lid.."Update route denied. Group is DEAD!") + self:T(self.lid.."Update route denied. Group is DEAD!") return false elseif self:IsStopped() then - self:E(self.lid.."Update route denied. Group is STOPPED!") + self:T(self.lid.."Update route denied. Group is STOPPED!") return false elseif self:IsHolding() then self:T(self.lid.."Update route denied. Group is holding position!") - return false + return false end - return true + + -- Check for a current task. + if self.taskcurrent>0 then + + -- Get the current task. Must not be executing already. + local task=self:GetTaskByID(self.taskcurrent) + + if task then + if task.dcstask.id=="PatrolZone" then + -- For patrol zone, we need to allow the update as we insert new waypoints. + self:T2(self.lid.."Allowing update route for Task: PatrolZone") + elseif task.dcstask.id=="ReconMission" then + -- For recon missions, we need to allow the update as we insert new waypoints. + self:T2(self.lid.."Allowing update route for Task: ReconMission") + elseif task.dcstask.id==AUFTRAG.SpecialTask.RELOCATECOHORT then + -- For relocate + self:T2(self.lid.."Allowing update route for Task: Relocate Cohort") + else + local taskname=task and task.description or "No description" + self:T(self.lid..string.format("WARNING: Update route denied because taskcurrent=%d>0! Task description = %s", self.taskcurrent, tostring(taskname))) + allowed=false + end + else + -- Now this can happen, if we directly use TaskExecute as the task is not in the task queue and cannot be removed. Therefore, also directly executed tasks should be added to the queue! + self:T(self.lid..string.format("WARNING: before update route taskcurrent=%d (>0!) but no task?!", self.taskcurrent)) + -- Anyhow, a task is running so we do not allow to update the route! + allowed=false + end + end + + -- Not good, because mission will never start. Better only check if there is a current task! + --if self.currentmission then + --end + + -- Only AI flights. + if not self.isAI then + allowed=false + end + + -- Debug info. + self:T2(self.lid..string.format("Onbefore Updateroute in state %s: allowed=%s (repeat in %s)", self:GetState(), tostring(allowed), tostring(trepeat))) + + -- Try again? + if trepeat then + self:__UpdateRoute(trepeat, n) + end + + return allowed + end --- On after "UpdateRoute" event. @@ -1712,6 +1764,13 @@ function NAVYGROUP:_InitGroup(Template) -- Max speed in km/h. self.speedMax=self.group:GetSpeedMax() + -- Is group mobile? + if self.speedMax>3.6 then + self.isMobile=true + else + self.isMobile=false + end + -- Cruise speed: 70% of max speed. self.speedCruise=self.speedMax*0.7 diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index dd4b628e6..da46d8230 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -4144,8 +4144,18 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) -- Debug info. self:T(self.lid..string.format("Fire at point with nshots=%d of %d", nShots, nAmmo)) - -- Only fire number of avail shots. - nShots=math.min(nShots, nAmmo) + if nShots==-1 then + -- The -1 is for using all available ammo. + nShots=nAmmo + self:T(self.lid..string.format("Fire at point taking max amount of ammo = %d", nShots)) + elseif nShots<1 then + local p=nShots + nShots=UTILS.Round(p*nAmmo, 0) + self:T(self.lid..string.format("Fire at point taking %.1f percent amount of ammo = %d", p, nShots)) + else + -- Fire nShots but at most nAmmo. + nShots=math.min(nShots, nAmmo) + end -- Set quantity of task. DCSTask.params.expendQty=nShots