• 🏆 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!

Perfect Unit Indexing

Status
Not open for further replies.
Is there a method of obtaining perfect unit indexing? Perfect indexing is:
  • Indexes each unit that is created withCreateUnit().
  • Index every unit created training and buying units.
  • Deindex a unit that is removed withRemoveUnit[icode=jass].[*]Deindex a unit that is removed because it decayed (either the corpse decayed, or the unit had no corpse and dies).[*]This should handle units, heroes, and buildings as well as account for resurrection of said units, heroes, and buildings.[/list]The system probably can easily be extended to tell if a unit is dead or alive as well. I want this to be done automagically. That is; I won't want to monitor each time I use the aforementioned functions. I currently use a unit enters region event with a region covering the entire map, and a building starts construction to catch built buildings. However, getting deindexing to work properly I use the undefend order, but that doesn't work for buildings oddly enough.Any input is appreciated.
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
The core of basically every indexer is written around catching/checking the undefend order. Nes' UnitIndexer probably suits every and each of your needs.
I don't recall TH' UnitDex being unaccurate in any of mentioned situations either.

Have you even tried checking demo maps/tutorials/codes for available indexers (AIDS/UI/UDex)?

Btw, whats wrong with ur deindex method when buildings are involved?
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
We know that :) Sometimes it's even wierd why so many "undefends" occur. The trick is to check the level of "indexer defend" ability. If it's still there, the unit is probably decaying, has been killed etc.

You do not have to be dealing with indexers since there are plenty available already. There is one for GUIers (Bribe') which works just fine, and of course, vJass versions - they are seen everywhere.
 
We know that :) Sometimes it's even wierd why so many "undefends" occur. The trick is to check the level of "indexer defend" ability. If it's still there, the unit is probably decaying, has been killed etc.

You do not have to be dealing with indexers since there are plenty available already. There is one for GUIers (Bribe') which works just fine, and of course, vJass versions - they are seen everywhere.
What do you mean with 'indexer defend'?
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
I'm coming into this with 0 knowledge of the standard implementation of unit indexers or their purpose, but what on earth does the human ability "Defend" have to do with indexing each unit uniquely?

Also why do people need unit indexers in the first place? What I have seen is that they are used for MUI. But for (v)JASSers you can just simulate a data structure for each unit instantiated and then reference that by a quick table look up the relevant information (unit handle id, etc.).

Or is this part of the standard vJASS library? I notice many systems rely on a unit indexer.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
vJASS doesn't have a standard library.

The reason why unit indexers are used is that unit IDs are way larger than 8k and thus, they can't be used in arrays.
Then again, hashtables are almost twice as slow as arrays, so there is a considerable efficiency impact.

Defend is used because the "undefend" order is issued to a unit that has it upon being removed. There is some trick about this that I don't know exactly, but there is a way to detect if the unit casting it was removed (unit == null?).
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
One might not need UnitIndexer. Whatmore, you can code script for your whole map without usage of such. Basically, those are made to ease the work with spells / systems with some relation to units.
They also provide nicely coupled events for detecting the moment unit enters/leaves, on the top of well known assignment of unique index for every unit.

The undefend trick that has been discovered in the past allowed for better solution in regard to "perfect" indexing. Basically unit that has "defend" ability, depending on it's state, will be ordered to "undefend" e.g when it dies, when it is removed.
With such opportunity, we don't have to hook RemoveUnit and we can avoid all of the wierd stuff, focusing on catching the issue_order instead.
The check related to ability level assures us that unit is indeed being removed instead of being e.g killed - unit that is dead and decays, is still viable target.
 
Status
Not open for further replies.
Top