Merge pull request #142 from FlightControl-Master/PICKUP

2016-08-12
- Temporary release of the new cargo handling.
-- Released available functionality to handle one CARGO_UNIT loading, boarding, unloading.
-- Created CARGO_UNIT test missions.
- Removed PointVec3 field from POINT_VEC3 class and added x, y, z coordinates.
- Removed PointVec2 field from POINT_VEC2 class and added x, y, alt coordinates.
- Added Translate method in POINT_VEC2.

2016-08-06
- Made PointVec3 and Vec3, PointVec2 and Vec2 terminology used in the code consistent.
-- Replaced method PointVec3() to Vec3() where the code manages a Vec3. Replaced all references to the method.
-- Replaced method PointVec2() to Vec2() where the code manages a Vec2. Replaced all references to the method.
-- Replaced method RandomPointVec3() to RandomVec3() where the code manages a Vec3. Replaced all references to the method.
This commit is contained in:
Sven Van de Velde 2016-08-12 08:20:55 +02:00 committed by GitHub
commit fec2b39469
33 changed files with 5334 additions and 3578 deletions

File diff suppressed because it is too large Load Diff

View File

@ -506,15 +506,15 @@ end
--- (AIR) Delivering weapon at the point on the ground. --- (AIR) Delivering weapon at the point on the ground.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCSTypes#Vec2 PointVec2 2D-coordinates of the point to deliver weapon at. -- @param DCSTypes#Vec2 Vec2 2D-coordinates of the point to deliver weapon at.
-- @param #number WeaponType (optional) Bitmask of weapon types those allowed to use. If parameter is not defined that means no limits on weapon usage. -- @param #number WeaponType (optional) Bitmask of weapon types those allowed to use. If parameter is not defined that means no limits on weapon usage.
-- @param DCSTypes#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion. -- @param DCSTypes#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param #number AttackQty (optional) Desired quantity of passes. The parameter is not the same in AttackControllable and AttackUnit tasks. -- @param #number AttackQty (optional) Desired quantity of passes. The parameter is not the same in AttackControllable and AttackUnit tasks.
-- @param DCSTypes#Azimuth Direction (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction. -- @param DCSTypes#Azimuth Direction (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @param #boolean ControllableAttack (optional) Flag indicates that the target must be engaged by all aircrafts of the controllable. Has effect only if the task is assigned to a controllable, not to a single aircraft. -- @param #boolean ControllableAttack (optional) Flag indicates that the target must be engaged by all aircrafts of the controllable. Has effect only if the task is assigned to a controllable, not to a single aircraft.
-- @return DCSTask#Task The DCS task structure. -- @return DCSTask#Task The DCS task structure.
function CONTROLLABLE:TaskBombing( PointVec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack ) function CONTROLLABLE:TaskBombing( Vec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack )
self:F2( { self.ControllableName, PointVec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack } ) self:F2( { self.ControllableName, Vec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack } )
-- Bombing = { -- Bombing = {
-- id = 'Bombing', -- id = 'Bombing',
@ -531,7 +531,7 @@ function CONTROLLABLE:TaskBombing( PointVec2, WeaponType, WeaponExpend, AttackQt
local DCSTask local DCSTask
DCSTask = { id = 'Bombing', DCSTask = { id = 'Bombing',
params = { params = {
point = PointVec2, point = Vec2,
weaponType = WeaponType, weaponType = WeaponType,
expend = WeaponExpend, expend = WeaponExpend,
attackQty = AttackQty, attackQty = AttackQty,
@ -624,15 +624,15 @@ end
--- (AIR) Attacking the map object (building, structure, e.t.c). --- (AIR) Attacking the map object (building, structure, e.t.c).
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCSTypes#Vec2 PointVec2 2D-coordinates of the point the map object is closest to. The distance between the point and the map object must not be greater than 2000 meters. Object id is not used here because Mission Editor doesn't support map object identificators. -- @param DCSTypes#Vec2 Vec2 2D-coordinates of the point the map object is closest to. The distance between the point and the map object must not be greater than 2000 meters. Object id is not used here because Mission Editor doesn't support map object identificators.
-- @param #number WeaponType (optional) Bitmask of weapon types those allowed to use. If parameter is not defined that means no limits on weapon usage. -- @param #number WeaponType (optional) Bitmask of weapon types those allowed to use. If parameter is not defined that means no limits on weapon usage.
-- @param DCSTypes#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion. -- @param DCSTypes#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param #number AttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo. -- @param #number AttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param DCSTypes#Azimuth Direction (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction. -- @param DCSTypes#Azimuth Direction (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @param #boolean ControllableAttack (optional) Flag indicates that the target must be engaged by all aircrafts of the controllable. Has effect only if the task is assigned to a controllable, not to a single aircraft. -- @param #boolean ControllableAttack (optional) Flag indicates that the target must be engaged by all aircrafts of the controllable. Has effect only if the task is assigned to a controllable, not to a single aircraft.
-- @return DCSTask#Task The DCS task structure. -- @return DCSTask#Task The DCS task structure.
function CONTROLLABLE:TaskAttackMapObject( PointVec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack ) function CONTROLLABLE:TaskAttackMapObject( Vec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack )
self:F2( { self.ControllableName, PointVec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack } ) self:F2( { self.ControllableName, Vec2, WeaponType, WeaponExpend, AttackQty, Direction, ControllableAttack } )
-- AttackMapObject = { -- AttackMapObject = {
-- id = 'AttackMapObject', -- id = 'AttackMapObject',
@ -649,7 +649,7 @@ function CONTROLLABLE:TaskAttackMapObject( PointVec2, WeaponType, WeaponExpend,
local DCSTask local DCSTask
DCSTask = { id = 'AttackMapObject', DCSTask = { id = 'AttackMapObject',
params = { params = {
point = PointVec2, point = Vec2,
weaponType = WeaponType, weaponType = WeaponType,
expend = WeaponExpend, expend = WeaponExpend,
attackQty = AttackQty, attackQty = AttackQty,
@ -793,11 +793,11 @@ end
-- If another controllable is on land the unit / controllable will orbit around. -- If another controllable is on land the unit / controllable will orbit around.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param Controllable#CONTROLLABLE FollowControllable The controllable to be followed. -- @param Controllable#CONTROLLABLE FollowControllable The controllable to be followed.
-- @param DCSTypes#Vec3 PointVec3 Position of the unit / lead unit of the controllable relative lead unit of another controllable in frame reference oriented by course of lead unit of another controllable. If another controllable is on land the unit / controllable will orbit around. -- @param DCSTypes#Vec3 Vec3 Position of the unit / lead unit of the controllable relative lead unit of another controllable in frame reference oriented by course of lead unit of another controllable. If another controllable is on land the unit / controllable will orbit around.
-- @param #number LastWaypointIndex Detach waypoint of another controllable. Once reached the unit / controllable Follow task is finished. -- @param #number LastWaypointIndex Detach waypoint of another controllable. Once reached the unit / controllable Follow task is finished.
-- @return DCSTask#Task The DCS task structure. -- @return DCSTask#Task The DCS task structure.
function CONTROLLABLE:TaskFollow( FollowControllable, PointVec3, LastWaypointIndex ) function CONTROLLABLE:TaskFollow( FollowControllable, Vec3, LastWaypointIndex )
self:F2( { self.ControllableName, FollowControllable, PointVec3, LastWaypointIndex } ) self:F2( { self.ControllableName, FollowControllable, Vec3, LastWaypointIndex } )
-- Follow = { -- Follow = {
-- id = 'Follow', -- id = 'Follow',
@ -818,7 +818,7 @@ function CONTROLLABLE:TaskFollow( FollowControllable, PointVec3, LastWaypointInd
DCSTask = { id = 'Follow', DCSTask = { id = 'Follow',
params = { params = {
controllableId = FollowControllable:GetID(), controllableId = FollowControllable:GetID(),
pos = PointVec3, pos = Vec3,
lastWptIndexFlag = LastWaypointIndexFlag, lastWptIndexFlag = LastWaypointIndexFlag,
lastWptIndex = LastWaypointIndex, lastWptIndex = LastWaypointIndex,
}, },
@ -834,13 +834,13 @@ end
-- The unit / controllable will also protect that controllable from threats of specified types. -- The unit / controllable will also protect that controllable from threats of specified types.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param Controllable#CONTROLLABLE EscortControllable The controllable to be escorted. -- @param Controllable#CONTROLLABLE EscortControllable The controllable to be escorted.
-- @param DCSTypes#Vec3 PointVec3 Position of the unit / lead unit of the controllable relative lead unit of another controllable in frame reference oriented by course of lead unit of another controllable. If another controllable is on land the unit / controllable will orbit around. -- @param DCSTypes#Vec3 Vec3 Position of the unit / lead unit of the controllable relative lead unit of another controllable in frame reference oriented by course of lead unit of another controllable. If another controllable is on land the unit / controllable will orbit around.
-- @param #number LastWaypointIndex Detach waypoint of another controllable. Once reached the unit / controllable Follow task is finished. -- @param #number LastWaypointIndex Detach waypoint of another controllable. Once reached the unit / controllable Follow task is finished.
-- @param #number EngagementDistanceMax Maximal distance from escorted controllable to threat. If the threat is already engaged by escort escort will disengage if the distance becomes greater than 1.5 * engagementDistMax. -- @param #number EngagementDistanceMax Maximal distance from escorted controllable to threat. If the threat is already engaged by escort escort will disengage if the distance becomes greater than 1.5 * engagementDistMax.
-- @param DCSTypes#AttributeNameArray TargetTypes Array of AttributeName that is contains threat categories allowed to engage. -- @param DCSTypes#AttributeNameArray TargetTypes Array of AttributeName that is contains threat categories allowed to engage.
-- @return DCSTask#Task The DCS task structure. -- @return DCSTask#Task The DCS task structure.
function CONTROLLABLE:TaskEscort( FollowControllable, PointVec3, LastWaypointIndex, EngagementDistance, TargetTypes ) function CONTROLLABLE:TaskEscort( FollowControllable, Vec3, LastWaypointIndex, EngagementDistance, TargetTypes )
self:F2( { self.ControllableName, FollowControllable, PointVec3, LastWaypointIndex, EngagementDistance, TargetTypes } ) self:F2( { self.ControllableName, FollowControllable, Vec3, LastWaypointIndex, EngagementDistance, TargetTypes } )
-- Escort = { -- Escort = {
-- id = 'Escort', -- id = 'Escort',
@ -863,7 +863,7 @@ function CONTROLLABLE:TaskEscort( FollowControllable, PointVec3, LastWaypointInd
DCSTask = { id = 'Follow', DCSTask = { id = 'Follow',
params = { params = {
controllableId = FollowControllable:GetID(), controllableId = FollowControllable:GetID(),
pos = PointVec3, pos = Vec3,
lastWptIndexFlag = LastWaypointIndexFlag, lastWptIndexFlag = LastWaypointIndexFlag,
lastWptIndex = LastWaypointIndex, lastWptIndex = LastWaypointIndex,
engagementDistMax = EngagementDistance, engagementDistMax = EngagementDistance,
@ -880,11 +880,11 @@ end
--- (GROUND) Fire at a VEC2 point until ammunition is finished. --- (GROUND) Fire at a VEC2 point until ammunition is finished.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCSTypes#Vec2 PointVec2 The point to fire at. -- @param DCSTypes#Vec2 Vec2 The point to fire at.
-- @param DCSTypes#Distance Radius The radius of the zone to deploy the fire at. -- @param DCSTypes#Distance Radius The radius of the zone to deploy the fire at.
-- @return DCSTask#Task The DCS task structure. -- @return DCSTask#Task The DCS task structure.
function CONTROLLABLE:TaskFireAtPoint( PointVec2, Radius ) function CONTROLLABLE:TaskFireAtPoint( Vec2, Radius )
self:F2( { self.ControllableName, PointVec2, Radius } ) self:F2( { self.ControllableName, Vec2, Radius } )
-- FireAtPoint = { -- FireAtPoint = {
-- id = 'FireAtPoint', -- id = 'FireAtPoint',
@ -897,7 +897,7 @@ function CONTROLLABLE:TaskFireAtPoint( PointVec2, Radius )
local DCSTask local DCSTask
DCSTask = { id = 'FireAtPoint', DCSTask = { id = 'FireAtPoint',
params = { params = {
point = PointVec2, point = Vec2,
radius = Radius, radius = Radius,
} }
} }
@ -1004,13 +1004,13 @@ end
--- (AIR) Engaging a targets of defined types at circle-shaped zone. --- (AIR) Engaging a targets of defined types at circle-shaped zone.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCSTypes#Vec2 PointVec2 2D-coordinates of the zone. -- @param DCSTypes#Vec2 Vec2 2D-coordinates of the zone.
-- @param DCSTypes#Distance Radius Radius of the zone. -- @param DCSTypes#Distance Radius Radius of the zone.
-- @param DCSTypes#AttributeNameArray TargetTypes Array of target categories allowed to engage. -- @param DCSTypes#AttributeNameArray TargetTypes Array of target categories allowed to engage.
-- @param #number Priority All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first. -- @param #number Priority All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first.
-- @return DCSTask#Task The DCS task structure. -- @return DCSTask#Task The DCS task structure.
function CONTROLLABLE:EnRouteTaskEngageTargets( PointVec2, Radius, TargetTypes, Priority ) function CONTROLLABLE:EnRouteTaskEngageTargets( Vec2, Radius, TargetTypes, Priority )
self:F2( { self.ControllableName, PointVec2, Radius, TargetTypes, Priority } ) self:F2( { self.ControllableName, Vec2, Radius, TargetTypes, Priority } )
-- EngageTargetsInZone = { -- EngageTargetsInZone = {
-- id = 'EngageTargetsInZone', -- id = 'EngageTargetsInZone',
@ -1025,7 +1025,7 @@ function CONTROLLABLE:EnRouteTaskEngageTargets( PointVec2, Radius, TargetTypes,
local DCSTask local DCSTask
DCSTask = { id = 'EngageTargetsInZone', DCSTask = { id = 'EngageTargetsInZone',
params = { params = {
point = PointVec2, point = Vec2,
zoneRadius = Radius, zoneRadius = Radius,
targetTypes = TargetTypes, targetTypes = TargetTypes,
priority = Priority priority = Priority
@ -1428,12 +1428,12 @@ end
function CONTROLLABLE:TaskRouteToVec3( Point, Speed ) function CONTROLLABLE:TaskRouteToVec3( Point, Speed )
self:F2( { Point, Speed } ) self:F2( { Point, Speed } )
local ControllablePoint = self:GetUnit( 1 ):GetPointVec3() local ControllableVec3 = self:GetUnit( 1 ):GetVec3()
local PointFrom = {} local PointFrom = {}
PointFrom.x = ControllablePoint.x PointFrom.x = ControllableVec3.x
PointFrom.y = ControllablePoint.z PointFrom.y = ControllableVec3.z
PointFrom.alt = ControllablePoint.y PointFrom.alt = ControllableVec3.y
PointFrom.alt_type = "BARO" PointFrom.alt_type = "BARO"
PointFrom.type = "Turning Point" PointFrom.type = "Turning Point"
PointFrom.action = "Turning Point" PointFrom.action = "Turning Point"

View File

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

View File

@ -347,11 +347,11 @@ function DETECTION_BASE:_DetectionScheduler( SchedulerName )
local DetectionDetectedObjectName = DetectionObject:getName() local DetectionDetectedObjectName = DetectionObject:getName()
local DetectionDetectedObjectPositionVec3 = DetectionObject:getPoint() local DetectionDetectedObjectPositionVec3 = DetectionObject:getPoint()
local DetectionGroupPositionVec3 = DetectionGroup:GetPointVec3() local DetectionGroupVec3 = DetectionGroup:GetVec3()
local Distance = ( ( DetectionDetectedObjectPositionVec3.x - DetectionGroupPositionVec3.x )^2 + local Distance = ( ( DetectionDetectedObjectPositionVec3.x - DetectionGroupVec3.x )^2 +
( DetectionDetectedObjectPositionVec3.y - DetectionGroupPositionVec3.y )^2 + ( DetectionDetectedObjectPositionVec3.y - DetectionGroupVec3.y )^2 +
( DetectionDetectedObjectPositionVec3.z - DetectionGroupPositionVec3.z )^2 ( DetectionDetectedObjectPositionVec3.z - DetectionGroupVec3.z )^2
) ^ 0.5 / 1000 ) ^ 0.5 / 1000
self:T2( { DetectionGroupName, DetectionDetectedObjectName, Distance } ) self:T2( { DetectionGroupName, DetectionDetectedObjectName, Distance } )
@ -531,7 +531,7 @@ function DETECTION_AREAS:ReportFriendliesNearBy( ReportGroupData )
local SphereSearch = { local SphereSearch = {
id = world.VolumeType.SPHERE, id = world.VolumeType.SPHERE,
params = { params = {
point = DetectedZoneUnit:GetPointVec3(), point = DetectedZoneUnit:GetVec3(),
radius = 6000, radius = 6000,
} }
@ -613,9 +613,9 @@ function DETECTION_AREAS:NearestFAC( DetectedArea )
for FACUnit, FACUnitData in pairs( FACGroupData:GetUnits() ) do for FACUnit, FACUnitData in pairs( FACGroupData:GetUnits() ) do
local FACUnit = FACUnitData -- Unit#UNIT local FACUnit = FACUnitData -- Unit#UNIT
if FACUnit:IsActive() then if FACUnit:IsActive() then
local Vec3 = FACUnit:GetPointVec3() local Vec3 = FACUnit:GetVec3()
local PointVec3 = POINT_VEC3:NewFromVec3( Vec3 ) local PointVec3 = POINT_VEC3:NewFromVec3( Vec3 )
local Distance = PointVec3:Get2DDistance(POINT_VEC3:NewFromVec3( FACUnit:GetPointVec3() ) ) local Distance = PointVec3:Get2DDistance(POINT_VEC3:NewFromVec3( FACUnit:GetVec3() ) )
if Distance < MinDistance then if Distance < MinDistance then
MinDistance = Distance MinDistance = Distance
NearestFAC = FACUnit NearestFAC = FACUnit

View File

@ -460,7 +460,7 @@ do -- DETECTION_DISPATCHER
local ThreatLevel = Detection:GetTreatLevelA2G( DetectedArea ) local ThreatLevel = Detection:GetTreatLevelA2G( DetectedArea )
local DetectedAreaVec3 = DetectedZone:GetPointVec3() local DetectedAreaVec3 = DetectedZone:GetVec3()
local DetectedAreaPointVec3 = POINT_VEC3:New( DetectedAreaVec3.x, DetectedAreaVec3.y, DetectedAreaVec3.z ) local DetectedAreaPointVec3 = POINT_VEC3:New( DetectedAreaVec3.x, DetectedAreaVec3.y, DetectedAreaVec3.z )
local DetectedAreaPointLL = DetectedAreaPointVec3:ToStringLL( 3, true ) local DetectedAreaPointLL = DetectedAreaPointVec3:ToStringLL( 3, true )
AreaMsg[#AreaMsg+1] = string.format( " - Area #%d - %s - Threat Level [%s] (%2d)", AreaMsg[#AreaMsg+1] = string.format( " - Area #%d - %s - Threat Level [%s] (%2d)",

View File

@ -672,13 +672,13 @@ function ESCORT._HoldPosition( MenuParam )
self.FollowScheduler:Stop() self.FollowScheduler:Stop()
local PointFrom = {} local PointFrom = {}
local GroupPoint = EscortGroup:GetUnit(1):GetPointVec3() local GroupVec3 = EscortGroup:GetUnit(1):GetVec3()
PointFrom = {} PointFrom = {}
PointFrom.x = GroupPoint.x PointFrom.x = GroupVec3.x
PointFrom.y = GroupPoint.z PointFrom.y = GroupVec3.z
PointFrom.speed = 250 PointFrom.speed = 250
PointFrom.type = AI.Task.WaypointType.TURNING_POINT PointFrom.type = AI.Task.WaypointType.TURNING_POINT
PointFrom.alt = GroupPoint.y PointFrom.alt = GroupVec3.y
PointFrom.alt_type = AI.Task.AltitudeType.BARO PointFrom.alt_type = AI.Task.AltitudeType.BARO
local OrbitPoint = OrbitUnit:GetVec2() local OrbitPoint = OrbitUnit:GetVec2()
@ -1004,16 +1004,16 @@ function ESCORT:_FollowScheduler()
self:T( {ClientUnit.UnitName, GroupUnit.UnitName } ) self:T( {ClientUnit.UnitName, GroupUnit.UnitName } )
if self.CT1 == 0 and self.GT1 == 0 then if self.CT1 == 0 and self.GT1 == 0 then
self.CV1 = ClientUnit:GetPointVec3() self.CV1 = ClientUnit:GetVec3()
self:T( { "self.CV1", self.CV1 } ) self:T( { "self.CV1", self.CV1 } )
self.CT1 = timer.getTime() self.CT1 = timer.getTime()
self.GV1 = GroupUnit:GetPointVec3() self.GV1 = GroupUnit:GetVec3()
self.GT1 = timer.getTime() self.GT1 = timer.getTime()
else else
local CT1 = self.CT1 local CT1 = self.CT1
local CT2 = timer.getTime() local CT2 = timer.getTime()
local CV1 = self.CV1 local CV1 = self.CV1
local CV2 = ClientUnit:GetPointVec3() local CV2 = ClientUnit:GetVec3()
self.CT1 = CT2 self.CT1 = CT2
self.CV1 = CV2 self.CV1 = CV2
@ -1027,7 +1027,7 @@ function ESCORT:_FollowScheduler()
local GT1 = self.GT1 local GT1 = self.GT1
local GT2 = timer.getTime() local GT2 = timer.getTime()
local GV1 = self.GV1 local GV1 = self.GV1
local GV2 = GroupUnit:GetPointVec3() local GV2 = GroupUnit:GetVec3()
self.GT1 = GT2 self.GT1 = GT2
self.GV1 = GV2 self.GV1 = GV2
@ -1139,11 +1139,11 @@ function ESCORT:_ReportTargetsScheduler()
-- EscortTargetLastVelocity } ) -- EscortTargetLastVelocity } )
local EscortTargetUnitPositionVec3 = EscortTargetUnit:GetPointVec3() local EscortTargetUnitVec3 = EscortTargetUnit:GetVec3()
local EscortPositionVec3 = self.EscortGroup:GetPointVec3() local EscortVec3 = self.EscortGroup:GetVec3()
local Distance = ( ( EscortTargetUnitPositionVec3.x - EscortPositionVec3.x )^2 + local Distance = ( ( EscortTargetUnitVec3.x - EscortVec3.x )^2 +
( EscortTargetUnitPositionVec3.y - EscortPositionVec3.y )^2 + ( EscortTargetUnitVec3.y - EscortVec3.y )^2 +
( EscortTargetUnitPositionVec3.z - EscortPositionVec3.z )^2 ( EscortTargetUnitVec3.z - EscortVec3.z )^2
) ^ 0.5 / 1000 ) ^ 0.5 / 1000
self:T( { self.EscortGroup:GetName(), EscortTargetUnit:GetName(), Distance, EscortTarget } ) self:T( { self.EscortGroup:GetName(), EscortTargetUnit:GetName(), Distance, EscortTarget } )
@ -1198,11 +1198,11 @@ function ESCORT:_ReportTargetsScheduler()
EscortTargetMessage = EscortTargetMessage .. "Unknown target at " EscortTargetMessage = EscortTargetMessage .. "Unknown target at "
end end
local EscortTargetUnitPositionVec3 = ClientEscortTargetData.AttackUnit:GetPointVec3() local EscortTargetUnitVec3 = ClientEscortTargetData.AttackUnit:GetVec3()
local EscortPositionVec3 = self.EscortGroup:GetPointVec3() local EscortVec3 = self.EscortGroup:GetVec3()
local Distance = ( ( EscortTargetUnitPositionVec3.x - EscortPositionVec3.x )^2 + local Distance = ( ( EscortTargetUnitVec3.x - EscortVec3.x )^2 +
( EscortTargetUnitPositionVec3.y - EscortPositionVec3.y )^2 + ( EscortTargetUnitVec3.y - EscortVec3.y )^2 +
( EscortTargetUnitPositionVec3.z - EscortPositionVec3.z )^2 ( EscortTargetUnitVec3.z - EscortVec3.z )^2
) ^ 0.5 / 1000 ) ^ 0.5 / 1000
self:T( { self.EscortGroup:GetName(), ClientEscortTargetData.AttackUnit:GetName(), Distance, ClientEscortTargetData.AttackUnit } ) self:T( { self.EscortGroup:GetName(), ClientEscortTargetData.AttackUnit:GetName(), Distance, ClientEscortTargetData.AttackUnit } )
@ -1266,9 +1266,9 @@ function ESCORT:_ReportTargetsScheduler()
local TaskPoints = self:RegisterRoute() local TaskPoints = self:RegisterRoute()
for WayPointID, WayPoint in pairs( TaskPoints ) do for WayPointID, WayPoint in pairs( TaskPoints ) do
local EscortPositionVec3 = self.EscortGroup:GetPointVec3() local EscortVec3 = self.EscortGroup:GetVec3()
local Distance = ( ( WayPoint.x - EscortPositionVec3.x )^2 + local Distance = ( ( WayPoint.x - EscortVec3.x )^2 +
( WayPoint.y - EscortPositionVec3.z )^2 ( WayPoint.y - EscortVec3.z )^2
) ^ 0.5 / 1000 ) ^ 0.5 / 1000
MENU_CLIENT_COMMAND:New( self.EscortClient, "Waypoint " .. WayPointID .. " at " .. string.format( "%.2f", Distance ).. "km", self.EscortMenuResumeMission, ESCORT._ResumeMission, { ParamSelf = self, ParamWayPoint = WayPointID } ) MENU_CLIENT_COMMAND:New( self.EscortClient, "Waypoint " .. WayPointID .. " at " .. string.format( "%.2f", Distance ).. "km", self.EscortMenuResumeMission, ESCORT._ResumeMission, { ParamSelf = self, ParamWayPoint = WayPointID } )
end end

View File

@ -485,14 +485,14 @@ function GROUP:GetVec2()
return GroupPointVec2 return GroupPointVec2
end end
--- Returns the current point (Vec3 vector) of the first DCS Unit in the DCS Group. --- Returns the current Vec3 vector of the first DCS Unit in the GROUP.
-- @return DCSTypes#Vec3 Current Vec3 point of the first DCS Unit of the DCS Group. -- @return DCSTypes#Vec3 Current Vec3 of the first DCS Unit of the GROUP.
function GROUP:GetPointVec3() function GROUP:GetVec3()
self:F2( self.GroupName ) self:F2( self.GroupName )
local GroupPointVec3 = self:GetUnit(1):GetPointVec3() local GroupVec3 = self:GetUnit(1):GetVec3()
self:T3( GroupPointVec3 ) self:T3( GroupVec3 )
return GroupPointVec3 return GroupVec3
end end
@ -508,7 +508,8 @@ function GROUP:IsCompletelyInZone( Zone )
for UnitID, UnitData in pairs( self:GetUnits() ) do for UnitID, UnitData in pairs( self:GetUnits() ) do
local Unit = UnitData -- Unit#UNIT local Unit = UnitData -- Unit#UNIT
if Zone:IsPointVec3InZone( Unit:GetPointVec3() ) then -- TODO: Rename IsPointVec3InZone to IsVec3InZone
if Zone:IsPointVec3InZone( Unit:GetVec3() ) then
else else
return false return false
end end
@ -526,7 +527,7 @@ function GROUP:IsPartlyInZone( Zone )
for UnitID, UnitData in pairs( self:GetUnits() ) do for UnitID, UnitData in pairs( self:GetUnits() ) do
local Unit = UnitData -- Unit#UNIT local Unit = UnitData -- Unit#UNIT
if Zone:IsPointVec3InZone( Unit:GetPointVec3() ) then if Zone:IsPointVec3InZone( Unit:GetVec3() ) then
return true return true
end end
end end
@ -543,7 +544,7 @@ function GROUP:IsNotInZone( Zone )
for UnitID, UnitData in pairs( self:GetUnits() ) do for UnitID, UnitData in pairs( self:GetUnits() ) do
local Unit = UnitData -- Unit#UNIT local Unit = UnitData -- Unit#UNIT
if Zone:IsPointVec3InZone( Unit:GetPointVec3() ) then if Zone:IsPointVec3InZone( Unit:GetVec3() ) then
return false return false
end end
end end
@ -731,7 +732,7 @@ end
-- @param #table Template The template of the Group retrieved with GROUP:GetTemplate() -- @param #table Template The template of the Group retrieved with GROUP:GetTemplate()
function GROUP:Respawn( Template ) function GROUP:Respawn( Template )
local Vec3 = self:GetPointVec3() local Vec3 = self:GetVec3()
Template.x = Vec3.x Template.x = Vec3.x
Template.y = Vec3.z Template.y = Vec3.z
--Template.x = nil --Template.x = nil
@ -742,7 +743,7 @@ function GROUP:Respawn( Template )
local GroupUnit = UnitData -- Unit#UNIT local GroupUnit = UnitData -- Unit#UNIT
self:E( GroupUnit:GetName() ) self:E( GroupUnit:GetName() )
if GroupUnit:IsAlive() then if GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetPointVec3() local GroupUnitVec3 = GroupUnit:GetVec3()
local GroupUnitHeading = GroupUnit:GetHeading() local GroupUnitHeading = GroupUnit:GetHeading()
Template.units[UnitID].alt = GroupUnitVec3.y Template.units[UnitID].alt = GroupUnitVec3.y
Template.units[UnitID].x = GroupUnitVec3.x Template.units[UnitID].x = GroupUnitVec3.x

View File

@ -512,11 +512,11 @@ function MISSILETRAINER:_AddRange( Client, TrainerWeapon )
if self.DetailsRangeOnOff then if self.DetailsRangeOnOff then
local PositionMissile = TrainerWeapon:getPoint() local PositionMissile = TrainerWeapon:getPoint()
local PositionTarget = Client:GetPointVec3() local TargetVec3 = Client:GetVec3()
local Range = ( ( PositionMissile.x - PositionTarget.x )^2 + local Range = ( ( PositionMissile.x - TargetVec3.x )^2 +
( PositionMissile.y - PositionTarget.y )^2 + ( PositionMissile.y - TargetVec3.y )^2 +
( PositionMissile.z - PositionTarget.z )^2 ( PositionMissile.z - TargetVec3.z )^2
) ^ 0.5 / 1000 ) ^ 0.5 / 1000
RangeText = string.format( ", at %4.2fkm", Range ) RangeText = string.format( ", at %4.2fkm", Range )
@ -532,11 +532,11 @@ function MISSILETRAINER:_AddBearing( Client, TrainerWeapon )
if self.DetailsBearingOnOff then if self.DetailsBearingOnOff then
local PositionMissile = TrainerWeapon:getPoint() local PositionMissile = TrainerWeapon:getPoint()
local PositionTarget = Client:GetPointVec3() local TargetVec3 = Client:GetVec3()
self:T2( { PositionTarget, PositionMissile }) self:T2( { TargetVec3, PositionMissile })
local DirectionVector = { x = PositionMissile.x - PositionTarget.x, y = PositionMissile.y - PositionTarget.y, z = PositionMissile.z - PositionTarget.z } local DirectionVector = { x = PositionMissile.x - TargetVec3.x, y = PositionMissile.y - TargetVec3.y, z = PositionMissile.z - TargetVec3.z }
local DirectionRadians = math.atan2( DirectionVector.z, DirectionVector.x ) local DirectionRadians = math.atan2( DirectionVector.z, DirectionVector.x )
--DirectionRadians = DirectionRadians + routines.getNorthCorrection( PositionTarget ) --DirectionRadians = DirectionRadians + routines.getNorthCorrection( PositionTarget )
if DirectionRadians < 0 then if DirectionRadians < 0 then
@ -580,11 +580,11 @@ function MISSILETRAINER:_TrackMissiles()
if Client and Client:IsAlive() and TrainerSourceUnit and TrainerSourceUnit:IsAlive() and TrainerWeapon and TrainerWeapon:isExist() and TrainerTargetUnit and TrainerTargetUnit:IsAlive() then if Client and Client:IsAlive() and TrainerSourceUnit and TrainerSourceUnit:IsAlive() and TrainerWeapon and TrainerWeapon:isExist() and TrainerTargetUnit and TrainerTargetUnit:IsAlive() then
local PositionMissile = TrainerWeapon:getPosition().p local PositionMissile = TrainerWeapon:getPosition().p
local PositionTarget = Client:GetPointVec3() local TargetVec3 = Client:GetVec3()
local Distance = ( ( PositionMissile.x - PositionTarget.x )^2 + local Distance = ( ( PositionMissile.x - TargetVec3.x )^2 +
( PositionMissile.y - PositionTarget.y )^2 + ( PositionMissile.y - TargetVec3.y )^2 +
( PositionMissile.z - PositionTarget.z )^2 ( PositionMissile.z - TargetVec3.z )^2
) ^ 0.5 / 1000 ) ^ 0.5 / 1000
if Distance <= self.Distance then if Distance <= self.Distance then

View File

@ -0,0 +1,8 @@
local Mission = MISSION:New( "Pickup Cargo", "High", "Test for Cargo Pickup", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 300 )
local CargoCarrier = UNIT:FindByName( "CargoCarrier" )
InfantryCargo:OnBoard( CargoCarrier )

View File

@ -68,5 +68,22 @@ function OBJECT:GetID()
return nil return nil
end end
--- Destroys the OBJECT.
-- @param #OBJECT self
-- @return #nil The DCS Unit is not existing or alive.
function OBJECT:Destroy()
self:F2( self.ObjectName )
local DCSObject = self:GetDCSObject()
if DCSObject then
DCSObject:destroy()
end
return nil
end

View File

@ -31,7 +31,9 @@
--- The POINT_VEC3 class --- The POINT_VEC3 class
-- @type POINT_VEC3 -- @type POINT_VEC3
-- @extends Base#BASE -- @extends Base#BASE
-- @field DCSTypes#Vec3 PointVec3 -- @field #number x The x coordinate in 3D space.
-- @field #number y The y coordinate in 3D space.
-- @field #number z The z coordiante in 3D space.
-- @field #POINT_VEC3.SmokeColor SmokeColor -- @field #POINT_VEC3.SmokeColor SmokeColor
-- @field #POINT_VEC3.FlareColor FlareColor -- @field #POINT_VEC3.FlareColor FlareColor
-- @field #POINT_VEC3.RoutePointAltType RoutePointAltType -- @field #POINT_VEC3.RoutePointAltType RoutePointAltType
@ -113,8 +115,9 @@ POINT_VEC3 = {
function POINT_VEC3:New( x, y, z ) function POINT_VEC3:New( x, y, z )
local self = BASE:Inherit( self, BASE:New() ) local self = BASE:Inherit( self, BASE:New() )
self.PointVec3 = { x = x, y = y, z = z } self.x = x
self:F2( self.PointVec3 ) self.y = y
self.z = z
return self return self
end end
@ -132,14 +135,14 @@ end
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @return DCSTypes#Vec3 The Vec3 coodinate. -- @return DCSTypes#Vec3 The Vec3 coodinate.
function POINT_VEC3:GetVec3() function POINT_VEC3:GetVec3()
return self.PointVec3 return { x = self.x, y = self.y, z = self.z }
end end
--- Return the coordinates of the POINT_VEC3 in Vec2 format. --- Return the coordinates of the POINT_VEC3 in Vec2 format.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @return DCSTypes#Vec2 The Vec2 coodinate. -- @return DCSTypes#Vec2 The Vec2 coodinate.
function POINT_VEC3:GetVec2() function POINT_VEC3:GetVec2()
return { x = self.PointVec3.x, y = self.PointVec3.z } return { x = self.x, y = self.z }
end end
@ -147,33 +150,48 @@ end
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @return #number The x coodinate. -- @return #number The x coodinate.
function POINT_VEC3:GetX() function POINT_VEC3:GetX()
self:F2(self.PointVec3.x) return self.x
return self.PointVec3.x
end end
--- Return the y coordinate of the POINT_VEC3. --- Return the y coordinate of the POINT_VEC3.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @return #number The y coodinate. -- @return #number The y coodinate.
function POINT_VEC3:GetY() function POINT_VEC3:GetY()
self:F2(self.PointVec3.y) return self.y
return self.PointVec3.y
end end
--- Return the z coordinate of the POINT_VEC3. --- Return the z coordinate of the POINT_VEC3.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @return #number The z coodinate. -- @return #number The z coodinate.
function POINT_VEC3:GetZ() function POINT_VEC3:GetZ()
self:F2(self.PointVec3.z) return self.z
return self.PointVec3.z
end end
--- Return a random Vec3 point within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3. --- Set the x coordinate of the POINT_VEC3.
-- @param #number x The x coordinate.
function POINT_VEC3:SetX( x )
self.x = x
end
--- Set the y coordinate of the POINT_VEC3.
-- @param #number y The y coordinate.
function POINT_VEC3:SetY( y )
self.y = y
end
--- Set the z coordinate of the POINT_VEC3.
-- @param #number z The z coordinate.
function POINT_VEC3:SetZ( z )
self.z = z
end
--- Return a random Vec2 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @param DCSTypes#Distance OuterRadius -- @param DCSTypes#Distance OuterRadius
-- @param DCSTypes#Distance InnerRadius -- @param DCSTypes#Distance InnerRadius
-- @return DCSTypes#Vec2 Vec2 -- @return DCSTypes#Vec2 Vec2
function POINT_VEC3:GetRandomVec2InRadius( OuterRadius, InnerRadius ) function POINT_VEC3:GetRandomVec2InRadius( OuterRadius, InnerRadius )
self:F2( { self.PointVec3, OuterRadius, InnerRadius } ) self:F2( { OuterRadius, InnerRadius } )
local Theta = 2 * math.pi * math.random() local Theta = 2 * math.pi * math.random()
local Radials = math.random() + math.random() local Radials = math.random() + math.random()
@ -188,17 +206,28 @@ function POINT_VEC3:GetRandomVec2InRadius( OuterRadius, InnerRadius )
RadialMultiplier = OuterRadius * Radials RadialMultiplier = OuterRadius * Radials
end end
local RandomVec3 local RandomVec2
if OuterRadius > 0 then 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 else
RandomVec3 = { x = self:GetX(), y = self:GetZ() } RandomVec2 = { x = self:GetX(), y = self:GetZ() }
end end
return RandomVec3 return RandomVec2
end 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:GetRandomVec2InRadius( 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 #POINT_VEC3 self
-- @param DCSTypes#Distance OuterRadius -- @param DCSTypes#Distance OuterRadius
-- @param DCSTypes#Distance InnerRadius -- @param DCSTypes#Distance InnerRadius
@ -212,10 +241,20 @@ function POINT_VEC3:GetRandomVec3InRadius( OuterRadius, InnerRadius )
return RandomVec3 return RandomVec3
end 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. --- Return a direction vector Vec3 from POINT_VEC3 to the POINT_VEC3.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @param #POINT_VEC3 TargetPointVec3 The target PointVec3. -- @param #POINT_VEC3 TargetPointVec3 The target POINT_VEC3.
-- @return DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format. -- @return DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format.
function POINT_VEC3:GetDirectionVec3( TargetPointVec3 ) function POINT_VEC3:GetDirectionVec3( TargetPointVec3 )
return { x = TargetPointVec3:GetX() - self:GetX(), y = TargetPointVec3:GetY() - self:GetY(), z = TargetPointVec3:GetZ() - self:GetZ() } return { x = TargetPointVec3:GetX() - self:GetX(), y = TargetPointVec3:GetY() - self:GetY(), z = TargetPointVec3:GetZ() - self:GetZ() }
@ -247,7 +286,7 @@ end
--- Return the 2D distance in meters between the target POINT_VEC3 and the POINT_VEC3. --- Return the 2D distance in meters between the target POINT_VEC3 and the POINT_VEC3.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @param #POINT_VEC3 TargetPointVec3 The target PointVec3. -- @param #POINT_VEC3 TargetPointVec3 The target POINT_VEC3.
-- @return DCSTypes#Distance Distance The distance in meters. -- @return DCSTypes#Distance Distance The distance in meters.
function POINT_VEC3:Get2DDistance( TargetPointVec3 ) function POINT_VEC3:Get2DDistance( TargetPointVec3 )
local TargetVec3 = TargetPointVec3:GetVec3() local TargetVec3 = TargetPointVec3:GetVec3()
@ -257,7 +296,7 @@ end
--- Return the 3D distance in meters between the target POINT_VEC3 and the POINT_VEC3. --- Return the 3D distance in meters between the target POINT_VEC3 and the POINT_VEC3.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @param #POINT_VEC3 TargetPointVec3 The target PointVec3. -- @param #POINT_VEC3 TargetPointVec3 The target POINT_VEC3.
-- @return DCSTypes#Distance Distance The distance in meters. -- @return DCSTypes#Distance Distance The distance in meters.
function POINT_VEC3:Get3DDistance( TargetPointVec3 ) function POINT_VEC3:Get3DDistance( TargetPointVec3 )
local TargetVec3 = TargetPointVec3:GetVec3() local TargetVec3 = TargetPointVec3:GetVec3()
@ -294,7 +333,7 @@ end
function POINT_VEC3:ToStringLL( acc, DMS ) function POINT_VEC3:ToStringLL( acc, DMS )
acc = acc or 3 acc = acc or 3
local lat, lon = coord.LOtoLL( self.PointVec3 ) local lat, lon = coord.LOtoLL( self:GetVec3() )
return UTILS.tostringLL(lat, lon, acc, DMS) return UTILS.tostringLL(lat, lon, acc, DMS)
end end
@ -311,7 +350,7 @@ end
--- Return a BR string from a POINT_VEC3 to the POINT_VEC3. --- Return a BR string from a POINT_VEC3 to the POINT_VEC3.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @param #POINT_VEC3 TargetPointVec3 The target PointVec3. -- @param #POINT_VEC3 TargetPointVec3 The target POINT_VEC3.
-- @return #string The BR text. -- @return #string The BR text.
function POINT_VEC3:GetBRText( TargetPointVec3 ) function POINT_VEC3:GetBRText( TargetPointVec3 )
local DirectionVec3 = self:GetDirectionVec3( TargetPointVec3 ) local DirectionVec3 = self:GetDirectionVec3( TargetPointVec3 )
@ -349,9 +388,9 @@ function POINT_VEC3:RoutePointAir( AltType, Type, Action, Speed, SpeedLocked )
self:F2( { AltType, Type, Action, Speed, SpeedLocked } ) self:F2( { AltType, Type, Action, Speed, SpeedLocked } )
local RoutePoint = {} local RoutePoint = {}
RoutePoint.x = self.PointVec3.x RoutePoint.x = self:GetX()
RoutePoint.y = self.PointVec3.z RoutePoint.y = self:GetZ()
RoutePoint.alt = self.PointVec3.y RoutePoint.alt = self:GetY()
RoutePoint.alt_type = AltType RoutePoint.alt_type = AltType
RoutePoint.type = Type RoutePoint.type = Type
@ -381,13 +420,52 @@ function POINT_VEC3:RoutePointAir( AltType, Type, Action, Speed, SpeedLocked )
return RoutePoint return RoutePoint
end end
--- Build an ground type route point.
-- @param #POINT_VEC3 self
-- @param DCSTypes#Speed Speed Speed in km/h.
-- @param #POINT_VEC3.RoutePointAction Formation The route point Formation.
-- @return #table The route point.
function POINT_VEC3:RoutePointGround( Speed, Formation )
self:F2( { Formation, Speed } )
local RoutePoint = {}
RoutePoint.x = self:GetX()
RoutePoint.y = self:GetZ()
RoutePoint.action = Formation or ""
RoutePoint.speed = Speed / 3.6
RoutePoint.speed_locked = true
-- ["task"] =
-- {
-- ["id"] = "ComboTask",
-- ["params"] =
-- {
-- ["tasks"] =
-- {
-- }, -- end of ["tasks"]
-- }, -- end of ["params"]
-- }, -- end of ["task"]
RoutePoint.task = {}
RoutePoint.task.id = "ComboTask"
RoutePoint.task.params = {}
RoutePoint.task.params.tasks = {}
return RoutePoint
end
--- Smokes the point in a color. --- Smokes the point in a color.
-- @param #POINT_VEC3 self -- @param #POINT_VEC3 self
-- @param Point#POINT_VEC3.SmokeColor SmokeColor -- @param Point#POINT_VEC3.SmokeColor SmokeColor
function POINT_VEC3:Smoke( SmokeColor ) function POINT_VEC3:Smoke( SmokeColor )
self:F2( { SmokeColor, self.PointVec3 } ) self:F2( { SmokeColor } )
trigger.action.smoke( self.PointVec3, SmokeColor ) trigger.action.smoke( self:GetVec3(), SmokeColor )
end end
--- Smoke the POINT_VEC3 Green. --- Smoke the POINT_VEC3 Green.
@ -430,8 +508,8 @@ end
-- @param Point#POINT_VEC3.FlareColor -- @param Point#POINT_VEC3.FlareColor
-- @param DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. -- @param DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0.
function POINT_VEC3:Flare( FlareColor, Azimuth ) function POINT_VEC3:Flare( FlareColor, Azimuth )
self:F2( { FlareColor, self.PointVec3 } ) self:F2( { FlareColor } )
trigger.action.signalFlare( self.PointVec3, FlareColor, Azimuth and Azimuth or 0 ) trigger.action.signalFlare( self:GetVec3(), FlareColor, Azimuth and Azimuth or 0 )
end end
--- Flare the POINT_VEC3 White. --- Flare the POINT_VEC3 White.
@ -468,8 +546,9 @@ end
--- The POINT_VEC2 class --- The POINT_VEC2 class
-- @type POINT_VEC2 -- @type POINT_VEC2
-- @field DCSTypes#Vec2 PointVec2
-- @extends Point#POINT_VEC3 -- @extends Point#POINT_VEC3
-- @field #number x The x coordinate in 2D space.
-- @field #number y the y coordinate in 2D space.
POINT_VEC2 = { POINT_VEC2 = {
ClassName = "POINT_VEC2", ClassName = "POINT_VEC2",
} }
@ -483,14 +562,11 @@ POINT_VEC2 = {
function POINT_VEC2:New( x, y, LandHeightAdd ) function POINT_VEC2:New( x, y, LandHeightAdd )
local LandHeight = land.getHeight( { ["x"] = x, ["y"] = y } ) local LandHeight = land.getHeight( { ["x"] = x, ["y"] = y } )
if LandHeightAdd then
LandHeightAdd = LandHeightAdd or 0
LandHeight = LandHeight + LandHeightAdd LandHeight = LandHeight + LandHeightAdd
end
local self = BASE:Inherit( self, POINT_VEC3:New( x, LandHeight, y ) ) local self = BASE:Inherit( self, POINT_VEC3:New( x, LandHeight, y ) )
self:F2( { x, y, LandHeightAdd } )
self.PointVec2 = { x = x, y = y }
return self return self
end end
@ -501,30 +577,77 @@ end
-- @return Point#POINT_VEC2 self -- @return Point#POINT_VEC2 self
function POINT_VEC2:NewFromVec2( Vec2, LandHeightAdd ) function POINT_VEC2:NewFromVec2( Vec2, LandHeightAdd )
local self = BASE:Inherit( self, BASE:New() )
local LandHeight = land.getHeight( Vec2 ) local LandHeight = land.getHeight( Vec2 )
if LandHeightAdd then
LandHeightAdd = LandHeightAdd or 0
LandHeight = LandHeight + LandHeightAdd LandHeight = LandHeight + LandHeightAdd
end
local self = BASE:Inherit( self, POINT_VEC3:New( Vec2.x, LandHeight, Vec2.y ) ) local self = BASE:Inherit( self, POINT_VEC3:New( Vec2.x, LandHeight, Vec2.y ) )
self:F2( { Vec2.x, Vec2.y, LandHeightAdd } ) self:F2( { Vec2.x, Vec2.y, LandHeightAdd } )
self.PointVec2 = Vec2 return self
self:F2( self.PointVec3 ) end
--- Create a new POINT_VEC2 object from Vec3 coordinates.
-- @param #POINT_VEC2 self
-- @param DCSTypes#Vec3 Vec3 The Vec3 point.
-- @return Point#POINT_VEC2 self
function POINT_VEC2:NewFromVec3( Vec3 )
local self = BASE:Inherit( self, BASE:New() )
local Vec2 = { x = Vec3.x, y = Vec3.z }
local LandHeight = land.getHeight( Vec2 )
local self = BASE:Inherit( self, POINT_VEC3:New( Vec2.x, LandHeight, Vec2.y ) )
self:F2( { Vec2.x, LandHeight, Vec2.y } )
return self return self
end end
--- Calculate the distance from a reference @{Point#POINT_VEC2}. --- Return the x coordinate of the POINT_VEC2.
-- @param #POINT_VEC2 self -- @param #POINT_VEC2 self
-- @param #POINT_VEC2 PointVec2Reference The reference @{Point#POINT_VEC2}. -- @return #number The x coodinate.
-- @return DCSTypes#Distance The distance from the reference @{Point#POINT_VEC2} in meters. function POINT_VEC2:GetX()
return self.x
end
--- Return the y coordinate of the POINT_VEC2.
-- @param #POINT_VEC2 self
-- @return #number The y coodinate.
function POINT_VEC2:GetY()
return self.z
end
--- Return the altitude of the land at the POINT_VEC2.
-- @param #POINT_VEC2 self
-- @return #number The land altitude.
function POINT_VEC2:GetAlt()
return land.getHeight( { x = self.x, y = self.z } )
end
--- Set the x coordinate of the POINT_VEC2.
-- @param #number x The x coordinate.
function POINT_VEC2:SetX( x )
self.x = x
end
--- Set the y coordinate of the POINT_VEC2.
-- @param #number y The y coordinate.
function POINT_VEC2:SetY( y )
self.z = y
end
--- Calculate the distance from a reference @{#POINT_VEC2}.
-- @param #POINT_VEC2 self
-- @param #POINT_VEC2 PointVec2Reference The reference @{#POINT_VEC2}.
-- @return DCSTypes#Distance The distance from the reference @{#POINT_VEC2} in meters.
function POINT_VEC2:DistanceFromPointVec2( PointVec2Reference ) function POINT_VEC2:DistanceFromPointVec2( PointVec2Reference )
self:F2( PointVec2Reference ) self:F2( PointVec2Reference )
local Distance = ( ( PointVec2Reference.PointVec2.x - self.PointVec2.x ) ^ 2 + ( PointVec2Reference.PointVec2.y - self.PointVec2.y ) ^2 ) ^0.5 local Distance = ( ( PointVec2Reference:GetX() - self:GetX() ) ^ 2 + ( PointVec2Reference:GetY() - self:GetY() ) ^2 ) ^0.5
self:T2( Distance ) self:T2( Distance )
return Distance return Distance
@ -537,7 +660,7 @@ end
function POINT_VEC2:DistanceFromVec2( Vec2Reference ) function POINT_VEC2:DistanceFromVec2( Vec2Reference )
self:F2( Vec2Reference ) self:F2( Vec2Reference )
local Distance = ( ( Vec2Reference.x - self.PointVec2.x ) ^ 2 + ( Vec2Reference.y - self.PointVec2.y ) ^2 ) ^0.5 local Distance = ( ( Vec2Reference.x - self:GetX() ) ^ 2 + ( Vec2Reference.y - self:GetY() ) ^2 ) ^0.5
self:T2( Distance ) self:T2( Distance )
return Distance return Distance
@ -551,3 +674,20 @@ function POINT_VEC2:GetAltitudeText()
return '' return ''
end end
--- Add a Distance in meters from the POINT_VEC2 orthonormal plane, with the given angle, and calculate the new POINT_VEC2.
-- @param #POINT_VEC2 self
-- @param DCSTypes#Distance Distance The Distance to be added in meters.
-- @param DCSTypes#Angle Angle The Angle in degrees.
-- @return #POINT_VEC2 The new calculated POINT_VEC2.
function POINT_VEC2:Translate( Distance, Angle )
local SX = self:GetX()
local SY = self:GetY()
local Radians = Angle / 180 * math.pi
local TX = Distance * math.cos( Radians ) + SX
local TY = Distance * math.sin( Radians ) + SY
return POINT_VEC2:New( TX, TY )
end

View File

@ -2,11 +2,11 @@
-- --
-- 1) @{Positionable#POSITIONABLE} class, extends @{Identifiable#IDENTIFIABLE} -- 1) @{Positionable#POSITIONABLE} class, extends @{Identifiable#IDENTIFIABLE}
-- =========================================================== -- ===========================================================
-- The @{Positionable#POSITIONABLE} class is a wrapper class to handle the DCS Positionable objects: -- The @{Positionable#POSITIONABLE} class is a wrapper class to handle the POSITIONABLE objects:
-- --
-- * Support all DCS Positionable APIs. -- * Support all DCS APIs.
-- * Enhance with Positionable specific APIs not in the DCS Positionable API set. -- * Enhance with POSITIONABLE specific APIs not in the DCS API set.
-- * Manage the "state" of the DCS Positionable. -- * Manage the "state" of the POSITIONABLE.
-- --
-- 1.1) POSITIONABLE constructor: -- 1.1) POSITIONABLE constructor:
-- ------------------------------ -- ------------------------------
@ -41,7 +41,7 @@ POSITIONABLE = {
--- Create a new POSITIONABLE from a DCSPositionable --- Create a new POSITIONABLE from a DCSPositionable
-- @param #POSITIONABLE self -- @param #POSITIONABLE self
-- @param DCSPositionable#Positionable PositionableName The DCS Positionable name -- @param DCSPositionable#Positionable PositionableName The POSITIONABLE name
-- @return #POSITIONABLE self -- @return #POSITIONABLE self
function POSITIONABLE:New( PositionableName ) function POSITIONABLE:New( PositionableName )
local self = BASE:Inherit( self, IDENTIFIABLE:New( PositionableName ) ) local self = BASE:Inherit( self, IDENTIFIABLE:New( PositionableName ) )
@ -49,10 +49,10 @@ function POSITIONABLE:New( PositionableName )
return self return self
end end
--- Returns the @{DCSTypes#Position3} position vectors indicating the point and direction vectors in 3D of the DCS Positionable within the mission. --- Returns the @{DCSTypes#Position3} position vectors indicating the point and direction vectors in 3D of the POSITIONABLE within the mission.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return DCSTypes#Position The 3D position vectors of the DCS Positionable. -- @return DCSTypes#Position The 3D position vectors of the POSITIONABLE.
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetPositionVec3() function POSITIONABLE:GetPositionVec3()
self:F2( self.PositionableName ) self:F2( self.PositionableName )
@ -67,21 +67,42 @@ function POSITIONABLE:GetPositionVec3()
return nil return nil
end end
--- Returns the @{DCSTypes#Vec2} vector indicating the point in 2D of the DCS Positionable within the mission. --- Returns the @{DCSTypes#Vec2} vector indicating the point in 2D of the POSITIONABLE within the mission.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return DCSTypes#Vec2 The 2D point vector of the DCS Positionable. -- @return DCSTypes#Vec2 The 2D point vector of the POSITIONABLE.
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetVec2() function POSITIONABLE:GetVec2()
self:F2( self.PositionableName ) self:F2( self.PositionableName )
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
if DCSPositionable then if DCSPositionable then
local PositionablePointVec3 = DCSPositionable:getPosition().p local PositionableVec3 = DCSPositionable:getPosition().p
local PositionablePointVec2 = {} local PositionableVec2 = {}
PositionablePointVec2.x = PositionablePointVec3.x PositionableVec2.x = PositionableVec3.x
PositionablePointVec2.y = PositionablePointVec3.z PositionableVec2.y = PositionableVec3.z
self:T2( PositionableVec2 )
return PositionableVec2
end
return nil
end
--- Returns a POINT_VEC2 object indicating the point in 2D of the POSITIONABLE within the mission.
-- @param Positionable#POSITIONABLE self
-- @return Point#POINT_VEC2 The 2D point vector of the POSITIONABLE.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetPointVec2()
self:F2( self.PositionableName )
local DCSPositionable = self:GetDCSObject()
if DCSPositionable then
local PositionableVec3 = DCSPositionable:getPosition().p
local PositionablePointVec2 = POINT_VEC2:NewFromVec3( PositionableVec3 )
self:T2( PositionablePointVec2 ) self:T2( PositionablePointVec2 )
return PositionablePointVec2 return PositionablePointVec2
@ -91,52 +112,52 @@ function POSITIONABLE:GetVec2()
end end
--- Returns a random @{DCSTypes#Vec3} vector within a range, indicating the point in 3D of the DCS Positionable within the mission. --- Returns a random @{DCSTypes#Vec3} vector within a range, indicating the point in 3D of the POSITIONABLE within the mission.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return DCSTypes#Vec3 The 3D point vector of the DCS Positionable. -- @return DCSTypes#Vec3 The 3D point vector of the POSITIONABLE.
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetRandomPointVec3( Radius ) function POSITIONABLE:GetRandomVec3( Radius )
self:F2( self.PositionableName ) self:F2( self.PositionableName )
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
if DCSPositionable then if DCSPositionable then
local PositionablePointVec3 = DCSPositionable:getPosition().p local PositionablePointVec3 = DCSPositionable:getPosition().p
local PositionableRandomPointVec3 = {} local PositionableRandomVec3 = {}
local angle = math.random() * math.pi*2; local angle = math.random() * math.pi*2;
PositionableRandomPointVec3.x = PositionablePointVec3.x + math.cos( angle ) * math.random() * Radius; PositionableRandomVec3.x = PositionablePointVec3.x + math.cos( angle ) * math.random() * Radius;
PositionableRandomPointVec3.y = PositionablePointVec3.y PositionableRandomVec3.y = PositionablePointVec3.y
PositionableRandomPointVec3.z = PositionablePointVec3.z + math.sin( angle ) * math.random() * Radius; PositionableRandomVec3.z = PositionablePointVec3.z + math.sin( angle ) * math.random() * Radius;
self:T3( PositionableRandomPointVec3 ) self:T3( PositionableRandomVec3 )
return PositionableRandomPointVec3 return PositionableRandomVec3
end end
return nil return nil
end end
--- Returns the @{DCSTypes#Vec3} vector indicating the point in 3D of the DCS Positionable within the mission. --- Returns the @{DCSTypes#Vec3} vector indicating the 3D vector of the POSITIONABLE within the mission.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return DCSTypes#Vec3 The 3D point vector of the DCS Positionable. -- @return DCSTypes#Vec3 The 3D point vector of the POSITIONABLE.
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetPointVec3() function POSITIONABLE:GetVec3()
self:F2( self.PositionableName ) self:F2( self.PositionableName )
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
if DCSPositionable then if DCSPositionable then
local PositionablePointVec3 = DCSPositionable:getPosition().p local PositionableVec3 = DCSPositionable:getPosition().p
self:T3( PositionablePointVec3 ) self:T3( PositionableVec3 )
return PositionablePointVec3 return PositionableVec3
end end
return nil return nil
end end
--- Returns the altitude of the DCS Positionable. --- Returns the altitude of the POSITIONABLE.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return DCSTypes#Distance The altitude of the DCS Positionable. -- @return DCSTypes#Distance The altitude of the POSITIONABLE.
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetAltitude() function POSITIONABLE:GetAltitude()
self:F2() self:F2()
@ -153,7 +174,7 @@ end
--- Returns if the Positionable is located above a runway. --- Returns if the Positionable is located above a runway.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return #boolean true if Positionable is above a runway. -- @return #boolean true if Positionable is above a runway.
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:IsAboveRunway() function POSITIONABLE:IsAboveRunway()
self:F2( self.PositionableName ) self:F2( self.PositionableName )
@ -161,8 +182,8 @@ function POSITIONABLE:IsAboveRunway()
if DCSPositionable then if DCSPositionable then
local PointVec2 = self:GetVec2() local Vec2 = self:GetVec2()
local SurfaceType = land.getSurfaceType( PointVec2 ) local SurfaceType = land.getSurfaceType( Vec2 )
local IsAboveRunway = SurfaceType == land.SurfaceType.RUNWAY local IsAboveRunway = SurfaceType == land.SurfaceType.RUNWAY
self:T2( IsAboveRunway ) self:T2( IsAboveRunway )
@ -174,9 +195,9 @@ end
--- Returns the DCS Positionable heading. --- Returns the POSITIONABLE heading in degrees.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return #number The DCS Positionable heading -- @return #number The POSTIONABLE heading
function POSITIONABLE:GetHeading() function POSITIONABLE:GetHeading()
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
@ -188,6 +209,7 @@ function POSITIONABLE:GetHeading()
if PositionableHeading < 0 then if PositionableHeading < 0 then
PositionableHeading = PositionableHeading + 2 * math.pi PositionableHeading = PositionableHeading + 2 * math.pi
end end
PositionableHeading = PositionableHeading * 180 / math.pi
self:T2( PositionableHeading ) self:T2( PositionableHeading )
return PositionableHeading return PositionableHeading
end end
@ -197,10 +219,10 @@ function POSITIONABLE:GetHeading()
end end
--- Returns true if the DCS Positionable is in the air. --- Returns true if the POSITIONABLE is in the air.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return #boolean true if in the air. -- @return #boolean true if in the air.
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:InAir() function POSITIONABLE:InAir()
self:F2( self.PositionableName ) self:F2( self.PositionableName )
@ -215,10 +237,10 @@ function POSITIONABLE:InAir()
return nil return nil
end end
--- Returns the DCS Positionable velocity vector. --- Returns the POSITIONABLE velocity vector.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return DCSTypes#Vec3 The velocity vector -- @return DCSTypes#Vec3 The velocity vector
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetVelocity() function POSITIONABLE:GetVelocity()
self:F2( self.PositionableName ) self:F2( self.PositionableName )
@ -233,10 +255,10 @@ function POSITIONABLE:GetVelocity()
return nil return nil
end end
--- Returns the @{Unit#UNIT} velocity in km/h. --- Returns the POSITIONABLE velocity in km/h.
-- @param Positionable#POSITIONABLE self -- @param Positionable#POSITIONABLE self
-- @return #number The velocity in km/h -- @return #number The velocity in km/h
-- @return #nil The DCS Positionable is not existing or alive. -- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetVelocityKMH() function POSITIONABLE:GetVelocityKMH()
self:F2( self.PositionableName ) self:F2( self.PositionableName )

View File

@ -162,9 +162,9 @@ function PROCESS_JTAC:OnJTACMenuSpot( Fsm, Event, From, To, TargetUnit )
TaskJTAC.Spots[TargetUnitName] = TaskJTAC.Spots[TargetUnitName] or {} TaskJTAC.Spots[TargetUnitName] = TaskJTAC.Spots[TargetUnitName] or {}
local DCSFACObject = self.FACUnit:GetDCSObject() local DCSFACObject = self.FACUnit:GetDCSObject()
local TargetVec3 = TargetUnit:GetPointVec3() local TargetVec3 = TargetUnit:GetVec3()
TaskJTAC.Spots[TargetUnitName] = Spot.createInfraRed( self.FACUnit:GetDCSObject(), { x = 0, y = 1, z = 0 }, TargetUnit:GetPointVec3(), math.random( 1000, 9999 ) ) TaskJTAC.Spots[TargetUnitName] = Spot.createInfraRed( self.FACUnit:GetDCSObject(), { x = 0, y = 1, z = 0 }, TargetUnit:GetVec3(), math.random( 1000, 9999 ) )
local SpotData = TaskJTAC.Spots[TargetUnitName] local SpotData = TaskJTAC.Spots[TargetUnitName]
self.FACUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " with laser code " .. SpotData:getCode(), 15, self.ProcessGroup ) self.FACUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " with laser code " .. SpotData:getCode(), 15, self.ProcessGroup )

View File

@ -0,0 +1,173 @@
--- @module Process_Pickup
--- PROCESS_PICKUP class
-- @type PROCESS_PICKUP
-- @field Unit#UNIT ProcessUnit
-- @field Set#SET_UNIT TargetSetUnit
-- @extends Process#PROCESS
PROCESS_PICKUP = {
ClassName = "PROCESS_PICKUP",
Fsm = {},
TargetSetUnit = nil,
}
--- Creates a new DESTROY process.
-- @param #PROCESS_PICKUP self
-- @param Task#TASK Task
-- @param Unit#UNIT ProcessUnit
-- @param Set#SET_UNIT TargetSetUnit
-- @return #PROCESS_PICKUP self
function PROCESS_PICKUP:New( Task, ProcessName, ProcessUnit )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( ProcessName, Task, ProcessUnit ) ) -- #PROCESS_PICKUP
self.DisplayInterval = 30
self.DisplayCount = 30
self.DisplayMessage = true
self.DisplayTime = 10 -- 10 seconds is the default
self.DisplayCategory = "HQ" -- Targets is the default display category
self.Fsm = STATEMACHINE_PROCESS:New( self, {
initial = 'Assigned',
events = {
{ name = 'Start', from = 'Assigned', to = 'Navigating' },
{ name = 'Start', from = 'Navigating', to = 'Navigating' },
{ name = 'Nearby', from = 'Navigating', to = 'Preparing' },
{ name = 'Pickup', from = 'Preparing', to = 'Loading' },
{ name = 'Load', from = 'Loading', to = 'Success' },
{ name = 'Fail', from = 'Assigned', to = 'Failed' },
{ name = 'Fail', from = 'Navigating', to = 'Failed' },
{ name = 'Fail', from = 'Preparing', to = 'Failed' },
},
callbacks = {
onStart = self.OnStart,
onNearby = self.OnNearby,
onPickup = self.OnPickup,
onLoad = self.OnLoad,
},
endstates = { 'Success', 'Failed' }
} )
return self
end
--- Process Events
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_PICKUP self
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_PICKUP:OnStart( Fsm, Event, From, To )
self:NextEvent( Fsm.Start )
end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_PICKUP self
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_PICKUP:OnNavigating( Fsm, Event, From, To )
local TaskGroup = self.ProcessUnit:GetGroup()
if self.DisplayCount >= self.DisplayInterval then
MESSAGE:New( "Your group with assigned " .. self.Task:GetName() .. " task has " .. self.TargetSetUnit:GetUnitTypesText() .. " targets left to be destroyed.", 5, "HQ" ):ToGroup( TaskGroup )
self.DisplayCount = 1
else
self.DisplayCount = self.DisplayCount + 1
end
return true -- Process always the event.
end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_PICKUP self
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Event#EVENTDATA Event
function PROCESS_PICKUP:OnHitTarget( Fsm, Event, From, To, Event )
self.TargetSetUnit:Flush()
if self.TargetSetUnit:FindUnit( Event.IniUnitName ) then
self.TargetSetUnit:RemoveUnitsByName( Event.IniUnitName )
local TaskGroup = self.ProcessUnit:GetGroup()
MESSAGE:New( "You hit a target. Your group with assigned " .. self.Task:GetName() .. " task has " .. self.TargetSetUnit:Count() .. " targets ( " .. self.TargetSetUnit:GetUnitTypesText() .. " ) left to be destroyed.", 15, "HQ" ):ToGroup( TaskGroup )
end
if self.TargetSetUnit:Count() > 0 then
self:NextEvent( Fsm.MoreTargets )
else
self:NextEvent( Fsm.Destroyed )
end
end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_PICKUP self
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_PICKUP:OnMoreTargets( Fsm, Event, From, To )
end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_PICKUP self
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Event#EVENTDATA DCSEvent
function PROCESS_PICKUP:OnKilled( Fsm, Event, From, To )
self:NextEvent( Fsm.Restart )
end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_PICKUP self
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_PICKUP:OnRestart( Fsm, Event, From, To )
self:NextEvent( Fsm.Menu )
end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_PICKUP self
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_PICKUP:OnDestroyed( Fsm, Event, From, To )
end
--- DCS Events
--- @param #PROCESS_PICKUP self
-- @param Event#EVENTDATA Event
function PROCESS_PICKUP:EventDead( Event )
if Event.IniDCSUnit then
self:NextEvent( self.Fsm.HitTarget, Event )
end
end

View File

@ -651,7 +651,7 @@ function SPAWN:SpawnFromUnit( HostUnit, OuterRadius, InnerRadius, SpawnIndex )
self:F( { self.SpawnTemplatePrefix, HostUnit, OuterRadius, InnerRadius, SpawnIndex } ) self:F( { self.SpawnTemplatePrefix, HostUnit, OuterRadius, InnerRadius, SpawnIndex } )
if HostUnit and HostUnit:IsAlive() then -- and HostUnit:getUnit(1):inAir() == false then if HostUnit and HostUnit:IsAlive() then -- and HostUnit:getUnit(1):inAir() == false then
return self:SpawnFromVec3( HostUnit:GetPointVec3(), OuterRadius, InnerRadius, SpawnIndex ) return self:SpawnFromVec3( HostUnit:GetVec3(), OuterRadius, InnerRadius, SpawnIndex )
end end
return nil return nil
@ -670,7 +670,7 @@ function SPAWN:SpawnFromStatic( HostStatic, OuterRadius, InnerRadius, SpawnIndex
self:F( { self.SpawnTemplatePrefix, HostStatic, OuterRadius, InnerRadius, SpawnIndex } ) self:F( { self.SpawnTemplatePrefix, HostStatic, OuterRadius, InnerRadius, SpawnIndex } )
if HostStatic and HostStatic:IsAlive() then if HostStatic and HostStatic:IsAlive() then
return self:SpawnFromVec3( HostStatic:GetPointVec3(), OuterRadius, InnerRadius, SpawnIndex ) return self:SpawnFromVec3( HostStatic:GetVec3(), OuterRadius, InnerRadius, SpawnIndex )
end end
return nil return nil
@ -1003,9 +1003,9 @@ function SPAWN:_GetTemplate( SpawnTemplatePrefix )
error( 'No Template returned for SpawnTemplatePrefix = ' .. SpawnTemplatePrefix ) error( 'No Template returned for SpawnTemplatePrefix = ' .. SpawnTemplatePrefix )
end end
SpawnTemplate.SpawnCoalitionID = self:_GetGroupCoalitionID( SpawnTemplatePrefix ) --SpawnTemplate.SpawnCoalitionID = self:_GetGroupCoalitionID( SpawnTemplatePrefix )
SpawnTemplate.SpawnCategoryID = self:_GetGroupCategoryID( SpawnTemplatePrefix ) --SpawnTemplate.SpawnCategoryID = self:_GetGroupCategoryID( SpawnTemplatePrefix )
SpawnTemplate.SpawnCountryID = self:_GetGroupCountryID( SpawnTemplatePrefix ) --SpawnTemplate.SpawnCountryID = self:_GetGroupCountryID( SpawnTemplatePrefix )
self:T3( { SpawnTemplate } ) self:T3( { SpawnTemplate } )
return SpawnTemplate return SpawnTemplate
@ -1026,12 +1026,12 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex )
--SpawnTemplate.lateActivation = false --SpawnTemplate.lateActivation = false
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..." ) self:T3( "For ground units, visible needs to be false..." )
SpawnTemplate.visible = false SpawnTemplate.visible = false
end 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 SpawnTemplate.uncontrolled = false
end 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 ) SpawnTemplate.route.points[t].y = SpawnTemplate.route.points[t].y + math.random( self.SpawnRandomizeRouteRadius * -1, self.SpawnRandomizeRouteRadius )
-- Manage randomization of altitude for airborne units ... -- 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 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 ) SpawnTemplate.route.points[t].alt = SpawnTemplate.route.points[t].alt + math.random( 1, self.SpawnRandomizeRouteHeight )
end end

View File

@ -67,6 +67,13 @@ function STATEMACHINE:New( options )
return self return self
end end
function STATEMACHINE:LoadCallBacks( CallBackTable )
for name, callback in pairs( CallBackTable or {} ) do
self[name] = callback
end
end
function STATEMACHINE:_submap( subs, sub, name ) function STATEMACHINE:_submap( subs, sub, name )
self:E( { sub = sub, name = name } ) self:E( { sub = sub, name = name } )

View File

@ -0,0 +1,137 @@
--- This module contains the TASK_PICKUP classes.
--
-- 1) @{#TASK_PICKUP} class, extends @{Task#TASK_BASE}
-- ===================================================
-- The @{#TASK_PICKUP} class defines a pickup task of a @{Set} of @{CARGO} objects defined within the mission.
-- based on the tasking capabilities defined in @{Task#TASK_BASE}.
-- The TASK_PICKUP is implemented using a @{Statemachine#STATEMACHINE_TASK}, and has the following statuses:
--
-- * **None**: Start of the process
-- * **Planned**: The SEAD task is planned. Upon Planned, the sub-process @{Process_Assign#PROCESS_ASSIGN_ACCEPT} is started to accept the task.
-- * **Assigned**: The SEAD task is assigned to a @{Group#GROUP}. Upon Assigned, the sub-process @{Process_Route#PROCESS_ROUTE} is started to route the active Units in the Group to the attack zone.
-- * **Success**: The SEAD task is successfully completed. Upon Success, the sub-process @{Process_SEAD#PROCESS_SEAD} is started to follow-up successful SEADing of the targets assigned in the task.
-- * **Failed**: The SEAD task has failed. This will happen if the player exists the task early, without communicating a possible cancellation to HQ.
--
-- ===
--
-- ### Authors: FlightControl - Design and Programming
--
-- @module Task_PICKUP
do -- TASK_PICKUP
--- The TASK_PICKUP class
-- @type TASK_PICKUP
-- @extends Task#TASK_BASE
TASK_PICKUP = {
ClassName = "TASK_PICKUP",
}
--- Instantiates a new TASK_PICKUP.
-- @param #TASK_PICKUP self
-- @param Mission#MISSION Mission
-- @param Set#SET_GROUP AssignedSetGroup The set of groups for which the Task can be assigned.
-- @param #string TaskName The name of the Task.
-- @param #string TaskType BAI or CAS
-- @param Set#SET_UNIT UnitSetTargets
-- @param Zone#ZONE_BASE TargetZone
-- @return #TASK_PICKUP self
function TASK_PICKUP:New( Mission, AssignedSetGroup, TaskName, TaskType )
local self = BASE:Inherit( self, TASK_BASE:New( Mission, AssignedSetGroup, TaskName, TaskType, "PICKUP" ) )
self:F()
_EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventPlayerLeaveUnit, self )
_EVENTDISPATCHER:OnDead( self._EventDead, self )
_EVENTDISPATCHER:OnCrash( self._EventDead, self )
_EVENTDISPATCHER:OnPilotDead( self._EventDead, self )
return self
end
--- Removes a TASK_PICKUP.
-- @param #TASK_PICKUP self
-- @return #nil
function TASK_PICKUP:CleanUp()
self:GetParent( self ):CleanUp()
return nil
end
--- Assign the @{Task} to a @{Unit}.
-- @param #TASK_PICKUP self
-- @param Unit#UNIT TaskUnit
-- @return #TASK_PICKUP self
function TASK_PICKUP:AssignToUnit( TaskUnit )
self:F( TaskUnit:GetName() )
local ProcessAssign = self:AddProcess( TaskUnit, PROCESS_ASSIGN_ACCEPT:New( self, TaskUnit, self.TaskBriefing ) )
local ProcessPickup = self:AddProcess( TaskUnit, PROCESS_PICKUP:New( self, self.TaskType, TaskUnit ) )
local Process = self:AddStateMachine( TaskUnit, STATEMACHINE_TASK:New( self, TaskUnit, {
initial = 'None',
events = {
{ name = 'Next', from = 'None', to = 'Planned' },
{ name = 'Next', from = 'Planned', to = 'Assigned' },
{ name = 'Next', from = 'Assigned', to = 'Success' },
{ name = 'Fail', from = 'Assigned', to = 'Failed' },
},
callbacks = {
onNext = self.OnNext,
},
subs = {
Assign = { onstateparent = 'Planned', oneventparent = 'Next', fsm = ProcessAssign.Fsm, event = 'Start', returnevents = { 'Next', 'Reject' } },
Pickup = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = ProcessDestroy.Fsm, event = 'Start', returnevents = { 'Next' } },
}
} ) )
ProcessRoute:AddScore( "Failed", "failed to destroy a ground unit", -100 )
ProcessDestroy:AddScore( "Pickup", "Picked-Up a Cargo", 25 )
ProcessDestroy:AddScore( "Failed", "failed to destroy a ground unit", -100 )
Process:Next()
return self
end
--- StateMachine callback function for a TASK
-- @param #TASK_PICKUP self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Event#EVENTDATA Event
function TASK_PICKUP:OnNext( Fsm, Event, From, To, Event )
self:SetState( self, "State", To )
end
--- @param #TASK_PICKUP self
function TASK_PICKUP:GetPlannedMenuText()
return self:GetStateString() .. " - " .. self:GetTaskName() .. " ( " .. self.TargetSetUnit:GetUnitTypesText() .. " )"
end
--- @param #TASK_PICKUP self
function TASK_PICKUP:_Schedule()
self:F2()
self.TaskScheduler = SCHEDULER:New( self, _Scheduler, {}, 15, 15 )
return self
end
--- @param #TASK_PICKUP self
function TASK_PICKUP._Scheduler()
self:F2()
return true
end
end

View File

@ -48,7 +48,7 @@
-- 1.4) Location Position, Point -- 1.4) Location Position, Point
-- ----------------------------- -- -----------------------------
-- The UNIT class provides methods to obtain the current point or position of the DCS Unit. -- The UNIT class provides methods to obtain the current point or position of the DCS Unit.
-- The @{#UNIT.GetPointVec2}(), @{#UNIT.GetPointVec3}() will obtain the current **location** of the DCS Unit in a Vec2 (2D) or a **point** in a Vec3 (3D) vector respectively. -- The @{#UNIT.GetPointVec2}(), @{#UNIT.GetVec3}() will obtain the current **location** of the DCS Unit in a Vec2 (2D) or a **point** in a Vec3 (3D) vector respectively.
-- If you want to obtain the complete **3D position** including ori<72>ntation and direction vectors, consult the @{#UNIT.GetPositionVec3}() method respectively. -- If you want to obtain the complete **3D position** including ori<72>ntation and direction vectors, consult the @{#UNIT.GetPositionVec3}() method respectively.
-- --
-- 1.5) Test if alive -- 1.5) Test if alive
@ -152,6 +152,14 @@ function UNIT:FindByName( UnitName )
return UnitFound return UnitFound
end 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 --- @param #UNIT self
-- @return DCSUnit#Unit -- @return DCSUnit#Unit
@ -166,6 +174,59 @@ function UNIT:GetDCSObject()
return nil return nil
end end
--- Respawn the @{Unit} using a (tweaked) template of the parent Group.
--
-- This function will:
--
-- * Get the current position and heading of the group.
-- * When the unit is alive, it will tweak the template x, y and heading coordinates of the group and the embedded units to the current units positions.
-- * Then it will respawn the re-modelled group.
--
-- @param Unit#UNIT self
-- @param DCSTypes#Vec3 SpawnVec3 The position where to Spawn the new Unit at.
-- @param #number Heading The heading of the unit respawn.
function UNIT:ReSpawn( SpawnVec3, Heading )
local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) )
self:T( SpawnGroupTemplate )
local SpawnGroup = self:GetGroup()
if SpawnGroup then
local Vec3 = SpawnGroup:GetVec3()
SpawnGroupTemplate.x = Vec3.x
SpawnGroupTemplate.y = Vec3.z
self:E( #SpawnGroupTemplate.units )
for UnitID, UnitData in pairs( SpawnGroup:GetUnits() ) do
local GroupUnit = UnitData -- Unit#UNIT
self:E( GroupUnit:GetName() )
if GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3()
local GroupUnitHeading = GroupUnit:GetHeading()
SpawnGroupTemplate.units[UnitID].alt = GroupUnitVec3.y
SpawnGroupTemplate.units[UnitID].x = GroupUnitVec3.x
SpawnGroupTemplate.units[UnitID].y = GroupUnitVec3.z
SpawnGroupTemplate.units[UnitID].heading = GroupUnitHeading
self:E( { UnitID, SpawnGroupTemplate.units[UnitID], SpawnGroupTemplate.units[UnitID] } )
end
end
end
for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do
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
SpawnGroupTemplate.units[UnitTemplateID].heading = Heading
self:E( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } )
end
end
_DATABASE:Spawn( SpawnGroupTemplate )
end
@ -187,22 +248,6 @@ function UNIT:IsActive()
return nil return nil
end end
--- Destroys the @{Unit}.
-- @param Unit#UNIT self
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:Destroy()
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
if DCSUnit then
DCSUnit:destroy()
end
return nil
end
--- Returns the Unit's callsign - the localized string. --- Returns the Unit's callsign - the localized string.
@ -521,7 +566,7 @@ function UNIT:IsInZone( Zone )
self:F2( { self.UnitName, Zone } ) self:F2( { self.UnitName, Zone } )
if self:IsAlive() then if self:IsAlive() then
local IsInZone = Zone:IsPointVec3InZone( self:GetPointVec3() ) local IsInZone = Zone:IsPointVec3InZone( self:GetVec3() )
self:T( { IsInZone } ) self:T( { IsInZone } )
return IsInZone return IsInZone
@ -538,7 +583,7 @@ function UNIT:IsNotInZone( Zone )
self:F2( { self.UnitName, Zone } ) self:F2( { self.UnitName, Zone } )
if self:IsAlive() then if self:IsAlive() then
local IsInZone = not Zone:IsPointVec3InZone( self:GetPointVec3() ) local IsInZone = not Zone:IsPointVec3InZone( self:GetVec3() )
self:T( { IsInZone } ) self:T( { IsInZone } )
return IsInZone return IsInZone
@ -560,10 +605,10 @@ function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local UnitPos = self:GetPointVec3() local UnitVec3 = self:GetVec3()
local AwaitUnitPos = AwaitUnit:GetPointVec3() local AwaitUnitVec3 = AwaitUnit:GetVec3()
if (((UnitPos.x - AwaitUnitPos.x)^2 + (UnitPos.z - AwaitUnitPos.z)^2)^0.5 <= Radius) then if (((UnitVec3.x - AwaitUnitVec3.x)^2 + (UnitVec3.z - AwaitUnitVec3.z)^2)^0.5 <= Radius) then
self:T3( "true" ) self:T3( "true" )
return true return true
else else
@ -581,35 +626,35 @@ end
-- @param #UNIT self -- @param #UNIT self
function UNIT:Flare( FlareColor ) function UNIT:Flare( FlareColor )
self:F2() self:F2()
trigger.action.signalFlare( self:GetPointVec3(), FlareColor , 0 ) trigger.action.signalFlare( self:GetVec3(), FlareColor , 0 )
end end
--- Signal a white flare at the position of the UNIT. --- Signal a white flare at the position of the UNIT.
-- @param #UNIT self -- @param #UNIT self
function UNIT:FlareWhite() function UNIT:FlareWhite()
self:F2() self:F2()
trigger.action.signalFlare( self:GetPointVec3(), trigger.flareColor.White , 0 ) trigger.action.signalFlare( self:GetVec3(), trigger.flareColor.White , 0 )
end end
--- Signal a yellow flare at the position of the UNIT. --- Signal a yellow flare at the position of the UNIT.
-- @param #UNIT self -- @param #UNIT self
function UNIT:FlareYellow() function UNIT:FlareYellow()
self:F2() self:F2()
trigger.action.signalFlare( self:GetPointVec3(), trigger.flareColor.Yellow , 0 ) trigger.action.signalFlare( self:GetVec3(), trigger.flareColor.Yellow , 0 )
end end
--- Signal a green flare at the position of the UNIT. --- Signal a green flare at the position of the UNIT.
-- @param #UNIT self -- @param #UNIT self
function UNIT:FlareGreen() function UNIT:FlareGreen()
self:F2() self:F2()
trigger.action.signalFlare( self:GetPointVec3(), trigger.flareColor.Green , 0 ) trigger.action.signalFlare( self:GetVec3(), trigger.flareColor.Green , 0 )
end end
--- Signal a red flare at the position of the UNIT. --- Signal a red flare at the position of the UNIT.
-- @param #UNIT self -- @param #UNIT self
function UNIT:FlareRed() function UNIT:FlareRed()
self:F2() self:F2()
local Vec3 = self:GetPointVec3() local Vec3 = self:GetVec3()
if Vec3 then if Vec3 then
trigger.action.signalFlare( Vec3, trigger.flareColor.Red, 0 ) trigger.action.signalFlare( Vec3, trigger.flareColor.Red, 0 )
end end
@ -620,9 +665,9 @@ end
function UNIT:Smoke( SmokeColor, Range ) function UNIT:Smoke( SmokeColor, Range )
self:F2() self:F2()
if Range then if Range then
trigger.action.smoke( self:GetRandomPointVec3( Range ), SmokeColor ) trigger.action.smoke( self:GetRandomVec3( Range ), SmokeColor )
else else
trigger.action.smoke( self:GetPointVec3(), SmokeColor ) trigger.action.smoke( self:GetVec3(), SmokeColor )
end end
end end
@ -631,35 +676,35 @@ end
-- @param #UNIT self -- @param #UNIT self
function UNIT:SmokeGreen() function UNIT:SmokeGreen()
self:F2() self:F2()
trigger.action.smoke( self:GetPointVec3(), trigger.smokeColor.Green ) trigger.action.smoke( self:GetVec3(), trigger.smokeColor.Green )
end end
--- Smoke the UNIT Red. --- Smoke the UNIT Red.
-- @param #UNIT self -- @param #UNIT self
function UNIT:SmokeRed() function UNIT:SmokeRed()
self:F2() self:F2()
trigger.action.smoke( self:GetPointVec3(), trigger.smokeColor.Red ) trigger.action.smoke( self:GetVec3(), trigger.smokeColor.Red )
end end
--- Smoke the UNIT White. --- Smoke the UNIT White.
-- @param #UNIT self -- @param #UNIT self
function UNIT:SmokeWhite() function UNIT:SmokeWhite()
self:F2() self:F2()
trigger.action.smoke( self:GetPointVec3(), trigger.smokeColor.White ) trigger.action.smoke( self:GetVec3(), trigger.smokeColor.White )
end end
--- Smoke the UNIT Orange. --- Smoke the UNIT Orange.
-- @param #UNIT self -- @param #UNIT self
function UNIT:SmokeOrange() function UNIT:SmokeOrange()
self:F2() self:F2()
trigger.action.smoke( self:GetPointVec3(), trigger.smokeColor.Orange ) trigger.action.smoke( self:GetVec3(), trigger.smokeColor.Orange )
end end
--- Smoke the UNIT Blue. --- Smoke the UNIT Blue.
-- @param #UNIT self -- @param #UNIT self
function UNIT:SmokeBlue() function UNIT:SmokeBlue()
self:F2() self:F2()
trigger.action.smoke( self:GetPointVec3(), trigger.smokeColor.Blue ) trigger.action.smoke( self:GetVec3(), trigger.smokeColor.Blue )
end end
-- Is methods -- Is methods

View File

@ -111,12 +111,12 @@ end
--- Returns if a point is within the zone. --- Returns if a point is within the zone.
-- @param #ZONE_BASE self -- @param #ZONE_BASE self
-- @param DCSTypes#Vec3 PointVec3 The point to test. -- @param DCSTypes#Vec3 Vec3 The point to test.
-- @return #boolean true if the point is within the zone. -- @return #boolean true if the point is within the zone.
function ZONE_BASE:IsPointVec3InZone( PointVec3 ) function ZONE_BASE:IsPointVec3InZone( Vec3 )
self:F2( PointVec3 ) self:F2( Vec3 )
local InZone = self:IsPointVec2InZone( { x = PointVec3.x, y = PointVec3.z } ) local InZone = self:IsPointVec2InZone( { x = Vec3.x, y = Vec3.z } )
return InZone return InZone
end end
@ -282,11 +282,11 @@ function ZONE_RADIUS:SetPointVec2( Vec2 )
return self.Vec2 return self.Vec2
end end
--- Returns the point of the zone. --- Returns the @{DCSTypes#Vec3} of the ZONE_RADIUS.
-- @param #ZONE_RADIUS self -- @param #ZONE_RADIUS self
-- @param DCSTypes#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCSTypes#Distance Height The height to add to the land height where the center of the zone is located.
-- @return DCSTypes#Vec3 The point of the zone. -- @return DCSTypes#Vec3 The point of the zone.
function ZONE_RADIUS:GetPointVec3( Height ) function ZONE_RADIUS:GetVec3( Height )
self:F2( { self.ZoneName, Height } ) self:F2( { self.ZoneName, Height } )
Height = Height or 0 Height = Height or 0
@ -320,7 +320,7 @@ end
--- Returns if a point is within the zone. --- Returns if a point is within the zone.
-- @param #ZONE_RADIUS self -- @param #ZONE_RADIUS self
-- @param DCSTypes#Vec3 PointVec3 The point to test. -- @param DCSTypes#Vec3 Vec3 The point to test.
-- @return #boolean true if the point is within the zone. -- @return #boolean true if the point is within the zone.
function ZONE_RADIUS:IsPointVec3InZone( Vec3 ) function ZONE_RADIUS:IsPointVec3InZone( Vec3 )
self:F2( Vec3 ) self:F2( Vec3 )
@ -445,22 +445,22 @@ function ZONE_UNIT:GetRandomVec2()
return Point return Point
end end
--- Returns the point of the zone. --- Returns the @{DCSTypes#Vec3} of the ZONE_UNIT.
-- @param #ZONE_RADIUS self -- @param #ZONE_UNIT self
-- @param DCSTypes#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCSTypes#Distance Height The height to add to the land height where the center of the zone is located.
-- @return DCSTypes#Vec3 The point of the zone. -- @return DCSTypes#Vec3 The point of the zone.
function ZONE_UNIT:GetPointVec3( Height ) function ZONE_UNIT:GetVec3( Height )
self:F2( self.ZoneName ) self:F2( self.ZoneName )
Height = Height or 0 Height = Height or 0
local Vec2 = self:GetVec2() local Vec2 = self:GetVec2()
local PointVec3 = { x = Vec2.x, y = land.getHeight( self:GetVec2() ) + Height, z = Vec2.y } local Vec3 = { x = Vec2.x, y = land.getHeight( self:GetVec2() ) + Height, z = Vec2.y }
self:T2( { PointVec3 } ) self:T2( { Vec3 } )
return PointVec3 return Vec3
end end
--- The ZONE_GROUP class defined by a zone around a @{Group}, taking the average center point of all the units within the Group, with a radius. --- The ZONE_GROUP class defined by a zone around a @{Group}, taking the average center point of all the units within the Group, with a radius.

View File

@ -2,6 +2,12 @@
- Added briefing to method ESCORT:New() - Added briefing to method ESCORT:New()
-- If no EscortBriefing is given, the New() method will show the default briefing. -- If no EscortBriefing is given, the New() method will show the default briefing.
2016-08-06
- Made PointVec3 and Vec3, PointVec2 and Vec2 terminology used in the code consistent.
-- Replaced method PointVec3() to Vec3() where the code manages a Vec3. Replaced all references to the method.
-- Replaced method PointVec2() to Vec2() where the code manages a Vec2. Replaced all references to the method.
-- Replaced method RandomPointVec3() to RandomVec3() where the code manages a Vec3. Replaced all references to the method.
2016-08-03 2016-08-03
- Fixed error at SPAWN:RandomizeTemplate() - Fixed error at SPAWN:RandomizeTemplate()
-- Units started in wrong x, y position (at the template, instead of at the master template of the SPAWN). -- Units started in wrong x, y position (at the template, instead of at the master template of the SPAWN).

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
local Mission = MISSION:New( "Pickup Cargo", "High", "Test for Cargo Pickup", coalition.side.RED )
local DeliveryUnit = UNIT:FindByName( "Delivery" )
local Letter = CARGO_PACKAGE:New( Mission, DeliveryUnit, "Letter", "Secret Orders", "0.3", 2000, 25 )
local CargoCarrier = UNIT:FindByName( "Carrier" )
-- This call will make the Cargo run to the CargoCarrier.
-- Upon arrival at the CargoCarrier, the Cargo will be Loaded into the Carrier.
-- This process is now fully automated.
Letter:Board( CargoCarrier, 40, 3, 25, 90 )

View File

@ -0,0 +1,15 @@
local Mission = MISSION:New( "Pickup Cargo", "High", "Test for Cargo Pickup", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 25 )
local CargoCarrier = UNIT:FindByName( "Carrier" )
-- This will Load the Cargo into the Carrier, regardless where the Cargo is.
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( 10, 2, 20, 10, 180 )

View File

@ -0,0 +1,13 @@
local Mission = MISSION:New( "Transfer Cargo", "High", "Test for Cargo", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 25 )
local CargoCarrier = UNIT:FindByName( "Carrier" )
-- This call will make the Cargo run to the CargoCarrier.
-- Upon arrival at the CargoCarrier, the Cargo will be Loaded into the Carrier.
-- This process is now fully automated.
InfantryCargo:Board( CargoCarrier )

View File

@ -0,0 +1,28 @@
local Mission = MISSION:New( "Transfer Cargo", "High", "Test for Cargo", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 25 )
local CargoCarrierFrom = UNIT:FindByName( "CarrierFrom" )
local CargoCarrierTo = UNIT:FindByName( "CarrierTo" )
-- This call will make the Cargo run to the CargoCarrier.
-- Upon arrival at the CargoCarrier, the Cargo will be Loaded into the Carrier.
-- This process is now fully automated.
InfantryCargo:Board( CargoCarrierFrom )
-- Once the Cargo has been loaded into the Carrier, drive to a point and unload the Cargo.
InfantryCargo:OnLoaded(
function( Cargo )
Cargo:UnLoad()
end
)
-- Once the Cargo has been unloaded from the Carrier (the Cargo has arrived to the unload gathering point), OnBoard the Cargo in the other Carrier.
InfantryCargo:OnUnLoaded(
function( Cargo )
Cargo:Board( CargoCarrierTo )
end
)

View File

@ -0,0 +1,13 @@
local Mission = MISSION:New( "Transfer Cargo", "High", "Test for Cargo", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 25 )
local CargoCarrier = UNIT:FindByName( "Carrier" )
-- This will Load the Cargo into the Carrier, regardless where the Cargo is.
InfantryCargo:Load( CargoCarrier )
-- This will Unboard the Cargo from the Carrier.
InfantryCargo:UnLoad()