This commit is contained in:
Frank
2019-09-28 00:51:01 +02:00
parent 6eafba3032
commit fff30c21cd
3 changed files with 116 additions and 44 deletions
@@ -3793,9 +3793,9 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
-- Destroy group if it is alive.
if group:IsAlive()==true then
self:_DebugMessage(string.format("Destroying group %s.", group:GetName()), 5)
self:_DebugMessage(string.format("Removing group %s.", group:GetName()), 5)
-- Setting parameter to false, i.e. creating NO dead or remove unit event, seems to not confuse the dispatcher logic.
group:Destroy(false)
group:Destroy()
end
else
@@ -5021,7 +5021,7 @@ end
-- @param #WAREHOUSE.Pendingitem request The request of the dead asset.
function WAREHOUSE:onafterAssetSpawned(From, Event, To, group, asset, request)
local text=string.format("Asset %s from request id=%d was spawned!", asset.templatename, request.uid)
self:T(self.wid..text)
self:I(self.wid..text)
self:_DebugMessage(text)
-- Sete asset state to spawned.
@@ -6093,29 +6093,34 @@ function WAREHOUSE:_OnEventArrived(EventData)
if self.uid==wid then
local request=self:_GetRequestOfGroup(group, self.pending)
local istransport=self:_GroupIsTransport(group, request)
-- Get closest airbase.
-- Note, this crashed at somepoint when the Tarawa was in the mission. Don't know why. Deleting the Tarawa and adding it again solved the problem.
local closest=group:GetCoordinate():GetClosestAirbase()
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations.
local rightairbase=closest:GetName()==request.warehouse:GetAirbase():GetName()
-- Check that group is cargo and not transport.
if istransport==false and rightairbase then
-- Debug info.
local text=string.format("Air asset group %s from warehouse %s arrived at its destination.", group:GetName(), self.alias)
self:_InfoMessage(text)
-- Trigger arrived event for this group. Note that each unit of a group will trigger this event. So the onafterArrived function needs to take care of that.
-- Actually, we only take the first unit of the group that arrives. If it does, we assume the whole group arrived, which might not be the case, since
-- some units might still be taxiing or whatever. Therefore, we add 10 seconds for each additional unit of the group until the first arrived event is triggered.
local nunits=#group:GetUnits()
local dt=10*(nunits-1)+1 -- one unit = 1 sec, two units = 11 sec, three units = 21 sec before we call the group arrived.
self:__Arrived(dt, group)
-- Better check that the request still exists, because for a group with more units, the
if request then
local istransport=self:_GroupIsTransport(group, request)
-- Get closest airbase.
-- Note, this crashed at somepoint when the Tarawa was in the mission. Don't know why. Deleting the Tarawa and adding it again solved the problem.
local closest=group:GetCoordinate():GetClosestAirbase()
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations.
local rightairbase=closest:GetName()==request.warehouse:GetAirbase():GetName()
-- Check that group is cargo and not transport.
if istransport==false and rightairbase then
-- Debug info.
local text=string.format("Air asset group %s from warehouse %s arrived at its destination.", group:GetName(), self.alias)
self:_InfoMessage(text)
-- Trigger arrived event for this group. Note that each unit of a group will trigger this event. So the onafterArrived function needs to take care of that.
-- Actually, we only take the first unit of the group that arrives. If it does, we assume the whole group arrived, which might not be the case, since
-- some units might still be taxiing or whatever. Therefore, we add 10 seconds for each additional unit of the group until the first arrived event is triggered.
local nunits=#group:GetUnits()
local dt=10*(nunits-1)+1 -- one unit = 1 sec, two units = 11 sec, three units = 21 sec before we call the group arrived.
self:__Arrived(dt, group)
end
end
end