Optimization of Cargo Loading behaviour

Cargo loading is a bit complex.
- Cargo should only respawn if it is not existing, and if it is not
loading to another client.
- The pickup menu should allow Cargo that was loading (but for some
reason it did not load), to retry the loading process, but only when the
Client is the Client of the active player.
- When the menus are removed, any unit that was loading but not loaded,
should become back to status none, but only when the Client is the
Client of the active player.
- Fixed a couple of errors with the Pickup-menu function.
This commit is contained in:
svenvandevelde 2016-02-26 10:15:03 +01:00
parent 6955d45840
commit c7d3e44a57
2 changed files with 43 additions and 5 deletions

View File

@ -308,10 +308,23 @@ self:T()
end
function CARGO:IsLoadingToClient()
self:T()
if self:IsStatusLoading() then
return self.CargoClient
end
return nil
end
function CARGO:IsLoadedInClient()
self:T()
if self:IsStatusLoaded() or self:IsStatusLoading() then
if self:IsStatusLoaded() then
return self.CargoClient
end
@ -380,7 +393,7 @@ self:T()
self.CargoClient = Client
self.CargoStatus = CARGO.STATUS.LOADING
self:T( "Cargo loaded in Client: " .. CargoClient:GetClientGroupName() )
self:T( "Cargo " .. self.CargoName .. " loading to Client: " .. CargoClient:GetClientGroupName() )
return self
end
@ -390,6 +403,7 @@ self:T()
self.CargoClient = Client
self.CargoStatus = CARGO.STATUS.LOADED
self:T( "Cargo " .. self.CargoName .. " loaded in Client: " .. CargoClient:GetClientGroupName() )
return self
end
@ -452,8 +466,24 @@ self:T()
local SpawnCargo = true
if self:IsStatusNone() then
local CargoGroup = Group.getByName( self.CargoSpawn:SpawnGroupName() )
if CargoGroup then
SpawnCargo = false
end
elseif self:IsStatusLoading() then
elseif self:IsStatusLoaded() or self:IsStatusLoading() then
local Client = self:IsLoadingToClient()
if Client and Client:ClientGroup() then
SpawnCargo = false
else
local CargoGroup = Group.getByName( self.CargoSpawn:SpawnGroupName() )
if CargoGroup then
SpawnCargo = false
end
end
elseif self:IsStatusLoaded() then
local Client = self:IsLoadedInClient()
if Client and Client:ClientGroup() then

View File

@ -78,7 +78,8 @@ self:T()
self:T( { Cargo.ClassName, Cargo.CargoName, Cargo.CargoType, Cargo:IsStatusNone(), Cargo:IsStatusLoaded(), Cargo:IsStatusLoading(), Cargo:IsStatusUnLoaded() } )
if Cargo:IsStatusNone() or ( Cargo:IsStatusLoaded() and Client ~= Cargo:IsLoadedInClient() ) then
-- If the Cargo has no status, allow the menu option.
if Cargo:IsStatusNone() or ( Cargo:IsStatusLoading() and Client == Cargo:IsLoadingToClient() ) then
local MenuAdd = false
if Cargo:IsNear( Client, self.CurrentCargoZone ) then
@ -132,7 +133,14 @@ self:T()
MenuData.PickupMenu = nil
end
end
for CargoID, Cargo in pairs( Cargos ) do
self:T( { Cargo.ClassName, Cargo.CargoName, Cargo.CargoType, Cargo:IsStatusNone(), Cargo:IsStatusLoaded(), Cargo:IsStatusLoading(), Cargo:IsStatusUnLoaded() } )
if Cargo:IsStatusLoading() and Client == Cargo:IsLoadingToClient() then
Cargo:StatusNone()
end
end
end