mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Progress on AI_CARGO_TROOPS
This commit is contained in:
parent
718138abd6
commit
a247f56c7e
@ -24,20 +24,17 @@ AI_CARGO_TROOPS = {
|
|||||||
|
|
||||||
--- Creates a new AI_CARGO_TROOPS object.
|
--- Creates a new AI_CARGO_TROOPS object.
|
||||||
-- @param #AI_CARGO_TROOPS self
|
-- @param #AI_CARGO_TROOPS self
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param Cargo.CargoGroup#CARGO_GROUP CargoGroup
|
||||||
|
-- @param #number CombatRadius
|
||||||
-- @return #AI_CARGO_TROOPS
|
-- @return #AI_CARGO_TROOPS
|
||||||
function AI_CARGO_TROOPS:New( CargoCarrier, CargoGroup, CombatRadius )
|
function AI_CARGO_TROOPS:New( CargoCarrier, CargoGroup, CombatRadius )
|
||||||
|
|
||||||
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New( ) ) -- #AI_CARGO_TROOPS
|
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New( ) ) -- #AI_CARGO_TROOPS
|
||||||
|
|
||||||
self.CargoCarrier = CargoCarrier -- Wrapper.Unit#UNIT
|
self.CargoGroup = CargoGroup -- Cargo.CargoGroup#CARGO_GROUP
|
||||||
self.CargoGroup = CargoGroup -- Core.Cargo#CARGO_GROUP
|
|
||||||
self.CombatRadius = CombatRadius
|
self.CombatRadius = CombatRadius
|
||||||
|
|
||||||
self.Zone = ZONE_UNIT:New( self.CargoCarrier:GetName() .. "-Zone", self.CargoCarrier, CombatRadius )
|
|
||||||
self.Coalition = self.CargoCarrier:GetCoalition()
|
|
||||||
|
|
||||||
self:SetControllable( CargoCarrier )
|
|
||||||
|
|
||||||
self:SetStartState( "UnLoaded" )
|
self:SetStartState( "UnLoaded" )
|
||||||
|
|
||||||
self:AddTransition( "*", "Load", "Boarding" )
|
self:AddTransition( "*", "Load", "Boarding" )
|
||||||
@ -51,13 +48,90 @@ function AI_CARGO_TROOPS:New( CargoCarrier, CargoGroup, CombatRadius )
|
|||||||
self:AddTransition( "*", "Follow", "Following" )
|
self:AddTransition( "*", "Follow", "Following" )
|
||||||
self:AddTransition( "*", "Guard", "Guarding" )
|
self:AddTransition( "*", "Guard", "Guarding" )
|
||||||
|
|
||||||
|
self:AddTransition( "*", "Destroyed", "Destroyed" )
|
||||||
|
|
||||||
self:__Monitor( 1 )
|
self:__Monitor( 1 )
|
||||||
self:__Load( 1 )
|
|
||||||
|
self:SetCarrier( CargoCarrier )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Set the Carrier.
|
||||||
|
-- @param #AI_CARGO_TROOPS self
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @return #AI_CARGO_TROOPS
|
||||||
|
function AI_CARGO_TROOPS:SetCarrier( CargoCarrier )
|
||||||
|
|
||||||
|
self.CargoCarrier = CargoCarrier -- Wrapper.Unit#UNIT
|
||||||
|
self.CargoCarrier:SetState( self.CargoCarrier, "AI_CARGO_TROOPS", self )
|
||||||
|
|
||||||
|
CargoCarrier:HandleEvent( EVENTS.Dead )
|
||||||
|
CargoCarrier:HandleEvent( EVENTS.Hit )
|
||||||
|
|
||||||
|
function CargoCarrier:OnEventDead( EventData )
|
||||||
|
self:F({"dead"})
|
||||||
|
local AICargoTroops = self:GetState( self, "AI_CARGO_TROOPS" )
|
||||||
|
self:F({AICargoTroops=AICargoTroops})
|
||||||
|
if AICargoTroops then
|
||||||
|
self:F({})
|
||||||
|
if not AICargoTroops:Is( "Loaded" ) then
|
||||||
|
-- There are enemies within combat range. Unload the CargoCarrier.
|
||||||
|
AICargoTroops:Destroyed()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function CargoCarrier:OnEventHit( EventData )
|
||||||
|
self:F({"hit"})
|
||||||
|
local AICargoTroops = self:GetState( self, "AI_CARGO_TROOPS" )
|
||||||
|
if AICargoTroops then
|
||||||
|
self:F( { OnHitLoaded = AICargoTroops:Is( "Loaded" ) } )
|
||||||
|
if AICargoTroops:Is( "Loaded" ) or AICargoTroops:Is( "Boarding" ) then
|
||||||
|
-- There are enemies within combat range. Unload the CargoCarrier.
|
||||||
|
AICargoTroops:Unload()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.Zone = ZONE_UNIT:New( self.CargoCarrier:GetName() .. "-Zone", self.CargoCarrier, self.CombatRadius )
|
||||||
|
self.Coalition = self.CargoCarrier:GetCoalition()
|
||||||
|
|
||||||
|
self:SetControllable( CargoCarrier )
|
||||||
|
|
||||||
|
self:Guard()
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Find a free Carrier within a range.
|
||||||
|
-- @param #AI_CARGO_TROOPS self
|
||||||
|
-- @param Core.Point#COORDINATE Coordinate
|
||||||
|
-- @param #number Radius
|
||||||
|
-- @return Wrapper.Unit#UNIT NewCarrier
|
||||||
|
function AI_CARGO_TROOPS:FindCarrier( Coordinate, Radius )
|
||||||
|
|
||||||
|
local CoordinateZone = ZONE_RADIUS:New( "Zone" , Coordinate:GetVec2(), Radius )
|
||||||
|
CoordinateZone:Scan( { Object.Category.UNIT } )
|
||||||
|
for _, DCSUnit in pairs( CoordinateZone:GetScannedUnits() ) do
|
||||||
|
local NearUnit = UNIT:Find( DCSUnit )
|
||||||
|
self:F({NearUnit=NearUnit})
|
||||||
|
if not NearUnit:GetState( NearUnit, "AI_CARGO_TROOPS" ) then
|
||||||
|
local Attributes = NearUnit:GetDesc()
|
||||||
|
self:F({Desc=Attributes})
|
||||||
|
if NearUnit:HasAttribute( "Trucks" ) then
|
||||||
|
self:SetCarrier( NearUnit )
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Follow Infantry to the Carrier.
|
--- Follow Infantry to the Carrier.
|
||||||
-- @param #AI_CARGO_TROOPS self
|
-- @param #AI_CARGO_TROOPS self
|
||||||
-- @param #AI_CARGO_TROOPS Me
|
-- @param #AI_CARGO_TROOPS Me
|
||||||
@ -68,6 +142,9 @@ function AI_CARGO_TROOPS:FollowToCarrier( Me, CargoCarrier, InfantryGroup )
|
|||||||
|
|
||||||
self:F( { self = self:GetClassNameAndID(), InfantryGroup = InfantryGroup:GetName() } )
|
self:F( { self = self:GetClassNameAndID(), InfantryGroup = InfantryGroup:GetName() } )
|
||||||
|
|
||||||
|
--if self:Is( "Following" ) then
|
||||||
|
|
||||||
|
if CargoCarrier:IsAlive() then
|
||||||
-- We check if the Cargo is near to the CargoCarrier.
|
-- We check if the Cargo is near to the CargoCarrier.
|
||||||
if InfantryGroup:IsPartlyInZone( ZONE_UNIT:New( "Radius", CargoCarrier, 5 ) ) then
|
if InfantryGroup:IsPartlyInZone( ZONE_UNIT:New( "Radius", CargoCarrier, 5 ) ) then
|
||||||
|
|
||||||
@ -90,7 +167,7 @@ function AI_CARGO_TROOPS:FollowToCarrier( Me, CargoCarrier, InfantryGroup )
|
|||||||
self:F({FromGround=FromGround})
|
self:F({FromGround=FromGround})
|
||||||
table.insert( Waypoints, FromGround )
|
table.insert( Waypoints, FromGround )
|
||||||
|
|
||||||
local ToCoord = CargoCarrier:GetCoordinate()
|
local ToCoord = CargoCarrier:GetCoordinate():GetRandomCoordinateInRadius( 10, 5 )
|
||||||
local ToGround = ToCoord:WaypointGround( 10, "Diamond" )
|
local ToGround = ToCoord:WaypointGround( 10, "Diamond" )
|
||||||
self:F({ToGround=ToGround})
|
self:F({ToGround=ToGround})
|
||||||
table.insert( Waypoints, ToGround )
|
table.insert( Waypoints, ToGround )
|
||||||
@ -105,6 +182,7 @@ function AI_CARGO_TROOPS:FollowToCarrier( Me, CargoCarrier, InfantryGroup )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- @param #AI_CARGO_TROOPS self
|
--- @param #AI_CARGO_TROOPS self
|
||||||
@ -132,6 +210,22 @@ function AI_CARGO_TROOPS:onafterMonitor( CargoCarrier, From, Event, To )
|
|||||||
self:Follow()
|
self:Follow()
|
||||||
end
|
end
|
||||||
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
|
||||||
|
if self.CarrierStopped then
|
||||||
|
if self.CargoGroup:IsNear( CargoCarrier, 10 ) then
|
||||||
|
CargoCarrier:RouteResume()
|
||||||
|
self.CarrierStopped = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
self.CarrierCoordinate = CargoCarrier:GetCoordinate()
|
self.CarrierCoordinate = CargoCarrier:GetCoordinate()
|
||||||
end
|
end
|
||||||
@ -149,7 +243,7 @@ function AI_CARGO_TROOPS:onafterLoad( CargoCarrier, From, Event, To )
|
|||||||
if CargoCarrier and CargoCarrier:IsAlive() then
|
if CargoCarrier and CargoCarrier:IsAlive() then
|
||||||
CargoCarrier:RouteStop()
|
CargoCarrier:RouteStop()
|
||||||
self:__Board( 10 )
|
self:__Board( 10 )
|
||||||
self.CargoGroup:Board( CargoCarrier, 100 )
|
self.CargoGroup:Board( CargoCarrier, 10 )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -325,7 +325,7 @@ do -- CARGO
|
|||||||
-- @param #CARGO self
|
-- @param #CARGO self
|
||||||
function CARGO:Destroy()
|
function CARGO:Destroy()
|
||||||
if self.CargoObject then
|
if self.CargoObject then
|
||||||
self.CargoObject:Destroy()
|
self.CargoObject:Destroy( false )
|
||||||
end
|
end
|
||||||
self:Destroyed()
|
self:Destroyed()
|
||||||
end
|
end
|
||||||
@ -576,21 +576,23 @@ do -- CARGO
|
|||||||
-- @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( PointVec2, NearRadius )
|
||||||
self:F( { PointVec2 = PointVec2, NearRadius = NearRadius } )
|
self:F2( { PointVec2 = PointVec2, NearRadius = NearRadius } )
|
||||||
|
|
||||||
if self.CargoObject:IsAlive() then
|
if self.CargoObject:IsAlive() then
|
||||||
--local Distance = PointVec2:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
|
--local Distance = PointVec2:DistanceFromPointVec2( 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 = PointVec2:Get2DDistance( self.CargoObject:GetPointVec2() )
|
||||||
self:T( Distance )
|
--self:F( Distance )
|
||||||
|
|
||||||
if Distance <= NearRadius then
|
if Distance <= NearRadius then
|
||||||
|
self:F( { PointVec2 = PointVec2, NearRadius = NearRadius, IsNear = true } )
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:F( { PointVec2 = PointVec2, NearRadius = NearRadius, IsNear = false } )
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ do -- CARGO_UNIT
|
|||||||
|
|
||||||
--- Models CARGO in the form of units, which can be boarded, unboarded, loaded, unloaded.
|
--- Models CARGO in the form of units, which can be boarded, unboarded, loaded, unloaded.
|
||||||
-- @type CARGO_UNIT
|
-- @type CARGO_UNIT
|
||||||
-- @extends #CARGO_REPRESENTABLE
|
-- @extends Cargo.Cargo#CARGO_REPRESENTABLE
|
||||||
|
|
||||||
--- # CARGO\_UNIT class, extends @{#CARGO_REPRESENTABLE}
|
--- # CARGO\_UNIT class, extends @{#CARGO_REPRESENTABLE}
|
||||||
--
|
--
|
||||||
@ -83,6 +83,8 @@ do -- CARGO_UNIT
|
|||||||
|
|
||||||
local CargoCarrier = self.CargoCarrier -- Wrapper.Controllable#CONTROLLABLE
|
local CargoCarrier = self.CargoCarrier -- Wrapper.Controllable#CONTROLLABLE
|
||||||
|
|
||||||
|
if CargoCarrier:IsAlive() then
|
||||||
|
|
||||||
local CargoCarrierPointVec2 = CargoCarrier:GetPointVec2()
|
local CargoCarrierPointVec2 = CargoCarrier:GetPointVec2()
|
||||||
local CargoCarrierHeading = self.CargoCarrier:GetHeading() -- Get Heading of object in degrees.
|
local CargoCarrierHeading = self.CargoCarrier:GetHeading() -- Get Heading of object in degrees.
|
||||||
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
||||||
@ -119,6 +121,10 @@ do -- CARGO_UNIT
|
|||||||
|
|
||||||
self:__UnBoarding( 1, ToPointVec2, NearRadius )
|
self:__UnBoarding( 1, ToPointVec2, NearRadius )
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- the Carrier is dead. This cargo is dead too!
|
||||||
|
self:Destroyed()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -603,6 +603,7 @@ function ZONE_RADIUS:Scan( ObjectCategories )
|
|||||||
self.ScanData = {}
|
self.ScanData = {}
|
||||||
self.ScanData.Coalitions = {}
|
self.ScanData.Coalitions = {}
|
||||||
self.ScanData.Scenery = {}
|
self.ScanData.Scenery = {}
|
||||||
|
self.ScanData.Units = {}
|
||||||
|
|
||||||
local ZoneCoord = self:GetCoordinate()
|
local ZoneCoord = self:GetCoordinate()
|
||||||
local ZoneRadius = self:GetRadius()
|
local ZoneRadius = self:GetRadius()
|
||||||
@ -625,6 +626,7 @@ function ZONE_RADIUS:Scan( ObjectCategories )
|
|||||||
(ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then
|
(ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then
|
||||||
local CoalitionDCSUnit = ZoneObject:getCoalition()
|
local CoalitionDCSUnit = ZoneObject:getCoalition()
|
||||||
self.ScanData.Coalitions[CoalitionDCSUnit] = true
|
self.ScanData.Coalitions[CoalitionDCSUnit] = true
|
||||||
|
self.ScanData.Units[ZoneObject] = ZoneObject
|
||||||
self:F( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } )
|
self:F( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } )
|
||||||
end
|
end
|
||||||
if ObjectCategory == Object.Category.SCENERY then
|
if ObjectCategory == Object.Category.SCENERY then
|
||||||
@ -643,6 +645,12 @@ function ZONE_RADIUS:Scan( ObjectCategories )
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function ZONE_RADIUS:GetScannedUnits()
|
||||||
|
|
||||||
|
return self.ScanData.Units
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function ZONE_RADIUS:CountScannedCoalitions()
|
function ZONE_RADIUS:CountScannedCoalitions()
|
||||||
|
|
||||||
local Count = 0
|
local Count = 0
|
||||||
|
|||||||
@ -239,15 +239,18 @@ end
|
|||||||
-- Note that this destroy method also raises a destroy event at run-time.
|
-- Note that this destroy method also raises a destroy event at run-time.
|
||||||
-- So all event listeners will catch the destroy event of this DCS Group.
|
-- So all event listeners will catch the destroy event of this DCS Group.
|
||||||
-- @param #GROUP self
|
-- @param #GROUP self
|
||||||
function GROUP:Destroy()
|
-- @param #boolean GenerateEvent
|
||||||
|
function GROUP:Destroy( GenerateEvent )
|
||||||
self:F2( self.GroupName )
|
self:F2( self.GroupName )
|
||||||
|
|
||||||
local DCSGroup = self:GetDCSObject()
|
local DCSGroup = self:GetDCSObject()
|
||||||
|
|
||||||
if DCSGroup then
|
if DCSGroup then
|
||||||
|
if not GenerateEvent then
|
||||||
for Index, UnitData in pairs( DCSGroup:getUnits() ) do
|
for Index, UnitData in pairs( DCSGroup:getUnits() ) do
|
||||||
self:CreateEventCrash( timer.getTime(), UnitData )
|
self:CreateEventCrash( timer.getTime(), UnitData )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
USERFLAG:New( self:GetName() ):Set( 100 )
|
USERFLAG:New( self:GetName() ):Set( 100 )
|
||||||
DCSGroup:destroy()
|
DCSGroup:destroy()
|
||||||
DCSGroup = nil
|
DCSGroup = nil
|
||||||
|
|||||||
@ -229,6 +229,26 @@ function IDENTIFIABLE:GetDesc()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if the Object has the attribute.
|
||||||
|
-- @param #IDENTIFIABLE self
|
||||||
|
-- @param #string AttributeName The attribute name.
|
||||||
|
-- @return #boolean true if the attribute exists.
|
||||||
|
-- @return #nil The DCS Identifiable is not existing or alive.
|
||||||
|
function IDENTIFIABLE:HasAttribute( AttributeName )
|
||||||
|
self:F2( self.IdentifiableName )
|
||||||
|
|
||||||
|
local DCSIdentifiable = self:GetDCSObject()
|
||||||
|
|
||||||
|
if DCSIdentifiable then
|
||||||
|
local IdentifiableHasAttribute = DCSIdentifiable:hasAttribute( AttributeName )
|
||||||
|
self:T2( IdentifiableHasAttribute )
|
||||||
|
return IdentifiableHasAttribute
|
||||||
|
end
|
||||||
|
|
||||||
|
self:F( self.ClassName .. " " .. self.IdentifiableName .. " not found!" )
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Gets the CallSign of the IDENTIFIABLE, which is a blank by default.
|
--- Gets the CallSign of the IDENTIFIABLE, which is a blank by default.
|
||||||
-- @param #IDENTIFIABLE self
|
-- @param #IDENTIFIABLE self
|
||||||
-- @return #string The CallSign of the IDENTIFIABLE.
|
-- @return #string The CallSign of the IDENTIFIABLE.
|
||||||
|
|||||||
@ -91,3 +91,5 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user