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. Dismiss Notice
  6. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  7. 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.

Trigger Viewer

testingAcceleration.w3x
Variables
Initialization
Adding Acceleration to the footman
AccelerationSystem[Units]
How to implement the system
GUI guide on using the system
How to use the system
-------------------------------------------
Normal Guide
Using the System
Configuring the system
Acceleration System
Acceleration Library
-------------------------------------------
Extra credits
Enter map-specific custom script code below. This text will be included in the map script after variables are declared and before any trigger code.

		
Name Type Is Array Initial Value
Unit1 unit No
Adding Acceleration to the footman
  Events
    Map initialization
  Conditions
  Actions
    Visibility - Disable black mask
    Visibility - Disable fog of war
    Set VariableSet Unit1 = Rifleman 0000 <gen>
    Custom script: call AddUnitAcceleration(udg_Unit1)
    Set VariableSet Unit1 = Rifleman 0003 <gen>
    Custom script: call AddUnitAcceleration(udg_Unit1)
Note:

MS = Movement Speed
//TESH.scrollpos=0
//TESH.alwaysfold=0
 First of all, copy the folder/category "Acceleration System[Units]" and paste it to your maps trigger editor section

 Alright guys, to make this system work in ur map you need to realize one important thing

 and mess with gameplay constants in the Advanced section:

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

 *first of all, know that the maximum speed any unit in the game he can have is 522, so he he will not be able to accelerate while going down
 a high mountian if he is 522 because i cant increase his speed. Also know that if the unit doesnt have enough movement speed, for example 60,
 he will deaccelerate up a mountain or any high terrain and wil have his speed reach 0 pretty fast, so then he wont be able to move up in that
 direction.
 
     so what i did to fix this problem and show acceleration/deacceleration we;; is use a good movement speed of 270, the footmans default MS;
     
  *Now for the gameplay constants changing:
   
    - click on "Advanced" in the world editor screen and go to "Gameplay Constants"
   
    - Now find "Movement - Unit Speed - Maximum" and change its value to 522
   
    - Now find "Movement - Unit Speed - Minimum" and change its value to 0 by clicking Shift+Enter and changing its value to 0,
    if you dont know how to use the shift+enter trick i just mentioned, just change the value to 1 in it.

----------------------------------------------------------------------------------------------------------------------------------------------
   
    ... i hope to find a hack to make the maximum movement speed over 522, but until then, you must do what i told u
   
    also, if you have alot of periodic events in ur map, or triggers that run periodically like Event - Every 5 seconds or w/e
   
    and ur feeling that this may lag you, then go to the "Acceleration Libary" trigger and
   
    find this code line:      private real tIteration = 0.30 // timer periodic iteration
   
    now the 0.30 value is the time that the timer runs, just like the Every 5 seconds event in GUI, and that value is like the 5.
   
    so now it runs every .30 seconds to make acceleration work well, you might want to increase it to .45 or someting to decrease lag in ur map if u have
   
    any, although u should know, this does NOT lag, but doing this can make lag less.
   
    Please give credits if you use this system
   
    Best regards,
    Diehard@Azeroth
//TESH.scrollpos=0
//TESH.alwaysfold=0

    How to use the system for GUI users

I made this system extra easy for GUI users, since i was a GUI fanatic and i understand what you guys go through when seeing JASS :p

anyways you go to the GUI command "Custom Script:"

and type in (without the quotes): "call AddUnitAcceleration()"

now create a new unit variable, and set the unit you want to have acceleration in that variable

lets say the variable i created was named Unit1

so i do "Set Unit1 = Footman 0000 <gen>" to set the unit1 variable have the footie in the map as its value

Thats the GUI Command for Setting Variables btw

then i add "udg_Unit1" without quotes, in between the brackets in the first line in the Custom Script

so it would be "call AddUnitAcceleration(udg_Unit1)"

 thats it! now you added acceleration to the unit!
 
 now to make your unit not have acceleration, you do "call RemoveUnitAcceleration(udg_Unit1)"
 
 and btw Unit1 is the name of the variable, so just replace Unit1 with the name of your variable, make sure it is typed correctly since
 
 JASS is case sensitive.
 
//TESH.scrollpos=0
//TESH.alwaysfold=0
the functions are as follows:

function AddUnitAcceleration takes unit u returns nothing

function RemoveUnitAcceleration takes unit u returns nothing
 
these functions add the ability to accelerate to a unit, and remove the ability to accelerate from a unit

*MAKE SURE TO REMOVE THE ACCELERATION OF A UNIT ONCE ITS PERMANENTLY OUT OF A GAME OR DEAD.

(so the system wont have to cycle through the
unit, decreasing the chance of a map to have any lag from this system [although it doesnt as proven in the demo], just a precautionary step)

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

make sure to change timer iteration if needed (its in the globals section of the library), and change the private constant in the globals section called "gravity"

to lower the change in acceleration/deacceleration; it would be more suitable for some movement speeds, but less realistic

since the real constant of gravity is -9.81.

btw, the units movespeed will be reverted to normal if you removed its ability to accelerate.


enjoy
 
//TESH.scrollpos=0
//TESH.alwaysfold=0
To configure this system, you need to first find the lines of code:


        // CONFIGURABLES
       
        private constant real NoDrag = 10. //the 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
       
       
       
        ------------------------------------------------------
        ----- The guide below is intended for GUI users ------
        ------------------------------------------------------

 and change these values, the numbers or reals, for example if i want to change NoDrags value then

 i would change the number 10 in "private constant real NoDrag = 10."
 
 *MAKE SURE TO PUT THE PERIOD INFRONT OF THE NUMBER IF YOUR NUMBER IS AN INTEGER
 ---------------------------------------------------------------------------------------------------
 
 btw what i mean by acceleration/deacceleration rate is how much acceleration or deacceleration there is depending on the height level,
 so if the rifleman goes down the hill, itll accelerate down it, depending on how much the number is. If u changed gravity to -6 instead of
 leaving it at -9.81, the acceleration will decrease, as will the deacceleration; and if you change gravity to a number higher than -9.81
 the acceleration will increase, as will the deacceleration too.
0 = is being dragged
1 = initial velocity of drag
2 = angle

or diffZ > NoDrag
//TESH.scrollpos=45
//TESH.alwaysfold=0
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
Elejrk@hiveworkshop.com for helping me find several bugs and fix the drag

Revolve, Shendoo2 and D4RK_G4ND4LF@hiveworkshop.com for finding a minor bug in the acceleration of units

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