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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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