mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-18 05:05:56 +00:00
Warehouse and other things
This commit is contained in:
@@ -1,172 +0,0 @@
|
||||
--- **Functional** - (R2.4) JTAC
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- JTAC mimic
|
||||
--
|
||||
-- ## Features:
|
||||
--
|
||||
-- * Feature 1
|
||||
-- * Feature 2
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
-- # Demo Missions
|
||||
--
|
||||
-- ### [MOOSE - ALL Demo Missions](https://github.com/FlightControl-Master/MOOSE_MISSIONS)
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
-- # YouTube Channel
|
||||
--
|
||||
-- ### [MOOSE YouTube Channel](https://www.youtube.com/channel/UCjrA9j5LQoWsG4SpS8i79Qg)
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **[funkyfranky](https://forums.eagle.ru/member.php?u=115026)**
|
||||
--
|
||||
-- ### Contributions: [FlightControl](https://forums.eagle.ru/member.php?u=89536)
|
||||
--
|
||||
-- ====
|
||||
-- @module Functional.Jtac
|
||||
-- @image JTAC.JPG
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--- JTAC class
|
||||
-- @type JTAC
|
||||
-- @field #string ClassName Name of the class.
|
||||
|
||||
--- Easy assignment of JTAC.
|
||||
--
|
||||
-- A new ARTY object can be created with the @{#ARTY.New}(*group*) contructor.
|
||||
-- The parameter *group* has to be a MOOSE Group object and defines ARTY group.
|
||||
--
|
||||
-- The ARTY FSM process can be started by the @{#ARTY.Start}() command.
|
||||
--
|
||||
-- ## The ARTY Process
|
||||
--
|
||||
-- 
|
||||
--
|
||||
--
|
||||
--
|
||||
-- @field #JTAC
|
||||
JTAC={
|
||||
ClassName="JTAC",
|
||||
Debug=false,
|
||||
}
|
||||
|
||||
--- Some ID to identify who we are in output of the DCS.log file.
|
||||
-- @field #string id
|
||||
JTAC.id="JTAC | "
|
||||
|
||||
--- Arty script version.
|
||||
-- @field #string version
|
||||
JTAC.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO list:
|
||||
-- TODO: a lot.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Creates a new JTAC object.
|
||||
-- @param #JTAC self
|
||||
-- @param Wrapper.Group#GROUP group The GROUP object for which artillery tasks should be assigned.
|
||||
-- @param alias (Optional) Alias name the group will be calling itself when sending messages. Default is the group name.
|
||||
-- @return #JTAC JTAC object or nil if group does not exist or is not a ground or naval group.
|
||||
function JTAC:New(group, alias)
|
||||
BASE:F2(group)
|
||||
|
||||
-- Inherits from FSM_CONTROLLABLE
|
||||
local self=BASE:Inherit(self, FSM_CONTROLLABLE:New()) -- #JTAC
|
||||
|
||||
-- Check that group is present.
|
||||
if group then
|
||||
self:T(JTAC.id..string.format("JTAC script version %s. Added group %s.", JTAC.version, group:GetName()))
|
||||
else
|
||||
self:E(JTAC.id.."ERROR: Requested JTAC group does not exist! (Has to be a MOOSE group.)")
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Set the controllable for the FSM.
|
||||
self:SetControllable(group)
|
||||
|
||||
---------------
|
||||
-- Transitions:
|
||||
---------------
|
||||
|
||||
-- Entry.
|
||||
self:AddTransition("*", "Start", "Ready")
|
||||
self:AddTransition("Ready", "LaserOn", "Lasing")
|
||||
self:AddTransition("Lasing", "Lasing", "Lasing")
|
||||
self:AddTransition("Lasing", "LaserOff", "Ready")
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- FSM Start Event
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- After "Start" event.
|
||||
-- @param #JTAC 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 JTAC:onafterStart(Controllable, From, Event, To)
|
||||
--self:_EventFromTo("onafterStart", Event, From, To)
|
||||
|
||||
-- Debug output.
|
||||
local text=string.format("Started JTAC version %s for group %s.", JTAC.version, Controllable:GetName())
|
||||
self:E(JTAC.id..text)
|
||||
MESSAGE:New(text, 5):ToAllIf(self.Debug)
|
||||
|
||||
end
|
||||
|
||||
--- After "LaserOn" event.
|
||||
-- @param #JTAC self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Unit#UNIT Target Target that should be lased.
|
||||
function JTAC:onafterLaserOn(Controllable, From, Event, To, Target)
|
||||
--self:_EventFromTo("onafterStart", Event, From, To)
|
||||
|
||||
-- Debug output.
|
||||
local text=string.format("JTAC %s lasing target %s.", Controllable:GetName(), Target:GetName())
|
||||
self:E(JTAC.id..text)
|
||||
MESSAGE:New(text, 5):ToAllIf(self.Debug)
|
||||
|
||||
-- Start lasing.
|
||||
Controllable:LaseUnit(Target, self.LaserCode, self.Duration)
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- After "LaserOff" event.
|
||||
-- @param #JTAC 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 JTAC:onafterLaserOff(Controllable, From, Event, To)
|
||||
--self:_EventFromTo("onafterStart", Event, From, To)
|
||||
|
||||
-- Debug output.
|
||||
local text=string.format("JTAC %s stoped lasing.", Controllable:GetName())
|
||||
self:E(JTAC.id..text)
|
||||
MESSAGE:New(text, 5):ToAllIf(self.Debug)
|
||||
|
||||
-- Turn of laser.
|
||||
Controllable:LaseOff()
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -328,29 +328,9 @@ function WAREHOUSE:onbeforeRequest(From, Event, To, Airbase, AssetDescriptor, As
|
||||
local _stockitem=_stockrequest[1] --#WAREHOUSE.Stockitem
|
||||
local _assetattribute=self:_GetAttribute(_stockitem.templatename)
|
||||
|
||||
-- Shortcut
|
||||
-- Get assets in stock which are of the right type.
|
||||
local _instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, TransportType)
|
||||
|
||||
--[[
|
||||
-- Check the availability of transport units.
|
||||
if _TT == WAREHOUSE.TransportType.AIRPLANE then
|
||||
_instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.TRANSPORT_PLANE)
|
||||
elseif _TT == WAREHOUSE.TransportType.HELICOPTER then
|
||||
_instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.TRANSPORT_HELO)
|
||||
elseif _TT == WAREHOUSE.TransportType.GROUND then
|
||||
_instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.TRANSPORT_APC)
|
||||
elseif _TT == WAREHOUSE.TransportType.SHIP then
|
||||
_instock=0
|
||||
elseif _TT == WAREHOUSE.TransportType.TRAIN then
|
||||
_instock=0
|
||||
elseif _TT == WAREHOUSE.TransportType.SELFPROPELLED then
|
||||
_instock=_stockrequest
|
||||
else
|
||||
self:E(self.wid..string.format("ERROR: unknown transport type requested! type = %s", tostring(TransportType)))
|
||||
return false
|
||||
end
|
||||
]]
|
||||
|
||||
-- Check that a transport unit is available.
|
||||
if #_instock==0 and TransportType~=WAREHOUSE.TransportType.SELFPROPELLED then
|
||||
local text=string.format("Request denied! No transport unit currently available.")
|
||||
@@ -359,6 +339,8 @@ function WAREHOUSE:onbeforeRequest(From, Event, To, Airbase, AssetDescriptor, As
|
||||
return false
|
||||
end
|
||||
|
||||
-- TODO: For aircraft check that a parking spot is available.
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -406,6 +388,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
self:_DeleteStockItem(_id)
|
||||
end
|
||||
|
||||
-- No transport unit requested. Assets go by themselfes.
|
||||
if TransportType==WAREHOUSE.TransportType.SELFPROPELLED then
|
||||
for _i,_spawngroup in pairs(_spawngroups) do
|
||||
local group=_spawngroup --Wrapper.Group#GROUP
|
||||
@@ -415,13 +398,12 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
end
|
||||
|
||||
|
||||
--TODO: naje nearradius depended on types.
|
||||
--TODO: make nearradius depended on transport type and asset type.
|
||||
local _loadradius=5000
|
||||
local _nearradius=35
|
||||
|
||||
-- Add spawned groups to cargo group object.
|
||||
for _i,_spawngroup in pairs(_spawngroups) do
|
||||
--TODO: check near and load radius.
|
||||
local _name=string.format("%s %d",AssetDescriptorValue, _i)
|
||||
env.info(string.format("FF cargo group %d: %s",_i,_name))
|
||||
local cargogroup = CARGO_GROUP:New(_spawngroup, AssetDescriptorValue, _name, _loadradius, _nearradius)
|
||||
@@ -430,8 +412,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
|
||||
env.info(string.format("FF cargo set object names %s", CargoGroups:GetObjectNames()))
|
||||
|
||||
|
||||
|
||||
|
||||
-- Filter the requested assets.
|
||||
local _transportitem --#WAREHOUSE.Stockitem
|
||||
@@ -452,8 +432,8 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
if Plane==nil then
|
||||
-- Plane was not spawned correctly. Try again in 60 seconds.
|
||||
local text="Technical problems with the transport plane occurred. Request was cancelled! Try again later."
|
||||
--self:__Request(60, Airbase, AssetDescriptor, AssetDescriptorValue, nAsset, TransportType)
|
||||
--TODO: despawn units and but them back into the warehouse.
|
||||
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.Report or self.Debug)
|
||||
--TODO: Despawn asset units and but them back into the warehouse.
|
||||
return
|
||||
else
|
||||
-- Remove chosen transport asset from list.
|
||||
@@ -472,7 +452,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
|
||||
--- Once the cargo was loaded start off to deploy airbase.
|
||||
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
||||
CargoPlane:__Deploy(10, Airbase, 500)
|
||||
CargoPlane:__Deploy(10, Airbase)
|
||||
end
|
||||
|
||||
--- Function called when cargo has arrived and was unloaded.
|
||||
@@ -520,8 +500,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
-- Trigger Delivered event.
|
||||
warehouse:__Delivered(1, group)
|
||||
end
|
||||
|
||||
|
||||
|
||||
elseif TransportType==WAREHOUSE.TransportType.APC then
|
||||
|
||||
-- Spawn APC in spawn zone.
|
||||
@@ -574,12 +553,10 @@ end
|
||||
-- @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)
|
||||
env.info("FF warehouse cargo delivered! Croutine to closest point on road")
|
||||
local road=Group:GetCoordinate():GetClosestPointToRoad()
|
||||
local speed=Group:GetSpeedMax()*0.5
|
||||
local speed=Group:GetSpeedMax()*0.6
|
||||
Group:RouteGroundTo(road, speed, "Off Road")
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user