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 02:26:10 +00:00
|
|
|
var guy = c_gettile(target.pos.x, target.pos.y);
|
|
|
|
if target.pos.x < dude.pos.x {
|
|
|
|
var guy = c_gettile(target.pos.x+1, target.pos.y);
|
|
|
|
} else if target.pos.x > dude.pos.x {
|
|
|
|
var guy = c_gettile(target.pos.x-1, target.pos.y);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if guy != noone {
|
|
|
|
if guy.passable && !c_containsunit(guy.x, guy.y) {
|
|
|
|
c_moveunit(target, guy);
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
2022-08-19 02:26:10 +00:00
|
|
|
c_loadmarkings();
|
|
|
|
}
|
|
|
|
target.waiting = true;
|
|
|
|
break;
|
|
|
|
case AI.WAITER:
|
|
|
|
var dude = c_findnearestunit(ARMY.US);
|
|
|
|
var dist = c_tiledist(target.pos.x, target.pos.y, dude.pos.x, dude.pos.y);
|
|
|
|
if dist > target.data.mov.val + target.data.rng.val {
|
|
|
|
target.waiting = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
repeat(target.data.mov.val) {
|
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 02:26:10 +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;
|
|
|
|
}
|
2022-08-19 01:47:44 +00:00
|
|
|
c_loadmarkings();
|
2022-08-19 01:05:37 +00:00
|
|
|
}
|
|
|
|
target.waiting = true;
|
|
|
|
break;
|
|
|
|
case AI.ESCAPER:
|
2022-08-19 02:26:10 +00:00
|
|
|
var dude = c_gettile(0, 9);
|
|
|
|
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, target.pos.y+1);
|
|
|
|
} else if target.pos.y > dude.y && target.pos.x < 4 {
|
|
|
|
var guy = c_gettile(target.pos.x, target.pos.y-1);
|
|
|
|
}
|
|
|
|
if guy != noone {
|
|
|
|
if guy.passable {
|
|
|
|
c_moveunit(target, guy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var dist = c_tiledist(target.pos.x, target.pos.y, dude.x, dude.y);
|
|
|
|
log(dist);
|
|
|
|
if dist.x+dist.y <= 0 {
|
|
|
|
log("IM LEAVING");
|
|
|
|
c_deleteunit(target.pos.x, target.pos.y, target);
|
|
|
|
}
|
|
|
|
c_loadmarkings();
|
|
|
|
}
|
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
|
|
|
}
|