Split monster goal coordinate out of mstrategy field

Instead of packing a coordinate into unsigned long, store the goal in
a coord struct, making the code a bit cleaner.  Monster struct is
of course slightly bigger, but that should not really matter.
No change in monster behaviour.

Breaks saves and bones.
This commit is contained in:
Pasi Kallinen
2025-02-16 10:35:17 +02:00
parent 8672807a5e
commit 3cb7819c81
4 changed files with 21 additions and 18 deletions

View File

@@ -180,12 +180,10 @@ struct monst {
#define STRAT_PLAYER 0x01000000L #define STRAT_PLAYER 0x01000000L
#define STRAT_NONE 0x00000000L #define STRAT_NONE 0x00000000L
#define STRAT_STRATMASK 0x0f000000L #define STRAT_STRATMASK 0x0f000000L
#define STRAT_XMASK 0x00ff0000L /* mstrategy unused 0x00ffff00L */
#define STRAT_YMASK 0x0000ff00L
#define STRAT_GOAL 0x000000ffL #define STRAT_GOAL 0x000000ffL
#define STRAT_GOALX(s) ((coordxy) ((s & STRAT_XMASK) >> 16))
#define STRAT_GOALY(s) ((coordxy) ((s & STRAT_YMASK) >> 8))
coord mgoal; /* monster strategy, target location */
long mtrapseen; /* bitmap of traps we've been trapped in */ long mtrapseen; /* bitmap of traps we've been trapped in */
long mlstmv; /* for catching up with lost time */ long mlstmv; /* for catching up with lost time */
long mstate; /* debugging info on monsters stored here */ long mstate; /* debugging info on monsters stored here */

View File

@@ -17,7 +17,7 @@
* Incrementing EDITLEVEL can be used to force invalidation of old bones * Incrementing EDITLEVEL can be used to force invalidation of old bones
* and save files. * and save files.
*/ */
#define EDITLEVEL 119 #define EDITLEVEL 120
/* /*
* Development status possibilities. * Development status possibilities.

View File

@@ -1750,8 +1750,8 @@ m_move(struct monst *mtmp, int after)
if (is_covetous(ptr)) { /* [should this include if (is_covetous(ptr)) { /* [should this include
* '&& mtmp->mstrategy != STRAT_NONE'?] */ * '&& mtmp->mstrategy != STRAT_NONE'?] */
int covetousattack; int covetousattack;
coordxy tx = STRAT_GOALX(mtmp->mstrategy), coordxy tx = mtmp->mgoal.x,
ty = STRAT_GOALY(mtmp->mstrategy); ty = mtmp->mgoal.y;
struct monst *intruder = isok(tx, ty) ? m_at(tx, ty) : NULL; struct monst *intruder = isok(tx, ty) ? m_at(tx, ty) : NULL;
/* /*
* if there's a monster on the object or in possession of it, * if there's a monster on the object or in possession of it,

View File

@@ -135,9 +135,6 @@ mon_has_special(struct monst *mtmp)
* The strategy section decides *what* the monster is going * The strategy section decides *what* the monster is going
* to attempt, the tactics section implements the decision. * to attempt, the tactics section implements the decision.
*/ */
#define STRAT(w, x, y, typ) \
((unsigned long) (w) | ((unsigned long) (x) << 16) \
| ((unsigned long) (y) << 8) | (unsigned long) (typ))
#define M_Wants(mask) (mtmp->data->mflags3 & (mask)) #define M_Wants(mask) (mtmp->data->mflags3 & (mask))
@@ -247,17 +244,25 @@ target_on(int mask, struct monst *mtmp)
otyp = which_arti(mask); otyp = which_arti(mask);
if (!mon_has_arti(mtmp, otyp)) { if (!mon_has_arti(mtmp, otyp)) {
if (you_have(mask)) if (you_have(mask)) {
return STRAT(STRAT_PLAYER, u.ux, u.uy, mask); mtmp->mgoal.x = u.ux;
else if ((otmp = on_ground(otyp))) mtmp->mgoal.y = u.uy;
return STRAT(STRAT_GROUND, otmp->ox, otmp->oy, mask); return (STRAT_PLAYER | mask);
else if ((mtmp2 = other_mon_has_arti(mtmp, otyp)) != 0 } else if ((otmp = on_ground(otyp))) {
mtmp->mgoal.x = otmp->ox;
mtmp->mgoal.y = otmp->oy;
return (STRAT_GROUND | mask);
} else if ((mtmp2 = other_mon_has_arti(mtmp, otyp)) != 0
/* when seeking the Amulet, avoid targeting the Wizard /* when seeking the Amulet, avoid targeting the Wizard
or temple priests (to protect Moloch's high priest) */ or temple priests (to protect Moloch's high priest) */
&& (otyp != AMULET_OF_YENDOR && (otyp != AMULET_OF_YENDOR
|| (!mtmp2->iswiz && !inhistemple(mtmp2)))) || (!mtmp2->iswiz && !inhistemple(mtmp2)))) {
return STRAT(STRAT_MONSTR, mtmp2->mx, mtmp2->my, mask); mtmp->mgoal.x = mtmp2->mx;
mtmp->mgoal.y = mtmp2->my;
return (STRAT_MONSTR | mask);
}
} }
mtmp->mgoal.x = mtmp->mgoal.y = 0;
return (unsigned long) STRAT_NONE; return (unsigned long) STRAT_NONE;
} }
@@ -410,7 +415,7 @@ tactics(struct monst *mtmp)
default: /* kill, maim, pillage! */ default: /* kill, maim, pillage! */
{ {
long where = (strat & STRAT_STRATMASK); long where = (strat & STRAT_STRATMASK);
coordxy tx = STRAT_GOALX(strat), ty = STRAT_GOALY(strat); coordxy tx = mtmp->mgoal.x, ty = mtmp->mgoal.y;
int targ = (int) (strat & STRAT_GOAL); int targ = (int) (strat & STRAT_GOAL);
struct obj *otmp; struct obj *otmp;