• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Damage Formula in JASS Spells

Status
Not open for further replies.
Level 16
Joined
Mar 3, 2006
Messages
1,564
I want to make a damage formula as:

CONST FACTOR + (LEVEL FACTOR * AbilityLevel) + (PREV LEVEL FACTOR * PrevLevelDamage)

The CONST FACTOR and LEVEL FACTOR * AbilityLevel was easy to make but the problem is with the PREV LEVEL FACTOR * PrevLevelDamage

Here is a part of the script:

JASS:
scope AoETemplate initializer Init
    private keyword Data
 
    globals
        // Constants
        private constant real TIMER_INTERVAL = 0.015
        private constant real DIST = 16.00
        private constant real NOVA_RADIUS = 512.00 // radius of the Nova
        private constant integer NOVA_SIZE = 36 // number of the Nova Units
        private constant real dA = 360/NOVA_SIZE
        private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
        private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
        private constant attacktype ATKTYPE = ATTACK_TYPE_MAGIC
        private constant damagetype DMGTYPE = DAMAGE_TYPE_FIRE
        private constant real AB_CONST_FACTOR = 50.00
        private constant real AB_LEVEL_FACTOR = 50.00
        private constant real AB_PREV_LVL_FACTOR = 1
        // Variables
        private timer tm = CreateTimer()
        private Data array temp_dat
        private integer index = 0
        private Data iFilter // Filter Data
        private boolexpr fFilter // Filter function
        private group TempGroup = CreateGroup()
    endglobals
    private struct Data
        unit Caster
        unit array Nova[NOVA_SIZE]
        real expand
        real Cx
        real Cy
        player Owner
        group dGroup = CreateGroup() // Damaged Units Group
        real dmg
        real prev
 
        static method Damage takes integer AbiLevel returns real
            local real damage = AB_CONST_FACTOR + AB_LEVEL_FACTOR * AbiLevel //+ AB_PREV_LVL_FACTOR * prev
        return damage
        endmethod
 
        // ...
        //rest of the script
        // ...
 
        static method create takes unit caster returns Data
            local thistype dat = thistype.allocate()
            local integer i = 0
            local real A = 0.00
            set dat.Caster = caster
            set dat.Owner = GetOwningPlayer(dat.Caster)
            set dat.Cx = GetUnitX(dat.Caster)
            set dat.Cy = GetUnitY(dat.Caster)
            set dat.dmg = Data.Damage(GetUnitAbilityLevel(dat.Caster,ABIL_ID))
 
        // ...
        // To the end of the script
        // ...

This is the same script that good :thumbs_up: Element of Water fixed it to me, I just wanted to add a damage function but I was stuck by that problem.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Assuming factor is not constant (either that the prev level factor is different from the current level factor, or that the factor is a formula). If it is, there's a better way:

JASS:
constant function Factor takes integer lv returns real
    return someFormula
endfunction

constant function GetDamage takes integer lv returns real
    if lv > 1 then
        return const+lv*Factor(lv)+GetDamage(lv-1)*Factor(lv-1)
    endif
    return const+lv*Factor(lv)
endfunction
 
Try this function. Don't ask how it works, I don't really know either. I just know that it kinda does work.

JASS:
function GetDamage takes integer level returns real
    local real prevDamage
    if level == 1 then
        set prevDamage = 0
    else
        set prevDamage = GetDamage.evaluate(level - 1)
    endif
    
    return CONST_FACTOR + (LEVEL_FACTOR * level) + (PREV_LEVEL_FACTOR * prevDamage)
endfunction
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Try this function. Don't ask how it works, I don't really know either. I just know that it kinda does work.

JASS:
function GetDamage takes integer level returns real
    local real prevDamage
    if level == 1 then
        set prevDamage = 0
    else
        set prevDamage = GetDamage.evaluate(level - 1)
    endif
 
    return CONST_FACTOR + (LEVEL_FACTOR * level) + (PREV_LEVEL_FACTOR * prevDamage)
endfunction
.evaluate don't work inside static members.

<< ADDED >>

OK, EOW no need to answer. I just made a function outside the struct as you mentioned and it worked.

It seems that .evaluate runs a function and ignores anything inside it; it looks only for the arguments and the return value or so it seems to me.
 
Last edited:
Status
Not open for further replies.
Top