Snippet Slide

AdamGriffith

You can change this now in User CP.
Reaction score
69
This is just a piece of code that I made for my map and I found it quite useful.
It basically just moves a unit to a point with a uniform deceleration.
You specify the displacement, final velocity, time, which unit and the angle.

REQUIRES:
-NewGen

The code:
JASS:
library Slide

//######################################################################################################################################\\
//  Slide System                                                                                                                        \\
//              By:                                                                                                                     \\
//                  AdamGriffith @ <a href="http://www.thehelper.net/" class="link link--internal">http://www.thehelper.net/</a>                                                                            \\
//                  Adamdagr8@Northrend                                                                                                 \\
//                                                                                                                                      \\
//      Key:                                                                                                                            \\
//          S = Displacement                                                                                                            \\
//          U = Intial_Velocity                                                                                                         \\
//          V = Final_Velocity                                                                                                          \\
//          A = Acceleration                                                                                                            \\
//          T = Time                                                                                                                    \\
//                                                                                                                                      \\
//      Function list:                                                                                                                  \\
//          call Slide_SVT(Displacement, Final_Velocity, Time, whatAngle, whichUnit)                                                    \\
//                                                                                                                                      \\
//######################################################################################################################################\\

struct SlideData
    real S = 0.00
    real U = 0.00
    real V = 0.00
    real A = 0.00
    real T = 0.00
    real angle = 0.00
    real time = 0.00
    real x = 0.00
    real y = 0.00
    unit slider = null
endstruct

globals
    private integer C = 0
    private real timeout = 0.035 // This is the timeout of the SlideTimer. This value should be good for eyecandy and lag.
    private timer SlideTimer = CreateTimer()
    private SlideData array data
endglobals

private function Slide takes nothing returns nothing
    local SlideData a
    local integer i = C
    local real displacement
    local real newx
    local real newy
    loop
        exitwhen i &lt;= 0
        set a = data<i>
        set displacement = (a.U * a.time) + (0.50 * a.A * Pow(a.time, 2.00))
        set newx = a.x + displacement * Cos(a.angle * bj_DEGTORAD)
        set newy = a.y + displacement * Sin(a.angle * bj_DEGTORAD)
        call SetUnitPosition(a.slider, newx, newy)
        set a.time = a.time + timeout
        if a.time &gt;= a.T then
            call a.destroy()
            set data<i> = data[C]
            set C = C - 1
            if C == 0 then
                call PauseTimer(SlideTimer)
            else
            endif
        else
        endif
        set i = i - 1
    endloop
endfunction

public function SVT takes real Displacement, real Final_Velocity, real Time, real whatAngle, unit whichUnit returns nothing
    local SlideData a
    set C = C + 1
    set data[C] = SlideData.create()
    set a = data[C]
    set a.S = Displacement
    set a.V = Final_Velocity
    set a.T = Time
    set a.U = (a.S / (0.5 * a.T)) - a.V
    set a.A = (a.S - (a.V * a.T)) / (-0.50 * Pow(a.T, 2.00))
    set a.angle = whatAngle
    set a.slider = whichUnit
    set a.x = GetUnitX(a.slider)
    set a.y = GetUnitY(a.slider)
    if C == 1 then
        call TimerStart(SlideTimer, 0.035, true, function Slide)
    else
    endif
endfunction

//===========================================================================
function InitTrig_Slide takes nothing returns nothing
    set gg_trg_Slide = CreateTrigger(  )
endfunction

endlibrary</i></i>


View attachment 23734
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
JASS:
function InitTrig_Slide takes nothing returns nothing
    set gg_trg_Slide = CreateTrigger(  )
endfunction

endlibrary


What's this for?

Also change your function name of:

JASS:
function Slide_SVT_01 takes real displacement, real final_velocity, real time, real angle, unit whichUnit returns nothing


to:
JASS:

public function Start takes real displacement, real final_velocity, real time, real angle, unit whichUnit returns nothing


(Or change Start to something else). That way you would call the function using

JASS:
call Slide_Start(arguments)


Which is a lot easier than what you're using at this point.
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
Okay, let me get this straight it you want to call a public function that is within a library you must do:

call LIBRARYNAME_FUNCTIONNAME(Arg1, Arg2, ...)

EDIT:
If that is the case, how come I can call it atm without the library name? =S
 

Flare

Stops copies me!
Reaction score
662
Functions called within the library don't need the prefix e.g.

JASS:
library Something
public function Test1 takes nothing returns nothing
endfunction

public function Test2 takes nothing returns nothing
call Test1 ()
endfunction

endlibrary


However, if you are calling Test1 or Test2 from outside the library, the library's name is required as a prefix i.e.
call Something_Test1 ()
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
But in the test trigger in my map which was in a seperate trigger I did:

call Slide_SVT_01( blah, blah, blah, blah, blah)

And it worked.
Is that because I had no public or private infront of it?
 

Daskunk

SC2 Forum MVP - TheSkunk #386
Reaction score
186
When I open in in the map editor and click test it boots me to main warcraft screen, and when I try to get into it from wc3, when I click start, the menus go up like it normally does to start a game, then the menus come down again, and nothing happens. Not my wc3, as I can play and test other games..
 

Flare

Stops copies me!
Reaction score
662
But in the test trigger in my map which was in a seperate trigger I did:

call Slide_SVT_01( blah, blah, blah, blah, blah)

And it worked.
Is that because I had no public or private infront of it?

Ye. If there isn't a public/private prefix, the function doesn't change. Public gives it <scope/library name>_ prefix, and private gives it a <scope/library name>_<randomly generated number>_ prefix, I think

When I open in in the map editor and click test it boots me to main warcraft screen, and when I try to get into it from wc3, when I click start, the menus go up like it normally does to start a game, then the menus come down again, and nothing happens. Not my wc3, as I can play and test other games..

Open with NewGen and save before testing. If that doesn't fix it, go to Scenario -> Forces Properties, and check Use Custom Forces (Grimoire has custom test map settings, but you can disable them by ticking Use Custom Forces)
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
First post modified.
Well it seems this is okay, will leave this for a couple of days for feedback, then if it goes down well, I will released the full system! :)
 

Flare

Stops copies me!
Reaction score
662
First post modified.
Well it seems this is okay, will leave this for a couple of days for feedback, then if it goes down well, I will released the full system! :)

There's more to it? Can't really see what more needs to be added other than a configuration header and possibly boolean arguments to determine whether SFX is displayed, and if destructables in range are damaged/destroyed
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
I already have it, just debating wether others will find it useful.
Basically in this snippet, you can change the time, distance and final velocity.
In the system they're is more combinations, such as acceleration with distance and starting velocity. So the unit starts at 0 speed and accelerates to the point, basically this in reverse.

Updated code and test map.
Now only uses reals. No locations! :)

Is this the best most optimized way, before I start on the other functions? :)
 

Trollvottel

never aging title
Reaction score
262
sin and cos are slow functions:
JASS:

        set newx = a.x + displacement * Cos(a.angle * bj_DEGTORAD)
        set newy = a.y + displacement * Sin(a.angle * bj_DEGTORAD)


i think the angle doesnt change? so why dont you just set this cos and sin values once and store them in the struct, like this:


JASS:

        set newx = a.x + displacement * a.anglecos
        set newy = a.y + displacement * a.anglesin
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top