This commit is contained in:
Sven Van de Velde 2016-08-06 21:22:19 +02:00
parent d2efc61ddc
commit 7ec2d3425c
8 changed files with 96 additions and 73 deletions

View File

@ -110,10 +110,10 @@ end
-- @param #CARGO self
-- @param Unit#UNIT CargoCarrier
-- @param #number Speed
function CARGO:UnBoard( Speed )
function CARGO:UnBoard( Speed, Distance, Angle )
self:F()
self:_NextEvent( self.FsmP.UnBoard, Speed )
self:_NextEvent( self.FsmP.UnBoard, Speed, Distance, Angle )
end
--- Load Cargo to a Carrier.
@ -181,13 +181,12 @@ function CARGO:OnUnLoaded( FsmP, Event, From, To )
self:F()
self:T( "Cargo " .. self.Name .. " unloaded from " .. self.CargoCarrier:GetName() )
self.CargoCarrier = nil
end
--- @param #CARGO self
function CARGO:_NextEvent( NextEvent, ... )
self:F( self.Name )
self.CargoScheduler:Schedule( self.FsmP, NextEvent, arg, 1 ) -- This schedules the next event, but only if scheduling is activated.
SCHEDULER:New( self.FsmP, NextEvent, arg, 1 ) -- This schedules the next event, but only if scheduling is activated.
end
end
@ -224,10 +223,9 @@ function CARGO_REPRESENTABLE:New( Mission, CargoObject, Type, Name, Weight, Repo
{ name = 'Boarded', from = 'Boarding', to = 'Boarding' },
{ name = 'Load', from = 'Boarding', to = 'Loaded' },
{ name = 'Load', from = 'UnLoaded', to = 'Loaded' },
{ name = 'UnBoard', from = 'Loaded', to = 'UnLoading' },
{ name = 'UnLoad', from = 'UnLoading', to = 'UnBoarding' },
{ name = 'UnBoard', from = 'UnBoarding', to = 'UnBoarding' },
{ name = 'UnBoarded', from = 'UnBoarding', to = 'UnLoaded' },
{ name = 'UnBoard', from = 'Loaded', to = 'UnBoarding' },
{ name = 'UnBoarded', from = 'UnBoarding', to = 'UnBoarding' },
{ name = 'UnLoad', from = 'UnBoarding', to = 'UnLoaded' },
{ name = 'UnLoad', from = 'Loaded', to = 'UnLoaded' },
},
callbacks = {
@ -316,45 +314,30 @@ function CARGO_REPRESENTABLE:OnUnBoard( FsmP, Event, From, To, Speed, Distance,
-- (eg. cargo can be on a oil derrick, moving the cargo on the oil derrick will drop the cargo on the sea).
if not self.CargoInAir then
if self.FsmP:is( "Loaded" ) then
self:_NextEvent( FsmP.UnLoad, Distance, Angle )
if self.FsmP:is( "UnLoading" ) then
self:_NextEvent( FsmP.UnLoad, 3, Angle )
self:_NextEvent( FsmP.UnBoard, Speed, Distance, Angle )
else
local Points = {}
local StartPointVec2 = self.CargoCarrier:GetPointVec2()
local CargoCarrierHeading = self.CargoCarrier:GetHeading() -- Get Heading of object in degrees.
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
self:T( { CargoCarrierHeading, CargoDeployHeading } )
local CargoDeployPointVec2 = StartPointVec2:Translate( Distance, CargoDeployHeading )
local CargoDeployPointVec2 = CargoDeployPointVec2:GetRandomPointVec2InRadius( self.NearRadius )
Points[#Points+1] = StartPointVec2:RoutePointGround( Speed )
Points[#Points+1] = CargoDeployPointVec2:RoutePointGround( Speed )
local TaskRoute = self.CargoObject:TaskRoute( Points )
self.CargoObject:SetTask( TaskRoute, 4 )
self:_NextEvent( FsmP.UnBoarded )
self.CargoObject:SetTask( TaskRoute, 1 )
end
end
end
--- UnBoarded Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO_REPRESENTABLE:OnUnBoarded( FsmP, Event, From, To )
self:F()
if self.CargoObject:GetVelocityKMH() <= 0.1 then
else
self:_NextEvent( FsmP.UnBoarded )
end
end
--- Load Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP

View File

@ -264,19 +264,19 @@ end
-- @param #table SpawnTemplate
-- @return #DATABASE self
function DATABASE:Spawn( SpawnTemplate )
self:F2( SpawnTemplate.name )
self:F( SpawnTemplate.name )
self:T2( { SpawnTemplate.SpawnCountryID, SpawnTemplate.SpawnCategoryID } )
self:T( { SpawnTemplate.SpawnCountryID, SpawnTemplate.SpawnCategoryID } )
-- Copy the spawn variables of the template in temporary storage, nullify, and restore the spawn variables.
local SpawnCoalitionID = SpawnTemplate.SpawnCoalitionID
local SpawnCountryID = SpawnTemplate.SpawnCountryID
local SpawnCategoryID = SpawnTemplate.SpawnCategoryID
local SpawnCoalitionID = SpawnTemplate.CoalitionID
local SpawnCountryID = SpawnTemplate.CountryID
local SpawnCategoryID = SpawnTemplate.CategoryID
-- Nullify
SpawnTemplate.SpawnCoalitionID = nil
SpawnTemplate.SpawnCountryID = nil
SpawnTemplate.SpawnCategoryID = nil
SpawnTemplate.CoalitionID = nil
SpawnTemplate.CountryID = nil
SpawnTemplate.CategoryID = nil
self:_RegisterTemplate( SpawnTemplate, SpawnCoalitionID, SpawnCategoryID, SpawnCountryID )
@ -284,9 +284,9 @@ function DATABASE:Spawn( SpawnTemplate )
coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate )
-- Restore
SpawnTemplate.SpawnCoalitionID = SpawnCoalitionID
SpawnTemplate.SpawnCountryID = SpawnCountryID
SpawnTemplate.SpawnCategoryID = SpawnCategoryID
SpawnTemplate.CoalitionID = SpawnCoalitionID
SpawnTemplate.CountryID = SpawnCountryID
SpawnTemplate.CategoryID = SpawnCategoryID
local SpawnGroup = self:AddGroup( SpawnTemplate.name )
return SpawnGroup
@ -330,6 +330,10 @@ function DATABASE:_RegisterTemplate( GroupTemplate, CoalitionID, CategoryID, Cou
GroupTemplate.route.spans = nil
end
GroupTemplate.CategoryID = CategoryID
GroupTemplate.CoalitionID = CoalitionID
GroupTemplate.CountryID = CountryID
self.Templates.Groups[GroupTemplateName].GroupName = GroupTemplateName
self.Templates.Groups[GroupTemplateName].Template = GroupTemplate
self.Templates.Groups[GroupTemplateName].groupId = GroupTemplate.groupId
@ -354,26 +358,27 @@ function DATABASE:_RegisterTemplate( GroupTemplate, CoalitionID, CategoryID, Cou
for unit_num, UnitTemplate in pairs( GroupTemplate.units ) do
local UnitTemplateName = env.getValueDictByKey(UnitTemplate.name)
self.Templates.Units[UnitTemplateName] = {}
self.Templates.Units[UnitTemplateName].UnitName = UnitTemplateName
self.Templates.Units[UnitTemplateName].Template = UnitTemplate
self.Templates.Units[UnitTemplateName].GroupName = GroupTemplateName
self.Templates.Units[UnitTemplateName].GroupTemplate = GroupTemplate
self.Templates.Units[UnitTemplateName].GroupId = GroupTemplate.groupId
self.Templates.Units[UnitTemplateName].CategoryID = CategoryID
self.Templates.Units[UnitTemplateName].CoalitionID = CoalitionID
self.Templates.Units[UnitTemplateName].CountryID = CountryID
UnitTemplate.name = env.getValueDictByKey(UnitTemplate.name)
self.Templates.Units[UnitTemplate.name] = {}
self.Templates.Units[UnitTemplate.name].UnitName = UnitTemplate.name
self.Templates.Units[UnitTemplate.name].Template = UnitTemplate
self.Templates.Units[UnitTemplate.name].GroupName = GroupTemplateName
self.Templates.Units[UnitTemplate.name].GroupTemplate = GroupTemplate
self.Templates.Units[UnitTemplate.name].GroupId = GroupTemplate.groupId
self.Templates.Units[UnitTemplate.name].CategoryID = CategoryID
self.Templates.Units[UnitTemplate.name].CoalitionID = CoalitionID
self.Templates.Units[UnitTemplate.name].CountryID = CountryID
if UnitTemplate.skill and (UnitTemplate.skill == "Client" or UnitTemplate.skill == "Player") then
self.Templates.ClientsByName[UnitTemplateName] = UnitTemplate
self.Templates.ClientsByName[UnitTemplateName].CategoryID = CategoryID
self.Templates.ClientsByName[UnitTemplateName].CoalitionID = CoalitionID
self.Templates.ClientsByName[UnitTemplateName].CountryID = CountryID
self.Templates.ClientsByName[UnitTemplate.name] = UnitTemplate
self.Templates.ClientsByName[UnitTemplate.name].CategoryID = CategoryID
self.Templates.ClientsByName[UnitTemplate.name].CoalitionID = CoalitionID
self.Templates.ClientsByName[UnitTemplate.name].CountryID = CountryID
self.Templates.ClientsByID[UnitTemplate.unitId] = UnitTemplate
end
TraceTable[#TraceTable+1] = self.Templates.Units[UnitTemplateName].UnitName
TraceTable[#TraceTable+1] = self.Templates.Units[UnitTemplate.name].UnitName
end
self:E( TraceTable )

View File

@ -185,7 +185,7 @@ function POINT_VEC3:SetZ( z )
self.z = z
end
--- Return a random Vec3 point within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3.
--- Return a random Vec2 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3.
-- @param #POINT_VEC3 self
-- @param DCSTypes#Distance OuterRadius
-- @param DCSTypes#Distance InnerRadius
@ -206,17 +206,28 @@ function POINT_VEC3:GetRandomVec2InRadius( OuterRadius, InnerRadius )
RadialMultiplier = OuterRadius * Radials
end
local RandomVec3
local RandomVec2
if OuterRadius > 0 then
RandomVec3 = { x = math.cos( Theta ) * RadialMultiplier + self:GetX(), y = math.sin( Theta ) * RadialMultiplier + self:GetZ() }
RandomVec2 = { x = math.cos( Theta ) * RadialMultiplier + self:GetX(), y = math.sin( Theta ) * RadialMultiplier + self:GetZ() }
else
RandomVec3 = { x = self:GetX(), y = self:GetZ() }
RandomVec2 = { x = self:GetX(), y = self:GetZ() }
end
return RandomVec3
return RandomVec2
end
--- Return a random Vec3 point within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3.
--- Return a random POINT_VEC2 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3.
-- @param #POINT_VEC3 self
-- @param DCSTypes#Distance OuterRadius
-- @param DCSTypes#Distance InnerRadius
-- @return #POINT_VEC2
function POINT_VEC3:GetRandomPointVec2InRadius( OuterRadius, InnerRadius )
self:F2( { OuterRadius, InnerRadius } )
return POINT_VEC2:NewFromVec2( self:GetRandomPointVec2InRadius( OuterRadius, InnerRadius ) )
end
--- Return a random Vec3 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3.
-- @param #POINT_VEC3 self
-- @param DCSTypes#Distance OuterRadius
-- @param DCSTypes#Distance InnerRadius
@ -230,6 +241,16 @@ function POINT_VEC3:GetRandomVec3InRadius( OuterRadius, InnerRadius )
return RandomVec3
end
--- Return a random POINT_VEC3 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3.
-- @param #POINT_VEC3 self
-- @param DCSTypes#Distance OuterRadius
-- @param DCSTypes#Distance InnerRadius
-- @return #POINT_VEC3
function POINT_VEC3:GetRandomPointVec3InRadius( OuterRadius, InnerRadius )
return POINT_VEC3:NewFromVec3( self:GetRandomVec3InRadius( OuterRadius, InnerRadius ) )
end
--- Return a direction vector Vec3 from POINT_VEC3 to the POINT_VEC3.
-- @param #POINT_VEC3 self
@ -295,8 +316,10 @@ function POINT_VEC3:Translate( Distance, Angle )
local TX = Distance * math.cos( Radians ) + SX
local TY = Distance * math.sin( Radians ) + SY
local SourceVec3 = self:GetVec3()
return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.y - SourceVec3.y ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5
self:SetX( TX )
self:SetY( TY )
return self
end
--- Provides a Bearing / Range string
@ -626,7 +649,7 @@ end
--- Set the x coordinate of the POINT_VEC2.
-- @param #number x The x coordinate.
function POINT_VEC2:SetX( x )
elf.x = x
self.x = x
end
--- Set the y coordinate of the POINT_VEC2.

View File

@ -209,6 +209,7 @@ function POSITIONABLE:GetHeading()
if PositionableHeading < 0 then
PositionableHeading = PositionableHeading + 2 * math.pi
end
PositionableHeading = PositionableHeading * 180 / math.pi
self:T2( PositionableHeading )
return PositionableHeading
end

View File

@ -1003,9 +1003,9 @@ function SPAWN:_GetTemplate( SpawnTemplatePrefix )
error( 'No Template returned for SpawnTemplatePrefix = ' .. SpawnTemplatePrefix )
end
SpawnTemplate.SpawnCoalitionID = self:_GetGroupCoalitionID( SpawnTemplatePrefix )
SpawnTemplate.SpawnCategoryID = self:_GetGroupCategoryID( SpawnTemplatePrefix )
SpawnTemplate.SpawnCountryID = self:_GetGroupCountryID( SpawnTemplatePrefix )
--SpawnTemplate.SpawnCoalitionID = self:_GetGroupCoalitionID( SpawnTemplatePrefix )
--SpawnTemplate.SpawnCategoryID = self:_GetGroupCategoryID( SpawnTemplatePrefix )
--SpawnTemplate.SpawnCountryID = self:_GetGroupCountryID( SpawnTemplatePrefix )
self:T3( { SpawnTemplate } )
return SpawnTemplate
@ -1026,12 +1026,12 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex )
--SpawnTemplate.lateActivation = false
SpawnTemplate.lateActivation = false
if SpawnTemplate.SpawnCategoryID == Group.Category.GROUND then
if SpawnTemplate.CategoryID == Group.Category.GROUND then
self:T3( "For ground units, visible needs to be false..." )
SpawnTemplate.visible = false
end
if SpawnTemplate.SpawnCategoryID == Group.Category.HELICOPTER or SpawnTemplate.SpawnCategoryID == Group.Category.AIRPLANE then
if SpawnTemplate.CategoryID == Group.Category.HELICOPTER or SpawnTemplate.CategoryID == Group.Category.AIRPLANE then
SpawnTemplate.uncontrolled = false
end
@ -1064,7 +1064,7 @@ function SPAWN:_RandomizeRoute( SpawnIndex )
SpawnTemplate.route.points[t].y = SpawnTemplate.route.points[t].y + math.random( self.SpawnRandomizeRouteRadius * -1, self.SpawnRandomizeRouteRadius )
-- Manage randomization of altitude for airborne units ...
if SpawnTemplate.SpawnCategoryID == Group.Category.AIRPLANE or SpawnTemplate.SpawnCategoryID == Group.Category.HELICOPTER then
if SpawnTemplate.CategoryID == Group.Category.AIRPLANE or SpawnTemplate.CategoryID == Group.Category.HELICOPTER then
if SpawnTemplate.route.points[t].alt and self.SpawnRandomizeRouteHeight then
SpawnTemplate.route.points[t].alt = SpawnTemplate.route.points[t].alt + math.random( 1, self.SpawnRandomizeRouteHeight )
end

View File

@ -152,6 +152,14 @@ function UNIT:FindByName( UnitName )
return UnitFound
end
--- Return the name of the UNIT.
-- @param #UNIT self
-- @return #string The UNIT name.
function UNIT:Name()
return self.UnitName
end
--- @param #UNIT self
-- @return DCSUnit#Unit
@ -179,7 +187,8 @@ end
-- @param #number Heading The heading of the unit respawn.
function UNIT:ReSpawn( SpawnVec3, Heading )
local SpawnGroupTemplate = _DATABASE:GetGroupTemplateFromUnitName( self:GetName() )
local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) )
self:T( SpawnGroupTemplate )
local SpawnGroup = self:GetGroup()
if SpawnGroup then
@ -205,7 +214,9 @@ function UNIT:ReSpawn( SpawnVec3, Heading )
end
for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do
if UnitTemplateData.name == self:GetName() then
self:T( UnitTemplateData.name )
if UnitTemplateData.name == self:Name() then
self:T("Adjusting")
SpawnGroupTemplate.units[UnitTemplateID].alt = SpawnVec3.y
SpawnGroupTemplate.units[UnitTemplateID].x = SpawnVec3.x
SpawnGroupTemplate.units[UnitTemplateID].y = SpawnVec3.z

View File

@ -12,4 +12,4 @@ InfantryCargo:Load( CargoCarrier )
-- This will Unboard the Cargo from the Carrier.
-- The Cargo will run from the Carrier to a point in the NearRadius around the Carrier.
-- Unboard the Cargo with a speed of 10 km/h, go to 200 meters 180 degrees from the Carrier, iin a zone of 25 meters (NearRadius).
InfantryCargo:UnBoard( CargoCarrier, 10, 200, 180 )
InfantryCargo:UnBoard( 10, 200, 180 )