mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Warehouse 0.1.7w
This commit is contained in:
parent
7a5aa3a4f9
commit
7599459779
@ -4,9 +4,9 @@
|
|||||||
-- Features:
|
-- Features:
|
||||||
--
|
--
|
||||||
-- * Holds (virtual) assests such as intrantry groups in stock.
|
-- * Holds (virtual) assests such as intrantry groups in stock.
|
||||||
-- * Manages requests of assets from other airbases or warehouses.
|
-- * Manages requests of assets from other warehouses.
|
||||||
-- * Take care of transportation to other airbases.
|
-- * Take care of transportation to other warehouses and its accociated airbases.
|
||||||
-- * Different means of automatic transportation (planes, helicopters, selfpropelled).
|
-- * Different means of automatic transportation (planes, helicopters, APCs, selfpropelled).
|
||||||
--
|
--
|
||||||
-- # QUICK START GUIDE
|
-- # QUICK START GUIDE
|
||||||
--
|
--
|
||||||
@ -32,6 +32,7 @@
|
|||||||
-- @field Core.Point#COORDINATE road Closest point to warehouse on road.
|
-- @field Core.Point#COORDINATE road Closest point to warehouse on road.
|
||||||
-- @field Core.Point#COORDINATE rail Closest point to warehouse on rail.
|
-- @field Core.Point#COORDINATE rail Closest point to warehouse on rail.
|
||||||
-- @field Core.Zone#ZONE spawnzone Zone in which assets are spawned.
|
-- @field Core.Zone#ZONE spawnzone Zone in which assets are spawned.
|
||||||
|
-- @field Functional.ZoneCaptureCoalition#ZONE_CAPTURE_COALITION capturezone Zone capture object handling the capturing of the warehouse spawn zone.
|
||||||
-- @field #string wid Identifier of the warehouse printed before other output to DCS.log file.
|
-- @field #string wid Identifier of the warehouse printed before other output to DCS.log file.
|
||||||
-- @field #number uid Unit identifier of the warehouse. Derived from the associated airbase.
|
-- @field #number uid Unit identifier of the warehouse. Derived from the associated airbase.
|
||||||
-- @field #number markerid ID of the warehouse marker at the airbase.
|
-- @field #number markerid ID of the warehouse marker at the airbase.
|
||||||
@ -96,6 +97,7 @@ WAREHOUSE = {
|
|||||||
road = nil,
|
road = nil,
|
||||||
rail = nil,
|
rail = nil,
|
||||||
spawnzone = nil,
|
spawnzone = nil,
|
||||||
|
capturezone = nil,
|
||||||
wid = nil,
|
wid = nil,
|
||||||
uid = nil,
|
uid = nil,
|
||||||
markerid = nil,
|
markerid = nil,
|
||||||
@ -459,6 +461,23 @@ function WAREHOUSE:onafterStart(From, Event, To)
|
|||||||
self.spawnzone:BoundZone(60, self.country)
|
self.spawnzone:BoundZone(60, self.country)
|
||||||
self.spawnzone:GetCoordinate():MarkToAll("Spawnzone of warehouse "..self.warehouse:GetName())
|
self.spawnzone:GetCoordinate():MarkToAll("Spawnzone of warehouse "..self.warehouse:GetName())
|
||||||
|
|
||||||
|
-- Create a zone capture object.
|
||||||
|
self.capturezone=ZONE_CAPTURE_COALITION:New(self.spawnzone, self.coalition)
|
||||||
|
|
||||||
|
-- Add warehouse to zone capture object. Does this work?
|
||||||
|
self.capturezone.warehouse=self
|
||||||
|
|
||||||
|
-- Start capturing monitoring.
|
||||||
|
self.capturezone:Start(10, 60)
|
||||||
|
|
||||||
|
-- Handle capturing.
|
||||||
|
function self.capturezone:OnEnterCaptured()
|
||||||
|
local coalition = self:GetCoalition()
|
||||||
|
self:E(string.format("Warehouse %s was captured by coalition %d", tostring(self.warehouse:GetName()), coalition))
|
||||||
|
self.warehouse.coalition=coalition --:SetCoalition(coalition)
|
||||||
|
self:Guard()
|
||||||
|
end
|
||||||
|
|
||||||
-- Handle events:
|
-- Handle events:
|
||||||
self:HandleEvent(EVENTS.Birth, self._OnEventBirth)
|
self:HandleEvent(EVENTS.Birth, self._OnEventBirth)
|
||||||
self:HandleEvent(EVENTS.EngineStartup, self._OnEventEngineStartup)
|
self:HandleEvent(EVENTS.EngineStartup, self._OnEventEngineStartup)
|
||||||
@ -469,6 +488,7 @@ function WAREHOUSE:onafterStart(From, Event, To)
|
|||||||
self:HandleEvent(EVENTS.Dead, self._OnEventCrashOrDead)
|
self:HandleEvent(EVENTS.Dead, self._OnEventCrashOrDead)
|
||||||
self:HandleEvent(EVENTS.BaseCaptured, self._OnEventBaseCaptured)
|
self:HandleEvent(EVENTS.BaseCaptured, self._OnEventBaseCaptured)
|
||||||
|
|
||||||
|
-- Start the status monitoring.
|
||||||
self:__Status(5)
|
self:__Status(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -550,6 +570,14 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
self:_PrintQueue(self.queue, "Queue:")
|
self:_PrintQueue(self.queue, "Queue:")
|
||||||
self:_PrintQueue(self.pending, "Pending:")
|
self:_PrintQueue(self.pending, "Pending:")
|
||||||
|
|
||||||
|
-- Check if requests are valid and remove invalid one.
|
||||||
|
self:_CheckRequestConsistancy(self.queue)
|
||||||
|
|
||||||
|
-- Print queue.
|
||||||
|
self:_PrintQueue(self.queue, "Queue after consitancy:")
|
||||||
|
self:_PrintQueue(self.pending, "Pending after consistancy:")
|
||||||
|
|
||||||
|
|
||||||
-- Check queue and handle requests if possible.
|
-- Check queue and handle requests if possible.
|
||||||
local request=self:_CheckQueue()
|
local request=self:_CheckQueue()
|
||||||
|
|
||||||
@ -559,8 +587,8 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Print queue.
|
-- Print queue.
|
||||||
self:_PrintQueue(self.queue, "Queue2:")
|
self:_PrintQueue(self.queue, "Queue after request:")
|
||||||
self:_PrintQueue(self.pending, "Pending2:")
|
self:_PrintQueue(self.pending, "Pending after request:")
|
||||||
|
|
||||||
-- Call status again in 30 sec.
|
-- Call status again in 30 sec.
|
||||||
self:__Status(30)
|
self:__Status(30)
|
||||||
@ -750,13 +778,17 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
local Pending=Request --#WAREHOUSE.Pendingitem
|
local Pending=Request --#WAREHOUSE.Pendingitem
|
||||||
|
|
||||||
-- Spawn assets.
|
-- Spawn assets.
|
||||||
local _spawngroups,_cargotype,_cargocategory,_cargoassets=self:_SpawnAssetRequest(Request) --Core.Set#SET_GROUP
|
local _spawngroups,_cargoassets=self:_SpawnAssetRequest(Request) --Core.Set#SET_GROUP
|
||||||
|
|
||||||
|
-- General type and category.
|
||||||
|
local _cargotype=_cargoassets[1].attribute --#WAREHOUSE.Attribute
|
||||||
|
local _cargocategory=_cargoassets[1].category --DCS#Group.Category
|
||||||
|
|
||||||
-- Add cargo groups to request.
|
-- Add cargo groups to request.
|
||||||
Pending.cargogroupset=_spawngroups
|
Pending.cargogroupset=_spawngroups
|
||||||
Pending.cargoassets=_cargoassets
|
Pending.cargoassets=_cargoassets
|
||||||
--Request.cargogroupset=_spawngroups
|
Pending.cargoattribute=_cargotype
|
||||||
--Request.ndelivered=0
|
Pending.cargocategory=_cargocategory
|
||||||
|
|
||||||
-- Add groups to cargo if they don't go by themselfs.
|
-- Add groups to cargo if they don't go by themselfs.
|
||||||
local CargoGroups --Core.Set#SET_CARGO
|
local CargoGroups --Core.Set#SET_CARGO
|
||||||
@ -832,10 +864,10 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Add request to pending queue.
|
-- Add request to pending queue.
|
||||||
table.insert(self.pending, Request)
|
table.insert(self.pending, Pending)
|
||||||
|
|
||||||
-- Delete request from queue.
|
-- Delete request from queue.
|
||||||
self:_DeleteQueueItem(Request.uid)
|
self:_DeleteQueueItem(Request, self.queue)
|
||||||
|
|
||||||
-- No cargo transport necessary.
|
-- No cargo transport necessary.
|
||||||
return
|
return
|
||||||
@ -869,11 +901,13 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
Parking=self:_GetParkingForAssets(_assetstock)
|
Parking=self:_GetParkingForAssets(_assetstock)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Transport assets table.
|
||||||
|
local _transportassets={}
|
||||||
|
|
||||||
-- Dependent on transport type, spawn the transports and set up the dispatchers.
|
-- Dependent on transport type, spawn the transports and set up the dispatchers.
|
||||||
if Request.transporttype==WAREHOUSE.TransportType.AIRPLANE then
|
if Request.transporttype==WAREHOUSE.TransportType.AIRPLANE then
|
||||||
|
|
||||||
-- Spawn the transport groups.
|
-- Spawn the transport groups.
|
||||||
local _delid={}
|
|
||||||
for i=1,Request.ntransport do
|
for i=1,Request.ntransport do
|
||||||
|
|
||||||
-- Get stock item.
|
-- Get stock item.
|
||||||
@ -897,13 +931,13 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
-- Add group to transportset.
|
-- Add group to transportset.
|
||||||
TransportSet:AddGroup(spawngroup)
|
TransportSet:AddGroup(spawngroup)
|
||||||
|
|
||||||
table.insert(_delid,_assetitem.uid)
|
table.insert(_transportassets,_assetitem)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delete spawned items from warehouse stock.
|
-- Delete spawned items from warehouse stock.
|
||||||
for _,_id in pairs(_delid) do
|
for _,_item in pairs(_transportassets) do
|
||||||
self:_DeleteStockItem(_id)
|
self:_DeleteStockItem(_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Define dispatcher for this task.
|
-- Define dispatcher for this task.
|
||||||
@ -912,7 +946,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
elseif Request.transporttype==WAREHOUSE.TransportType.HELICOPTER then
|
elseif Request.transporttype==WAREHOUSE.TransportType.HELICOPTER then
|
||||||
|
|
||||||
-- Spawn the transport groups.
|
-- Spawn the transport groups.
|
||||||
local _delid={}
|
|
||||||
for i=1,Request.ntransport do
|
for i=1,Request.ntransport do
|
||||||
|
|
||||||
-- Get stock item.
|
-- Get stock item.
|
||||||
@ -936,15 +969,15 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
-- Add group to transportset.
|
-- Add group to transportset.
|
||||||
TransportSet:AddGroup(spawngroup)
|
TransportSet:AddGroup(spawngroup)
|
||||||
|
|
||||||
table.insert(_delid,_assetitem.uid)
|
table.insert(_transportassets,_assetitem)
|
||||||
else
|
else
|
||||||
self:E(self.wid.."ERROR: spawngroup helo transport does not exist!")
|
self:E(self.wid.."ERROR: spawngroup helo transport does not exist!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delete spawned items from warehouse stock.
|
-- Delete spawned items from warehouse stock.
|
||||||
for _,_id in pairs(_delid) do
|
for _,_item in pairs(_transportassets) do
|
||||||
self:_DeleteStockItem(_id)
|
self:_DeleteStockItem(_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Define dispatcher for this task.
|
-- Define dispatcher for this task.
|
||||||
@ -957,7 +990,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
elseif Request.transporttype==WAREHOUSE.TransportType.APC then
|
elseif Request.transporttype==WAREHOUSE.TransportType.APC then
|
||||||
|
|
||||||
-- Spawn the transport groups.
|
-- Spawn the transport groups.
|
||||||
local _delid={}
|
|
||||||
for i=1,Request.ntransport do
|
for i=1,Request.ntransport do
|
||||||
|
|
||||||
-- Get stock item.
|
-- Get stock item.
|
||||||
@ -978,13 +1010,13 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
-- Add group to transportset.
|
-- Add group to transportset.
|
||||||
TransportSet:AddGroup(spawngroup)
|
TransportSet:AddGroup(spawngroup)
|
||||||
|
|
||||||
table.insert(_delid,_assetitem.uid)
|
table.insert(_transportassets,_assetitem)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delete spawned items from warehouse stock.
|
-- Delete spawned items from warehouse stock.
|
||||||
for _,_id in pairs(_delid) do
|
for _,_item in pairs(_transportassets) do
|
||||||
self:_DeleteStockItem(_id)
|
self:_DeleteStockItem(_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Define dispatcher for this task.
|
-- Define dispatcher for this task.
|
||||||
@ -1049,11 +1081,20 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
-- Start dispatcher.
|
-- Start dispatcher.
|
||||||
CargoTransport:__Start(5)
|
CargoTransport:__Start(5)
|
||||||
|
|
||||||
|
-- Add transportassets to pending queue item.
|
||||||
|
Pending.transportassets=_transportassets
|
||||||
|
|
||||||
|
-- Add cargo groups to request.
|
||||||
|
Pending.transportgroupset=_transportgroups
|
||||||
|
Pending.transportassets=_transportassets
|
||||||
|
Pending.transportattribute=_transporttype
|
||||||
|
Pending.transportcategory=_transportcategory
|
||||||
|
|
||||||
-- Add request to pending queue.
|
-- Add request to pending queue.
|
||||||
table.insert(self.pending, Request)
|
table.insert(self.pending, Pending)
|
||||||
|
|
||||||
-- Delete request from queue.
|
-- Delete request from queue.
|
||||||
self:_DeleteQueueItem(Request.uid)
|
self:_DeleteQueueItem(Request, self.queue)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1062,8 +1103,7 @@ end
|
|||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #WAREHOUSE.Queueitem Request Information table of the request.
|
-- @param #WAREHOUSE.Queueitem Request Information table of the request.
|
||||||
-- @return Core.Set#SET_GROUP Set of groups that were spawned.
|
-- @return Core.Set#SET_GROUP Set of groups that were spawned.
|
||||||
-- @return #WAREHOUSE.Attribute Generalized attribute of asset.
|
-- @return #table List of spawned assets.
|
||||||
-- @return DCS#Group.Category Category of asset, i.e. ground, air, ship, ...
|
|
||||||
function WAREHOUSE:_SpawnAssetRequest(Request)
|
function WAREHOUSE:_SpawnAssetRequest(Request)
|
||||||
|
|
||||||
-- Filter the requested cargo assets.
|
-- Filter the requested cargo assets.
|
||||||
@ -1093,10 +1133,9 @@ function WAREHOUSE:_SpawnAssetRequest(Request)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Create an empty set.
|
-- Create an empty set.
|
||||||
local groupset=SET_GROUP:New():FilterDeads()
|
local _groupset=SET_GROUP:New():FilterDeads()
|
||||||
|
|
||||||
-- Spawn the assets.
|
-- Spawn the assets.
|
||||||
local _delid={}
|
|
||||||
local _spawngroups={}
|
local _spawngroups={}
|
||||||
local _assets={}
|
local _assets={}
|
||||||
|
|
||||||
@ -1143,9 +1182,8 @@ function WAREHOUSE:_SpawnAssetRequest(Request)
|
|||||||
|
|
||||||
if _group then
|
if _group then
|
||||||
--_spawngroups[i]=_group
|
--_spawngroups[i]=_group
|
||||||
groupset:AddGroup(_group)
|
_groupset:AddGroup(_group)
|
||||||
table.insert(_assets, _assetitem)
|
table.insert(_assets, _assetitem)
|
||||||
table.insert(_delid,_assetitem.uid)
|
|
||||||
else
|
else
|
||||||
self:E(self.wid.."ERROR: cargo asset could not be spawned!")
|
self:E(self.wid.."ERROR: cargo asset could not be spawned!")
|
||||||
end
|
end
|
||||||
@ -1153,11 +1191,11 @@ function WAREHOUSE:_SpawnAssetRequest(Request)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Delete spawned items from warehouse stock.
|
-- Delete spawned items from warehouse stock.
|
||||||
for _,_id in pairs(_delid) do
|
for _,_item in pairs(_assets) do
|
||||||
self:_DeleteStockItem(_id)
|
self:_DeleteStockItem(_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
return groupset,_cargotype,_cargocategory,_assets
|
return _groupset,_assets
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -1455,7 +1493,7 @@ end
|
|||||||
|
|
||||||
--- Warehouse event handling function.
|
--- Warehouse event handling function.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param Core.Event#EVENTDATA Eventdata Event data.
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
function WAREHOUSE:_OnEventBirth(EventData)
|
function WAREHOUSE:_OnEventBirth(EventData)
|
||||||
self:E(self.wid..string.format("Warehouse %s captured event birth!",self.warehouse:GetName()))
|
self:E(self.wid..string.format("Warehouse %s captured event birth!",self.warehouse:GetName()))
|
||||||
|
|
||||||
@ -1469,42 +1507,55 @@ end
|
|||||||
|
|
||||||
--- Warehouse event handling function.
|
--- Warehouse event handling function.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param Core.Event#EVENTDATA Eventdata Event data.
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
function WAREHOUSE:_OnEventEngineStartup(EventData)
|
function WAREHOUSE:_OnEventEngineStartup(EventData)
|
||||||
self:E(self.wid..string.format("Warehouse %s captured event engine startup!",self.warehouse:GetName()))
|
self:E(self.wid..string.format("Warehouse %s captured event engine startup!",self.warehouse:GetName()))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Warehouse event handling function.
|
--- Warehouse event handling function.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param Core.Event#EVENTDATA Eventdata Event data.
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
function WAREHOUSE:_OnEventTakeOff(EventData)
|
function WAREHOUSE:_OnEventTakeOff(EventData)
|
||||||
self:E(self.wid..string.format("Warehouse %s captured event takeoff!",self.warehouse:GetName()))
|
self:E(self.wid..string.format("Warehouse %s captured event takeoff!",self.warehouse:GetName()))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Warehouse event handling function.
|
--- Warehouse event handling function.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param Core.Event#EVENTDATA Eventdata Event data.
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
function WAREHOUSE:_OnEventLanding(EventData)
|
function WAREHOUSE:_OnEventLanding(EventData)
|
||||||
self:E(self.wid..string.format("Warehouse %s captured event landing!",self.warehouse:GetName()))
|
self:E(self.wid..string.format("Warehouse %s captured event landing!",self.warehouse:GetName()))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Warehouse event handling function.
|
--- Warehouse event handling function.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param Core.Event#EVENTDATA Eventdata Event data.
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
function WAREHOUSE:_OnEventEngineShutdown(EventData)
|
function WAREHOUSE:_OnEventEngineShutdown(EventData)
|
||||||
self:E(self.wid..string.format("Warehouse %s captured event engine shutdown!",self.warehouse:GetName()))
|
self:E(self.wid..string.format("Warehouse %s captured event engine shutdown!",self.warehouse:GetName()))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Warehouse event handling function.
|
--- Warehouse event handling function.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param Core.Event#EVENTDATA Eventdata Event data.
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
function WAREHOUSE:_OnEventCrashOrDead(EventData)
|
function WAREHOUSE:_OnEventCrashOrDead(EventData)
|
||||||
self:E(self.wid..string.format("Warehouse %s captured event birth!",self.warehouse:GetName()))
|
self:E(self.wid..string.format("Warehouse %s captured event dead or crash!",self.warehouse:GetName()))
|
||||||
|
|
||||||
|
if EventData and EventData.IniUnit then
|
||||||
|
|
||||||
|
-- Check if warehouse was destroyed.
|
||||||
|
local warehousename=self.warehouse:GetName()
|
||||||
|
if EventData.IniUnitName==warehousename then
|
||||||
|
env.info(self.wid..string.format("Warehouse %s was destroyed!", warehousename))
|
||||||
|
--TODO: Add destroy event.
|
||||||
|
self:__Stop(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Warehouse event handling function.
|
--- Warehouse event handling function.
|
||||||
|
-- Handles the case when the airbase associated with the warehous is captured.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param Core.Event#EVENTDATA Eventdata Event data.
|
-- @param Core.Event#EVENTDATA EventData Event data.
|
||||||
function WAREHOUSE:_OnEventBaseCaptured(EventData)
|
function WAREHOUSE:_OnEventBaseCaptured(EventData)
|
||||||
self:E(self.wid..string.format("Warehouse %s captured event base captured!",self.warehouse:GetName()))
|
self:E(self.wid..string.format("Warehouse %s captured event base captured!",self.warehouse:GetName()))
|
||||||
|
|
||||||
@ -1516,6 +1567,7 @@ function WAREHOUSE:_OnEventBaseCaptured(EventData)
|
|||||||
if EventData and EventData.id==world.event.S_EVENT_BASE_CAPTURED then
|
if EventData and EventData.id==world.event.S_EVENT_BASE_CAPTURED then
|
||||||
if EventData.Place then
|
if EventData.Place then
|
||||||
|
|
||||||
|
-- Place is the airbase that was captured.
|
||||||
local airbase=EventData.Place --Wrapper.Airbase#AIRBASE
|
local airbase=EventData.Place --Wrapper.Airbase#AIRBASE
|
||||||
|
|
||||||
if EventData.PlaceName==self.airbasename then
|
if EventData.PlaceName==self.airbasename then
|
||||||
@ -1548,16 +1600,24 @@ end
|
|||||||
-- Helper functions
|
-- Helper functions
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--- Count number of troups in spawn zone of the warehouse.
|
||||||
|
-- If only enemy troops are captured.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
function WAREHOUSE:_CheckSpawnZone()
|
||||||
|
|
||||||
|
--self.spawnzone:IsAllInZoneOfCoalition(Coalition)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
--- Checks if the request can be fulfilled in general. If not, it is removed from the queue.
|
--- Checks if the request can be fulfilled in general. If not, it is removed from the queue.
|
||||||
-- Check if departure and destination bases are of the right type.
|
-- Check if departure and destination bases are of the right type.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #table queue The queue which is holding the requests to check.
|
-- @param #table queue The queue which is holding the requests to check.
|
||||||
-- @param #WAREHOUSE.Queueitem qitem The request to be checked.
|
|
||||||
-- @return #boolean If true, request can be executed. If false, something is not right.
|
-- @return #boolean If true, request can be executed. If false, something is not right.
|
||||||
function WAREHOUSE:_CheckRequestValid(queue)
|
function WAREHOUSE:_CheckRequestConsistancy(queue)
|
||||||
|
|
||||||
-- Requests to delete.
|
-- Requests to delete.
|
||||||
local delid={}
|
local invalid={}
|
||||||
|
|
||||||
for _,_request in pairs(queue) do
|
for _,_request in pairs(queue) do
|
||||||
local request=_request --#WAREHOUSE.Queueitem
|
local request=_request --#WAREHOUSE.Queueitem
|
||||||
@ -1740,15 +1800,15 @@ function WAREHOUSE:_CheckRequestValid(queue)
|
|||||||
|
|
||||||
-- Add request as unvalid and delete it later.
|
-- Add request as unvalid and delete it later.
|
||||||
if not valid then
|
if not valid then
|
||||||
table.insert(delid, request.id)
|
table.insert(invalid, request)
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- loop queue items.
|
end -- loop queue items.
|
||||||
|
|
||||||
|
|
||||||
-- Delete invalid requests.
|
-- Delete invalid requests.
|
||||||
for _,_uid in pairs(delid) do
|
for _,_request in pairs(invalid) do
|
||||||
self:_DeleteQueueItem(_uid)
|
self:_DeleteQueueItem(_request, self.queue)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -2235,13 +2295,13 @@ function WAREHOUSE:GetStockInfo(stock)
|
|||||||
return _data
|
return _data
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Delete item from stock.
|
--- Delete an asset item from stock.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #number _uid The unique id of the item to be deleted.
|
-- @param #WAREHOUSE.Stockitem stockitem Asset item to delete from stock table.
|
||||||
function WAREHOUSE:_DeleteStockItem(_uid)
|
function WAREHOUSE:_DeleteStockItem(stockitem)
|
||||||
for i=1,#self.stock do
|
for i=1,#self.stock do
|
||||||
local item=self.stock[i] --#WAREHOUSE.Stockitem
|
local item=self.stock[i] --#WAREHOUSE.Stockitem
|
||||||
if item.uid==_uid then
|
if item.uid==stockitem.uid then
|
||||||
table.remove(self.stock,i)
|
table.remove(self.stock,i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -2250,12 +2310,13 @@ end
|
|||||||
|
|
||||||
--- Delete item from queue.
|
--- Delete item from queue.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #number _uid The id of the item to be deleted.
|
-- @param #WAREHOUSE.Queueitem qitem Item of queue to be removed.
|
||||||
function WAREHOUSE:_DeleteQueueItem(_uid)
|
-- @param #table queue The queue from which the item should be deleted.
|
||||||
for i=1,#self.queue do
|
function WAREHOUSE:_DeleteQueueItem(qitem, queue)
|
||||||
local item=self.queue[i] --#WAREHOUSE.Queueitem
|
for i=1,#queue do
|
||||||
if item.uid==_uid then
|
local _item=queue[i] --#WAREHOUSE.Queueitem
|
||||||
table.remove(self.queue,i)
|
if _item.uid==qitem.uid then
|
||||||
|
table.remove(queue,i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2280,8 +2341,8 @@ function WAREHOUSE:_PrintQueue(queue, name)
|
|||||||
env.info(self.wid..name)
|
env.info(self.wid..name)
|
||||||
for _,_qitem in ipairs(queue) do
|
for _,_qitem in ipairs(queue) do
|
||||||
local qitem=_qitem --#WAREHOUSE.Queueitem
|
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",
|
local text=self.wid..string.format("UID=%d, Prio=%d, Warehouse=%s, 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)
|
qitem.uid, qitem.prio, qitem.warehouse:GetName(), qitem.airbase:GetName(),qitem.category, qitem.assetdesc,tostring(qitem.assetdescval),qitem.nasset,qitem.transporttype,qitem.ntransport)
|
||||||
env.info(text)
|
env.info(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user