eastern-flames/eastern flames/scripts/c_doenemyai/c_doenemyai.gml

123 lines
3.7 KiB
Plaintext

function c_doenemyai(target) {
switch target.data.aitype {
case AI.AFK:
var dude = c_findnearestunit(ARMY.US);
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;
}
c_loadmarkings();
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.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);
}
}
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;
}
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.x+dist.y > target.data.mov.val + target.data.rng.val {
target.waiting = true;
break;
}
repeat(target.data.mov.val) {
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);
}
}
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;
}
c_loadmarkings();
}
target.waiting = true;
break;
case AI.ESCAPER:
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);
break;
}
c_loadmarkings();
}
target.waiting = true;
break;
}
c_loadmarkings();
waiting = 70;
}
function c_findnearestunit(x, y, alignment) {
var lowest = new vec2(99, 99);
var lowestunit = noone;
for (i=0; i<array_length(global.units[alignment]); i++) {
var guy = c_tiledist(x, y, global.units[alignment][i].pos.x, global.units[alignment][i].pos.y);
if (lowest.x + lowest.y > guy.x + guy.y) {
lowest = guy;
lowestunit = global.units[alignment][i];
}
}
return lowestunit;
}