• 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.

Indexing Problem

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
I have a spell which if cast onto a target, it will create 2/3/4/5 floating orbs around the target and circling the it.

How can I assign so that each orb knows its owner ?

Situation:
Unit A self-cast the ability and it spawns 3 orbs around it.
Unit B self-cast the ability and it spawns 5 orbs around it.

How can I know which orb belongs to which unit ?

I can imagine this by doing 2 separate arrays for casterIndex and orbIndex in which;

Hero[1]
-----Orb[1]
-----Orb[2]
-----Orb[3]

Hero[2]
-----Orb[4]
-----Orb[5]
-----Orb[6]
-----Orb[7]
-----Orb[8]

How to achieve this ?
And no Hashtable please, I'd like to stick with Indexing.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
That works like a Hashtable too, such as Bribe's GUI Unit Indexer.
So there is no other solution if it uses a pure indexing approach ?

One guy PM'd me but his approach would waste numbers of indexes which is inefficient.
His method is to set a pre-set domain value for each indexes;
Maximum Domain Range would be 5 for each instances.

Therefore I reserve 5 index per cast, which would waste indexes if the orbCount != number of reserved indexes.
 
It depends on what kind of information you're given.

If, for example, you are arbitrarily given the orb unit, then you should resort to a hashtable or unit indexer because you can get the hero with O(1) complexity. Otherwise you will have to create a list of all heroes with their orbs and see if the orb is within that list (by using a loop). That method depends on how you are storing the orbs.

If you have access to the index of the orb, then you can always do some mapping e.g. set hero[index of orb in array] = the caster, and then load it that way. Again, this depends on how you've stored the orbs for your spell, so you should post whatever code you have so far so we can give you better advice.
 
Status
Not open for further replies.
Top