mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Cargo Troops
This commit is contained in:
parent
cce90b1f46
commit
e7518d69e6
@ -8,8 +8,8 @@
|
||||
--
|
||||
-- @module AI_Cargo_Troops
|
||||
|
||||
--- @type AI_Cargo_Troops
|
||||
-- @extends Core.Base#BASE
|
||||
--- @type AI_CARGO_TROOPS
|
||||
-- @extends Core.Fsm#FSM_CONTROLLABLE
|
||||
|
||||
|
||||
--- # AI\_CARGO\_TROOPS class, extends @{Core.Base@BASE}
|
||||
@ -19,6 +19,7 @@
|
||||
-- @field #AI_CARGO_TROOPS
|
||||
AI_CARGO_TROOPS = {
|
||||
ClassName = "AI_CARGO_TROOPS",
|
||||
Coordinate = nil -- Core.Point#COORDINATE,
|
||||
}
|
||||
|
||||
--- Creates a new AI_CARGO_TROOPS object
|
||||
@ -32,6 +33,9 @@ function AI_CARGO_TROOPS:New( CargoCarrier, CargoGroup, CombatRadius )
|
||||
self.CargoGroup = CargoGroup -- Core.Cargo#CARGO_GROUP
|
||||
self.CombatRadius = CombatRadius
|
||||
|
||||
self.Zone = ZONE_UNIT:New( self.CargoCarrier:GetName() .. "-Zone", self.CargoCarrier, CombatRadius )
|
||||
self.Coalition = self.CargoCarrier:GetCoalition()
|
||||
|
||||
self:SetControllable( self.CargoCarrier )
|
||||
|
||||
self:SetStartState( "UnLoaded" )
|
||||
@ -57,6 +61,22 @@ function AI_CARGO_TROOPS:onafterMonitor( CargoCarrier, From, Event, To )
|
||||
self:F( { CargoCarrier, From, Event, To } )
|
||||
|
||||
if CargoCarrier and CargoCarrier:IsAlive() then
|
||||
if self.Coordinate then
|
||||
local Coordinate = CargoCarrier:GetCoordinate()
|
||||
if Coordinate:IsAtCoordinate2D( self.Coordinate, 2 ) then
|
||||
self.Zone:Scan( { Object.Category.UNIT } )
|
||||
if self.Zone:IsAllInZoneOfCoalition( self.Coalition ) then
|
||||
else
|
||||
if not self:Is( "Unloaded" ) then
|
||||
-- There are enemies within combat range. Unload the CargoCarrier.
|
||||
self:__Unload( 1 )
|
||||
self.CargoCarrier:RouteStop()
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
self.Coordinate = CargoCarrier:GetCoordinate()
|
||||
end
|
||||
end
|
||||
|
||||
self:__Monitor( 1 )
|
||||
@ -99,6 +119,7 @@ function AI_CARGO_TROOPS:onafterLoaded( CargoCarrier, From, Event, To )
|
||||
self:F( { CargoCarrier, From, Event, To } )
|
||||
|
||||
if CargoCarrier and CargoCarrier:IsAlive() then
|
||||
CargoCarrier:RouteStop()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -192,6 +192,20 @@ do -- COORDINATE
|
||||
return self
|
||||
end
|
||||
|
||||
--- COORDINATE constructor.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #COORDINATE Coordinate.
|
||||
-- @return #COORDINATE
|
||||
function COORDINATE:NewFromCoordinate( Coordinate )
|
||||
|
||||
local self = BASE:Inherit( self, BASE:New() ) -- #COORDINATE
|
||||
self.x = Coordinate.x
|
||||
self.y = Coordinate.y
|
||||
self.z = Coordinate.z
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create a new COORDINATE object from Vec2 coordinates.
|
||||
-- @param #COORDINATE self
|
||||
-- @param Dcs.DCSTypes#Vec2 Vec2 The Vec2 point.
|
||||
@ -241,6 +255,20 @@ do -- COORDINATE
|
||||
return { x = self.x, y = self.z }
|
||||
end
|
||||
|
||||
|
||||
--- Returns if the 2 coordinates are at the same 2D position.
|
||||
-- @param #COORDINATE self
|
||||
-- @return #boolean true if at the same position.
|
||||
function COORDINATE:IsAtCoordinate2D( Coordinate, Precision )
|
||||
|
||||
local x = Coordinate.x
|
||||
local z = Coordinate.z
|
||||
|
||||
return x - Precision <= self.x and x + Precision >= self.x and z - Precision <= self.z and z + Precision >= self.z
|
||||
end
|
||||
|
||||
|
||||
|
||||
--TODO: check this to replace
|
||||
--- Calculate the distance from a reference @{DCSTypes#Vec2}.
|
||||
-- @param #COORDINATE self
|
||||
|
||||
@ -1908,6 +1908,28 @@ function CONTROLLABLE:Route( Route, DelaySeconds )
|
||||
end
|
||||
|
||||
|
||||
--- Stops the movement of the vehicle on the route.
|
||||
-- @param #CONTROLLABLE self
|
||||
-- @return #CONTROLLABLE
|
||||
function CONTROLLABLE:RouteStop()
|
||||
self:F2()
|
||||
|
||||
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:F2()
|
||||
|
||||
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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user