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

Any units mana less then 1?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I want to know how long it has been since a unit 'ate' so my idea was to have negative mana regen and when it reaches 0 it becomes hungry. The problem is 1) thats not verly flexible, but I can live with that. 2) There is no any unit event so the only option would be to loop through a large group of units and check there mana every now and then - would that be feasible. At which point are there "too many" units to do this?

Can u add/remove units from a specific unit event?

Suggestions?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Just stagger the testing. Run it every 0.1 seconds but only check a few units at a time. You can perform the stagger using two unit groups. You take the first unit from the one, process it (check mana, lower mana, whatever you want) and then stick it in the other unit group. Repeat 4 or 5 times or until null is returned (group is empty). If the group is empty then you swap the groups around and the process repeats again.

Using some simple mathematics you can compute the period between the same unit being processed twice (the time it takes to empty the group) and use this amount to lower the mana so the actual mana loss per second remains constant (or near constant, no one will notice a few fractions of a mana here or there going missing). The advantage of staggering like this is that the system becomes very scalable. If you have 1000 units it will still use as many resources as if you had 100 units or even 10 units. Sure you may start to notice that it takes longer between mana being decremented but who cares if it keeps your frame rate smooth?
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
Just stagger the testing. Run it every 0.1 seconds but only check a few units at a time. You can perform the stagger using two unit groups. You take the first unit from the one, process it (check mana, lower mana, whatever you want) and then stick it in the other unit group. Repeat 4 or 5 times or until null is returned (group is empty). If the group is empty then you swap the groups around and the process repeats again.

Using some simple mathematics you can compute the period between the same unit being processed twice (the time it takes to empty the group) and use this amount to lower the mana so the actual mana loss per second remains constant (or near constant, no one will notice a few fractions of a mana here or there going missing). The advantage of staggering like this is that the system becomes very scalable. If you have 1000 units it will still use as many resources as if you had 100 units or even 10 units. Sure you may start to notice that it takes longer between mana being decremented but who cares if it keeps your frame rate smooth?

Negative mana regeneration, the looping would only be to check their current mana? But its an intresting idea to split it up. How would one split it up, player groups? Player Groups after Unit size? or just add a created unt to group a, b, c, and d, sure some groups will become "heavier then others" but this perhaps is negligible?

Also to check more frequently then 1 second is unnecessary, even 5 seconds could be considered "often enough". So I could split up the groups over 3 or 5 seconds even.

For feeding I will use the undead ability 'replenish mana' as it can be turned on to auto-cast. I wonder if those units that are missing mana and get effected by the spell can be captured by some event? Otherwise I just pick every unit within AOE and "feed" them.

Also, after the units mana has become 0 I want to add a starvation ability (negative life regeneration, slower attack and movement speed). It's not necessary but how would one increment the negative buff factor over time (when its mana becomes depleted.) Should i add them to a new Starving group and count their time with a integer instead?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
How would one split it up, player groups? Player Groups after Unit size? or just add a created unt to group a, b, c, and d, sure some groups will become "heavier then others" but this perhaps is negligible?
I already explained how. Use two unit groups.

Pop elements from the one, process them and put them in the other.
When the group you pop from is empty, swap over.
Each tick (time the thing runs) you only pop a certain number of units. or the number of units in the group if the total is small (no point cycling 5 times for 1 unit).

Problem with sub-group ordering when popping and pushing? Just use an un-ordered array collection of the elements and loop through it. In fact the array approach is probably the fastest and most efficient (just it is slightly harder to do as you need to manage the collection logic unlike groups which do that for you).
 
Status
Not open for further replies.
Top