This commit is contained in:
Frank 2021-08-02 11:57:45 +02:00
parent d64de26ded
commit 1a53f58540
9 changed files with 204 additions and 77 deletions

View File

@ -2647,6 +2647,25 @@ function WAREHOUSE:_CheckParkingValid(spot)
return false
end
--- Check parking ID for an asset.
-- @param #WAREHOUSE self
-- @param Wrapper.Airbase#AIRBASE.ParkingSpot spot Parking spot.
-- @return #boolean If true, parking is valid.
function WAREHOUSE:_CheckParkingAsset(spot, asset)
if asset.parkingIDs==nil then
return true
end
for _,id in pairs(asset.parkingIDs or {}) do
if spot.TerminalID==id then
return true
end
end
return false
end
--- Enable auto save of warehouse assets at mission end event.
-- @param #WAREHOUSE self
@ -7848,7 +7867,7 @@ function WAREHOUSE:_FindParkingForAssets(airbase, assets)
local parkingspot=_parkingspot --Wrapper.Airbase#AIRBASE.ParkingSpot
-- Check correct terminal type for asset. We don't want helos in shelters etc.
if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) and self:_CheckParkingValid(parkingspot) and airbase:_CheckParkingLists(parkingspot.TerminalID) then
if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) and self:_CheckParkingValid(parkingspot) and self:_CheckParkingAsset(parkingspot, asset) and airbase:_CheckParkingLists(parkingspot.TerminalID) then
-- Coordinate of the parking spot.
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE

View File

@ -155,7 +155,7 @@ AIRWING = {
--- AIRWING class version.
-- @field #string version
AIRWING.version="0.6.0"
AIRWING.version="0.7.0"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ToDo list
@ -745,6 +745,11 @@ end
-- @return #AIRWING.PatrolData Patrol point table.
function AIRWING:NewPatrolPoint(Type, Coordinate, Altitude, Speed, Heading, LegLength, RefuelSystem)
-- Check if a zone was passed instead of a coordinate.
if Coordinate:IsInstanceOf("ZONE_BASE") then
Coordinate=Coordinate:GetCoordinate()
end
local patrolpoint={} --#AIRWING.PatrolData
patrolpoint.type=Type or "Unknown"
patrolpoint.coord=Coordinate or self:GetCoordinate():Translate(UTILS.NMToMeters(math.random(10, 15)), math.random(360))
@ -994,7 +999,7 @@ function AIRWING:CheckTANKER()
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
if mission:IsNotOver() and mission.type==AUFTRAG.Type.TANKER then
if mission:IsNotOver() and mission.type==AUFTRAG.Type.TANKER and mission.patroldata then
if mission.refuelSystem==Unit.RefuelingSystem.BOOM_AND_RECEPTACLE then
Nboom=Nboom+1
elseif mission.refuelSystem==Unit.RefuelingSystem.PROBE_AND_DROGUE then
@ -1567,6 +1572,9 @@ function AIRWING:onafterNewAsset(From, Event, To, asset, assignment)
-- Set takeoff type.
asset.takeoffType=squad.takeoffType
-- Set parking IDs.
asset.parkingIDs=squad.parkingIDs
-- Create callsign and modex (needs to be after grouping).
squad:GetCallsign(asset)
squad:GetModex(asset)
@ -2032,6 +2040,23 @@ function AIRWING:CountAssets()
return N
end
--- Count total number of assets that are in the warehouse stock (not spawned).
-- @param #AIRWING self
-- @param #table MissionTypes (Optional) Count only assest that can perform certain mission type(s). Default is all types.
-- @return #number Amount of asset groups in stock.
function AIRWING:CountAssetsInStock(MissionTypes)
local N=0
for _,_squad in pairs(self.squadrons) do
local squad=_squad --Ops.Squadron#SQUADRON
N=N+squad:CountAssetsInStock(MissionTypes)
end
return N
end
--- Count assets on mission.
-- @param #AIRWING self
-- @param #table MissionTypes Types on mission to be checked. Default all.

View File

@ -3601,6 +3601,8 @@ function AIRBOSS:_CheckAIStatus()
-- Unit
local unit=element.unit
if unit and unit:IsAlive() then
-- Get lineup and distance to carrier.
local lineup=self:_Lineup(unit, true)
@ -3632,6 +3634,7 @@ function AIRBOSS:_CheckAIStatus()
-- This is for the whole flight. Maybe we need it.
flight.ballcall=true
end
end
end
end

View File

@ -53,8 +53,9 @@
-- @field #number dTevaluate Time interval in seconds before the mission result is evaluated after mission is over.
-- @field #number Tover Mission abs. time stamp, when mission was over.
-- @field #table conditionStart Condition(s) that have to be true, before the mission will be started.
-- @field #table conditionSuccess If all stop conditions are true, the mission is cancelled.
-- @field #table conditionFailure If all stop conditions are true, the mission is cancelled.
-- @field #table conditionSuccess If all conditions are true, the mission is cancelled.
-- @field #table conditionFailure If all conditions are true, the mission is cancelled.
-- @field #table conditionPush If all conditions are true, the mission is executed. Before, the group(s) wait at the mission execution waypoint.
--
-- @field #number orbitSpeed Orbit speed in m/s.
-- @field #number orbitAltitude Orbit altitude in meters.
@ -288,6 +289,7 @@ AUFTRAG = {
conditionStart = {},
conditionSuccess = {},
conditionFailure = {},
conditionPush = {},
}
--- Global mission counter.
@ -445,7 +447,7 @@ AUFTRAG.TargetType={
--- AUFTRAG class version.
-- @field #string version
AUFTRAG.version="0.7.0"
AUFTRAG.version="0.7.1"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@ -1825,6 +1827,26 @@ function AUFTRAG:AddConditionFailure(ConditionFunction, ...)
return self
end
--- Add push condition.
-- @param #AUFTRAG self
-- @param #function ConditionFunction If this function returns `true`, the mission is executed.
-- @param ... Condition function arguments if any.
-- @return #AUFTRAG self
function AUFTRAG:AddConditionPush(ConditionFunction, ...)
local condition={} --#AUFTRAG.Condition
condition.func=ConditionFunction
condition.arg={}
if arg then
condition.arg=arg
end
table.insert(self.conditionPush, condition)
return self
end
--- Assign airwing squadron(s) to the mission. Only these squads will be considered for the job.
-- @param #AUFTRAG self
@ -1983,12 +2005,12 @@ function AUFTRAG:IsReadyToGo()
local Tnow=timer.getAbsTime()
-- Start time did not pass yet.
if self.Tstart and Tnow<self.Tstart or false then
if self.Tstart and Tnow<self.Tstart then
return false
end
-- Stop time already passed.
if self.Tstop and Tnow>self.Tstop or false then
if self.Tstop and Tnow>self.Tstop then
return false
end
@ -2014,7 +2036,7 @@ function AUFTRAG:IsReadyToCancel()
local Tnow=timer.getAbsTime()
-- Stop time already passed.
if self.Tstop and Tnow>self.Tstop then
if self.Tstop and Tnow>=self.Tstop then
return true
end
@ -2038,6 +2060,26 @@ function AUFTRAG:IsReadyToCancel()
return false
end
--- Check if mission is ready to be pushed.
-- * Mission push time already passed.
-- * All push conditions are true.
-- @param #AUFTRAG self
-- @return #boolean If true, mission groups can push.
function AUFTRAG:IsReadyToPush()
local Tnow=timer.getAbsTime()
-- Push time passed?
if self.Tpush and Tnow<self.Tpush then
return false
end
-- Evaluate push condition(s) if any. All need to be true.
local push=self:EvalConditionsAll(self.conditionPush)
return push
end
--- Check if all given condition are true.
-- @param #AUFTRAG self
-- @param #table Conditions Table of conditions.

View File

@ -823,10 +823,10 @@ function FLIGHTGROUP:onbeforeStatus(From, Event, To)
-- This one is dead.
if isdead then
local text=string.format("Element %s is dead at t=%.3f! Maybe despawned without notice or landed at a too small airbase. Calling ElementDead in 60 sec to give other events a chance",
tostring(element.name), timer.getTime())
local text=string.format("Element %s is dead at t=%.3f but has status %s! Maybe despawned without notice or landed at a too small airbase. Calling ElementDead in 60 sec to give other events a chance",
tostring(element.name), timer.getTime(), tostring(element.status))
self:E(self.lid..text)
--self:__ElementDead(60, element)
self:__ElementDead(60, element)
end
end
@ -925,6 +925,8 @@ function FLIGHTGROUP:onafterStatus(From, Event, To)
local unit=element.unit
local fuel=unit:GetFuel() or 0
local life=unit:GetLifeRelative() or 0
local lp=unit:GetLife()
local lp0=unit:GetLife0()
local parking=element.parking and tostring(element.parking.TerminalID) or "X"
-- Check if element is not dead and we missed an event.
@ -936,8 +938,8 @@ function FLIGHTGROUP:onafterStatus(From, Event, To)
local ammo=self:GetAmmoElement(element)
-- Output text for element.
text=text..string.format("\n[%d] %s: status=%s, fuel=%.1f, life=%.1f, guns=%d, rockets=%d, bombs=%d, missiles=%d (AA=%d, AG=%d, AS=%s), parking=%s",
i, name, status, fuel*100, life*100, ammo.Guns, ammo.Rockets, ammo.Bombs, ammo.Missiles, ammo.MissilesAA, ammo.MissilesAG, ammo.MissilesAS, parking)
text=text..string.format("\n[%d] %s: status=%s, fuel=%.1f, life=%.1f [%.1f/%.1f], guns=%d, rockets=%d, bombs=%d, missiles=%d (AA=%d, AG=%d, AS=%s), parking=%s",
i, name, status, fuel*100, life*100, lp, lp0, ammo.Guns, ammo.Rockets, ammo.Bombs, ammo.Missiles, ammo.MissilesAA, ammo.MissilesAG, ammo.MissilesAS, parking)
end
if #self.elements==0 then
text=text.." none!"

View File

@ -2932,17 +2932,19 @@ function OPSGROUP:onbeforeTaskExecute(From, Event, To, Task)
-- Get mission of this task (if any).
local Mission=self:GetMissionByTaskID(Task.id)
if Mission then
if Mission and (Mission.Tpush or #Mission.conditionPush>0) then
if Mission.Tpush then
if Mission:IsReadyToPush() then
local Tnow=timer.getAbsTime()
-- Not waiting any more.
self.Twaiting=nil
self.dTwait=nil
-- Time to push
local dt=Mission.Tpush-Tnow
else
-- Push time not reached.
if Tnow<Mission.Tpush then
---
-- Not ready to push yet
---
if self:IsWaiting() then
-- Group is already waiting
@ -2950,25 +2952,22 @@ function OPSGROUP:onbeforeTaskExecute(From, Event, To, Task)
self:Wait()
end
-- Time to for the next try.
local dt=Mission.Tpush and Mission.Tpush-timer.getAbsTime() or 20
-- Debug info.
self:T(self.lid..string.format("Mission %s task execute suspended for %d seconds", Mission.name, dt))
-- Reexecute task.
self:__TaskExecute(-dt, Task)
-- Deny transition.
return false
else
-- Not waiting any more.
self.Twaiting=nil
self.dTwait=nil
end
end
else
--env.info("FF no mission task execute")
end
return true
end

View File

@ -150,7 +150,7 @@ _OPSTRANSPORTID=0
--- Army Group version.
-- @field #string version
OPSTRANSPORT.version="0.1.0"
OPSTRANSPORT.version="0.3.0"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list

View File

@ -46,6 +46,7 @@
-- @field #number radioFreq Radio frequency in MHz the squad uses.
-- @field #number radioModu Radio modulation the squad uses.
-- @field #number takeoffType Take of type.
-- @field #table parkingIDs Parking IDs for this squadron.
-- @extends Core.Fsm#FSM
--- *It is unbelievable what a squadron of twelve aircraft did to tip the balance.* -- Adolf Galland
@ -88,7 +89,7 @@ SQUADRON = {
--- SQUADRON class version.
-- @field #string version
SQUADRON.version="0.5.2"
SQUADRON.version="0.7.0"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@ -136,7 +137,6 @@ function SQUADRON:New(TemplateGroupName, Ngroups, SquadronName)
self.Ngroups=Ngroups or 3
self:SetMissionRange()
self:SetSkill(AI.Skill.GOOD)
--self:SetVerbosity(0)
-- Everyone can ORBIT.
self:AddMissionCapability(AUFTRAG.Type.ORBIT)
@ -284,6 +284,18 @@ function SQUADRON:SetGrouping(nunits)
return self
end
--- Set valid parking spot IDs. Assets of this squad are only allowed to be spawned at these parking spots. **Note** that the IDs are different from the ones displayed in the mission editor!
-- @param #SQUADRON self
-- @param #table ParkingIDs Table of parking ID numbers or a single `#number`.
-- @return #SQUADRON self
function SQUADRON:SetParkingIDs(ParkingIDs)
if type(ParkingIDs)~="table" then
ParkingIDs={ParkingIDs}
end
self.parkingIDs=ParkingIDs
return self
end
--- Set takeoff type. All assets of this squadron will be spawned with cold (default) or hot engines.
-- Spawning on runways is not supported.
@ -876,8 +888,9 @@ end
--- Count assets in airwing (warehous) stock.
-- @param #SQUADRON self
-- @param #table MissionTypes (Optional) Count only assest that can perform certain mission type(s). Default is all types.
-- @return #number Assets not spawned.
function SQUADRON:CountAssetsInStock()
function SQUADRON:CountAssetsInStock(MissionTypes)
local N=0
for _,_asset in pairs(self.assets) do
@ -885,9 +898,11 @@ function SQUADRON:CountAssetsInStock()
if asset.spawned then
else
if MissionTypes==nil or self:CheckMissionCapability(MissionTypes, self.missiontypes) then
N=N+1
end
end
end
return N
end
@ -1063,17 +1078,23 @@ end
--- Check if a mission type is contained in a list of possible capabilities.
-- @param #SQUADRON self
-- @param #string MissionType The requested mission type.
-- @param #table MissionTypes The requested mission type. Can also be passed as a single mission type `#string`.
-- @param #table Capabilities A table with possible capabilities.
-- @return #boolean If true, the requested mission type is part of the possible mission types.
function SQUADRON:CheckMissionCapability(MissionType, Capabilities)
function SQUADRON:CheckMissionCapability(MissionTypes, Capabilities)
if type(MissionTypes)~="table" then
MissionTypes={MissionTypes}
end
for _,cap in pairs(Capabilities) do
local capability=cap --Ops.Auftrag#AUFTRAG.Capability
for _,MissionType in pairs(MissionTypes) do
if capability.MissionType==MissionType then
return true
end
end
end
return false
end

View File

@ -128,7 +128,7 @@ _TARGETID=0
--- TARGET class version.
-- @field #string version
TARGET.version="0.3.1"
TARGET.version="0.5.0"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@ -231,12 +231,24 @@ end
-- User functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Create target data from a given object.
--- Create target data from a given object. Valid objects are:
--
-- * GROUP
-- * UNIT
-- * STATIC
-- * AIRBASE
-- * COORDINATE
-- * ZONE
-- * SET_GROUP
-- * SET_UNIT
-- * SET_STATIC
-- * SET_OPSGROUP
--
-- @param #TARGET self
-- @param Wrapper.Positionable#POSITIONABLE Object The target GROUP, UNIT, STATIC, AIRBASE or COORDINATE.
function TARGET:AddObject(Object)
if Object:IsInstanceOf("SET_GROUP") or Object:IsInstanceOf("SET_UNIT") then
if Object:IsInstanceOf("SET_GROUP") or Object:IsInstanceOf("SET_UNIT") or Object:IsInstanceOf("SET_STATIC") or Object:IsInstanceOf("SET_OPSGROUP") then
---
-- Sets
@ -254,7 +266,11 @@ function TARGET:AddObject(Object)
-- Groups, Units, Statics, Airbases, Coordinates
---
if Object:IsInstanceOf("OPSGROUP") then
self:_AddObject(Object:GetGroup()) -- We add the MOOSE GROUP object not the OPSGROUP object.
else
self:_AddObject(Object)
end
end