Eliminate magic numbers from uchangealign()

This commit is contained in:
Michael Meyer
2023-11-30 00:55:23 -05:00
committed by PatR
parent cd04780907
commit f42250eb9d
4 changed files with 14 additions and 7 deletions

View File

@@ -60,4 +60,11 @@ typedef struct align { /* alignment & record */
#define Msa2amask(x) (((x) == 3) ? 4 : (x))
#define MSA_NONE 0 /* unaligned or multiple alignments */
/* alignment change reasons for uchangealign(attrib.c) */
enum uchangealign_reasons {
A_CG_CONVERT = 0, /* permanently converted */
A_CG_HELM_ON = 1, /* donned helm of opposite alignment */
A_CG_HELM_OFF = 2, /* doffed helm of opposite alignment */
};
#endif /* ALIGN_H */

View File

@@ -1237,7 +1237,7 @@ adjalign(int n)
/* change hero's alignment type, possibly losing use of artifacts */
void
uchangealign(int newalign,
int reason) /* 0==conversion, 1==helm-of-OA on, 2==helm-of-OA off */
int reason) /* A_CG_CONVERT, A_CG_HELM_ON, or A_CG_HELM_OFF */
{
aligntyp oldalign = u.ualign.type;
@@ -1245,7 +1245,7 @@ uchangealign(int newalign,
/* You/Your/pline message with call flush_screen(), triggering bot(),
so the actual data change needs to come before the message */
disp.botl = TRUE; /* status line needs updating */
if (reason == 0) {
if (reason == A_CG_CONVERT) {
/* conversion via altar */
livelog_printf(LL_ALIGNMENT, "permanently converted to %s",
aligns[1 - newalign].adj);
@@ -1258,7 +1258,7 @@ uchangealign(int newalign,
} else {
/* putting on or taking off a helm of opposite alignment */
u.ualign.type = (aligntyp) newalign;
if (reason == 1) {
if (reason == A_CG_HELM_ON) {
adjalign(-7); /* for abuse -- record will be cleared shortly */
Your("mind oscillates %s.", Hallucination ? "wildly" : "briefly");
make_confused(rn1(2, 3), FALSE);
@@ -1267,7 +1267,7 @@ uchangealign(int newalign,
/* don't livelog taking it back off */
livelog_printf(LL_ALIGNMENT, "used a helm to turn %s",
aligns[1 - newalign].adj);
} else if (reason == 2) {
} else if (reason == A_CG_HELM_OFF) {
Your("mind is %s.", Hallucination
? "much of a muchness"
: "back in sync with your body");

View File

@@ -440,7 +440,7 @@ Helmet_on(void)
uchangealign((u.ualign.type != A_NEUTRAL)
? -u.ualign.type
: (uarmh->o_id % 2) ? A_CHAOTIC : A_LAWFUL,
1);
A_CG_HELM_ON);
/* makeknown(HELM_OF_OPPOSITE_ALIGNMENT); -- below, after Tobjnam() */
/*FALLTHRU*/
case DUNCE_CAP:
@@ -521,7 +521,7 @@ Helmet_off(void)
/* changing alignment can toggle off active artifact
properties, including levitation; uarmh could get
dropped or destroyed here */
uchangealign(u.ualignbase[A_CURRENT], 2);
uchangealign(u.ualignbase[A_CURRENT], A_CG_HELM_OFF);
break;
default:
impossible(unknown_type, c_helmet, uarmh->otyp);

View File

@@ -1612,7 +1612,7 @@ offer_different_alignment_altar(
consume_offering(otmp);
pline("%s accepts your allegiance.", a_gname());
uchangealign(altaralign, 0);
uchangealign(altaralign, A_CG_CONVERT);
/* Beware, Conversion is costly */
change_luck(-3);
u.ublesscnt += 300;