47 lines
1.1 KiB
Plaintext
47 lines
1.1 KiB
Plaintext
|
function c_doenemyai(target) {
|
||
|
switch target.data.aitype {
|
||
|
case AI.AFK:
|
||
|
target.waiting = true;
|
||
|
break;
|
||
|
case AI.KILLER:
|
||
|
var dude = c_findnearestunit(ARMY.US);
|
||
|
repeat(target.data.mov.val) {
|
||
|
var guy = c_gettile(target.pos.x, target.pos.y);
|
||
|
if target.pos.x < dude.x {
|
||
|
var guy = c_gettile(target.pos.x+1, target.pos.y);
|
||
|
} else if target.pos.x > dude.x {
|
||
|
var guy = c_gettile(target.pos.x-1, target.pos.y);
|
||
|
}
|
||
|
if target.pos.y < dude.y {
|
||
|
var guy = c_gettile(target.pos.x+1, target.pos.y);
|
||
|
} else if target.pos.x > dude.x {
|
||
|
var guy = c_gettile(target.pos.x-1, target.pos.y);
|
||
|
}
|
||
|
if guy.passable {
|
||
|
c_moveunit(target, guy);
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
target.waiting = true;
|
||
|
break;
|
||
|
case AI.WAITER:
|
||
|
|
||
|
break;
|
||
|
case AI.ESCAPER:
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function c_findnearestunit(alignment) {
|
||
|
var lowest = new vec2(99, 99);
|
||
|
var lowestunit = new vec2(99, 99);
|
||
|
for (i=0; i<array_length(global.units[alignment]); i++) {
|
||
|
var guy = global.units[alignment][i].pos;
|
||
|
if (lowest.x + lowest.y < guy.x + guy.y) {
|
||
|
lowest = guy;
|
||
|
lowestunit = global.units[alignment][i];
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|