improved Golem pathfinding

This commit is contained in:
Zeno Rogue 2020-11-05 15:02:47 +01:00
parent a6edbe3378
commit 771fe3458d
2 changed files with 17 additions and 12 deletions

View File

@ -129,10 +129,11 @@ EX void compute_graphical_distance() {
} }
} }
EX void computePathdist(eMonster param) { EX void computePathdist(eMonster param, bool include_allies IS(true)) {
for(cell *c: targets) for(cell *c: targets)
onpath(c, isPlayerOn(c) ? 0 : 1, hrand(c->type)); if(include_allies || isPlayerOn(c))
onpath(c, isPlayerOn(c) ? 0 : 1, hrand(c->type));
int qtarg = isize(targets); int qtarg = isize(targets);
@ -157,9 +158,12 @@ EX void computePathdist(eMonster param) {
int i = (fd+j) % c->type; int i = (fd+j) % c->type;
// printf("i=%d cd=%d\n", i, c->move(i)->cpdist); // printf("i=%d cd=%d\n", i, c->move(i)->cpdist);
cell *c2 = c->move(i); cell *c2 = c->move(i);
flagtype f = P_MONSTER | P_REVDIR;
if(param == moTameBomberbird) f |= P_FLYING;
if(c2 && c2->pathdist == PINFD && if(c2 && c2->pathdist == PINFD &&
passable(c2, (qb<qtarg) && !nonAdjacent(c,c2) && !thruVine(c,c2) ?NULL:c, P_MONSTER | P_REVDIR)) { passable(c2, (qb<qtarg) && !nonAdjacent(c,c2) && !thruVine(c,c2) ?NULL:c, f)) {
if(qb >= qtarg) { if(qb >= qtarg) {
if(param == moTortoise && nogoSlow(c, c2)) continue; if(param == moTortoise && nogoSlow(c, c2)) continue;
@ -186,9 +190,9 @@ struct pathdata {
pathlock--; pathlock--;
clear_pathdata(); clear_pathdata();
} }
pathdata(eMonster m) { pathdata(eMonster m, bool include_allies IS(true)) {
checklock(); checklock();
computePathdist(m); computePathdist(m, include_allies);
} }
pathdata(int i) { pathdata(int i) {
checklock(); checklock();

View File

@ -1562,8 +1562,9 @@ EX int movevalue(eMonster m, cell *c, int dir, flagtype flags) {
else if(passable_for(m, c2, c, P_DEADLY)) val = -1100; else if(passable_for(m, c2, c, P_DEADLY)) val = -1100;
else val = -1750; else val = -1750;
if(c->monst == moGolem ) if(c->monst == moGolem ) {
val -= c2->cpdist; val -= c2->pathdist;
}
else if(c->monst == moFriendlyGhost ) else if(c->monst == moFriendlyGhost )
val += c2->cpdist - 40; val += c2->cpdist - 40;
else if(c->monst == moMouse) { else if(c->monst == moMouse) {
@ -1612,9 +1613,9 @@ EX int movevalue(eMonster m, cell *c, int dir, flagtype flags) {
val -= 5; val -= 5;
} }
if(c->monst == moTameBomberbird) { if(c->monst == moTameBomberbird) {
int d = c2->cpdist; int d = c2->pathdist;
if(d == 1 && c->cpdist > 1) d = 5; if(d == 1 && c->pathdist > 1) d = 5;
if(d == 2 && c->cpdist > 2) d = 4; if(d == 2 && c->pathdist > 2) d = 4;
val -= d; val -= d;
} }
if(c->monst == moKnight && (eubinary || c2->master->alt)) { if(c->monst == moKnight && (eubinary || c2->master->alt)) {
@ -1629,11 +1630,11 @@ EX int movevalue(eMonster m, cell *c, int dir, flagtype flags) {
EX void movegolems(flagtype flags) { EX void movegolems(flagtype flags) {
if(items[itOrbEmpathy] && items[itOrbSlaying]) if(items[itOrbEmpathy] && items[itOrbSlaying])
flags |= AF_CRUSH; flags |= AF_CRUSH;
pathdata pd(moMouse);
int qg = 0; int qg = 0;
for(int i=0; i<isize(golems); i++) { for(int i=0; i<isize(golems); i++) {
cell *c = golems[i]; cell *c = golems[i];
eMonster m = c->monst; eMonster m = c->monst;
pathdata pd(m, false);
if(c->stuntime) continue; if(c->stuntime) continue;
if(m == moGolem || m == moKnight || m == moTameBomberbird || m == moPrincess || if(m == moGolem || m == moKnight || m == moTameBomberbird || m == moPrincess ||
m == moPrincessArmed || m == moMouse || m == moFriendlyGhost) { m == moPrincessArmed || m == moMouse || m == moFriendlyGhost) {