github PR #1185 - refactor give_u_to_m_resistances

Pull request from entrez:  redo the code that confers intrinsics
acquired by dying hero to the monster it becomes in bones.

Closes #1185
This commit is contained in:
PatR
2024-05-31 09:52:50 -07:00
5 changed files with 19 additions and 20 deletions
+3
View File
@@ -67,6 +67,9 @@ enum ms_sounds {
#define MR_POISON 0x20 /* resists poison */ #define MR_POISON 0x20 /* resists poison */
#define MR_ACID 0x40 /* resists acid */ #define MR_ACID 0x40 /* resists acid */
#define MR_STONE 0x80 /* resists petrification */ #define MR_STONE 0x80 /* resists petrification */
/* NB: the above resistances correspond to the first 8 hero properties in
prop_types (FIRE_RES through STONE_RES), which can be converted to their
MR_foo equivalents with the macro res_to_mr() defined in prop.h */
/* other resistances: magic, sickness */ /* other resistances: magic, sickness */
/* other conveyances: teleport, teleport control, telepathy */ /* other conveyances: teleport, teleport control, telepathy */
+4 -1
View File
@@ -20,7 +20,10 @@ enum prop_types {
POISON_RES = 6, POISON_RES = 6,
ACID_RES = 7, ACID_RES = 7,
STONE_RES = 8, STONE_RES = 8,
/* note: for the first eight properties, MR_xxx == (1 << (xxx_RES - 1)) */ /* note: the first eight properties above are equivalent to MR_xxx bits
* MR_FIRE through MR_STONE, and can be directly converted to them: */
#define res_to_mr(r) \
((FIRE_RES <= (r) && (r) <= STONE_RES) ? (uchar) (1 << ((r) - 1)) : 0x00)
DRAIN_RES = 9, DRAIN_RES = 9,
SICK_RES = 10, SICK_RES = 10,
INVULNERABLE = 11, INVULNERABLE = 11,
+1 -6
View File
@@ -1682,33 +1682,28 @@ mon_give_prop(struct monst *mtmp, int prop)
control or whatever, ignore it. */ control or whatever, ignore it. */
switch (prop) { switch (prop) {
case FIRE_RES: case FIRE_RES:
intrinsic = MR_FIRE;
msg = "%s shivers slightly."; msg = "%s shivers slightly.";
break; break;
case COLD_RES: case COLD_RES:
intrinsic = MR_COLD;
msg = "%s looks quite warm."; msg = "%s looks quite warm.";
break; break;
case SLEEP_RES: case SLEEP_RES:
intrinsic = MR_SLEEP;
msg = "%s looks wide awake."; msg = "%s looks wide awake.";
break; break;
case DISINT_RES: case DISINT_RES:
intrinsic = MR_DISINT;
msg = "%s looks very firm."; msg = "%s looks very firm.";
break; break;
case SHOCK_RES: case SHOCK_RES:
intrinsic = MR_ELEC;
msg = "%s crackles with static electricity."; msg = "%s crackles with static electricity.";
break; break;
case POISON_RES: case POISON_RES:
intrinsic = MR_POISON;
msg = "%s looks healthy."; msg = "%s looks healthy.";
break; break;
default: default:
return; /* can't give it */ return; /* can't give it */
break; break;
} }
intrinsic = res_to_mr(prop);
/* Don't give message if it already had this property intrinsically, but /* Don't give message if it already had this property intrinsically, but
still do grant the intrinsic if it only had it from mresists. still do grant the intrinsic if it only had it from mresists.
+9 -6
View File
@@ -1498,13 +1498,16 @@ monstunseesu(unsigned long seenres)
void void
give_u_to_m_resistances(struct monst *mtmp) give_u_to_m_resistances(struct monst *mtmp)
{ {
const int u_intrins[] = { FIRE_RES, COLD_RES, SLEEP_RES, DISINT_RES, SHOCK_RES, POISON_RES, ACID_RES, STONE_RES }; int intr;
const int m_intrins[] = { MR_FIRE, MR_COLD, MR_SLEEP, MR_DISINT, MR_ELEC, MR_POISON, MR_ACID, MR_STONE };
int i;
for (i = 0; i < SIZE(u_intrins); i++) /* convert the hero's current set of intrinsics to their monster
if (u.uprops[u_intrins[i]].intrinsic & INTRINSIC) equivalents -- FIRE_RES to MR_FIRE, COLD_RES to MR_COLD, etc -- and
mtmp->mintrinsics |= m_intrins[i]; add each to the mintrinsics field for the given monster */
for (intr = FIRE_RES; intr <= STONE_RES; intr++) {
if ((u.uprops[intr].intrinsic & INTRINSIC) != 0L) {
mtmp->mintrinsics |= (unsigned short) res_to_mr(intr);
}
}
} }
/* Can monster resist conflict caused by hero? /* Can monster resist conflict caused by hero?
+2 -7
View File
@@ -550,12 +550,7 @@ update_mon_extrinsics(
case JUMPING: case JUMPING:
break; break;
default: default:
/* 1 through 8 correspond to MR_xxx mask values */ mon->mextrinsics |= (unsigned short) res_to_mr(which);
if (which >= 1 && which <= 8) {
/* FIRE,COLD,SLEEP,DISINT,SHOCK,POISON,ACID,STONE */
mask = (uchar) (1 << (which - 1));
mon->mextrinsics |= (unsigned short) mask;
}
break; break;
} }
} else { /* off */ } else { /* off */
@@ -592,7 +587,7 @@ update_mon_extrinsics(
* only one pass but a worn alchemy smock will be an * only one pass but a worn alchemy smock will be an
* alternate source for either of those two resistances. * alternate source for either of those two resistances.
*/ */
mask = (uchar) (1 << (which - 1)); mask = res_to_mr(which);
for (otmp = mon->minvent; otmp; otmp = otmp->nobj) { for (otmp = mon->minvent; otmp; otmp = otmp->nobj) {
if (otmp == obj || !otmp->owornmask) if (otmp == obj || !otmp->owornmask)
continue; continue;