mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
First working prototype of AI_CARGO_TROOPS.
This commit is contained in:
parent
b6fc46fdd0
commit
727d64927b
@ -48,6 +48,8 @@ function AI_CARGO_TROOPS:New( CargoCarrier, CargoGroup, CombatRadius )
|
|||||||
self:AddTransition( "Unboarding", "Unloaded", "Unloaded" )
|
self:AddTransition( "Unboarding", "Unloaded", "Unloaded" )
|
||||||
|
|
||||||
self:AddTransition( "*", "Monitor", "*" )
|
self:AddTransition( "*", "Monitor", "*" )
|
||||||
|
self:AddTransition( "*", "Follow", "Following" )
|
||||||
|
self:AddTransition( "*", "Guard", "Guarding" )
|
||||||
|
|
||||||
self:__Monitor( 1 )
|
self:__Monitor( 1 )
|
||||||
self:__Load( 1 )
|
self:__Load( 1 )
|
||||||
@ -56,38 +58,94 @@ function AI_CARGO_TROOPS:New( CargoCarrier, CargoGroup, CombatRadius )
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Follow Infantry to the Carrier.
|
||||||
|
-- @param #AI_CARGO_TROOPS self
|
||||||
|
-- @return #AI_CARGO_TROOPS
|
||||||
|
function AI_CARGO_TROOPS:FollowToCarrier( Me )
|
||||||
|
|
||||||
|
self = Me
|
||||||
|
|
||||||
|
self:F( { self = self:GetClassNameAndID(), CargoGroup = self.CargoGroup:GetName() } )
|
||||||
|
|
||||||
|
-- We check if the Cargo is near to the CargoCarrier.
|
||||||
|
if self.CargoGroup:IsNear( self.CargoCarrier, 5 ) then
|
||||||
|
|
||||||
|
-- The Cargo does not need to follow the Carrier.
|
||||||
|
self:Guard()
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
-- The Cargo needs to continue to follow the Carrier.
|
||||||
|
if self:Is( "Following" ) then
|
||||||
|
|
||||||
|
-- For each Cargo object within the CARGO_GROUPED, route each object to the CargoLoadPointVec2
|
||||||
|
self.CargoGroup.CargoSet:ForEach(
|
||||||
|
--- @param Core.Cargo#CARGO Cargo
|
||||||
|
function( Cargo )
|
||||||
|
local CargoUnit = Cargo.CargoObject -- Wrapper.Unit#UNIT
|
||||||
|
self:F( { UnitName = CargoUnit:GetName() } )
|
||||||
|
|
||||||
|
if CargoUnit:IsAlive() then
|
||||||
|
|
||||||
|
local InfantryGroup = CargoUnit:GetGroup()
|
||||||
|
self:F( { GroupName = InfantryGroup:GetName() } )
|
||||||
|
|
||||||
|
local Waypoints = {}
|
||||||
|
|
||||||
|
-- Calculate the new Route.
|
||||||
|
local FromCoord = InfantryGroup:GetCoordinate()
|
||||||
|
local FromGround = FromCoord:WaypointGround( 10, "Diamond" )
|
||||||
|
table.insert( Waypoints, FromGround )
|
||||||
|
|
||||||
|
local ToCoord = self.CargoCarrier:GetCoordinate()
|
||||||
|
local ToGround = ToCoord:WaypointGround( 10, "Diamond" )
|
||||||
|
table.insert( Waypoints, ToGround )
|
||||||
|
|
||||||
|
local TaskRoute = InfantryGroup:TaskFunction( "AI_CARGO_TROOPS.FollowToCarrier", self )
|
||||||
|
|
||||||
|
self:F({Waypoints = Waypoints})
|
||||||
|
local Waypoint = Waypoints[#Waypoints]
|
||||||
|
InfantryGroup:SetTaskWaypoint( Waypoint, TaskRoute ) -- Set for the given Route at Waypoint 2 the TaskRouteToZone.
|
||||||
|
|
||||||
|
InfantryGroup:Route( Waypoints ) -- Move after a random seconds to the Route. See the Route method for details.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- @param #AI_CARGO_TROOPS self
|
--- @param #AI_CARGO_TROOPS self
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
function AI_CARGO_TROOPS:onafterMonitor( CargoCarrier, From, Event, To )
|
function AI_CARGO_TROOPS:onafterMonitor( 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 self.Coordinate then
|
if self.CarrierCoordinate then
|
||||||
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" ) then
|
if self:Is( "Unloaded" ) or self:Is( "Guarding" ) 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( 1 )
|
||||||
-- 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
|
||||||
end
|
end
|
||||||
if self:Is( "Unloaded" ) then
|
if self:Is( "Guarding" ) then
|
||||||
if not Coordinate:IsAtCoordinate2D( self.Coordinate, 2 ) then
|
if not self.CargoGroup:IsNear( CargoCarrier, 5 ) then
|
||||||
--self.CargoGroup:RouteTo( Coordinate, 30 )
|
self:Follow()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
self.CarrierCoordinate = CargoCarrier:GetCoordinate()
|
||||||
|
end
|
||||||
|
|
||||||
else
|
self:__Monitor( -5 )
|
||||||
self.Coordinate = CargoCarrier:GetCoordinate()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self:__Monitor( 1 )
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,7 +225,23 @@ function AI_CARGO_TROOPS:onafterUnloaded( 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
|
||||||
|
self:Guard()
|
||||||
|
self.CargoCarrier = CargoCarrier
|
||||||
CargoCarrier:RouteResume()
|
CargoCarrier:RouteResume()
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- @param #AI_CARGO_TROOPS self
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
function AI_CARGO_TROOPS:onafterFollow( CargoCarrier, From, Event, To )
|
||||||
|
self:F( { CargoCarrier, From, Event, To } )
|
||||||
|
|
||||||
|
self:F( "Follow" )
|
||||||
|
if CargoCarrier and CargoCarrier:IsAlive() then
|
||||||
|
self:FollowToCarrier( self )
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|||||||
@ -491,17 +491,22 @@ end
|
|||||||
-- @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, NearRadius } )
|
self:F( { PointVec2 = PointVec2, NearRadius = NearRadius } )
|
||||||
|
|
||||||
|
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( { CargoObjectVec2 = self.CargoObject:GetVec2() } )
|
||||||
|
self:F( { PointVec2 = PointVec2:GetVec2() } )
|
||||||
local Distance = PointVec2:Get2DDistance( self.CargoObject:GetPointVec2() )
|
local Distance = PointVec2:Get2DDistance( self.CargoObject:GetPointVec2() )
|
||||||
self:T( Distance )
|
self:T( Distance )
|
||||||
|
|
||||||
if Distance <= NearRadius then
|
if Distance <= NearRadius then
|
||||||
return true
|
return true
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the current PointVec2 of the cargo.
|
--- Get the current PointVec2 of the cargo.
|
||||||
@ -746,7 +751,7 @@ do -- CARGO_UNIT
|
|||||||
function CARGO_UNIT:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
function CARGO_UNIT:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
NearRadius = NearRadius or 25
|
NearRadius = NearRadius or 100
|
||||||
|
|
||||||
local Angle = 180
|
local Angle = 180
|
||||||
local Speed = 60
|
local Speed = 60
|
||||||
@ -804,7 +809,7 @@ do -- CARGO_UNIT
|
|||||||
function CARGO_UNIT:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
function CARGO_UNIT:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
NearRadius = NearRadius or 25
|
NearRadius = NearRadius or 100
|
||||||
|
|
||||||
local Angle = 180
|
local Angle = 180
|
||||||
local Speed = 10
|
local Speed = 10
|
||||||
@ -831,7 +836,7 @@ do -- CARGO_UNIT
|
|||||||
function CARGO_UNIT:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
function CARGO_UNIT:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
NearRadius = NearRadius or 25
|
NearRadius = NearRadius or 100
|
||||||
|
|
||||||
self.CargoInAir = self.CargoObject:InAir()
|
self.CargoInAir = self.CargoObject:InAir()
|
||||||
|
|
||||||
@ -1149,15 +1154,15 @@ do -- CARGO_GROUP
|
|||||||
ClassName = "CARGO_GROUP",
|
ClassName = "CARGO_GROUP",
|
||||||
}
|
}
|
||||||
|
|
||||||
--- CARGO_GROUP constructor.
|
--- CARGO_GROUP constructor.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Wrapper.Group#GROUP CargoGroup
|
-- @param Wrapper.Group#GROUP CargoGroup
|
||||||
-- @param #string Type
|
-- @param #string Type
|
||||||
-- @param #string Name
|
-- @param #string Name
|
||||||
-- @param #number ReportRadius (optional)
|
-- @param #number ReportRadius (optional)
|
||||||
-- @param #number NearRadius (optional)
|
-- @param #number NearRadius (optional)
|
||||||
-- @return #CARGO_GROUP
|
-- @return #CARGO_GROUP
|
||||||
function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
|
function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
|
||||||
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( CargoGroup, Type, Name, 0, ReportRadius ) ) -- #CARGO_GROUP
|
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( CargoGroup, Type, Name, 0, ReportRadius ) ) -- #CARGO_GROUP
|
||||||
self:F( { Type, Name, ReportRadius } )
|
self:F( { Type, Name, ReportRadius } )
|
||||||
|
|
||||||
@ -1189,11 +1194,11 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
|
|||||||
self:SetEventPriority( 4 )
|
self:SetEventPriority( 4 )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param #CARGO_GROUP self
|
--- @param #CARGO_GROUP self
|
||||||
-- @param Core.Event#EVENTDATA EventData
|
-- @param Core.Event#EVENTDATA EventData
|
||||||
function CARGO_GROUP:OnEventCargoDead( EventData )
|
function CARGO_GROUP:OnEventCargoDead( EventData )
|
||||||
|
|
||||||
local Destroyed = false
|
local Destroyed = false
|
||||||
|
|
||||||
@ -1221,15 +1226,15 @@ function CARGO_GROUP:OnEventCargoDead( EventData )
|
|||||||
self:E( { "Cargo group destroyed" } )
|
self:E( { "Cargo group destroyed" } )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Enter Boarding State.
|
--- Enter Boarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
function CARGO_GROUP:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
self:F( { CargoCarrier.UnitName, From, Event, To } )
|
self:F( { CargoCarrier.UnitName, From, Event, To } )
|
||||||
|
|
||||||
local NearRadius = NearRadius or 25
|
local NearRadius = NearRadius or 25
|
||||||
@ -1246,15 +1251,15 @@ function CARGO_GROUP:onenterBoarding( From, Event, To, CargoCarrier, NearRadius,
|
|||||||
self:__Boarding( 1, CargoCarrier, NearRadius, ... )
|
self:__Boarding( 1, CargoCarrier, NearRadius, ... )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Enter Loaded State.
|
--- Enter Loaded State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onenterLoaded( From, Event, To, CargoCarrier, ... )
|
function CARGO_GROUP:onenterLoaded( From, Event, To, CargoCarrier, ... )
|
||||||
self:F( { From, Event, To, CargoCarrier, ...} )
|
self:F( { From, Event, To, CargoCarrier, ...} )
|
||||||
|
|
||||||
if From == "UnLoaded" then
|
if From == "UnLoaded" then
|
||||||
@ -1267,18 +1272,18 @@ function CARGO_GROUP:onenterLoaded( From, Event, To, CargoCarrier, ... )
|
|||||||
--self.CargoObject:Destroy()
|
--self.CargoObject:Destroy()
|
||||||
self.CargoCarrier = CargoCarrier
|
self.CargoCarrier = CargoCarrier
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Leave Boarding State.
|
--- Leave Boarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
self:F( { CargoCarrier.UnitName, From, Event, To } )
|
self:F( { CargoCarrier.UnitName, From, Event, To } )
|
||||||
|
|
||||||
local NearRadius = NearRadius or 25
|
local NearRadius = NearRadius or 100
|
||||||
|
|
||||||
local Boarded = true
|
local Boarded = true
|
||||||
local Cancelled = false
|
local Cancelled = false
|
||||||
@ -1322,26 +1327,26 @@ function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius,
|
|||||||
self:__Destroyed( 1, CargoCarrier, NearRadius, ... )
|
self:__Destroyed( 1, CargoCarrier, NearRadius, ... )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the amount of cargo units in the group.
|
--- Get the amount of cargo units in the group.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @return #CARGO_GROUP
|
-- @return #CARGO_GROUP
|
||||||
function CARGO_GROUP:GetCount()
|
function CARGO_GROUP:GetCount()
|
||||||
return self.CargoSet:Count()
|
return self.CargoSet:Count()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Enter UnBoarding State.
|
--- Enter UnBoarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
||||||
self:F( {From, Event, To, ToPointVec2, NearRadius } )
|
self:F( {From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
NearRadius = NearRadius or 25
|
NearRadius = NearRadius or 100
|
||||||
|
|
||||||
local Timer = 1
|
local Timer = 1
|
||||||
|
|
||||||
@ -1364,15 +1369,15 @@ function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius
|
|||||||
self:__UnBoarding( 1, ToPointVec2, NearRadius, ... )
|
self:__UnBoarding( 1, ToPointVec2, NearRadius, ... )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Leave UnBoarding State.
|
--- Leave UnBoarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
function CARGO_GROUP:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
--local NearRadius = NearRadius or 25
|
--local NearRadius = NearRadius or 25
|
||||||
@ -1401,31 +1406,31 @@ function CARGO_GROUP:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- UnBoard Event.
|
--- UnBoard Event.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
function CARGO_GROUP:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
--local NearRadius = NearRadius or 25
|
--local NearRadius = NearRadius or 25
|
||||||
|
|
||||||
self:__UnLoad( 1, ToPointVec2, ... )
|
self:__UnLoad( 1, ToPointVec2, ... )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Enter UnLoaded State.
|
--- Enter UnLoaded State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2
|
-- @param Core.Point#POINT_VEC2
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onenterUnLoaded( From, Event, To, ToPointVec2, ... )
|
function CARGO_GROUP:onenterUnLoaded( From, Event, To, ToPointVec2, ... )
|
||||||
self:F( { From, Event, To, ToPointVec2 } )
|
self:F( { From, Event, To, ToPointVec2 } )
|
||||||
|
|
||||||
if From == "Loaded" then
|
if From == "Loaded" then
|
||||||
@ -1441,7 +1446,7 @@ function CARGO_GROUP:onenterUnLoaded( From, Event, To, ToPointVec2, ... )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Respawn the cargo when destroyed
|
--- Respawn the cargo when destroyed
|
||||||
@ -1464,21 +1469,37 @@ end
|
|||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#COORDINATE Coordinate
|
-- @param Core.Point#COORDINATE Coordinate
|
||||||
function CARGO_GROUP:RouteTo( Coordinate )
|
function CARGO_GROUP:RouteTo( Coordinate )
|
||||||
self:F( )
|
self:F( {Coordinate = Coordinate } )
|
||||||
|
|
||||||
--local NearRadius = NearRadius or 25
|
|
||||||
|
|
||||||
if From == "UnLoaded" then
|
|
||||||
|
|
||||||
-- For each Cargo object within the CARGO_GROUPED, route each object to the CargoLoadPointVec2
|
-- For each Cargo object within the CARGO_GROUPED, route each object to the CargoLoadPointVec2
|
||||||
self.CargoSet:ForEach(
|
self.CargoSet:ForEach(
|
||||||
function( Cargo, Coordinate )
|
function( Cargo )
|
||||||
Cargo.CargoObject:RouteTo( Coordinate )
|
Cargo.CargoObject:RouteGroundTo( Coordinate, 10, "vee", 0 )
|
||||||
end, Coordinate
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if Cargo is near to the Carrier.
|
||||||
|
-- The Cargo is near to the Carrier if the first unit of the Cargo Group is within NearRadius.
|
||||||
|
-- @param #CARGO_GROUP self
|
||||||
|
-- @param Wrapper.Group#GROUP CargoCarrier
|
||||||
|
-- @param #number NearRadius
|
||||||
|
-- @return #boolean The Cargo is near to the Carrier.
|
||||||
|
-- @return #nil The Cargo is not near to the Carrier.
|
||||||
|
function CARGO_GROUP:IsNear( CargoCarrier, NearRadius )
|
||||||
|
self:F( {NearRadius = NearRadius } )
|
||||||
|
|
||||||
|
local FirstCargo = self.CargoSet:GetFirst() -- #CARGO
|
||||||
|
|
||||||
|
if FirstCargo then
|
||||||
|
if FirstCargo:IsNear( CargoCarrier:GetCoordinate(), NearRadius ) then
|
||||||
|
self:F( "Near" )
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- CARGO_GROUP
|
end -- CARGO_GROUP
|
||||||
|
|||||||
@ -258,9 +258,14 @@ do -- COORDINATE
|
|||||||
|
|
||||||
--- Returns if the 2 coordinates are at the same 2D position.
|
--- Returns if the 2 coordinates are at the same 2D position.
|
||||||
-- @param #COORDINATE self
|
-- @param #COORDINATE self
|
||||||
|
-- @param #COORDINATE Coordinate
|
||||||
|
-- @param #number Precision
|
||||||
-- @return #boolean true if at the same position.
|
-- @return #boolean true if at the same position.
|
||||||
function COORDINATE:IsAtCoordinate2D( Coordinate, Precision )
|
function COORDINATE:IsAtCoordinate2D( Coordinate, Precision )
|
||||||
|
|
||||||
|
self:F( { Coordinate = Coordinate:GetVec2() } )
|
||||||
|
self:F( { self = self:GetVec2() } )
|
||||||
|
|
||||||
local x = Coordinate.x
|
local x = Coordinate.x
|
||||||
local z = Coordinate.z
|
local z = Coordinate.z
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user