This commit is contained in:
Frank
2020-04-28 00:42:13 +02:00
parent 25e58393ea
commit f9e5785f52
3 changed files with 90 additions and 59 deletions
+39 -7
View File
@@ -342,7 +342,7 @@ AUFTRAG.version="0.2.0"
-- TODO: F10 marker to create new missions. -- TODO: F10 marker to create new missions.
-- DONE: Evaluate mission result ==> SUCCESS/FAILURE -- DONE: Evaluate mission result ==> SUCCESS/FAILURE
-- DONE: NewAUTO() NewA2G NewA2A -- DONE: NewAUTO() NewA2G NewA2A
-- TODO: Transport mission. -- DONE: Transport mission.
-- TODO: Recon mission. -- TODO: Recon mission.
-- TODO: Set mission coalition, e.g. for F10 markers. -- TODO: Set mission coalition, e.g. for F10 markers.
@@ -916,11 +916,13 @@ function AUFTRAG:NewBOMBCARPET(Target, Altitude, CarpetLength)
mission.engageWeaponType=ENUMS.WeaponFlag.AnyBomb mission.engageWeaponType=ENUMS.WeaponFlag.AnyBomb
mission.engageWeaponExpend=AI.Task.WeaponExpend.ALL mission.engageWeaponExpend=AI.Task.WeaponExpend.ALL
mission.engageCarpetLength=CarpetLength or 500 mission.engageCarpetLength=CarpetLength or 500
mission.engageAsGroup=false -- Looks like this must be false or the task is not executed. It is not available in the ME anyway but in the task of the mission file.
mission.engageDirection=nil -- This is also not available in the ME.
-- Mission options: -- Mission options:
mission.missionTask=ENUMS.MissionTask.GROUNDATTACK mission.missionTask=ENUMS.MissionTask.GROUNDATTACK
mission.missionAltitude=mission.engageAltitude*0.8 mission.missionAltitude=mission.engageAltitude*0.8
mission.missionFraction=0.2 mission.missionFraction=0.5
mission.optionROE=ENUMS.ROE.OpenFire mission.optionROE=ENUMS.ROE.OpenFire
mission.optionROT=ENUMS.ROT.NoReaction mission.optionROT=ENUMS.ROT.NoReaction
@@ -1852,6 +1854,29 @@ function AUFTRAG:GetFlightWaypointTask(flightgroup)
end end
end end
--- Set flightgroup waypoint index.
-- @param #AUFTRAG self
-- @param Ops.FlightGroup#FLIGHTGROUP flightgroup The flight group.
-- @param #number waypointindex Waypoint index.
function AUFTRAG:SetFlightWaypointIndex(flightgroup, waypointindex)
self:I(self.lid..string.format("Setting waypoint index %d", waypointindex))
local flightdata=self:GetFlightData(flightgroup)
if flightdata then
flightdata.waypointindex=waypointindex
end
end
--- Get flightgroup waypoint index.
-- @param #AUFTRAG self
-- @param Ops.FlightGroup#FLIGHTGROUP flightgroup The flight group.
-- @return #number Waypoint index
function AUFTRAG:GetFlightWaypointIndex(flightgroup)
local flightdata=self:GetFlightData(flightgroup)
if flightdata then
return flightdata.waypointindex
end
end
--- Check if all flights are done with their mission (or dead). --- Check if all flights are done with their mission (or dead).
-- @param #AUFTRAG self -- @param #AUFTRAG self
@@ -1864,6 +1889,7 @@ function AUFTRAG:CheckFlightsDone()
end end
-- It could be that all flights were destroyed on the way to the mission execution waypoint. -- It could be that all flights were destroyed on the way to the mission execution waypoint.
-- TODO: would be better to check if everybody is dead by now.
if self:IsStarted() and self:CountFlightGroups()==0 then if self:IsStarted() and self:CountFlightGroups()==0 then
return true return true
end end
@@ -1876,7 +1902,6 @@ function AUFTRAG:CheckFlightsDone()
-- This one is done or cancelled. -- This one is done or cancelled.
else else
-- At least this flight is not DONE or CANCELLED. -- At least this flight is not DONE or CANCELLED.
--flightdata.status
return false return false
end end
end end
@@ -1889,21 +1914,28 @@ end
-- EVENT Functions -- EVENT Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Flightgroup event function handling the crash of a unit. --- Unit lost event.
-- @param #AUFTRAG self -- @param #AUFTRAG self
-- @param Core.Event#EVENTDATA EventData Event data. -- @param Core.Event#EVENTDATA EventData Event data.
function AUFTRAG:OnEventCrash(EventData) function AUFTRAG:OnEventUnitLost(EventData)
-- Check that this is the right group. -- Check that this is the right group.
if EventData and EventData.IniGroup and EventData.IniUnit and EventData.IniGroupName and EventData.IniGroupName==self.groupname then if EventData and EventData.IniGroup and EventData.IniUnit then
local unit=EventData.IniUnit local unit=EventData.IniUnit
local group=EventData.IniGroup local group=EventData.IniGroup
local unitname=EventData.IniUnitName local unitname=EventData.IniUnitName
for _,_flightdata in pairs(self.flightdata) do
local flightdata=_flightdata --#AUFTRAG.FlightData
if flightdata and flightdata.flightgroup and flightdata.flightgroup.groupname==EventData.IniGroupName then
self:I(self.lid..string.format("UNIT LOST event for flightgroup %s unit %s", flightdata.flightgroup.groupname, EventData.IniUnitName))
end
end
end end
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- FSM Functions -- FSM Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+50 -50
View File
@@ -789,7 +789,10 @@ function FLIGHTGROUP:RemoveMission(Mission)
-- Remove mission waypoint task. -- Remove mission waypoint task.
local Task=Mission:GetFlightWaypointTask(self) local Task=Mission:GetFlightWaypointTask(self)
self:RemoveTask(Task)
if Task then
self:RemoveTask(Task)
end
-- Remove mission from queue. -- Remove mission from queue.
table.remove(self.missionqueue, i) table.remove(self.missionqueue, i)
@@ -1608,9 +1611,13 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
local element=_element --#FLIGHTGROUP.Element local element=_element --#FLIGHTGROUP.Element
local fuel=element.unit:GetFuel() or 0 local fuel=element.unit:GetFuel() or 0
local df=element.fuelrel-fuel
local fmass=element.fuelmass*fuel -- Relative fuel used since last check.
local dFrel=element.fuelrel-fuel
local dFabs=element.fuelmass
local fmass=element.fuelmass0*fuel
local dm=element.fuelmass-fmass local dm=element.fuelmass-fmass
@@ -1622,7 +1629,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
fuelmass=fmass fuelmass=fmass
end end
self:I(self.lid..string.format("Fuel consumption %s: df=%.1f, dm=%.1f kg ==> dm/ds=%.1f kg/s dm/dt=%.1f 1/s", element.name, df, dm, dmds, dmdt)) self:I(self.lid..string.format("Fuel consumption %s F=%.1f: dF=%.3f, dm=%.1f kg ==> dm/ds=%.1f kg/min dm/dt=%.1f 1/s", element.name, fuel*100, dFrel*100, dm, dmds*60, dmdt))
element.fuelrel=fuel element.fuelrel=fuel
element.fuelmass=fmass element.fuelmass=fmass
@@ -1686,8 +1693,8 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
local mission=_mission --Ops.Auftrag#AUFTRAG local mission=_mission --Ops.Auftrag#AUFTRAG
local Cstart= UTILS.SecondsToClock(mission.Tstart, true) local Cstart= UTILS.SecondsToClock(mission.Tstart, true)
local Cstop = mission.Tstop and UTILS.SecondsToClock(mission.Tstop, true) or "INF" local Cstop = mission.Tstop and UTILS.SecondsToClock(mission.Tstop, true) or "INF"
text=text..string.format("\n[%d] %s (%s) status=%s (%s), Time=%s-%s, prio=%d targets=%d", text=text..string.format("\n[%d] %s (%s) status=%s (%s), Time=%s-%s, prio=%d wp=%s targets=%d",
i, tostring(mission.name), mission.type, mission:GetFlightStatus(self), tostring(mission.status), Cstart, Cstop, mission.prio, mission:CountMissionTargets()) i, tostring(mission.name), mission.type, mission:GetFlightStatus(self), tostring(mission.status), Cstart, Cstop, mission.prio, tostring(mission:GetFlightWaypointIndex(self)), mission:CountMissionTargets())
end end
self:I(self.lid..text) self:I(self.lid..text)
end end
@@ -3680,7 +3687,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To, Task)
Task.formation:Stop() Task.formation:Stop()
self:TaskDone(Task) self:TaskDone(Task)
elseif stopflag==1 then elseif stopflag==1 then
-- Manuall call TaskDone if setting flag to one was not successful. -- Manual call TaskDone if setting flag to one was not successful.
self:TaskDone(Task) self:TaskDone(Task)
end end
@@ -3693,6 +3700,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To, Task)
self:TaskDone(Task) self:TaskDone(Task)
--[[
local mission=self:GetMissionByTaskID(Task.id) local mission=self:GetMissionByTaskID(Task.id)
-- Is this a waypoint task? -- Is this a waypoint task?
@@ -3703,6 +3711,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To, Task)
self:RemoveWaypoint(Task.waypoint) self:RemoveWaypoint(Task.waypoint)
end end
end end
]]
end end
else else
@@ -3966,7 +3975,17 @@ function FLIGHTGROUP:onafterMissionDone(From, Event, To, Mission)
Mission:SetFlightStatus(self, AUFTRAG.FlightStatus.DONE) Mission:SetFlightStatus(self, AUFTRAG.FlightStatus.DONE)
-- Set current mission to nil. -- Set current mission to nil.
self.currentmission=nil if self.currentmission and Mission.auftragsnummer==self.currentmission then
self.currentmission=nil
end
-- Remove mission waypoint.
local wpidx=Mission:GetFlightWaypointIndex(self)
if wpidx then
self:RemoveWaypoint(wpidx)
end
-- TODO: reset mission specific parameters like radio, ROE etc.
-- Check if flight is done. -- Check if flight is done.
self:_CheckFlightDone(1) self:_CheckFlightDone(1)
@@ -3994,7 +4013,7 @@ function FLIGHTGROUP:RouteToMission(mission, delay)
-- Set altitude of mission waypoint. -- Set altitude of mission waypoint.
if mission.missionAltitude then if mission.missionAltitude then
waypointcoord.y=mission.missionAltitude waypointcoord:SetAltitude(mission.missionAltitude, true)
end end
-- Add enroute tasks. -- Add enroute tasks.
@@ -4008,6 +4027,7 @@ function FLIGHTGROUP:RouteToMission(mission, delay)
-- Add waypoint. -- Add waypoint.
self:AddWaypointAir(waypointcoord, nextwaypoint, speed, false) self:AddWaypointAir(waypointcoord, nextwaypoint, speed, false)
-- Special for Troop transport.
if mission.type==AUFTRAG.Type.TROOPTRANSPORT then if mission.type==AUFTRAG.Type.TROOPTRANSPORT then
-- Refresh DCS task with the known controllable. -- Refresh DCS task with the known controllable.
@@ -4032,9 +4052,8 @@ function FLIGHTGROUP:RouteToMission(mission, delay)
-- Set waypoint task. -- Set waypoint task.
mission:SetFlightWaypointTask(self, waypointtask) mission:SetFlightWaypointTask(self, waypointtask)
-- TODO: better marker text, mission.maker -- Set waypoint index.
--mission.marker=waypointcoord:MarkToCoalition(mission.name, self:GetCoalition(), true) mission:SetFlightWaypointIndex(self, nextwaypoint)
--mission.marker=waypointcoord:MarkToAll(string.format("%s %s %s", mission.name, mission.type, self.groupname), true)
--- ---
-- Mission Specific Settings -- Mission Specific Settings
@@ -4823,11 +4842,10 @@ end
-- @param #number wpnumber Waypoint number. Default at the end. -- @param #number wpnumber Waypoint number. Default at the end.
-- @param #number speed Speed in knots. Default 350 kts. -- @param #number speed Speed in knots. Default 350 kts.
-- @param #boolean updateroute If true or nil, call UpdateRoute. If false, no call. -- @param #boolean updateroute If true or nil, call UpdateRoute. If false, no call.
-- @return #FLIGHTGROUP self -- @return #number Waypoint index.
function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute) function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute)
-- Waypoint number. -- Waypoint number. Default is at the end.
--TODO: by default add after last AIR waypoint! Last WP could be landing...
wpnumber=wpnumber or #self.waypoints+1 wpnumber=wpnumber or #self.waypoints+1
if wpnumber>self.currentwp then if wpnumber>self.currentwp then
@@ -4860,9 +4878,15 @@ function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute)
-- Shift all mission waypoints after the inserted waypoint. -- Shift all mission waypoints after the inserted waypoint.
for _,_mission in pairs(self.missionqueue) do for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG local mission=_mission --Ops.Auftrag#AUFTRAG
if mission.waypointindex and mission.waypointindex>=wpnumber then
mission.waypointindex=mission.waypointindex+1 -- Get mission waypoint index.
end local wpidx=mission:GetFlightWaypointIndex(self)
-- Increase number if this waypoint lies in the future.
if wpidx and wpidx>=wpnumber then
mission:SetFlightWaypointIndex(self, wpidx+1)
end
end end
-- Update route. -- Update route.
@@ -4870,7 +4894,7 @@ function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute)
self:__UpdateRoute(-1) self:__UpdateRoute(-1)
end end
return self return wpnumber
end end
--- Remove a waypoint. --- Remove a waypoint.
@@ -4904,9 +4928,12 @@ function FLIGHTGROUP:RemoveWaypoint(wpindex)
for _,_mission in pairs(self.missionqueue) do for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG local mission=_mission --Ops.Auftrag#AUFTRAG
-- TODO: This is not the waypoint index any more. Waypoint index is now for each FLIGHTGROUP. -- Get mission waypoint index.
if mission.waypointindex and mission.waypointindex>wpindex then local wpidx=mission:GetFlightWaypointIndex(self)
mission.waypointindex=mission.waypointindex-1
-- Reduce number if this waypoint lies in the future.
if wpidx and wpidx>wpindex then
mission:SetFlightWaypointIndex(self, wpidx-1)
end end
end end
@@ -4933,37 +4960,10 @@ function FLIGHTGROUP:RemoveWaypoint(wpindex)
end end
end
--- Set the landing waypoint.
-- @param #FLIGHTGROUP self
-- @param Wrapper.Airbase#AIRBASE airbase The destination airbase.
-- @param #number wpnumber Waypoint number. Default at the end.
-- @param #number speed Speed in knots. Default 350 kts.
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:SetWaypointLanding(airbase)
local wpnumber=#self.waypoints
local lastwp=self.waypoints[wpnumber]
if self:IsLandingAirbase(lastwp) then
table.remove(self.waypoints, wpnumber)
end
local wp=self.group:GetCoordinate():WaypointAir(COORDINATE.WaypointAltType.BARO, COORDINATE.WaypointType.Land, COORDINATE.WaypointAction.Landing, self.speedmax*0.8, true, nil, {}, string.format("Landing Waypoint #%d", wpnumber))
table.insert(self.waypoints, wp)
self.destbase=airbase
-- Update route.
self:__UpdateRoute(-1)
return self return self
end end
--- Check if a unit is an element of the flightgroup. --- Check if a unit is an element of the flightgroup.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param #string unitname Name of unit. -- @param #string unitname Name of unit.
@@ -1011,7 +1011,6 @@ function CONTROLLABLE:TaskCarpetBombing(Vec2, GroupAttack, WeaponExpend, AttackQ
id = 'CarpetBombing', id = 'CarpetBombing',
params = { params = {
attackType = "Carpet", attackType = "Carpet",
point = Vec2,
x = Vec2.x, x = Vec2.x,
y = Vec2.y, y = Vec2.y,
groupAttack = GroupAttack and GroupAttack or false, groupAttack = GroupAttack and GroupAttack or false,
@@ -1019,7 +1018,7 @@ function CONTROLLABLE:TaskCarpetBombing(Vec2, GroupAttack, WeaponExpend, AttackQ
weaponType = WeaponType or ENUMS.WeaponFlag.AnyBomb, weaponType = WeaponType or ENUMS.WeaponFlag.AnyBomb,
expend = WeaponExpend or "All", expend = WeaponExpend or "All",
attackQtyLimit = AttackQty and true or false, attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty, attackQty = AttackQty or 1,
directionEnabled = Direction and true or false, directionEnabled = Direction and true or false,
direction = Direction and math.rad(Direction) or 0, direction = Direction and math.rad(Direction) or 0,
altitudeEnabled = Altitude and true or false, altitudeEnabled = Altitude and true or false,