mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Warehouse v0.2.4
This commit is contained in:
parent
31a5bfee9e
commit
64e67494b6
@ -41,7 +41,8 @@
|
|||||||
-- @field #number queueid Unit id of each request in the queue. Essentially a running number starting at one and incremented when a new request is added.
|
-- @field #number queueid Unit id of each request in the queue. Essentially a running number starting at one and incremented when a new request is added.
|
||||||
-- @field #table stock Table holding all assets in stock. Table entries are of type @{#WAREHOUSE.Assetitem}.
|
-- @field #table stock Table holding all assets in stock. Table entries are of type @{#WAREHOUSE.Assetitem}.
|
||||||
-- @field #table queue Table holding all queued requests. Table entries are of type @{#WAREHOUSE.Queueitem}.
|
-- @field #table queue Table holding all queued requests. Table entries are of type @{#WAREHOUSE.Queueitem}.
|
||||||
-- @field #table pending Table holding all pending requests, i.e. those that are currently in progress. Table entries are of type @{#WAREHOUSE.Pendingitem}.
|
-- @field #table pending Table holding all pending requests, i.e. those that are currently in progress. Table elements are of type @{#WAREHOUSE.Pendingitem}.
|
||||||
|
-- @field #table defending Table holding all defending requests, i.e. self requests that were if the warehouse is under attack. Table elements are of type @{#WAREHOUSE.Pendingitem}.
|
||||||
-- @extends Core.Fsm#FSM
|
-- @extends Core.Fsm#FSM
|
||||||
|
|
||||||
--- Manages ground assets of an airbase and offers the possibility to transport them to another airbase or warehouse.
|
--- Manages ground assets of an airbase and offers the possibility to transport them to another airbase or warehouse.
|
||||||
@ -109,6 +110,7 @@ WAREHOUSE = {
|
|||||||
stock = {},
|
stock = {},
|
||||||
queue = {},
|
queue = {},
|
||||||
pending = {},
|
pending = {},
|
||||||
|
defending = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Item of the warehouse stock table.
|
--- Item of the warehouse stock table.
|
||||||
@ -209,7 +211,7 @@ WAREHOUSE.db = {
|
|||||||
|
|
||||||
--- Warehouse class version.
|
--- Warehouse class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
WAREHOUSE.version="0.2.3w"
|
WAREHOUSE.version="0.2.4"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO: Warehouse todo list.
|
-- TODO: Warehouse todo list.
|
||||||
@ -729,8 +731,8 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Print queue after processing requests.
|
-- Print queue after processing requests.
|
||||||
self:_PrintQueue(self.queue, "Queue waiting - after request")
|
self:_PrintQueue(self.queue, "Queue waiting - after request")
|
||||||
self:_PrintQueue(self.pending, "Queue pending - after request")
|
self:_PrintQueue(self.pending, "Queue pending - after request")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1429,10 +1431,8 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
|||||||
|
|
||||||
-- Get stock item.
|
-- Get stock item.
|
||||||
local _assetitem=_assetstock[i] --#WAREHOUSE.Assetitem
|
local _assetitem=_assetstock[i] --#WAREHOUSE.Assetitem
|
||||||
local _parking=Parking[i]
|
|
||||||
|
|
||||||
-- Spawn with ALIAS here or DCS crashes!
|
-- Spawn with ALIAS here or DCS crashes!
|
||||||
--local _alias=string.format("%s_%d", _assetitem.templatename,_assetitem.id)
|
|
||||||
local _alias=self:_Alias(_assetitem, Request)
|
local _alias=self:_Alias(_assetitem, Request)
|
||||||
|
|
||||||
-- Spawn plane at airport in uncontrolled state.
|
-- Spawn plane at airport in uncontrolled state.
|
||||||
@ -1666,7 +1666,7 @@ function WAREHOUSE:_SpawnAssetRequest(Request)
|
|||||||
--TODO: spawn only so many groups as there are parking spots. Adjust request and create a new one with the reduced number!
|
--TODO: spawn only so many groups as there are parking spots. Adjust request and create a new one with the reduced number!
|
||||||
|
|
||||||
-- Spawn air units.
|
-- Spawn air units.
|
||||||
_group=self:_SpawnAssetAircraft(_assetitem, Request, Parking[i])
|
_group=self:_SpawnAssetAircraft(_assetitem, Request, Parking[_assetitem.uid])
|
||||||
|
|
||||||
elseif _assetitem.category==Group.Category.TRAIN then
|
elseif _assetitem.category==Group.Category.TRAIN then
|
||||||
|
|
||||||
@ -1872,7 +1872,8 @@ function WAREHOUSE:onafterSelfRequest(From, Event, To, groupset, request)
|
|||||||
|
|
||||||
-- Add a "defender request" to be able to despawn all assets once defeated.
|
-- Add a "defender request" to be able to despawn all assets once defeated.
|
||||||
if self:IsAttacked() then
|
if self:IsAttacked() then
|
||||||
self.defenderrequest=request
|
--self.defenderrequest=request
|
||||||
|
table.insert(self.defending, request)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove pending request.
|
-- Remove pending request.
|
||||||
@ -1901,10 +1902,11 @@ end
|
|||||||
function WAREHOUSE:onafterDefeated(From, Event, To)
|
function WAREHOUSE:onafterDefeated(From, Event, To)
|
||||||
self:E(self.wid..string.format("Attack was defeated!"))
|
self:E(self.wid..string.format("Attack was defeated!"))
|
||||||
|
|
||||||
if self.defenderrequest then
|
--if self.defenderrequest then
|
||||||
|
for _,request in pairs(self.defending) do
|
||||||
|
|
||||||
-- Get all assets that were deployed for defending the warehouse.
|
-- Get all assets that were deployed for defending the warehouse.
|
||||||
local request=self.defenderrequest --#WAREHOUSE.Pendingitem
|
--local request=self.defenderrequest --#WAREHOUSE.Pendingitem
|
||||||
|
|
||||||
-- Route defenders back to warehoue (for visual reasons only) and put them back into stock.
|
-- Route defenders back to warehoue (for visual reasons only) and put them back into stock.
|
||||||
for _,_group in pairs(request.cargogroupset:GetSetObjects()) do
|
for _,_group in pairs(request.cargogroupset:GetSetObjects()) do
|
||||||
@ -1921,9 +1923,13 @@ function WAREHOUSE:onafterDefeated(From, Event, To)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Set defender request back to nil.
|
-- Set defender request back to nil.
|
||||||
self.defenderrequest=nil
|
--self.defenderrequest=nil
|
||||||
|
|
||||||
|
--self:_DeleteQueueItem(request, self.defending)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.defending=nil
|
||||||
|
self.defending={}
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "Captured" event. Warehouse has been captured by another coalition.
|
--- On after "Captured" event. Warehouse has been captured by another coalition.
|
||||||
@ -2974,7 +2980,17 @@ function WAREHOUSE:_FindParkingForAssets(airbase, assets)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- TODO Clients? Unoccupied client aircraft are also important! Are they already included in scanned units maybe?
|
-- TODO Clients? Unoccupied client aircraft are also important! Are they already included in scanned units maybe?
|
||||||
|
--[[
|
||||||
|
local clients=_DATABASE.CLIENTS
|
||||||
|
for _,_client in pairs(clients) do
|
||||||
|
local client=_client --Wrapper.Client#CLIENT
|
||||||
|
local unit=client:GetClientGroupUnit()
|
||||||
|
local _coord=unit:GetCoordinate()
|
||||||
|
local _name=unit:GetName()
|
||||||
|
local _size=self:_GetObjectSize(client:GetClientGroupDCSUnit())
|
||||||
|
table.insert(obstacles[_termid],{coord=_coord, size=_size, name=_name, type="client"})
|
||||||
|
end
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Parking data for all assets.
|
-- Parking data for all assets.
|
||||||
@ -2994,25 +3010,31 @@ function WAREHOUSE:_FindParkingForAssets(airbase, assets)
|
|||||||
for i=1,_asset.nunits do
|
for i=1,_asset.nunits do
|
||||||
|
|
||||||
-- Loop over all parking spots.
|
-- Loop over all parking spots.
|
||||||
|
local gotit=false
|
||||||
for _,parkingspot in pairs(parkingdata) do
|
for _,parkingspot in pairs(parkingdata) do
|
||||||
|
|
||||||
-- Check correct terminal type for asset. We don't want helos in shelters etc.
|
-- Check correct terminal type for asset. We don't want helos in shelters etc.
|
||||||
if AIRBASE._CheckTerminalType(parkingspot.TerminalType,terminaltype) then
|
if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) then
|
||||||
|
|
||||||
-- Coordinate of the parking spot.
|
-- Coordinate of the parking spot.
|
||||||
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE
|
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE
|
||||||
local _termid=parkingspot.TerminalID
|
local _termid=parkingspot.TerminalID
|
||||||
|
local _toac=parkingspot.TOAC
|
||||||
|
|
||||||
-- Loop over all obstacles.
|
-- Loop over all obstacles.
|
||||||
local free=true
|
local free=true
|
||||||
|
local problem=nil
|
||||||
for _,obstacle in pairs(obstacles[_termid]) do
|
for _,obstacle in pairs(obstacles[_termid]) do
|
||||||
|
|
||||||
-- Check if aircraft overlaps with any obstacle.
|
-- Check if aircraft overlaps with any obstacle.
|
||||||
local safe=_overlap(_asset.size, obstacle.size, _spot:Get2DDistance(obstacle.coord))
|
local dist=_spot:Get2DDistance(obstacle.coord)
|
||||||
|
local safe=_overlap(_asset.size, obstacle.size, dist)
|
||||||
|
|
||||||
-- Spot is blocked.
|
-- Spot is blocked.
|
||||||
if not safe then
|
if not safe then
|
||||||
free=false
|
free=false
|
||||||
|
problem=obstacle
|
||||||
|
problem.dist=dist
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -3023,17 +3045,29 @@ function WAREHOUSE:_FindParkingForAssets(airbase, assets)
|
|||||||
-- Add parkingspot for this asset unit.
|
-- Add parkingspot for this asset unit.
|
||||||
table.insert(parking[_asset.uid], parkingspot)
|
table.insert(parking[_asset.uid], parkingspot)
|
||||||
|
|
||||||
|
self:E(self.wid..string.format("Parking spot #%d is free for asset id=%d!", _termid, _asset.uid))
|
||||||
|
|
||||||
-- Add the unit as obstacle so that this spot will not be available for the next unit.
|
-- Add the unit as obstacle so that this spot will not be available for the next unit.
|
||||||
-- TODO Alternatively, I could remove this parking spot from the table, right?
|
-- TODO Alternatively, I could remove this parking spot from the table, right?
|
||||||
obstacles[_termid]={coord=_spot, size=_asset.size, name=_asset.templatename, type="asset"}
|
table.insert(obstacles[_termid], {coord=_spot, size=_asset.size, name=_asset.templatename, type="asset"})
|
||||||
|
|
||||||
|
gotit=true
|
||||||
|
break
|
||||||
else
|
else
|
||||||
-- Not enough parking available!
|
self:E(self.wid..string.format("Parking spot #%d is occupied or not big enough!", _termid))
|
||||||
return nil
|
local coord=problem.coord --Core.Point#COORDINATE
|
||||||
|
local text=string.format("Obstacle blocking spot #%d is %s type %s with size=%.1f m and distance=%.1f m.", _termid, problem.name, problem.type, problem.size, problem.dist)
|
||||||
|
coord:MarkToAll(string.format(text))
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- check terminal type
|
end -- check terminal type
|
||||||
end -- loop over parking spots
|
end -- loop over parking spots
|
||||||
|
|
||||||
|
|
||||||
|
if not gotit then
|
||||||
|
self:E(self.wid..string.format("WARNING: No free parking spot for asset id=%d",_asset.uid))
|
||||||
|
return nil
|
||||||
|
end
|
||||||
end -- loop over asset units
|
end -- loop over asset units
|
||||||
end -- loop over asset groups
|
end -- loop over asset groups
|
||||||
|
|
||||||
@ -3127,7 +3161,6 @@ function WAREHOUSE:_GetIDsFromGroup(group)
|
|||||||
return _wid,_aid,_rid
|
return _wid,_aid,_rid
|
||||||
end
|
end
|
||||||
|
|
||||||
self:E({_function="getids", group=group})
|
|
||||||
if group then
|
if group then
|
||||||
|
|
||||||
-- Group name
|
-- Group name
|
||||||
@ -3137,10 +3170,10 @@ function WAREHOUSE:_GetIDsFromGroup(group)
|
|||||||
local wid,aid,rid=analyse(name)
|
local wid,aid,rid=analyse(name)
|
||||||
|
|
||||||
-- Debug info
|
-- Debug info
|
||||||
self:E(self.wid..string.format("Group Name = %s", tostring(name)))
|
self:T3(self.wid..string.format("Group Name = %s", tostring(name)))
|
||||||
self:E(self.wid..string.format("Warehouse ID = %s", tostring(wid)))
|
self:T3(self.wid..string.format("Warehouse ID = %s", tostring(wid)))
|
||||||
self:E(self.wid..string.format("Asset ID = %s", tostring(aid)))
|
self:T3(self.wid..string.format("Asset ID = %s", tostring(aid)))
|
||||||
self:E(self.wid..string.format("Request ID = %s", tostring(rid)))
|
self:T3(self.wid..string.format("Request ID = %s", tostring(rid)))
|
||||||
|
|
||||||
return wid,aid,rid
|
return wid,aid,rid
|
||||||
else
|
else
|
||||||
@ -3395,7 +3428,7 @@ function WAREHOUSE:_PrintQueue(queue, name)
|
|||||||
if qitem.airbase then
|
if qitem.airbase then
|
||||||
airbasename=qitem.airbase:GetName()
|
airbasename=qitem.airbase:GetName()
|
||||||
end
|
end
|
||||||
local text=text..string.format("\nUID=%d, Prio=%d, Requestor=%s, Airbase=%s (category=%d), Descriptor: %s=%s, Nasssets=%s, Transport=%s, Ntransport=%d.",
|
text=text..string.format("\nUID=%d, Prio=%d, Requestor=%s, Airbase=%s (category=%d), Descriptor: %s=%s, Nasssets=%s, Transport=%s, Ntransport=%d.",
|
||||||
qitem.uid, qitem.prio, qitem.warehouse.alias, airbasename, qitem.category, qitem.assetdesc,tostring(qitem.assetdescval), tostring(qitem.nasset), qitem.transporttype, qitem.ntransport)
|
qitem.uid, qitem.prio, qitem.warehouse.alias, airbasename, qitem.category, qitem.assetdesc,tostring(qitem.assetdescval), tostring(qitem.nasset), qitem.transporttype, qitem.ntransport)
|
||||||
end
|
end
|
||||||
if #queue==0 then
|
if #queue==0 then
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
--
|
--
|
||||||
-- ### Author: **FlightControl**
|
-- ### Author: **FlightControl**
|
||||||
--
|
--
|
||||||
-- ### Contributions:
|
-- ### Contributions: **funkyfranky**
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
@ -261,6 +261,16 @@ AIRBASE.PersianGulf = {
|
|||||||
["Kerman_Airport"] = "Kerman Airport",
|
["Kerman_Airport"] = "Kerman Airport",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- AIRBASE.ParkingSpot ".Coordinate, ".TerminalID", ".TerminalType", ".TOAC", ".Free", ".TerminalID0", ".DistToRwy".
|
||||||
|
-- @type AIRBASE.ParkingSpot
|
||||||
|
-- @field Core.Point#COORDINATE Coordinate Coordinate of the parking spot.
|
||||||
|
-- @field #number TerminalID Terminal ID of the spot. Generally, this is not the same number as displayed in the mission editor.
|
||||||
|
-- @field #AIRBASE.TerminalType TerminalType Type of the spot, i.e. for which type of aircraft it can be used.
|
||||||
|
-- @field #boolean TOAC Takeoff or landing aircarft. I.e. this stop is occupied currently by an aircraft until it took of or until it landed.
|
||||||
|
-- @field #boolean Free This spot is currently free, i.e. there is no alive aircraft on it at the present moment.
|
||||||
|
-- @field #number TerminalID0 Unknown what this means. If you know, please tell us!
|
||||||
|
-- @field #number DistToRwy Distance to runway in meters. Currently bugged and giving the same number as the TerminalID.
|
||||||
|
|
||||||
--- Terminal Types of parking spots. See also https://wiki.hoggitworld.com/view/DCS_func_getParking
|
--- Terminal Types of parking spots. See also https://wiki.hoggitworld.com/view/DCS_func_getParking
|
||||||
--
|
--
|
||||||
-- Supported types are:
|
-- Supported types are:
|
||||||
@ -273,7 +283,16 @@ AIRBASE.PersianGulf = {
|
|||||||
-- * AIRBASE.TerminalType.OpenMedOrBig = 176: Combines OpenMed and OpenBig spots.
|
-- * AIRBASE.TerminalType.OpenMedOrBig = 176: Combines OpenMed and OpenBig spots.
|
||||||
-- * AIRBASE.TerminalType.HelicopterUnsable = 216: Combines HelicopterOnly, OpenMed and OpenBig.
|
-- * AIRBASE.TerminalType.HelicopterUnsable = 216: Combines HelicopterOnly, OpenMed and OpenBig.
|
||||||
-- * AIRBASE.TerminalType.FighterAircraft = 244: Combines Shelter. OpenMed and OpenBig spots. So effectively all spots usable by fixed wing aircraft.
|
-- * AIRBASE.TerminalType.FighterAircraft = 244: Combines Shelter. OpenMed and OpenBig spots. So effectively all spots usable by fixed wing aircraft.
|
||||||
-- @field TerminalType
|
--
|
||||||
|
-- @type AIRBASE.TerminalType
|
||||||
|
-- @field #number Runway 16: Valid spawn points on runway.
|
||||||
|
-- @field #number HelicopterOnly 40: Special spots for Helicopers.
|
||||||
|
-- @field #number Shelter 68: Hardened Air Shelter. Currently only on Caucaus map.
|
||||||
|
-- @field #number OpenMed 72: Open/Shelter air airplane only.
|
||||||
|
-- @field #number OpenBig 104: Open air spawn points. Generally larger but does not guarantee large aircraft are capable of spawning there.
|
||||||
|
-- @field #number OpenMedOrBig 176: Combines OpenMed and OpenBig spots.
|
||||||
|
-- @field #number HelicopterUnsable 216: Combines HelicopterOnly, OpenMed and OpenBig.
|
||||||
|
-- @field #number FighterAircraft 244: Combines Shelter. OpenMed and OpenBig spots. So effectively all spots usable by fixed wing aircraft.
|
||||||
AIRBASE.TerminalType = {
|
AIRBASE.TerminalType = {
|
||||||
Runway=16,
|
Runway=16,
|
||||||
HelicopterOnly=40,
|
HelicopterOnly=40,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user