- Joined
- Mar 25, 2016
- Messages
- 1,327
JASS:
scope Wanderer initializer Init
globals
private hashtable hash
endglobals
private function Move takes nothing returns nothing
local unit u = LoadUnitHandle(hash,0,0)
local real x0 = GetUnitX(u)
local real y0 = GetUnitY(u)
local real x1
local real y1
local real distance = GetRandomReal(500, 1500)
local real angle = GetRandomReal(0, 2*bj_PI)
//I don't know if we have to deal with exceptions, but here it is in case the point is not within
//the playable map area.
//It's a bad algorithm, but since the minimum chance of succes is 25% (in a corner),
//it should be sufficient for only one unit.
loop
set x1 = x0 + distance * Cos(angle)
set y1 = y0 + distance * Sin(angle)
exitwhen RectContainsCoords(bj_mapInitialPlayableArea, x1, y1)
endloop
call SaveInteger(hash, 0, 2, GetTerrainType(x1,y1))
call SaveReal(hash, 0, 3, x1)
call SaveReal(hash, 0, 4, y1)
call SaveInteger(hash, 0, 5, GetTerrainVariance(x1, y1))
call SetTerrainType(x1, y1, 'Nsnw', -1, 1, 0)
call IssuePointOrder(u,"move",x1,y1)
set u = null
endfunction
private function Check takes nothing returns nothing
local unit u = LoadUnitHandle(hash,0,0)
local real x0 = GetUnitX(u)
local real y0 = GetUnitY(u)
local real x1 = LoadReal(hash, 0, 3)
local real y1 = LoadReal(hash, 0, 4)
if(IsUnitInRangeXY(u, x1, y1, 20)) then
call SetTerrainType(x1, y1, LoadInteger(hash, 0, 2), LoadInteger(hash, 0, 5), 1, 0)
call Move()
endif
set u = null
endfunction
private function Init takes nothing returns nothing
local timer t = CreateTimer()
set hash = InitHashtable()
call SaveUnitHandle(hash, 0, 0, CreateUnit(GetLocalPlayer(), 'hgry', GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea), 0))
call TimerStart(t, 0.03, true, function Check)
call SaveTimerHandle(hash, 0, 1, t)
call Move()
set t = null
endfunction
endscope
I was not sure, if we need to deal with exceptions, that are not specified in the mission description, so I used a very bad algorithm to make the target point always be within the playable map area.