• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Is there a way to get the attack type of a unit?

Status
Not open for further replies.
Level 42
Joined
Feb 27, 2007
Messages
5,330
You can write a function that clones a unit, forces it to attack a dummy (or a few), and calculates what the attack type must be based on the damage actually dealt... but it wouldn't be instant or perfectly accurate.

A better solution would probably be to precache all units' attack types in a hashtable. Store under the index [Rawcode of Unit-type] for each unit-type. Then load that data later when you want to know. attacktype, weapontype, and damagetype might not be valid objects to save in hashtables, in which case you should probably store the integers used for each *-type when they're defined.

For example you store 0 for whoknows: constant weapontype WEAPON_TYPE_WHOKNOWS = ConvertWeaponType(0)
 
Level 14
Joined
Nov 4, 2006
Messages
1,241
depending on how many units you have you could set variables (can be string, or you use an integer for each attack type) for each unit and check for that instead.

if a unit has two different attack types you can check also the attacked unit, wether it's flying, building, etc. and then determine it by that.
it's sort of a big one time effort though
 
Level 13
Joined
Mar 29, 2012
Messages
542
You can write a function that clones a unit, forces it to attack a dummy (or a few), and calculates what the attack type must be based on the damage actually dealt... but it wouldn't be instant or perfectly accurate.
I've been considering this one, but there are some armor reductions that has the 2 same values; like Pierce has the same reduction against Normal and Large.
2018-08-14-18_12_12-edit-gameplay-constant-defense-table-png.304409

This is not effective.
A better solution would probably be to precache all units' attack types in a hashtable. Store under the index [Rawcode of Unit-type] for each unit-type. Then load that data later when you want to know. attacktype, weapontype, and damagetype might not be valid objects to save in hashtables, in which case you should probably store the integers used for each *-type when they're defined.
I don't really like this one. :/
depending on how many units you have you could set variables (can be string, or you use an integer for each attack type) for each unit and check for that instead.

if a unit has two different attack types you can check also the attacked unit, wether it's flying, building, etc. and then determine it by that.
it's sort of a big one time effort though
Same as this.

It seems these are all the options possible?
 

Attachments

  • 2018-08-14 18_12_12-Edit Gameplay Constant - Defense Table.png
    2018-08-14 18_12_12-Edit Gameplay Constant - Defense Table.png
    4.7 KB · Views: 112
Level 42
Joined
Feb 27, 2007
Messages
5,330
Does your map really have so many different types of units that it would still take more time to write out a trigger that precaches all their attack types than it would to wait for a better idea to appear in this thread? You could even make a error-displaying function that would notify you when you try to get the attacktype of a unit-type that hasn't been cached so you know you forgot to add it to the hashtable. This method, unlike my other suggestion, would actually work without errors or guesswork.

there are some armor reductions that has the 2 same values
That's why I said "attack a dummy (or a few)". This method would also be less accurate the larger range a unit's attack damage values has (I believe damage dice is the right phrase in the OE); a unit that does 11-11 damage will be easy to determine, but a unit that does 7-13 damage would be much more difficult/come with much greater uncertainty. If your damage range is large enough some reduction values would be within the uncertainty of your % reduction computation and then you couldn't even be sure the attack type you got was correct. Add to that, as I said, that this will take actual time to complete so it can't work as a function call or part of a larger trigger and you end up with a spectacularly awful way to tackle this question. Precache like UreDe4D and I suggested.
 
Level 13
Joined
Mar 29, 2012
Messages
542
I'm actually making an AI system that will be submitted here, so it's not just for my map.
I think if someone's map for example use random creep unit-type spawn, they will need to precache all those hundred of creep unit-types.

This method would also be less accurate the larger range a unit's attack damage values has (I believe damage dice is the right phrase in the OE); a unit that does 11-11 damage will be easy to determine, but a unit that does 7-13 damage would be much more difficult/come with much greater uncertainty.
But maybe I could use the new function to set dice of the clones.
BlzSetUnitDiceSides(u, 1, 0)
 
Status
Not open for further replies.
Top