(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Resources > JASS Functions

JASS Functions Approved JASS functions will be located here.
Remember to submit your own resources to the submission forum.

Reply
 
LinkBack Thread Tools Display Modes
Old 01-13-2008, 10:45 AM   #1 (permalink)
 
Silvenon's Avatar

BBoy Silv
 
Join Date: Nov 2006
Posts: 866

Silvenon is on a distinguished road (81)Silvenon is on a distinguished road (81)


[vJASS] Jump

Jump


Credits to:
  • Shadow1500 - JumpParabola function
  • PitzerMike - TreeFilter function (not the original function name, though)
  • PurplePoot - improvement suggestions
  • Vexorian - Jass NewGen Pack
Fixes:
  • removed the Jump wrapper function
  • minor performance improvements
  • polished the function a bit
  • remove an accidentally commented piece of line
  • removed the Data returnage
  • replaced the TreeFilter function, thanks to Av3n
  • removed the CSSafety requirement since only one timer is used, thanks to PurplePoot (I was obviously too stupid to figure that out myself)
  • fixed a syntax error (again, thanks to PurplePoot)

library Jump initializer Init_Jump

// ****************************************************************************
// ** **
// ** Jump **
// ** ———————— **
// ** **
// ** Just a function I made for efficient jumping **
// ** **
// ****************************************************************************

//=======//
//Globals//
//=======//

globals
    private integer DUMMY_ID = 'h000'
    private integer array Ar

    private constant real Interval = 0.035
    private boolexpr Bool
    private location Loc = Location(0, 0)

    private timer Tim = CreateTimer()
    private integer Total = 0
endglobals

//===========================================================================

//========================================//
//Credits to Shadow1500 for this function!//
//========================================//

private function JumpParabola takes real dist, real maxdist, real curve returns real
    local real t = (dist * 2) / maxdist - 1
    return (- t * t + 1) * (maxdist / curve)
endfunction

//=======================================//
//Credits to PitzerMike for this function//
//=======================================//

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, 'Ahrl')
    if i then
        call SetDestructableInvulnerable(d, false)
    endif
    set result = IssueTargetOrder(u, "harvest", d)
    call RemoveUnit(u)
    if i then
      call SetDestructableInvulnerable(d, true)
    endif
    set u = null
    set d = null
    return result
endfunction

//===========================================================================

private function TreeKill takes nothing returns nothing
    call KillDestructable(GetEnumDestructable())
endfunction

public struct Data
    unit u
    integer q
    real md
    real d
    real c

    real sin
    real cos
    integer i = 1

    real r
    string s

    static method create takes unit u, integer q, real x2, real y2, real c, real r, string s1, string s2 returns Data
        local Data dat = Data.allocate()

        local real x1 = GetUnitX(u)
        local real y1 = GetUnitY(u)
        local real dx = x1 - x2
        local real dy = y1 - y2
        local real a = Atan2(y2 - y1, x2 - x1)

        set dat.u = u
        set dat.q = q
        set dat.md = SquareRoot(dx * dx + dy * dy)
        set dat.d = dat.md / q
        set dat.c = c
        set dat.sin = Sin(a)
        set dat.cos = Cos(a)
        set dat.r = r
        set dat.s = s2

        if s1 != "" and s1 != null then
            call DestroyEffect(AddSpecialEffect(s1, x1, y1))
        endif

        call UnitAddAbility(u, 'Amrf')
        call UnitRemoveAbility(u, 'Amrf')
        call PauseUnit(u, true)

        return dat
    endmethod

    method onDestroy takes nothing returns nothing
        local real x
        local real y
        local rect r

        if .r != 0 then
            set x = GetUnitX(.u)
            set y = GetUnitY(.u)
            set r = Rect(x - .r, y - .r, x + .r, y + .r)
            call EnumDestructablesInRect(r, Bool, function TreeKill)
            call RemoveRect(r)

            set r = null
        endif

        if .s != "" and .s != null then
            call DestroyEffect(AddSpecialEffect(.s, x, y))
        endif

        call PauseUnit(.u, false)
    endmethod
endstruct

private function Execute takes nothing returns nothing
    local Data dat
    local integer i = 0
    local real x
    local real y
    local location l
    local real h
    local rect r

    loop
        exitwhen i >= Total
        set dat = Ar[i]
        set x = GetUnitX(dat.u) + (dat.d) * dat.cos
        set y = GetUnitY(dat.u) + (dat.d) * dat.sin

        call MoveLocation(Loc, x, y)

        set h = JumpParabola(dat.d * dat.i, dat.md, dat.c) - GetLocationZ(Loc)

        call SetUnitX(dat.u, x)
        call SetUnitY(dat.u, y)
        call SetUnitFlyHeight(dat.u, h, 0)

        if dat.i >= dat.q then
            call dat.destroy()
            set Total = Total - 1
            set Ar[i] = Ar[Total]
        else
            set dat.i = dat.i + 1
endif

        set i = i + 1
    endloop

    if Total == 0 then
        call PauseTimer(Tim)
    endif

    set l = null
endfunction

function Jump takes unit whichUnit, real dur, real destX, real destY, real curve, real radius, string sfx1, string sfx2 returns nothing
local Data dat = Data.create(whichUnit, R2I(dur / Interval), destX, destY, curve, radius, sfx1, sfx2)

    if Total == 0 then
        call TimerStart(Tim, Interval, true, function Execute)
    endif

    set Ar[Total] = dat
    set Total = Total + 1
endfunction

//==================================================================================

function Init_Jump takes nothing returns nothing
    set Bool = Filter(function TreeFilter)
endfunction

endlibrary


This is just Shadow1500's JumpParabola function put in use. Jump function makes a unit jump according to the following parameters:
  • whichUnit = jumping unit
  • dur = duration of the jump
  • destX = x of the destination point
  • destY = y of the destination point
  • curve = well, uhmm, better look here for explanation
  • radius = when the unit lands, it will kill all trees in this radius (if you don't want any tree killing, just put 0)
  • sfx1 = jumping effect (if you don't want any, just put "")
  • sfx2 = landing effect (if you don't want any, just put "")

Create a dummy unit according to one of these two tutorials: 1, 2 (I suggest the second one). You MUST change the DUMMY_ID constant integer to that unit's id.

You can change the Interval constant to modify the interval of the timer that's executing the jump, but it's really unnecessary.

Example of usage:

function Test takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real d = 500
    local real a = GetUnitFacing(u) * bj_DEGTORAD
    local real dur = 1
    local real x1 = GetUnitX(u)
    local real y1 = GetUnitY(u)
    local real x2 = x1 + d * Cos(a)
    local real y2 = y1 + d * Sin(a)
    local real c = 1.8
    local real r = 200
    local string sfx2 = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"

    call Jump(u, dur, x2, y2, c, r, "", sfx2)
endfunction


Requires: Jass NewGen Pack





Please report any bugs!

Last edited by Silvenon; 06-17-2008 at 09:43 PM..
Silvenon is offline   Reply With Quote
Old 01-18-2008, 09:11 PM   #2 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

-Same critique of the tree filter function

Quote:
set Total = Total + 1
set Ar[Total-1] = dat
-Kinda picky here (t'would just save a few characters and an operation), but you should move the set Ar[...] above the other line, and thus not have to subtract 1.

-Why do you return dat? It seems like all that is going to accomplish is to allow users to screw up the spell.

-Is there a point in including a Jump wrapper function?

-It would be <slightly> faster to have the location be a global and use MoveLocation than to constantly create/destroy it.

-It's slightly faster <and shorter in code> to reference parameters directly than through the struct (in the create method), so (for example), replacing dat.q with q would be ideal. (Not a big deal, though)

-Possibly include a boolean option (parameter) for the z-support or remove it completely? Most people won't notice it sitting there commented out, especially the type of people who might be using this.

Quote:
set Ar[i] = Ar[Total-1]
set Total = Total - 1
-Like above, an unnecessary operation.

-Unless you're using CSData or something similar, it's CreateTimer(), not NewTimer() (And you don't seem to mention CSData or an equivalent)
PurplePoot is offline   Reply With Quote
Old 01-18-2008, 09:47 PM   #3 (permalink)
 
Silvenon's Avatar

BBoy Silv
 
Join Date: Nov 2006
Posts: 866

Silvenon is on a distinguished road (81)Silvenon is on a distinguished road (81)


Quote:
-Same critique of the tree filter function
Yeah, yeah, fixing that......

Quote:
-Why do you return dat? It seems like all that is going to accomplish is to allow users to screw up the spell.
I thought someone will find that useful, fixing.....

Quote:
-Kinda picky here (t'would just save a few characters and an operation), but you should move the set Ar[...] above the other line, and thus not have to subtract 1.
I was wondering why Vex did that way also, I remember I tried your way, but something stopped me........fixing that also..... (you really are picky :P)

Quote:
-Is there a point in including a Jump wrapper function?
Not really, I thought you would say same as for the Knockback function.

Quote:
-It would be <slightly> faster to have the location be a global and use MoveLocation than to constantly create/destroy it.
Yeah, fixing that......

Quote:
-It's slightly faster <and shorter in code> to reference parameters directly than through the struct (in the create method), so (for example), replacing dat.q with q would be ideal. (Not a big deal, though)
I thought the speed is the same since they are just global variables.......but ok, fixing......

Quote:
-Possibly include a boolean option (parameter) for the z-support or remove it completely? Most people won't notice it sitting there commented out, especially the type of people who might be using this.
Whooops! Forgot to uncomment it :), fixing......

Quote:
-Like above, an unnecessary operation.
Same as above :). Wow, I'm gonna save a loooot of space this way :P

Quote:
-Unless you're using CSData or something similar, it's CreateTimer(), not NewTimer() (And you don't seem to mention CSData or an equivalent)
CSData is small side-system made by Vex that allows attaching integers to other handles, works like UnitUserData with units. The functions are SetCSData(<handle>, <integer>) and GetCSData(<handle>)
You probably meant CSSafety library which I've put as requirements, look closer :).

Last edited by Silvenon; 01-18-2008 at 10:03 PM..
Silvenon is offline   Reply With Quote
Old 01-22-2008, 05:32 AM   #4 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

Ah, yes, I meant CSSafety, and you should put it in the readable bit, that IS a little obscure ;)

Also, the speed is not the same, since one's an array (it barely makes a difference though, I was just feeling picky)
PurplePoot is offline   Reply With Quote
Old 01-22-2008, 07:17 AM   #5 (permalink)
 
Av3n's Avatar

Mursumane Strike!
 
Join Date: Jul 2005
Posts: 290

Av3n has little to show at this moment (31)Av3n has little to show at this moment (31)Av3n has little to show at this moment (31)Av3n has little to show at this moment (31)


The Tree filter is horrible.... try using this one instead:
function IsDestructableTree takes destructable d returns boolean
  local boolean i = IsDestructableInvulnerable(d)
  local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), <invisible caster>,GetWidgetX(d), GetWidgetY(d), 0)
  local boolean result = false
  call UnitAddAbility(u, 'Ahrl')
  if i then
    call SetDestructableInvulnerable(d, false)
  endif
  set result = IssueTargetOrder(u, "harvest", d)
  call RemoveUnit(u)
  if i then
    call SetDestructableInvulnerable(d, true)
  endif
  return result
endfunction

Use that... I got it from pitzermike's post at wc3c.

Its mroe effcient custom wise as well

-Av3n
Av3n is offline   Reply With Quote
Old 01-22-2008, 02:51 PM   #6 (permalink)
 
Silvenon's Avatar

BBoy Silv
 
Join Date: Nov 2006
Posts: 866

Silvenon is on a distinguished road (81)Silvenon is on a distinguished road (81)


Ok, Pooty, I did everything you asked. Is there anything else? If there is, try to merge all your remaining suggestions in your next post so that I can fix it asap.

Tnx Av3n..........but then the code would require an invisible caster unit and that's really unnecessary. The efficiency difference is probably unnoticeable.

After all, that function is called just once and won't really be any efficient if I change it to your suggestion. If somebody complains about lags, I will modify it.
Silvenon is offline   Reply With Quote
Old 02-06-2008, 01:03 AM   #7 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

Quote:
Tnx Av3n..........but then the code would require an invisible caster unit and that's really unnecessary. The efficiency difference is probably unnoticeable.

After all, that function is called just once and won't really be any efficient if I change it to your suggestion. If somebody complains about lags, I will modify it.
It's not because of efficiency. It's because if you make 10 custom trees, this way works fine with them.

I'll just have to stick this in a map and test it sometime, but it seems fine.
PurplePoot is offline   Reply With Quote
Old 02-06-2008, 01:28 PM   #8 (permalink)
 
Silvenon's Avatar

BBoy Silv
 
Join Date: Nov 2006
Posts: 866

Silvenon is on a distinguished road (81)Silvenon is on a distinguished road (81)


Ok, fixed.

I hate this minimum characters post system.
Silvenon is offline   Reply With Quote
Old 02-06-2008, 06:36 PM   #9 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

  • Having CSSafety as a requirement when you only ever use one global timer is a bit of a hindrance.
  • TreeKill must be placed above the struct declaration
  • Works nicely otherwise
PurplePoot is offline   Reply With Quote
Old 02-06-2008, 10:12 PM   #10 (permalink)
 
Silvenon's Avatar

BBoy Silv
 
Join Date: Nov 2006
Posts: 866

Silvenon is on a distinguished road (81)Silvenon is on a distinguished road (81)


Quote:
Having CSSafety as a requirement when you only ever use one global timer is a bit of a hindrance.
Crap, you're right.

Quote:
TreeKill must be placed above the struct declaration
Whoops, thanks :)
Silvenon is offline   Reply With Quote
Old 02-06-2008, 11:06 PM   #11 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

Edited your post, you forgot to remove CSSafety from the requirements for the library :P

~Approved.
PurplePoot is offline   Reply With Quote
Old 02-07-2008, 09:03 PM   #12 (permalink)
 
Silvenon's Avatar

BBoy Silv
 
Join Date: Nov 2006
Posts: 866

Silvenon is on a distinguished road (81)Silvenon is on a distinguished road (81)


Thanks :)

Darn character minimum
Silvenon is offline   Reply With Quote
Old 06-04-2008, 09:32 AM   #13 (permalink)
 
waaaks!'s Avatar

RotG v1.34 R.I.P
 
Join Date: Dec 2006
Posts: 81

waaaks! has little to show at this moment (1)


nice, i used this in my map and tested it, but theres some part that makes the jump looks crappy

like when my hero jumps to that target, the first movement doesnt lift the hero up instead sliding first before jumping and also when it lands, it slides the hero for 1 movement before stopping

what i wanted is to remove the part where the unit slides, instead of jumping directly, or stopping directly
heres an illustration of the jump below
Attached Thumbnails
jump.jpg  
__________________
waaaks! is offline   Reply With Quote
Old 06-04-2008, 11:25 AM   #14 (permalink)
 
Silvenon's Avatar

BBoy Silv
 
Join Date: Nov 2006
Posts: 866

Silvenon is on a distinguished road (81)Silvenon is on a distinguished road (81)


Thanks for reporting this, but I really must say I have no idea how to fix this. I'll think about it.

I tried to do something which should get rid of the first slide, but then it will probably slide even more in the end.

I can't test this, I rely on you guys.
__________________
PurgeandFire111: Then you can delete the sound and whala... You have the label,filepath, and other parameters.
Silvenon: It's voila, not whala, you... stupidhead :)
PurgeandFire111: Yeah, I was in a rush. =( *cry*
Herman: Voila is an instrument that I quit playing in 6th grade, whala works just fine if not better
PurgeandFire111: No, viola is an instrument. Stupidhead... =D
Silvenon is offline   Reply With Quote
Old 06-05-2008, 01:30 AM   #15 (permalink)
 
waaaks!'s Avatar

RotG v1.34 R.I.P
 
Join Date: Dec 2006
Posts: 81

waaaks! has little to show at this moment (1)


ok, ill look forward on it
__________________
waaaks! is offline   Reply With Quote
Reply

Bookmarks