**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:
Frank 2022-05-03 09:41:22 +02:00 committed by GitHub
parent 68dce2f247
commit d2d431ce2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 341 additions and 164 deletions

View File

@ -897,9 +897,12 @@ function ARMYGROUP:onafterSpawned(From, Event, To)
--self.option.Formation=self.optionDefault.Formation --self.option.Formation=self.optionDefault.Formation
end end
-- Number of waypoints.
local Nwp=#self.waypoints
-- Update route. -- Update route.
if #self.waypoints>1 then if Nwp>1 and self.isMobile then
self:T(self.lid.."Got waypoints on spawn ==> Cruise in -0.1 sec!") self:T(self.lid..string.format("Got %d waypoints on spawn ==> Cruise in -1.0 sec!", Nwp))
self:__Cruise(-1, nil, self.option.Formation) self:__Cruise(-1, nil, self.option.Formation)
else else
self:T(self.lid.."No waypoints on spawn ==> Full Stop!") 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 Speed Speed in knots. Default cruise speed.
-- @param #number Formation Formation of the group. -- @param #number Formation Formation of the group.
function ARMYGROUP:onbeforeUpdateRoute(From, Event, To, n, N, Speed, Formation) 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 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 return false
elseif self:IsInUtero() then elseif self:IsInUtero() then
self:T(self.lid.."Update route denied. Group is INUTERO!") 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!") self:T(self.lid.."Update route denied. Group is holding position!")
return false return false
end 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 end
--- On after "UpdateRoute" event. --- On after "UpdateRoute" event.
@ -1239,6 +1294,33 @@ function ARMYGROUP:onafterRearmed(From, Event, To)
self:_CheckGroupDone(1) self:_CheckGroupDone(1)
end 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. --- On after "RTZ" event.
-- @param #ARMYGROUP self -- @param #ARMYGROUP self
-- @param #string From From state. -- @param #string From From state.
@ -1619,7 +1701,11 @@ function ARMYGROUP:onafterCruise(From, Event, To, Speed, Formation)
self.Twaiting=nil self.Twaiting=nil
self.dTwait=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 end
@ -1712,6 +1798,13 @@ function ARMYGROUP:_InitGroup(Template)
-- Max speed in km/h. -- Max speed in km/h.
self.speedMax=self.group:GetSpeedMax() 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 -- Cruise speed in km/h
self.speedCruise=self.speedMax*0.7 self.speedCruise=self.speedMax*0.7

View File

@ -3098,6 +3098,13 @@ function FLIGHTGROUP:_InitGroup(Template)
-- Max speed in km/h. -- Max speed in km/h.
self.speedMax=group:GetSpeedMax() 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. -- 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) local speedCruiseLimit=self.isHelo and UTILS.KnotsToKmph(80) or UTILS.KnotsToKmph(350)

View File

@ -1989,28 +1989,37 @@ function INTEL:GetClusterCoordinate(Cluster, Update)
local vec3=nil --DCS#Vec3 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() vec3 = contact.group:GetVec3()
else
vec3 = contact.position
end end
-- Sum up posits. if not vec3 then
vec3=contact.position
end
if vec3 then if vec3 then
-- Sum up posits.
x=x+vec3.x x=x+vec3.x
y=y+vec3.y y=y+vec3.y
z=z+vec3.z z=z+vec3.z
-- Increase counter. -- Increase counter.
n=n+1 n=n+1
end end
end end
-- Average. if n>0 then
local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3
-- Update cluster coordinate. -- Average.
Cluster.coordinate:UpdateFromVec3(Vec3) local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3
-- Update cluster coordinate.
Cluster.coordinate:UpdateFromVec3(Vec3)
end
return Cluster.coordinate return Cluster.coordinate
end end

View File

@ -83,7 +83,6 @@ function LEGION:New(WarehouseName, LegionName)
self.lid=string.format("LEGION %s | ", self.alias) self.lid=string.format("LEGION %s | ", self.alias)
-- Defaults: -- Defaults:
-- TODO: What?
self:SetMarker(false) self:SetMarker(false)
-- Dead and crash events are handled via opsgroups. -- Dead and crash events are handled via opsgroups.

View File

@ -1021,23 +1021,75 @@ end
-- @param #number Speed Speed in knots to the next waypoint. -- @param #number Speed Speed in knots to the next waypoint.
-- @param #number Depth Depth in meters to the next waypoint. -- @param #number Depth Depth in meters to the next waypoint.
function NAVYGROUP:onbeforeUpdateRoute(From, Event, To, n, Speed, Depth) 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 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 return false
elseif self:IsInUtero() then 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 return false
elseif self:IsDead() then 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 return false
elseif self:IsStopped() then 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 return false
elseif self:IsHolding() then elseif self:IsHolding() then
self:T(self.lid.."Update route denied. Group is holding position!") self:T(self.lid.."Update route denied. Group is holding position!")
return false return false
end 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 end
--- On after "UpdateRoute" event. --- On after "UpdateRoute" event.
@ -1712,6 +1764,13 @@ function NAVYGROUP:_InitGroup(Template)
-- Max speed in km/h. -- Max speed in km/h.
self.speedMax=self.group:GetSpeedMax() 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. -- Cruise speed: 70% of max speed.
self.speedCruise=self.speedMax*0.7 self.speedCruise=self.speedMax*0.7

View File

@ -4144,8 +4144,18 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task)
-- Debug info. -- Debug info.
self:T(self.lid..string.format("Fire at point with nshots=%d of %d", nShots, nAmmo)) self:T(self.lid..string.format("Fire at point with nshots=%d of %d", nShots, nAmmo))
-- Only fire number of avail shots. if nShots==-1 then
nShots=math.min(nShots, nAmmo) -- 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. -- Set quantity of task.
DCSTask.params.expendQty=nShots DCSTask.params.expendQty=nShots