- Joined
- Nov 13, 2006
- Messages
- 1,814
my question is: can i use linked list system for make something like special effect group (not exist but i mean something what work like unit group, just with special effect)
because i dont understanded well, so i got its replace 1 hole, but what happen when suddenly have lets say 10 hole (destroy 10 special effect) and later in another trigger i create another (lets say 7) special effect, then 1st effect get 1 from 10 hole but another special effect?
i give a example:
f[0]= a special effect
f[1]= a special effect
f[2]= a special effect
f[3]= a special effect
f[4]= a special effect
if i destroy 1,2,3 and create 4 special effect then
index will be 1,2,3,5 or 1,5,6,7?
or this
http://www.hiveworkshop.com/forums/...array-linked-list-stack-queue-dequeue-188528/
because i dont understanded well, so i got its replace 1 hole, but what happen when suddenly have lets say 10 hole (destroy 10 special effect) and later in another trigger i create another (lets say 7) special effect, then 1st effect get 1 from 10 hole but another special effect?
i give a example:
f[0]= a special effect
f[1]= a special effect
f[2]= a special effect
f[3]= a special effect
f[4]= a special effect
if i destroy 1,2,3 and create 4 special effect then
index will be 1,2,3,5 or 1,5,6,7?
Dynamic Indexing is a process that finds a new index for you to use in the data arrays.
This is how it's done in Jass:
You need 2 variables:
JASS:integer array nextRecycle integer iCount = 0
Instead of hashtables, we're going to use arrays.
So, declare arrays for anything you need:
unit array caster
real array heal
integer array level
etc...
When a unit casts a spell, the first thing we're going to do is get a special index:
JASS:local integer index = nextRecycle[0] // if the index is null if index == 0 then // nothing in the recycler, so we just add instances from the top set iCount = iCount + 1 set index = iCount else // we set the next instance to be recycled set nextRecycle[0] = nextRecycle[this] endif
After this,index
is going to be equal to the index that we're going to use in our arrays.
Now, since we're going to use only one timer, we need a way to put all the instances in a list for the timer to loop over.
Let's do a linked list then ^_^
You can lookup linked lists on Google if you don't know what they are ;p
Here's how it works:
You need 2 integer arrays (next and prev)
When we want to put something in a linked list, we do this:
JASS:// We set the next one in the list to 0 set next[index] = 0 // We set the one behind it to the last added instance set prev[index] = prev[0] // We set the next of the one behind it to this set next[prev[0]] = index // We set the last added instance to this set prev[0] = index
This is what we should after allocating an instance (index)
After we do this, we should declare another variable called "amount"
This integer variable is going to be increased by one every time we cast the spell and decreased by 1 every time we end the spell.
Now we get to the easy part:
We set the data:
JASS:set caster[index] = GetTriggerUnit() set duration[index] = bleh set ble[index] = bla
etc..
Then we should check if amount == 1.
If it does, we start the timer.
The timer will call a function that loops over the list like this:
JASS:function Loop takes nothing returns nothing local integer this = next[0] // get the first instance in the list loop // Exit when we hit a null instance (the end of the list) exitwhen this == 0 // do spell loop actions using "this" as the index for the arrays // we go to the next one in the list set this = next[this] endloop endfunction
Now when a unit finishes casting a spell, we have to do 3 things:
First, let's deallocate the index.
To deallocate an index, we do this:
JASS:// Set the one that we have to recycle after this to the one that we were just going to recycle set nextRecycle[INDEX] = nextRecycle[0] // Set the one that we're going to recycle now to this set nextRecycle[0] = INDEX
Next, we're going to remove it from the list so we dont keep looping over it again and again:
JASS:set next[prev[INDEX]] = next[INDEX] set prev[next[INDEX]] = prev[INDEX]
Finally, we decrease the amount:
set amount = amount - 1
Then, to wrap it all up (OUTSIDE of that loop in the timer function):
JASS:if amount == 0 then call PauseTimer(timer) endif
Done!
or this
http://www.hiveworkshop.com/forums/...array-linked-list-stack-queue-dequeue-188528/