mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Update Suppression.lua
- Fixed routing of group (passing waypoint function was triggered too early due to changed DCS behaviour)
This commit is contained in:
parent
0f1ad9d811
commit
2538d583ad
@ -85,6 +85,7 @@
|
|||||||
-- @field #boolean eventmoose If true, events are handled by MOOSE. If false, events are handled directly by DCS eventhandler. Default true.
|
-- @field #boolean eventmoose If true, events are handled by MOOSE. If false, events are handled directly by DCS eventhandler. Default true.
|
||||||
-- @field Core.Zone#ZONE BattleZone
|
-- @field Core.Zone#ZONE BattleZone
|
||||||
-- @field #boolean AutoEngage
|
-- @field #boolean AutoEngage
|
||||||
|
-- @field #table waypoints Waypoints of the group as defined in the ME.
|
||||||
-- @extends Core.Fsm#FSM_CONTROLLABLE
|
-- @extends Core.Fsm#FSM_CONTROLLABLE
|
||||||
--
|
--
|
||||||
|
|
||||||
@ -265,6 +266,7 @@ SUPPRESSION={
|
|||||||
DefaultAlarmState = "Auto",
|
DefaultAlarmState = "Auto",
|
||||||
DefaultROE = "Weapon Free",
|
DefaultROE = "Weapon Free",
|
||||||
eventmoose = true,
|
eventmoose = true,
|
||||||
|
waypoints = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Enumerator of possible rules of engagement.
|
--- Enumerator of possible rules of engagement.
|
||||||
@ -295,7 +297,7 @@ SUPPRESSION.MenuF10=nil
|
|||||||
|
|
||||||
--- PSEUDOATC version.
|
--- PSEUDOATC version.
|
||||||
-- @field #number version
|
-- @field #number version
|
||||||
SUPPRESSION.version="0.9.3"
|
SUPPRESSION.version="0.9.4"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -309,7 +311,7 @@ SUPPRESSION.version="0.9.3"
|
|||||||
--- Creates a new AI_suppression object.
|
--- Creates a new AI_suppression object.
|
||||||
-- @param #SUPPRESSION self
|
-- @param #SUPPRESSION self
|
||||||
-- @param Wrapper.Group#GROUP group The GROUP object for which suppression should be applied.
|
-- @param Wrapper.Group#GROUP group The GROUP object for which suppression should be applied.
|
||||||
-- @return #SUPPRESSION SUPPRESSION object or *nil* if group does not exist or is not a ground group.
|
-- @return #SUPPRESSION self
|
||||||
function SUPPRESSION:New(group)
|
function SUPPRESSION:New(group)
|
||||||
|
|
||||||
-- Inherits from FSM_CONTROLLABLE
|
-- Inherits from FSM_CONTROLLABLE
|
||||||
@ -320,7 +322,7 @@ function SUPPRESSION:New(group)
|
|||||||
self.lid=string.format("SUPPRESSION %s | ", tostring(group:GetName()))
|
self.lid=string.format("SUPPRESSION %s | ", tostring(group:GetName()))
|
||||||
self:T(self.lid..string.format("SUPPRESSION version %s. Activating suppressive fire for group %s", SUPPRESSION.version, group:GetName()))
|
self:T(self.lid..string.format("SUPPRESSION version %s. Activating suppressive fire for group %s", SUPPRESSION.version, group:GetName()))
|
||||||
else
|
else
|
||||||
self:E(self.lid.."SUPPRESSION | Requested group does not exist! (Has to be a MOOSE group.)")
|
self:E("SUPPRESSION | Requested group does not exist! (Has to be a MOOSE group)")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1186,6 +1188,16 @@ function SUPPRESSION:onafterFightBack(Controllable, From, Event, To)
|
|||||||
-- Set ROE and alarm state back to default.
|
-- Set ROE and alarm state back to default.
|
||||||
self:_SetROE()
|
self:_SetROE()
|
||||||
self:_SetAlarmState()
|
self:_SetAlarmState()
|
||||||
|
|
||||||
|
local group=Controllable --Wrapper.Group#GROUP
|
||||||
|
|
||||||
|
local Waypoints = group:GetTemplateRoutePoints()
|
||||||
|
|
||||||
|
-- env.info("FF waypoints",showMessageBox)
|
||||||
|
-- self:I(Waypoints)
|
||||||
|
|
||||||
|
group:Route(Waypoints, 5)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -1251,7 +1263,7 @@ function SUPPRESSION:onafterFallBack(Controllable, From, Event, To, AttackUnit)
|
|||||||
self:_SetROE(SUPPRESSION.ROE.Hold)
|
self:_SetROE(SUPPRESSION.ROE.Hold)
|
||||||
|
|
||||||
-- Set alarm state to GREEN and let the unit run away.
|
-- Set alarm state to GREEN and let the unit run away.
|
||||||
self:_SetAlarmState(SUPPRESSION.AlarmState.Green)
|
self:_SetAlarmState(SUPPRESSION.AlarmState.Auto)
|
||||||
|
|
||||||
-- Make the group run away.
|
-- Make the group run away.
|
||||||
self:_Run(Coord, self.Speed, self.Formation, self.FallbackWait)
|
self:_Run(Coord, self.Speed, self.Formation, self.FallbackWait)
|
||||||
@ -1537,7 +1549,7 @@ end
|
|||||||
-- @param #SUPPRESSION self
|
-- @param #SUPPRESSION self
|
||||||
-- @param Core.Event#EVENTDATA EventData
|
-- @param Core.Event#EVENTDATA EventData
|
||||||
function SUPPRESSION:_OnEventHit(EventData)
|
function SUPPRESSION:_OnEventHit(EventData)
|
||||||
self:F(EventData)
|
self:F3(EventData)
|
||||||
|
|
||||||
local GroupNameSelf=self.Controllable:GetName()
|
local GroupNameSelf=self.Controllable:GetName()
|
||||||
local GroupNameTgt=EventData.TgtGroupName
|
local GroupNameTgt=EventData.TgtGroupName
|
||||||
@ -1676,15 +1688,15 @@ end
|
|||||||
function SUPPRESSION:_Run(fin, speed, formation, wait)
|
function SUPPRESSION:_Run(fin, speed, formation, wait)
|
||||||
|
|
||||||
speed=speed or 20
|
speed=speed or 20
|
||||||
formation=formation or "Off road"
|
formation=formation or ENUMS.Formation.Vehicle.OffRoad
|
||||||
wait=wait or 30
|
wait=wait or 30
|
||||||
|
|
||||||
local group=self.Controllable -- Wrapper.Controllable#CONTROLLABLE
|
local group=self.Controllable -- Wrapper.Group#GROUP
|
||||||
|
|
||||||
if group and group:IsAlive() then
|
if group and group:IsAlive() then
|
||||||
|
|
||||||
-- Clear all tasks.
|
-- Clear all tasks.
|
||||||
group:ClearTasks()
|
--group:ClearTasks()
|
||||||
|
|
||||||
-- Current coordinates of group.
|
-- Current coordinates of group.
|
||||||
local ini=group:GetCoordinate()
|
local ini=group:GetCoordinate()
|
||||||
@ -1695,56 +1707,17 @@ function SUPPRESSION:_Run(fin, speed, formation, wait)
|
|||||||
-- Heading from ini to fin.
|
-- Heading from ini to fin.
|
||||||
local heading=self:_Heading(ini, fin)
|
local heading=self:_Heading(ini, fin)
|
||||||
|
|
||||||
-- Number of waypoints.
|
|
||||||
local nx
|
|
||||||
if dist <= 50 then
|
|
||||||
nx=2
|
|
||||||
elseif dist <= 100 then
|
|
||||||
nx=3
|
|
||||||
elseif dist <= 500 then
|
|
||||||
nx=4
|
|
||||||
else
|
|
||||||
nx=5
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Number of intermediate waypoints.
|
|
||||||
local dx=dist/(nx-1)
|
|
||||||
|
|
||||||
-- Waypoint and task arrays.
|
-- Waypoint and task arrays.
|
||||||
local wp={}
|
local wp={}
|
||||||
local tasks={}
|
local tasks={}
|
||||||
|
|
||||||
-- First waypoint is the current position of the group.
|
-- First waypoint is the current position of the group.
|
||||||
wp[1]=ini:WaypointGround(speed, formation)
|
wp[1]=ini:WaypointGround(speed, formation)
|
||||||
tasks[1]=group:TaskFunction("SUPPRESSION._Passing_Waypoint", self, 1, false)
|
|
||||||
|
|
||||||
if self.Debug then
|
if self.Debug then
|
||||||
local MarkerID=ini:MarkToAll(string.format("Waypoing %d of group %s (initial)", #wp, self.Controllable:GetName()))
|
local MarkerID=ini:MarkToAll(string.format("Waypoing %d of group %s (initial)", #wp, self.Controllable:GetName()))
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T2(self.lid..string.format("Number of waypoints %d", nx))
|
|
||||||
for i=1,nx-2 do
|
|
||||||
|
|
||||||
local x=dx*i
|
|
||||||
local coord=ini:Translate(x, heading)
|
|
||||||
|
|
||||||
wp[#wp+1]=coord:WaypointGround(speed, formation)
|
|
||||||
tasks[#tasks+1]=group:TaskFunction("SUPPRESSION._Passing_Waypoint", self, #wp, false)
|
|
||||||
|
|
||||||
self:T2(self.lid..string.format("%d x = %4.1f", i, x))
|
|
||||||
if self.Debug then
|
|
||||||
local MarkerID=coord:MarkToAll(string.format("Waypoing %d of group %s", #wp, self.Controllable:GetName()))
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
self:T2(self.lid..string.format("Total distance: %4.1f", dist))
|
|
||||||
|
|
||||||
-- Final waypoint.
|
|
||||||
wp[#wp+1]=fin:WaypointGround(speed, formation)
|
|
||||||
if self.Debug then
|
|
||||||
local MarkerID=fin:MarkToAll(string.format("Waypoing %d of group %s (final)", #wp, self.Controllable:GetName()))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Task to hold.
|
-- Task to hold.
|
||||||
local ConditionWait=group:TaskCondition(nil, nil, nil, nil, wait, nil)
|
local ConditionWait=group:TaskCondition(nil, nil, nil, nil, wait, nil)
|
||||||
local TaskHold = group:TaskHold()
|
local TaskHold = group:TaskHold()
|
||||||
@ -1754,24 +1727,14 @@ function SUPPRESSION:_Run(fin, speed, formation, wait)
|
|||||||
TaskComboFin[#TaskComboFin+1] = group:TaskFunction("SUPPRESSION._Passing_Waypoint", self, #wp, true)
|
TaskComboFin[#TaskComboFin+1] = group:TaskFunction("SUPPRESSION._Passing_Waypoint", self, #wp, true)
|
||||||
TaskComboFin[#TaskComboFin+1] = group:TaskControlled(TaskHold, ConditionWait)
|
TaskComboFin[#TaskComboFin+1] = group:TaskControlled(TaskHold, ConditionWait)
|
||||||
|
|
||||||
-- Add final task.
|
-- Final waypoint.
|
||||||
tasks[#tasks+1]=group:TaskCombo(TaskComboFin)
|
wp[#wp+1]=fin:WaypointGround(speed, formation, TaskComboFin)
|
||||||
|
if self.Debug then
|
||||||
-- Original waypoints of the group.
|
local MarkerID=fin:MarkToAll(string.format("Waypoing %d of group %s (final)", #wp, self.Controllable:GetName()))
|
||||||
local Waypoints = group:GetTemplateRoutePoints()
|
|
||||||
|
|
||||||
-- New points are added to the default route.
|
|
||||||
for i,p in ipairs(wp) do
|
|
||||||
table.insert(Waypoints, i, wp[i])
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Set task for all waypoints.
|
|
||||||
for i,wp in ipairs(Waypoints) do
|
|
||||||
group:SetTaskWaypoint(Waypoints[i], tasks[i])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Submit task and route group along waypoints.
|
-- Submit task and route group along waypoints.
|
||||||
group:Route(Waypoints)
|
group:Route(wp)
|
||||||
|
|
||||||
else
|
else
|
||||||
self:E(self.lid..string.format("ERROR: Group is not alive!"))
|
self:E(self.lid..string.format("ERROR: Group is not alive!"))
|
||||||
@ -1790,7 +1753,7 @@ function SUPPRESSION._Passing_Waypoint(group, Fsm, i, final)
|
|||||||
local text=string.format("Group %s passing waypoint %d (final=%s)", group:GetName(), i, tostring(final))
|
local text=string.format("Group %s passing waypoint %d (final=%s)", group:GetName(), i, tostring(final))
|
||||||
MESSAGE:New(text,10):ToAllIf(Fsm.Debug)
|
MESSAGE:New(text,10):ToAllIf(Fsm.Debug)
|
||||||
if Fsm.Debug then
|
if Fsm.Debug then
|
||||||
env.info(self.lid..text)
|
env.info(Fsm.lid..text)
|
||||||
end
|
end
|
||||||
|
|
||||||
if final then
|
if final then
|
||||||
@ -1891,7 +1854,7 @@ function SUPPRESSION:_GetLife()
|
|||||||
|
|
||||||
local groupstrength=#units/self.IniGroupStrength*100
|
local groupstrength=#units/self.IniGroupStrength*100
|
||||||
|
|
||||||
self.T2(self.lid..string.format("Group %s _GetLife nunits = %d", self.Controllable:GetName(), #units))
|
self:T2(self.lid..string.format("Group %s _GetLife nunits = %d", self.Controllable:GetName(), #units))
|
||||||
|
|
||||||
for _,unit in pairs(units) do
|
for _,unit in pairs(units) do
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user