From f9e5785f52a62302d3177ab4dfc7f2e35c1e810a Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 28 Apr 2020 00:42:13 +0200 Subject: [PATCH] Ops --- Moose Development/Moose/Ops/Auftrag.lua | 46 ++++++-- Moose Development/Moose/Ops/FlightGroup.lua | 100 +++++++++--------- .../Moose/Wrapper/Controllable.lua | 3 +- 3 files changed, 90 insertions(+), 59 deletions(-) diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index 42bf6cf22..edae08183 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -342,7 +342,7 @@ AUFTRAG.version="0.2.0" -- TODO: F10 marker to create new missions. -- DONE: Evaluate mission result ==> SUCCESS/FAILURE -- DONE: NewAUTO() NewA2G NewA2A --- TODO: Transport mission. +-- DONE: Transport mission. -- TODO: Recon mission. -- 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.engageWeaponExpend=AI.Task.WeaponExpend.ALL 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.missionTask=ENUMS.MissionTask.GROUNDATTACK mission.missionAltitude=mission.engageAltitude*0.8 - mission.missionFraction=0.2 + mission.missionFraction=0.5 mission.optionROE=ENUMS.ROE.OpenFire mission.optionROT=ENUMS.ROT.NoReaction @@ -1852,6 +1854,29 @@ function AUFTRAG:GetFlightWaypointTask(flightgroup) 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). -- @param #AUFTRAG self @@ -1864,6 +1889,7 @@ function AUFTRAG:CheckFlightsDone() end -- 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 return true end @@ -1876,7 +1902,6 @@ function AUFTRAG:CheckFlightsDone() -- This one is done or cancelled. else -- At least this flight is not DONE or CANCELLED. - --flightdata.status return false end end @@ -1889,21 +1914,28 @@ end -- EVENT Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- Flightgroup event function handling the crash of a unit. +--- Unit lost event. -- @param #AUFTRAG self -- @param Core.Event#EVENTDATA EventData Event data. -function AUFTRAG:OnEventCrash(EventData) +function AUFTRAG:OnEventUnitLost(EventData) -- 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 group=EventData.IniGroup 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 - ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- FSM Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 4e36a1262..b7da936b8 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -789,7 +789,10 @@ function FLIGHTGROUP:RemoveMission(Mission) -- Remove mission waypoint task. local Task=Mission:GetFlightWaypointTask(self) - self:RemoveTask(Task) + + if Task then + self:RemoveTask(Task) + end -- Remove mission from queue. table.remove(self.missionqueue, i) @@ -1608,9 +1611,13 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To) local element=_element --#FLIGHTGROUP.Element 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 @@ -1622,7 +1629,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To) fuelmass=fmass 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.fuelmass=fmass @@ -1686,8 +1693,8 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To) local mission=_mission --Ops.Auftrag#AUFTRAG local Cstart= UTILS.SecondsToClock(mission.Tstart, true) 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", - i, tostring(mission.name), mission.type, mission:GetFlightStatus(self), tostring(mission.status), Cstart, Cstop, mission.prio, mission:CountMissionTargets()) + 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, tostring(mission:GetFlightWaypointIndex(self)), mission:CountMissionTargets()) end self:I(self.lid..text) end @@ -3680,7 +3687,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To, Task) Task.formation:Stop() self:TaskDone(Task) 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) end @@ -3693,6 +3700,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To, Task) self:TaskDone(Task) + --[[ local mission=self:GetMissionByTaskID(Task.id) -- Is this a waypoint task? @@ -3703,6 +3711,7 @@ function FLIGHTGROUP:onafterTaskCancel(From, Event, To, Task) self:RemoveWaypoint(Task.waypoint) end end + ]] end else @@ -3966,7 +3975,17 @@ function FLIGHTGROUP:onafterMissionDone(From, Event, To, Mission) Mission:SetFlightStatus(self, AUFTRAG.FlightStatus.DONE) -- 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. self:_CheckFlightDone(1) @@ -3994,7 +4013,7 @@ function FLIGHTGROUP:RouteToMission(mission, delay) -- Set altitude of mission waypoint. if mission.missionAltitude then - waypointcoord.y=mission.missionAltitude + waypointcoord:SetAltitude(mission.missionAltitude, true) end -- Add enroute tasks. @@ -4008,6 +4027,7 @@ function FLIGHTGROUP:RouteToMission(mission, delay) -- Add waypoint. self:AddWaypointAir(waypointcoord, nextwaypoint, speed, false) + -- Special for Troop transport. if mission.type==AUFTRAG.Type.TROOPTRANSPORT then -- Refresh DCS task with the known controllable. @@ -4032,9 +4052,8 @@ function FLIGHTGROUP:RouteToMission(mission, delay) -- Set waypoint task. mission:SetFlightWaypointTask(self, waypointtask) - -- TODO: better marker text, mission.maker - --mission.marker=waypointcoord:MarkToCoalition(mission.name, self:GetCoalition(), true) - --mission.marker=waypointcoord:MarkToAll(string.format("%s %s %s", mission.name, mission.type, self.groupname), true) + -- Set waypoint index. + mission:SetFlightWaypointIndex(self, nextwaypoint) --- -- Mission Specific Settings @@ -4823,11 +4842,10 @@ end -- @param #number wpnumber Waypoint number. Default at the end. -- @param #number speed Speed in knots. Default 350 kts. -- @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) - -- Waypoint number. - --TODO: by default add after last AIR waypoint! Last WP could be landing... + -- Waypoint number. Default is at the end. wpnumber=wpnumber or #self.waypoints+1 if wpnumber>self.currentwp then @@ -4860,9 +4878,15 @@ function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute) -- Shift all mission waypoints after the inserted waypoint. for _,_mission in pairs(self.missionqueue) do local mission=_mission --Ops.Auftrag#AUFTRAG - if mission.waypointindex and mission.waypointindex>=wpnumber then - mission.waypointindex=mission.waypointindex+1 - end + + -- Get mission waypoint index. + 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 -- Update route. @@ -4870,7 +4894,7 @@ function FLIGHTGROUP:AddWaypointAir(coordinate, wpnumber, speed, updateroute) self:__UpdateRoute(-1) end - return self + return wpnumber end --- Remove a waypoint. @@ -4904,9 +4928,12 @@ function FLIGHTGROUP:RemoveWaypoint(wpindex) for _,_mission in pairs(self.missionqueue) do local mission=_mission --Ops.Auftrag#AUFTRAG - -- TODO: This is not the waypoint index any more. Waypoint index is now for each FLIGHTGROUP. - if mission.waypointindex and mission.waypointindex>wpindex then - mission.waypointindex=mission.waypointindex-1 + -- Get mission waypoint index. + local wpidx=mission:GetFlightWaypointIndex(self) + + -- Reduce number if this waypoint lies in the future. + if wpidx and wpidx>wpindex then + mission:SetFlightWaypointIndex(self, wpidx-1) end end @@ -4933,37 +4960,10 @@ function FLIGHTGROUP:RemoveWaypoint(wpindex) 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 end + --- Check if a unit is an element of the flightgroup. -- @param #FLIGHTGROUP self -- @param #string unitname Name of unit. diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 828188dc9..8661f648a 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -1011,7 +1011,6 @@ function CONTROLLABLE:TaskCarpetBombing(Vec2, GroupAttack, WeaponExpend, AttackQ id = 'CarpetBombing', params = { attackType = "Carpet", - point = Vec2, x = Vec2.x, y = Vec2.y, groupAttack = GroupAttack and GroupAttack or false, @@ -1019,7 +1018,7 @@ function CONTROLLABLE:TaskCarpetBombing(Vec2, GroupAttack, WeaponExpend, AttackQ weaponType = WeaponType or ENUMS.WeaponFlag.AnyBomb, expend = WeaponExpend or "All", attackQtyLimit = AttackQty and true or false, - attackQty = AttackQty, + attackQty = AttackQty or 1, directionEnabled = Direction and true or false, direction = Direction and math.rad(Direction) or 0, altitudeEnabled = Altitude and true or false,