#### Dirac

##### 22710180

JASS:

```
library SpeedMod /* v2.1.0
*/uses/*
*/ LinkedListModule /* thehelper.net/forums/showthread.php/168775-LinkedListModule
*/ optional UnitIndexer /*
*/ optional AIDS /*
**********************************************************************
*
* struct SpeedMod
* - Handles unit's movement speed modifications.
*
* static method create takes unit whichUnit, real percent returns SpeedMod
* - Modifies the unit's speed in the given percent.
* - 1.0 means 100% increase.
* static method base takes unit whichUnit, real amount returns nothing
* - Modifies the unit's base speed by the given amount.
* - Giving it 20 adds 20 movement speed.
* method destroy takes nothing returns nothing
* - Destroys the mod.
* real amount
* - Is the percentage of speed this SpeedMod awards, if
* - set to another value it applies the effect.
*
*********************************************************************/
private struct UnitBaseSpeed extends array
implement LinkedList
real add
real total
thistype node
static if LIBRARY_UnitIndexer then
method index takes nothing returns nothing
set this.node = createNode()
endmethod
method deindex takes nothing returns nothing
call this.node.flushNode()
endmethod
else
method AIDS_onCreate takes nothing returns nothing
set this.node = createNode()
endmethod
method AIDS_onDestroy takes nothing returns nothing
call this.node.flushNode()
endmethod
endif
implement optional UnitIndexStruct
//! runtextmacro optional AIDS()
endstruct
struct SpeedMod extends array
readonly unit target
private real value
private real input
method operator amount= takes real v returns nothing
local UnitBaseSpeed index=GetUnitUserData(target)
local real speed=index.add+GetUnitDefaultMoveSpeed(target)
set index.total=index.total-value
set value=v*speed
set input=v
set index.total=index.total+value
call SetUnitMoveSpeed(target,speed+index.total)
endmethod
static method base takes unit whichUnit, real value returns nothing
local UnitBaseSpeed index=GetUnitUserData(whichUnit)
local UnitBaseSpeed this = index.node.next
set index.add=index.add+value
call SetUnitMoveSpeed(whichUnit,GetUnitDefaultMoveSpeed(whichUnit)+index.add+index.total)
loop
exitwhen this.head
set thistype(this).amount=thistype(this).input
set this=this.next
endloop
endmethod
method operator amount takes nothing returns real
return input
endmethod
static method create takes unit whichUnit, real v returns thistype
local thistype this=UnitBaseSpeed.allocate()
local UnitBaseSpeed index=GetUnitUserData(whichUnit)
local real speed=index.add+GetUnitDefaultMoveSpeed(whichUnit)
set value=v*speed
set input=v
set target=whichUnit
set index.total=index.total+value
call SetUnitMoveSpeed(whichUnit,speed+index.total)
call index.node.insertNode(this)
return this
endmethod
method destroy takes nothing returns nothing
local UnitBaseSpeed index=GetUnitUserData(target)
set index.total=index.total-value
call UnitBaseSpeed(this).removeNode()
call UnitBaseSpeed(this).deallocate()
call SetUnitMoveSpeed(target,GetUnitDefaultMoveSpeed(target)+index.add+index.total)
endmethod
endstruct
endlibrary
```