Merge pull request #1174 from FlightControl-Master/FF/Develop

MISC Fixes and Improvements
This commit is contained in:
Frank 2019-06-26 19:56:15 +02:00 committed by GitHub
commit ab1ba9595d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 849 additions and 250 deletions

View File

@ -1095,7 +1095,7 @@ do -- AI_A2A_DISPATCHER
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
self:ParkDefender( Squadron, Defender )
self:ParkDefender( Squadron )
return
end
if DefenderUnit:GetLife() ~= DefenderUnit:GetLife0() then
@ -1122,7 +1122,7 @@ do -- AI_A2A_DISPATCHER
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
self:ParkDefender( Squadron, Defender )
self:ParkDefender( Squadron )
end
end
end
@ -2873,7 +2873,7 @@ do -- AI_A2A_DISPATCHER
if Dispatcher:GetSquadronLanding( Squadron.Name ) == AI_A2A_DISPATCHER.Landing.NearAirbase then
Dispatcher:RemoveDefenderFromSquadron( Squadron, Defender )
Defender:Destroy()
self:ParkDefender( Squadron, Defender )
Dispatcher:ParkDefender( Squadron )
end
end
end
@ -3060,7 +3060,7 @@ do -- AI_A2A_DISPATCHER
if Dispatcher:GetSquadronLanding( Squadron.Name ) == AI_A2A_DISPATCHER.Landing.NearAirbase then
Dispatcher:RemoveDefenderFromSquadron( Squadron, Defender )
Defender:Destroy()
self:ParkDefender( Squadron, Defender )
Dispatcher:ParkDefender( Squadron )
end
end
end -- if DefenderGCI then

View File

@ -1102,7 +1102,7 @@ function AI_FORMATION:onenterFollowing( FollowGroupSet ) --R2.1
if FollowGroup:GetState( FollowGroup, "Mode" ) == self.__Enum.Mode.Formation then
self:I({Mode=FollowGroup:GetState( FollowGroup, "Mode" )})
self:T({Mode=FollowGroup:GetState( FollowGroup, "Mode" )})
FollowGroup:OptionROTEvadeFire()
FollowGroup:OptionROEReturnFire()

View File

@ -1571,6 +1571,35 @@ do -- SET_GROUP
return Count
end
--- Iterate the SET_GROUP and count how many GROUPs and UNITs are alive.
-- @param #SET_GROUP self
-- @return #number The number of GROUPs completely in the Zone
-- @return #number The number of UNITS alive.
function SET_GROUP:CountAlive()
local CountG = 0
local CountU = 0
local Set = self:GetSet()
for GroupID, GroupData in pairs(Set) do -- For each GROUP in SET_GROUP
if GroupData and GroupData:IsAlive() then
CountG = CountG + 1
--Count Units.
for _,_unit in pairs(GroupData:GetUnits()) do
local unit=_unit --Wrapper.Unit#UNIT
if unit and unit:IsAlive() then
CountU=CountU+1
end
end
end
end
return CountG,CountU
end
----- Iterate the SET_GROUP and call an interator function for each **alive** player, providing the Group of the player and optional parameters.
---- @param #SET_GROUP self
---- @param #function IteratorFunction The function that will be called when there is an alive player in the SET_GROUP. The function needs to accept a GROUP parameter.

View File

@ -127,6 +127,39 @@ do
-- @param #number LaserCode Laser code.
-- @param #number Duration Duration of lasing in seconds.
self:AddTransition( "Off", "LaseOnCoordinate", "On" )
--- LaseOnCoordinate Handler OnBefore for SPOT.
-- @function [parent=#SPOT] OnBeforeLaseOnCoordinate
-- @param #SPOT self
-- @param #string From
-- @param #string Event
-- @param #string To
-- @return #boolean
--- LaseOnCoordinate Handler OnAfter for SPOT.
-- @function [parent=#SPOT] OnAfterLaseOnCoordinate
-- @param #SPOT self
-- @param #string From
-- @param #string Event
-- @param #string To
--- LaseOnCoordinate Trigger for SPOT.
-- @function [parent=#SPOT] LaseOnCoordinate
-- @param #SPOT self
-- @param Core.Point#COORDINATE Coordinate The coordinate to lase.
-- @param #number LaserCode Laser code.
-- @param #number Duration Duration of lasing in seconds.
--- LaseOn Asynchronous Trigger for SPOT
-- @function [parent=#SPOT] __LaseOn
-- @param #SPOT self
-- @param #number Delay
-- @param Wrapper.Positionable#POSITIONABLE Target
-- @param #number LaserCode Laser code.
-- @param #number Duration Duration of lasing in seconds.
self:AddTransition( "On", "Lasing", "On" )
self:AddTransition( { "On", "Destroyed" } , "LaseOff", "Off" )
@ -194,7 +227,8 @@ do
return self
end
--- @param #SPOT self
--- On after LaseOn event. Activates the laser spot.
-- @param #SPOT self
-- @param From
-- @param Event
-- @param To
@ -227,6 +261,43 @@ do
self:__Lasing( -1 )
end
--- On after LaseOnCoordinate event. Activates the laser spot.
-- @param #SPOT self
-- @param From
-- @param Event
-- @param To
-- @param Core.Point#COORDINATE Coordinate The coordinate at which the laser is pointing.
-- @param #number LaserCode Laser code.
-- @param #number Duration Duration of lasing in seconds.
function SPOT:onafterLaseOnCoordinate(From, Event, To, Coordinate, LaserCode, Duration)
self:F( { "LaseOnCoordinate", Coordinate, LaserCode, Duration } )
local function StopLase( self )
self:LaseOff()
end
self.Target = nil
self.TargetCoord=Coordinate
self.LaserCode = LaserCode
self.Lasing = true
local RecceDcsUnit = self.Recce:GetDCSObject()
local aimat=Coordinate
aimat.y=aimat.y+1
self.SpotIR = Spot.createInfraRed( RecceDcsUnit, { x = 0, y = 2, z = 0 }, aimat:GetVec3() )
self.SpotLaser = Spot.createLaser( RecceDcsUnit, { x = 0, y = 2, z = 0 }, aimat:GetVec3(), LaserCode )
if Duration then
self.ScheduleID = self.LaseScheduler:Schedule( self, StopLase, {self}, Duration )
end
self:__Lasing(-1)
end
--- @param #SPOT self
-- @param Core.Event#EVENTDATA EventData
function SPOT:OnEventDead(EventData)
@ -246,9 +317,19 @@ do
-- @param To
function SPOT:onafterLasing( From, Event, To )
if self.Target:IsAlive() then
if self.Target and self.Target:IsAlive() then
self.SpotIR:setPoint( self.Target:GetPointVec3():AddY(1):AddY(math.random(-100,100)/100):AddX(math.random(-100,100)/100):GetVec3() )
self.SpotLaser:setPoint( self.Target:GetPointVec3():AddY(1):GetVec3() )
self:__Lasing( -0.2 )
elseif self.TargetCoord then
local aimat=self.TargetCoord --Core.Point#COORDINATE
aimat.y=aimat.y+1+math.random(-100,100)/100
aimat.x=aimat.x+math.random(-100,100)/100
self.SpotIR:setPoint(aimat:GetVec3())
self.SpotLaser:setPoint(self.TargetCoord:GetVec3())
self:__Lasing( -0.2 )
else
self:F( { "Target is not alive", self.Target:IsAlive() } )

View File

@ -40,7 +40,7 @@
-- @field #boolean Debug Write Debug messages to DCS log file and send Debug messages to all players.
-- @field #table targets All targets assigned.
-- @field #table moves All moves assigned.
-- @field #table currentTarget Holds the current target, if there is one assigned.
-- @field #ARTY.Target currentTarget Holds the current target, if there is one assigned.
-- @field #table currentMove Holds the current commanded move, if there is one assigned.
-- @field #number Nammo0 Initial amount total ammunition (shells+rockets+missiles) of the whole group.
-- @field #number Nshells0 Initial amount of shells of the whole group.
@ -99,6 +99,9 @@
-- @field #boolean autorelocate ARTY group will automatically move to within the max/min firing range.
-- @field #number autorelocatemaxdist Max distance [m] the ARTY group will travel to get within firing range. Default 50000 m = 50 km.
-- @field #boolean autorelocateonroad ARTY group will use mainly road to automatically get within firing range. Default is false.
-- @field #number coalition The coalition of the arty group.
-- @field #boolean respawnafterdeath Respawn arty group after all units are dead.
-- @field #number respawndelay Respawn delay in seconds.
-- @extends Core.Fsm#FSM_CONTROLLABLE
--- Enables mission designers easily to assign targets for artillery units. Since the implementation is based on a Finite State Model (FSM), the mission designer can
@ -587,6 +590,9 @@ ARTY={
autorelocate=false,
autorelocatemaxdist=50000,
autorelocateonroad=false,
coalition=nil,
respawnafterdeath=false,
respawndelay=nil
}
--- Weapong type ID. See [here](http://wiki.hoggit.us/view/DCS_enum_weapon_flag).
@ -668,13 +674,28 @@ ARTY.db={
},
}
--- Target.
-- @type ARTY.Target
-- @field #string name Name of target.
-- @field Core.Point#COORDINATE coord Target coordinates.
-- @field #number radius Shelling radius in meters.
-- @field #number nshells Number of shells (or other weapon types) fired upon target.
-- @field #number engaged Number of times this target was engaged.
-- @field #boolean underfire If true, target is currently under fire.
-- @field #number prio Priority of target.
-- @field #number maxengage Max number of times, the target will be engaged.
-- @field #number time Abs. mission time in seconds, when the target is scheduled to be attacked.
-- @field #number weapontype Type of weapon used for engagement. See #ARTY.WeaponType.
-- @field #number Tassigned Abs. mission time when target was assigned.
-- @field #boolean attackgroup If true, use task attack group rather than fire at point for engagement.
--- Some ID to identify who we are in output of the DCS.log file.
-- @field #string id
ARTY.id="ARTY | "
--- Arty script version.
-- @field #string version
ARTY.version="1.0.7"
ARTY.version="1.1.2"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -767,6 +788,9 @@ function ARTY:New(group, alias)
-- Set the group name
self.groupname=group:GetName()
-- Get coalition.
self.coalition=group:GetCoalition()
-- Set an alias name.
if alias~=nil then
self.alias=tostring(alias)
@ -843,6 +867,7 @@ function ARTY:New(group, alias)
self:AddTransition("*", "Status", "*")
self:AddTransition("*", "NewMove", "*")
self:AddTransition("*", "Dead", "*")
self:AddTransition("*", "Respawn", "CombatReady")
-- Transport as cargo (not in diagram).
self:AddTransition("*", "Loaded", "InTransit")
@ -953,7 +978,15 @@ function ARTY:New(group, alias)
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param #string Unitname Name of the dead unit.
--- User function for OnAfter "Respawn" event.
-- @function [parent=#ARTY] OnAfterRespawn
-- @param #ARTY self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
--- User function for OnEnter "CombatReady" state.
-- @function [parent=#ARTY] OnEnterCombatReady
@ -1025,11 +1058,13 @@ function ARTY:New(group, alias)
--- Function called when a unit of the ARTY group died. Triggers the FSM event "Dead".
-- @function [parent=#ARTY] Dead
-- @param #ARTY self
-- @param #string unitname Name of the unit that died.
--- Function called when a unit of the ARTY group died after a delay. Triggers the FSM event "Dead".
-- @function [parent=#ARTY] __Dead
-- @param #ARTY self
-- @param #number Delay in seconds.
-- @param #string unitname Name of the unit that died.
--- Add a new target for the ARTY group. Triggers the FSM event "NewTarget".
-- @function [parent=#ARTY] NewTarget
@ -1113,6 +1148,14 @@ function ARTY:New(group, alias)
-- @param #ARTY self
-- @param #number delay Delay in seconds.
--- Respawn ARTY group.
-- @function [parent=#ARTY] Respawn
-- @param #ARTY self
--- Respawn ARTY group after a delay.
-- @function [parent=#ARTY] __Respawn
-- @param #ARTY self
-- @param #number delay Delay in seconds.
return self
end
@ -1209,6 +1252,97 @@ function ARTY:AssignTargetCoord(coord, prio, radius, nshells, maxengage, time, w
return _name
end
--- Assign a target group to the ARTY group. Note that this will use the Attack Group Task rather than the Fire At Point Task.
-- @param #ARTY self
-- @param Wrapper.Group#GROUP group Target group.
-- @param #number prio (Optional) Priority of target. Number between 1 (high) and 100 (low). Default 50.
-- @param #number radius (Optional) Radius. Default is 100 m.
-- @param #number nshells (Optional) How many shells (or rockets) are fired on target per engagement. Default 5.
-- @param #number maxengage (Optional) How many times a target is engaged. Default 1.
-- @param #string time (Optional) Day time at which the target should be engaged. Passed as a string in format "08:13:45". Current task will be canceled.
-- @param #number weapontype (Optional) Type of weapon to be used to attack this target. Default ARTY.WeaponType.Auto, i.e. the DCS logic automatically determins the appropriate weapon.
-- @param #string name (Optional) Name of the target. Default is LL DMS coordinate of the target. If the name was already given, the numbering "#01", "#02",... is appended automatically.
-- @param #boolean unique (Optional) Target is unique. If the target name is already known, the target is rejected. Default false.
-- @return #string Name of the target. Can be used for further reference, e.g. deleting the target from the list.
-- @usage paladin=ARTY:New(GROUP:FindByName("Blue Paladin"))
-- paladin:AssignTargetCoord(GROUP:FindByName("Red Targets 1"):GetCoordinate(), 10, 300, 10, 1, "08:02:00", ARTY.WeaponType.Auto, "Target 1")
-- paladin:Start()
function ARTY:AssignAttackGroup(group, prio, radius, nshells, maxengage, time, weapontype, name, unique)
-- Set default values.
nshells=nshells or 5
radius=radius or 100
maxengage=maxengage or 1
prio=prio or 50
prio=math.max( 1, prio)
prio=math.min(100, prio)
if unique==nil then
unique=false
end
weapontype=weapontype or ARTY.WeaponType.Auto
-- TODO Check if we have a group object.
if type(group)=="string" then
group=GROUP:FindByName(group)
end
if group and group:IsAlive() then
local coord=group:GetCoordinate()
-- Name of the target.
local _name=group:GetName()
local _unique=true
-- Check if the name has already been used for another target. If so, the function returns a new unique name.
_name,_unique=self:_CheckName(self.targets, _name, not unique)
-- Target name should be unique and is not.
if unique==true and _unique==false then
self:T(ARTY.id..string.format("%s: target %s should have a unique name but name was already given. Rejecting target!", self.groupname, _name))
return nil
end
-- Time in seconds.
local _time
if type(time)=="string" then
_time=self:_ClockToSeconds(time)
elseif type(time)=="number" then
_time=timer.getAbsTime()+time
else
_time=timer.getAbsTime()
end
-- Prepare target array.
local target={} --#ARTY.Target
target.attackgroup=true
target.name=_name
target.coord=coord
target.radius=radius
target.nshells=nshells
target.engaged=0
target.underfire=false
target.prio=prio
target.time=_time
target.maxengage=maxengage
target.weapontype=weapontype
-- Add to table.
table.insert(self.targets, target)
-- Trigger new target event.
self:__NewTarget(1, target)
return _name
else
self:E("ERROR: Group does not exist!")
end
return nil
end
--- Assign coordinate to where the ARTY group should move.
-- @param #ARTY self
-- @param Core.Point#COORDINATE coord Coordinates of the new position.
@ -1288,14 +1422,17 @@ end
--- Set alias, i.e. the name the group will use when sending messages.
-- @param #ARTY self
-- @param #string alias The alias for the group.
-- @return self
function ARTY:SetAlias(alias)
self:F({alias=alias})
self.alias=tostring(alias)
return self
end
--- Add ARTY group to one or more clusters. Enables addressing all ARTY groups within a cluster simultaniously via marker assignments.
-- @param #ARTY self
-- @param #table clusters Table of cluster names the group should belong to.
-- @return self
function ARTY:AddToCluster(clusters)
self:F({clusters=clusters})
@ -1315,98 +1452,121 @@ function ARTY:AddToCluster(clusters)
for _,cluster in pairs(names) do
table.insert(self.clusters, cluster)
end
return self
end
--- Set minimum firing range. Targets closer than this distance are not engaged.
-- @param #ARTY self
-- @param #number range Min range in kilometers. Default is 0.1 km.
-- @return self
function ARTY:SetMinFiringRange(range)
self:F({range=range})
self.minrange=range*1000 or 100
return self
end
--- Set maximum firing range. Targets further away than this distance are not engaged.
-- @param #ARTY self
-- @param #number range Max range in kilometers. Default is 1000 km.
-- @return self
function ARTY:SetMaxFiringRange(range)
self:F({range=range})
self.maxrange=range*1000 or 1000*1000
return self
end
--- Set time interval between status updates. During the status check, new events are triggered.
-- @param #ARTY self
-- @param #number interval Time interval in seconds. Default 10 seconds.
-- @return self
function ARTY:SetStatusInterval(interval)
self:F({interval=interval})
self.StatusInterval=interval or 10
return self
end
--- Set time how it is waited a unit the first shot event happens. If no shot is fired after this time, the task to fire is aborted and the target removed.
-- @param #ARTY self
-- @param #number waittime Time in seconds. Default 300 seconds.
-- @return self
function ARTY:SetWaitForShotTime(waittime)
self:F({waittime=waittime})
self.WaitForShotTime=waittime or 300
return self
end
--- Define the safe distance between ARTY group and rearming unit or rearming place at which rearming process is possible.
-- @param #ARTY self
-- @param #number distance Safe distance in meters. Default is 100 m.
-- @return self
function ARTY:SetRearmingDistance(distance)
self:F({distance=distance})
self.RearmingDistance=distance or 100
return self
end
--- Assign a group, which is responsible for rearming the ARTY group. If the group is too far away from the ARTY group it will be guided towards the ARTY group.
-- @param #ARTY self
-- @param Wrapper.Group#GROUP group Group that is supposed to rearm the ARTY group. For the blue coalition, this is often a unarmed M818 transport whilst for red an unarmed Ural-375 transport can be used.
-- @return self
function ARTY:SetRearmingGroup(group)
self:F({group=group})
self.RearmingGroup=group
return self
end
--- Set the speed the rearming group moves at towards the ARTY group or the rearming place.
-- @param #ARTY self
-- @param #number speed Speed in km/h.
-- @return self
function ARTY:SetRearmingGroupSpeed(speed)
self:F({speed=speed})
self.RearmingGroupSpeed=speed
return self
end
--- Define if rearming group uses mainly roads to drive to the ARTY group or rearming place.
-- @param #ARTY self
-- @param #boolean onroad If true, rearming group uses mainly roads. If false, it drives directly to the ARTY group or rearming place.
-- @return self
function ARTY:SetRearmingGroupOnRoad(onroad)
self:F({onroad=onroad})
if onroad==nil then
onroad=true
end
self.RearmingGroupOnRoad=onroad
return self
end
--- Define if ARTY group uses mainly roads to drive to the rearming place.
-- @param #ARTY self
-- @param #boolean onroad If true, ARTY group uses mainly roads. If false, it drives directly to the rearming place.
-- @return self
function ARTY:SetRearmingArtyOnRoad(onroad)
self:F({onroad=onroad})
if onroad==nil then
onroad=true
end
self.RearmingArtyOnRoad=onroad
return self
end
--- Defines the rearming place of the ARTY group. If the place is too far away from the ARTY group it will be routed to the place.
-- @param #ARTY self
-- @param Core.Point#COORDINATE coord Coordinates of the rearming place.
-- @return self
function ARTY:SetRearmingPlace(coord)
self:F({coord=coord})
self.RearmingPlaceCoord=coord
return self
end
--- Set automatic relocation of ARTY group if a target is assigned which is out of range. The unit will drive automatically towards or away from the target to be in max/min firing range.
-- @param #ARTY self
-- @param #number maxdistance (Optional) The maximum distance in km the group will travel to get within firing range. Default is 50 km. No automatic relocation is performed if targets are assigned which are further away.
-- @param #boolean onroad (Optional) If true, ARTY group uses roads whenever possible. Default false, i.e. group will move in a straight line to the assigned coordinate.
-- @return self
function ARTY:SetAutoRelocateToFiringRange(maxdistance, onroad)
self:F({distance=maxdistance, onroad=onroad})
self.autorelocate=true
@ -1416,12 +1576,14 @@ function ARTY:SetAutoRelocateToFiringRange(maxdistance, onroad)
onroad=false
end
self.autorelocateonroad=onroad
return self
end
--- Set relocate after firing. Group will find a new location after each engagement. Default is off
-- @param #ARTY self
-- @param #number rmax (Optional) Max distance in meters, the group will move to relocate. Default is 800 m.
-- @param #number rmin (Optional) Min distance in meters, the group will move to relocate. Default is 300 m.
-- @return self
function ARTY:SetAutoRelocateAfterEngagement(rmax, rmin)
self.relocateafterfire=true
self.relocateRmax=rmax or 800
@ -1429,37 +1591,59 @@ function ARTY:SetAutoRelocateAfterEngagement(rmax, rmin)
-- Ensure that Rmin<=Rmax
self.relocateRmin=math.min(self.relocateRmin, self.relocateRmax)
return self
end
--- Report messages of ARTY group turned on. This is the default.
-- @param #ARTY self
-- @return self
function ARTY:SetReportON()
self.report=true
return self
end
--- Report messages of ARTY group turned off. Default is on.
-- @param #ARTY self
-- @return self
function ARTY:SetReportOFF()
self.report=false
return self
end
--- Respawn group once all units are dead.
-- @param #ARTY self
-- @param #number delay (Optional) Delay before respawn in seconds.
-- @return self
function ARTY:SetRespawnOnDeath(delay)
self.respawnafterdeath=true
self.respawndelay=delay
return self
end
--- Turn debug mode on. Information is printed to screen.
-- @param #ARTY self
-- @return self
function ARTY:SetDebugON()
self.Debug=true
return self
end
--- Turn debug mode off. This is the default setting.
-- @param #ARTY self
-- @return self
function ARTY:SetDebugOFF()
self.Debug=false
return self
end
--- Set default speed the group is moving at if not specified otherwise.
-- @param #ARTY self
-- @param #number speed Speed in km/h.
-- @return self
function ARTY:SetSpeed(speed)
self.Speed=speed
return self
end
--- Delete a target from target list. If the target is currently engaged, it is cancelled.
@ -1528,50 +1712,60 @@ end
--- Define shell types that are counted to determine the ammo amount the ARTY group has.
-- @param #ARTY self
-- @param #table tableofnames Table of shell type names.
-- @return self
function ARTY:SetShellTypes(tableofnames)
self:F2(tableofnames)
self.ammoshells={}
for _,_type in pairs(tableofnames) do
table.insert(self.ammoshells, _type)
end
return self
end
--- Define rocket types that are counted to determine the ammo amount the ARTY group has.
-- @param #ARTY self
-- @param #table tableofnames Table of rocket type names.
-- @return self
function ARTY:SetRocketTypes(tableofnames)
self:F2(tableofnames)
self.ammorockets={}
for _,_type in pairs(tableofnames) do
table.insert(self.ammorockets, _type)
end
return self
end
--- Define missile types that are counted to determine the ammo amount the ARTY group has.
-- @param #ARTY self
-- @param #table tableofnames Table of rocket type names.
-- @return self
function ARTY:SetMissileTypes(tableofnames)
self:F2(tableofnames)
self.ammomissiles={}
for _,_type in pairs(tableofnames) do
table.insert(self.ammomissiles, _type)
end
return self
end
--- Set number of tactical nuclear warheads available to the group.
-- Note that it can be max the number of normal shells. Also if all normal shells are empty, firing nuclear shells is also not possible any more until group gets rearmed.
-- @param #ARTY self
-- @param #number n Number of warheads for the whole group.
-- @return self
function ARTY:SetTacNukeShells(n)
self.Nukes=n
return self
end
--- Set nuclear warhead explosion strength.
-- @param #ARTY self
-- @param #number strength Explosion strength in kilo tons TNT. Default is 0.075 kt.
-- @return self
function ARTY:SetTacNukeWarhead(strength)
self.nukewarhead=strength or 0.075
self.nukewarhead=self.nukewarhead*1000*1000 -- convert to kg TNT.
return self
end
--- Set number of illumination shells available to the group.
@ -1579,10 +1773,12 @@ end
-- @param #ARTY self
-- @param #number n Number of illumination shells for the whole group.
-- @param #number power (Optional) Power of illumination warhead in mega candela. Default 1.0 mcd.
-- @return self
function ARTY:SetIlluminationShells(n, power)
self.Nillu=n
self.illuPower=power or 1.0
self.illuPower=self.illuPower * 1000000
return self
end
--- Set minimum and maximum detotation altitude for illumination shells. A value between min/max is selected randomly.
@ -1590,6 +1786,7 @@ end
-- @param #ARTY self
-- @param #number minalt (Optional) Minium altitude in meters. Default 500 m.
-- @param #number maxalt (Optional) Maximum altitude in meters. Default 1000 m.
-- @return self
function ARTY:SetIlluminationMinMaxAlt(minalt, maxalt)
self.illuMinalt=minalt or 500
self.illuMaxalt=maxalt or 1000
@ -1597,6 +1794,7 @@ function ARTY:SetIlluminationMinMaxAlt(minalt, maxalt)
if self.illuMinalt>self.illuMaxalt then
self.illuMinalt=self.illuMaxalt
end
return self
end
--- Set number of smoke shells available to the group.
@ -1604,38 +1802,46 @@ end
-- @param #ARTY self
-- @param #number n Number of smoke shells for the whole group.
-- @param Utilities.Utils#SMOKECOLOR color (Optional) Color of the smoke. Default SMOKECOLOR.Red.
-- @return self
function ARTY:SetSmokeShells(n, color)
self.Nsmoke=n
self.smokeColor=color or SMOKECOLOR.Red
return self
end
--- Set nuclear fires and extra demolition explosions.
-- @param #ARTY self
-- @param #number nfires (Optional) Number of big smoke and fire objects created in the demolition zone.
-- @param #number demolitionrange (Optional) Demolition range in meters.
-- @return self
function ARTY:SetTacNukeFires(nfires, range)
self.nukefire=true
self.nukefires=nfires
self.nukerange=range
return self
end
--- Enable assigning targets and moves by placing markers on the F10 map.
-- @param #ARTY self
-- @param #number key (Optional) Authorization key. Only players knowing this key can assign targets. Default is no authorization required.
-- @param #boolean readonly (Optional) Marks are readonly and cannot be removed by players. This also means that targets cannot be cancelled by removing the mark. Default false.
-- @return self
function ARTY:SetMarkAssignmentsOn(key, readonly)
self.markkey=key
self.markallow=true
if readonly==nil then
self.markreadonly=false
end
return self
end
--- Disable assigning targets by placing markers on the F10 map.
-- @param #ARTY self
-- @return self
function ARTY:SetMarkTargetsOff()
self.markallow=false
self.markkey=nil
return self
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -1825,8 +2031,8 @@ function ARTY:onafterStart(Controllable, From, Event, To)
self.Controllable:OptionROEHoldFire()
-- Add event handler.
self:HandleEvent(EVENTS.Shot, self._OnEventShot)
self:HandleEvent(EVENTS.Dead, self._OnEventDead)
self:HandleEvent(EVENTS.Shot) --, self._OnEventShot)
self:HandleEvent(EVENTS.Dead) --, self._OnEventDead)
--self:HandleEvent(EVENTS.MarkAdded, self._OnEventMarkAdded)
-- Add DCS event handler - necessary for S_EVENT_MARK_* events. So we only start it, if this was requested.
@ -1904,7 +2110,7 @@ function ARTY:_StatusReport(display)
end
text=text..string.format("******************************************************")
env.info(ARTY.id..text)
MESSAGE:New(text, 20):Clear():ToCoalitionIf(self.Controllable:GetCoalition(), display)
MESSAGE:New(text, 20):Clear():ToCoalitionIf(self.coalition, display)
end
@ -1915,7 +2121,7 @@ end
--- Eventhandler for shot event.
-- @param #ARTY self
-- @param Core.Event#EVENTDATA EventData
function ARTY:_OnEventShot(EventData)
function ARTY:OnEventShot(EventData)
self:F(EventData)
-- Weapon data.
@ -2193,7 +2399,7 @@ end
function ARTY:_OnEventMarkRemove(Event)
-- Get battery coalition and name.
local batterycoalition=self.Controllable:GetCoalition()
local batterycoalition=self.coalition
--local batteryname=self.groupname
if Event.text~=nil and Event.text:find("BATTERY") then
@ -2279,7 +2485,7 @@ function ARTY:_OnEventMarkChange(Event)
_coord.y=_coord:GetLandHeight()
-- Get battery coalition and name.
local batterycoalition=self.Controllable:GetCoalition()
local batterycoalition=self.coalition
local batteryname=self.groupname
-- Check if the coalition is the same or an authorization key has been defined.
@ -2390,7 +2596,7 @@ function ARTY:_OnEventMarkChange(Event)
if _assign.setrearmingplace and self.ismobile then
self:SetRearmingPlace(_coord)
_coord:RemoveMark(Event.idx)
_coord:MarkToCoalition(string.format("Rearming place for battery %s", self.groupname), self.Controllable:GetCoalition(), false, string.format("New rearming place for battery %s defined.", self.groupname))
_coord:MarkToCoalition(string.format("Rearming place for battery %s", self.groupname), self.coalition, false, string.format("New rearming place for battery %s defined.", self.groupname))
if self.Debug then
_coord:SmokeOrange()
end
@ -2398,7 +2604,7 @@ function ARTY:_OnEventMarkChange(Event)
if _assign.setrearminggroup then
_coord:RemoveMark(Event.idx)
local rearminggroupcoord=_assign.setrearminggroup:GetCoordinate()
rearminggroupcoord:MarkToCoalition(string.format("Rearming group for battery %s", self.groupname), self.Controllable:GetCoalition(), false, string.format("New rearming group for battery %s defined.", self.groupname))
rearminggroupcoord:MarkToCoalition(string.format("Rearming group for battery %s", self.groupname), self.coalition, false, string.format("New rearming group for battery %s defined.", self.groupname))
self:SetRearmingGroup(_assign.setrearminggroup)
if self.Debug then
rearminggroupcoord:SmokeOrange()
@ -2502,20 +2708,24 @@ end
--- Event handler for event Dead.
-- @param #ARTY self
-- @param Core.Event#EVENTDATA EventData
function ARTY:_OnEventDead(EventData)
function ARTY:OnEventDead(EventData)
self:F(EventData)
-- Name of controllable.
local _name=self.groupname
-- Check for correct group.
if EventData.IniGroupName==_name then
if EventData and EventData.IniGroupName and EventData.IniGroupName==_name then
-- Name of the dead unit.
local unitname=tostring(EventData.IniUnitName)
-- Dead Unit.
self:T2(string.format("%s: Captured dead event for unit %s.", _name, EventData.IniUnitName))
self:T(ARTY.id..string.format("%s: Captured dead event for unit %s.", _name, unitname))
-- FSM Dead event. We give one second for update of data base.
self:__Dead(1)
--self:__Dead(1, unitname)
self:Dead(unitname)
end
end
@ -2533,6 +2743,12 @@ end
function ARTY:onafterStatus(Controllable, From, Event, To)
self:_EventFromTo("onafterStatus", Event, From, To)
-- FSM state.
local fsmstate=self:GetState()
self:I(ARTY.id..string.format("Status of group %s: %s", self.alias, fsmstate))
if self.Controllable and self.Controllable:IsAlive() then
-- We have a cargo group ==> check if group was loaded into a carrier.
if self.cargogroup then
if self.cargogroup:IsLoaded() and not self:is("InTransit") then
@ -2672,6 +2888,10 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
-- Call status again in ~10 sec.
self:__Status(self.StatusInterval)
else
self:E(ARTY.id..string.format("Arty group %s is not alive!", self.groupname))
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -2766,7 +2986,7 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param #table target Array holding the target info.
-- @param #ARTY.Target target Array holding the target info.
function ARTY:onafterOpenFire(Controllable, From, Event, To, target)
self:_EventFromTo("onafterOpenFire", Event, From, To)
@ -2819,7 +3039,7 @@ function ARTY:onafterOpenFire(Controllable, From, Event, To, target)
-- Send message.
local text=string.format("%s, opening fire on target %s with %d %s. Distance %.1f km.", Controllable:GetName(), target.name, target.nshells, _type, range/1000)
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report)
--if self.Debug then
-- local _coord=target.coord --Core.Point#COORDINATE
@ -2828,7 +3048,11 @@ function ARTY:onafterOpenFire(Controllable, From, Event, To, target)
--end
-- Start firing.
if target.attackgroup then
self:_AttackGroup(target)
else
self:_FireAtCoord(target.coord, target.radius, target.nshells, target.weapontype)
end
end
@ -2849,7 +3073,7 @@ function ARTY:onafterCeaseFire(Controllable, From, Event, To, target)
-- Send message.
local text=string.format("%s, ceasing fire on target %s.", Controllable:GetName(), target.name)
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report)
-- Get target array index.
local id=self:_GetTargetIndexByName(target.name)
@ -2903,7 +3127,7 @@ function ARTY:onafterWinchester(Controllable, From, Event, To)
-- Send message.
local text=string.format("%s, winchester!", Controllable:GetName())
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
end
@ -2969,7 +3193,7 @@ function ARTY:onafterRearm(Controllable, From, Event, To)
-- Send message.
local text=string.format("%s, %s, request rearming at rearming place.", Controllable:GetName(), self.RearmingGroup:GetName())
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Distances.
local dA=coordARTY:Get2DDistance(self.RearmingPlaceCoord)
@ -2994,7 +3218,7 @@ function ARTY:onafterRearm(Controllable, From, Event, To)
-- Send message.
local text=string.format("%s, %s, request rearming.", Controllable:GetName(), self.RearmingGroup:GetName())
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Distance between ARTY group and rearming unit.
local distance=coordARTY:Get2DDistance(coordRARM)
@ -3013,7 +3237,7 @@ function ARTY:onafterRearm(Controllable, From, Event, To)
-- Send message.
local text=string.format("%s, moving to rearming place.", Controllable:GetName())
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Distance.
local dA=coordARTY:Get2DDistance(self.RearmingPlaceCoord)
@ -3042,7 +3266,7 @@ function ARTY:onafterRearmed(Controllable, From, Event, To)
-- Send message.
local text=string.format("%s, rearming complete.", Controllable:GetName())
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- "Rearm" tactical nukes as well.
self.Nukes=self.Nukes0
@ -3094,7 +3318,7 @@ function ARTY:_CheckRearmed()
if _rearmpc>1 then
local text=string.format("%s, rearming %d %% complete.", self.alias, _rearmpc)
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(self.Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
end
-- Return if ammo is full.
@ -3189,7 +3413,7 @@ function ARTY:onafterArrived(Controllable, From, Event, To)
-- Send message
local text=string.format("%s, arrived at destination.", Controllable:GetName())
self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Remove executed move from queue.
if self.currentMove then
@ -3240,26 +3464,62 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function ARTY:onafterDead(Controllable, From, Event, To)
-- @param #string Unitname Name of the unit that died.
function ARTY:onafterDead(Controllable, From, Event, To, Unitname)
self:_EventFromTo("onafterDead", Event, From, To)
-- Number of units left in the group.
local units=self.Controllable:GetUnits()
local nunits=0
if units~=nil then
nunits=#units
end
-- Number of units still alive.
--local nunits=self.Controllable and self.Controllable:CountAliveUnits() or 0
local nunits=self.Controllable:CountAliveUnits()
-- Message.
local text=string.format("%s, one of our units just died! %d units left.", self.groupname, nunits)
local text=string.format("%s, our unit %s just died! %d units left.", self.groupname, Unitname, nunits)
MESSAGE:New(text, 5):ToAllIf(self.Debug)
self:T(ARTY.id..text)
self:I(ARTY.id..text)
-- Go to stop state.
if nunits==0 then
self:Stop()
-- Cease Fire on current target.
if self.currentTarget then
self:CeaseFire(self.currentTarget)
end
if self.respawnafterdeath then
-- Respawn group.
if not self.respawning then
self.respawning=true
self:__Respawn(self.respawndelay or 1)
end
else
-- Stop FSM.
self:Stop()
end
end
end
--- After "Dead" event, when a unit has died. When all units of a group are dead trigger "Stop" event.
-- @param #ARTY self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function ARTY:onafterRespawn(Controllable, From, Event, To)
self:_EventFromTo("onafterRespawn", Event, From, To)
env.info("FF Respawning arty group")
local group=self.Controllable --Wrapper.Group#GROUP
-- Respawn group.
self.Controllable=group:Respawn()
self.respawning=false
-- Call status again.
self:__Status(-1)
end
--- After "Stop" event. Unhandle events and cease fire on current target.
@ -3272,7 +3532,7 @@ function ARTY:onafterStop(Controllable, From, Event, To)
self:_EventFromTo("onafterStop", Event, From, To)
-- Debug info.
self:T(ARTY.id..string.format("Stopping ARTY FSM for group %s.", Controllable:GetName()))
self:I(ARTY.id..string.format("Stopping ARTY FSM for group %s.", tostring(Controllable:GetName())))
-- Cease Fire on current target.
if self.currentTarget then
@ -3321,6 +3581,36 @@ function ARTY:_FireAtCoord(coord, radius, nshells, weapontype)
group:SetTask(fire)
end
--- Set task for attacking a group.
-- @param #ARTY self
-- @param #ARTY.Target target Target data.
function ARTY:_AttackGroup(target)
-- Controllable.
local group=self.Controllable --Wrapper.Group#GROUP
local weapontype=target.weapontype
-- Tactical nukes are actually cannon shells.
if weapontype==ARTY.WeaponType.TacticalNukes or weapontype==ARTY.WeaponType.IlluminationShells or weapontype==ARTY.WeaponType.SmokeShells then
weapontype=ARTY.WeaponType.Cannon
end
-- Set ROE to weapon free.
group:OptionROEOpenFire()
-- Target group.
local targetgroup=GROUP:FindByName(target.name)
-- Get task.
local fire=group:TaskAttackGroup(targetgroup, weapontype, AI.Task.WeaponExpend.ONE, 1)
-- Execute task.
group:SetTask(fire)
end
--- Model a nuclear blast/destruction by creating fires and destroy scenery.
-- @param #ARTY self
-- @param Core.Point#COORDINATE _coord Coordinate of the impact point (center of the blast).
@ -3790,7 +4080,7 @@ function ARTY:_MarkerKeyAuthentification(text)
-- Set battery and coalition.
--local batteryname=self.groupname
local batterycoalition=self.Controllable:GetCoalition()
local batterycoalition=self.coalition
-- Get assignment.
local mykey=nil
@ -4105,7 +4395,7 @@ function ARTY:_MarkRequestMoves()
else
text=text..string.format("\n- no queued relocations")
end
MESSAGE:New(text, 20):Clear():ToCoalition(self.Controllable:GetCoalition())
MESSAGE:New(text, 20):Clear():ToCoalition(self.coalition)
end
--- Request Targets.
@ -4123,7 +4413,7 @@ function ARTY:_MarkRequestTargets()
else
text=text..string.format("\n- no queued targets")
end
MESSAGE:New(text, 20):Clear():ToCoalition(self.Controllable:GetCoalition())
MESSAGE:New(text, 20):Clear():ToCoalition(self.coalition)
end
--- Create a name for an engagement initiated by placing a marker.
@ -4305,7 +4595,7 @@ function ARTY:_CheckTargetsInRange()
-- Inform coalition that target is now in range.
local text=string.format("%s, target %s is now in range.", self.alias, _target.name)
self:T(ARTY.id..text)
MESSAGE:New(text,10):ToCoalitionIf(self.Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(text,10):ToCoalitionIf(self.coalition, self.report or self.Debug)
end
end
@ -4342,7 +4632,7 @@ function ARTY:_CheckTargetsInRange()
end
-- Send info message.
MESSAGE:New(_name.." assigned.", 10):ToCoalitionIf(self.Controllable:GetCoalition(), self.report or self.Debug)
MESSAGE:New(_name.." assigned.", 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Assign relocation move.
self:AssignMoveCoord(_tocoord, nil, nil, self.autorelocateonroad, false, _name, true)
@ -4775,7 +5065,7 @@ function ARTY:_TargetInRange(target, message)
-- Debug output.
if not _inrange then
self:T(ARTY.id..text)
MESSAGE:New(text, 5):ToCoalitionIf(self.Controllable:GetCoalition(), (self.report and message) or (self.Debug and message))
MESSAGE:New(text, 5):ToCoalitionIf(self.coalition, (self.report and message) or (self.Debug and message))
end
-- Remove target if ARTY group cannot move, e.g. Mortas. No chance to be ever in range - unless they are cargo.
@ -4860,13 +5150,14 @@ end
--- Returns the target parameters as formatted string.
-- @param #ARTY self
-- @param #ARTY.Target target The target data.
-- @return #string name, prio, radius, nshells, engaged, maxengage, time, weapontype
function ARTY:_TargetInfo(target)
local clock=tostring(self:_SecondsToClock(target.time))
local weapon=self:_WeaponTypeName(target.weapontype)
local _underfire=tostring(target.underfire)
return string.format("%s: prio=%d, radius=%d, nshells=%d, engaged=%d/%d, weapontype=%s, time=%s, underfire=%s",
target.name, target.prio, target.radius, target.nshells, target.engaged, target.maxengage, weapon, clock,_underfire)
return string.format("%s: prio=%d, radius=%d, nshells=%d, engaged=%d/%d, weapontype=%s, time=%s, underfire=%s, attackgroup=%s",
target.name, target.prio, target.radius, target.nshells, target.engaged, target.maxengage, weapon, clock,_underfire, tostring(target.attackgroup))
end
--- Returns a formatted string with information about all move parameters.

View File

@ -541,7 +541,8 @@ do -- DETECTION_BASE
end
self.DetectionCount = self.DetectionSet:Count()
-- Count alive(!) groups only. Solves issue #1173 https://github.com/FlightControl-Master/MOOSE/issues/1173
self.DetectionCount = self.DetectionSet:CountAlive()
self.DetectionSet:ForEachGroupAlive(
function( DetectionGroup )

View File

@ -77,6 +77,8 @@
-- @field #boolean safeparking If true, parking spots for aircraft are considered as occupied if e.g. a client aircraft is parked there. Default false.
-- @field #boolean isunit If true, warehouse is represented by a unit instead of a static.
-- @field #number lowfuelthresh Low fuel threshold. Triggers the event AssetLowFuel if for any unit fuel goes below this number.
-- @field #boolean respawnafterdestroyed If true, warehouse is respawned after it was destroyed. Assets are kept.
-- @field #number respawndelay Delay before respawn in seconds.
-- @extends Core.Fsm#FSM
--- Have your assets at the right place at the right time - or not!
@ -1569,6 +1571,8 @@ WAREHOUSE = {
saveparking = false,
isunit = false,
lowfuelthresh = 0.15,
respawnafterdestroyed=false,
respawndelay = nil,
}
--- Item of the warehouse stock table.
@ -1634,11 +1638,13 @@ WAREHOUSE = {
-- @field #string UNITTYPE Typename of the DCS unit, e.g. "A-10C".
-- @field #string ATTRIBUTE Generalized attribute @{#WAREHOUSE.Attribute}.
-- @field #string CATEGORY Asset category of type DCS#Group.Category, i.e. GROUND, AIRPLANE, HELICOPTER, SHIP, TRAIN.
-- @field #string ASSIGNMENT Assignment of asset when it was added.
WAREHOUSE.Descriptor = {
GROUPNAME="templatename",
UNITTYPE="unittype",
ATTRIBUTE="attribute",
CATEGORY="category",
ASSIGNMENT="assignment",
}
--- Generalized asset attributes. Can be used to request assets with certain general characteristics. See [DCS attributes](https://wiki.hoggitworld.com/view/DCS_enum_attributes) on hoggit.
@ -1743,7 +1749,7 @@ _WAREHOUSEDB = {
--- Warehouse class version.
-- @field #string version
WAREHOUSE.version="0.9.2"
WAREHOUSE.version="0.9.5"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Warehouse todo list.
@ -1906,6 +1912,7 @@ function WAREHOUSE:New(warehouse, alias)
self:AddTransition("*", "AirbaseRecaptured", "*") -- Airbase was re-captured from other coalition.
self:AddTransition("*", "AssetDead", "*") -- An asset group died.
self:AddTransition("*", "Destroyed", "Destroyed") -- Warehouse was destroyed. All assets in stock are gone and warehouse is stopped.
self:AddTransition("Destroyed", "Respawn", "Running") -- Respawn warehouse after it was destroyed.
------------------------
--- Pseudo Functions ---
@ -1938,6 +1945,22 @@ function WAREHOUSE:New(warehouse, alias)
-- @param #WAREHOUSE self
-- @param #number delay Delay in seconds.
--- Triggers the FSM event "Respawn".
-- @function [parent=#WAREHOUSE] Respawn
-- @param #WAREHOUSE self
--- Triggers the FSM event "Respawn" after a delay.
-- @function [parent=#WAREHOUSE] __Respawn
-- @param #WAREHOUSE self
-- @param #number delay Delay in seconds.
--- On after "Respawn" event user function.
-- @function [parent=#WAREHOUSE] OnAfterRespawn
-- @param #WAREHOUSE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
--- Triggers the FSM event "Pause". Pauses the warehouse. Assets can still be added and requests be made. However, requests are not processed.
-- @function [parent=#WAREHOUSE] Pause
-- @param #WAREHOUSE self
@ -2531,6 +2554,15 @@ function WAREHOUSE:SetSaveOnMissionEnd(path, filename)
return self
end
--- Set respawn after destroy.
-- @param #WAREHOUSE self
-- @return #WAREHOUSE self
function WAREHOUSE:SetRespawnAfterDestroyed(delay)
self.respawnafterdestroyed=true
self.respawndelay=delay
return self
end
--- Set the airbase belonging to this warehouse.
-- Note that it has to be of the same coalition as the warehouse.
@ -3684,7 +3716,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
self:_DebugMessage(string.format("Warehouse %s: Adding %d NEW assets of group %s to stock.", self.alias, n, tostring(group:GetName())), 5)
-- This is a group that is not in the db yet. Add it n times.
local assets=self:_RegisterAsset(group, n, forceattribute, forcecargobay, forceweight, loadradius, liveries, skill)
local assets=self:_RegisterAsset(group, n, forceattribute, forcecargobay, forceweight, loadradius, liveries, skill, assignment)
-- Add created assets to stock of this warehouse.
for _,asset in pairs(assets) do
@ -3720,8 +3752,9 @@ end
-- @param #number loadradius Radius in meters when cargo is loaded into the carrier.
-- @param #table liveries Table of liveries.
-- @param DCS#AI.Skill skill Skill of AI.
-- @param #string assignment Assignment attached to the asset item.
-- @return #table A table containing all registered assets.
function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, forceweight, loadradius, liveries, skill)
function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, forceweight, loadradius, liveries, skill, assignment)
self:F({groupname=group:GetName(), ngroups=ngroups, forceattribute=forceattribute, forcecargobay=forcecargobay, forceweight=forceweight})
-- Set default.
@ -3823,6 +3856,7 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay,
asset.livery=liveries[math.random(#liveries)]
end
asset.skill=skill
asset.assignment=assignment
if i==1 then
self:_AssetItemInfo(asset)
@ -3937,8 +3971,15 @@ function WAREHOUSE:onbeforeAddRequest(From, Event, To, warehouse, AssetDescripto
okay=false
end
elseif AssetDescriptor==WAREHOUSE.Descriptor.ASSIGNMENT then
if type(AssetDescriptorValue)~="string" then
self:_ErrorMessage("ERROR: Invalid request. Asset assignment type must be passed as a string!", 5)
okay=false
end
else
self:_ErrorMessage("ERROR: Invalid request. Asset descriptor is not ATTRIBUTE, CATEGORY, GROUPNAME or UNITTYPE!", 5)
self:_ErrorMessage("ERROR: Invalid request. Asset descriptor is not ATTRIBUTE, CATEGORY, GROUPNAME, UNITTYPE or ASSIGNMENT!", 5)
okay=false
end
@ -3949,7 +3990,7 @@ function WAREHOUSE:onbeforeAddRequest(From, Event, To, warehouse, AssetDescripto
end
-- Warehouse is destroyed?
if self:IsDestroyed() then
if self:IsDestroyed() and not self.respawnafterdestroyed then
self:_ErrorMessage("ERROR: Invalid request. Warehouse is destroyed!", 0)
okay=false
end
@ -4816,6 +4857,21 @@ function WAREHOUSE:onbeforeChangeCountry(From, Event, To, Country)
return false
end
--- Respawn warehouse.
-- @param #WAREHOUSE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function WAREHOUSE:onafterRespawn(From, Event, To)
-- Info message.
local text=string.format("Respawning warehouse %s.", self.alias)
self:_InfoMessage(text)
-- Respawn warehouse.
self.warehouse:ReSpawn()
end
--- On after "ChangeCountry" event. Warehouse is respawned with the specified country. All queued requests are deleted and the owned airbase is reset if the coalition is changed by changing the
-- country.
@ -4952,9 +5008,20 @@ end
function WAREHOUSE:onafterDestroyed(From, Event, To)
-- Message.
local text=string.format("Warehouse %s was destroyed! Assets lost %d.", self.alias, #self.stock)
local text=string.format("Warehouse %s was destroyed! Assets lost %d. Respawn=%s", self.alias, #self.stock, tostring(self.respawnafterdestroyed))
self:_InfoMessage(text)
if self.respawnafterdestroyed then
if self.respawndelay then
self:Pause()
self:__Respawn(self.respawndelay)
else
self:Respawn()
end
else
-- Remove all table entries from waiting queue and stock.
for k,_ in pairs(self.queue) do
self.queue[k]=nil
@ -4968,6 +5035,7 @@ function WAREHOUSE:onafterDestroyed(From, Event, To)
--self.stock=nil
--self.stock={}
end
end
@ -6332,7 +6400,7 @@ function WAREHOUSE:_CheckRequestConsistancy(queue)
end
-- Is receiving warehouse destroyed?
if request.warehouse:IsDestroyed() then
if request.warehouse:IsDestroyed() and not self.respawnafterdestroyed then
self:E(self.wid..string.format("ERROR: INVALID request. Requesting warehouse is destroyed!"))
valid=false
end

View File

@ -16,7 +16,7 @@
-- * Advanced F10 radio menu including carrier info, weather, radio frequencies, TACAN/ICLS channels, player LSO grades, marking of zones etc.
-- * Recovery tanker and refueling option via integration of @{Ops.RecoveryTanker} class.
-- * Rescue helicopter option via @{Ops.RescueHelo} class.
-- * Combine multiple human players to sections (WIP).
-- * Combine multiple human players to sections.
-- * Many parameters customizable by convenient user API functions.
-- * Multiple carrier support due to object oriented approach.
-- * Unlimited number of players.
@ -32,7 +32,7 @@
-- **Supported Aircraft:**
--
-- * [F/A-18C Hornet Lot 20](https://forums.eagle.ru/forumdisplay.php?f=557) (Player & AI)
-- * [F-14B Tomcat](https://forums.eagle.ru/forumdisplay.php?f=395) (Player & AI) [**WIP**]
-- * [F-14B Tomcat](https://forums.eagle.ru/forumdisplay.php?f=395) (Player & AI)
-- * [A-4E Skyhawk Community Mod](https://forums.eagle.ru/showthread.php?t=224989) (Player & AI)
-- * [AV-8B N/A Harrier](https://forums.eagle.ru/forumdisplay.php?f=555) (Player & AI) [**WIP**]
-- * F/A-18C Hornet (AI)
@ -46,10 +46,8 @@
-- the no other fixed wing aircraft (human or AI controlled) are supposed to land on the Tarawa. Currently only Case I is supported. Case II/III take slightly steps from the CVN carrier.
-- However, the two Case II/III pattern are very similar so this is not a big drawback.
--
-- Heatblur's mighty F-14B Tomcat has just been added (March 13th 2019). Beware that this is currently WIP - both the module and the AIRBOSS implementation.
-- Heatblur's mighty F-14B Tomcat has been added (March 13th 2019) as well.
--
-- **PLEASE NOTE** that his class is work in progress. Many/most things work already very nicely but there a lot of cases I did not run into yet.
-- Therefore, your *constructive* feedback is both necessary and appreciated!
--
-- ## Discussion
--
@ -174,7 +172,6 @@
-- @field #number NmaxStack Number of max flights per stack. Default 2.
-- @field #boolean handleai If true (default), handle AI aircraft.
-- @field Ops.RecoveryTanker#RECOVERYTANKER tanker Recovery tanker flying overhead of carrier.
-- @field Functional.Warehouse#WAREHOUSE warehouse Warehouse object of the carrier.
-- @field DCS#Vec3 Corientation Carrier orientation in space.
-- @field DCS#Vec3 Corientlast Last known carrier orientation.
-- @field Core.Point#COORDINATE Cposition Carrier position.
@ -1182,7 +1179,6 @@ AIRBOSS = {
NmaxStack = nil,
handleai = nil,
tanker = nil,
warehouse = nil,
Corientation = nil,
Corientlast = nil,
Cposition = nil,
@ -1685,7 +1681,7 @@ AIRBOSS.MenuF10Root=nil
--- Airboss class version.
-- @field #string version
AIRBOSS.version="1.0.2"
AIRBOSS.version="1.0.3"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@ -1803,6 +1799,15 @@ function AIRBOSS:New(carriername, alias)
-- Init player scores table.
self.playerscores={}
-- Initialize ME waypoints.
self:_InitWaypoints()
-- Current waypoint.
self.currentwp=1
-- Patrol route.
self:_PatrolRoute()
-------------
--- Defaults:
-------------
@ -2432,6 +2437,19 @@ function AIRBOSS:SetExcludeAI(setgroup)
return self
end
--- Add a group to the exclude set. If no set exists, it is created.
-- @param #AIRBOSS self
-- @param Wrapper.Group#GROUP group The group to be excluded.
-- @return #AIRBOSS self
function AIRBOSS:AddExcludeAI(group)
self.excludesetAI=self.excludesetAI or SET_GROUP:New()
self.excludesetAI:AddGroup(group)
return self
end
--- Close currently running recovery window and stop recovery ops. Recovery window is deleted.
-- @param #AIRBOSS self
-- @param #number delay (Optional) Delay in seconds before the window is deleted.
@ -3044,15 +3062,6 @@ function AIRBOSS:SetRecoveryTanker(recoverytanker)
return self
end
--- Define warehouse associated with the carrier.
-- @param #AIRBOSS self
-- @param Functional.Warehouse#WAREHOUSE warehouse Warehouse object of the carrier.
-- @return #AIRBOSS self
function AIRBOSS:SetWarehouse(warehouse)
self.warehouse=warehouse
return self
end
--- Set default player skill. New players will be initialized with this skill.
--
-- * "Flight Student" = @{#AIRBOSS.Difficulty.Easy}
@ -3202,9 +3211,6 @@ function AIRBOSS:onafterStart(From, Event, To)
self.Corientlast=self.Corientation
self.Tpupdate=timer.getTime()
-- Init patrol route of carrier.
self:_PatrolRoute(1)
-- Check if no recovery window is set. DISABLED!
if #self.recoverytimes==0 and false then
@ -3232,9 +3238,6 @@ function AIRBOSS:onafterStart(From, Event, To)
self:HandleEvent(EVENTS.PlayerLeaveUnit, self._PlayerLeft)
self:HandleEvent(EVENTS.MissionEnd)
-- DCS event handler.
--world.addEventHandler(self)
-- Start status check in 1 second.
self:__Status(1)
end
@ -3617,6 +3620,20 @@ function AIRBOSS:_CheckRecoveryTimes()
if self:IsRecovering() and not recovery.OVER then
-- Get number of airborne aircraft units(!) currently in pattern.
local _,npattern=self:_GetQueueInfo(self.Qpattern)
if npattern>0 then
-- Extend recovery time. 5 min per flight.
local extmin=5*npattern
recovery.STOP=recovery.STOP+extmin*60
local text=string.format("We still got flights in the pattern.\nRecovery time prolonged by %d minutes.\nNow get your act together and no more bolters!", extmin)
self:MessageToPattern(text, "AIRBOSS", "99", 10, false, nil)
else
-- Set carrier to idle.
self:RecoveryStop()
state="closing now"
@ -3626,6 +3643,8 @@ function AIRBOSS:_CheckRecoveryTimes()
-- Window just closed.
recovery.OVER=true
end
else
-- Carrier is already idle.
@ -3690,9 +3709,10 @@ function AIRBOSS:_CheckRecoveryTimes()
--Debug info
self:T(self.lid..string.format("Heading=%03d°, Wind=%03d° %.1f kts, Delta=%03d° ==> U-turn=%s", hdg, wind,UTILS.MpsToKnots(vwind), delta, tostring(uturn)))
-- Time into the wind 1 day or if longer recovery time + the 5 min early.
local t=math.max(nextwindow.STOP-nextwindow.START+300, 60*60*24)
-- Time into the wind + the 5 min early.
local t=nextwindow.STOP-nextwindow.START+300
-- Recovery wind on deck in knots.
local v=UTILS.KnotsToMps(nextwindow.SPEED)
-- Check that we do not go above max possible speed.
@ -13206,6 +13226,42 @@ function AIRBOSS:_GetNextWaypoint()
return nextwp,Nextwp
end
--- Initialize Mission Editor waypoints.
-- @param #AIRBOSS self
-- @return #AIRBOSS self
function AIRBOSS:_InitWaypoints()
-- Waypoints of group as defined in the ME.
local Waypoints=self.carrier:GetGroup():GetTemplateRoutePoints()
-- Init array.
self.waypoints={}
-- Set waypoint table.
for i,point in ipairs(Waypoints) do
-- Coordinate of the waypoint
local coord=COORDINATE:New(point.x, point.alt, point.y)
-- Set velocity of the coordinate.
coord:SetVelocity(point.speed)
-- Add to table.
table.insert(self.waypoints, coord)
-- Debug info.
if self.Debug then
coord:MarkToAll(string.format("Carrier Waypoint %d, Speed=%.1f knots", i, UTILS.MpsToKnots(point.speed)))
end
end
return self
end
--[[
--- Patrol carrier.
-- @param #AIRBOSS self
-- @param #number n Current waypoint.
@ -13259,6 +13315,58 @@ function AIRBOSS:_PatrolRoute(n)
return self
end
]]
--- Patrol carrier.
-- @param #AIRBOSS self
-- @param #number n Next waypoint number.
-- @return #AIRBOSS self
function AIRBOSS:_PatrolRoute(n)
-- Get next waypoint coordinate and number.
local nextWP, N=self:_GetNextWaypoint()
-- Default resume is to next waypoint.
n=n or N
-- Get carrier group.
local CarrierGroup=self.carrier:GetGroup()
-- Waypoints table.
local Waypoints={}
-- Create a waypoint from the current coordinate.
local wp=self:GetCoordinate():WaypointGround(CarrierGroup:GetVelocityKMH())
-- Add current position as first waypoint.
table.insert(Waypoints, wp)
-- Loop over waypoints.
for i=n,#self.waypoints do
local coord=self.waypoints[i] --Core.Point#COORDINATE
-- Create a waypoint from the coordinate.
local wp=coord:WaypointGround(UTILS.MpsToKmph(coord.Velocity))
-- Passing waypoint taskfunction
local TaskPassingWP=CarrierGroup:TaskFunction("AIRBOSS._PassingWaypoint", self, i, #self.waypoints)
-- Call task function when carrier arrives at waypoint.
CarrierGroup:SetTaskWaypoint(wp, TaskPassingWP)
-- Add waypoint to table.
table.insert(Waypoints, wp)
end
-- Route carrier group.
CarrierGroup:Route(Waypoints)
return self
end
--- Estimated the carrier position at some point in the future given the current waypoints and speeds.
-- @param #AIRBOSS self
-- @return DCS#time ETA abs. time in seconds.
@ -13484,7 +13592,7 @@ function AIRBOSS._PassingWaypoint(group, airboss, i, final)
-- If final waypoint reached, do route all over again.
if i==final and final>1 and airboss.adinfinitum then
airboss:_PatrolRoute(i)
airboss:_PatrolRoute()
end
end

View File

@ -553,14 +553,14 @@ function AIRBASE:GetParkingSpotsTable(termtype)
local spots={}
for _,_spot in pairs(parkingdata) do
if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then
self:I({_spot=_spot})
self:T2({_spot=_spot})
local _free=_isfree(_spot)
local _coord=COORDINATE:NewFromVec3(_spot.vTerminalPos)
table.insert(spots, {Coordinate=_coord, TerminalID=_spot.Term_Index, TerminalType=_spot.Term_Type, TOAC=_spot.TO_AC, Free=_free, TerminalID0=_spot.Term_Index_0, DistToRwy=_spot.fDistToRW})
end
end
self:I({ spots = spots } )
self:T2({ spots = spots } )
return spots
end
@ -711,7 +711,7 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE
local _termid=parkingspot.TerminalID
self:I({_termid=_termid})
self:T2({_termid=_termid})
if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) then

View File

@ -1388,7 +1388,7 @@ function CONTROLLABLE:TaskFireAtPoint( Vec2, Radius, AmmoCount, WeaponType )
DCSTask = { id = 'FireAtPoint',
params = {
point = Vec2,
radius = Radius,
zoneRadius = Radius,
expendQty = 100, -- dummy value
expendQtyEnabled = false,
}
@ -3165,7 +3165,8 @@ function CONTROLLABLE:OptionAlarmStateAuto()
if self:IsGround() then
Controller:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.AUTO)
elseif self:IsShip() then
Controller:setOption(AI.Option.Naval.id.ALARM_STATE, AI.Option.Naval.val.ALARM_STATE.AUTO)
--Controller:setOption(AI.Option.Naval.id.ALARM_STATE, AI.Option.Naval.val.ALARM_STATE.AUTO)
Controller:setOption(9, 0)
end
return self
@ -3189,6 +3190,7 @@ function CONTROLLABLE:OptionAlarmStateGreen()
elseif self:IsShip() then
-- AI.Option.Naval.id.ALARM_STATE does not seem to exist!
--Controller:setOption( AI.Option.Naval.id.ALARM_STATE, AI.Option.Naval.val.ALARM_STATE.GREEN )
Controller:setOption(9, 1)
end
return self
@ -3210,7 +3212,8 @@ function CONTROLLABLE:OptionAlarmStateRed()
if self:IsGround() then
Controller:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.RED)
elseif self:IsShip() then
Controller:setOption(AI.Option.Naval.id.ALARM_STATE, AI.Option.Naval.val.ALARM_STATE.RED)
--Controller:setOption(AI.Option.Naval.id.ALARM_STATE, AI.Option.Naval.val.ALARM_STATE.RED)
Controller:setOption(9, 2)
end
return self

View File

@ -1184,6 +1184,24 @@ function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) --R2.1
end
--- Start Lasing a COORDINATE.
-- @param #POSITIONABLE self
-- @param Core.Point#COORDIUNATE Coordinate The coordinate where the lase is pointing at.
-- @param #number LaserCode Laser code or random number in [1000, 9999].
-- @param #number Duration Duration of lasing in seconds.
-- @return Core.Spot#SPOT
function POSITIONABLE:LaseCoordinate(Coordinate, LaserCode, Duration)
self:F2()
LaserCode = LaserCode or math.random(1000, 9999)
self.Spot = SPOT:New(self) -- Core.Spot#SPOT
self.Spot:LaseOnCoordinate(Coordinate, LaserCode, Duration)
self.LaserCode = LaserCode
return self.Spot
end
--- Stop Lasing a POSITIONABLE
-- @param #POSITIONABLE self
-- @return #POSITIONABLE