UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED

comment

Used to access WorldEditor's unit data field "Combat - Attack 1/2 - Targets Allowed" (ua1g/ua2g aka targs1/targs2) which is a bitfield for allowed types.

Indexing starts from zero, hence access "Attack 1" with index 0 and "Attack 2" with index 1. Units can only have 2 attacks max.

Example (Lua):

function printUnitAttacks(unitType)
    local u = CreateUnit(Player(0), FourCC(unitType), -30, 0, 90)
    local wpn0 = BlzGetUnitWeaponIntegerField(u, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
    local wpn1 = BlzGetUnitWeaponIntegerField(u, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 1)
    local wpn2 = BlzGetUnitWeaponIntegerField(u, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 2)
    print(string.format("%4s: %14d %14d %6d", unitType, wpn0, wpn1, wpn2))
    RemoveUnit(u)
end
print("unitType | idx0, idx1, idx2 (if buggy)")
printUnitAttacks("hgry")
note

Works as intended

note

Each type has a corresponding bit if targeting is enabled

TARGETS_ALLOWED = {
    Terrain = 0, -- bug or not implemented? Appears to use default
    None = 1, -- disables weapon, weird behavior, beware <https://github.com/lep/jassdoc/issues/129>
    Ground = 1 << 1,
    Air = 1 << 2,
    Structure = 1 << 3,
    Ward = 1 << 4,
    Item = 1 << 5,
    Tree = 1 << 6,
    Wall = 1 << 7,
    Debris = 1 << 8,
    Decoration = 1 << 9,
    Bridge = 1 << 10,

    Self = 1 << 12,
    PlayerUnits = 1 << 13,
    Allies = 1 << 14,
    Neutral = 1 << 15,
    Enemy = 1 << 16,

    Vulnerable = 1 << 20,
    Invulnerable = 1 << 21,
    Hero = 1 << 22,
    NonHero = 1 << 23,
    Alive = 1 << 24,
    Dead = 1 << 25,
    Organic = 1 << 26,
    Mechanical = 1 << 27,
    NonSapper = 1 << 28,
    Sapper = 1 << 29,
    NonAncient = 1 << 30,
    Ancient = 1 << 31,

    NotSelf = PlayerUnits | Allies | Neutral | Enemy,
    Friend = PlayerUnits | Allies,
    DefaultWE = Ground | Air | Structure | Self | PlayerUnits | Allied | Neutral | Enemy | Vulnerable | Hero | NonHero | Alive | Organic | Mech | NonSapper | Sapper | NonAncient | Ancient -- -36573170; when nothing was selected
}
patch

1.31.0.11889

Source
common.j (raise an issue to discuss on Github or submit a PR)
Source code
    constant unitweaponintegerfield UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED           = ConvertUnitWeaponIntegerField('ua1g')