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

[JASS] Exponential System

Status
Not open for further replies.
Level 16
Joined
Feb 22, 2006
Messages
960
So i was a bit borred and then i tested a bit around and created a littel exponential system which creates an exponential equation. you can call each product from these equation:

JASS:
library ExpoSystem
globals
    private constant integer x = 100 //not more then 100 powers   
    private constant integer MAX_PLAYER = 12 //max player support
    private constant integer MAX_INSTANCES = 3000 //max instances which can be created at the same time per player
    
    private boolean array EXPO_ALREADY [MAX_PLAYER]
endglobals

private struct expostruct
    real array r [x]
    static method create takes real c,real a,integer n returns expostruct
        local expostruct dat = expostruct.allocate()
        local integer i = 1    
            set dat.r[1] = c*a
            loop
                exitwhen i >= n+1
                set dat.r[i] = dat.r[i-1]*a
                set i = i + 1
            endloop
            return dat
    endmethod
endstruct

globals
    private expostruct array Dat [MAX_INSTANCES] [MAX_PLAYER]
endglobals

function CreateExpo takes real c, real a, integer n,player p,integer instance returns nothing
        if instance > 3000 then
            debug call BJDebugMsg("You can't have more then 3000 instances so pls chose a number under 3000!")
            return
        endif
        if Dat[instance] [GetPlayerId(p)] > 0 then
            call expostruct.destroy(Dat[instance] [GetPlayerId(p)])
            set Dat[instance] [GetPlayerId(p)] = expostruct.create(c,a,n)
        endif
endfunction

function GetExpo takes integer n,player p,integer instance returns real
    return Dat[instance] [GetPlayerId(p)].r[n]
endfunction

function DestroyExpo takes player p,integer instance returns nothing
    call expostruct.destroy(Dat[instance] [GetPlayerId(p)])
endfunction
endlibrary

here a sample usage:

the original math formula is = f(x) = c * a^x

so in my case c = 300 | a = 1.3 | x = 5

note: a > 1 increase | a < 1 decrease

the last number in the function call is always the number of the instance

call CreateExpo(300,1.3,5,Player(0),1)

this will create following reals (expostruct.r[1-5])
r[1] = 390.00
r[2] = 507.00
r[3] = 659.10
r[4] = 856.83
r[5] = 1113.879

you get this reals with the function GetExpo(1-5,Player(0),1)


to destroy a Expo you have the function DestroyExpo(GetTriggerPlayer(),1)
then you could use it for your spell :)

i think the system could be usefull for some spells which increases damage per time or something like that :D
 
Last edited:
Level 23
Joined
Nov 29, 2006
Messages
2,482
Okayk some feedback then:p

It seems nice from my point of view. However you could optimise it alittle (this is only a minor adjustment^^).
JASS:
endif
        if Dat[instance] [GetPlayerId(p)] > 0 then
            call expostruct.destroy(Dat[instance] [GetPlayerId(p)])
            set Dat[instance] [GetPlayerId(p)] = expostruct.create(c,a,n)
        else
            set Dat[instance] [GetPlayerId(p)] = expostruct.create(c,a,n)
        endif

heh, you could rather just do one set Dat[instance] [GetPlayerId(p)] = expostruct.create(c,a,n) after the if checking.

Oh, and also,
private boolean array EXPO_ALREADY [MAX_PLAYER]
is never used.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Seems rather pointless as I thought wc3's native Pow(base,exponent) already let you generate exponential values on the fly with but a few other calculations. All in all I think it might still be faster than your system and certainly is less memory intensive.
 
Status
Not open for further replies.
Top