Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm and add UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED #129

Open
Luashine opened this issue Dec 31, 2023 · 1 comment
Open

Confirm and add UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED #129

Luashine opened this issue Dec 31, 2023 · 1 comment

Comments

@Luashine
Copy link
Collaborator

public enum TargetsAllowed
{
    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,
    Allied = 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,
    NonSuicidal = 1 << 28,
    Suicidal = 1 << 29,
    NonAncient = 1 << 30,
    Ancient = 1 << 31,

    NotSelf = PlayerUnits | Allied | Neutral | Enemy,
    Friend = PlayerUnits | Allied,
}

so I believe this is its structure

By Arxos in Hive Discord

@Luashine
Copy link
Collaborator Author

Luashine commented Jun 19, 2024

I double checked it, the list is almost complete:

"NONE" is missing from table above = value 1
"TERRAIN" returns 0 -- a bug?
"Non-Sapper" in WE, "NonSuicidal" name by Arxos
"Sapper" in WE, "Suicidal" name by Arxos
<NONE SELECTED> aka WE enforces some default = -36573170 = Ground | Air | Structure | Self | PlayerUnits | Allied | Neutral | Enemy | Vulnerable | Hero | NonHero | Alive | Organic | Mech | NonSapper | Sapper | NonAncient | Ancient

I've done some more testing with NONE and TERRAIN. "NONE" seems to be a legit target flag, if its ON (i've only tested it alone) then the unit will not have an attack nor an attack icon. However all UI order buttons will be present. Except when you click a target unit (frost arrow with NONE) then your unit will just "attack move" to that position (actually just move)

With only "TERRAIN" enabled I think the game resets it to default from above. Everything works. I am not sure if TERRAIN is supposed to be there or do anything special. I thought they had just swapped terrain & none.

Here's one old post asking about terrain not working, no further explanation: https://www.hiveworkshop.com/threads/help-can-cold-arrows-target-terrain.217982/

BlzGetUnitWeaponIntegerField(u, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0) because in this lookup code I don't specify anything, the confusion is ought to be on WorldEditors end.

unit - weapon1 / weapon2
h000 - air/alive 4,16777216
h001 - allies/ancient 16384,-2147483648
h002 - bridge/dead 1024,33554432
h003 - debris/deco 256,512
h004 - enemy/friend 65536,24576
h005 - ground/hero 2,4194304
h006 - invul/item 2097152,32
h007 - mech/neutr 134217728,32768
h008 - non-ancient/none 1073741824,1
h009 - non-hero/non-sapper 8388608,268435456
h00A - not self/organic 122880,67108864
h00B - player/sapper 8192,536870912
h00C - self/structure 4096,8
h00D - terrain/tree 0,64
h00E - vulnerable/wall 1048576,128
h00F - ward/NONE SELECTED 16,-36573170

--[[
unitweaponintegerfield UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED
native BlzGetUnitWeaponIntegerField takes unit whichUnit, unitweaponintegerfield whichField, integer index returns integer
native BlzSetUnitWeaponIntegerField takes unit whichUnit, unitweaponintegerfield whichField, integer index, integer value returns boolean
]]

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)")
unitRawcodes = {
"h000","h001",
"h002","h003",
"h004","h005",
"h006","h007",
"h008","h009",
"h00A","h00B",
"h00C","h00D",
"h00E","h00F",
}
for _, rawcode in ipairs(unitRawcodes) do
	printUnitAttacks(rawcode)
end

I don't know if either TERRAIN/NONE have some special behavior when used with other natives or orders. If anyone has any ideas, feel free. I will attach the map with units having one target type per attack and the tests with none/terrain. It will save you some time setting it up.

LuaDebug-AttackTargetTypes.zip

Luashine added a commit to Luashine/jassdoc that referenced this issue Jun 19, 2024
lep pushed a commit that referenced this issue Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant