Spell Force of Nature

Flare

Stops copies me!
Reaction score
662
A new spin on the Force of Nature ability :D

Technical details
Made with vJASS
Requires NewGen WE
Uses Vexorian's TimerUtils and a custom function library I made
Lagless
Leakless (to my knowledge)

Description:
Fires an orb filled with natural energy towards a target point - any trees in the way will be converted into a Treant. Each level increases the maximum Treants spawnable. If the maximum number of Treants isn't reached when the orb is destroyed, new trees will be spawned and converted to Treants when fully grown

Screenshots:
FON.jpg

Importing:
Code:
(1) Copy the FON and GAC triggers into your map
(2) If you don't already have a variant of TimerUtils in your map, copy the TimerUtils trigger into your map
(3) Copy the FoN dummy unit (h000) into your map
(4) Copy the Force of Nature (new) ability (A000) into your map
(5) Modify the SID and DID constants within the FON trigger to match the rawcodes of the FoN dummy unit and the Force of Nature (new) ability
(6) Modify the available constants in the FON/GAC triggers to suit your needs
(7) Enjoy!


Code:
Spell code
JASS:
//Force of Nature (New)
//By Flare
//Requires: This trigger
//          GAC library
//          Vexorian's TimerUtils
//          The FoN dummy unit ('h000')
//          The Force of Nature (new) ability ('A000')
//          NewGen World Editor

//NOTE: Change the Stats - Duration field in the Object Editor to change the number of Treants per level in the tooltip (this doesn't affect actual number spawned)

scope FON initializer FONInit

private keyword FONData

globals
//Configurable arrays (not using constants since it'd be insane)
//Use the ArraySetup function to alter this stuff

//Rawcodes of all trees usable by this spell
    private integer array TREES
//Rawcodes of the spawned treants
    private integer array SPAWNS

//Constant configurables
//Ability rawcode
    private constant integer SID = 'A000'
//Dummy rawcode
    private constant integer DID = 'h000'
//Set this to the total number of applicable targets (i.e. ID's defined in the TREES array)
    private constant integer TOTALTREES = 9
//Rawcode of trees spawned specifically for conversion
    private constant integer TREESPAWNID = 'ATtr'
//Time taken for the birth animation of the above tree
    private constant real BIRTHTIME = 3.
//Determines whether spawned trees are removed when converted, or left as stumps (true = remove, false = leave as stumps)
    private constant boolean REMOVESPAWNED = true
//Timer interval (for dummy movement)
    private constant real INTERVAL = 0.03125
//Speed/sec of the dummy
    private constant real SPEEDPERSEC = 800.
//Speed/timer interval of the dummy
    private constant real MOVEDIST = SPEEDPERSEC*INTERVAL
//Collision radius of projectile - determines how far away from a tree you must be to convert
//DOES NOT AFFECT END RADIUS
    private constant real COLLRAD = 150
//Determines whether treants should be spawned at the end, if the total treant count hasn't been reached from colliding with trees/end effect
    private constant boolean SPAWNREM = true
//SFX string used for destroying trees
    private constant string FXSTRING = ""//"Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl"
//Animation string played when Treants are created
    private constant string ANIMSTRING = "birth"
//Queued animation string after above animation is played
    private constant string NEXTANIM = "stand"
//Expiration timer ID
    private constant integer EXPID = 'BTLF'
//Spawned tree's offset
    private constant real OFFSET = 75
endglobals

//Determines end radius of the spell
private function GetRadius takes unit u returns real
    local real base = 150
    local real m1 = I2R (GetUnitAbilityLevel (u, SID))
    local real m2 = 50
    return base + m1*m2
endfunction

//Determines the maximum number of Treants per level
private function GetTotalTreants takes unit u returns integer
    local integer base = 1
    local integer m1 = GetUnitAbilityLevel (u, SID)
    local integer m2 = 1
    return base + m1 * m2
endfunction

//Determines the duration of spawned Treants
private function GetDuration takes unit u returns real
    local real base = 30
    local real m1 = I2R (GetUnitAbilityLevel (u, SID))
    local real m2 = 10
    return base + m1 * m2
endfunction

//This is for setting up the destructables which are applicable for conversion, and the spawn ID's (for each level)
private function ArraySetup takes nothing returns nothing
//Spawned unit ID's (I'm being lazy, so I'm just gonna use default FoN treant for all levels)
    set SPAWNS[0] = 'efon'
    set SPAWNS[1] = 'efon'
    set SPAWNS[2] = 'efon'
//I'm only adding some of the trees (since I honestly can't be arsed to add every single possible tree that's available
//Anyway, it's not too difficult to add them
//Just add this
//set TREES[X] = rawcode
//where X is the next number available to be used in the arrays
//and update the value for TOTALTREES to match the number of values set in the list
//TOTALTREES should be LASTARRAYVALUE + 1 (if you're doing things correctly)
//In this case, it's (8 + 1 =) 9
    set TREES[0] = 'ATtr'
    set TREES[1] = 'BTtw'
    set TREES[2] = 'KTtw'
    set TREES[3] = 'YTft'
    set TREES[4] = 'JTct'
    set TREES[5] = 'YTst'
    set TREES[6] = 'YTct'
    set TREES[7] = 'YTwt'
    set TREES[8] = 'JTtw'
endfunction
//End of configuration
//-------------------------

globals
    private FONData z
endglobals

private function SetUnitXY takes unit u,real x,real y returns nothing
    if x<GetRectMaxX(bj_mapInitialPlayableArea) and x>GetRectMinX(bj_mapInitialPlayableArea) and y<GetRectMaxY(bj_mapInitialPlayableArea) and y>GetRectMinY(bj_mapInitialPlayableArea) then
        call SetUnitX(u,x)
        call SetUnitY(u,y)
    endif
endfunction

private struct FONData
    unit caster
    unit dummy
    real cos
    real sin
    real ticks
    integer treants = 0
    integer maxtreants
endstruct

private function DestructFilter takes nothing returns boolean
    local integer i = 0
    //call BJDebugMsg ("A DESTRUCTABLE HAS ENTERED THE FILTER OLIOLIOLIOLIO!!! .treants is equal to " + I2S (z.treants))
    loop
    exitwhen i >= TOTALTREES
        if GetDestructableTypeId (GetFilterDestructable ()) == TREES<i> and GetWidgetLife (GetFilterDestructable ()) &gt; .405 then
            return true
        endif
        set i = i + 1
    endloop
    return false
endfunction

private function DestructActions takes nothing returns nothing
    local destructable d = GetEnumDestructable ()
    local real x = GetWidgetX (d)
    local real y = GetWidgetY (d)
    local integer i = GetUnitAbilityLevel (z.caster, SID) - 1
    local unit u
    if z.treants &lt; z.maxtreants then
        call KillDestructable (d)
        set u = CreateUnit (GetOwningPlayer (z.caster), SPAWNS<i>, x, y, bj_UNIT_FACING)
        call SetUnitX (u, x)
        call SetUnitY (u, y)
        call UnitApplyTimedLife (u, EXPID, GetDuration (z.caster))
        call DestroyEffect (AddSpecialEffect (FXSTRING, x, y))
        call SetUnitAnimation (u, ANIMSTRING)
        call QueueUnitAnimation (u, NEXTANIM)
        set z.treants = z.treants + 1
    endif
    set u = null
    set d = null
endfunction


private function TimerCallback takes nothing returns nothing
    local timer t = GetExpiredTimer ()
    local FONData a = GetTimerData (t)
    local real x = GetUnitX (a.dummy)
    local real y = GetUnitY (a.dummy)
    local real endradius
    local rect r
    local rect r2
    local integer i = 0
    local real angle = GetRandomReal (0, bj_PI * 2)
    local real nx
    local real ny
    set x = x + a.cos * MOVEDIST
    set y = y + a.sin * MOVEDIST
    call SetUnitXY (a.dummy, x, y)
    set a.ticks = a.ticks - MOVEDIST
    set r = Rect(x - COLLRAD, y - COLLRAD, x + COLLRAD, y + COLLRAD)
    set z = a
    call EnumDestructablesInRect (r, Condition (function DestructFilter), function DestructActions)
    call RemoveRect (r)
    if a.ticks &lt;= 0 then
        set endradius = GetRadius (a.caster)
        set r = Rect (x - endradius, y - endradius, x + endradius, y + endradius)
        call EnumDestructablesInRect (r, Condition (function DestructFilter), function DestructActions)
        call RemoveRect (r)
        call ReleaseTimer (t)
        call KillUnit (a.dummy)
        call ShowUnit (a.dummy, false)
        if a.treants &lt; a.maxtreants and SPAWNREM then
            loop
            exitwhen i &gt;= a.maxtreants - a.treants
                set nx = x + Cos (angle) * OFFSET
                set ny = y + Sin (angle) * OFFSET
                call GAC_Start (TREESPAWNID, SPAWNS[GetUnitAbilityLevel (a.caster, SID) - 1], BIRTHTIME, GetOwningPlayer (a.caster), nx, ny, REMOVESPAWNED, FXSTRING, GetDuration (a.caster))
                set angle = angle + ((bj_PI*2)/(a.maxtreants - a.treants))
                set i = i + 1
            endloop
        endif
        call a.destroy ()
    endif
    set r = null
    set t = null
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId () == SID
endfunction

private function Actions takes nothing returns nothing
    local FONData a = FONData.create ()
    local timer t = NewTimer ()
    local location l = GetSpellTargetLoc ()
    local real cx = GetUnitX (GetTriggerUnit ())
    local real cy = GetUnitY (GetTriggerUnit ())
    local real tx = GetLocationX (l)
    local real ty = GetLocationY (l)
    local real x = tx-cx
    local real y = ty-cy
    local real angle = Atan2 (y, x)
    call RemoveLocation (l)
    set a.ticks = SquareRoot ((x*x) + (y*y))
    set a.caster = GetTriggerUnit ()
    set a.dummy = CreateUnit (GetOwningPlayer (a.caster), DID, cx, cy, angle * bj_RADTODEG)
    set a.cos = Cos (angle)
    set a.sin = Sin (angle)
    set a.maxtreants = GetTotalTreants (a.caster)
    call SetTimerData (t, a)
    call TimerStart (t, INTERVAL, true, function TimerCallback)
    set t = null
    set l = null
endfunction

private function FONInit takes nothing returns nothing
    local trigger t = CreateTrigger ()
    call TriggerRegisterAnyUnitEventBJ (t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition (t, Condition (function Conditions))
    call TriggerAddAction (t, function Actions)
    call ArraySetup ()
endfunction

endscope</i></i>


GAC library code
JASS:
//Grow And Convert library
//By Flare
//Made for Force of Nature (new)
library GAC requires TimerUtils

globals
//Timer interval
    private constant real TIMERINT = 0.25
//Tree/spawn facing
    private constant real FACING = bj_UNIT_FACING
//Tree variation
    private constant integer VARIATION = 1
//Tree scale
    private constant real SCALE = 1
//Timed life ID
    private constant integer EXPID = &#039;BTLF&#039;
//Animation played by the tree
    private constant string TREEANIM = &quot;birth&quot;
//Animation played by spawn when spawned
    private constant string SPAWNANIM1 = &quot;birth&quot;
//Animation played by spawn after SPAWNANIM1
    private constant string SPAWNANIM2 = &quot;stand&quot;
endglobals

private struct GrowData
    integer spawnId
    destructable tree
    player owner
    real ticks
    boolean removeOnConv
    string sfx
    real duration
    real t
endstruct

private function TimerCallback takes nothing returns nothing
    local GrowData a = GetTimerData (GetExpiredTimer ())
    local real x = GetWidgetX (a.tree)
    local real y = GetWidgetY (a.tree)
    local unit u
    set a.ticks = a.ticks - 1
    if a.ticks &lt;= 0 then
        if a.removeOnConv then
            call RemoveDestructable (a.tree)
        else
            call KillDestructable (a.tree)
        endif
        call DestroyEffect (AddSpecialEffect (a.sfx, x, y))
        set u = CreateUnit (a.owner, a.spawnId, x, y, FACING)
        call SetUnitAnimation (u, SPAWNANIM1)
        call QueueUnitAnimation (u, SPAWNANIM2)
        call UnitApplyTimedLife (u, EXPID, a.duration)
        call ReleaseTimer (GetExpiredTimer ())
        call a.destroy ()
    endif
    set u = null
endfunction

public function Start takes integer treeId, integer convertId, real growTime, player convertOwner, real x, real y, boolean remove, string fxString, real spawnDur returns nothing
    local GrowData a = GrowData.create ()
    local timer t = NewTimer ()
    set a.tree = CreateDestructable (treeId, x, y, FACING, SCALE, VARIATION)
    call SetDestructableAnimation (a.tree, TREEANIM)
    set a.owner = convertOwner
    set a.ticks = growTime / TIMERINT
    set a.t = a.ticks
    set a.removeOnConv = remove
    set a.spawnId = convertId
    set a.sfx = fxString
    set a.duration = spawnDur
    call SetTimerData (t, a)
    call TimerStart (t, TIMERINT, true, function TimerCallback)
    set t = null
endfunction

endlibrary

(if you want me to bundle the GAC library in with the spell's code, let me know)

Credits:
The usual - if you use this spell in your map, please credit me for making it

The rest:
If you find any bugs/leaks/suggestions/lack of configuration anywhere in the spell, let me know, or if I've left anything out of the thread

Updates:
Code:
v1 - Initial release
v2 - Fixed spawned trees spawning if they died before fully grown, added the option to make grown trees invulnerable, spell no longer affects invulnerable trees
 

Attachments

  • Force of Nature (release 3).w3x
    30.4 KB · Views: 260

Tukki

is Skeleton Pirate.
Reaction score
29
Will comment more later, when I've tested the spell itself. Right now there are some things I wonder about..

JASS:
//Determines end radius of the spell
private function GetRadius takes unit u returns real
    local real base = 150
    local real m1 = I2R (GetUnitAbilityLevel (u, SID))
    local real m2 = 50
    return base + m1*m2
endfunction

//Determines the maximum number of Treants per level
private function GetTotalTreants takes unit u returns integer
    local integer base = 1
    local integer m1 = GetUnitAbilityLevel (u, SID)
    local integer m2 = 1
    return base + m1 * m2
endfunction

//Determines the duration of spawned Treants
private function GetDuration takes unit u returns real
    local real base = 30
    local real m1 = I2R (GetUnitAbilityLevel (u, SID))
    local real m2 = 10
    return base + m1 * m2
endfunction

These things could easily be inlinable with the formula 'Base + ((Level-1)*Increment)'

Looks cool :eek:, though.

EDIT:

1) When the ball reaches its destination, it spawns some X amount of trees, which spawns treants upon death. If you then fast-as-hell cast the spell again at the previously targeted point those trees which are currently spawning will die and spawn a treant.

2) A suggestion would be that you can change which unit to spawn on which tree-type. Like;
The tree killed was of type 'oaak'.
Then your spell will spawn a unit of type 'e000', as it's linked to 'oaak'.
-- This could easily be done with 2D arrays.

Heh, but heck, I must admit that I'd never came up with something like this :p + Rep
 

Flare

Stops copies me!
Reaction score
662
I always do that, for the sake of avoiding situations with those who ask "uh.. hw do i chnage dis?????"

Anyway, not being inlined won't break a map where this spell is used...

1) When the ball reaches its destination, it spawns some X amount of trees, which spawns treants upon death. If you then fast-as-hell cast the spell again at the previously targeted point those trees which are currently spawning will die and spawn a treant.
I never tested that :eek: Easily fixable though :D

2) A suggestion would be that you can change which unit to spawn on which tree-type. Like;
The tree killed was of type 'oaak'.
Then your spell will spawn a unit of type 'e000', as it's linked to 'oaak'.
-- This could easily be done with 2D arrays.
Too much work lol :D

Heh, but heck, I must admit that I'd never came up with something like this
You can thank AceHart, it was his idea :p
 

Flare

Stops copies me!
Reaction score
662
It's really simple once it's all set up
Ye, it's easy, once it's all set up :rolleyes: Anyway, I really don't like setting up arrays (was annoying enough to set up only 12 array values), but it would be a very nice addition ^_^

Anyway, I've updated the spell - GAC library now has a constant that allows you to make spawned trees invulnerable (thus making them unaffected by the orb) or leaving them vulnerable, allowing the orb to convert them
 

Forty

New Member
Reaction score
6
if you just want to get any tree, why not use the tree filter function:

JASS:

// by PitzerMike
private function TreeFilter takes nothing returns boolean
    local destructable d = GetFilterDestructable()
    local boolean i = IsDestructableInvulnerable(d)
    local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID,GetWidgetX(d), GetWidgetY(d), 0)
    local boolean result = false
    call UnitAddAbility(u, &#039;Ahrl&#039;)
    if i then
        call SetDestructableInvulnerable(d, false)
    endif
    set result = IssueTargetOrder(u, &quot;harvest&quot;, d)
    call RemoveUnit(u)
    if i then
      call SetDestructableInvulnerable(d, true)
    endif
    set u = null
    set d = null
    return result
endfunction


+will shorten the configuration time
+ every tree will be affected

- every tree will be affected
 

Tukki

is Skeleton Pirate.
Reaction score
29
but it would be a very nice addition ^_^
Then make it! :D

I didn't know of the existence of that function when I made the spell
You have seriously missed some stuff then :p But as you said, it doesn't fit if the user wants to use Rock Chunks instead.

Furthermore you can merge these two to one function instead :)
JASS:
private function DestructFilter takes nothing returns boolean
    local integer i = 0
    //call BJDebugMsg (&quot;A DESTRUCTABLE HAS ENTERED THE FILTER OLIOLIOLIOLIO!!! .treants is equal to &quot; + I2S (z.treants))
    loop
    exitwhen i &gt;= TOTALTREES
        if GetDestructableTypeId (GetFilterDestructable ()) == TREES<i> and GetWidgetLife (GetFilterDestructable ()) &gt; .405 then
            return true
        endif
        set i = i + 1
    endloop
    return false
endfunction

private function DestructActions takes nothing returns nothing
    local destructable d = GetEnumDestructable ()
    local real x = GetWidgetX (d)
    local real y = GetWidgetY (d)
    local integer i = GetUnitAbilityLevel (z.caster, SID) - 1
    local unit u
    if z.treants &lt; z.maxtreants then
        call KillDestructable (d)
        set u = CreateUnit (GetOwningPlayer (z.caster), SPAWNS<i>, x, y, bj_UNIT_FACING)
        call SetUnitX (u, x)
        call SetUnitY (u, y)
        call UnitApplyTimedLife (u, EXPID, GetDuration (z.caster))
        call DestroyEffect (AddSpecialEffect (FXSTRING, x, y))
        call SetUnitAnimation (u, ANIMSTRING)
        call QueueUnitAnimation (u, NEXTANIM)
        set z.treants = z.treants + 1
    endif
    set u = null
    set d = null
endfunction</i></i>


And you should destroy the unit if it tries to leave map-area, it could look ugly if it just stands there ^^
JASS:
private function SetUnitXY takes unit u,real x,real y returns nothing
    if x&lt;GetRectMaxX(bj_mapInitialPlayableArea) and x&gt;GetRectMinX(bj_mapInitialPlayableArea) and y&lt;GetRectMaxY(bj_mapInitialPlayableArea) and y&gt;GetRectMinY(bj_mapInitialPlayableArea) then
        call SetUnitX(u,x)
        call SetUnitY(u,y)
    else // WOHOO KILL ZE UNITH
        call ImplodeLeavingUnitBackToTheStoneAge(u)
    // and destroy things etc..
    endif
endfunction
 

Flare

Stops copies me!
Reaction score
662
Furthermore you can merge these two to one function instead
I could do that, but I'd rather not :p

And you should destroy the unit if it tries to leave map-area, it could look ugly if it just stands there ^^
People should be smart enough not to cast outside of the map boundaries (since the projectile only travels as far as the spell's target location)
 

Tukki

is Skeleton Pirate.
Reaction score
29
I could do that, but I'd rather not
Hey, it's actually good for your spell!

People should be smart enough
That statement fails right after "enough"..And maybe there are some hax0r amounts of trees near the edge?
 

Flare

Stops copies me!
Reaction score
662
And maybe there are some hax0r amounts of trees near the edge?
Near the edge doesn't mean you have to cast outside the map to actually get them, there is a perfectly good AoE indicator which (contrary to popular belief) does indicate that the spell has an area of effect. But if people are too stupid to realise that, they probably have alot more to worry about than a WC3 spell :rolleyes:
 

Tukki

is Skeleton Pirate.
Reaction score
29
Okey, I give up ^^ -- but the majority just cast the spell somewhere and hopes it does something awesome (at least my buddy does it..).
 

Vexorian

Why no custom sig?
Reaction score
187
Uses Vexorian's TimerUtils (Blue)
//Requires:
//Vexorian's TimerUtils (Blue flavour)
Please don't say that, the whole point of TimerUtils was freedom of implementation, so it behaves just like a spec. In other words, your spell does NOT require blue timer utils, it can easily use either of the flavors, that's the reason behind the flavor idea I had, so just ask for TimerUtils, in fact, if a guy is able to correctly implement red your spell will be faster on his map.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top