DCS 2.5.6 fixes

This commit is contained in:
Frank 2020-02-17 23:19:28 +01:00
parent 04da941c36
commit 6ab85072d2
6 changed files with 660 additions and 609 deletions

View File

@ -626,6 +626,55 @@ do -- Event Handling
-- @param #BASE self -- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure. -- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Unknown precisely what creates this event, likely tied into newer damage model. Will update this page when new information become available.
--
-- * initiator: The unit that had the failure.
--
-- @function [parent=#BASE] OnEventDetailedFailure
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs when any modification to the "Score" as seen on the debrief menu would occur.
-- There is no information on what values the score was changed to. Event is likely similar to player_comment in this regard.
-- @function [parent=#BASE] OnEventScore
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs on the death of a unit. Contains more and different information. Similar to unit_lost it will occur for aircraft before the aircraft crash event occurs.
--
-- * initiator: The unit that killed the target
-- * target: Target Object
-- * weapon: Weapon Object
--
-- @function [parent=#BASE] OnEventKill
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs when any modification to the "Score" as seen on the debrief menu would occur.
-- There is no information on what values the score was changed to. Event is likely similar to player_comment in this regard.
-- @function [parent=#BASE] OnEventScore
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs when the game thinks an object is destroyed.
--
-- * initiator: The unit that is was destroyed.
--
-- @function [parent=#BASE] OnEventUnitLost
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
--- Occurs shortly after the landing animation of an ejected pilot touching the ground and standing up. Event does not occur if the pilot lands in the water and sub combs to Davey Jones Locker.
--
-- * initiator: Static object representing the ejected pilot. Place : Aircraft that the pilot ejected from.
-- * place: may not return as a valid object if the aircraft has crashed into the ground and no longer exists.
-- * subplace: is always 0 for unknown reasons.
--
-- @function [parent=#BASE] OnEventLandingAfterEjection
-- @param #BASE self
-- @param Core.Event#EVENTDATA EventData The EventData structure.
end end

View File

@ -247,12 +247,15 @@ end
--- Adds a Airbase based on the Airbase Name in the DATABASE. --- Adds a Airbase based on the Airbase Name in the DATABASE.
-- @param #DATABASE self -- @param #DATABASE self
-- @param #string AirbaseName The name of the airbase -- @param #string AirbaseName The name of the airbase.
-- @return Wrapper.Airbase#AIRBASE Airbase object.
function DATABASE:AddAirbase( AirbaseName ) function DATABASE:AddAirbase( AirbaseName )
if not self.AIRBASES[AirbaseName] then if not self.AIRBASES[AirbaseName] then
self.AIRBASES[AirbaseName] = AIRBASE:Register( AirbaseName ) self.AIRBASES[AirbaseName] = AIRBASE:Register( AirbaseName )
end end
return self.AIRBASES[AirbaseName]
end end
@ -893,6 +896,7 @@ end
--- @param #DATABASE self --- @param #DATABASE self
function DATABASE:_RegisterAirbases() function DATABASE:_RegisterAirbases()
--[[
local CoalitionsData = { AirbasesRed = coalition.getAirbases( coalition.side.RED ), AirbasesBlue = coalition.getAirbases( coalition.side.BLUE ), AirbasesNeutral = coalition.getAirbases( coalition.side.NEUTRAL ) } local CoalitionsData = { AirbasesRed = coalition.getAirbases( coalition.side.RED ), AirbasesBlue = coalition.getAirbases( coalition.side.BLUE ), AirbasesNeutral = coalition.getAirbases( coalition.side.NEUTRAL ) }
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
for DCSAirbaseId, DCSAirbase in pairs( CoalitionData ) do for DCSAirbaseId, DCSAirbase in pairs( CoalitionData ) do
@ -903,6 +907,18 @@ function DATABASE:_RegisterAirbases()
self:AddAirbase( DCSAirbaseName ) self:AddAirbase( DCSAirbaseName )
end end
end end
]]
for DCSAirbaseId, DCSAirbase in pairs(world.getAirbases()) do
local DCSAirbaseName = DCSAirbase:getName()
-- This gives the incorrect value to be inserted into the airdromeID for DCS 2.5.6!
local airbaseID=DCSAirbase:getID()
local airbase=self:AddAirbase( DCSAirbaseName )
self:I(string.format("Register Airbase: %s, getID=%d, GetID=%d (unique=%d)", DCSAirbaseName, DCSAirbase:getID(), airbase:GetID(), airbase:GetID(true)))
end
return self return self
end end

View File

@ -221,9 +221,11 @@ EVENTS = {
PlayerComment = world.event.S_EVENT_PLAYER_COMMENT, PlayerComment = world.event.S_EVENT_PLAYER_COMMENT,
ShootingStart = world.event.S_EVENT_SHOOTING_START, ShootingStart = world.event.S_EVENT_SHOOTING_START,
ShootingEnd = world.event.S_EVENT_SHOOTING_END, ShootingEnd = world.event.S_EVENT_SHOOTING_END,
-- Added with DCS 2.5.1
MarkAdded = world.event.S_EVENT_MARK_ADDED, MarkAdded = world.event.S_EVENT_MARK_ADDED,
MarkChange = world.event.S_EVENT_MARK_CHANGE, MarkChange = world.event.S_EVENT_MARK_CHANGE,
MarkRemoved = world.event.S_EVENT_MARK_REMOVED, MarkRemoved = world.event.S_EVENT_MARK_REMOVED,
-- Moose Events
NewCargo = world.event.S_EVENT_NEW_CARGO, NewCargo = world.event.S_EVENT_NEW_CARGO,
DeleteCargo = world.event.S_EVENT_DELETE_CARGO, DeleteCargo = world.event.S_EVENT_DELETE_CARGO,
NewZone = world.event.S_EVENT_NEW_ZONE, NewZone = world.event.S_EVENT_NEW_ZONE,
@ -231,6 +233,12 @@ EVENTS = {
NewZoneGoal = world.event.S_EVENT_NEW_ZONE_GOAL, NewZoneGoal = world.event.S_EVENT_NEW_ZONE_GOAL,
DeleteZoneGoal = world.event.S_EVENT_DELETE_ZONE_GOAL, DeleteZoneGoal = world.event.S_EVENT_DELETE_ZONE_GOAL,
RemoveUnit = world.event.S_EVENT_REMOVE_UNIT, RemoveUnit = world.event.S_EVENT_REMOVE_UNIT,
-- Added with DCS 2.5.6
DetailedFailure = world.event.S_EVENT_DETAILED_FAILURE or -1, --We set this to -1 for backward compatibility to DCS 2.5.5 and earlier
Kill = world.event.S_EVENT_KILL or -1,
Score = world.event.S_EVENT_SCORE or -1,
UnitLost = world.event.S_EVENT_UNIT_LOST or -1,
LandingAfterEjection = world.event.S_EVENT_LANDING_AFTER_EJECTION or -1,
} }
--- The Event structure --- The Event structure
@ -481,6 +489,32 @@ local _EVENTMETA = {
Event = "OnEventRemoveUnit", Event = "OnEventRemoveUnit",
Text = "S_EVENT_REMOVE_UNIT" Text = "S_EVENT_REMOVE_UNIT"
}, },
-- Added with DCS 2.5.6
[EVENTS.DetailedFailure] = {
Order = 1,
Event = "OnEventDetailedFailure",
Text = "S_EVENT_DETAILED_FAILURE"
},
[EVENTS.Kill] = {
Order = 1,
Event = "OnEventKill",
Text = "S_EVENT_KILL"
},
[EVENTS.Score] = {
Order = 1,
Event = "OnEventScore",
Text = "S_EVENT_SCORE"
},
[EVENTS.UnitLost] = {
Order = 1,
Event = "OnEventUnitLost",
Text = "S_EVENT_UNIT_LOST"
},
[EVENTS.LandingAfterEjection] = {
Order = 1,
Event = "OnEventLandingAfterEjection",
Text = "S_EVENT_LANDING_AFTER_EJECTION"
},
} }
@ -881,258 +915,213 @@ function EVENT:onEvent( Event )
end end
-- Get event meta data.
local EventMeta = _EVENTMETA[Event.id] local EventMeta = _EVENTMETA[Event.id]
--self:E( { EventMeta.Text, Event } ) -- Activate the see all incoming events ... -- Check if this is a known event?
if EventMeta then
if self and if self and
self.Events and self.Events and
self.Events[Event.id] and self.Events[Event.id] and
self.MissionEnd == false and self.MissionEnd == false and
( Event.initiator ~= nil or ( Event.initiator == nil and Event.id ~= EVENTS.PlayerLeaveUnit ) ) then ( Event.initiator ~= nil or ( Event.initiator == nil and Event.id ~= EVENTS.PlayerLeaveUnit ) ) then
if Event.id and Event.id == EVENTS.MissionEnd then if Event.id and Event.id == EVENTS.MissionEnd then
self.MissionEnd = true self.MissionEnd = true
end end
if Event.initiator then if Event.initiator then
Event.IniObjectCategory = Event.initiator:getCategory() Event.IniObjectCategory = Event.initiator:getCategory()
if Event.IniObjectCategory == Object.Category.UNIT then if Event.IniObjectCategory == Object.Category.UNIT then
Event.IniDCSUnit = Event.initiator Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit:getName() Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName Event.IniUnitName = Event.IniDCSUnitName
Event.IniDCSGroup = Event.IniDCSUnit:getGroup() Event.IniDCSGroup = Event.IniDCSUnit:getGroup()
Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName ) Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName )
if not Event.IniUnit then if not Event.IniUnit then
-- Unit can be a CLIENT. Most likely this will be the case ... -- Unit can be a CLIENT. Most likely this will be the case ...
Event.IniUnit = CLIENT:FindByName( Event.IniDCSUnitName, '', true ) Event.IniUnit = CLIENT:FindByName( Event.IniDCSUnitName, '', true )
end
Event.IniDCSGroupName = ""
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
--if Event.IniGroup then
Event.IniGroupName = Event.IniDCSGroupName
--end
end
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
Event.IniCategory = Event.IniDCSUnit:getDesc().category
end end
Event.IniDCSGroupName = ""
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then if Event.IniObjectCategory == Object.Category.STATIC then
Event.IniDCSGroupName = Event.IniDCSGroup:getName() Event.IniDCSUnit = Event.initiator
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName ) Event.IniDCSUnitName = Event.IniDCSUnit:getName()
--if Event.IniGroup then Event.IniUnitName = Event.IniDCSUnitName
Event.IniGroupName = Event.IniDCSGroupName Event.IniUnit = STATIC:FindByName( Event.IniDCSUnitName, false )
--end Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniCategory = Event.IniDCSUnit:getDesc().category
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
end end
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
Event.IniCategory = Event.IniDCSUnit:getDesc().category
end
if Event.IniObjectCategory == Object.Category.STATIC then if Event.IniObjectCategory == Object.Category.CARGO then
Event.IniDCSUnit = Event.initiator Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit:getName() Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = STATIC:FindByName( Event.IniDCSUnitName, false ) Event.IniUnit = CARGO:FindByName( Event.IniDCSUnitName )
Event.IniCoalition = Event.IniDCSUnit:getCoalition() Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniCategory = Event.IniDCSUnit:getDesc().category Event.IniCategory = Event.IniDCSUnit:getDesc().category
Event.IniTypeName = Event.IniDCSUnit:getTypeName() Event.IniTypeName = Event.IniDCSUnit:getTypeName()
end end
if Event.IniObjectCategory == Object.Category.CARGO then if Event.IniObjectCategory == Object.Category.SCENERY then
Event.IniDCSUnit = Event.initiator Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit:getName() Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = CARGO:FindByName( Event.IniDCSUnitName ) Event.IniUnit = SCENERY:Register( Event.IniDCSUnitName, Event.initiator )
Event.IniCoalition = Event.IniDCSUnit:getCoalition() Event.IniCategory = Event.IniDCSUnit:getDesc().category
Event.IniCategory = Event.IniDCSUnit:getDesc().category Event.IniTypeName = Event.initiator:isExist() and Event.IniDCSUnit:getTypeName() or "SCENERY" -- TODO: Bug fix for 2.1!
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
end
if Event.IniObjectCategory == Object.Category.SCENERY then
Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = SCENERY:Register( Event.IniDCSUnitName, Event.initiator )
Event.IniCategory = Event.IniDCSUnit:getDesc().category
Event.IniTypeName = Event.initiator:isExist() and Event.IniDCSUnit:getTypeName() or "SCENERY" -- TODO: Bug fix for 2.1!
end
end
if Event.target then
Event.TgtObjectCategory = Event.target:getCategory()
if Event.TgtObjectCategory == Object.Category.UNIT then
Event.TgtDCSUnit = Event.target
Event.TgtDCSGroup = Event.TgtDCSUnit:getGroup()
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = UNIT:FindByName( Event.TgtDCSUnitName )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
--if Event.TgtGroup then
Event.TgtGroupName = Event.TgtDCSGroupName
--end
end end
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()
end end
if Event.TgtObjectCategory == Object.Category.STATIC then if Event.target then
Event.TgtDCSUnit = Event.target
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName() Event.TgtObjectCategory = Event.target:getCategory()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = STATIC:FindByName( Event.TgtDCSUnitName, false ) if Event.TgtObjectCategory == Object.Category.UNIT then
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition() Event.TgtDCSUnit = Event.target
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category Event.TgtDCSGroup = Event.TgtDCSUnit:getGroup()
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName() Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = UNIT:FindByName( Event.TgtDCSUnitName )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
--if Event.TgtGroup then
Event.TgtGroupName = Event.TgtDCSGroupName
--end
end
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()
end
if Event.TgtObjectCategory == Object.Category.STATIC then
Event.TgtDCSUnit = Event.target
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = STATIC:FindByName( Event.TgtDCSUnitName, false )
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()
end
if Event.TgtObjectCategory == Object.Category.SCENERY then
Event.TgtDCSUnit = Event.target
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = SCENERY:Register( Event.TgtDCSUnitName, Event.target )
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()
end
end end
if Event.TgtObjectCategory == Object.Category.SCENERY then if Event.weapon then
Event.TgtDCSUnit = Event.target Event.Weapon = Event.weapon
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName() Event.WeaponName = Event.Weapon:getTypeName()
Event.TgtUnitName = Event.TgtDCSUnitName Event.WeaponUNIT = CLIENT:Find( Event.Weapon, '', true ) -- Sometimes, the weapon is a player unit!
Event.TgtUnit = SCENERY:Register( Event.TgtDCSUnitName, Event.target ) Event.WeaponPlayerName = Event.WeaponUNIT and Event.Weapon:getPlayerName()
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category Event.WeaponCoalition = Event.WeaponUNIT and Event.Weapon:getCoalition()
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName() Event.WeaponCategory = Event.WeaponUNIT and Event.Weapon:getDesc().category
Event.WeaponTypeName = Event.WeaponUNIT and Event.Weapon:getTypeName()
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
end end
end
if Event.weapon then -- Place should be given for takeoff and landing events as well as base captured. It should be a DCS airbase.
Event.Weapon = Event.weapon if Event.place then
Event.WeaponName = Event.Weapon:getTypeName() if Event.id==EVENTS.LandingAfterEjection then
Event.WeaponUNIT = CLIENT:Find( Event.Weapon, '', true ) -- Sometimes, the weapon is a player unit! -- Place is here the UNIT of which the pilot ejected.
Event.WeaponPlayerName = Event.WeaponUNIT and Event.Weapon:getPlayerName() Event.Place=UNIT:Find(Event.place)
Event.WeaponCoalition = Event.WeaponUNIT and Event.Weapon:getCoalition() else
Event.WeaponCategory = Event.WeaponUNIT and Event.Weapon:getDesc().category Event.Place=AIRBASE:Find(Event.place)
Event.WeaponTypeName = Event.WeaponUNIT and Event.Weapon:getTypeName() Event.PlaceName=Event.Place:GetName()
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget() end
end end
-- Place should be given for takeoff and landing events as well as base captured. It should be a DCS airbase. -- Mark points.
if Event.place then if Event.idx then
Event.Place=AIRBASE:Find(Event.place) Event.MarkID=Event.idx
Event.PlaceName=Event.Place:GetName() Event.MarkVec3=Event.pos
end Event.MarkCoordinate=COORDINATE:NewFromVec3(Event.pos)
Event.MarkText=Event.text
Event.MarkCoalition=Event.coalition
Event.MarkGroupID = Event.groupID
end
-- Mark points. if Event.cargo then
if Event.idx then Event.Cargo = Event.cargo
Event.MarkID=Event.idx Event.CargoName = Event.cargo.Name
Event.MarkVec3=Event.pos end
Event.MarkCoordinate=COORDINATE:NewFromVec3(Event.pos)
Event.MarkText=Event.text
Event.MarkCoalition=Event.coalition
Event.MarkGroupID = Event.groupID
end
if Event.cargo then if Event.zone then
Event.Cargo = Event.cargo Event.Zone = Event.zone
Event.CargoName = Event.cargo.Name Event.ZoneName = Event.zone.ZoneName
end end
if Event.zone then local PriorityOrder = EventMeta.Order
Event.Zone = Event.zone local PriorityBegin = PriorityOrder == -1 and 5 or 1
Event.ZoneName = Event.zone.ZoneName local PriorityEnd = PriorityOrder == -1 and 1 or 5
end
local PriorityOrder = EventMeta.Order if Event.IniObjectCategory ~= Object.Category.STATIC then
local PriorityBegin = PriorityOrder == -1 and 5 or 1 self:F( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } )
local PriorityEnd = PriorityOrder == -1 and 1 or 5 end
if Event.IniObjectCategory ~= Object.Category.STATIC then for EventPriority = PriorityBegin, PriorityEnd, PriorityOrder do
self:F( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } )
end
for EventPriority = PriorityBegin, PriorityEnd, PriorityOrder do if self.Events[Event.id][EventPriority] then
if self.Events[Event.id][EventPriority] then -- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called.
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
-- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called. --if Event.IniObjectCategory ~= Object.Category.STATIC then
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do -- self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } )
--end
--if Event.IniObjectCategory ~= Object.Category.STATIC then Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
-- self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } ) Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
--end
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName ) -- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT.
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName ) if EventData.EventUnit then
-- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT. -- So now the EventClass must be a UNIT class!!! We check if it is still "Alive".
if EventData.EventUnit then
-- So now the EventClass must be a UNIT class!!! We check if it is still "Alive".
if EventClass:IsAlive() or
Event.id == EVENTS.PlayerEnterUnit or
Event.id == EVENTS.Crash or
Event.id == EVENTS.Dead or
Event.id == EVENTS.RemoveUnit then
local UnitName = EventClass:GetName()
if ( EventMeta.Side == "I" and UnitName == Event.IniDCSUnitName ) or
( EventMeta.Side == "T" and UnitName == Event.TgtDCSUnitName ) then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.EventFunction then
if Event.IniObjectCategory ~= 3 then
self:F( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
end
local Result, Value = xpcall(
function()
return EventData.EventFunction( EventClass, Event )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ EventMeta.Event ]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
if Event.IniObjectCategory ~= 3 then
self:F( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
return EventFunction( EventClass, Event )
end, ErrorHandler )
end
end
end
else
-- The EventClass is not alive anymore, we remove it from the EventHandlers...
self:RemoveEvent( EventClass, Event.id )
end
else
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
if EventData.EventGroup then
-- So now the EventClass must be a GROUP class!!! We check if it is still "Alive".
if EventClass:IsAlive() or if EventClass:IsAlive() or
Event.id == EVENTS.PlayerEnterUnit or Event.id == EVENTS.PlayerEnterUnit or
Event.id == EVENTS.Crash or Event.id == EVENTS.Crash or
Event.id == EVENTS.Dead or Event.id == EVENTS.Dead or
Event.id == EVENTS.RemoveUnit then Event.id == EVENTS.RemoveUnit then
-- We can get the name of the EventClass, which is now always a GROUP object. local UnitName = EventClass:GetName()
local GroupName = EventClass:GetName()
if ( EventMeta.Side == "I" and GroupName == Event.IniDCSGroupName ) or if ( EventMeta.Side == "I" and UnitName == Event.IniDCSUnitName ) or
( EventMeta.Side == "T" and GroupName == Event.TgtDCSGroupName ) then ( EventMeta.Side == "T" and UnitName == Event.TgtDCSUnitName ) then
-- First test if a EventFunction is Set, otherwise search for the default function -- First test if a EventFunction is Set, otherwise search for the default function
if EventData.EventFunction then if EventData.EventFunction then
if Event.IniObjectCategory ~= 3 then if Event.IniObjectCategory ~= 3 then
self:F( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } ) self:F( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
end end
local Result, Value = xpcall( local Result, Value = xpcall(
function() function()
return EventData.EventFunction( EventClass, Event, unpack( EventData.Params ) ) return EventData.EventFunction( EventClass, Event )
end, ErrorHandler ) end, ErrorHandler )
else else
@ -1143,74 +1132,129 @@ function EVENT:onEvent( Event )
-- Now call the default event function. -- Now call the default event function.
if Event.IniObjectCategory ~= 3 then if Event.IniObjectCategory ~= 3 then
self:F( { "Calling " .. EventMeta.Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } ) self:F( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end end
local Result, Value = xpcall( local Result, Value = xpcall(
function() function()
return EventFunction( EventClass, Event, unpack( EventData.Params ) ) return EventFunction( EventClass, Event )
end, ErrorHandler ) end, ErrorHandler )
end end
end end
end end
else else
-- The EventClass is not alive anymore, we remove it from the EventHandlers... -- The EventClass is not alive anymore, we remove it from the EventHandlers...
--self:RemoveEvent( EventClass, Event.id ) self:RemoveEvent( EventClass, Event.id )
end end
else else
-- If the EventData is not bound to a specific unit, then call the EventClass EventFunction. -- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
-- Note that here the EventFunction will need to implement and determine the logic for the relevant source- or target unit, or weapon. if EventData.EventGroup then
if not EventData.EventUnit then
-- First test if a EventFunction is Set, otherwise search for the default function -- So now the EventClass must be a GROUP class!!! We check if it is still "Alive".
if EventData.EventFunction then if EventClass:IsAlive() or
Event.id == EVENTS.PlayerEnterUnit or
Event.id == EVENTS.Crash or
Event.id == EVENTS.Dead or
Event.id == EVENTS.RemoveUnit then
-- There is an EventFunction defined, so call the EventFunction. -- We can get the name of the EventClass, which is now always a GROUP object.
if Event.IniObjectCategory ~= 3 then local GroupName = EventClass:GetName()
self:F2( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
return EventData.EventFunction( EventClass, Event )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object. if ( EventMeta.Side == "I" and GroupName == Event.IniDCSGroupName ) or
local EventFunction = EventClass[ EventMeta.Event ] ( EventMeta.Side == "T" and GroupName == Event.TgtDCSGroupName ) then
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function. -- First test if a EventFunction is Set, otherwise search for the default function
if Event.IniObjectCategory ~= 3 then if EventData.EventFunction then
self:F2( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
if Event.IniObjectCategory ~= 3 then
self:F( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
end
local Result, Value = xpcall(
function()
return EventData.EventFunction( EventClass, Event, unpack( EventData.Params ) )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ EventMeta.Event ]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
if Event.IniObjectCategory ~= 3 then
self:F( { "Calling " .. EventMeta.Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
return EventFunction( EventClass, Event, unpack( EventData.Params ) )
end, ErrorHandler )
end
end end
end
else
-- The EventClass is not alive anymore, we remove it from the EventHandlers...
--self:RemoveEvent( EventClass, Event.id )
end
else
-- If the EventData is not bound to a specific unit, then call the EventClass EventFunction.
-- Note that here the EventFunction will need to implement and determine the logic for the relevant source- or target unit, or weapon.
if not EventData.EventUnit then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.EventFunction then
-- There is an EventFunction defined, so call the EventFunction.
if Event.IniObjectCategory ~= 3 then
self:F2( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall( local Result, Value = xpcall(
function() function()
local Result, Value = EventFunction( EventClass, Event ) return EventData.EventFunction( EventClass, Event )
return Result, Value
end, ErrorHandler ) end, ErrorHandler )
end else
end
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ EventMeta.Event ]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
if Event.IniObjectCategory ~= 3 then
self:F2( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end
local Result, Value = xpcall(
function()
local Result, Value = EventFunction( EventClass, Event )
return Result, Value
end, ErrorHandler )
end
end
end
end end
end end
end end
end end
end end
end
-- When cargo was deleted, it may probably be because of an S_EVENT_DEAD. -- When cargo was deleted, it may probably be because of an S_EVENT_DEAD.
-- However, in the loading logic, an S_EVENT_DEAD is also generated after a Destroy() call. -- However, in the loading logic, an S_EVENT_DEAD is also generated after a Destroy() call.
-- And this is a problem because it will remove all entries from the SET_CARGOs. -- And this is a problem because it will remove all entries from the SET_CARGOs.
-- To prevent this from happening, the Cargo object has a flag NoDestroy. -- To prevent this from happening, the Cargo object has a flag NoDestroy.
-- When true, the SET_CARGO won't Remove the Cargo object from the set. -- When true, the SET_CARGO won't Remove the Cargo object from the set.
-- But we need to switch that flag off after the event handlers have been called. -- But we need to switch that flag off after the event handlers have been called.
if Event.id == EVENTS.DeleteCargo then if Event.id == EVENTS.DeleteCargo then
Event.Cargo.NoDestroy = nil Event.Cargo.NoDestroy = nil
end
else
self:T( { EventMeta.Text, Event } )
end end
else else
self:T( { EventMeta.Text, Event } ) self:E(string.format("WARNING: Could not get EVENTMETA data for event ID=%d! Is this an unknown/new DCS event?", tostring(Event.id)))
end end
Event = nil Event = nil

View File

@ -1215,34 +1215,64 @@ do -- COORDINATE
--- Build an ground type route point. --- Build an ground type route point.
-- @param #COORDINATE self -- @param #COORDINATE self
-- @param #number Speed (optional) Speed in km/h. The default speed is 20 km/h. -- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h.
-- @param #string Formation (optional) The route point Formation, which is a text string that specifies exactly the Text in the Type of the route point, like "Vee", "Echelon Right". -- @param #string Formation (Optional) The route point Formation, which is a text string that specifies exactly the Text in the Type of the route point, like "Vee", "Echelon Right".
-- @param #table DCSTasks A table of DCS tasks that are executed at the waypoints. Mind the curly brackets {}! -- @param #table DCSTasks (Optional) A table of DCS tasks that are executed at the waypoints. Mind the curly brackets {}!
-- @return #table The route point. -- @return #table The route point.
function COORDINATE:WaypointGround( Speed, Formation, DCSTasks ) function COORDINATE:WaypointGround( Speed, Formation, DCSTasks )
self:F2( { Formation, Speed } ) self:F2( { Speed, Formation, DCSTasks } )
local RoutePoint = {} local RoutePoint = {}
RoutePoint.x = self.x
RoutePoint.y = self.z
RoutePoint.action = Formation or "" RoutePoint.x = self.x
--RoutePoint.formation_template = Formation and "" or nil RoutePoint.y = self.z
RoutePoint.alt = self:GetLandHeight()+1 -- self.y
RoutePoint.alt_type = COORDINATE.WaypointAltType.BARO
RoutePoint.action = Formation or "Off Road"
RoutePoint.formation_template=""
RoutePoint.ETA=0
RoutePoint.ETA_locked=true
RoutePoint.speed = ( Speed or 20 ) / 3.6 RoutePoint.speed = ( Speed or 20 ) / 3.6
RoutePoint.speed_locked = true RoutePoint.speed_locked = true
-- ["task"] = RoutePoint.task = {}
-- { RoutePoint.task.id = "ComboTask"
-- ["id"] = "ComboTask", RoutePoint.task.params = {}
-- ["params"] = RoutePoint.task.params.tasks = DCSTasks or {}
-- {
-- ["tasks"] = return RoutePoint
-- { end
-- }, -- end of ["tasks"]
-- }, -- end of ["params"] --- Build route waypoint point for Naval units.
-- }, -- end of ["task"] -- @param #COORDINATE self
-- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h.
-- @param #string Depth (Optional) Dive depth in meters. Only for submarines. Default is COORDINATE.y component.
-- @param #table DCSTasks (Optional) A table of DCS tasks that are executed at the waypoints. Mind the curly brackets {}!
-- @return #table The route point.
function COORDINATE:WaypointNaval( Speed, Depth, DCSTasks )
self:F2( { Speed, Depth, DCSTasks } )
local RoutePoint = {}
RoutePoint.x = self.x
RoutePoint.y = self.z
RoutePoint.alt = Depth or self.y -- Depth is for submarines only. Ships should have alt=0.
RoutePoint.alt_type = "BARO"
RoutePoint.type = "Turning Point"
RoutePoint.action = "Turning Point"
RoutePoint.formation_template = ""
RoutePoint.ETA=0
RoutePoint.ETA_locked=true
RoutePoint.speed = ( Speed or 20 ) / 3.6
RoutePoint.speed_locked = true
RoutePoint.task = {} RoutePoint.task = {}
RoutePoint.task.id = "ComboTask" RoutePoint.task.id = "ComboTask"

View File

@ -342,8 +342,9 @@ AIRBASE.TerminalType = {
-- @return Wrapper.Airbase#AIRBASE -- @return Wrapper.Airbase#AIRBASE
function AIRBASE:Register( AirbaseName ) function AIRBASE:Register( AirbaseName )
local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) ) local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) ) --#AIRBASE
self.AirbaseName = AirbaseName self.AirbaseName = AirbaseName
self.AirbaseID = self:GetID(true)
self.AirbaseZone = ZONE_RADIUS:New( AirbaseName, self:GetVec2(), 2500 ) self.AirbaseZone = ZONE_RADIUS:New( AirbaseName, self:GetVec2(), 2500 )
return self return self
end end
@ -380,7 +381,7 @@ function AIRBASE:FindByID(id)
for name,_airbase in pairs(_DATABASE.AIRBASES) do for name,_airbase in pairs(_DATABASE.AIRBASES) do
local airbase=_airbase --#AIRBASE local airbase=_airbase --#AIRBASE
local aid=tonumber(airbase:GetID()) local aid=tonumber(airbase:GetID(true))
if aid==id then if aid==id then
return airbase return airbase
@ -430,6 +431,54 @@ function AIRBASE.GetAllAirbases(coalition, category)
return airbases return airbases
end end
--- Get ID of the airbase.
-- @param #AIRBASE self
-- @param #boolean unique (Optional) If true, ships will get a negative sign as the unit ID might be the same as an airbase ID. Default off!
-- @return #number The airbase ID.
function AIRBASE:GetID(unique)
if self.AirbaseID then
return unique and self.AirbaseID or math.abs(self.AirbaseID)
else
for DCSAirbaseId, DCSAirbase in pairs(world.getAirbases()) do
-- Get the airbase name.
local AirbaseName = DCSAirbase:getName()
-- This gives the incorrect value to be inserted into the airdromeID for DCS 2.5.6!
local airbaseID=tonumber(DCSAirbase:getID())
-- No way AFIK to get the DCS version. So we check if the event exists. That should tell us if we are on DCS 2.5.6 or prior to that.
if world.event.S_EVENT_KILL and world.event.S_EVENT_KILL>0 and self:GetAirbaseCategory()==Airbase.Category.AIRDROME then
-- We have to take the key value of this loop!
airbaseID=DCSAirbaseId
-- Now another quirk: for Caucasus, we need to add 11 to the key value to get the correct ID. See https://forums.eagle.ru/showpost.php?p=4210774&postcount=11
if UTILS.GetDCSMap()==DCSMAP.Caucasus then
airbaseID=airbaseID+11
end
end
if AirbaseName==self.AirbaseName then
if self:GetAirbaseCategory()==Airbase.Category.SHIP then
-- Ships get a negative sign as their unit number might be the same as the ID of another airbase.
return unique and -airbaseID or airbaseID
else
return airbaseID
end
end
end
end
return nil
end
--- Returns a table of parking data for a given airbase. If the optional parameter *available* is true only available parking will be returned, otherwise all parking at the base is returned. Term types have the following enumerated values: --- Returns a table of parking data for a given airbase. If the optional parameter *available* is true only available parking will be returned, otherwise all parking at the base is returned. Term types have the following enumerated values:
-- --

View File

@ -861,34 +861,18 @@ function CONTROLLABLE:TaskAttackGroup( AttackGroup, WeaponType, WeaponExpend, At
-- } -- }
-- } -- }
local DirectionEnabled = nil
if Direction then
DirectionEnabled = true
else
DirectionEnabled = false
Direction=0
end
local AltitudeEnabled = nil local DCSTask = { id = 'AttackGroup',
if Altitude then
AltitudeEnabled = true
else
AltitudeEnabled = false
Altitude=0
end
local DCSTask
DCSTask = { id = 'AttackGroup',
params = { params = {
groupId = AttackGroup:GetID(), groupId = AttackGroup:GetID(),
weaponType = WeaponType, weaponType = WeaponType or 1073741822,
expend = WeaponExpend, expend = WeaponExpend or "Auto",
attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty, attackQty = AttackQty,
directionEnabled = DirectionEnabled, directionEnabled = Direction and true or false,
direction = Direction, direction = Direction and math.rad(Direction) or nil,
altitudeEnabled = AltitudeEnabled, altitudeEnabled = Altitude and true or false,
altitude = Altitude, altitude = Altitude,
attackQtyLimit = AttackQtyLimit,
}, },
}, },
@ -914,15 +898,15 @@ function CONTROLLABLE:TaskAttackUnit(AttackUnit, GroupAttack, WeaponExpend, Atta
id = 'AttackUnit', id = 'AttackUnit',
params = { params = {
unitId = AttackUnit:GetID(), unitId = AttackUnit:GetID(),
groupAttack = GroupAttack or false, groupAttack = GroupAttack and GroupAttack or false,
expend = WeaponExpend or "Auto", expend = WeaponExpend or "Auto",
directionEnabled = Direction and true or false, directionEnabled = Direction and true or false,
direction = math.rad(Direction or 0), direction = Direction and math.rad(Direction) or nil,
altitudeEnabled = Altitude and true or false, altitudeEnabled = Altitude and true or false,
altitude = Altitude or math.max(1000, AttackUnit:GetAltitude()), altitude = Altitude,
attackQtyLimit = AttackQty and true or false, attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty, attackQty = AttackQty,
weaponType = WeaponType weaponType = WeaponType or 1073741822,
} }
} }
@ -946,25 +930,6 @@ end
function CONTROLLABLE:TaskBombing( Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, Divebomb ) function CONTROLLABLE:TaskBombing( Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, Divebomb )
self:F( { self.ControllableName, Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, Divebomb } ) self:F( { self.ControllableName, Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, Divebomb } )
local _groupattack=false
if GroupAttack then
_groupattack=GroupAttack
end
local _direction=0
local _directionenabled=false
if Direction then
_direction=math.rad(Direction)
_directionenabled=true
end
local _altitude=5000
local _altitudeenabled=false
if Altitude then
_altitude=Altitude
_altitudeenabled=true
end
local _attacktype=nil local _attacktype=nil
if Divebomb then if Divebomb then
_attacktype="Dive" _attacktype="Dive"
@ -975,17 +940,18 @@ function CONTROLLABLE:TaskBombing( Vec2, GroupAttack, WeaponExpend, AttackQty, D
DCSTask = { DCSTask = {
id = 'Bombing', id = 'Bombing',
params = { params = {
point = Vec2,
x = Vec2.x, x = Vec2.x,
y = Vec2.y, y = Vec2.y,
groupAttack = _groupattack, groupAttack = GroupAttack and GroupAttack or false,
expend = WeaponExpend or "Auto", expend = WeaponExpend or "Auto",
attackQtyLimit = false, attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty or 1, attackQty = AttackQty,
directionEnabled = _directionenabled, directionEnabled = Direction and true or false,
direction = _direction, direction = Direction and math.rad(Direction) or nil,
altitudeEnabled = _altitudeenabled, altitudeEnabled = Altitude and true or false,
altitude = _altitude, altitude = Altitude,
weaponType = WeaponType, weaponType = WeaponType or 1073741822,
attackType = _attacktype, attackType = _attacktype,
}, },
} }
@ -998,7 +964,7 @@ end
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCS#Vec2 Vec2 2D-coordinates of the point to deliver weapon at. -- @param DCS#Vec2 Vec2 2D-coordinates of the point to deliver weapon at.
-- @param #boolean GroupAttack (Optional) If true, all units in the group will attack the Unit when found. -- @param #boolean GroupAttack (Optional) If true, all units in the group will attack the Unit when found.
-- @param DCS#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 DCS#AI.Task.WeaponExpend WeaponExpend (Optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit 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 DCS#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 DCS#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 #number Altitude (Optional) The altitude [meters] from where to attack. Default 30 m. -- @param #number Altitude (Optional) The altitude [meters] from where to attack. Default 30 m.
@ -1021,7 +987,7 @@ function CONTROLLABLE:TaskAttackMapObject( Vec2, GroupAttack, WeaponExpend, Atta
directionEnabled = Direction and true or false, directionEnabled = Direction and true or false,
direction = Direction, direction = Direction,
altitudeEnabled = Altitude and true or false, altitudeEnabled = Altitude and true or false,
altitude = Altitude or 30, altitude = Altitude,
weaponType = WeaponType or 1073741822, weaponType = WeaponType or 1073741822,
}, },
}, },
@ -1035,7 +1001,7 @@ end
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCS#Vec2 Vec2 2D-coordinates of the point to deliver weapon at. -- @param DCS#Vec2 Vec2 2D-coordinates of the point to deliver weapon at.
-- @param #boolean GroupAttack (optional) If true, all units in the group will attack the Unit when found. -- @param #boolean GroupAttack (optional) If true, all units in the group will attack the Unit when found.
-- @param DCS#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 DCS#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit 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 DCS#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 DCS#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 #number Altitude (optional) The altitude from where to attack. -- @param #number Altitude (optional) The altitude from where to attack.
@ -1045,55 +1011,24 @@ end
function CONTROLLABLE:TaskCarpetBombing(Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, CarpetLength) function CONTROLLABLE:TaskCarpetBombing(Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, CarpetLength)
self:F2( { self.ControllableName, Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, CarpetLength } ) self:F2( { self.ControllableName, Vec2, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, WeaponType, CarpetLength } )
local _groupattack=false
if GroupAttack then
_groupattack=GroupAttack
end
local _direction=0
local _directionenabled=false
if Direction then
_direction=math.rad(Direction)
_directionenabled=true
end
local _altitude=0
local _altitudeenabled=false
if Altitude then
_altitude=Altitude
_altitudeenabled=true
end
-- default to 500m
local _carpetLength = 500
if CarpetLength then
_carpetLength = CarpetLength
end
local _weaponexpend = "Auto"
if WeaponExpend then
_weaponexpend = WeaponExpend
end
-- Build Task Structure -- Build Task Structure
local DCSTask local DCSTask = {
DCSTask = {
id = 'CarpetBombing', id = 'CarpetBombing',
params = { params = {
attackType = "Carpet", attackType = "Carpet",
point = Vec2, point = Vec2,
x = Vec2.x, x = Vec2.x,
y = Vec2.y, y = Vec2.y,
groupAttack = _groupattack, groupAttack = GroupAttack and GroupAttack or false,
carpetLength = _carpetLength, carpetLength = CarpetLength or 500,
weaponType = WeaponType, weaponType = WeaponType or ENUMS.WeaponFlag.AnyBomb,
expend = "All", expend = WeaponExpend or "All",
attackQtyLimit = false, --AttackQty and true or false, attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty or 1, attackQty = AttackQty,
directionEnabled = _directionenabled, directionEnabled = Direction and true or false,
direction = _direction, direction = Direction and math.rad(Direction) or nil,
altitudeEnabled = _altitudeenabled, altitudeEnabled = Altitude and true or false,
altitude = _altitude altitude = Altitude,
} }
} }
@ -1148,7 +1083,15 @@ function CONTROLLABLE:TaskEmbarking(Vec2, GroupSetForEmbarking, Duration, Distri
return nil return nil
end end
-- Table of group IDs for embarking.
local Distribution={}
if DistributionGroupSet then
for _,_group in pairs(DistributionGroupSet:GetSet()) do
local group=_group --Wrapper.Group#GROUP
table.insert(Distribution, group:GetID())
end
end
local DCSTask = { local DCSTask = {
id = 'Embarking', id = 'Embarking',
@ -1169,68 +1112,22 @@ function CONTROLLABLE:TaskEmbarking(Vec2, GroupSetForEmbarking, Duration, Distri
end end
--- (AIR) Move the controllable to a Vec2 Point, wait for a defined duration and embark a controllable.
-- @param #CONTROLLABLE self
-- @param DCS#Vec2 Vec2 The point where to wait.
-- @param #number Duration The duration in seconds to wait.
-- @param #CONTROLLABLE EmbarkingControllable The controllable to be embarked.
-- @return DCS#Task The DCS task structure
function CONTROLLABLE:TaskDisembarking(Vec2, Duration, EmbarkingControllable)
-- Table of group IDs for embarking.
local g4e={}
if GroupSetForEmbarking then
for _,_group in pairs(GroupSetForEmbarking:GetSet()) do
local group=_group --Wrapper.Group#GROUP
table.insert(g4e, group:GetID())
end
else
self:E("ERROR: No groups for embarking specified!")
return nil
end
local DCSTask = {
id = 'Disembarking',
params = {
point = Vec2,
x = Vec2.x,
y = Vec2.y,
duration = Duration,
groupsForEmbarking = { EmbarkingControllable:GetID() },
durationFlag = durationflag,
distributionFlag = false,
distribution = {},
}
}
return DCSTask
end
----
--- (AIR) Orbit at a specified position at a specified alititude during a specified duration with a specified speed. --- (AIR) Orbit at a specified position at a specified alititude during a specified duration with a specified speed.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param DCS#Vec2 Point The point to hold the position. -- @param DCS#Vec2 Point The point to hold the position.
-- @param #number Altitude The altitude [m] to hold the position. -- @param #number Altitude The altitude AGL in meters to hold the position.
-- @param #number Speed The speed [m/s] flying when holding the position. -- @param #number Speed The speed [m/s] flying when holding the position.
-- @return #CONTROLLABLE self -- @return #CONTROLLABLE self
function CONTROLLABLE:TaskOrbitCircleAtVec2( Point, Altitude, Speed ) function CONTROLLABLE:TaskOrbitCircleAtVec2( Point, Altitude, Speed )
self:F2( { self.ControllableName, Point, Altitude, Speed } ) self:F2( { self.ControllableName, Point, Altitude, Speed } )
local LandHeight = land.getHeight( Point )
self:T3( { LandHeight } )
local DCSTask = { local DCSTask = {
id = 'Orbit', id = 'Orbit',
params = { params = {
pattern = AI.Task.OrbitPattern.CIRCLE, pattern = AI.Task.OrbitPattern.CIRCLE,
point = Point, point = Point,
speed = Speed, speed = Speed,
altitude = Altitude + LandHeight altitude = Altitude + land.getHeight( Point )
} }
} }
@ -1331,7 +1228,7 @@ function CONTROLLABLE:TaskBombingRunway(Airbase, WeaponType, WeaponExpend, Attac
expend = WeaponExpend or AI.Task.WeaponExpend.ALL, expend = WeaponExpend or AI.Task.WeaponExpend.ALL,
attackQty = AttackQty or 1, attackQty = AttackQty or 1,
direction = Direction and math.rad(Direction) or nil, direction = Direction and math.rad(Direction) or nil,
groupAttack = GroupAttack, groupAttack = GroupAttack and GroupAttack or false,
}, },
} }
@ -1419,14 +1316,13 @@ function CONTROLLABLE:TaskFollow( FollowControllable, Vec3, LastWaypointIndex )
lastWptIndexFlagChangedManually = true lastWptIndexFlagChangedManually = true
end end
local DCSTask local DCSTask = {
DCSTask = {
id = 'Follow', id = 'Follow',
params = { params = {
groupId = FollowControllable:GetID(), groupId = FollowControllable:GetID(),
pos = Vec3, pos = Vec3,
lastWptIndexFlag = LastWaypointIndexFlag, lastWptIndexFlag = LastWaypointIndexFlag,
lastWptIndex = LastWaypointIndex, lastWptIndex = LastWaypointIndex,
lastWptIndexFlagChangedManually = lastWptIndexFlagChangedManually, lastWptIndexFlagChangedManually = lastWptIndexFlagChangedManually,
} }
} }
@ -1444,7 +1340,7 @@ end
-- @param DCS#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 DCS#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 EngagementDistance 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 EngagementDistance 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 DCS#AttributeNameArray TargetTypes Array of AttributeName that is contains threat categories allowed to engage. -- @param DCS#AttributeNameArray TargetTypes Array of AttributeName that is contains threat categories allowed to engage. Default {"Air"}.
-- @return DCS#Task The DCS task structure. -- @return DCS#Task The DCS task structure.
function CONTROLLABLE:TaskEscort( FollowControllable, Vec3, LastWaypointIndex, EngagementDistance, TargetTypes ) function CONTROLLABLE:TaskEscort( FollowControllable, Vec3, LastWaypointIndex, EngagementDistance, TargetTypes )
self:F2( { self.ControllableName, FollowControllable, Vec3, LastWaypointIndex, EngagementDistance, TargetTypes } ) self:F2( { self.ControllableName, FollowControllable, Vec3, LastWaypointIndex, EngagementDistance, TargetTypes } )
@ -1461,22 +1357,16 @@ function CONTROLLABLE:TaskEscort( FollowControllable, Vec3, LastWaypointIndex, E
-- } -- }
-- } -- }
local LastWaypointIndexFlag = false
if LastWaypointIndex then
LastWaypointIndexFlag = true
end
TargetTypes=TargetTypes or {}
local DCSTask local DCSTask
DCSTask = { id = 'Escort', DCSTask = {
id = 'Escort',
params = { params = {
groupId = FollowControllable:GetID(), groupId = FollowControllable:GetID(),
pos = Vec3, pos = Vec3,
lastWptIndexFlag = LastWaypointIndexFlag, lastWptIndexFlag = LastWaypointIndex and true or false,
lastWptIndex = LastWaypointIndex, lastWptIndex = LastWaypointIndex,
engagementDistMax = EngagementDistance, engagementDistMax = EngagementDistance,
targetTypes = TargetTypes, targetTypes = TargetTypes or {"Air"},
}, },
}, },
@ -1650,29 +1540,19 @@ function CONTROLLABLE:EnRouteTaskEngageGroup( AttackGroup, Priority, WeaponType,
-- } -- }
-- } -- }
local DirectionEnabled = nil local DCSTask = {
if Direction then id = 'EngageControllable',
DirectionEnabled = true
end
local AltitudeEnabled = nil
if Altitude then
AltitudeEnabled = true
end
local DCSTask
DCSTask = { id = 'EngageControllable',
params = { params = {
groupId = AttackGroup:GetID(), groupId = AttackGroup:GetID(),
weaponType = WeaponType, weaponType = WeaponType,
expend = WeaponExpend, expend = WeaponExpend or "Auto",
attackQty = AttackQty, directionEnabled = Direction and true or false,
directionEnabled = DirectionEnabled, direction = Direction,
direction = Direction, altitudeEnabled = Altitude and true or false,
altitudeEnabled = AltitudeEnabled, altitude = Altitude,
altitude = Altitude, attackQtyLimit = AttackQty and true or false,
attackQtyLimit = AttackQtyLimit, attackQty = AttackQty,
priority = Priority, priority = Priority or 1,
}, },
}, },
@ -1694,36 +1574,22 @@ end
-- @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 DCS#Task The DCS task structure. -- @return DCS#Task The DCS task structure.
function CONTROLLABLE:EnRouteTaskEngageUnit( EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack ) function CONTROLLABLE:EnRouteTaskEngageUnit( EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack )
self:F2( { self.ControllableName, EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack } ) self:F2( { self.ControllableName, EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack } )
-- EngageUnit = { local DCSTask = {
-- id = 'EngageUnit', id = 'EngageUnit',
-- params = {
-- unitId = Unit.ID,
-- weaponType = number,
-- expend = enum AI.Task.WeaponExpend
-- attackQty = number,
-- direction = Azimuth,
-- attackQtyLimit = boolean,
-- controllableAttack = boolean,
-- priority = number,
-- }
-- }
local DCSTask
DCSTask = { id = 'EngageUnit',
params = { params = {
unitId = EngageUnit:GetID(), unitId = EngageUnit:GetID(),
priority = Priority or 1, priority = Priority or 1,
groupAttack = GroupAttack or false, groupAttack = GroupAttack and GroupAttack or false,
visible = Visible or false, visible = Visible and Visible or false,
expend = WeaponExpend or "Auto", expend = WeaponExpend or "Auto",
directionEnabled = Direction and true or false, directionEnabled = Direction and true or false,
direction = Direction, direction = Direction and math.rad(Direction) or nil,
altitudeEnabled = Altitude and true or false, altitudeEnabled = Altitude and true or false,
altitude = Altitude, altitude = Altitude,
attackQtyLimit = AttackQty and true or false, attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty, attackQty = AttackQty,
controllableAttack = ControllableAttack, controllableAttack = ControllableAttack,
}, },
}, },
@ -1782,33 +1648,22 @@ end
-- If the task is assigned to the controllable lead unit will be a FAC. -- If the task is assigned to the controllable lead unit will be a FAC.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param Wrapper.Controllable#CONTROLLABLE AttackGroup Target CONTROLLABLE. -- @param Wrapper.Controllable#CONTROLLABLE AttackGroup Target CONTROLLABLE.
-- @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 (Optional) 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. Default is 0.
-- @param #number WeaponType 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. Default is "Auto".
-- @param DCS#AI.Task.Designation Designation (optional) Designation type. -- @param DCS#AI.Task.Designation Designation (Optional) Designation type.
-- @param #boolean Datalink (optional) Allows to use datalink to send the target information to attack aircraft. Enabled by default. -- @param #boolean Datalink (optional) Allows to use datalink to send the target information to attack aircraft. Enabled by default.
-- @return DCS#Task The DCS task structure. -- @return DCS#Task The DCS task structure.
function CONTROLLABLE:EnRouteTaskFAC_EngageGroup( AttackGroup, Priority, WeaponType, Designation, Datalink ) function CONTROLLABLE:EnRouteTaskFAC_EngageGroup( AttackGroup, Priority, WeaponType, Designation, Datalink )
self:F2( { self.ControllableName, AttackGroup, WeaponType, Priority, Designation, Datalink } ) self:F2( { self.ControllableName, AttackGroup, WeaponType, Priority, Designation, Datalink } )
-- FAC_EngageControllable = { local DCSTask = {
-- id = 'FAC_EngageControllable', id = 'FAC_EngageControllable',
-- params = {
-- groupId = Group.ID,
-- weaponType = number,
-- designation = enum AI.Task.Designation,
-- datalink = boolean,
-- priority = number,
-- }
-- }
local DCSTask
DCSTask = { id = 'FAC_EngageControllable',
params = { params = {
groupId = AttackGroup:GetID(), groupId = AttackGroup:GetID(),
weaponType = WeaponType, weaponType = WeaponType or "Auto",
designation = Designation, designation = Designation,
datalink = Datalink, datalink = Datalink and Datalink or false,
priority = Priority, priority = Priority or 0,
} }
} }
@ -1979,9 +1834,12 @@ function CONTROLLABLE:TaskEmbarkToTransport( Point, Radius )
self:F2( { self.ControllableName, Point, Radius } ) self:F2( { self.ControllableName, Point, Radius } )
local DCSTask --DCS#Task local DCSTask --DCS#Task
DCSTask = { id = 'EmbarkToTransport', DCSTask = {
params = { x = Point.x, id = 'EmbarkToTransport',
y = Point.y, params = {
point = Point,
x = Point.x,
y = Point.y,
zoneRadius = Radius, zoneRadius = Radius,
} }
} }
@ -2233,8 +2091,13 @@ end
function CONTROLLABLE:TaskRoute( Points ) function CONTROLLABLE:TaskRoute( Points )
self:F2( Points ) self:F2( Points )
local DCSTask local DCSTask = {
DCSTask = { id = 'Mission', params = { route = { points = Points, }, }, } id = 'Mission',
params = {
airborne = self:IsAir(),
route = {points = Points},
},
}
self:T3( { DCSTask } ) self:T3( { DCSTask } )
return DCSTask return DCSTask