From b8148a7950b3c74f5579a1512e8fe660bffcddef Mon Sep 17 00:00:00 2001 From: svenvandevelde Date: Fri, 19 Feb 2016 19:00:40 +0100 Subject: [PATCH] Converted SPAWN:FromCarrier function SPAWN:FromCarrier now spawns from a Unit instead of a Group. It was confusing from the beginning anyway :-) --- Moose/Cargo.lua | 14 +++---- Moose/Spawn.lua | 103 +++++++++++++++++++++--------------------------- 2 files changed, 53 insertions(+), 64 deletions(-) diff --git a/Moose/Cargo.lua b/Moose/Cargo.lua index 681830b77..32656f4e3 100644 --- a/Moose/Cargo.lua +++ b/Moose/Cargo.lua @@ -249,12 +249,12 @@ trace.f( self.ClassName ) end -function CARGO_ZONE:GetCargoHostGroup() +function CARGO_ZONE:GetCargoHostUnit() trace.f( self.ClassName ) - local CargoHostGroup = Group.getByName( self.CargoHostSpawn:SpawnGroupName() ) - if CargoHostGroup and CargoHostGroup:isExist() then - return CargoHostGroup + local CargoHostUnit = Group.getByName( self.CargoHostSpawn:SpawnGroupName() ):getUnit(1) + if CargoHostUnit and CargoHostUnit:isExist() then + return CargoHostUnit end return nil @@ -462,9 +462,9 @@ trace.f( self.ClassName ) end if SpawnCargo then - if self.CargoZone:GetCargoHostGroup() then + if self.CargoZone:GetCargoHostUnit() then --- ReSpawn the Cargo from the CargoHost - self.CargoGroupName = self.CargoSpawn:FromCarrier( self.CargoZone:GetCargoHostGroup(), self.CargoZone:GetCargoZoneName(), self.CargoName, false ).name + self.CargoGroupName = self.CargoSpawn:FromCarrier( self.CargoZone:GetCargoHostUnit(), self.CargoZone:GetCargoZoneName(), self.CargoName, false ).name else --- ReSpawn the Cargo in the CargoZone without a host ... self.CargoGroupName = self.CargoSpawn:InZone( self.CargoZone:GetCargoZoneName(), self.CargoName ).name @@ -589,7 +589,7 @@ trace.f( self.ClassName ) trace.i( self.ClassName, 'self.CargoName = ' .. self.CargoName ) trace.i( self.ClassName, 'self.CargoGroupName = ' .. self.CargoGroupName ) - self.CargoSpawn:FromCarrier( Client:ClientGroup(), TargetZoneName, self.CargoGroupName ) + self.CargoSpawn:FromCarrier( Client:GetClientGroupUnit(), TargetZoneName, self.CargoGroupName ) self:StatusUnLoaded() local Cargo = Client:RemoveCargo( self ) diff --git a/Moose/Spawn.lua b/Moose/Spawn.lua index 48df6e921..14d5cb43b 100644 --- a/Moose/Spawn.lua +++ b/Moose/Spawn.lua @@ -298,76 +298,65 @@ end --- Will SPAWN a Group from a Carrier. This function is mostly advisable to be used if you want to simulate SPAWNing from air units, like helicopters, which are dropping infantry into a defined Landing Zone. --- @tparam Group CarrierGroup is the Group of the AIR unit or GROUND unit dropping or unloading other units. +-- @tparam Group CarrierUnit is the AIR unit or GROUND unit dropping or unloading the Spawn group. -- @tparam string TargetZonePrefix is the Prefix of the Zone defined in the ME where the Group should be moving to after drop. -- @tparam string NewGroupName (forgot this). -- @tparam bool LateActivate (optional) does the SPAWNing with Lateactivation on. -function SPAWN:FromCarrier( CarrierGroup, TargetZonePrefix, NewGroupName, LateActivate ) -trace.f( self.ClassName, { CarrierGroup, TargetZonePrefix, NewGroupName, LateActivate } ) +function SPAWN:FromCarrier( CarrierUnit, TargetZonePrefix, NewGroupName, LateActivate ) +trace.f( self.ClassName, { CarrierUnit, TargetZonePrefix, NewGroupName, LateActivate } ) local SpawnTemplate - if CarrierGroup and CarrierGroup:isExist() and CarrierGroup:getUnit(1) then -- and CarrierGroup:getUnit(1):inAir() == false then + if CarrierUnit and CarrierUnit:isExist() then -- and CarrierUnit:getUnit(1):inAir() == false then - local GroupUnits = CarrierGroup:getUnits() - local GroupUnitCount = table.getn(GroupUnits) - trace.i( self.ClassName, "CarrierGroup:getSize() = " .. CarrierGroup:getSize() ) - trace.i( self.ClassName, 'GroupUnitCount = ' .. GroupUnitCount ) - - for UnitId, UnitData in pairs(GroupUnits) do + SpawnTemplate = self:_Prepare( NewGroupName ) - UnitDeploy = UnitData - - SpawnTemplate = self:_Prepare( NewGroupName ) - - if ( self.SpawnMaxGroups == 0 ) or ( self.SpawnCount <= self.SpawnMaxGroups ) then - if ( self.SpawnMaxGroupsAlive == 0 ) or ( self.AliveUnits < self.SpawnMaxGroupsAlive * #self.SpawnTemplate.units ) or self.UnControlled then + if ( self.SpawnMaxGroups == 0 ) or ( self.SpawnCount <= self.SpawnMaxGroups ) then + if ( self.SpawnMaxGroupsAlive == 0 ) or ( self.AliveUnits < self.SpawnMaxGroupsAlive * #self.SpawnTemplate.units ) or self.UnControlled then - if LateActivate ~= nil then - if LateActivate == true then - SpawnTemplate.lateActivation = true - SpawnTemplate.visible = true - end + if LateActivate ~= nil then + if LateActivate == true then + SpawnTemplate.lateActivation = true + SpawnTemplate.visible = true end - - SpawnTemplate = self:_RandomizeRoute( SpawnTemplate ) - - local TargetZone = trigger.misc.getZone( TargetZonePrefix ) - local TargetZonePos = {} - TargetZonePos.x = TargetZone.point.x + math.random(TargetZone.radius / 2 * -1, TargetZone.radius / 2 ) - TargetZonePos.z = TargetZone.point.z + math.random(TargetZone.radius / 2 * -1, TargetZone.radius / 2 ) - - local RouteCount = table.getn( SpawnTemplate.route.points ) - trace.i( self.ClassName, "RouteCount = " .. RouteCount ) - - local UnitDeployPosition = UnitDeploy:getPoint() - SpawnTemplate.route.points[1].x = UnitDeployPosition.x - 50 - SpawnTemplate.route.points[1].y = UnitDeployPosition.z - SpawnTemplate.route.points[1].alt = nil - SpawnTemplate.route.points[1].alt_type = nil - - if SpawnStartPoint ~= 0 and SpawnEndPoint ~= 0 then - SpawnTemplate.route.points[RouteCount].x = TargetZonePos.x - SpawnTemplate.route.points[RouteCount].y = TargetZonePos.z - else - SpawnTemplate.route.points[RouteCount].x = TargetZone.point.x - SpawnTemplate.route.points[RouteCount].y = TargetZone.point.z - end - - trace.i( self.ClassName, 'SpawnTemplate.route.points['..RouteCount..'].x = ' .. SpawnTemplate.route.points[RouteCount].x .. ', SpawnTemplate.route.points['..RouteCount..'].y = ' .. SpawnTemplate.route.points[RouteCount].y ) - - for v = 1, table.getn( SpawnTemplate.units ) do - local SpawnPos = routines.getRandPointInCircle( UnitDeployPosition, 40, 10 ) - SpawnTemplate.units[v].x = SpawnPos.x - SpawnTemplate.units[v].y = SpawnPos.y - trace.i( self.ClassName, 'SpawnTemplate.units['..v..'].x = ' .. SpawnTemplate.units[v].x .. ', SpawnTemplate.units['..v..'].y = ' .. SpawnTemplate.units[v].y ) - end - - _Database:Spawn( SpawnTemplate ) end + + SpawnTemplate = self:_RandomizeRoute( SpawnTemplate ) + + local TargetZone = trigger.misc.getZone( TargetZonePrefix ) + local TargetZonePos = {} + TargetZonePos.x = TargetZone.point.x + math.random(TargetZone.radius / 2 * -1, TargetZone.radius / 2 ) + TargetZonePos.z = TargetZone.point.z + math.random(TargetZone.radius / 2 * -1, TargetZone.radius / 2 ) + + local RouteCount = table.getn( SpawnTemplate.route.points ) + trace.i( self.ClassName, "RouteCount = " .. RouteCount ) + + local UnitDeployPosition = CarrierUnit:getPoint() + SpawnTemplate.route.points[1].x = UnitDeployPosition.x - 50 + SpawnTemplate.route.points[1].y = UnitDeployPosition.z + SpawnTemplate.route.points[1].alt = nil + SpawnTemplate.route.points[1].alt_type = nil + + if SpawnStartPoint ~= 0 and SpawnEndPoint ~= 0 then + SpawnTemplate.route.points[RouteCount].x = TargetZonePos.x + SpawnTemplate.route.points[RouteCount].y = TargetZonePos.z + else + SpawnTemplate.route.points[RouteCount].x = TargetZone.point.x + SpawnTemplate.route.points[RouteCount].y = TargetZone.point.z + end + + trace.i( self.ClassName, 'SpawnTemplate.route.points['..RouteCount..'].x = ' .. SpawnTemplate.route.points[RouteCount].x .. ', SpawnTemplate.route.points['..RouteCount..'].y = ' .. SpawnTemplate.route.points[RouteCount].y ) + + for v = 1, table.getn( SpawnTemplate.units ) do + local SpawnPos = routines.getRandPointInCircle( UnitDeployPosition, 40, 10 ) + SpawnTemplate.units[v].x = SpawnPos.x + SpawnTemplate.units[v].y = SpawnPos.y + trace.i( self.ClassName, 'SpawnTemplate.units['..v..'].x = ' .. SpawnTemplate.units[v].x .. ', SpawnTemplate.units['..v..'].y = ' .. SpawnTemplate.units[v].y ) + end + + _Database:Spawn( SpawnTemplate ) end end - end trace.r( self.ClassName, "" )