2022-08-19 01:05:37 +00:00
|
|
|
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) {
|
2022-08-19 01:47:44 +00:00
|
|
|
var dist = c_tiledist(target.pos.x, target.pos.y, dude.pos.x, dude.pos.y);
|
|
|
|
if dist.x+dist.y <= target.data.rng.val {
|
|
|
|
log("started combat")
|
|
|
|
c_generatecombatstack([target, dude]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
log(c_tiledist(target.pos.x, target.pos.y, dude.pos.x, dude.pos.y));
|
2022-08-19 01:05:37 +00:00
|
|
|
var guy = c_gettile(target.pos.x, target.pos.y);
|
2022-08-19 01:47:44 +00:00
|
|
|
if target.pos.x < dude.pos.x {
|
2022-08-19 01:05:37 +00:00
|
|
|
var guy = c_gettile(target.pos.x+1, target.pos.y);
|
2022-08-19 01:47:44 +00:00
|
|
|
} else if target.pos.x > dude.pos.x {
|
2022-08-19 01:05:37 +00:00
|
|
|
var guy = c_gettile(target.pos.x-1, target.pos.y);
|
|
|
|
}
|
2022-08-19 01:47:44 +00:00
|
|
|
if target.pos.y < dude.pos.y {
|
|
|
|
var guy = c_gettile(target.pos.x, target.pos.y+1);
|
|
|
|
} else if target.pos.y > dude.pos.y {
|
|
|
|
var guy = c_gettile(target.pos.x, target.pos.y-1);
|
2022-08-19 01:05:37 +00:00
|
|
|
}
|
2022-08-19 01:47:44 +00:00
|
|
|
if guy != noone {
|
|
|
|
if guy.passable && !c_containsunit(guy.x, guy.y) {
|
|
|
|
c_moveunit(target, guy);
|
|
|
|
}
|
2022-08-19 01:05:37 +00:00
|
|
|
}
|
2022-08-19 01:47:44 +00:00
|
|
|
c_loadmarkings();
|
2022-08-19 01:05:37 +00:00
|
|
|
}
|
|
|
|
target.waiting = true;
|
|
|
|
break;
|
|
|
|
case AI.WAITER:
|
2022-08-19 01:47:44 +00:00
|
|
|
target.waiting = true;
|
2022-08-19 01:05:37 +00:00
|
|
|
break;
|
|
|
|
case AI.ESCAPER:
|
2022-08-19 01:47:44 +00:00
|
|
|
target.waiting = true;
|
2022-08-19 01:05:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-08-19 01:47:44 +00:00
|
|
|
c_loadmarkings();
|
2022-08-19 01:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function c_findnearestunit(alignment) {
|
|
|
|
var lowest = new vec2(99, 99);
|
2022-08-19 01:47:44 +00:00
|
|
|
var lowestunit = noone;
|
2022-08-19 01:05:37 +00:00
|
|
|
for (i=0; i<array_length(global.units[alignment]); i++) {
|
|
|
|
var guy = global.units[alignment][i].pos;
|
2022-08-19 01:47:44 +00:00
|
|
|
if (lowest.x + lowest.y > guy.x + guy.y) {
|
2022-08-19 01:05:37 +00:00
|
|
|
lowest = guy;
|
|
|
|
lowestunit = global.units[alignment][i];
|
|
|
|
}
|
|
|
|
}
|
2022-08-19 01:47:44 +00:00
|
|
|
return lowestunit;
|
2022-08-19 01:05:37 +00:00
|
|
|
}
|