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_NONE 0x00000000L
#define STRAT_STRATMASK 0x0f000000L
#define STRAT_XMASK 0x00ff0000L
#define STRAT_YMASK 0x0000ff00L
/* mstrategy unused 0x00ffff00L */
#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 mlstmv; /* for catching up with lost time */
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
* and save files.
*/
#define EDITLEVEL 119
#define EDITLEVEL 120
/*
* Development status possibilities.

View File

@@ -1750,8 +1750,8 @@ m_move(struct monst *mtmp, int after)
if (is_covetous(ptr)) { /* [should this include
* '&& mtmp->mstrategy != STRAT_NONE'?] */
int covetousattack;
coordxy tx = STRAT_GOALX(mtmp->mstrategy),
ty = STRAT_GOALY(mtmp->mstrategy);
coordxy tx = mtmp->mgoal.x,
ty = mtmp->mgoal.y;
struct monst *intruder = isok(tx, ty) ? m_at(tx, ty) : NULL;
/*
* 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
* 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))
@@ -247,17 +244,25 @@ target_on(int mask, struct monst *mtmp)
otyp = which_arti(mask);
if (!mon_has_arti(mtmp, otyp)) {
if (you_have(mask))
return STRAT(STRAT_PLAYER, u.ux, u.uy, mask);
else if ((otmp = on_ground(otyp)))
return STRAT(STRAT_GROUND, otmp->ox, otmp->oy, mask);
else if ((mtmp2 = other_mon_has_arti(mtmp, otyp)) != 0
if (you_have(mask)) {
mtmp->mgoal.x = u.ux;
mtmp->mgoal.y = u.uy;
return (STRAT_PLAYER | mask);
} 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
or temple priests (to protect Moloch's high priest) */
&& (otyp != AMULET_OF_YENDOR
|| (!mtmp2->iswiz && !inhistemple(mtmp2))))
return STRAT(STRAT_MONSTR, mtmp2->mx, mtmp2->my, mask);
|| (!mtmp2->iswiz && !inhistemple(mtmp2)))) {
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;
}
@@ -410,7 +415,7 @@ tactics(struct monst *mtmp)
default: /* kill, maim, pillage! */
{
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);
struct obj *otmp;