mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
WAREHOUSE
This commit is contained in:
parent
b46c238dda
commit
009e38b6f7
@ -224,7 +224,8 @@ function AI_CARGO_HELICOPTER:onafterLanded( Helicopter, From, Event, To )
|
|||||||
|
|
||||||
if self.RoutePickup == true then
|
if self.RoutePickup == true then
|
||||||
if Helicopter:GetHeight( true ) <= 5 and Helicopter:GetVelocityKMH() < 10 then
|
if Helicopter:GetHeight( true ) <= 5 and Helicopter:GetVelocityKMH() < 10 then
|
||||||
self:Load( Helicopter:GetPointVec2() )
|
--self:Load( Helicopter:GetPointVec2() )
|
||||||
|
self:Load()
|
||||||
self.RoutePickup = false
|
self.RoutePickup = false
|
||||||
self.Relocating = true
|
self.Relocating = true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -252,6 +252,15 @@ function WAREHOUSE:NewAirbase(airbase)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Set a zone where the (ground) assets of the warehouse are spawned once requested.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
-- @param Core.Zone#ZONE zone The spawn zone.
|
||||||
|
-- @return #WAREHOUSE self
|
||||||
|
function WAREHOUSE:SetSpawnZone(zone)
|
||||||
|
self.spawnzone=zone
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- FSM states
|
-- FSM states
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -262,7 +271,7 @@ end
|
|||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
function WAREHOUSE:onafterStart(From, Event, To)
|
function WAREHOUSE:onafterStart(From, Event, To)
|
||||||
self:E(self.wid..string.format("Starting warehouse at airbase %s.", self.homebase:GetName()))
|
self:E(self.wid..string.format("Starting warehouse at airbase %s, category %d, coalition %d.", self.homebase:GetName(), self.category, self.coalition))
|
||||||
|
|
||||||
-- handle events
|
-- handle events
|
||||||
-- event takeoff
|
-- event takeoff
|
||||||
@ -307,13 +316,7 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Print queue.
|
-- Print queue.
|
||||||
env.info(self.wid.."Queue:")
|
self:_PrintQueue()
|
||||||
for _,_qitem in ipairs(self.queue) do
|
|
||||||
local qitem=_qitem --#WAREHOUSE.Queueitem
|
|
||||||
local text=string.format("uid=%d, prio=%d, airbase=%s, descriptor: %s=%s, nasssets=%d, transport=%s, ntransport=%d",
|
|
||||||
qitem.uid, qitem.prio, qitem.airbase:GetName(), qitem.assetdesc,tostring(qitem.assetdescval),qitem.nasset,qitem.transporttype,qitem.ntransport)
|
|
||||||
env.info(text)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check queue and handle requests if possible.
|
-- Check queue and handle requests if possible.
|
||||||
local request=self:_CheckQueue()
|
local request=self:_CheckQueue()
|
||||||
@ -325,7 +328,7 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Call status again in 30 sec.
|
-- Call status again in 30 sec.
|
||||||
self:__Status(30)
|
self:__Status(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -384,12 +387,15 @@ function WAREHOUSE:_CheckQueue()
|
|||||||
local okay=true
|
local okay=true
|
||||||
-- Check if number of requested assets is in stock.
|
-- Check if number of requested assets is in stock.
|
||||||
local _instock=#self:_FilterStock(self.stock, qitem.assetdesc, qitem.assetdescval)
|
local _instock=#self:_FilterStock(self.stock, qitem.assetdesc, qitem.assetdescval)
|
||||||
|
env.info(string.format("FF desc = %s val=%s number=%d", qitem.assetdesc, tostring(qitem.assetdescval),_instock))
|
||||||
if qitem.nasset > _instock then
|
if qitem.nasset > _instock then
|
||||||
|
env.info("FF check queue nasset > instock okay=false")
|
||||||
okay=false
|
okay=false
|
||||||
end
|
end
|
||||||
-- Check if enough transport units are in stock.
|
-- Check if enough transport units are in stock.
|
||||||
_instock=#self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, qitem.transporttype)
|
_instock=#self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, qitem.transporttype)
|
||||||
if qitem.ntransport > _instock then
|
if qitem.ntransport > _instock then
|
||||||
|
env.info("FF check queue ntransport > instock okay=false")
|
||||||
okay=false
|
okay=false
|
||||||
end
|
end
|
||||||
return okay
|
return okay
|
||||||
@ -468,6 +474,13 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
-- New empty cargo set in case we need it.
|
||||||
|
local CargoGroups = SET_CARGO:New()
|
||||||
|
|
||||||
|
--TODO: make nearradius depended on transport type and asset type.
|
||||||
|
local _loadradius=5000
|
||||||
|
local _nearradius=35
|
||||||
|
|
||||||
-- Filter the requested assets.
|
-- Filter the requested assets.
|
||||||
local _assetstock=self:_FilterStock(self.stock, Request.assetdesc, Request.assetdescval)
|
local _assetstock=self:_FilterStock(self.stock, Request.assetdesc, Request.assetdescval)
|
||||||
|
|
||||||
@ -484,15 +497,18 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
-- Find a random point within the spawn zone.
|
-- Find a random point within the spawn zone.
|
||||||
local spawncoord=self.spawnzone:GetRandomCoordinate()
|
local spawncoord=self.spawnzone:GetRandomCoordinate()
|
||||||
|
|
||||||
spawncoord:MarkToAll(string.format("spawnpoint %d",i))
|
|
||||||
|
|
||||||
-- Alias of the group. Spawn with ALIAS here or DCS crashes!
|
-- Alias of the group. Spawn with ALIAS here or DCS crashes!
|
||||||
local _alias=string.format("%s_WHID%04d", _assetitem.templatename,_assetitem.id)
|
local _alias=string.format("%s_AssetID-%04d_RequestID-%04d", _assetitem.templatename,_assetitem.id,Request.uid)
|
||||||
local _spawn=SPAWN:NewWithAlias(_assetitem.templatename,_alias)
|
local _spawn=SPAWN:NewWithAlias(_assetitem.templatename,_alias)
|
||||||
local _group
|
local _group=nil --Wrapper.Group#GROUP
|
||||||
|
|
||||||
|
-- Set a marker for the spawned group.
|
||||||
|
spawncoord:MarkToAll(string.format("Spawnpoint %s",_alias))
|
||||||
|
|
||||||
if _assetitem.category==Group.Category.GROUND then
|
if _assetitem.category==Group.Category.GROUND then
|
||||||
-- Spawn ground troops.
|
-- Spawn ground troops.
|
||||||
_group=_spawn:SpawnFromCoordinate(spawncoord)
|
_group=_spawn:SpawnFromCoordinate(spawncoord)
|
||||||
|
env.info(string.format("FF spawning group %s", _alias))
|
||||||
elseif _assetitem.category==Group.Category.AIRPLANE or _assetitem.category==Group.Category.HELICOPTER then
|
elseif _assetitem.category==Group.Category.AIRPLANE or _assetitem.category==Group.Category.HELICOPTER then
|
||||||
-- Spawn air units.
|
-- Spawn air units.
|
||||||
local _takeoff=SPAWN.Takeoff.Cold
|
local _takeoff=SPAWN.Takeoff.Cold
|
||||||
@ -512,6 +528,12 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
_cargotype=_assetitem.attribute
|
_cargotype=_assetitem.attribute
|
||||||
_cargocategory=_assetitem.category
|
_cargocategory=_assetitem.category
|
||||||
table.insert(_delid,_assetitem.id)
|
table.insert(_delid,_assetitem.id)
|
||||||
|
|
||||||
|
if Request.transporttype ~= WAREHOUSE.TransportType.SELFPROPELLED then
|
||||||
|
local cargogroup = CARGO_GROUP:New(_group, _alias, _alias, _loadradius, _nearradius)
|
||||||
|
CargoGroups:AddCargo(cargogroup)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -551,22 +573,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------
|
env.info("FF cargo set name(s) = "..CargoGroups:GetObjectNames())
|
||||||
-- New empty cargo set.
|
|
||||||
local CargoGroups = SET_CARGO:New()
|
|
||||||
|
|
||||||
--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
|
|
||||||
local _name=string.format("%s %d", Request.assetdescval, _i)
|
|
||||||
env.info(string.format("FF cargo group %d: %s",_i,_name))
|
|
||||||
local cargogroup = CARGO_GROUP:New(_spawngroup, Request.assetdescval, _name, _loadradius, _nearradius)
|
|
||||||
CargoGroups:AddCargo(cargogroup)
|
|
||||||
end
|
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
local TransportSet = SET_GROUP:New() --:AddGroupsByName(Plane:GetName())
|
local TransportSet = SET_GROUP:New() --:AddGroupsByName(Plane:GetName())
|
||||||
@ -764,9 +771,8 @@ end
|
|||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #string templategroupname Name of the late activated template group as defined in the mission editor.
|
-- @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 #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
|
-- @return #WAREHOUSE self
|
||||||
function WAREHOUSE:AddAsset(templategroupname, ngroups, istransport)
|
function WAREHOUSE:AddAsset(templategroupname, ngroups)
|
||||||
|
|
||||||
-- Set default.
|
-- Set default.
|
||||||
local n=ngroups or 1
|
local n=ngroups or 1
|
||||||
@ -1069,10 +1075,11 @@ end
|
|||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #number _uid The unique id of the item to be deleted.
|
-- @param #number _uid The unique id of the item to be deleted.
|
||||||
function WAREHOUSE:_DeleteStockItem(_uid)
|
function WAREHOUSE:_DeleteStockItem(_uid)
|
||||||
for _i,_item in pairs(self.stock) do
|
for i=1,#self.stock do
|
||||||
local item=_item --#WAREHOUSE.Stockitem
|
local item=self.stock[i] --#WAREHOUSE.Stockitem
|
||||||
if item.id==_uid then
|
if item.id==_uid then
|
||||||
self.stock[_i]=nil
|
table.remove(self.stock,i)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1081,27 +1088,41 @@ end
|
|||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #number _uid The id of the item to be deleted.
|
-- @param #number _uid The id of the item to be deleted.
|
||||||
function WAREHOUSE:_DeleteQueueItem(_uid)
|
function WAREHOUSE:_DeleteQueueItem(_uid)
|
||||||
for _i,_item in pairs(self.queue) do
|
env.info("FF BEFORE delete queue")
|
||||||
local item=_item --#WAREHOUSE.Queueitem
|
self:_PrintQueue()
|
||||||
|
for i=1,#self.queue do
|
||||||
|
local item=self.queue[i] --#WAREHOUSE.Queueitem
|
||||||
if item.uid==_uid then
|
if item.uid==_uid then
|
||||||
self.queue[_i]=nil
|
table.remove(self.queue,i)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
env.info("FF AFTER delete queue")
|
||||||
|
self:_PrintQueue()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Sort requests queue wrt prio and request uid.
|
--- Sort requests queue wrt prio and request uid.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
function WAREHOUSE:_SortQueue()
|
function WAREHOUSE:_SortQueue()
|
||||||
self:F2()
|
self:F3()
|
||||||
|
-- Sort.
|
||||||
-- Sort results table wrt times they have already been engaged.
|
|
||||||
local function _sort(a, b)
|
local function _sort(a, b)
|
||||||
return (a.prio < b.prio) or (a.prio==b.prio and a.uid < b.uid)
|
return (a.prio < b.prio) or (a.prio==b.prio and a.uid < b.uid)
|
||||||
end
|
end
|
||||||
table.sort(self.queue, _sort)
|
table.sort(self.queue, _sort)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Prints the queue to DCS.log file.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
function WAREHOUSE:_PrintQueue()
|
||||||
|
env.info(self.wid.."Queue:")
|
||||||
|
for _,_qitem in ipairs(self.queue) do
|
||||||
|
local qitem=_qitem --#WAREHOUSE.Queueitem
|
||||||
|
local text=string.format("uid=%d, prio=%d, airbase=%s (category=%d), descriptor: %s=%s, nasssets=%d, transport=%s, ntransport=%d",
|
||||||
|
qitem.uid, qitem.prio, qitem.airbase:GetName(),qitem.category, qitem.assetdesc,tostring(qitem.assetdescval),qitem.nasset,qitem.transporttype,qitem.ntransport)
|
||||||
|
env.info(text)
|
||||||
|
end
|
||||||
|
end
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user