Handler for unloading too.

This commit is contained in:
FlightControl_Master 2018-04-23 06:51:49 +02:00
parent af050629aa
commit c999389cda
10 changed files with 600 additions and 438 deletions

View File

@ -24,18 +24,21 @@ AI_CARGO_APC = {
--- Creates a new AI_CARGO_APC object. --- Creates a new AI_CARGO_APC object.
-- @param #AI_CARGO_APC self -- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
-- @param Cargo.CargoGroup#CARGO_GROUP CargoGroup -- @param Core.Set#SET_CARGO CargoSet
-- @param #number CombatRadius -- @param #number CombatRadius
-- @return #AI_CARGO_APC -- @return #AI_CARGO_APC
function AI_CARGO_APC:New( CargoCarrier, CargoGroup, CombatRadius ) function AI_CARGO_APC:New( CargoCarrier, CargoSet, CombatRadius )
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- #AI_CARGO_APC local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- #AI_CARGO_APC
self.CargoGroup = CargoGroup -- Cargo.CargoGroup#CARGO_GROUP self.CargoSet = CargoSet -- Core.Set#SET_CARGO
self.CombatRadius = CombatRadius self.CombatRadius = CombatRadius
self:SetStartState( "UnLoaded" ) self:SetStartState( "Unloaded" )
self:AddTransition( "Unloaded", "Pickup", "*" )
self:AddTransition( "Loaded", "Deploy", "*" )
self:AddTransition( "*", "Load", "Boarding" ) self:AddTransition( "*", "Load", "Boarding" )
self:AddTransition( "Boarding", "Board", "Boarding" ) self:AddTransition( "Boarding", "Board", "Boarding" )
@ -46,10 +49,85 @@ function AI_CARGO_APC:New( CargoCarrier, CargoGroup, CombatRadius )
self:AddTransition( "*", "Monitor", "*" ) self:AddTransition( "*", "Monitor", "*" )
self:AddTransition( "*", "Follow", "Following" ) self:AddTransition( "*", "Follow", "Following" )
self:AddTransition( "*", "Guard", "Guarding" ) self:AddTransition( "*", "Guard", "Unloaded" )
self:AddTransition( "*", "Destroyed", "Destroyed" ) self:AddTransition( "*", "Destroyed", "Destroyed" )
--- Pickup Handler OnBefore for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] OnBeforePickup
-- @param #AI_CARGO_APC self
-- @param #string From
-- @param #string Event
-- @param #string To
-- @param Core.Point#COORDINATE Coordinate
-- @return #boolean
--- Pickup Handler OnAfter for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] OnAfterPickup
-- @param #AI_CARGO_APC self
-- @param #string From
-- @param #string Event
-- @param #string To
-- @param Core.Point#COORDINATE Coordinate
--- Pickup Trigger for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] Pickup
-- @param #AI_CARGO_APC self
-- @param Core.Point#COORDINATE Coordinate
--- Pickup Asynchronous Trigger for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] __Pickup
-- @param #AI_CARGO_APC self
-- @param #number Delay
-- @param Core.Point#COORDINATE Coordinate
--- Deploy Handler OnBefore for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] OnBeforeDeploy
-- @param #AI_CARGO_APC self
-- @param #string From
-- @param #string Event
-- @param #string To
-- @param Core.Point#COORDINATE Coordinate
-- @return #boolean
--- Deploy Handler OnAfter for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] OnAfterDeploy
-- @param #AI_CARGO_APC self
-- @param #string From
-- @param #string Event
-- @param #string To
-- @param Core.Point#COORDINATE Coordinate
--- Deploy Trigger for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] Deploy
-- @param #AI_CARGO_APC self
-- @param Core.Point#COORDINATE Coordinate
--- Deploy Asynchronous Trigger for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] __Deploy
-- @param #AI_CARGO_APC self
-- @param Core.Point#COORDINATE Coordinate
-- @param #number Delay
--- Loaded Handler OnAfter for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] OnAfterLoaded
-- @param #AI_CARGO_APC self
-- @param Wrapper.Group#GROUP APC
-- @param #string From
-- @param #string Event
-- @param #string To
--- Unloaded Handler OnAfter for AI_CARGO_APC
-- @function [parent=#AI_CARGO_APC] OnAfterUnloaded
-- @param #AI_CARGO_APC self
-- @param Wrapper.Group#GROUP APC
-- @param #string From
-- @param #string Event
-- @param #string To
self:__Monitor( 1 ) self:__Monitor( 1 )
self:SetCarrier( CargoCarrier ) self:SetCarrier( CargoCarrier )
@ -60,11 +138,11 @@ end
--- Set the Carrier. --- Set the Carrier.
-- @param #AI_CARGO_APC self -- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
-- @return #AI_CARGO_APC -- @return #AI_CARGO_APC
function AI_CARGO_APC:SetCarrier( CargoCarrier ) function AI_CARGO_APC:SetCarrier( CargoCarrier )
self.CargoCarrier = CargoCarrier -- Wrapper.Unit#UNIT self.CargoCarrier = CargoCarrier -- Wrapper.Group#GROUP
self.CargoCarrier:SetState( self.CargoCarrier, "AI_CARGO_APC", self ) self.CargoCarrier:SetState( self.CargoCarrier, "AI_CARGO_APC", self )
CargoCarrier:HandleEvent( EVENTS.Dead ) CargoCarrier:HandleEvent( EVENTS.Dead )
@ -110,7 +188,7 @@ end
-- @param #AI_CARGO_APC self -- @param #AI_CARGO_APC self
-- @param Core.Point#COORDINATE Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @param #number Radius -- @param #number Radius
-- @return Wrapper.Unit#UNIT NewCarrier -- @return Wrapper.Group#GROUP NewCarrier
function AI_CARGO_APC:FindCarrier( Coordinate, Radius ) function AI_CARGO_APC:FindCarrier( Coordinate, Radius )
local CoordinateZone = ZONE_RADIUS:New( "Zone" , Coordinate:GetVec2(), Radius ) local CoordinateZone = ZONE_RADIUS:New( "Zone" , Coordinate:GetVec2(), Radius )
@ -122,11 +200,12 @@ function AI_CARGO_APC:FindCarrier( Coordinate, Radius )
local Attributes = NearUnit:GetDesc() local Attributes = NearUnit:GetDesc()
self:F({Desc=Attributes}) self:F({Desc=Attributes})
if NearUnit:HasAttribute( "Trucks" ) then if NearUnit:HasAttribute( "Trucks" ) then
self:SetCarrier( NearUnit ) return NearUnit:GetGroup()
break
end end
end end
end end
return nil
end end
@ -135,7 +214,7 @@ end
--- Follow Infantry to the Carrier. --- Follow Infantry to the Carrier.
-- @param #AI_CARGO_APC self -- @param #AI_CARGO_APC self
-- @param #AI_CARGO_APC Me -- @param #AI_CARGO_APC Me
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
-- @param Wrapper.Group#GROUP InfantryGroup -- @param Wrapper.Group#GROUP InfantryGroup
-- @return #AI_CARGO_APC -- @return #AI_CARGO_APC
function AI_CARGO_APC:FollowToCarrier( Me, CargoCarrier, InfantryGroup ) function AI_CARGO_APC:FollowToCarrier( Me, CargoCarrier, InfantryGroup )
@ -186,7 +265,7 @@ end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
function AI_CARGO_APC:onafterMonitor( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onafterMonitor( CargoCarrier, From, Event, To )
self:F( { CargoCarrier, From, Event, To } ) self:F( { CargoCarrier, From, Event, To } )
@ -195,32 +274,33 @@ function AI_CARGO_APC:onafterMonitor( CargoCarrier, From, Event, To )
local Coordinate = CargoCarrier:GetCoordinate() local Coordinate = CargoCarrier:GetCoordinate()
self.Zone:Scan( { Object.Category.UNIT } ) self.Zone:Scan( { Object.Category.UNIT } )
if self.Zone:IsAllInZoneOfCoalition( self.Coalition ) then if self.Zone:IsAllInZoneOfCoalition( self.Coalition ) then
if self:Is( "Unloaded" ) or self:Is( "Guarding" ) or self:Is( "Following" ) then if self:Is( "Unloaded" ) or self:Is( "Following" ) then
-- There are no enemies within combat range. Load the CargoCarrier. -- There are no enemies within combat range. Load the CargoCarrier.
self:__Load( 1 ) self:Load()
end end
else else
if self:Is( "Loaded" ) then if self:Is( "Loaded" ) then
-- There are enemies within combat range. Unload the CargoCarrier. -- There are enemies within combat range. Unload the CargoCarrier.
self:__Unload( 1 ) self:__Unload( 1 )
end
end
if self:Is( "Guarding" ) then
if not self.CargoGroup:IsNear( CargoCarrier, 5 ) then
self:Follow()
end
end
if self:Is( "Following" ) then
local Distance = Coordinate:Get2DDistance( self.CargoGroup:GetCoordinate() )
self:F( { Distance = Distance } )
if Distance > 40 then
CargoCarrier:RouteStop()
self.CarrierStopped = true
else else
if self.CarrierStopped then if self:Is( "Unloaded" ) then
if self.CargoGroup:IsNear( CargoCarrier, 10 ) then if not self.Cargo:IsNear( CargoCarrier, 5 ) then
CargoCarrier:RouteResume() self:Follow()
self.CarrierStopped = nil end
end
if self:Is( "Following" ) then
local Distance = Coordinate:Get2DDistance( self.Cargo:GetCoordinate() )
self:F( { Distance = Distance } )
if Distance > 40 then
CargoCarrier:RouteStop()
self.CarrierStopped = true
else
if self.CarrierStopped then
if self.Cargo:IsNear( CargoCarrier, 10 ) then
CargoCarrier:RouteResume()
self.CarrierStopped = nil
end
end
end end
end end
end end
@ -236,66 +316,77 @@ end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP Carrier
function AI_CARGO_APC:onafterLoad( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onbeforeLoad( Carrier, From, Event, To )
self:F( { CargoCarrier, From, Event, To } ) self:F( { Carrier, From, Event, To } )
if CargoCarrier and CargoCarrier:IsAlive() then if Carrier and Carrier:IsAlive() then
CargoCarrier:RouteStop() for _, Cargo in pairs( self.CargoSet:GetSet() ) do
self:__Board( 10 ) local Cargo = Cargo -- Cargo.Cargo#CARGO
self.CargoGroup:Board( CargoCarrier, 10 ) self:F( Cargo )
if Cargo:IsInLoadRadius( Carrier:GetCoordinate() ) then
self:F( "In radius" )
Carrier:RouteStop()
self:__Board( 1, Cargo )
Cargo:Board( Carrier:GetUnit(1), 25 )
return true
end
end
end end
return false
end end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP Carrier
function AI_CARGO_APC:onafterBoard( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onafterBoard( Carrier, From, Event, To, Cargo )
self:F( { CargoCarrier, From, Event, To } ) self:F( { Carrier, From, Event, To, Cargo } )
if CargoCarrier and CargoCarrier:IsAlive() then if Carrier and Carrier:IsAlive() then
self:F({ IsLoaded = self.CargoGroup:IsLoaded() } ) self:F({ IsLoaded = Cargo:IsLoaded() } )
if not self.CargoGroup:IsLoaded() then if not Cargo:IsLoaded() then
self:__Board( 10 ) self:__Board( 10, Cargo )
else else
self:__Loaded( 1 ) self:__Loaded( 1, Cargo )
end end
end end
end end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
function AI_CARGO_APC:onafterLoaded( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onafterLoaded( CargoCarrier, From, Event, To, Cargo )
self:F( { CargoCarrier, From, Event, To } ) self:F( { CargoCarrier, From, Event, To, Cargo } )
if CargoCarrier and CargoCarrier:IsAlive() then if CargoCarrier and CargoCarrier:IsAlive() then
CargoCarrier:RouteResume() CargoCarrier:RouteResume()
self.Cargo = Cargo
end end
end end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
function AI_CARGO_APC:onafterUnload( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onafterUnload( CargoCarrier, From, Event, To )
self:F( { CargoCarrier, From, Event, To } ) self:F( { CargoCarrier, From, Event, To } )
if CargoCarrier and CargoCarrier:IsAlive() then if CargoCarrier and CargoCarrier:IsAlive() then
CargoCarrier:RouteStop() CargoCarrier:RouteStop()
self.CargoGroup:UnBoard( ) self.Cargo:UnBoard()
self:__Unboard( 10 ) self:__Unboard( 10 )
end end
end end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
function AI_CARGO_APC:onafterUnboard( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onafterUnboard( CargoCarrier, From, Event, To )
self:F( { CargoCarrier, From, Event, To } ) self:F( { CargoCarrier, From, Event, To } )
if CargoCarrier and CargoCarrier:IsAlive() then if CargoCarrier and CargoCarrier:IsAlive() then
if not self.CargoGroup:IsUnLoaded() then if not self.Cargo:IsUnLoaded() then
self:__Unboard( 10 ) self:__Unboard( 10 )
else else
self:__Unloaded( 1 ) self:__Unloaded( 1 )
@ -305,7 +396,7 @@ function AI_CARGO_APC:onafterUnboard( CargoCarrier, From, Event, To )
end end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
function AI_CARGO_APC:onafterUnloaded( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onafterUnloaded( CargoCarrier, From, Event, To )
self:F( { CargoCarrier, From, Event, To } ) self:F( { CargoCarrier, From, Event, To } )
@ -319,13 +410,13 @@ end
--- @param #AI_CARGO_APC self --- @param #AI_CARGO_APC self
-- @param Wrapper.Unit#UNIT CargoCarrier -- @param Wrapper.Group#GROUP CargoCarrier
function AI_CARGO_APC:onafterFollow( CargoCarrier, From, Event, To ) function AI_CARGO_APC:onafterFollow( CargoCarrier, From, Event, To )
self:F( { CargoCarrier, From, Event, To } ) self:F( { CargoCarrier, From, Event, To } )
self:F( "Follow" ) self:F( "Follow" )
if CargoCarrier and CargoCarrier:IsAlive() then if CargoCarrier and CargoCarrier:IsAlive() then
self.CargoGroup.CargoSet:ForEach( self.Cargo.CargoSet:ForEach(
--- @param Core.Cargo#CARGO Cargo --- @param Core.Cargo#CARGO Cargo
function( Cargo ) function( Cargo )
self:F( { "Follow", Cargo.CargoObject:GetName() } ) self:F( { "Follow", Cargo.CargoObject:GetName() } )
@ -339,3 +430,66 @@ function AI_CARGO_APC:onafterFollow( CargoCarrier, From, Event, To )
end end
--- @param #AI_CARGO_APC
-- @param Wrapper.Group#GROUP Carrier
function AI_CARGO_APC._Pickup( Carrier )
Carrier:F( { "AI_CARGO_APC._Pickup:", Carrier:GetName() } )
if Carrier:IsAlive() then
Carrier:__Load( 1 )
end
end
--- @param #AI_CARGO_APC
-- @param Wrapper.Group#GROUP Carrier
function AI_CARGO_APC._Deploy( Carrier )
Carrier:F( { "AI_CARGO_APC._Deploy:", Carrier:GetName() } )
if Carrier:IsAlive() then
Carrier:__Unload( 1 )
end
end
--- @param #AI_CARGO_APC self
-- @param Wrapper.Group#GROUP Carrier
-- @param From
-- @param Event
-- @param To
-- @param Core.Point#COORDINATE Coordinate
-- @param #number Speed
function AI_CARGO_APC:onafterPickup( Carrier, From, Event, To, Coordinate, Speed )
if Carrier and Carrier:IsAlive() then
self.RoutePickup = true
Carrier:RouteGroundOnRoad( Coordinate, Speed, 1 )
end
end
--- @param #AI_CARGO_APC self
-- @param Wrapper.Group#GROUP Carrier
-- @param From
-- @param Event
-- @param To
-- @param Core.Point#COORDINATE Coordinate
-- @param #number Speed
function AI_CARGO_APC:onafterDeploy( Carrier, From, Event, To, Coordinate, Speed )
if Carrier and Carrier:IsAlive() then
self.RouteDeploy = true
Carrier:RouteGroundOnRoad( Coordinate, Speed, 1 )
end
end

View File

@ -24,7 +24,7 @@ AI_CARGO_HELICOPTER = {
--- Creates a new AI_CARGO_HELICOPTER object. --- Creates a new AI_CARGO_HELICOPTER object.
-- @param #AI_CARGO_HELICOPTER self -- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
-- @param Core.Set#SET_CARGO CargoSet -- @param Core.Set#SET_CARGO CargoSet
-- @param #number CombatRadius -- @param #number CombatRadius
-- @return #AI_CARGO_HELICOPTER -- @return #AI_CARGO_HELICOPTER
@ -116,13 +116,13 @@ end
--- Set the Carrier. --- Set the Carrier.
-- @param #AI_CARGO_HELICOPTER self -- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
-- @return #AI_CARGO_HELICOPTER -- @return #AI_CARGO_HELICOPTER
function AI_CARGO_HELICOPTER:SetCarrier( Helicopter ) function AI_CARGO_HELICOPTER:SetCarrier( Helicopter )
local AICargo = self local AICargo = self
self.Helicopter = Helicopter -- Wrapper.Unit#UNIT self.Helicopter = Helicopter -- Wrapper.Group#GROUP
self.Helicopter:SetState( self.Helicopter, "AI_CARGO_HELICOPTER", self ) self.Helicopter:SetState( self.Helicopter, "AI_CARGO_HELICOPTER", self )
self.RoutePickup = false self.RoutePickup = false
@ -173,7 +173,7 @@ end
-- @param #AI_CARGO_HELICOPTER self -- @param #AI_CARGO_HELICOPTER self
-- @param Core.Point#COORDINATE Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @param #number Radius -- @param #number Radius
-- @return Wrapper.Unit#UNIT NewCarrier -- @return Wrapper.Group#GROUP NewCarrier
function AI_CARGO_HELICOPTER:FindCarrier( Coordinate, Radius ) function AI_CARGO_HELICOPTER:FindCarrier( Coordinate, Radius )
local CoordinateZone = ZONE_RADIUS:New( "Zone" , Coordinate:GetVec2(), Radius ) local CoordinateZone = ZONE_RADIUS:New( "Zone" , Coordinate:GetVec2(), Radius )
@ -183,18 +183,19 @@ function AI_CARGO_HELICOPTER:FindCarrier( Coordinate, Radius )
self:F({NearUnit=NearUnit}) self:F({NearUnit=NearUnit})
if not NearUnit:GetState( NearUnit, "AI_CARGO_HELICOPTER" ) then if not NearUnit:GetState( NearUnit, "AI_CARGO_HELICOPTER" ) then
local Attributes = NearUnit:GetDesc() local Attributes = NearUnit:GetDesc()
self:F({Desc=Attributes}) self:F({Attributes=Attributes})
if NearUnit:HasAttribute( "Trucks" ) then if NearUnit:HasAttribute( "Trucks" ) then
self:SetCarrier( NearUnit ) return NearUnit:GetGroup()
break
end end
end end
end end
return nil
end end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
-- @param From -- @param From
-- @param Event -- @param Event
-- @param To -- @param To
@ -221,7 +222,7 @@ end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
-- @param From -- @param From
-- @param Event -- @param Event
-- @param To -- @param To
@ -276,7 +277,7 @@ end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
-- @param From -- @param From
-- @param Event -- @param Event
-- @param To -- @param To
@ -331,7 +332,7 @@ end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
function AI_CARGO_HELICOPTER:onafterLoad( Helicopter, From, Event, To, Coordinate ) function AI_CARGO_HELICOPTER:onafterLoad( Helicopter, From, Event, To, Coordinate )
if Helicopter and Helicopter:IsAlive() then if Helicopter and Helicopter:IsAlive() then
@ -339,7 +340,7 @@ function AI_CARGO_HELICOPTER:onafterLoad( Helicopter, From, Event, To, Coordinat
for _, Cargo in pairs( self.CargoSet:GetSet() ) do for _, Cargo in pairs( self.CargoSet:GetSet() ) do
if Cargo:IsInLoadRadius( Coordinate ) then if Cargo:IsInLoadRadius( Coordinate ) then
self:__Board( 5 ) self:__Board( 5 )
Cargo:Board( Helicopter, 25 ) Cargo:Board( Helicopter:GetUnit(1), 25 )
self.Cargo = Cargo self.Cargo = Cargo
break break
end end
@ -349,7 +350,7 @@ function AI_CARGO_HELICOPTER:onafterLoad( Helicopter, From, Event, To, Coordinat
end end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To ) function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To )
if Helicopter and Helicopter:IsAlive() then if Helicopter and Helicopter:IsAlive() then
@ -364,7 +365,7 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To )
end end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
function AI_CARGO_HELICOPTER:onafterLoaded( Helicopter, From, Event, To ) function AI_CARGO_HELICOPTER:onafterLoaded( Helicopter, From, Event, To )
if Helicopter and Helicopter:IsAlive() then if Helicopter and Helicopter:IsAlive() then
@ -374,7 +375,7 @@ end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
function AI_CARGO_HELICOPTER:onafterUnload( Helicopter, From, Event, To ) function AI_CARGO_HELICOPTER:onafterUnload( Helicopter, From, Event, To )
if Helicopter and Helicopter:IsAlive() then if Helicopter and Helicopter:IsAlive() then
@ -385,7 +386,7 @@ function AI_CARGO_HELICOPTER:onafterUnload( Helicopter, From, Event, To )
end end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
function AI_CARGO_HELICOPTER:onafterUnboard( Helicopter, From, Event, To ) function AI_CARGO_HELICOPTER:onafterUnboard( Helicopter, From, Event, To )
if Helicopter and Helicopter:IsAlive() then if Helicopter and Helicopter:IsAlive() then
@ -399,7 +400,7 @@ function AI_CARGO_HELICOPTER:onafterUnboard( Helicopter, From, Event, To )
end end
--- @param #AI_CARGO_HELICOPTER self --- @param #AI_CARGO_HELICOPTER self
-- @param Wrapper.Unit#UNIT Helicopter -- @param Wrapper.Group#GROUP Helicopter
function AI_CARGO_HELICOPTER:onafterUnloaded( Helicopter, From, Event, To ) function AI_CARGO_HELICOPTER:onafterUnloaded( Helicopter, From, Event, To )
if Helicopter and Helicopter:IsAlive() then if Helicopter and Helicopter:IsAlive() then

View File

@ -566,14 +566,14 @@ do -- CARGO
--- Check if Cargo is in the LoadRadius for the Cargo to be Boarded or Loaded. --- Check if Cargo is in the LoadRadius for the Cargo to be Boarded or Loaded.
-- @param #CARGO self -- @param #CARGO self
-- @param Core.Point#Coordinate Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @return #boolean true if the CargoGroup is within the loading radius. -- @return #boolean true if the CargoGroup is within the loading radius.
function CARGO:IsInLoadRadius( Coordinate ) function CARGO:IsInLoadRadius( Coordinate )
self:F( { Coordinate, LoadRadius = self.LoadRadius } ) self:F( { Coordinate, LoadRadius = self.LoadRadius } )
local Distance = 0 local Distance = 0
if self:IsUnLoaded() then if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
self:T( Distance ) self:T( Distance )
if Distance <= self.LoadRadius then if Distance <= self.LoadRadius then
return true return true
@ -586,14 +586,14 @@ do -- CARGO
--- Check if the Cargo can report itself to be Boarded or Loaded. --- Check if the Cargo can report itself to be Boarded or Loaded.
-- @param #CARGO self -- @param #CARGO self
-- @param Core.Point#Coordinate Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @return #boolean true if the Cargo can report itself. -- @return #boolean true if the Cargo can report itself.
function CARGO:IsInReportRadius( Coordinate ) function CARGO:IsInReportRadius( Coordinate )
self:F( { Coordinate } ) self:F( { Coordinate } )
local Distance = 0 local Distance = 0
if self:IsUnLoaded() then if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
self:T( Distance ) self:T( Distance )
if Distance <= self.LoadRadius then if Distance <= self.LoadRadius then
return true return true
@ -606,18 +606,18 @@ do -- CARGO
--- Check if CargoCarrier is near the Cargo to be Loaded. --- Check if CargoCarrier is near the Cargo to be Loaded.
-- @param #CARGO self -- @param #CARGO self
-- @param Core.Point#POINT_VEC2 PointVec2 -- @param Core.Point#COORDINATE Coordinate
-- @param #number NearRadius The radius when the cargo will board the Carrier (to avoid collision). -- @param #number NearRadius The radius when the cargo will board the Carrier (to avoid collision).
-- @return #boolean -- @return #boolean
function CARGO:IsNear( PointVec2, NearRadius ) function CARGO:IsNear( Coordinate, NearRadius )
--self:F( { PointVec2 = PointVec2, NearRadius = NearRadius } ) --self:F( { PointVec2 = PointVec2, NearRadius = NearRadius } )
if self.CargoObject:IsAlive() then if self.CargoObject:IsAlive() then
--local Distance = PointVec2:DistanceFromPointVec2( self.CargoObject:GetPointVec2() ) --local Distance = PointVec2:Get2DDistance( self.CargoObject:GetPointVec2() )
--self:F( { CargoObjectName = self.CargoObject:GetName() } ) --self:F( { CargoObjectName = self.CargoObject:GetName() } )
--self:F( { CargoObjectVec2 = self.CargoObject:GetVec2() } ) --self:F( { CargoObjectVec2 = self.CargoObject:GetVec2() } )
--self:F( { PointVec2 = PointVec2:GetVec2() } ) --self:F( { PointVec2 = PointVec2:GetVec2() } )
local Distance = PointVec2:Get2DDistance( self.CargoObject:GetPointVec2() ) local Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
--self:F( Distance ) --self:F( Distance )
if Distance <= NearRadius then if Distance <= NearRadius then
@ -979,9 +979,9 @@ end
function CARGO_PACKAGE:IsNear( CargoCarrier ) function CARGO_PACKAGE:IsNear( CargoCarrier )
self:F() self:F()
local CargoCarrierPoint = CargoCarrier:GetPointVec2() local CargoCarrierPoint = CargoCarrier:GetCoordinate()
local Distance = CargoCarrierPoint:DistanceFromPointVec2( self.CargoCarrier:GetPointVec2() ) local Distance = CargoCarrierPoint:Get2DDistance( self.CargoCarrier:GetCoordinate() )
self:T( Distance ) self:T( Distance )
if Distance <= self.NearRadius then if Distance <= self.NearRadius then

View File

@ -166,14 +166,14 @@ do -- CARGO_CRATE
--- Check if Cargo Crate is in the radius for the Cargo to be reported. --- Check if Cargo Crate is in the radius for the Cargo to be reported.
-- @param #CARGO self -- @param #CARGO self
-- @param Core.Point#Coordinate Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @return #boolean true if the Cargo Crate is within the report radius. -- @return #boolean true if the Cargo Crate is within the report radius.
function CARGO_CRATE:IsInReportRadius( Coordinate ) function CARGO_CRATE:IsInReportRadius( Coordinate )
--self:F( { Coordinate, LoadRadius = self.LoadRadius } ) --self:F( { Coordinate, LoadRadius = self.LoadRadius } )
local Distance = 0 local Distance = 0
if self:IsUnLoaded() then if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
--self:T( Distance ) --self:T( Distance )
if Distance <= self.LoadRadius then if Distance <= self.LoadRadius then
return true return true
@ -193,7 +193,7 @@ do -- CARGO_CRATE
local Distance = 0 local Distance = 0
if self:IsUnLoaded() then if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
--self:T( Distance ) --self:T( Distance )
if Distance <= self.NearRadius then if Distance <= self.NearRadius then
return true return true

View File

@ -58,8 +58,9 @@ do -- CARGO_GROUP
local WeightGroup = 0 local WeightGroup = 0
self.GroupName = CargoGroup:GetName() local GroupName = CargoGroup:GetName()
self.CargoTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplate( self.GroupName ) ) local CargoName = GroupName:match("(.*)~CARGO") or GroupName
self.CargoTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplate( GroupName ) )
CargoGroup:Destroy() CargoGroup:Destroy()
@ -67,11 +68,11 @@ do -- CARGO_GROUP
for UnitID, UnitTemplate in pairs( self.CargoTemplate.units ) do for UnitID, UnitTemplate in pairs( self.CargoTemplate.units ) do
local GroupTemplate = UTILS.DeepCopy( self.CargoTemplate ) local GroupTemplate = UTILS.DeepCopy( self.CargoTemplate )
local GroupName = env.getValueDictByKey( GroupTemplate.name ) --local GroupName = env.getValueDictByKey( GroupTemplate.name )
-- We create a new group object with one unit... -- We create a new group object with one unit...
-- First we prepare the template... -- First we prepare the template...
GroupTemplate.name = GroupName .. "#CARGO#" .. UnitID GroupTemplate.name = CargoName .. "#CARGO#" .. UnitID
GroupTemplate.groupId = nil GroupTemplate.groupId = nil
GroupTemplate.units = {} GroupTemplate.units = {}
GroupTemplate.units[1] = UnitTemplate GroupTemplate.units[1] = UnitTemplate
@ -442,7 +443,7 @@ do -- CARGO_GROUP
--- Check if Cargo Group is in the radius for the Cargo to be Boarded. --- Check if Cargo Group is in the radius for the Cargo to be Boarded.
-- @param #CARGO_GROUP self -- @param #CARGO_GROUP self
-- @param Core.Point#Coordinate Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @return #boolean true if the Cargo Group is within the load radius. -- @return #boolean true if the Cargo Group is within the load radius.
function CARGO_GROUP:IsInLoadRadius( Coordinate ) function CARGO_GROUP:IsInLoadRadius( Coordinate )
--self:F( { Coordinate } ) --self:F( { Coordinate } )
@ -452,12 +453,12 @@ do -- CARGO_GROUP
if Cargo then if Cargo then
local Distance = 0 local Distance = 0
if Cargo:IsLoaded() then if Cargo:IsLoaded() then
Distance = Coordinate:DistanceFromPointVec2( Cargo.CargoCarrier:GetPointVec2() ) Distance = Coordinate:Get2DDistance( Cargo.CargoCarrier:GetCoordinate() )
else else
Distance = Coordinate:DistanceFromPointVec2( Cargo.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( Cargo.CargoObject:GetCoordinate() )
end end
--self:T( Distance )
self:F( { Distance = Distance, LoadRadius = self.LoadRadius } )
if Distance <= self.LoadRadius then if Distance <= self.LoadRadius then
return true return true
else else
@ -480,9 +481,10 @@ do -- CARGO_GROUP
local Cargo = self.CargoSet:GetFirst() -- #CARGO local Cargo = self.CargoSet:GetFirst() -- #CARGO
if Cargo then if Cargo then
self:F( { Cargo } )
local Distance = 0 local Distance = 0
if Cargo:IsUnLoaded() then if Cargo:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( Cargo.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( Cargo.CargoObject:GetCoordinate() )
--self:T( Distance ) --self:T( Distance )
if Distance <= self.LoadRadius then if Distance <= self.LoadRadius then
return true return true

View File

@ -119,14 +119,14 @@ do -- CARGO_SLINGLOAD
--- Check if Cargo Crate is in the radius for the Cargo to be reported. --- Check if Cargo Crate is in the radius for the Cargo to be reported.
-- @param #CARGO_SLINGLOAD self -- @param #CARGO_SLINGLOAD self
-- @param Core.Point#Coordinate Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @return #boolean true if the Cargo Crate is within the report radius. -- @return #boolean true if the Cargo Crate is within the report radius.
function CARGO_SLINGLOAD:IsInReportRadius( Coordinate ) function CARGO_SLINGLOAD:IsInReportRadius( Coordinate )
--self:F( { Coordinate, LoadRadius = self.LoadRadius } ) --self:F( { Coordinate, LoadRadius = self.LoadRadius } )
local Distance = 0 local Distance = 0
if self:IsUnLoaded() then if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
if Distance <= self.LoadRadius then if Distance <= self.LoadRadius then
return true return true
end end
@ -138,14 +138,14 @@ do -- CARGO_SLINGLOAD
--- Check if Cargo Slingload is in the radius for the Cargo to be Boarded or Loaded. --- Check if Cargo Slingload is in the radius for the Cargo to be Boarded or Loaded.
-- @param #CARGO_SLINGLOAD self -- @param #CARGO_SLINGLOAD self
-- @param Core.Point#Coordinate Coordinate -- @param Core.Point#COORDINATE Coordinate
-- @return #boolean true if the Cargo Slingload is within the loading radius. -- @return #boolean true if the Cargo Slingload is within the loading radius.
function CARGO_SLINGLOAD:IsInLoadRadius( Coordinate ) function CARGO_SLINGLOAD:IsInLoadRadius( Coordinate )
--self:F( { Coordinate } ) --self:F( { Coordinate } )
local Distance = 0 local Distance = 0
if self:IsUnLoaded() then if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() ) Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
if Distance <= self.NearRadius then if Distance <= self.NearRadius then
return true return true
end end

View File

@ -49,7 +49,7 @@ do -- CARGO_UNIT
-- @return #CARGO_UNIT -- @return #CARGO_UNIT
function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius ) function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, NearRadius ) ) -- #CARGO_UNIT local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, NearRadius ) ) -- #CARGO_UNIT
self:F( { Type, Name, Weight, NearRadius } ) self:I( { Type, Name, Weight, NearRadius } )
self:T( CargoUnit ) self:T( CargoUnit )
self.CargoObject = CargoUnit self.CargoObject = CargoUnit

View File

@ -284,7 +284,7 @@ do -- cargo
TemplateName = env.getValueDictByKey( TemplateName ) TemplateName = env.getValueDictByKey( TemplateName )
local Cargo = TemplateName:match( "#(CARGO)" ) local Cargo = TemplateName:match( "~(CARGO)" )
return Cargo and Cargo == "CARGO" return Cargo and Cargo == "CARGO"
end end
@ -293,6 +293,7 @@ do -- cargo
-- @param #DATABASE self -- @param #DATABASE self
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:RegisterCargos() function DATABASE:RegisterCargos()
for CargoGroupName, CargoGroup in pairs( self.GROUPS ) do for CargoGroupName, CargoGroup in pairs( self.GROUPS ) do
if self:IsCargo( CargoGroupName ) then if self:IsCargo( CargoGroupName ) then
@ -300,11 +301,12 @@ do -- cargo
local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)") local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)")
local CargoName = CargoGroupName:match("(.*)~CARGO") local CargoName = CargoGroupName:match("(.*)~CARGO")
local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?") local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?")
local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") or CargoName
local LoadRadius = CargoParam and CargoParam:match( "RR=([%a%d]+),?") local LoadRadius = CargoParam and tonumber( CargoParam:match( "RR=([%a%d]+),?") )
local NearRadius = CargoParam and CargoParam:match( "NR=([%a%d]+),?") local NearRadius = CargoParam and tonumber( CargoParam:match( "NR=([%a%d]+),?") )
CARGO_GROUP:New( CargoGroup, Type, Name or CargoName, LoadRadius, NearRadius ) self:F({"Register CargoGroup:",Type=Type,Name=Name,LoadRadius=LoadRadius,NearRadius=NearRadius})
CARGO_GROUP:New( CargoGroup, Type, Name, LoadRadius, NearRadius )
end end
end end
@ -315,15 +317,17 @@ do -- cargo
local CargoName = CargoStaticName:match("(.*)~CARGO") local CargoName = CargoStaticName:match("(.*)~CARGO")
local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?") local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?")
local Category = CargoParam and CargoParam:match( "C=([%a%d ]+),?") local Category = CargoParam and CargoParam:match( "C=([%a%d ]+),?")
local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") or CargoName
local LoadRadius = CargoParam and tonumber( CargoParam:match( "RR=([%a%d]+),?") ) local LoadRadius = CargoParam and tonumber( CargoParam:match( "RR=([%a%d]+),?") )
local NearRadius = CargoParam and tonumber( CargoParam:match( "NR=([%a%d]+),?") ) local NearRadius = CargoParam and tonumber( CargoParam:match( "NR=([%a%d]+),?") )
if Category == "SLING" then if Category == "SLING" then
CARGO_SLINGLOAD:New( CargoStatic, Type, Name or CargoName, LoadRadius, NearRadius ) self:F({"Register CargoSlingload:",Type=Type,Name=Name,LoadRadius=LoadRadius,NearRadius=NearRadius})
CARGO_SLINGLOAD:New( CargoStatic, Type, Name, LoadRadius, NearRadius )
else else
if Category == "CRATE" then if Category == "CRATE" then
CARGO_CRATE:New( CargoStatic, Type, Name or CargoName, LoadRadius, NearRadius ) self:F({"Register CargoCrate:",Type=Type,Name=Name,LoadRadius=LoadRadius,NearRadius=NearRadius})
CARGO_CRATE:New( CargoStatic, Type, Name, LoadRadius, NearRadius )
end end
end end
end end

View File

@ -274,21 +274,19 @@ do -- COORDINATE
--TODO: check this to replace --- Calculate the distance from a reference @{#COORDINATE}.
--- Calculate the distance from a reference @{DCSTypes#Vec2}.
-- @param #COORDINATE self -- @param #COORDINATE self
-- @param Dcs.DCSTypes#Vec2 Vec2Reference The reference @{DCSTypes#Vec2}. -- @param #COORDINATE PointVec2Reference The reference @{#COORDINATE}.
-- @return Dcs.DCSTypes#Distance The distance from the reference @{DCSTypes#Vec2} in meters. -- @return Dcs.DCSTypes#Distance The distance from the reference @{#COORDINATE} in meters.
function COORDINATE:DistanceFromVec2( Vec2Reference ) function COORDINATE:DistanceFromPointVec2( PointVec2Reference )
self:F2( Vec2Reference ) self:F2( PointVec2Reference )
local Distance = ( ( Vec2Reference.x - self.x ) ^ 2 + ( Vec2Reference.y - self.z ) ^2 ) ^0.5 local Distance = ( ( PointVec2Reference.x - self.x ) ^ 2 + ( PointVec2Reference.z - self.z ) ^2 ) ^ 0.5
self:T2( Distance ) self:T2( Distance )
return Distance return Distance
end end
--- Add a Distance in meters from the COORDINATE orthonormal plane, with the given angle, and calculate the new COORDINATE. --- Add a Distance in meters from the COORDINATE orthonormal plane, with the given angle, and calculate the new COORDINATE.
-- @param #COORDINATE self -- @param #COORDINATE self
-- @param Dcs.DCSTypes#Distance Distance The Distance to be added in meters. -- @param Dcs.DCSTypes#Distance Distance The Distance to be added in meters.

View File

@ -1761,351 +1761,354 @@ function CONTROLLABLE:TaskRoute( Points )
return DCSTask return DCSTask
end end
--- (AIR + GROUND) Make the Controllable move to fly to a given point. do -- Route methods
-- @param #CONTROLLABLE self
-- @param Dcs.DCSTypes#Vec3 Point The destination point in Vec3 format.
-- @param #number Speed The speed to travel.
-- @return #CONTROLLABLE self
function CONTROLLABLE:RouteToVec2( Point, Speed )
self:F2( { Point, Speed } )
local ControllablePoint = self:GetUnit( 1 ):GetVec2() --- (AIR + GROUND) Make the Controllable move to fly to a given point.
-- @param #CONTROLLABLE self
local PointFrom = {} -- @param Dcs.DCSTypes#Vec3 Point The destination point in Vec3 format.
PointFrom.x = ControllablePoint.x -- @param #number Speed The speed to travel.
PointFrom.y = ControllablePoint.y -- @return #CONTROLLABLE self
PointFrom.type = "Turning Point" function CONTROLLABLE:RouteToVec2( Point, Speed )
PointFrom.action = "Turning Point" self:F2( { Point, Speed } )
PointFrom.speed = Speed
PointFrom.speed_locked = true
PointFrom.properties = {
["vnav"] = 1,
["scale"] = 0,
["angle"] = 0,
["vangle"] = 0,
["steer"] = 2,
}
local PointTo = {}
PointTo.x = Point.x
PointTo.y = Point.y
PointTo.type = "Turning Point"
PointTo.action = "Fly Over Point"
PointTo.speed = Speed
PointTo.speed_locked = true
PointTo.properties = {
["vnav"] = 1,
["scale"] = 0,
["angle"] = 0,
["vangle"] = 0,
["steer"] = 2,
}
local Points = { PointFrom, PointTo }
self:T3( Points )
self:Route( Points )
return self
end
--- (AIR + GROUND) Make the Controllable move to a given point.
-- @param #CONTROLLABLE self
-- @param Dcs.DCSTypes#Vec3 Point The destination point in Vec3 format.
-- @param #number Speed The speed to travel.
-- @return #CONTROLLABLE self
function CONTROLLABLE:RouteToVec3( Point, Speed )
self:F2( { Point, Speed } )
local ControllableVec3 = self:GetUnit( 1 ):GetVec3()
local PointFrom = {}
PointFrom.x = ControllableVec3.x
PointFrom.y = ControllableVec3.z
PointFrom.alt = ControllableVec3.y
PointFrom.alt_type = "BARO"
PointFrom.type = "Turning Point"
PointFrom.action = "Turning Point"
PointFrom.speed = Speed
PointFrom.speed_locked = true
PointFrom.properties = {
["vnav"] = 1,
["scale"] = 0,
["angle"] = 0,
["vangle"] = 0,
["steer"] = 2,
}
local PointTo = {}
PointTo.x = Point.x
PointTo.y = Point.z
PointTo.alt = Point.y
PointTo.alt_type = "BARO"
PointTo.type = "Turning Point"
PointTo.action = "Fly Over Point"
PointTo.speed = Speed
PointTo.speed_locked = true
PointTo.properties = {
["vnav"] = 1,
["scale"] = 0,
["angle"] = 0,
["vangle"] = 0,
["steer"] = 2,
}
local Points = { PointFrom, PointTo }
self:T3( Points )
self:Route( Points )
return self
end
--- Make the controllable to follow a given route.
-- @param #CONTROLLABLE self
-- @param #table Route A table of Route Points.
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:Route( Route, DelaySeconds )
self:F2( Route )
local DCSControllable = self:GetDCSObject()
if DCSControllable then
local RouteTask = self:TaskRoute( Route ) -- Create a RouteTask, that will route the CONTROLLABLE to the Route.
self:SetTask( RouteTask, DelaySeconds or 1 ) -- Execute the RouteTask after the specified seconds (default is 1).
return self
end
return nil
end
--- Stops the movement of the vehicle on the route.
-- @param #CONTROLLABLE self
-- @return #CONTROLLABLE
function CONTROLLABLE:RouteStop()
self:F("RouteStop")
local CommandStop = self:CommandStopRoute( true ) local ControllablePoint = self:GetUnit( 1 ):GetVec2()
self:SetCommand( CommandStop )
end
--- Resumes the movement of the vehicle on the route.
-- @param #CONTROLLABLE self
-- @return #CONTROLLABLE
function CONTROLLABLE:RouteResume()
self:F("RouteResume")
local CommandResume = self:CommandStopRoute( false )
self:SetCommand( CommandResume )
end
--- Make the GROUND Controllable to drive towards a specific point.
-- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param #number Speed (optional) Speed in km/h. The default speed is 999 km/h.
-- @param #string Formation (optional) The route point Formation, which is a text string that specifies exactly the Text in the Type of the route point, like "Vee", "Echelon Right".
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteGroundTo( ToCoordinate, Speed, Formation, DelaySeconds )
local FromCoordinate = self:GetCoordinate()
local FromWP = FromCoordinate:WaypointGround()
local ToWP = ToCoordinate:WaypointGround( Speed, Formation )
self:Route( { FromWP, ToWP }, DelaySeconds )
return self
end
--- Make the GROUND Controllable to drive towards a specific point using (only) roads.
-- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param #number Speed (optional) Speed in km/h. The default speed is 999 km/h.
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteGroundOnRoad( ToCoordinate, Speed, DelaySeconds )
-- Current coordinate.
local FromCoordinate = self:GetCoordinate()
-- Formation is set to on road.
local Formation="On Road"
-- Path on road from current position to destination coordinate.
local path=FromCoordinate:GetPathOnRoad(ToCoordinate)
-- Route, ground waypoints along roads.
local route={}
table.insert(route, FromCoordinate:WaypointGround(Speed, Formation))
-- Convert coordinates to ground waypoints and insert into table.
for _, coord in ipairs(path) do
table.insert(route, coord:WaypointGround(Speed, Formation))
end
-- Add the final coordinate because the final coordinate in path is last point on road.
local dist=ToCoordinate:Get2DDistance(path[#path])
if dist>10 then
table.insert(route, ToCoordinate:WaypointGround(Speed, "Vee"))
end
-- Route controllable to destination.
self:Route(route, DelaySeconds)
return self
end
--- Make the AIR Controllable fly towards a specific point.
-- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param Core.Point#COORDINATE.RoutePointAltType AltType The altitude type.
-- @param Core.Point#COORDINATE.RoutePointType Type The route point type.
-- @param Core.Point#COORDINATE.RoutePointAction Action The route point action.
-- @param #number Speed (optional) Speed in km/h. The default speed is 999 km/h.
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteAirTo( ToCoordinate, AltType, Type, Action, Speed, DelaySeconds )
local FromCoordinate = self:GetCoordinate()
local FromWP = FromCoordinate:WaypointAir()
local ToWP = ToCoordinate:WaypointAir( AltType, Type, Action, Speed )
self:Route( { FromWP, ToWP }, DelaySeconds )
return self
end
--- (AIR + GROUND) Route the controllable to a given zone.
-- The controllable final destination point can be randomized.
-- A speed can be given in km/h.
-- A given formation can be given.
-- @param #CONTROLLABLE self
-- @param Core.Zone#ZONE Zone The zone where to route to.
-- @param #boolean Randomize Defines whether to target point gets randomized within the Zone.
-- @param #number Speed The speed.
-- @param Base#FORMATION Formation The formation string.
function CONTROLLABLE:TaskRouteToZone( Zone, Randomize, Speed, Formation )
self:F2( Zone )
local DCSControllable = self:GetDCSObject()
if DCSControllable then
local ControllablePoint = self:GetVec2()
local PointFrom = {} local PointFrom = {}
PointFrom.x = ControllablePoint.x PointFrom.x = ControllablePoint.x
PointFrom.y = ControllablePoint.y PointFrom.y = ControllablePoint.y
PointFrom.type = "Turning Point" PointFrom.type = "Turning Point"
PointFrom.action = Formation or "Cone" PointFrom.action = "Turning Point"
PointFrom.speed = 20 / 1.6 PointFrom.speed = Speed
PointFrom.speed_locked = true
PointFrom.properties = {
["vnav"] = 1,
["scale"] = 0,
["angle"] = 0,
["vangle"] = 0,
["steer"] = 2,
}
local PointTo = {} local PointTo = {}
local ZonePoint PointTo.x = Point.x
PointTo.y = Point.y
if Randomize then
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetVec2()
end
PointTo.x = ZonePoint.x
PointTo.y = ZonePoint.y
PointTo.type = "Turning Point" PointTo.type = "Turning Point"
PointTo.action = "Fly Over Point"
if Formation then PointTo.speed = Speed
PointTo.action = Formation PointTo.speed_locked = true
else PointTo.properties = {
PointTo.action = "Cone" ["vnav"] = 1,
end ["scale"] = 0,
["angle"] = 0,
if Speed then ["vangle"] = 0,
PointTo.speed = Speed ["steer"] = 2,
else }
PointTo.speed = 20 / 1.6
end
local Points = { PointFrom, PointTo } local Points = { PointFrom, PointTo }
self:T3( Points ) self:T3( Points )
self:Route( Points ) self:Route( Points )
return self return self
end end
return nil --- (AIR + GROUND) Make the Controllable move to a given point.
end -- @param #CONTROLLABLE self
-- @param Dcs.DCSTypes#Vec3 Point The destination point in Vec3 format.
--- (GROUND) Route the controllable to a given Vec2. -- @param #number Speed The speed to travel.
-- A speed can be given in km/h. -- @return #CONTROLLABLE self
-- A given formation can be given. function CONTROLLABLE:RouteToVec3( Point, Speed )
-- @param #CONTROLLABLE self self:F2( { Point, Speed } )
-- @param #Vec2 Vec2 The Vec2 where to route to.
-- @param #number Speed The speed. local ControllableVec3 = self:GetUnit( 1 ):GetVec3()
-- @param Base#FORMATION Formation The formation string.
function CONTROLLABLE:TaskRouteToVec2( Vec2, Speed, Formation )
local DCSControllable = self:GetDCSObject()
if DCSControllable then
local ControllablePoint = self:GetVec2()
local PointFrom = {} local PointFrom = {}
PointFrom.x = ControllablePoint.x PointFrom.x = ControllableVec3.x
PointFrom.y = ControllablePoint.y PointFrom.y = ControllableVec3.z
PointFrom.alt = ControllableVec3.y
PointFrom.alt_type = "BARO"
PointFrom.type = "Turning Point" PointFrom.type = "Turning Point"
PointFrom.action = Formation or "Cone" PointFrom.action = "Turning Point"
PointFrom.speed = 20 / 1.6 PointFrom.speed = Speed
PointFrom.speed_locked = true
PointFrom.properties = {
["vnav"] = 1,
["scale"] = 0,
["angle"] = 0,
["vangle"] = 0,
["steer"] = 2,
}
local PointTo = {} local PointTo = {}
PointTo.x = Point.x
PointTo.x = Vec2.x PointTo.y = Point.z
PointTo.y = Vec2.y PointTo.alt = Point.y
PointTo.alt_type = "BARO"
PointTo.type = "Turning Point" PointTo.type = "Turning Point"
PointTo.action = "Fly Over Point"
if Formation then PointTo.speed = Speed
PointTo.action = Formation PointTo.speed_locked = true
else PointTo.properties = {
PointTo.action = "Cone" ["vnav"] = 1,
end ["scale"] = 0,
["angle"] = 0,
if Speed then ["vangle"] = 0,
PointTo.speed = Speed ["steer"] = 2,
else }
PointTo.speed = 60 / 3.6
end
local Points = { PointFrom, PointTo } local Points = { PointFrom, PointTo }
self:T3( Points ) self:T3( Points )
self:Route( Points ) self:Route( Points )
return self return self
end end
--- Make the controllable to follow a given route.
-- @param #CONTROLLABLE self
-- @param #table Route A table of Route Points.
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:Route( Route, DelaySeconds )
self:F2( Route )
local DCSControllable = self:GetDCSObject()
if DCSControllable then
local RouteTask = self:TaskRoute( Route ) -- Create a RouteTask, that will route the CONTROLLABLE to the Route.
self:SetTask( RouteTask, DelaySeconds or 1 ) -- Execute the RouteTask after the specified seconds (default is 1).
return self
end
return nil
end
--- Stops the movement of the vehicle on the route.
-- @param #CONTROLLABLE self
-- @return #CONTROLLABLE
function CONTROLLABLE:RouteStop()
self:F("RouteStop")
local CommandStop = self:CommandStopRoute( true )
self:SetCommand( CommandStop )
end
--- Resumes the movement of the vehicle on the route.
-- @param #CONTROLLABLE self
-- @return #CONTROLLABLE
function CONTROLLABLE:RouteResume()
self:F("RouteResume")
local CommandResume = self:CommandStopRoute( false )
self:SetCommand( CommandResume )
end
--- Make the GROUND Controllable to drive towards a specific point.
-- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param #number Speed (optional) Speed in km/h. The default speed is 999 km/h.
-- @param #string Formation (optional) The route point Formation, which is a text string that specifies exactly the Text in the Type of the route point, like "Vee", "Echelon Right".
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteGroundTo( ToCoordinate, Speed, Formation, DelaySeconds )
local FromCoordinate = self:GetCoordinate()
local FromWP = FromCoordinate:WaypointGround()
local ToWP = ToCoordinate:WaypointGround( Speed, Formation )
self:Route( { FromWP, ToWP }, DelaySeconds )
return self
end
--- Make the GROUND Controllable to drive towards a specific point using (only) roads.
-- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param #number Speed (optional) Speed in km/h. The default speed is 999 km/h.
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteGroundOnRoad( ToCoordinate, Speed, DelaySeconds )
-- Current coordinate.
local FromCoordinate = self:GetCoordinate()
-- Formation is set to on road.
local Formation="On Road"
-- Path on road from current position to destination coordinate.
local path=FromCoordinate:GetPathOnRoad(ToCoordinate)
-- Route, ground waypoints along roads.
local route={}
table.insert(route, FromCoordinate:WaypointGround(Speed, Formation))
-- Convert coordinates to ground waypoints and insert into table.
for _, coord in ipairs(path) do
table.insert(route, coord:WaypointGround(Speed, Formation))
end
-- Add the final coordinate because the final coordinate in path is last point on road.
local dist=ToCoordinate:Get2DDistance(path[#path])
if dist>10 then
table.insert(route, ToCoordinate:WaypointGround(Speed, "Vee"))
end
-- Route controllable to destination.
self:Route(route, DelaySeconds)
return self
end
--- Make the AIR Controllable fly towards a specific point.
-- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param Core.Point#COORDINATE.RoutePointAltType AltType The altitude type.
-- @param Core.Point#COORDINATE.RoutePointType Type The route point type.
-- @param Core.Point#COORDINATE.RoutePointAction Action The route point action.
-- @param #number Speed (optional) Speed in km/h. The default speed is 999 km/h.
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteAirTo( ToCoordinate, AltType, Type, Action, Speed, DelaySeconds )
local FromCoordinate = self:GetCoordinate()
local FromWP = FromCoordinate:WaypointAir()
local ToWP = ToCoordinate:WaypointAir( AltType, Type, Action, Speed )
self:Route( { FromWP, ToWP }, DelaySeconds )
return self
end
--- (AIR + GROUND) Route the controllable to a given zone.
-- The controllable final destination point can be randomized.
-- A speed can be given in km/h.
-- A given formation can be given.
-- @param #CONTROLLABLE self
-- @param Core.Zone#ZONE Zone The zone where to route to.
-- @param #boolean Randomize Defines whether to target point gets randomized within the Zone.
-- @param #number Speed The speed.
-- @param Base#FORMATION Formation The formation string.
function CONTROLLABLE:TaskRouteToZone( Zone, Randomize, Speed, Formation )
self:F2( Zone )
local DCSControllable = self:GetDCSObject()
if DCSControllable then
local ControllablePoint = self:GetVec2()
local PointFrom = {}
PointFrom.x = ControllablePoint.x
PointFrom.y = ControllablePoint.y
PointFrom.type = "Turning Point"
PointFrom.action = Formation or "Cone"
PointFrom.speed = 20 / 1.6
local PointTo = {}
local ZonePoint
if Randomize then
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetVec2()
end
PointTo.x = ZonePoint.x
PointTo.y = ZonePoint.y
PointTo.type = "Turning Point"
if Formation then
PointTo.action = Formation
else
PointTo.action = "Cone"
end
if Speed then
PointTo.speed = Speed
else
PointTo.speed = 20 / 1.6
end
local Points = { PointFrom, PointTo }
self:T3( Points )
self:Route( Points )
return self
end
return nil
end
--- (GROUND) Route the controllable to a given Vec2.
-- A speed can be given in km/h.
-- A given formation can be given.
-- @param #CONTROLLABLE self
-- @param #Vec2 Vec2 The Vec2 where to route to.
-- @param #number Speed The speed.
-- @param Base#FORMATION Formation The formation string.
function CONTROLLABLE:TaskRouteToVec2( Vec2, Speed, Formation )
local DCSControllable = self:GetDCSObject()
if DCSControllable then
local ControllablePoint = self:GetVec2()
local PointFrom = {}
PointFrom.x = ControllablePoint.x
PointFrom.y = ControllablePoint.y
PointFrom.type = "Turning Point"
PointFrom.action = Formation or "Cone"
PointFrom.speed = 20 / 1.6
local PointTo = {}
PointTo.x = Vec2.x
PointTo.y = Vec2.y
PointTo.type = "Turning Point"
if Formation then
PointTo.action = Formation
else
PointTo.action = "Cone"
end
if Speed then
PointTo.speed = Speed
else
PointTo.speed = 60 / 3.6
end
local Points = { PointFrom, PointTo }
self:T3( Points )
self:Route( Points )
return self
end
return nil
end
return nil end -- Route methods
end
-- Commands -- Commands