- Joined
- Jul 10, 2007
- Messages
- 6,306
JASS:
library FlatFlier /* v1.0.1.0
*************************************************************************************
*
* Makes units fly flatly over terrain (realistic) rather than go up and down
* with terrain.
*
* - Flying units will not be able to go over terrain higher than them
*
* - Non flying units will stop flying if they touch the ground
*
* - Requires the use of SetUnitZ (SetUnitFlyHeight will not work with this)
* - The reason for this is because a unit's fly height will continue to raise
* - while it climbs terrain higher than it is. There is no way to make SetUnitFlyHeight
* - work correctly.
*
*************************************************************************************
*
* */uses/*
*
* */ AutoFly /* hiveworkshop.com/forums/submissions-414/autofly-unitindexer-version-195563/
* */ IsUnitMoving /* hiveworkshop.com/forums/jass-functions-413/system-unit-moving-178341/
*
************************************************************************************
*
* SETTINGS
*/
globals
private constant boolean DO_GROUND_COLLISION = false
endglobals
private function OnGroundCollision takes unit u returns nothing
endfunction
/*
************************************************************************************
*
* Functions
*
* function SetUnitZ takes unit u, real v returns nothing
* function GetUnitZ takes unit u returns real
*
************************************************************************************/
globals
private integer array n
private integer array p
private real array w
private real array tz
private location z = Location(0,0)
private boolean array f
endglobals
private function i takes nothing returns nothing
local integer u = n[0]
local unit h
local real q
loop
exitwhen u == 0
set h = GetUnitById(u)
call MoveLocation(z, GetUnitX(h), GetUnitY(h))
set q = GetLocationZ(z)
set w[u] = w[u]+tz[u]-q
static if DO_GROUND_COLLISION then
if (w[u] <= 0) then
call OnGroundCollision(h)
endif
endif
call SetUnitFlyHeight(h, w[u], 10000)
set tz[u] = q
set u = n[u]
endloop
set h = null
endfunction
private function a takes nothing returns boolean
local integer u = GetMovingUnitId()
if (f[u]) then
set n[u] = 0
set p[u] = p[0]
set n[p[0]] = u
set p[0] = u
endif
return false
endfunction
private function r takes nothing returns boolean
local integer u = GetMovingUnitId()
if (f[u]) then
set n[p[u]] = n[u]
set p[n[u]] = p[u]
endif
return false
endfunction
private function g takes nothing returns boolean
local integer u = GetIndexedUnitId()
local unit h = GetUnitById(u)
call MoveLocation(z, GetUnitX(h), GetUnitY(h))
set tz[u] = GetLocationZ(z)
set w[u] = GetUnitFlyHeight(h)
set f[u] = w[u] > 0
set h = null
return false
endfunction
function SetUnitZ takes unit u, real v returns nothing
local integer c = GetUnitUserData(u)
call MoveLocation(z, GetUnitX(u), GetUnitY(u))
set w[c] = v-GetLocationZ(z)
set f[c] = w[c] > 0
if (f[c]) then
call SetUnitFlyHeight(u,w[c],10000)
if (IsUnitMoving(u)) then
set n[c] = 0
set p[c] = p[0]
set n[p[0]] = c
set p[0] = c
endif
endif
endfunction
function GetUnitZ takes unit u returns real
return w[GetUnitUserData(u)]
endfunction
private module Init
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function g), UnitIndexer.INDEX)
call TimerStart(CreateTimer(), .03125, true, function i)
call UnitMoving.MOVE.register(Condition(function a))
call UnitMoving.STOP.register(Condition(function r))
endmethod
endmodule
private struct Inits extends array
implement Init
endstruct
endlibrary
Last edited: