- Joined
- Jul 20, 2009
- Messages
- 835
JASS:
// function InitProjectile takes player whichPlayer, integer typeId, real x, real y, real z, real facing returns integer
// Initializes a new projectile on the map. Returns the Id of the projectile so you deal just with integers.
// function RemoveProjectile takes integer whichId, boolean killNeeded, boolean explodeNeeded returns nothing
// Removes the projectile by id.
// function AllocateNewProjectile takes nothing returns integer
// Determines the id where the projectile will take its place.
// function GetProjectile takes integer whichId returns unit
// Returns the projectile from selected id.
// function GroupEnumProjectilesInRect takes group whichGroup, rect whichRect returns nothing
// Enumerates projectiles in rect.
// function GroupEnumProjectilesInRange takes group whichGroup, real x, real y, real rangeAmount returns nothing
// Enumerates projectiles in range.
// function GroupEnumProjectilesOfPlayer takes group whichGroup, player whichPlayer returns nothing
// Enumerates projectiles of player.
function GetProjectile takes integer whichId returns unit
return LoadUnitHandle(udg_H,0,whichId)
endfunction
function AllocateNewProjectile takes nothing returns integer
local integer i = -2147483648
loop
exitwhen i > 2147483647 or GetProjectile(i) == null
set i = i + 1
endloop
return i
endfunction
function GroupEnumProjectilesOfPlayer takes group whichGroup, player whichPlayer returns nothing
// Because the projectiles have Locust, they can't be enumed in ordinary way.
local integer currentId = -2147483648
local unit currentProjectile
loop
exitwhen currentId > 2147483647
set currentProjectile = GetProjectile(currentId)
if currentProjectile != null then
if GetOwningPlayer(currentProjectile) == whichPlayer then
call GroupAddUnit(whichGroup,currentProjectile)
endif
endif
set currentId = currentId + 1
endloop
set currentProjectile = null
endfunction
function GroupEnumProjectilesInRect takes group whichGroup, rect whichRect returns nothing
// Because the projectiles have Locust, they can't be enumed in ordinary way.
local integer currentId = -2147483648
local unit currentProjectile
local real projectileX
local real projectileY
loop
exitwhen currentId > 2147483647
set currentProjectile = GetProjectile(currentId)
if currentProjectile != null then
set projectileX = GetUnitX(currentProjectile)
set projectileY = GetUnitY(currentProjectile)
if (GetRectMinX(whichRect) <= projectileX) and (projectileX <= GetRectMaxX(whichRect)) and (GetRectMinY(whichRect) <= projectileY) and (projectileY <= GetRectMaxY(whichRect)) then
call GroupAddUnit(whichGroup,currentProjectile)
endif
endif
set currentId = currentId + 1
endloop
set currentProjectile = null
endfunction
function GroupEnumProjectilesInRange takes group whichGroup, real x, real y, real rangeAmount returns nothing
// Because the projectiles have Locust, they can't be enumed in ordinary way.
local integer currentId = -2147483648
local unit currentProjectile
local real projectileX
local real projectileY
local real thisDistance = 0.
loop
exitwhen currentId > 2147483647
set currentProjectile = GetProjectile(currentId)
if currentProjectile != null then
set projectileX = GetUnitX(currentProjectile)
set projectileY = GetUnitY(currentProjectile)
set thisDistance = SquareRoot((x-projectileX)*(x-projectileX)+(y-projectileY)*(y-projectileY))
if thisDistance <= rangeAmount then
call GroupAddUnit(whichGroup,currentProjectile)
endif
endif
set currentId = currentId + 1
endloop
set currentProjectile = null
endfunction
function RemoveProjectile takes integer whichId, boolean killNeeded, boolean explodeNeeded returns nothing
local unit whichProjectile = GetProjectile(whichId)
call SetUnitExploded(whichProjectile,explodeNeeded)
if killNeeded then
call KillUnit(whichProjectile)
else
call RemoveUnit(whichProjectile)
endif
call RemoveSavedHandle(udg_H,0,whichId)
set whichProjectile = null
endfunction
function InitProjectile takes player whichPlayer, integer typeId, real x, real y, real z, real facing returns integer
local integer lastSavedID = AllocateNewProjectile()
local unit newProjectile = CreateUnit(whichPlayer,typeId,x,y,facing)
if UnitAddAbility(newProjectile,'Amrf') then
call UnitRemoveAbility(newProjectile,'Amrf')
endif
call SetUnitFlyHeight(newProjectile,z,0.)
call UnitAddAbility(newProjectile,'Aloc')
call SaveUnitHandle(udg_H,0,lastSavedID,newProjectile)
return newProjectile
endfunction
Requires initialized hashtable H.