• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Disable abilities when unloaded

Status
Not open for further replies.
Level 23
Joined
Oct 12, 2008
Messages
1,783
Im making a 'Garrison' system in the vein of 'Orc Burrow', but in addition to attacks, I need active abilities to be disabled when the Garrison is empty.

Currently, each Garrison type has an assigned index and associated ability.
- When unloaded/loaded, the ability is disabled/enabled
- This works fine, as long as each Garrison type only has 1 skill.

(eg. Index = 1 , Garrison(Index) = 'Spear Burrow', Skill(Index) = 'Throw Spear')

The problem is that I want various Garrisons to have varying numbers of skills (currently the number is small enough that I can make exception manually).
I could store each ability in a different index (eg. Skill1(Index) = 'Throw Spear', Skill2(Index) = 'Thrust Spear') and loop through them.

That said, Im trying to find a more elegant solution to disabling multiple abilities on a unit.
 
Maybe something like silence, PauseUnit, stunning, would achieve similar wanted effect.

If you go with working with a unit's abilities and it's not too much work, I honestly would suggest something like your mentioned un-elegant way, with defining the abilities yourself hardcoded.
There are approaches to get a unit's current ability list, but it's not too performant with current tequniques. It might be the initial loading time isn't worth it for you. However:
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
Using a hashtable instead of parallel arrays would allow for variable numbers of abilities under the same index value. You could also build a 2D array with width equal to the max number of abilities you expect a garrison to have.
 
Level 23
Joined
Oct 12, 2008
Messages
1,783
Maybe something like silence, PauseUnit, stunning, would achieve similar wanted effect.

Definitely out of the question since the Garrison needs to be able to use 'battle stations' to pull workers.

Using a hashtable instead of parallel arrays would allow for variable numbers of abilities under the same index value. You could also build a 2D array with width equal to the max number of abilities you expect a garrison to have.

Im currently leaning toward the latter solution (2d array) but would definitely like to try the Hashtable solution. Didn't do much mapping after hashtables were added, hence I am not familiar with the system.
How would I go about setting this up?
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
In simple terms a hashtable is essentially a 2-D array that takes any integer or string as indices and can store all types of objects. The way you would do it would be something like this:

Index 1Index 2Data
Key(GarrisonUnit1)SpellCount1
Key(GarrisonUnit1)Spell1Throw Spear

Key(GarrisonUnit2)SpellCount2
Key(GarrisonUnit2)Spell1Throw Spear
Key(GarrisonUnit2)Spell2Thrust Spear

Key(GarrisonUnit3)SpellCount5
Key(GarrisonUnit2)Spell1Throw Spear
Key(GarrisonUnit2)Spell2Thrust Spear
Key(GarrisonUnit2)Spell3Burning Spear
Key(GarrisonUnit2)Spell4Sacrifice Peon
Key(GarrisonUnit2)Spell5Call for Help
Then for any given unit you load Key(TheUnit), "SpellCount" from the hashtable, loop from 1 to that value, and disable the spell found in Key(TheUnit), "Spell"+(Integer A).
 
Status
Not open for further replies.
Top