mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Added CARGO_CRATE
Added a new object called CARGO_CRATE
This commit is contained in:
parent
d5c7d0028b
commit
0cc36b5ee2
@ -529,7 +529,7 @@ do -- CARGO_REPRESENTABLE
|
|||||||
-- @extends #CARGO
|
-- @extends #CARGO
|
||||||
-- @field test
|
-- @field test
|
||||||
|
|
||||||
---
|
--- Models CARGO that is representable by a Unit.
|
||||||
-- @field #CARGO_REPRESENTABLE CARGO_REPRESENTABLE
|
-- @field #CARGO_REPRESENTABLE CARGO_REPRESENTABLE
|
||||||
CARGO_REPRESENTABLE = {
|
CARGO_REPRESENTABLE = {
|
||||||
ClassName = "CARGO_REPRESENTABLE"
|
ClassName = "CARGO_REPRESENTABLE"
|
||||||
@ -550,6 +550,18 @@ do -- CARGO_REPRESENTABLE
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- CARGO_REPRESENTABLE Destructor.
|
||||||
|
-- @param #CARGO_REPRESENTABLE self
|
||||||
|
-- @return #CARGO_REPRESENTABLE
|
||||||
|
function CARGO_REPRESENTABLE:Destroy()
|
||||||
|
|
||||||
|
-- Cargo objects are deleted from the _DATABASE and SET_CARGO objects.
|
||||||
|
self:F( { CargoName = self:GetName() } )
|
||||||
|
_EVENTDISPATCHER:CreateEventDeleteCargo( self )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- Route a cargo unit to a PointVec2.
|
--- Route a cargo unit to a PointVec2.
|
||||||
-- @param #CARGO_REPRESENTABLE self
|
-- @param #CARGO_REPRESENTABLE self
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
@ -678,7 +690,7 @@ end
|
|||||||
|
|
||||||
do -- CARGO_UNIT
|
do -- CARGO_UNIT
|
||||||
|
|
||||||
--- Hello
|
--- 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_REPRESENTABLE
|
||||||
|
|
||||||
@ -713,34 +725,11 @@ function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )
|
|||||||
|
|
||||||
self:T( self.ClassName )
|
self:T( self.ClassName )
|
||||||
|
|
||||||
-- self:HandleEvent( EVENTS.Dead,
|
|
||||||
-- --- @param #CARGO Cargo
|
|
||||||
-- -- @param Core.Event#EVENTDATA EventData
|
|
||||||
-- function( Cargo, EventData )
|
|
||||||
-- if Cargo:GetObjectName() == EventData.IniUnit:GetName() then
|
|
||||||
-- self:E( { "Cargo destroyed", Cargo } )
|
|
||||||
-- Cargo:Destroyed()
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- )
|
|
||||||
|
|
||||||
self:SetEventPriority( 5 )
|
self:SetEventPriority( 5 )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- CARGO_UNIT Destructor.
|
|
||||||
-- @param #CARGO_UNIT self
|
|
||||||
-- @return #CARGO_UNIT
|
|
||||||
function CARGO_UNIT:Destroy()
|
|
||||||
|
|
||||||
-- Cargo objects are deleted from the _DATABASE and SET_CARGO objects.
|
|
||||||
self:F( { CargoName = self:GetName() } )
|
|
||||||
_EVENTDISPATCHER:CreateEventDeleteCargo( self )
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Enter UnBoarding State.
|
--- Enter UnBoarding State.
|
||||||
-- @param #CARGO_UNIT self
|
-- @param #CARGO_UNIT self
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
@ -872,7 +861,7 @@ function CARGO_UNIT:onenterUnLoaded( From, Event, To, ToPointVec2 )
|
|||||||
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
||||||
local CargoDeployCoord = StartPointVec2:Translate( Distance, CargoDeployHeading )
|
local CargoDeployCoord = StartPointVec2:Translate( Distance, CargoDeployHeading )
|
||||||
|
|
||||||
ToPointVec2 = ToPointVec2 or POINT_VEC2:New( CargoDeployCoord.x, CargoDeployCoord.z )
|
ToPointVec2 = ToPointVec2 or COORDINATE:New( CargoDeployCoord.x, CargoDeployCoord.z )
|
||||||
|
|
||||||
-- Respawn the group...
|
-- Respawn the group...
|
||||||
if self.CargoObject then
|
if self.CargoObject then
|
||||||
@ -1030,10 +1019,112 @@ function CARGO_UNIT:onenterLoaded( From, Event, To, CargoCarrier )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end -- CARGO_UNIT
|
||||||
|
|
||||||
|
|
||||||
|
do -- CARGO_CRATE
|
||||||
|
|
||||||
|
--- Models the behaviour of cargo crates, which can be slingloaded and boarded on helicopters using the DCS menus.
|
||||||
|
-- @type CARGO_CRATE
|
||||||
|
-- @extends #CARGO_REPRESENTABLE
|
||||||
|
|
||||||
|
--- # CARGO\_CRATE class, extends @{#CARGO_REPRESENTABLE}
|
||||||
|
--
|
||||||
|
-- The CARGO\_CRATE class defines a cargo that is represented by a UNIT object within the simulator, and can be transported by a carrier.
|
||||||
|
-- Use the event functions as described above to Load, UnLoad, Board, UnBoard the CARGO\_CRATE objects to and from carriers.
|
||||||
|
--
|
||||||
|
-- ===
|
||||||
|
--
|
||||||
|
-- @field #CARGO_CRATE
|
||||||
|
CARGO_CRATE = {
|
||||||
|
ClassName = "CARGO_CRATE"
|
||||||
|
}
|
||||||
|
|
||||||
|
--- CARGO_CRATE Constructor.
|
||||||
|
-- @param #CARGO_CRATE self
|
||||||
|
-- @param #string CrateName
|
||||||
|
-- @param #string Type
|
||||||
|
-- @param #string Name
|
||||||
|
-- @param #number Weight
|
||||||
|
-- @param #number ReportRadius (optional)
|
||||||
|
-- @param #number NearRadius (optional)
|
||||||
|
-- @return #CARGO_CRATE
|
||||||
|
function CARGO_CRATE:New( CargoCrateName, Type, Name, NearRadius )
|
||||||
|
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoCrateName, Type, Name, nil, NearRadius ) ) -- #CARGO_CRATE
|
||||||
|
self:F( { Type, Name, NearRadius } )
|
||||||
|
|
||||||
|
self:T( CargoCrateName )
|
||||||
|
_DATABASE:AddStatic( CargoCrateName )
|
||||||
|
|
||||||
|
self.CargoObject = STATIC:FindByName( CargoCrateName )
|
||||||
|
|
||||||
|
self:T( self.ClassName )
|
||||||
|
|
||||||
|
self:SetEventPriority( 5 )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Enter UnLoaded State.
|
||||||
|
-- @param #CARGO_CRATE self
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string To
|
||||||
|
-- @param Core.Point#POINT_VEC2
|
||||||
|
function CARGO_CRATE:onenterUnLoaded( From, Event, To, ToPointVec2 )
|
||||||
|
self:F( { ToPointVec2, From, Event, To } )
|
||||||
|
|
||||||
|
local Angle = 180
|
||||||
|
local Speed = 10
|
||||||
|
local Distance = 10
|
||||||
|
|
||||||
|
if From == "Loaded" then
|
||||||
|
local StartCoordinate = self.CargoCarrier:GetCoordinate()
|
||||||
|
local CargoCarrierHeading = self.CargoCarrier:GetHeading() -- Get Heading of object in degrees.
|
||||||
|
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
||||||
|
local CargoDeployCoord = StartCoordinate:Translate( Distance, CargoDeployHeading )
|
||||||
|
|
||||||
|
ToPointVec2 = ToPointVec2 or COORDINATE:NewFromVec2( { x= CargoDeployCoord.x, y = CargoDeployCoord.z } )
|
||||||
|
|
||||||
|
-- Respawn the group...
|
||||||
|
if self.CargoObject then
|
||||||
|
self.CargoObject:ReSpawn( ToPointVec2, 0 )
|
||||||
|
self.CargoCarrier = nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.OnUnLoadedCallBack then
|
||||||
|
self.OnUnLoadedCallBack( self, unpack( self.OnUnLoadedParameters ) )
|
||||||
|
self.OnUnLoadedCallBack = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Loaded State.
|
||||||
|
-- @param #CARGO_CRATE self
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string To
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
function CARGO_CRATE:onenterLoaded( From, Event, To, CargoCarrier )
|
||||||
|
self:F( { From, Event, To, CargoCarrier } )
|
||||||
|
|
||||||
|
self.CargoCarrier = CargoCarrier
|
||||||
|
|
||||||
|
-- Only destroy the CargoObject is if there is a CargoObject (packages don't have CargoObjects).
|
||||||
|
if self.CargoObject then
|
||||||
|
self:T("Destroying")
|
||||||
|
self.CargoObject:Destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
do -- CARGO_GROUP
|
do -- CARGO_GROUP
|
||||||
|
|
||||||
|
|||||||
@ -522,7 +522,7 @@ function DATABASE:_RegisterStaticTemplate( StaticTemplate, CoalitionID, Category
|
|||||||
|
|
||||||
|
|
||||||
TraceTable[#TraceTable+1] = "Static"
|
TraceTable[#TraceTable+1] = "Static"
|
||||||
TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].GroupName
|
TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].StaticName
|
||||||
|
|
||||||
TraceTable[#TraceTable+1] = "Coalition"
|
TraceTable[#TraceTable+1] = "Coalition"
|
||||||
TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].CoalitionID
|
TraceTable[#TraceTable+1] = self.Templates.Statics[StaticTemplateName].CoalitionID
|
||||||
@ -649,6 +649,7 @@ end
|
|||||||
function DATABASE:_RegisterStatics()
|
function DATABASE:_RegisterStatics()
|
||||||
|
|
||||||
local CoalitionsData = { GroupsRed = coalition.getStaticObjects( coalition.side.RED ), GroupsBlue = coalition.getStaticObjects( coalition.side.BLUE ) }
|
local CoalitionsData = { GroupsRed = coalition.getStaticObjects( coalition.side.RED ), GroupsBlue = coalition.getStaticObjects( coalition.side.BLUE ) }
|
||||||
|
self:E( { Statics = CoalitionsData } )
|
||||||
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||||
for DCSStaticId, DCSStatic in pairs( CoalitionData ) do
|
for DCSStaticId, DCSStatic in pairs( CoalitionData ) do
|
||||||
|
|
||||||
|
|||||||
@ -157,8 +157,13 @@ function SPAWNSTATIC:SpawnFromPointVec2( PointVec2, Heading, NewName ) --R2.1
|
|||||||
|
|
||||||
local StaticTemplate = _DATABASE:GetStaticUnitTemplate( self.SpawnTemplatePrefix )
|
local StaticTemplate = _DATABASE:GetStaticUnitTemplate( self.SpawnTemplatePrefix )
|
||||||
|
|
||||||
StaticTemplate.x = PointVec2:GetLat()
|
StaticTemplate.x = PointVec2.x
|
||||||
StaticTemplate.y = PointVec2:GetLon()
|
StaticTemplate.y = PointVec2.z
|
||||||
|
|
||||||
|
StaticTemplate.units = nil
|
||||||
|
StaticTemplate.route = nil
|
||||||
|
StaticTemplate.groupId = nil
|
||||||
|
|
||||||
|
|
||||||
StaticTemplate.name = NewName or string.format("%s#%05d", self.SpawnTemplatePrefix, self.SpawnIndex )
|
StaticTemplate.name = NewName or string.format("%s#%05d", self.SpawnTemplatePrefix, self.SpawnIndex )
|
||||||
StaticTemplate.heading = ( Heading / 180 ) * math.pi
|
StaticTemplate.heading = ( Heading / 180 ) * math.pi
|
||||||
|
|||||||
@ -224,6 +224,7 @@ function GROUP:Destroy()
|
|||||||
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
|
||||||
|
USERFLAG:New( self:GetName() ):Set( 100 )
|
||||||
DCSGroup:destroy()
|
DCSGroup:destroy()
|
||||||
DCSGroup = nil
|
DCSGroup = nil
|
||||||
end
|
end
|
||||||
@ -231,6 +232,7 @@ function GROUP:Destroy()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Returns category of the DCS Group.
|
--- Returns category of the DCS Group.
|
||||||
-- @param #GROUP self
|
-- @param #GROUP self
|
||||||
-- @return Dcs.DCSWrapper.Group#Group.Category The category ID
|
-- @return Dcs.DCSWrapper.Group#Group.Category The category ID
|
||||||
|
|||||||
@ -79,7 +79,6 @@ function OBJECT:Destroy()
|
|||||||
local DCSObject = self:GetDCSObject()
|
local DCSObject = self:GetDCSObject()
|
||||||
|
|
||||||
if DCSObject then
|
if DCSObject then
|
||||||
USERFLAG:New( self:GetGroup():GetName() ):Set( 100 )
|
|
||||||
--BASE:CreateEventCrash( timer.getTime(), DCSObject )
|
--BASE:CreateEventCrash( timer.getTime(), DCSObject )
|
||||||
DCSObject:destroy()
|
DCSObject:destroy()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -61,7 +61,6 @@ function STATIC:FindByName( StaticName, RaiseError )
|
|||||||
|
|
||||||
if StaticFound then
|
if StaticFound then
|
||||||
StaticFound:F3( { StaticName } )
|
StaticFound:F3( { StaticName } )
|
||||||
|
|
||||||
return StaticFound
|
return StaticFound
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -93,3 +92,17 @@ function STATIC:GetThreatLevel()
|
|||||||
|
|
||||||
return 1, "Static"
|
return 1, "Static"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Respawn the @{Unit} using a (tweaked) template of the parent Group.
|
||||||
|
-- @param #UNIT self
|
||||||
|
-- @param Core.Point#COORDINATE Coordinate The coordinate where to spawn the new Static.
|
||||||
|
-- @param #number Heading The heading of the unit respawn.
|
||||||
|
function STATIC:ReSpawn( Coordinate, Heading )
|
||||||
|
|
||||||
|
|
||||||
|
-- todo: need to fix country
|
||||||
|
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, country.id.USA )
|
||||||
|
|
||||||
|
SpawnStatic:SpawnFromPointVec2( Coordinate, Heading, self.StaticName )
|
||||||
|
end
|
||||||
|
|
||||||
|
|||||||
@ -159,6 +159,24 @@ function UNIT:GetDCSObject()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Destroys the UNIT.
|
||||||
|
-- @param #UNIT self
|
||||||
|
-- @return #nil The DCS Unit is not existing or alive.
|
||||||
|
function UNIT:Destroy()
|
||||||
|
self:F2( self.ObjectName )
|
||||||
|
|
||||||
|
local DCSObject = self:GetDCSObject()
|
||||||
|
|
||||||
|
if DCSObject then
|
||||||
|
USERFLAG:New( self:GetGroup():GetName() ):Set( 100 )
|
||||||
|
--BASE:CreateEventCrash( timer.getTime(), DCSObject )
|
||||||
|
DCSObject:destroy()
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Respawn the @{Unit} using a (tweaked) template of the parent Group.
|
--- Respawn the @{Unit} using a (tweaked) template of the parent Group.
|
||||||
--
|
--
|
||||||
-- This function will:
|
-- This function will:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user