Warehouse v0.4.1

Improved JobDone function.
Fixed bugs.
This commit is contained in:
funkyfranky
2018-09-09 23:57:17 +02:00
parent 64ed3a119f
commit cc9b695b68
@@ -987,7 +987,7 @@ WAREHOUSE.db = {
--- Warehouse class version. --- Warehouse class version.
-- @field #string version -- @field #string version
WAREHOUSE.version="0.4.0" WAREHOUSE.version="0.4.1"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Warehouse todo list. -- TODO: Warehouse todo list.
@@ -2114,10 +2114,18 @@ function WAREHOUSE:_JobDone()
local request=request --#WAREHOUSE.Pendingitem local request=request --#WAREHOUSE.Pendingitem
-- Count number of cargo groups still alive and filter out dead groups. -- Count number of cargo groups still alive and filter out dead groups.
local ncargo=self:_FilterDead(request.cargogroupset) local ncargo=0
if request.cargogroupset then
ncargo=request.cargogroupset:Count()
end
--=self:_FilterDead(request.cargogroupset)
-- Count number of transport groups (if any) and filter out dead groups. Dead groups are removed from the set. -- Count number of transport groups (if any) and filter out dead groups. Dead groups are removed from the set.
local ntransport=self:_FilterDead(request.transportgroupset) local ntransport=0
if request.transportgroupset then
request.transportgroupset:Count()
end
--self:_FilterDead(request.transportgroupset)
if ncargo==0 and ntransport==0 then if ncargo==0 and ntransport==0 then
@@ -2293,7 +2301,7 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
-- Destroy group if it is alive. -- Destroy group if it is alive.
if group:IsAlive()==true then if group:IsAlive()==true then
self:_DebugMessage(string.format("Destroying group %s.", group:GetName()), 5) self:_DebugMessage(string.format("Destroying group %s.", group:GetName()), 5)
group:Destroy() group:Destroy(true)
end end
end end
@@ -3010,7 +3018,8 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
if Request.transporttype==WAREHOUSE.TransportType.AIRPLANE then if Request.transporttype==WAREHOUSE.TransportType.AIRPLANE then
_loadradius=10000 _loadradius=10000
elseif Request.transporttype==WAREHOUSE.TransportType.HELICOPTER then elseif Request.transporttype==WAREHOUSE.TransportType.HELICOPTER then
_loadradius=1000 --_loadradius=1000
_loadradius=nil
elseif Request.transporttype==WAREHOUSE.TransportType.APC then elseif Request.transporttype==WAREHOUSE.TransportType.APC then
_loadradius=1000 _loadradius=1000
end end
@@ -3232,9 +3241,8 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
local text=string.format("FF Group %s was unloaded from carrier %s.", tostring(group:GetName()), tostring(Carrier:GetName())) local text=string.format("FF Group %s was unloaded from carrier %s.", tostring(group:GetName()), tostring(Carrier:GetName()))
env.info(text) env.info(text)
-- Load the cargo in the warehouse. -- Load the cargo in the warehouse.
Cargo:Load(warehouse.warehouse) --Cargo:Load(warehouse.warehouse)
-- Trigger Arrived event. -- Trigger Arrived event.
warehouse:Arrived(group) warehouse:Arrived(group)
@@ -3501,7 +3509,7 @@ function WAREHOUSE:_UpdatePending(group)
if caid==aid then if caid==aid then
request.transportgroupset:Remove(transportgroup:GetName()) request.transportgroupset:Remove(transportgroup:GetName())
request.ntransporthome=request.ntransporthome+1 request.ntransporthome=request.ntransporthome+1
env.info("FF transport back home # "..request.ntransporthome) env.info(string.format("Transport back home #%s", request.ntransporthome))
isCargo=false isCargo=false
break break
end end
@@ -3520,7 +3528,7 @@ function WAREHOUSE:_UpdatePending(group)
if caid==aid then if caid==aid then
request.cargogroupset:Remove(cargogroup:GetName()) request.cargogroupset:Remove(cargogroup:GetName())
request.ndelivered=request.ndelivered+1 request.ndelivered=request.ndelivered+1
env.info("FF delivered cargo # "..request.ndelivered) env.info(string.format("FF delivered cargo # ", request.ndelivered))
isCargo=true isCargo=true
break break
end end
@@ -3856,12 +3864,9 @@ function WAREHOUSE:_RouteGround(group, request)
table.insert(Waypoints, #Waypoints+1, ToWP) table.insert(Waypoints, #Waypoints+1, ToWP)
end end
-- Task function triggering the arrived event.
--local TaskFunction = group:TaskFunction("WAREHOUSE._Arrived", self)
-- Task function triggering the arrived event at the last waypoint. -- Task function triggering the arrived event at the last waypoint.
local TaskFunction = self:_SimpleTaskFunction("warehouse:_ArrivedSimple", group) local TaskFunction = self:_SimpleTaskFunction("warehouse:_Arrived", group)
-- Put task function on last waypoint. -- Put task function on last waypoint.
local Waypoint = Waypoints[#Waypoints] local Waypoint = Waypoints[#Waypoints]
@@ -3893,7 +3898,7 @@ function WAREHOUSE:_RouteNaval(group, request)
-- Get off road path to remote warehouse. If more have been defined, pick one randomly. -- Get off road path to remote warehouse. If more have been defined, pick one randomly.
local remotename=request.warehouse.warehouse:GetName() local remotename=request.warehouse.warehouse:GetName()
local path=self.shippinglanes[remotename][math.random(#self.ship[remotename])] local lane=self.shippinglanes[remotename][math.random(#self.ship[remotename])]
if lane then if lane then
@@ -3914,7 +3919,7 @@ function WAREHOUSE:_RouteNaval(group, request)
end end
-- Task function triggering the arrived event at the last waypoint. -- Task function triggering the arrived event at the last waypoint.
local TaskFunction = self:_SimpleTaskFunction("warehouse:_ArrivedSimple", group) local TaskFunction = self:_SimpleTaskFunction("warehouse:_Arrived", group)
-- Put task function on last waypoint. -- Put task function on last waypoint.
local Waypoint = Waypoints[#Waypoints] local Waypoint = Waypoints[#Waypoints]
@@ -3976,8 +3981,8 @@ function WAREHOUSE:_RouteTrain(Group, Coordinate, Speed)
-- Create a -- Create a
local Waypoints = Group:TaskGroundOnRailRoads(Coordinate, Speed) local Waypoints = Group:TaskGroundOnRailRoads(Coordinate, Speed)
-- Task function triggering the arrived event. -- Task function triggering the arrived event at the last waypoint.
local TaskFunction = Group:TaskFunction("WAREHOUSE._Arrived", self) local TaskFunction = self:_SimpleTaskFunction("warehouse:_Arrived", Group)
-- Put task function on last waypoint. -- Put task function on last waypoint.
local Waypoint = Waypoints[#Waypoints] local Waypoint = Waypoints[#Waypoints]
@@ -3989,21 +3994,10 @@ function WAREHOUSE:_RouteTrain(Group, Coordinate, Speed)
end end
--- Task function for last waypoint. Triggering the "Arrived" event. --- Task function for last waypoint. Triggering the "Arrived" event.
-- @param Wrapper.Group#GROUP group The group that arrived.
-- @param #WAREHOUSE warehouse Warehouse self.
function WAREHOUSE._Arrived(group, warehouse)
env.info(warehouse.wid..string.format("Group %s arrived at destination.", tostring(group:GetName())))
--Trigger "Arrived" event.
warehouse:__Arrived(1, group)
end
--- Simple task function for last waypoint. Triggering the "Arrived" event.
-- @param #WAREHOUSE self -- @param #WAREHOUSE self
-- @param Wrapper.Group#GROUP group The group that arrived. -- @param Wrapper.Group#GROUP group The group that arrived.
function WAREHOUSE:_ArrivedSimple(group) function WAREHOUSE:_Arrived(group)
self:_DebugMessage(string.format("Group %s arrived (simple)!", tostring(group:GetName()))) self:_DebugMessage(string.format("Group %s arrived!", tostring(group:GetName())))
if group then if group then
--Trigger "Arrived event. --Trigger "Arrived event.
@@ -4143,7 +4137,6 @@ function WAREHOUSE:_OnEventLanding(EventData)
-- Group arrived. -- Group arrived.
self:Arrived(group) self:Arrived(group)
--self:__AddAsset(30, group)
end end
end end