• 🏆 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!

[vJASS] [Snipet] KillTreesInRange

Level 9
Joined
Jun 21, 2012
Messages
432
JASS:
library KillTreesInRange uses DestructableLib
/************************************************************************************
*
*   KillTreesInRange
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*   v1.0.0.0
*   by Thelordmarshall
*   
*   Description: kill trees in range ^^.
*   Requires any DestructableLib.
*   
*   API:
*   ¯¯¯¯
*       function KillTreesInRange takes real x, real y, real range returns boolean
*
*************************************************************************************/
    globals
        private rect r=Rect(0,0,0,0)
        private integer result=0
    endglobals
    
    private function KillHim takes nothing returns nothing
        local destructable d=GetEnumDestructable()
        if(IsDestructableTree(d) and not IsDestructableDead(d))then
            call KillDestructable(d)
            set result=result+1
        endif
        set d=null
    endfunction
    
    function KillTreesInRange takes real x, real y, real range returns boolean
        set result=0
        call SetRect(r,x-range,y-range,x+range,y+range)
        call EnumDestructablesInRect(r,null,function KillHim)
        return result>0
    endfunction
endlibrary
 
Heyho, I think a KillTreesInRange function might be used,
though then I would not just wrap the EnumInRect function.

You could check for WidgetX/Y for enum destructables,
to ensure a real circular destruction of trees, instead of rect.
It would be a bit slower of course, but who cares, the result
would be optimized.

Probably you could just use for example http://www.hiveworkshop.com/forums/jass-resources-412/snippet-isdestructabletree-248054/,
as a explicit requirement, then you also don't need to bother with your
own implementations for checks if destructable is a tree/alive, but
just call the KillTree takes destructable tree returns boolean.

I'm not sure if it's really senseful to return a boolean
for a "kill multiple x" function. I'm not sure if I would return anything,
but in my mind, if I did, I would return the amount of killed trees. (integer)
 
Last edited:
Top