mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OPS
**INTEL** - Added nil check for cluster position update **OPSGROUP** - Improved fire at point task to take only max avail shots and relative shot amount - Fixed tasks not executed after teleport
This commit is contained in:
parent
ba591c9dc5
commit
2d8fc40307
@ -897,9 +897,12 @@ function ARMYGROUP:onafterSpawned(From, Event, To)
|
||||
--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.
|
||||
@ -1619,7 +1701,11 @@ function ARMYGROUP:onafterCruise(From, Event, To, Speed, Formation)
|
||||
self.Twaiting=nil
|
||||
self.dTwait=nil
|
||||
|
||||
self:__UpdateRoute(-0.1, nil, nil, Speed, Formation)
|
||||
-- Debug info.
|
||||
self:T(self.lid.."Cruise ==> Update route in 0.01 sec")
|
||||
|
||||
-- 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
|
||||
|
||||
|
||||
@ -3098,6 +3098,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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
-- Average.
|
||||
local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3
|
||||
if n>0 then
|
||||
|
||||
-- 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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user