- Fixed a couple of minor bugs.
- FC added _PlayerAbortInbound function
This commit is contained in:
Frank 2021-10-05 23:59:24 +02:00
parent 1790d19809
commit 5dbf743052
8 changed files with 98 additions and 25 deletions

View File

@ -2077,6 +2077,9 @@ function AUFTRAG:SetRequiredEscorts(NescortMin, NescortMax)
self.NescortMax=self.NescortMin self.NescortMax=self.NescortMin
end end
-- Debug info.
self:T(self.lid..string.format("NescortMin=%s, NescortMax=%s", tostring(self.NescortMin), tostring(self.NescortMax)))
return self return self
end end

View File

@ -1448,7 +1448,15 @@ function CHIEF:CheckTargetQueue()
-- * how many assets are still in stock -- * how many assets are still in stock
-- * is it inside of our border -- * is it inside of our border
local NassetsMin=1 local NassetsMin=1
local NassetsMax=3 local NassetsMax=1
if target.threatlevel0>=8 then
NassetsMax=3
elseif target.threatlevel0>=5 then
NassetsMax=2
else
NassetsMax=1
end
for _,_mp in pairs(MissionPerformances) do for _,_mp in pairs(MissionPerformances) do
local mp=_mp --#CHIEF.MissionPerformance local mp=_mp --#CHIEF.MissionPerformance

View File

@ -668,7 +668,7 @@ function COMMANDER:onafterStatus(From, Event, To)
state=asset.flightgroup:GetState() state=asset.flightgroup:GetState()
local mission=legion:GetAssetCurrentMission(asset) local mission=legion:GetAssetCurrentMission(asset)
if mission then if mission then
state=state..string.format("Mission %s [%s]", mission:GetName(), mission:GetType()) state=state..string.format(", Mission \"%s\" [%s]", mission:GetName(), mission:GetType())
end end
else else
if asset.spawned then if asset.spawned then
@ -1023,7 +1023,7 @@ end
function COMMANDER:RecruitAssetsForMission(Mission) function COMMANDER:RecruitAssetsForMission(Mission)
-- Debug info. -- Debug info.
env.info(string.format("FF recruiting assets for mission %s [%s]", Mission:GetName(), Mission:GetType())) self:T2(self.lid..string.format("Recruiting assets for mission \"%s\" [%s]", Mission:GetName(), Mission:GetType()))
-- Cohorts. -- Cohorts.
local Cohorts={} local Cohorts={}
@ -1102,7 +1102,7 @@ function COMMANDER:RecruitAssetsForEscort(Mission, Assets)
-- Call LEGION function but provide COMMANDER as self. -- Call LEGION function but provide COMMANDER as self.
local assigned=LEGION.AssignAssetsForEscort(self, Cohorts, Assets, Mission.NescortMin, Mission.NescortMin) local assigned=LEGION.AssignAssetsForEscort(self, Cohorts, Assets, Mission.NescortMin, Mission.NescortMax)
return assigned return assigned
end end

View File

@ -90,6 +90,7 @@ FLIGHTCONTROL = {
--- Parking spot data. --- Parking spot data.
-- @type FLIGHTCONTROL.FlightStatus -- @type FLIGHTCONTROL.FlightStatus
-- @field #string UNKNOWN Flight state is unknown.
-- @field #string INBOUND Flight is inbound. -- @field #string INBOUND Flight is inbound.
-- @field #string HOLDING Flight is holding. -- @field #string HOLDING Flight is holding.
-- @field #string LANDING Flight is landing. -- @field #string LANDING Flight is landing.
@ -99,6 +100,7 @@ FLIGHTCONTROL = {
-- @field #string READYTO Flight is ready for takeoff. -- @field #string READYTO Flight is ready for takeoff.
-- @field #string TAKEOFF Flight is taking off. -- @field #string TAKEOFF Flight is taking off.
FLIGHTCONTROL.FlightStatus={ FLIGHTCONTROL.FlightStatus={
UNKNOWN="Unknown",
INBOUND="Inbound", INBOUND="Inbound",
HOLDING="Holding", HOLDING="Holding",
LANDING="Landing", LANDING="Landing",
@ -924,7 +926,10 @@ function FLIGHTCONTROL:_RemoveFlightFromQueue(queue, flight, queuename)
table.remove(queue, i) table.remove(queue, i)
if not flight.isAI then if not flight.isAI then
flight:_UpdateMenu() if flight.flightcontrol and flight.flightcontrol.airbasename==self.airbasename then
flight.flightcontrol=nil
end
flight:_UpdateMenu(0.1)
end end
return true, i return true, i
@ -1413,7 +1418,7 @@ function FLIGHTCONTROL:_CreatePlayerMenu(flight, atcmenu)
local airbaseName=airbasename local airbaseName=airbasename
local airbaseName2=airbaseName local airbaseName2=airbaseName
if gotcontrol then if gotcontrol then
airbaseName2=airbaseName2.." *" --airbaseName2=airbaseName2.." *"
end end
local Tag=airbasename local Tag=airbasename
local Tnow=timer.getTime() local Tnow=timer.getTime()
@ -1467,6 +1472,10 @@ function FLIGHTCONTROL:_CreatePlayerMenu(flight, atcmenu)
end end
if flight:IsInbound() or flight:IsHolding() or flight:IsLanding() or flight:IsLanded() then
MENU_GROUP_COMMAND_DELAYED:New(group, "Abort Inbound", rootmenu, self._PlayerAbortInbound, self, groupname):SetTime(Tnow):SetTag(Tag)
end
if flight:IsInbound() or flight:IsHolding() or flight:IsLanding() or flight:IsLanded() then if flight:IsInbound() or flight:IsHolding() or flight:IsLanding() or flight:IsLanded() then
MENU_GROUP_COMMAND_DELAYED:New(group, "Request Parking", rootmenu, self._PlayerRequestParking, self, groupname):SetTime(Tnow):SetTag(Tag) MENU_GROUP_COMMAND_DELAYED:New(group, "Request Parking", rootmenu, self._PlayerRequestParking, self, groupname):SetTime(Tnow):SetTag(Tag)
end end
@ -1692,7 +1701,7 @@ function FLIGHTCONTROL:_PlayerHolding(groupname)
local text=string.format("Roger, you are added to the holding queue!") local text=string.format("Roger, you are added to the holding queue!")
MESSAGE:New(text, 5):ToGroup(flight.group) MESSAGE:New(text, 5):ToGroup(flight.group)
-- Call holding event. -- Call holding event. Updates the menu.
flight:Holding() flight:Holding()
else else
@ -1841,6 +1850,40 @@ function FLIGHTCONTROL:_PlayerAbortTakeoff(groupname)
end end
--- Player wants to abort inbound.
-- @param #FLIGHTCONTROL self
-- @param #string groupname Name of the flight group.
function FLIGHTCONTROL:_PlayerAbortInbound(groupname)
MESSAGE:New("Abort inbound", 5):ToAll()
local flight=_DATABASE:GetOpsGroup(groupname)
if flight then
local flightstatus=self:GetFlightStatus(flight)
if flightstatus==FLIGHTCONTROL.FlightStatus.INBOUND or flightstatus==FLIGHTCONTROL.FlightStatus.HOLDING or flightstatus==FLIGHTCONTROL.FlightStatus.LANDING then
MESSAGE:New("Afirm, You are removed from all queues queue", 5):ToAll()
--TODO: what now? taxi inbound? or just another later attempt to takeoff.
self:SetFlightStatus(flight,FLIGHTCONTROL.FlightStatus.UNKNOWN)
-- Remove flight.
self:_RemoveFlight(flight)
-- Trigger cruise event.
flight:Cruise()
else
MESSAGE:New("Negative, You are NOT in the state INBOUND, HOLDING or LANDING!", 5):ToAll()
end
end
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Flight and Element Functions -- Flight and Element Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -1545,6 +1545,8 @@ function FLIGHTGROUP:onafterSpawned(From, Event, To)
else else
env.info("FF Spawned update menu")
-- F10 other menu. -- F10 other menu.
self:_UpdateMenu() self:_UpdateMenu()
@ -1695,7 +1697,7 @@ function FLIGHTGROUP:onafterCruise(From, Event, To)
-- CLIENT -- CLIENT
--- ---
self:_UpdateMenu() self:_UpdateMenu(0.1)
end end
@ -3218,7 +3220,7 @@ end
-- @return #boolean Hot start? -- @return #boolean Hot start?
function FLIGHTGROUP:IsTakeoffHot() function FLIGHTGROUP:IsTakeoffHot()
local wp=self:GetWaypoint(1) local wp=self.waypoints0 and self.waypoints0[1] or nil --self:GetWaypoint(1)
if wp then if wp then
@ -3238,7 +3240,7 @@ end
-- @return #boolean Cold start, i.e. engines off when spawned? -- @return #boolean Cold start, i.e. engines off when spawned?
function FLIGHTGROUP:IsTakeoffCold() function FLIGHTGROUP:IsTakeoffCold()
local wp=self:GetWaypoint(1) local wp=self.waypoints0 and self.waypoints0[1] or nil --self:GetWaypoint(1)
if wp then if wp then
@ -3258,7 +3260,7 @@ end
-- @return #boolean Runway start? -- @return #boolean Runway start?
function FLIGHTGROUP:IsTakeoffRunway() function FLIGHTGROUP:IsTakeoffRunway()
local wp=self:GetWaypoint(1) local wp=self.waypoints0 and self.waypoints0[1] or nil --self:GetWaypoint(1)
if wp then if wp then
@ -3278,7 +3280,7 @@ end
-- @return #boolean Air start? -- @return #boolean Air start?
function FLIGHTGROUP:IsTakeoffAir() function FLIGHTGROUP:IsTakeoffAir()
local wp=self:GetWaypoint(1) local wp=self.waypoints0 and self.waypoints0[1] or nil --self:GetWaypoint(1)
if wp then if wp then
@ -4010,20 +4012,29 @@ function FLIGHTGROUP:_UpdateMenu(delay)
end end
table.sort(fc, _sort) table.sort(fc, _sort)
for _,_menu in pairs(self.menu.atc or {}) do
local menu=_menu
end
-- If there is a designated FC, we put it first. -- If there is a designated FC, we put it first.
local N=8 local N=8
local gotairbase=nil
if self.flightcontrol then if self.flightcontrol then
self.flightcontrol:_CreatePlayerMenu(self, self.menu.atc) self.flightcontrol:_CreatePlayerMenu(self, self.menu.atc)
gotairbase=self.flightcontrol.airbasename
N=7 N=7
end end
-- Max 8 entries in F10 menu. -- Max 8 entries in F10 menu.
for i=1,math.min(#fc,N) do for i=1,math.min(#fc,N) do
local airbasename=fc[i].airbasename local airbasename=fc[i].airbasename
if gotairbase==nil or airbasename~=gotairbase then
local flightcontrol=_DATABASE:GetFlightControl(airbasename) local flightcontrol=_DATABASE:GetFlightControl(airbasename)
flightcontrol:_CreatePlayerMenu(self, self.menu.atc) flightcontrol:_CreatePlayerMenu(self, self.menu.atc)
end end
end end
end
end end

View File

@ -710,6 +710,7 @@ end
-- @param #table RecceDetecting Table of detecting recce names -- @param #table RecceDetecting Table of detecting recce names
function INTEL:CreateDetectedItems(DetectedGroups, RecceDetecting) function INTEL:CreateDetectedItems(DetectedGroups, RecceDetecting)
self:F({RecceDetecting=RecceDetecting}) self:F({RecceDetecting=RecceDetecting})
-- Current time. -- Current time.
local Tnow=timer.getAbsTime() local Tnow=timer.getAbsTime()
@ -750,7 +751,10 @@ function INTEL:CreateDetectedItems(DetectedGroups, RecceDetecting)
item.velocity=group:GetVelocityVec3() item.velocity=group:GetVelocityVec3()
item.speed=group:GetVelocityMPS() item.speed=group:GetVelocityMPS()
item.recce=RecceDetecting[groupname] item.recce=RecceDetecting[groupname]
-- Debug info.
self:T(string.format("%s group detect by %s/%s", groupname, RecceDetecting[groupname] or "unknown", item.recce or "unknown")) self:T(string.format("%s group detect by %s/%s", groupname, RecceDetecting[groupname] or "unknown", item.recce or "unknown"))
-- Add contact to table. -- Add contact to table.
self:AddContact(item) self:AddContact(item)

View File

@ -1833,7 +1833,7 @@ function LEGION:RecruitAssetsForEscort(Mission, Assets)
if Mission.NescortMin and Mission.NescortMax and (Mission.NescortMin>0 or Mission.NescortMax>0) then if Mission.NescortMin and Mission.NescortMax and (Mission.NescortMin>0 or Mission.NescortMax>0) then
-- Debug info. -- Debug info.
self:I(self.lid..string.format("Reqested escort for mission %s [%s]. Required assets=%d-%d", Mission:GetName(), Mission:GetType(), Mission.NescortMin,Mission.NescortMax)) self:I(self.lid..string.format("Requested escort for mission %s [%s]. Required assets=%d-%d", Mission:GetName(), Mission:GetType(), Mission.NescortMin,Mission.NescortMax))
-- Get special escort legions and/or cohorts. -- Get special escort legions and/or cohorts.
local Cohorts={} local Cohorts={}
@ -1855,7 +1855,7 @@ function LEGION:RecruitAssetsForEscort(Mission, Assets)
end end
-- Call LEGION function but provide COMMANDER as self. -- Call LEGION function but provide COMMANDER as self.
local assigned=LEGION.AssignAssetsForEscort(self, Cohorts, Assets, Mission.NescortMin, Mission.NescortMin) local assigned=LEGION.AssignAssetsForEscort(self, Cohorts, Assets, Mission.NescortMin, Mission.NescortMax)
return assigned return assigned
end end
@ -2083,7 +2083,7 @@ function LEGION:AssignAssetsForEscort(Cohorts, Assets, NescortMin, NescortMax)
if NescortMin and NescortMax and (NescortMin>0 or NescortMax>0) then if NescortMin and NescortMax and (NescortMin>0 or NescortMax>0) then
-- Debug info. -- Debug info.
self:I(self.lid..string.format("Reqested escort for %d assets from %d cohorts. Required escort assets=%d-%d", #Assets, #Cohorts, NescortMin, NescortMax)) self:T(self.lid..string.format("Requested escort for %d assets from %d cohorts. Required escort assets=%d-%d", #Assets, #Cohorts, NescortMin, NescortMax))
-- Escorts for each asset. -- Escorts for each asset.
local Escorts={} local Escorts={}
@ -2153,14 +2153,14 @@ function LEGION:AssignAssetsForEscort(Cohorts, Assets, NescortMin, NescortMax)
end end
-- Debug info. -- Debug info.
self:I(self.lid..string.format("Recruited %d escort assets", N)) self:T(self.lid..string.format("Recruited %d escort assets", N))
-- Yup! -- Yup!
return true return true
else else
-- Debug info. -- Debug info.
self:I(self.lid..string.format("Could not get at least one escort!")) self:T(self.lid..string.format("Could not get at least one escort!"))
-- Could not get at least one escort. Unrecruit all recruited ones. -- Could not get at least one escort. Unrecruit all recruited ones.
for groupname,value in pairs(Escorts) do for groupname,value in pairs(Escorts) do
@ -2174,6 +2174,7 @@ function LEGION:AssignAssetsForEscort(Cohorts, Assets, NescortMin, NescortMax)
else else
-- No escort required. -- No escort required.
self:T(self.lid..string.format("No escort required! NescortMin=%s, NescortMax=%s", tostring(NescortMin), tostring(NescortMax)))
return true return true
end end
@ -2392,6 +2393,7 @@ function LEGION._OptimizeAssetSelection(assets, MissionType, TargetVec2, Include
table.sort(assets, optimize) table.sort(assets, optimize)
-- Remove distance parameter. -- Remove distance parameter.
--[[
local text=string.format("Optimized %d assets for %s mission/transport (payload=%s):", #assets, MissionType, tostring(IncludePayload)) local text=string.format("Optimized %d assets for %s mission/transport (payload=%s):", #assets, MissionType, tostring(IncludePayload))
for i,Asset in pairs(assets) do for i,Asset in pairs(assets) do
local asset=Asset --Functional.Warehouse#WAREHOUSE.Assetitem local asset=Asset --Functional.Warehouse#WAREHOUSE.Assetitem
@ -2399,6 +2401,7 @@ function LEGION._OptimizeAssetSelection(assets, MissionType, TargetVec2, Include
asset.score=nil asset.score=nil
end end
env.info(text) env.info(text)
]]
end end

View File

@ -3469,7 +3469,8 @@ function OPSGROUP:onbeforeTaskExecute(From, Event, To, Task)
-- Group is already waiting -- Group is already waiting
else else
-- Wait indefinately. -- Wait indefinately.
self:Wait() local alt=Mission.missionAltitude and UTILS.MetersToFeet(Mission.missionAltitude) or nil
self:Wait(nil, alt)
end end
-- Time to for the next try. Best guess is when push time is reached or 20 sec when push conditions are not true yet. -- Time to for the next try. Best guess is when push time is reached or 20 sec when push conditions are not true yet.
@ -8762,7 +8763,7 @@ end
function OPSGROUP:_InitWaypoints(WpIndexMin, WpIndexMax) function OPSGROUP:_InitWaypoints(WpIndexMin, WpIndexMax)
-- Template waypoints. -- Template waypoints.
self.waypoints0=self.group:GetTemplateRoutePoints() self.waypoints0=UTILS.DeepCopy(_DATABASE:GetGroupTemplate(self.groupname).route.points) --self.group:GetTemplateRoutePoints()
-- Waypoints empty! -- Waypoints empty!
self.waypoints={} self.waypoints={}
@ -10904,7 +10905,7 @@ function OPSGROUP:_AddElementByName(unitname)
local text=string.format("Adding element %s: status=%s, skill=%s, life=%.1f/%.1f category=%s (%d), type=%s, size=%.1f (L=%.1f H=%.1f W=%.1f), weight=%.1f/%.1f (cargo=%.1f/%.1f)", local text=string.format("Adding element %s: status=%s, skill=%s, life=%.1f/%.1f category=%s (%d), type=%s, size=%.1f (L=%.1f H=%.1f W=%.1f), weight=%.1f/%.1f (cargo=%.1f/%.1f)",
element.name, element.status, element.skill, element.life, element.life0, element.categoryname, element.category, element.typename, element.name, element.status, element.skill, element.life, element.life0, element.categoryname, element.category, element.typename,
element.size, element.length, element.height, element.width, element.weight, element.weightMaxTotal, element.weightCargo, element.weightMaxCargo) element.size, element.length, element.height, element.width, element.weight, element.weightMaxTotal, element.weightCargo, element.weightMaxCargo)
self:I(self.lid..text) self:T(self.lid..text)
-- Add element to table. -- Add element to table.
if not self:_IsElement(unitname) then if not self:_IsElement(unitname) then
@ -10930,7 +10931,7 @@ end
function OPSGROUP:_SetTemplate(Template) function OPSGROUP:_SetTemplate(Template)
-- Set the template. -- Set the template.
self.template=Template or self.group:GetTemplate() self.template=Template or UTILS.DeepCopy(_DATABASE:GetGroupTemplate(self.groupname)) --self.group:GetTemplate()
-- Debug info. -- Debug info.
self:T3(self.lid.."Setting group template") self:T3(self.lid.."Setting group template")