Using Tomes of Damage to add natural damage to stuff

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
yeah so like, I want to use Tomes of Damage to add / remove natural damage to stuff

so like, i would have a set of tomes of damage items, like this:
Damage +1
Damage +2
Damage +4
Damage +8
Damage +16
Damage +32
Damage +64
Damage +128
Damage -1
Damage -2
Damage -4, etc and so on until i hit a nice cap

so, how do I write the algorithm that figures out which tomes to add to a unit when I specify how much damage i want to add or remove from the unit
 

Viikuna

No Marlo no game.
Reaction score
265
UnitProperties uses powers of 2, which is the way to go.

My math skills suck too much that I could explain why it works like that, so Id just copy that algothrim and use it.
 

the Immortal

I know, I know...
Reaction score
51
Create 'em with ObjMerger, specifying codes for 'dem:
+1 - 'xxx1'
+2 - 'xxx2'
+4 - 'xxx3'
...
+128 - 'xxx7'

Similar with minus abilities(items?).

Then 'ye need some vars:
JASS:

integer BaseItem  = 'xxx0'
integer MAX = 7 //(amount of 'them tomes)

Then y'er code would be something along these lines:
JASS:

function AddDmg takes integer amount, unit u returns nothing
    local integer i = MAX
    local integer tmp
    loop
        set tmp = Pow(2, i)
        if amount >= tmp then
            set amount = amount - tmp;
            call UnitAddItemById(u, BaseItem + i);
            if amount == 0 then
                exitwhen true
            endif
        endif
        set i = i - 1
        exitwhen i == 0
    endloop
endfunction


Freehanded but should work.


If the logic isn't clear:

Creating the items with consecutive numbers allows you to use 'em as array (for ex if TEMPINT is the +1 dmg, then (TEMPINT + 1) will be +2 dmg).

Then you begin iterating backwards to add them damage. So if you have 7 levels (128 max) and wanna add 250 hp for ex. this thingie would do:
add 128 dmg (, amount = 122.
add 64 dmg (122 > 64), amount = 58.
add 32 dmg (58 > 32), amount = 26.
add 16 dmg (26 > 16), amount = 10.
add 8 dmg (10 > 8), amount = 2.
will NOT add 4 dmg (2 < 4)
add 2 dmg (2 >= 2), amount = 0, break.

Total of 2 + 8 + 16 + 32 + 64 + 128 = 250.


Also remember you cannot add values higher than (2 ^ (MAX+1) - 1) which in this case is no more than 255. (a loop if i == MAX can be done though, or simply MAX be increased)

And also for things like HP / Mana where values are very often multiplies of 5 or 10 you can use different base (5 I use for my HP snippet, can show if ya'rr interested o_O).

Also HP / Mana can be done via the Item Bonus Life/Mana bug with only 2 abils :3
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
ty, just what I needed immortal
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top