walder/Skynet-IADS

C-RAM Phalanx stay off when bombs are inbound

Opened this issue · 0 comments

C-RAM Phalanx units managed by Skynet stay off when bombs are inbound, but they are perfectly capable to engage them.
The Phalanx are the first and only units that can engage bombs (as far as I know) so it was not a problem before, but we can note that in Skynet, this behavior is not by design but rather by accident.

In SkynetIADS.evaluateContacts(self), we decide which contacts will be passed to the IADS sites as follows:

local description = contact:getDesc()
local category = description.category
if category and category ~= Unit.Category.GROUND_UNIT and category ~= Unit.Category.SHIP and category ~= Unit.Category.STRUCTURE then
    samToTrigger:informOfContact(contact)
end

This will not always work, because it assumes that the contact is a unit. But actually a contact can be a unit or a weapon.
Categories returned by description.category will not be the same for a unit or a weapon:

Unit.Category = { AIRPLANE=0, HELICOPTER=1, GROUND_UNIT=2, SHIP=3, STRUCTURE=4 }
Weapon.Category = { SHELL=0, MISSILE=1, ROCKET=2, BOMB=3 }

As it is, we consider only the units categories that are not in [2, 3, 4], that is:
An airplane or a helicopter will be passed to the sites as designed
A missile (HARM, JSOW...) will be passed as well but only by chance because its category is equal to AIRPLANE

A bomb will not be passed because its category is the same as the SHIP category for units.

Proposed correction consists in correctly considering the contact object category before looking at its description category.

Note 1: we could enhance that by only turning the site on when it can indeed engage the target, like it is done for the HARMs.
Note 2: maybe the shells and rockets can be engaged by the CRAMs as it is in real life ?

Here is the proposed correction, that I will also put in a PR shortly.

local bShouldInform = false
local objectCategory = Object.getCategory(contact:getDCSRepresentation())
local category = contact:getDesc().category

if (objectCategory == Object.Category.UNIT) then
	bShouldInform = category ~= Unit.Category.GROUND_UNIT and category ~= Unit.Category.SHIP and category ~= Unit.Category.STRUCTURE
elseif (objectCategory == Object.Category.WEAPON) then
	bShouldInform = category ~= Weapon.Category.SHELL and category ~= Weapon.Category.ROCKET
end

if category and bShouldInform then
	samToTrigger:informOfContact(contact)
end