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

123 lines
3.8 KiB
Plaintext
Raw Permalink Normal View History

2022-08-19 01:05:37 +00:00
function c_doenemyai(target) {
switch target.data.aitype {
case AI.AFK:
2022-08-23 14:54:54 +00:00
var dude = c_findnearestunit(target.pos.x,target.pos.y,ARMY.US);
2022-08-23 13:06:02 +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;
}
c_loadmarkings();
2022-08-19 01:05:37 +00:00
target.waiting = true;
break;
case AI.KILLER:
2022-08-23 14:54:54 +00:00
var dude = c_findnearestunit(target.pos.x,target.pos.y,ARMY.US);
2022-08-19 01:05:37 +00:00
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:
2022-08-23 14:54:54 +00:00
var dude = c_findnearestunit(target.pos.x,target.pos.y,ARMY.US);
2022-08-19 02:26:10 +00:00
var dist = c_tiledist(target.pos.x, target.pos.y, dude.pos.x, dude.pos.y);
2022-08-23 13:06:02 +00:00
if dist.x+dist.y > target.data.mov.val + target.data.rng.val {
2022-08-19 02:26:10 +00:00
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");
2022-08-23 13:06:02 +00:00
//c_deleteunit(target.pos.x, target.pos.y, target);
break;
2022-08-19 02:26:10 +00:00
}
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-23 08:34:45 +00:00
waiting = 70;
2022-08-19 01:05:37 +00:00
}
2022-08-23 13:06:02 +00:00
function c_findnearestunit(x, y, alignment) {
2022-08-19 01:05:37 +00:00
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++) {
2022-08-23 13:06:02 +00:00
var guy = c_tiledist(x, y, global.units[alignment][i].pos.x, global.units[alignment][i].pos.y);
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
}