From c7d3e44a57d327269cb960a05683ff0c3a593e64 Mon Sep 17 00:00:00 2001 From: svenvandevelde Date: Fri, 26 Feb 2016 10:15:03 +0100 Subject: [PATCH] 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. --- Moose/Cargo.lua | 36 +++++++++++++++++++++++++++++++++--- Moose/PickupTask.lua | 12 ++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Moose/Cargo.lua b/Moose/Cargo.lua index d113e70b1..7a3fb6a6d 100644 --- a/Moose/Cargo.lua +++ b/Moose/Cargo.lua @@ -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 diff --git a/Moose/PickupTask.lua b/Moose/PickupTask.lua index 92100df64..d9423d73d 100644 --- a/Moose/PickupTask.lua +++ b/Moose/PickupTask.lua @@ -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