diff --git a/Moose/Cargo.lua b/Moose/Cargo.lua index 8cffe8311..53912c207 100644 --- a/Moose/Cargo.lua +++ b/Moose/Cargo.lua @@ -231,7 +231,8 @@ CARGO = { LOADED = 1, UNLOADED = 2, LOADING = 3 - } + }, + CargoCarrierGroupName = nil } --- Add Cargo to the mission... Cargo functionality needs to be reworked a bit, so this is still under construction. I need to make a CARGO Class... @@ -549,12 +550,14 @@ CARGO_PACKAGE = { } -function CARGO_PACKAGE:New( CargoType, CargoName, CargoWeight ) -trace.f( self.ClassName, { CargoType, CargoName, CargoWeight } ) +function CARGO_PACKAGE:New( CargoType, CargoName, CargoWeight, InitClientGroupName ) +trace.f( self.ClassName, { CargoType, CargoName, CargoWeight, InitClientGroupName } ) -- Arrange meta tables local self = BASE:Inherit( self, CARGO:New( CargoType, CargoName, CargoWeight ) ) + self.InitClientGroupName = InitClientGroupName .. '#' -- to fix + CARGOS[self.CargoName] = self return self @@ -564,6 +567,32 @@ end function CARGO_PACKAGE:Spawn() trace.f( self.ClassName ) + -- this needs to be checked thoroughly + + + local SpawnCargo = true + + if self.Client and self.Client:ClientGroup() then + trace.i( self.ClassName, 'There is a Client ' .. self.Client.ClientName ) + if self.Client:FindCargo( self.CargoName ) then + if self.Client:ClientUnit():getPlayerName() then -- this needs to be checked thoroughly + trace.i( self.ClassName, 'ok, Client is of player ' .. self.Client:ClientUnit():getPlayerName() .. ' and contains the Cargo, do nothing' ) + SpawnCargo = false + end + end + else + if self.InitClientGroupName then + local ClientGroup = Group.getByName( self.InitClientGroupName ) + if ClientGroup and ClientGroup:isExist() then + self.Client = CLIENT:New( self.InitClientGroupName, '' ) + end + end + end + + if SpawnCargo then + self.Client:AddCargo( self ) -- Adding cargo to the AI client + end + return self end @@ -571,10 +600,20 @@ function CARGO_PACKAGE:IsNear( Client, LandingZone ) trace.f( self.ClassName ) local Near = false - - local CargoHostGroup = LandingZone:GetCargoHostGroup() - if routines.IsPartOfGroupInRadius( CargoHostGroup, Client:ClientPosition(), 150 ) then - Near = true + + trace.i( self.ClassName, self.Client.ClientName ) + if self.Client and self.Client:ClientGroup():getName() then + trace.i( self.ClassName, 'Client Exists.' ) + trace.i( self.ClassName, 'self.Client:ClientGroup():getName() = ' .. self.Client:ClientGroup():getName() ) + + -- Find the cargo in the client + local Cargo = self.Client:FindCargo( self.CargoName ) + if Cargo == self then + trace.i( self.ClassName, 'Cargo is loaded in Client.' ) + if routines.IsPartOfGroupInRadius( self.Client:ClientGroup(), Client:ClientPosition(), 150 ) then + Near = true + end + end end return Near @@ -593,8 +632,8 @@ trace.f(self.ClassName ) local CarrierPosOnBoard = ClientUnit:getPoint() local CarrierPosMoveAway = ClientUnit:getPoint() - local CargoHostGroup = LandingZone:GetCargoHostGroup() - local CargoHostGroupName = LandingZone:GetCargoHostGroup():getName() + local CargoHostGroup = self.Client:ClientGroup() + local CargoHostGroupName = self.Client:ClientGroup():getName() local CargoHostUnits = CargoHostGroup:getUnits() local CargoPos = CargoHostUnits[1]:getPoint() @@ -677,10 +716,21 @@ trace.f(self.ClassName ) local OnBoarded = false - local CargoHostGroup = LandingZone:GetCargoHostGroup() - if routines.IsPartOfGroupInRadius( CargoHostGroup, Client:ClientPosition(), 25 ) then - --CargoGroup:destroy() - OnBoarded = true + if self.Client and self.Client:ClientGroup() then + if routines.IsPartOfGroupInRadius( self.Client:ClientGroup(), Client:ClientPosition(), 25 ) then + + -- Switch Cargo from self.Client to Client ... + Client:AddCargo( self ) + self.Client:RemoveCargo( self ) + trace.i( self.ClassName, 'Cargo switched from ' .. self.Client:ClientGroup():getName() .. ' to ' .. Client:ClientGroup():getName() ) + trace.i( self.ClassName, 'Cargo is ' .. self.CargoName ) -- Should not be null + + -- ok, so the Cargo has a new Client, thus, change the Owning Client of the Cargo. + self.Client = Client + + -- All done, onboarded the Cargo to the new Client. + OnBoarded = true + end end return OnBoarded diff --git a/Moose/Client.lua b/Moose/Client.lua index 0563a8685..eb6131080 100644 --- a/Moose/Client.lua +++ b/Moose/Client.lua @@ -45,7 +45,7 @@ CLIENT = { -- Mission:AddClient( CLIENT:New( 'RU MI-8MTV2*RAMP-Deploy Troops 4' ):Transport() ) function CLIENT:New( ClientName, ClientBriefing ) -trace.f(self.ClassName) +trace.f( self.ClassName, { ClientName, ClientBriefing } ) -- Arrange meta tables local self = BASE:Inherit( self, BASE:New() ) @@ -184,7 +184,7 @@ end -- @tparam string Cargo is the @{CARGO}. -- @treturn CLIENT function CLIENT:AddCargo( Cargo ) -trace.f(self.ClassName, { Cargo } ) +trace.f(self.ClassName, { Cargo.CargoName } ) local Valid = true @@ -201,7 +201,7 @@ end -- @tparam string CargoName is the name of the @{CARGO}. -- @treturn Cargo function CLIENT:RemoveCargo( Cargo ) -trace.f(self.ClassName ) +trace.f(self.ClassName, { Cargo.CargoName } ) local Valid = true diff --git a/Moose/Stage.lua b/Moose/Stage.lua index 7e3fe8e7a..9b6516a13 100644 --- a/Moose/Stage.lua +++ b/Moose/Stage.lua @@ -483,7 +483,7 @@ trace.f(self.ClassName) -- If the Cargo is ready to be loaded, load it into the Client. - trace.i(self.ClassName, Task.Cargo) + trace.i(self.ClassName, Task.Cargo.CargoName) if Task.Cargo:OnBoarded( Client, Task.CurrentCargoZone ) then