From 8ef6ef14ddc16dceb8521dd776e4c4282a522d60 Mon Sep 17 00:00:00 2001 From: Sven Van de Velde Date: Sun, 8 May 2016 16:16:41 +0200 Subject: [PATCH] Updates --- Moose/Cargo.lua | 59 ++++++++++++++++++++++++++++++++-------------- Moose/Routines.lua | 41 ++++++++++++++++++++++++++++++++ Moose/Scoring.lua | 4 ++-- Moose/Spawn.lua | 5 ++-- Moose/Stage.lua | 18 +++++++++----- Moose/Zone.lua | 11 +++++++++ 6 files changed, 110 insertions(+), 28 deletions(-) diff --git a/Moose/Cargo.lua b/Moose/Cargo.lua index c9e09135d..f5bf3fb88 100644 --- a/Moose/Cargo.lua +++ b/Moose/Cargo.lua @@ -31,18 +31,31 @@ CARGO_ZONE = { } } -function CARGO_ZONE:New( CargoZoneName, CargoHostName ) local self = BASE:Inherit( self, BASE:New() ) +--- Creates a new zone where cargo can be collected or deployed. +-- The zone functionality is useful to smoke or indicate routes for cargo pickups or deployments. +-- Provide the zone name as declared in the mission file into the CargoZoneName in the :New method. +-- An optional parameter is the CargoHostName, which is a Group declared with Late Activation switched on in the mission file. +-- The CargoHostName is the "host" of the cargo zone: +-- +-- * It will smoke the zone position when a client is approaching the zone. +-- * Depending on the cargo type, it will assist in the delivery of the cargo by driving to and from the client. +-- +-- @param #CARGO_ZONE self +-- @param #string CargoZoneName The name of the zone as declared within the mission editor. +-- @param #string CargoHostName The name of the Group "hosting" the zone. The Group MUST NOT be a static, and must be a "mobile" unit. +function CARGO_ZONE:New( CargoZoneName, CargoHostName ) local self = BASE:Inherit( self, ZONE:New( CargoZoneName ) ) self:F( { CargoZoneName, CargoHostName } ) self.CargoZoneName = CargoZoneName - self.CargoZone = trigger.misc.getZone( CargoZoneName ) + self.SignalHeight = 2 + --self.CargoZone = trigger.misc.getZone( CargoZoneName ) if CargoHostName then self.CargoHostName = CargoHostName end - self:T( self.CargoZone ) + self:T( self.CargoZoneName ) return self end @@ -50,17 +63,19 @@ end function CARGO_ZONE:Spawn() self:F( self.CargoHostName ) - if self.CargoHostSpawn then - local CargoHostGroup = self.CargoHostSpawn:GetGroupFromIndex() - if CargoHostGroup and CargoHostGroup:IsAlive() then - else - self.CargoHostSpawn:ReSpawn( 1 ) - end - else - self:T( "Initialize CargoHostSpawn" ) - self.CargoHostSpawn = SPAWN:New( self.CargoHostName ):Limit( 1, 1 ) - self.CargoHostSpawn:ReSpawn( 1 ) - end + if self.CargoHostName then -- Only spawn a host in the zone when there is one given as a parameter in the New function. + if self.CargoHostSpawn then + local CargoHostGroup = self.CargoHostSpawn:GetGroupFromIndex() + if CargoHostGroup and CargoHostGroup:IsAlive() then + else + self.CargoHostSpawn:ReSpawn( 1 ) + end + else + self:T( "Initialize CargoHostSpawn" ) + self.CargoHostSpawn = SPAWN:New( self.CargoHostName ):Limit( 1, 1 ) + self.CargoHostSpawn:ReSpawn( 1 ) + end + end return self end @@ -114,6 +129,14 @@ function CARGO_ZONE:ReportCargosToClient( Client, CargoType ) end end + +function CARGO_ZONE:SignalHeight( SignalHeight ) + + self.SignalHeight = SignalHeight + + return self +end + function CARGO_ZONE:Signal() self:F() @@ -148,16 +171,15 @@ function CARGO_ZONE:Signal() else - local CurrentPosition = { x = self.CargoZone.point.x, y = self.CargoZone.point.z } - self.CargoZone.point.y = land.getHeight( CurrentPosition ) + 2 + local ZonePointVec3 = self:GetPointVec3( self.SignalHeight ) -- Get the zone position + the landheight + 2 meters if self.SignalType.ID == CARGO_ZONE.SIGNAL.TYPE.SMOKE.ID then - trigger.action.smoke( self.CargoZone.point, self.SignalColor.TRIGGERCOLOR ) + trigger.action.smoke( ZonePointVec3, self.SignalColor.TRIGGERCOLOR ) Signalled = true elseif self.SignalType.ID == CARGO_ZONE.SIGNAL.TYPE.FLARE.ID then - trigger.action.signalFlare( self.CargoZone.point, self.SignalColor.TRIGGERCOLOR, 0 ) + trigger.action.signalFlare( ZonePointVec3, self.SignalColor.TRIGGERCOLOR, 0 ) Signalled = false end @@ -517,6 +539,7 @@ function CARGO_GROUP:Spawn( Client ) self.CargoGroupName = self.CargoSpawn:SpawnFromUnit( self.CargoZone:GetCargoHostUnit(), 60, 30, 1 ):GetName() else --- ReSpawn the Cargo in the CargoZone without a host ... + self:T( self.CargoZone ) self.CargoGroupName = self.CargoSpawn:SpawnInZone( self.CargoZone, true, 1 ):GetName() end self:StatusNone() diff --git a/Moose/Routines.lua b/Moose/Routines.lua index 4f12b2222..059f60544 100644 --- a/Moose/Routines.lua +++ b/Moose/Routines.lua @@ -1524,6 +1524,47 @@ function routines.IsUnitInZones( TransportUnit, LandingZones ) end end +function routines.IsUnitNearZonesRadius( TransportUnit, LandingZones, ZoneRadius ) +--trace.f("", "routines.IsUnitInZones" ) + + local TransportZoneResult = nil + local TransportZonePos = nil + local TransportZone = nil + + -- fill-up some local variables to support further calculations to determine location of units within the zone. + if TransportUnit then + local TransportUnitPos = TransportUnit:getPosition().p + if type( LandingZones ) == "table" then + for LandingZoneID, LandingZoneName in pairs( LandingZones ) do + TransportZone = trigger.misc.getZone( LandingZoneName ) + if TransportZone then + TransportZonePos = {radius = TransportZone.radius, x = TransportZone.point.x, y = TransportZone.point.y, z = TransportZone.point.z} + if ((( TransportUnitPos.x - TransportZonePos.x)^2 + (TransportUnitPos.z - TransportZonePos.z)^2)^0.5 <= ZoneRadius ) then + TransportZoneResult = LandingZoneID + break + end + end + end + else + TransportZone = trigger.misc.getZone( LandingZones ) + TransportZonePos = {radius = TransportZone.radius, x = TransportZone.point.x, y = TransportZone.point.y, z = TransportZone.point.z} + if ((( TransportUnitPos.x - TransportZonePos.x)^2 + (TransportUnitPos.z - TransportZonePos.z)^2)^0.5 <= ZoneRadius ) then + TransportZoneResult = 1 + end + end + if TransportZoneResult then + --trace.i( "routines", "TransportZone:" .. TransportZoneResult ) + else + --trace.i( "routines", "TransportZone:nil logic" ) + end + return TransportZoneResult + else + --trace.i( "routines", "TransportZone:nil hard" ) + return nil + end +end + + function routines.IsStaticInZones( TransportStatic, LandingZones ) --trace.f() diff --git a/Moose/Scoring.lua b/Moose/Scoring.lua index 53f05a831..55ece4484 100644 --- a/Moose/Scoring.lua +++ b/Moose/Scoring.lua @@ -197,7 +197,7 @@ end function SCORING:_AddPlayerFromUnit( UnitData ) self:F( UnitData ) - if UnitData:isExist() then + if UnitData and UnitData:isExist() then local UnitName = UnitData:getName() local PlayerName = UnitData:getPlayerName() local UnitDesc = UnitData:getDesc() @@ -324,7 +324,7 @@ function SCORING:_EventOnHit( Event ) local InitUnitName = "" local InitGroup = nil local InitGroupName = "" - local InitPlayerName = "dummy" + local InitPlayerName = nil local InitCoalition = nil local InitCategory = nil diff --git a/Moose/Spawn.lua b/Moose/Spawn.lua index 91a5af746..7152b7c29 100644 --- a/Moose/Spawn.lua +++ b/Moose/Spawn.lua @@ -679,8 +679,9 @@ function SPAWN:SpawnInZone( Zone, ZoneRandomize, SpawnIndex ) -- Apply SpawnFormation for UnitID = 1, #SpawnTemplate.units do - SpawnTemplate.units[UnitID].x = ZonePoint.x - SpawnTemplate.units[UnitID].y = ZonePoint.y + local ZonePointUnit = Zone:GetRandomPointVec2() + SpawnTemplate.units[UnitID].x = ZonePointUnit.x + SpawnTemplate.units[UnitID].y = ZonePointUnit.y self:T( 'SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y ) end diff --git a/Moose/Stage.lua b/Moose/Stage.lua index 08d0d4f06..753bcae55 100644 --- a/Moose/Stage.lua +++ b/Moose/Stage.lua @@ -36,16 +36,22 @@ end function STAGE:Execute( Mission, Client, Task ) local Valid = true - + + self:T( self.Name ) + return Valid end function STAGE:Executing( Mission, Client, Task ) + self:T( self.Name ) + end function STAGE:Validate( Mission, Client, Task ) local Valid = true + + self:T( self.Name ) return Valid end @@ -255,7 +261,7 @@ function STAGEROUTE:Validate( Mission, Client, Task ) -- check if the Client is in the landing zone self:T( Task.LandingZones.LandingZoneNames ) - Task.CurrentLandingZoneName = routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.LandingZones.LandingZoneNames ) + Task.CurrentLandingZoneName = routines.IsUnitNearZonesRadius( Client:GetClientGroupDCSUnit(), Task.LandingZones.LandingZoneNames, 500 ) if Task.CurrentLandingZoneName then @@ -354,7 +360,7 @@ end function STAGELANDING:Validate( Mission, Client, Task ) self:F() - Task.CurrentLandingZoneName = routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.LandingZones.LandingZoneNames ) + Task.CurrentLandingZoneName = routines.IsUnitNearZonesRadius( Client:GetClientGroupDCSUnit(), Task.LandingZones.LandingZoneNames, 500 ) if Task.CurrentLandingZoneName then -- Client is in de landing zone. @@ -420,7 +426,7 @@ end function STAGELANDED:Validate( Mission, Client, Task ) self:F() - if not routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName ) then + if not routines.IsUnitNearZonesRadius( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName, 500 ) then self:T( "Client is not anymore in the landing zone, go back to stage Route, and remove cargo menus." ) Task.Signalled = false Task:RemoveCargoMenus( Client ) @@ -503,7 +509,7 @@ function STAGEUNLOAD:Validate( Mission, Client, Task ) self:F() env.info( 'STAGEUNLOAD:Validate()' ) - if routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName ) then + if routines.IsUnitNearZonesRadius( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName, 500 ) then else Task.ExecuteStage = _TransportExecuteStage.FAILED Task:RemoveCargoMenus( Client ) @@ -631,7 +637,7 @@ function STAGELOAD:Validate( Mission, Client, Task ) self:T( "Task.CurrentLandingZoneName = " .. Task.CurrentLandingZoneName ) if not Task.IsSlingLoad then - if not routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName ) then + if not routines.IsUnitNearZonesRadius( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName, 500 ) then Task:RemoveCargoMenus( Client ) Task.ExecuteStage = _TransportExecuteStage.FAILED Task.CargoName = nil diff --git a/Moose/Zone.lua b/Moose/Zone.lua index c1ef13b25..c85cae774 100644 --- a/Moose/Zone.lua +++ b/Moose/Zone.lua @@ -40,6 +40,17 @@ function ZONE:GetPointVec2() return Point end +function ZONE:GetPointVec3( Height ) + self:F( self.ZoneName ) + + local Zone = trigger.misc.getZone( self.ZoneName ) + local Point = { x = Zone.point.x, y = land.getHeight( self:GetPointVec2() ) + Height, z = Zone.point.z } + + self:T( { Zone, Point } ) + + return Point +end + function ZONE:GetRandomPointVec2() self:F( self.ZoneName )