Gtam
Lerning how to write and read!! Yeah.
- Reaction score
- 164
Track Unit Movement System Created by Gtam
Requires:
NewGen
AIDS by Jesus4Lyf
A nice example of use is in the DemoMap
Requires:
NewGen
AIDS by Jesus4Lyf
JASS:
//=========================================================================================\\
//=========================================================================================\\
//== _______ __ __ ___ ___ ______ ==\\
//== |___ ___| | | | | | \ / | / _____ //================\\ ==\\
//== | | | | | | | \ \/ / | | |_____ //= Track Unit ===\\ ==\\
//== | | | | | | | |\ /| | \_____ \ //= Movement =====\\ ==\\
//== | | | |_| | | | \/ | | ______ | //= System v1.07 =\\ ==\\
//== |_| \_______/ |__| |__| \_______/ //================\\ ==\\
//== ==\\
//== ==\\
//== Track Unit Movement System is a system that keeps track of how far unit unit has ==\\
//== travelled for a long and short period and can say if a unit is currently moving and ==\\
//== in which direction. ==\\
//== ==\\
//== The Functions for you ==\\
//== ==\\
//== TrackUnitMovement() takes unit whichUnit returns nothing ==\\
//== This function adds a unit to the system ==\\
//== ==\\
//== StopTrackingUnit() takes unit whichUnit, boolean long returns nothing ==\\
//== This function removes the unit from the system ==\\
//== ==\\
//== IsUnitMoving() takes unit whichUnit returns boolean ==\\
//== This function will return true if a unit is moving and false if not ==\\
//== ==\\
//== GetUnitMovingAngle() takes unit whichUnit returns real ==\\
//== This function will return the angle the unit is moving in ==\\
//== ==\\
//== GetUnitMovingDistance() takes unit whichUnit returns real ==\\
//== This function returns the units moving distance since being added ==\\
//== ==\\
//== GetUnitTotalMovingDistance() takes unit whichUnit returns real ==\\
//== This function returns the units moving distance since being added and cannot be ==\\
//== reseted ==\\
//== ==\\
//== ResetUnitMovingDistance() takes unit whichUnit returns nothing ==\\
//== This set the units moving distance to 0 ==\\
//== ==\\
//=========================================================================================\\
//=========================================================================================\\
library TUMS initializer Init requires AIDS
struct TUMS extends array
//! runtextmacro AIDS()
real ox
real oy
real nx
real ny
real Distance
method AIDS_onCreate takes nothing returns nothing
set this.ox = 0.
set this.oy = 0.
set this.nx = 0.
set this.ny = 0.
set this.Distance = 0.
endmethod
endstruct
globals
private constant real PeriodicMovementCheck = .03125
private real x
private real y
private real Squareroot
private unit P
private group TrackUnits = CreateGroup()
endglobals
function TrackUnitMovement takes unit whichUnit returns nothing
if IsUnitInGroup( whichUnit, TrackUnits) == false then
call GroupAddUnit( TrackUnits, whichUnit)
endif
endfunction
function StopTrackingUnit takes unit whichUnit returns nothing
if IsUnitInGroup( whichUnit, TrackUnits) == true then
call GroupRemoveUnit( TrackUnits, whichUnit)
endif
endfunction
function IsUnitMoving takes unit whichUnit returns boolean
local TUMS d = TUMS[whichUnit]
local real dx = d.nx - d.ox
local real dy = d.ny - d.oy
if SquareRoot(dx * dx + dy * dy) > 0 then
return true
else
return false
endif
endfunction
function GetUnitMovingAngle takes unit whichUnit returns real
local TUMS d = TUMS[whichUnit]
return 57.2958 * (Atan2(d.ny - d.oy, d.nx - d.ox))
endfunction
function GetUnitMovingDistance takes unit whichUnit returns real
return TUMS[whichUnit].Distance
endfunction
function ResetUnitDistance takes unit whichUnit returns nothing
set TUMS[whichUnit].Distance = 0
endfunction
private function TUMS_Group takes nothing returns nothing
local TUMS d = TUMS[GetEnumUnit()]
local real dx
local real dy
set P = GetEnumUnit()
set x = GetUnitX(P)
set y = GetUnitY(P)
set dx = x - d.nx
set dy = y - d.ny
set Squareroot = SquareRoot(dx * dx + dy * dy)
if IsUnitType (P, UNIT_TYPE_DEAD) == false then
if Squareroot <= 35 then
set d.Distance = d.Distance + Squareroot
endif
set d.ox = d.nx
set d.oy = d.ny
set d.nx = x
set d.ny = y
else
call StopTrackingUnit(P)
endif
endfunction
private function TUMS_Actions takes nothing returns nothing
call ForGroup( TrackUnits, function TUMS_Group )
endfunction
private function Init takes nothing returns nothing
call TimerStart( CreateTimer(), PeriodicMovementCheck, true, function TUMS_Actions)
endfunction
endlibrary
A nice example of use is in the DemoMap
Code:
ChangeLog
v1.00 Released
v1.01 Uses Variable for picked unit and stops teleporting as counting.
v1.02 Updated to everyones suggestions
v1.03 Show what you must not do.
v1.04 New functions to prevent stuff ups
v1.05 No AIDS uses hashtable
v1.06 Now uses AIDS Structs and no hashtables.
v1.07 Little update