mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
RANGE 1.2.1, WAREHOUSE 0.1.0
This commit is contained in:
parent
5a034ecf4f
commit
e0564876f4
@ -137,309 +137,3 @@ do -- AI_G2G_DISPATCHER
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
do
|
||||
|
||||
--- WAREHOUSE class.
|
||||
-- @type WAREHOUSE
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- Create an automatic ground .
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # Demo Missions
|
||||
--
|
||||
-- ### None.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # YouTube Channel
|
||||
--
|
||||
-- ### None.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- Warehouse
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # USAGE GUIDE
|
||||
--
|
||||
--
|
||||
--
|
||||
-- @field #WAREHOUSE
|
||||
WAREHOUSE = {
|
||||
ClassName = "WAREHOUSE",
|
||||
coalition = nil,
|
||||
homebase = nil,
|
||||
plane = {},
|
||||
helo = {},
|
||||
arty = {},
|
||||
tank = {},
|
||||
apc = {},
|
||||
infantry = {},
|
||||
}
|
||||
|
||||
-- @field category
|
||||
WAREHOUSE.category= {
|
||||
Transport=1,
|
||||
Fighter=1,
|
||||
AWACS=1,
|
||||
Tanker=1,
|
||||
}
|
||||
|
||||
--- WAREHOUSE constructor. Creates a new WAREHOUSE object.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Airbase#AIRBASE airbase Airbase.
|
||||
-- @return #WAREHOUSE self
|
||||
function WAREHOUSE:NewAirbase(airbase)
|
||||
|
||||
-- Inherits from FSM
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #WAREHOUSE
|
||||
|
||||
self.homebase=airbase
|
||||
self.coordinate=airbase:GetCoordinate()
|
||||
self.coalition=airbase:GetCoalition()
|
||||
|
||||
self:AddTransition("*", "Start", "Running")
|
||||
self:AddTransition("*", "Status", "*")
|
||||
self:AddTransition("*", "Request", "*")
|
||||
self:AddTransition("*", "Delivered", "*")
|
||||
|
||||
--- Triggers the FSM event "Start".
|
||||
-- @function [parent=#WAREHOUSE] Start
|
||||
-- @param #WAREHOUSE self
|
||||
|
||||
--- Triggers the FSM event "Start" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Start
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #number delay Delay in seconds.
|
||||
|
||||
|
||||
--- Triggers the FSM event "Status".
|
||||
-- @function [parent=#WAREHOUSE] Status
|
||||
-- @param #WAREHOUSE self
|
||||
|
||||
--- Triggers the FSM event "Status" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Status
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #number delay Delay in seconds.
|
||||
|
||||
|
||||
--- Triggers the FSM event "Request".
|
||||
-- @function [parent=#WAREHOUSE] Request
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAsset Number of assets requested. Default 1.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
|
||||
--- Triggers the FSM event "Request" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Request
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #number delay Delay in seconds.
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAsset Number of assets requested. Default 1.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
|
||||
--- Triggers the FSM event "Delivered".
|
||||
-- @function [parent=#WAREHOUSE] Delivered
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Group#GROUP group Group that was delivered.
|
||||
|
||||
--- Triggers the FSM event "Delivered" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Delivered
|
||||
-- @param #number delay Delay in seconds.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Group#GROUP group Group that was delivered.
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function WAREHOUSE:onafterStart(From, Event, To)
|
||||
env.info("FF starting warehouse at airbase "..self.homebase:GetName())
|
||||
|
||||
-- handle events
|
||||
-- event takeoff
|
||||
-- event landing
|
||||
-- event crash/dead
|
||||
-- event base captured
|
||||
self:__Status(-5)
|
||||
end
|
||||
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function WAREHOUSE:onafterStatus(From, Event, To)
|
||||
env.info("FF checking warehouse status of airbase "..self.homebase:GetName())
|
||||
|
||||
env.info(string.format("FF warehouse at %s: number of transport planes = %d", self.homebase:GetName(), #self.plane))
|
||||
|
||||
self:__Status(-30)
|
||||
end
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAssed Number of groups of that asset requested.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
function WAREHOUSE:onafterRequest(From, Event, To, Airbase, Asset, nAsset, TransportType)
|
||||
env.info(string.format("FF airbase %s is requesting asset %s from warehouse %s", Airbase:GetName(), Asset, self.homebase:GetName()))
|
||||
|
||||
local nAsset=nAsset or 1
|
||||
|
||||
if TransportType=="Air" then
|
||||
|
||||
-- Get a random template from the stock list.
|
||||
local _chosenone=math.random(#self.plane)
|
||||
|
||||
-- Select template group name.
|
||||
local template=self.plane[_chosenone]
|
||||
|
||||
if template then
|
||||
|
||||
-- Spawn plane at warehouse homebase.
|
||||
local Plane=SPAWN:New(template):SpawnAtAirbase(Airbase, nil, nil, nil, false)
|
||||
|
||||
if Plane==nil then
|
||||
-- Plane was not spawned correctly. Try again in 60 seconds.
|
||||
self:__Request( 60, Airbase, Asset, nAsset, TransportType)
|
||||
return
|
||||
else
|
||||
-- Remove chosen plane from list.
|
||||
table.remove(self.plane,_chosenone)
|
||||
end
|
||||
|
||||
-- New empty cargo set.
|
||||
local CargoGroups = SET_CARGO:New()
|
||||
|
||||
-- Spawn requested assets.
|
||||
local spawn=SPAWN:New("Infantry Platoon Alpha")
|
||||
|
||||
for i=1,nAsset do
|
||||
local spawngroup=spawn:SpawnFromVec3(self.homebase:GetZone():GetRandomPointVec3(100,500))
|
||||
local cargogroup = CARGO_GROUP:New(spawngroup, "Infantry", string.format( "Infantry Platoon %d", i), 5000, 35)
|
||||
CargoGroups:AddCargo(cargogroup)
|
||||
end
|
||||
|
||||
-- Define cargo airplane.
|
||||
local CargoPlane = AI_CARGO_AIRPLANE:New(Plane, CargoGroups)
|
||||
|
||||
-- Pickup cargo at homebase.
|
||||
CargoPlane:__Pickup(5, self.homebase)
|
||||
|
||||
-- Set warehouse state so that we can retreive it later.
|
||||
Plane:SetState(Plane, "WAREHOUSE", self)
|
||||
|
||||
-- Once the cargo was loaded start off to deploy airbase.
|
||||
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
||||
CargoPlane:__Deploy(10, Airbase, 500)
|
||||
end
|
||||
|
||||
--- Function
|
||||
-- @param Wrapper.Group#GROUP Airplane
|
||||
function CargoPlane:OnAfterUnloaded(Airplane, From, Event, To)
|
||||
local group=CargoPlane.Cargo:GetObject()
|
||||
local Airplane=Airplane --Wrapper.Group#GROUP
|
||||
local warehouse Airplane:GetState(Airplane, "WAREHOUSE") --#WAREHOUSE
|
||||
warehouse:__Delivered(1, group)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Group#GROUP Group The group that was delivered.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAssed Number of groups of that asset requested.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
function WAREHOUSE:onafterDelivered(From, Event, To, Group)
|
||||
local road=Group:GetCoordinate():GetClosestPointToRoad()
|
||||
local speed=Group:GetSpeedMax()*0.5
|
||||
Group:RouteGroundTo(road, speed, "Off Road")
|
||||
end
|
||||
|
||||
--- Add an airplane group to the warehouse stock.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string templateprefix Name of the late activated template group as defined in the mission editor.
|
||||
-- @param #number n Number of groups to add to the warehouse stock.
|
||||
-- @return #WAREHOUSE self
|
||||
function WAREHOUSE:AddTransportPlane(templateprefix, n)
|
||||
|
||||
local n=n or 1
|
||||
|
||||
local group=GROUP:FindByName(templateprefix)
|
||||
local DCSgroup=group:GetDCSObject()
|
||||
local DCSunit=DCSgroup:getUnit(1)
|
||||
local DCSdesc=DCSunit:getDesc()
|
||||
local DCSdisplay=DCSunit:getDesc().displayName
|
||||
local DCScategory=DCSgroup:getCategory()
|
||||
local DCStype=DCSunit:getTypeName()
|
||||
|
||||
-- Add this n times to the table.
|
||||
for i=1,n do
|
||||
table.insert(self.plane, templateprefix)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Add an airplane group to the warehouse stock.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string templateprefix Name of the late activated template group as defined in the mission editor.
|
||||
-- @param #number n Number of groups to add to the warehouse stock.
|
||||
-- @return #WAREHOUSE self
|
||||
function WAREHOUSE:AddInfantry(templateprefix, n)
|
||||
|
||||
local n=n or 1
|
||||
|
||||
local group=GROUP:FindByName(templateprefix)
|
||||
|
||||
if group then
|
||||
|
||||
local DCSgroup=group:GetDCSObject()
|
||||
local DCSunit=DCSgroup:getUnit(1)
|
||||
local DCSdesc=DCSunit:getDesc()
|
||||
local DCSdisplay=DCSunit:getDesc().displayName
|
||||
local DCScategory=DCSgroup:getCategory()
|
||||
local DCStype=DCSunit:getTypeName()
|
||||
|
||||
-- Add this n times to the table.
|
||||
for i=1,n do
|
||||
table.insert(self.infantry, {templatename=templateprefix, category=DCScategory, typename=DCStype})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@ -959,6 +959,7 @@ do -- Group
|
||||
-- @field HELICOPTER
|
||||
-- @field GROUND
|
||||
-- @field SHIP
|
||||
-- @field TRAIN
|
||||
|
||||
-- Static Functions
|
||||
|
||||
|
||||
@ -68,6 +68,8 @@
|
||||
-- @field #number dtBombtrack Time step [sec] used for tracking released bomb/rocket positions. Default 0.005 seconds.
|
||||
-- @field #number BombtrackThreshold Bombs/rockets/missiles are only tracked if player-range distance is smaller than this threashold [m]. Default 25000 m.
|
||||
-- @field #number Tmsg Time [sec] messages to players are displayed. Default 30 sec.
|
||||
-- @field #string examinergroupname Name of the examiner group which should get all messages.
|
||||
-- @field #boolean examinerexclusive If true, only the examiner gets messages. If false, clients and examiner get messages.
|
||||
-- @field #number strafemaxalt Maximum altitude above ground for registering for a strafe run. Default is 914 m = 3000 ft.
|
||||
-- @field #number ndisplayresult Number of (player) results that a displayed. Default is 10.
|
||||
-- @field Utilities.Utils#SMOKECOLOR BombSmokeColor Color id used for smoking bomb targets.
|
||||
@ -234,6 +236,8 @@ RANGE={
|
||||
dtBombtrack=0.005,
|
||||
BombtrackThreshold=25000,
|
||||
Tmsg=30,
|
||||
examinergroupname=nil,
|
||||
examinerexclusive=nil,
|
||||
strafemaxalt=914,
|
||||
ndisplayresult=10,
|
||||
BombSmokeColor=SMOKECOLOR.Red,
|
||||
@ -279,8 +283,8 @@ RANGE.MenuF10={}
|
||||
RANGE.id="RANGE | "
|
||||
|
||||
--- Range script version.
|
||||
-- @field #number version
|
||||
RANGE.version="1.2.0"
|
||||
-- @field #string version
|
||||
RANGE.version="1.2.1"
|
||||
|
||||
--TODO list:
|
||||
--TODO: Add custom weapons, which can be specified by the user.
|
||||
@ -434,6 +438,15 @@ function RANGE:SetMessageTimeDuration(time)
|
||||
self.Tmsg=time or RANGE.Defaults.Tmsg
|
||||
end
|
||||
|
||||
--- Set messages to examiner. The examiner will receive messages from all clients.
|
||||
-- @param #RANGE self
|
||||
-- @param #string examinergroupname Name of the group of the examiner.
|
||||
-- @param #boolean exclusively If true, messages are send exclusively to the examiner, i.e. not to the clients.
|
||||
function RANGE:SetMessageToExaminer(examinergroupname, exclusively)
|
||||
self.examinergroupname=examinergroupname
|
||||
self.examinerexclusive=exclusively
|
||||
end
|
||||
|
||||
--- Set max number of player results that are displayed.
|
||||
-- @param #RANGE self
|
||||
-- @param #number nmax Number of results. Default is 10.
|
||||
@ -2119,13 +2132,24 @@ function RANGE:_DisplayMessageToGroup(_unit, _text, _time, _clear)
|
||||
-- Group ID.
|
||||
local _gid=_unit:GetGroup():GetID()
|
||||
|
||||
if _gid then
|
||||
if _gid and not self.examinerexclusive then
|
||||
if _clear == true then
|
||||
trigger.action.outTextForGroup(_gid, _text, _time, _clear)
|
||||
else
|
||||
trigger.action.outTextForGroup(_gid, _text, _time)
|
||||
end
|
||||
end
|
||||
|
||||
if self.examinergroupname~=nil then
|
||||
local _examinerid=GROUP:FindByName(self.examinergroupname):GetID()
|
||||
if _examinerid then
|
||||
if _clear == true then
|
||||
trigger.action.outTextForGroup(_examinerid, _text, _time, _clear)
|
||||
else
|
||||
trigger.action.outTextForGroup(_examinerid, _text, _time)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
383
Moose Development/Moose/Functional/Warehouse.lua
Normal file
383
Moose Development/Moose/Functional/Warehouse.lua
Normal file
@ -0,0 +1,383 @@
|
||||
--- **Functional** - (R2.4) - Manages assets of an airbase and transportation to other airbases.
|
||||
--
|
||||
--
|
||||
-- Features:
|
||||
--
|
||||
-- * Some nice stuff.
|
||||
--
|
||||
-- # QUICK START GUIDE
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Authors: **funkyfranky**
|
||||
--
|
||||
-- @module Functional.Warehouse
|
||||
-- @image Warehouse.JPG
|
||||
|
||||
--- WAREHOUSE class.
|
||||
-- @type WAREHOUSE
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- Manages ground assets of an airbase and offers the possibility to transport them to another airbase or warehouse.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # Demo Missions
|
||||
--
|
||||
-- ### None.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # YouTube Channel
|
||||
--
|
||||
-- ### None.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 
|
||||
--
|
||||
-- Warehouse
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # USAGE GUIDE
|
||||
--
|
||||
--
|
||||
--
|
||||
-- @field #WAREHOUSE
|
||||
WAREHOUSE = {
|
||||
ClassName = "WAREHOUSE",
|
||||
coalition = nil,
|
||||
homebase = nil,
|
||||
stock = {},
|
||||
}
|
||||
|
||||
--- Type Warehouse stock table. table.insert(self.stock, {templatename=templategroupname, category=DCScategory, type=DCStype, transport=transport, fighther=fighter, tanker=tanker, awacs=awacs, artillery=artillery})
|
||||
-- @type WAREHOUSE.Stock
|
||||
-- @field #string templatename Name of the template group.
|
||||
-- @field DCS#Category category Category of the group. Airplane, helicopter, ...
|
||||
-- @field #string type Type of the group
|
||||
-- @field #boolean fighter If true, group is a fighter airplane.
|
||||
-- @field #boolean transport If truie, group can transport other units either by air or ground.
|
||||
-- @field #boolean tanker If true, group is a tanker and can refuel other air units.
|
||||
-- @field #boolean awacs If true, group has AWACS capabilities.
|
||||
-- @field #boolean artillery If true, group is an artillery unit.
|
||||
|
||||
--- Warehouse classes.
|
||||
-- @field Warehouse.Class Class
|
||||
WAREHOUSE.Class = {
|
||||
TRANSPORT=1,
|
||||
FIGHTER=2,
|
||||
TANKER=3,
|
||||
AWACS=4,
|
||||
ARTY=5,
|
||||
}
|
||||
|
||||
--- Warehouse categories
|
||||
-- @field Category
|
||||
WAREHOUSE.Category = {
|
||||
AIRPLANE = 0,
|
||||
HELICOPTER = 1,
|
||||
GROUND = 2,
|
||||
SHIP = 3,
|
||||
TRAIN = 4,
|
||||
}
|
||||
|
||||
--- Warehouse class version.
|
||||
-- @field #number version
|
||||
WAREHOUSE.version="0.1.0"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO: Warehuse todo list.
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: A lot!
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor(s)
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- WAREHOUSE constructor. Creates a new WAREHOUSE object.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Airbase#AIRBASE airbase Airbase.
|
||||
-- @return #WAREHOUSE self
|
||||
function WAREHOUSE:NewAirbase(airbase)
|
||||
BASE:E({airbase=airbase})
|
||||
|
||||
-- Print version.
|
||||
env.info(string.format("Adding warehouse v%s for airbase %s", WAREHOUSE.version, airbase:GetName()))
|
||||
|
||||
-- Inherit everthing from FSM class.
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #WAREHOUSE
|
||||
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.wid=string.format("WAREHOUSE %s | ", airbase:GetName())
|
||||
|
||||
-- Set some variables.
|
||||
self.homebase=airbase
|
||||
self.coordinate=airbase:GetCoordinate()
|
||||
self.coalition=airbase:GetCoalition()
|
||||
|
||||
self:AddTransition("*", "Start", "Running")
|
||||
self:AddTransition("*", "Status", "*")
|
||||
self:AddTransition("*", "Request", "*")
|
||||
self:AddTransition("*", "Delivered", "*")
|
||||
|
||||
--- Triggers the FSM event "Start".
|
||||
-- @function [parent=#WAREHOUSE] Start
|
||||
-- @param #WAREHOUSE self
|
||||
|
||||
--- Triggers the FSM event "Start" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Start
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #number delay Delay in seconds.
|
||||
|
||||
|
||||
--- Triggers the FSM event "Status".
|
||||
-- @function [parent=#WAREHOUSE] Status
|
||||
-- @param #WAREHOUSE self
|
||||
|
||||
--- Triggers the FSM event "Status" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Status
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #number delay Delay in seconds.
|
||||
|
||||
|
||||
--- Triggers the FSM event "Request".
|
||||
-- @function [parent=#WAREHOUSE] Request
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAsset Number of assets requested. Default 1.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
|
||||
--- Triggers the FSM event "Request" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Request
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #number delay Delay in seconds.
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAsset Number of assets requested. Default 1.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
|
||||
--- Triggers the FSM event "Delivered".
|
||||
-- @function [parent=#WAREHOUSE] Delivered
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Group#GROUP group Group that was delivered.
|
||||
|
||||
--- Triggers the FSM event "Delivered" after a delay.
|
||||
-- @function [parent=#WAREHOUSE] __Delivered
|
||||
-- @param #number delay Delay in seconds.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param Wrapper.Group#GROUP group Group that was delivered.
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- FSM states
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function WAREHOUSE:onafterStart(From, Event, To)
|
||||
env.info("FF starting warehouse at airbase "..self.homebase:GetName())
|
||||
|
||||
-- handle events
|
||||
-- event takeoff
|
||||
-- event landing
|
||||
-- event crash/dead
|
||||
-- event base captured
|
||||
self:__Status(-5)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function WAREHOUSE:onafterStatus(From, Event, To)
|
||||
env.info("FF checking warehouse status of airbase "..self.homebase:GetName())
|
||||
|
||||
env.info(string.format("FF warehouse at %s: number of stock = %d", self.homebase:GetName(), #self.stock))
|
||||
|
||||
self:__Status(-30)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAssed Number of groups of that asset requested.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
function WAREHOUSE:onafterRequest(From, Event, To, Airbase, Asset, nAsset, TransportType)
|
||||
env.info(string.format("FF airbase %s is requesting asset %s from warehouse %s", Airbase:GetName(), Asset, self.homebase:GetName()))
|
||||
|
||||
local nAsset=nAsset or 1
|
||||
|
||||
if TransportType=="Air" then
|
||||
|
||||
-- Get a random template from the stock list.
|
||||
local _chosenone=math.random(#self.stock)
|
||||
|
||||
-- Select template group name.
|
||||
--TODO: FILTER HERE'!
|
||||
local template=self.stock[_chosenone].templatename
|
||||
|
||||
if template then
|
||||
|
||||
-- Spawn plane at warehouse homebase.
|
||||
local Plane=SPAWN:New(template):SpawnAtAirbase(Airbase, nil, nil, nil, false)
|
||||
|
||||
if Plane==nil then
|
||||
-- Plane was not spawned correctly. Try again in 60 seconds.
|
||||
self:__Request( 60, Airbase, Asset, nAsset, TransportType)
|
||||
return
|
||||
else
|
||||
-- Remove chosen plane from list.
|
||||
table.remove(self.stock,_chosenone)
|
||||
end
|
||||
|
||||
-- New empty cargo set.
|
||||
local CargoGroups = SET_CARGO:New()
|
||||
|
||||
-- Spawn requested assets.
|
||||
local spawn=SPAWN:New("Infantry Platoon Alpha")
|
||||
|
||||
for i=1,nAsset do
|
||||
local spawngroup=spawn:SpawnFromVec3(self.homebase:GetZone():GetRandomPointVec3(100,500))
|
||||
local cargogroup = CARGO_GROUP:New(spawngroup, "Infantry", string.format( "Infantry Platoon %d", i), 5000, 35)
|
||||
CargoGroups:AddCargo(cargogroup)
|
||||
end
|
||||
|
||||
-- Define cargo airplane.
|
||||
local CargoPlane = AI_CARGO_AIRPLANE:New(Plane, CargoGroups)
|
||||
|
||||
-- Pickup cargo at homebase.
|
||||
CargoPlane:__Pickup(5, self.homebase)
|
||||
|
||||
-- Set warehouse state so that we can retreive it later.
|
||||
Plane:SetState(Plane, "WAREHOUSE", self)
|
||||
|
||||
-- Once the cargo was loaded start off to deploy airbase.
|
||||
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
||||
CargoPlane:__Deploy(10, Airbase, 500)
|
||||
end
|
||||
|
||||
--- Function
|
||||
-- @param Wrapper.Group#GROUP Airplane
|
||||
function CargoPlane:OnAfterUnloaded(Airplane, From, Event, To)
|
||||
local group=CargoPlane.Cargo:GetObject()
|
||||
local Airplane=Airplane --Wrapper.Group#GROUP
|
||||
local warehouse Airplane:GetState(Airplane, "WAREHOUSE") --#WAREHOUSE
|
||||
warehouse:__Delivered(1, group)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Warehouse
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Group#GROUP Group The group that was delivered.
|
||||
-- @param #string Asset Asset that is requested.
|
||||
-- @param #number nAssed Number of groups of that asset requested.
|
||||
-- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC"
|
||||
function WAREHOUSE:onafterDelivered(From, Event, To, Group)
|
||||
local road=Group:GetCoordinate():GetClosestPointToRoad()
|
||||
local speed=Group:GetSpeedMax()*0.5
|
||||
Group:RouteGroundTo(road, speed, "Off Road")
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Add an airplane group to the warehouse stock.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #string templategroupname Name of the late activated template group as defined in the mission editor.
|
||||
-- @param #number ngroups Number of groups to add to the warehouse stock. Default is 1.
|
||||
-- @param #boolean istransport If true, this group will act as transport unit to transport other assets to another airbase. If false, this unit will not be used as transport unit. By default the behavior is determined for the group's attributes.
|
||||
-- @return #WAREHOUSE self
|
||||
function WAREHOUSE:AddAsset(templategroupname, ngroups, istransport)
|
||||
|
||||
local n=ngroups or 1
|
||||
|
||||
local group=GROUP:FindByName(templategroupname)
|
||||
|
||||
if group then
|
||||
|
||||
local DCSgroup=group:GetDCSObject()
|
||||
local DCSunit=DCSgroup:getUnit(1)
|
||||
local DCSdesc=DCSunit:getDesc()
|
||||
local DCSdisplay=DCSunit:getDesc().displayName
|
||||
local DCScategory=DCSgroup:getCategory()
|
||||
local DCStype=DCSunit:getTypeName()
|
||||
|
||||
env.info(string.format("group name = %s", group:GetName()))
|
||||
env.info(string.format("display name = %s", DCSdisplay))
|
||||
env.info(string.format("category = %s", DCScategory))
|
||||
env.info(string.format("type = %s", DCStype))
|
||||
env.info(string.format("attribute infantry = %s", tostring(group:HasAttribute("Infantry"))))
|
||||
self:E({desc=DCSdesc})
|
||||
|
||||
local transport=group:HasAttribute("Transport helicopters") or group:HasAttribute("Transports") or group:HasAttribute("Infantry carriers")
|
||||
local fighter=group:HasAttribute("Fighters") or group:HasAttribute("Interceptors") or group:HasAttribute("Multirole fighters")
|
||||
local tanker=group:HasAttribute("Tankers")
|
||||
local awacs=group:HasAttribute("AWACS")
|
||||
local apc=group:HasAttribute("Infantry carriers")
|
||||
local artillery=group:HasAttribute("Artillery")
|
||||
env.info(string.format("attribute transport = %s", tostring(transport)))
|
||||
env.info(string.format("attribute apc = %s", tostring(apc)))
|
||||
env.info(string.format("attribute figther = %s", tostring(fighter)))
|
||||
env.info(string.format("attribute tanker = %s", tostring(tanker)))
|
||||
env.info(string.format("attribute awacs = %s", tostring(awacs)))
|
||||
env.info(string.format("attribute artillery = %s", tostring(artillery)))
|
||||
|
||||
-- Add this n times to the table.
|
||||
for i=1,n do
|
||||
table.insert(self.stock, {templatename=templategroupname, category=DCScategory, type=DCStype, transport=transport, fighther=fighter, tanker=tanker, awacs=awacs, artillery=artillery})
|
||||
end
|
||||
|
||||
else
|
||||
-- Group name does not exist!
|
||||
self:E(string.format("ERROR: Template group name not defined in the mission editor. Check the spelling! templategroupname=%s",tostring(templategroupname)))
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Helper functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Filter stock assets by table entry.
|
||||
-- @param #WAREHOUSE self
|
||||
-- @param #WAREHOUSE.Stock entry
|
||||
function WAREHOUSE:_FilterStock(entry)
|
||||
--entry.artillery
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -335,8 +335,7 @@ end
|
||||
|
||||
--- Returns the country of the DCS Group.
|
||||
-- @param #GROUP self
|
||||
-- @return DCS#country.id The country identifier.
|
||||
-- @return #nil The DCS Group is not existing or alive.
|
||||
-- @return DCS#country.id The country identifier or nil if the DCS Group is not existing or alive.
|
||||
function GROUP:GetCountry()
|
||||
self:F2( self.GroupName )
|
||||
|
||||
@ -350,6 +349,40 @@ function GROUP:GetCountry()
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
--- Check if at least one (or all) unit(s) has (have) a certain attribute.
|
||||
-- See [hoggit documentation](https://wiki.hoggitworld.com/view/DCS_func_hasAttribute).
|
||||
-- @param #GROUP self
|
||||
-- @param #string attribute The name of the attribute the group is supposed to have. Valid attributes can be found in the "db_attributes.lua" file which is located at in "C:\Program Files\Eagle Dynamics\DCS World\Scripts\Database".
|
||||
-- @param #boolean all If true, all units of the group must have the attribute in order to return true. Default is only one unit of a heterogenious group needs to have the attribute.
|
||||
-- @return #boolean Group has this attribute.
|
||||
function GROUP:HasAttribute(attribute, all)
|
||||
|
||||
-- Get all units of the group.
|
||||
local _units=self:GetUnits()
|
||||
|
||||
local _allhave=true
|
||||
local _onehas=false
|
||||
|
||||
for _,_unit in pairs(_units) do
|
||||
local _unit=_unit --Wrapper.Unit#UNIT
|
||||
if _unit then
|
||||
local _hastit=_unit:HasAttribute(attribute)
|
||||
if _hastit==true then
|
||||
_onehas=true
|
||||
else
|
||||
_allhave=false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if all==true then
|
||||
return _allhave
|
||||
else
|
||||
return _onehas
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the maximum speed of the group.
|
||||
-- If the group is heterogenious and consists of different units, the max speed of the slowest unit is returned.
|
||||
-- @param #GROUP self
|
||||
|
||||
@ -57,6 +57,7 @@ Functional/ZoneCaptureCoalition.lua
|
||||
Functional/Artillery.lua
|
||||
Functional/Suppression.lua
|
||||
Functional/PseudoATC.lua
|
||||
Functional/Warehouse.lua
|
||||
|
||||
AI/AI_Balancer.lua
|
||||
AI/AI_A2A.lua
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user