1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  5. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  6. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  7. The 13th Music Contest Poll is up! Vote for the best tracks in this symphony of frost and flame.
    Dismiss Notice
  8. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Unit Acceleration System v0.16 (GUI Friendly)

Submitted by Diehard@Azeroth
This bundle is marked as approved. It works and satisfies the submission rules.
This system accelerates units based on terrain height, and drags units down if they are going down terrain such as a mountain (in the map), basically any higher terrain that has a relatively fair amount of difference in Z which makes the unit become dragged by gravity.

I used to increase or decrease acceleration, but it seems there was a bug in that because when a unit accelerates down a mountain, it will be able to pass over a part of the mountain that it shouldnt be able to pass because of how steep the location is; which the unit would have not been able to pass before deaccelerating down the mountain. Of course this bug happens only if you move down a mountain and then up the mountain really fast.

Anyways, thats why i included the drag aspect of the acceleration, and the higher the movespeed is, the faster the drag will be, cus im basing the acceleration on the same concept of V = Vo + at.

Hope you enjoy the system, its MUI, Lagless and is GUI-Friendly. made many directions, most for GUI users since the system is vJASS.

please give credits if you use it in your map

also guys, you may need to remove acceleration at times like for example, a unit jumps, and when he finishes jumping, add his acceleration back again; instructions are in the trigger section in the map.

BTW ANY OF U GUYS CAN EDIT THIS SYSTEM AS LONG AS YOU GIVE CREDITS TO ME AS THE ORIGINAL CREATOR, il fix any bugs and add extra functions if wanted, but probably not adding much extra features; unless if there is a special request to do so.

Credits:
-------------------------------------------------------------------------------------

Elejrk@hiveworkshop.com for helping me find several bugs and fix the drag and telling me to make the system's description better

Revolve, Shendoo2 and D4RK_G4ND4LF for finding a minor bug in the acceleration of units

The_Reborn_Devil for telling me to show others that my system is MUI by adding acceleration to the other rifleman

-------------------------------------------------------------------------------------

Here is code:
Code (vJASS):
library Acceleration initializer Init
   
    globals
        private timer t = CreateTimer()
        private group accelUnits = CreateGroup()
        private location Zloc = Location(0.,0.)
        private integer maxAccel = 0
        private constant real checkDist = 10.
        private timer d = CreateTimer()
        private constant group dragGroup = CreateGroup()
        private integer maxDrag = 0
        private hashtable ht = InitHashtable()
        private boolexpr kbBoolexpr
        private unit draggedUnit = null
        private unit tempFilter = null
        private boolexpr True
        private rect r = null
        private constant real DEGTORAD = 3.14159/180
       
        // CONFIGURABLES
       
        private constant real NoDrag = 10. //maximum difference in Z that cannot cause any drag, basically, the higher this value is, the lower
        // a terrain infront of the unit will be needed to drag the unit down, and vice versa. Values less than 0 wont work.
       
        private constant real dragIteration = 0.03 // drag timer periodic iteration
        private constant real tIteration = 0.30 // timer periodic iteration
       
        private constant real gravity = -9.81 // gravity's real value, make it lower to lower the acceleration/deacceleration change
        // END CONFIGURABLES
       
        private constant real dragGravity = gravity*dragIteration*-1
        private DN dat
    endglobals
   
   
    private function GetLocZ takes real x, real y returns real
        call MoveLocation(Zloc, x, y)
        return GetLocationZ(Zloc)
    endfunction
   
    private function returnTrue takes nothing returns boolean
        return true
    endfunction
   
    private function returnBoolean takes nothing returns boolean
        set tempFilter = GetFilterUnit()
        return GetUnitFlyHeight(tempFilter) <= 25 and IsUnit(tempFilter, draggedUnit) == false
    endfunction
   
    struct DN // Destructable detection
    integer dN = 0

        private static method returnValue takes nothing returns nothing
            set dat.dN = dat.dN + 1
        endmethod
   
        static method DestructablesNearby takes real x, real y returns boolean
            set dat = DN.allocate()
            set r = Rect(x-100, y-100, x+100, y+100)
            call EnumDestructablesInRect(r, True, function DN.returnValue)
            call RemoveRect(r)
            if dat.dN > 0 then
                return true
            else
                return false
            endif
        endmethod
   
    endstruct
   
    private function UnitsNearby takes real x, real y, unit dragged returns boolean
        local group nGroup = CreateGroup()
        local unit n
        set draggedUnit = dragged
        call GroupEnumUnitsInRange(nGroup, x, y, 60, kbBoolexpr)
        set n = FirstOfGroup(nGroup)
        call DestroyGroup(nGroup)
        set nGroup = null
        set draggedUnit = null
        if n == null then
            return false
        else
            set n = null
            return true
        endif
    endfunction
   
    private function coreDrag takes nothing returns nothing
        local unit e = GetEnumUnit()
        local integer i = GetHandleId(e)
        local real a = LoadReal(ht, i, 2)
        local real x = GetUnitX(e)
        local real y = GetUnitY(e)
        local real x2 = x+checkDist*Cos(a)
        local real y2 = y+checkDist*Sin(a)
        local real diffZ = GetLocZ(x2,y2)-GetLocZ(x,y)
        local real drag = LoadReal(ht, i, 1)
        local real x3 = x+drag*Cos(a)
        local real y3 = y+drag*Sin(a)
        if diffZ < -NoDrag and UnitsNearby(x2, y2, e) == false and DN.DestructablesNearby(x2, y2) == false and IsTerrainPathable(x3,y3, PATHING_TYPE_WALKABILITY) == false then
            set drag = drag + dragGravity
            call SaveReal(ht, i, 1, drag)
            call SetUnitX(e, x3)
            call SetUnitY(e, y3)
        else
            call GroupRemoveUnit(dragGroup, e)
            call SaveBoolean(ht, i, 0, false)
            set maxDrag = maxDrag - 1
            if maxDrag == 0 then
                call PauseTimer(d)
            endif
        endif
        set e = null
    endfunction
   
    private function DragUnits takes nothing returns nothing
        call ForGroup(dragGroup, function coreDrag)
    endfunction
   
    private function coreAccel takes nothing returns nothing
        local unit e = GetEnumUnit()
        local integer i = GetHandleId(e)
        local real f = GetUnitFacing(e)*DEGTORAD
        local real x = GetUnitX(e)
        local real y = GetUnitY(e)
        local real x2 = x+checkDist*Cos(f)
        local real y2 = y+checkDist*Sin(f)
        local real defaultSpeed = GetUnitDefaultMoveSpeed(e)
        local real diffZ = GetLocZ(x2,y2)-GetLocZ(x,y)
        local real newSpeed = defaultSpeed+(gravity*diffZ)
        if diffZ < -NoDrag and IsTerrainPathable(x2,y2, PATHING_TYPE_WALKABILITY) == false then
            if LoadBoolean(ht, i, 0) == false then
                call SaveBoolean( ht, i, 0, true )
                call SaveReal( ht, i, 1, dragGravity )
                call SaveReal( ht, i, 2, f )
                set maxDrag = maxDrag + 1
                call GroupAddUnit(dragGroup, e)
                call TimerStart(d, dragIteration, true, function DragUnits)
            endif
        else
            if LoadBoolean( ht, i, 0 ) == false then
                call SetUnitMoveSpeed(e, newSpeed)
            else
                call SetUnitMoveSpeed(e, defaultSpeed)
            endif
        endif
        set e = null
    endfunction
   
    private function AccelerateUnits takes nothing returns nothing
        call ForGroup(accelUnits, function coreAccel)
    endfunction
   
    function AddUnitAcceleration takes unit u returns nothing
        if u == null then
            return
        endif
        call GroupAddUnit(accelUnits, u)
        set maxAccel = maxAccel + 1
        call TimerStart(t, tIteration, true, function AccelerateUnits)
    endfunction

    function RemoveUnitAcceleration takes unit u returns nothing
        if u == null then
            return
        endif
        call GroupRemoveUnit(accelUnits, u)
        call SetUnitMoveSpeed( u, GetUnitDefaultMoveSpeed(u) )
        set maxAccel = maxAccel - 1
        if maxAccel == 0 then
            call PauseTimer(t)
        endif
    endfunction
   
    //-----------------------------------------------------------------
    private function Init takes nothing returns nothing
        set kbBoolexpr = Condition(function returnBoolean)
        set True = Condition(function returnTrue)
    endfunction
   
endlibrary

------------------------------------------------
- may add a function to access drag acceleration

ChangeLog:
Version 1
EDIT: Remembered to flush the child hashtable of dragged units.
EDIT2: Mesed up in a JASS line for adding acceleration to all units in map :p
EDIT3: Made units being dragged get stopped by units in their way, and be able to continue their drag only after their path is safe. Only problem here is that warcraft uses 2d distance for unit collision, so it may look wierd in REALLY RARE situations.
EDIT4 (IMPORTANT): Added destructable collision while on drag.
EDIT5: made coding slightly more efficient by using a hardcoded radius for finding nearby units and destructables.
EDIT6: made it so ranged units can stil attack while being dragged down.
EDIT7: Fixed Boolexpr Leak since i used null in destructable check

Version 0.12
EDIT8: added an initial velocity for drag as it should be done
Version 0.13
timer iteration changed to 0.30 from 0.15
Version 0.14
Slightly improved coding efficiency.
Version 0.15
private group dragGroup is now constant
Version 0.16
the rect r is now a global variable
made a constant DEGTORAD variable instead of the bj_DEGTORAD

Keywords:
acceleration, Diehard@Azeroth, height, physics
Contents

Acceleration System v0.16 (Map)

Reviews
Moderator
17:37, 28th Oct 2009 The_Reborn_Devil: Seems like a quite simple yet useful system. The coding looks good although for better efficiency please inline some of the functions. I couldn't find any leaks or bugs, but it would be better if you added...
  1. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    ^^ good, it feels pretty good to make people feel happy, a +rep for your positive attitude ;)
     
  2. eleljrk

    eleljrk

    Joined:
    Aug 27, 2009
    Messages:
    461
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    How can i change the speed of climbing to the top of a mountain?
    EDIT: NVM! I found out how! ;) *knock my head*
     
  3. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    you change the gravity variable, the lower it is, for example -6 instead of -9.81, the better since itll decrease the rate of acceleration/deacceleration

    btw: dl this again, sorry for the constant changes, but i just saw that the speed of the drag is a bit faster cus initial velocity is already there, so i made it correct >_< lul it was because i did a change to fix a bug in a previous ver
     
  4. eleljrk

    eleljrk

    Joined:
    Aug 27, 2009
    Messages:
    461
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    *Scream* Download number 5, or something! xD
    Well, i hope you will make the other system.. ;)
     
  5. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    haha yea sure man, cant now tho >_> and i think Anachrons bar system is only for units hp, but hopefully not :p
     
  6. Revolve

    Revolve

    Joined:
    Jun 11, 2007
    Messages:
    935
    Resources:
    11
    Icons:
    8
    Skins:
    1
    Maps:
    1
    Tutorials:
    1
    Resources:
    11
    Btw, hehe, forgot to mention that I voted for Approval for this one :) I just complained about the bug, but I think it's really awsome otherwise :D +rep also :3
     
  7. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    thanks mate ^^, yea its getting pretty fast when i removed the BOOLEXPR leak
     
  8. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,221
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    It should be a hell more customizeable.
    Add interfaces, so I am allowed to modify the units speed of a chosen unit.
    Also allow endless running, so he will never stop, until the method I setted before returns false.

    And btw, you are getting better. Keep up the good work.

    One thing through: You need a far better documentation.
    And the objects should be better named.

    Edit:
    It can be used for everything. You can do rage bars, you can use it for speed bars, pratically, it allows you to do everything you want to with a bar.
     
  9. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    u can modify the units default ms with object editor tho >_< and what do u mean by endless running mate?

    bwt thanks for review and for large rep xP
     
  10. eleljrk

    eleljrk

    Joined:
    Aug 27, 2009
    Messages:
    461
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    To do list:
    • Make unit move after draged.
    • Make it more configureable
    • Add more description, i had to read stuff many times before i did understand (In the Config area its very bad, ddidnt understand if i had to increase or decrease the values to do what i wanted)

    Thats all i got now.. ;)
     
  11. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    haha ok man :p, what do u mean make unit move after dragged tho? cus the unit is able to move while being dragged, increasing the overall velocity >_>

    --------------------------------------------------------
    btw Devil, ima do that to show its really MUI, and thanks for the moderating mate, anyways man do i reallyhave to inline the functions and give objects better names? cus the purpose of this system is not necessarily to learn from it >_> says lazy person :p

    and man, im really focusing on the efficiency part cus people may use it in a little laggy map, so better to be safe then sorry ), btw some may use it for alot of units so im afraid it may lag if that ever happens xP
     
  12. eleljrk

    eleljrk

    Joined:
    Aug 27, 2009
    Messages:
    461
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    When you set a Point before draged, and ur draged to the bottom, the unit dont finish the issue.
     
  13. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    o damn, that bug, yea il check it out; ur right, thy observant eye knoweth alot (shakespearian language ftl)
     
  14. YourNameHere

    YourNameHere

    Joined:
    Apr 29, 2007
    Messages:
    745
    Resources:
    4
    Maps:
    1
    Spells:
    2
    JASS:
    1
    Resources:
    4
    They should finish their orders with the newest version. He used SetUnitPosition before which stops all orders, and now uses SetUnitX/Y which doesn't.
     
  15. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    yea man i noticed i couldnt find the bug anymore, cus i was surprised that there ever was in this ver :p

    and yea, good knowledge of functions u got there mate ;)
     
  16. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,221
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Its basic, you have to know such stuff in order to make normal maps.

    Don't ask for the average maps...
     
  17. Arnadath

    Arnadath

    Joined:
    Oct 31, 2008
    Messages:
    227
    Resources:
    0
    Resources:
    0
    Excelent. Good job mate.

    I had made this system in mine rpg (see in sig what im working on) but only for giving 522 ms for decline and stop for incline. Still this is far better and i might use it
    Keep up the good work

    And also expect soon some work for me. I wont say much, but ill say its the first entirely vJASS yet nice system
     
  18. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    thanks alot mate; btw you can edit this system, continue it if ud like, i mean a good coder like you would always be a good asset to the system; i dont really think adding interfaces + w/e is necessary since u can already change things with variables such as gravity etc...

    thanks alot bro, feel free to edit it as youd like mate, as long as u give me credits as original creator, hoping you use vJass tho :p

    tho 2 bugs you will encounter is: if heights are really different, then you will see that unit collision is messed up, since WE treats it as a 2D environment, u can fix this by creating your own collision system, but thatll be damn hard :p

    you would also have to deal with the maximum ms bug , 522, problem think u know it already tho

    Good luck on ur system mate, appreciate your comment ^^
     
  19. Catch_ya

    Catch_ya

    Joined:
    May 21, 2009
    Messages:
    982
    Resources:
    1
    Spells:
    1
    Resources:
    1
    remember to say this 5/5 :D
     
  20. Diehard@Azeroth

    Diehard@Azeroth

    Joined:
    Sep 21, 2007
    Messages:
    483
    Resources:
    1
    Spells:
    1
    Resources:
    1
    haha :p thanks ^^