From a71866d7d9649263f3b49594745f5c089ca37415 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Wed, 20 Dec 2023 12:04:55 -0500 Subject: [PATCH] Refactor (very slightly) give_u_to_m_resistances I think that using two arrays in tandem like give_u_to_m_resistances originally did is frequently considered a bad idea, because one can easily be added to or subtracted from without modifying the other -- that could obviously cause problems. Combining the arrays like this avoids that potential problem. --- src/mondata.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/mondata.c b/src/mondata.c index 2a0333c5d..bcc6cc6ec 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -1498,13 +1498,22 @@ monstunseesu(unsigned long seenres) void 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 }; - const int m_intrins[] = { MR_FIRE, MR_COLD, MR_SLEEP, MR_DISINT, MR_ELEC, MR_POISON, MR_ACID, MR_STONE }; + const struct { + int u; + unsigned short m; + } u_to_m_res[] = { + { FIRE_RES, MR_FIRE }, { COLD_RES, MR_COLD }, + { SLEEP_RES, MR_SLEEP }, { DISINT_RES, MR_DISINT }, + { SHOCK_RES, MR_ELEC }, { POISON_RES, MR_POISON }, + { ACID_RES, MR_ACID }, { STONE_RES, MR_STONE }, + }; int i; - for (i = 0; i < SIZE(u_intrins); i++) - if (u.uprops[u_intrins[i]].intrinsic & INTRINSIC) - mtmp->mintrinsics |= m_intrins[i]; + for (i = 0; i < SIZE(u_to_m_res); i++) { + if ((u.uprops[u_to_m_res[i].u].intrinsic & INTRINSIC) != 0L) { + mtmp->mintrinsics |= u_to_m_res[i].m; + } + } } /* Can monster resist conflict caused by hero?