Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,239
JASS:
//! zinc
library Wanderer {
hashtable hash = InitHashtable();
function Move(unit u) {
integer id = GetHandleId(u);
integer dist = GetRandomInt(500,1500);
real angle = GetRandomReal(0, 360);
real x = GetUnitX(u) + dist * Cos(angle * bj_DEGTORAD);
real y = GetUnitY(u) + dist * Sin(angle * bj_DEGTORAD);
SaveInteger(hash, id, 0, GetTerrainType(x, y));
SaveReal(hash, id, 1, x);
SaveReal(hash, id, 2, y);
IssuePointOrder(u, "move", x, y);
SetTerrainType(x, y, 'Nsnw', -1, 1, 0);
}
function GetDistance(real cx, real cy, real dx, real dy) -> real {
real x = dx - cx;
real y = dy - cy;
return SquareRoot(x * x + y * y);
}
function GroupActions() {
unit u = GetEnumUnit();
integer id = GetHandleId(u);
real x = LoadReal(hash, id, 1);
real y = LoadReal(hash, id, 2);
if(GetDistance(GetUnitX(u), GetUnitY(u), x, y) < 50) {
SetTerrainType(x, y, LoadInteger(hash, id, 0), -1, 1, 0);
//chosing to not clear the hashtable since the values gets replaced anyway
Move(u);
}
u = null;
}
function onLoop() {
group g = GetUnitsInRectMatching(bj_mapInitialPlayableArea, null);
ForGroup(g, function GroupActions);
DestroyGroup(g);
g = null;
}
function onInit() {
timer t = CreateTimer();
TimerStart(t, 0.03, true, function onLoop);
Move(CreateUnit(Player(0), 'hgry', 0, 0, 0));
t = null;
}
}
//! endzinc
Attachments
Last edited: