From e4c3716387f6398224d1791ea0d442f7aedbf605 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Tue, 21 Jun 2016 21:37:19 +1000 Subject: [PATCH] Tidy up code around modification of player stats by god piety. --- god.c | 12 +++++++ god.h | 1 + io.c | 25 +++++++++++++- lf.c | 104 ++++++++++++++++++++++++++++++++++++---------------------- lf.h | 1 + 5 files changed, 102 insertions(+), 41 deletions(-) diff --git a/god.c b/god.c index b51c0de..243a0d6 100644 --- a/god.c +++ b/god.c @@ -36,6 +36,7 @@ extern condset_t ccwalkable; lifeform_t *godlf[MAXGODS]; int ngodlfs = 0; + void angergod(enum RACE rid, int amt, enum GODANGERREASON why) { lifeform_t *god; int piety; @@ -795,6 +796,17 @@ lifeform_t *findgod(enum RACE rid) { return lf; } +char *getgodname(enum RACE rid, char *buf) { + lifeform_t *god; + god = findgod(rid); + if (god) { + sprintf(buf, "%s", god->race->name); + } else { + sprintf(buf, "(unknowngod)"); + } + return buf; +} + enum RACE getopposinggod(enum RACE rid) { switch (rid) { //case R_GODPURITY: return R_GODCHAOS; diff --git a/god.h b/god.h index 70b112f..a4133a7 100644 --- a/god.h +++ b/god.h @@ -6,6 +6,7 @@ void askforworship(enum RACE rid); void checkgodbonus(enum RACE rid, enum PIETYLEV newlev, enum PIETYLEV oldlev); void dooffer(void); lifeform_t *findgod(enum RACE rid); +char *getgodname(enum RACE rid, char *buf); enum RACE getopposinggod(enum RACE rid); enum OBTYPE getopposinggodstone(enum RACE rid); int getpiety(enum RACE rid); diff --git a/io.c b/io.c index 49affa5..cb29100 100644 --- a/io.c +++ b/io.c @@ -13745,8 +13745,9 @@ void showlfstats(lifeform_t *lf, int showall) { y += headinglines; count = 0; - // gods angry? if (isplayer(lf)) { + //enum ATTRIB a; + // gods angry? if (godprayedto(R_GODLIFE)) { enum PIETYLEV plev; plev = getpietylev(R_GODLIFE, NULL, NULL); @@ -13768,6 +13769,28 @@ void showlfstats(lifeform_t *lf, int showall) { effectline(&stopnow, &count, offset, &nextoffset, headinglines, mainwin, &y, &x, 0, "The Goddess of Nature has cursed you with a rotting touch.", you(lf)); } + + // stats being modified by gods? + /* + for (a = 0; a < MAXATTS; a++) { + enum RACE godid = R_NONE; + int mod; + mod = getattrgodmod(a, &godid); + if (mod) { + char godname[BUFLEN]; + char attrname[BUFLEN]; + getgodname(godid, godname); + sprintf(attrname, getattrname(a)); + capitalise(attrname); + + effectline(&stopnow, &count, offset, &nextoffset, + headinglines, mainwin, &y, &x, 0, + "%s is %s your %s by %s%d.", + godname, (mod > 0) ? "boosting" : "lowering", attrname, + (mod > 0) ? "+" : "", mod ); + } + } + */ } // ready to gain a level? if (lfhasflag(lf, F_STATGAINREADY)) { diff --git a/lf.c b/lf.c index e1a372c..e7d15fd 100644 --- a/lf.c +++ b/lf.c @@ -8053,46 +8053,7 @@ int real_getattr(lifeform_t *lf, enum ATTRIB attr, int ignoreattrset) { } if ((gamemode == GM_GAMESTARTED) && isplayer(lf)) { - // worshipping yumi increases wisdom based on piety - if ((attr == A_WIS) && godprayedto(R_GODMERCY)) { - enum PIETYLEV plev; - plev = getpietylev(R_GODMERCY, NULL, NULL); - switch (plev) { - case PL_ENRAGED: val -= 25; break; - case PL_FURIOUS: val -= 10; break; - case PL_ANGRY: val -= 5; break; - case PL_TOLERATED: break; - case PL_INDIFFERENT: val += 10; break; - case PL_PLEASED: val += 20 ; break; - case PL_DELIGHTED: val += 35 ; break; - case PL_ECSTATIC: val += 50 ; break; - default: break; - } - } else if ((attr == A_CON) && godprayedto(R_GODLIFE)) { - enum PIETYLEV plev; - plev = getpietylev(R_GODLIFE, NULL, NULL); - switch (plev) { - case PL_INDIFFERENT: val += 5; break; - case PL_PLEASED: val += 10 ; break; - case PL_DELIGHTED: val += 15 ; break; - case PL_ECSTATIC: val += 20 ; break; - default: break; - } - } else if ((attr == A_IQ) && godprayedto(R_GODMAGIC)) { - enum PIETYLEV plev; - plev = getpietylev(R_GODMAGIC, NULL, NULL); - switch (plev) { - case PL_ENRAGED: val -= 20; break; - case PL_FURIOUS: val -= 10; break; - case PL_ANGRY: val -= 5; break; - case PL_TOLERATED: break; - case PL_INDIFFERENT: val += 10; break; - case PL_PLEASED: val += 20 ; break; - case PL_DELIGHTED: val += 30 ; break; - case PL_ECSTATIC: val += 50 ; break; - default: break; - } - } + val += getattrgodmod(attr, NULL); } if (val < 0) val = 0; @@ -8100,6 +8061,69 @@ int real_getattr(lifeform_t *lf, enum ATTRIB attr, int ignoreattrset) { return val; } +// returns how much the given attrib is being modified by god piety. +// if provided, populates 'retgod' with the id of the god modifying it (or R_NONE). +int getattrgodmod(enum ATTRIB attr, enum RACE *retgodid) { + int mod = 0; + enum RACE whichgod = R_NONE; + if ((attr == A_WIS) && godprayedto(R_GODMERCY)) { + // worshipping yumi increases wisdom based on piety + enum PIETYLEV plev; + plev = getpietylev(R_GODMERCY, NULL, NULL); + switch (plev) { + case PL_ENRAGED: mod -= 25; break; + case PL_FURIOUS: mod -= 10; break; + case PL_ANGRY: mod -= 5; break; + case PL_TOLERATED: break; + case PL_INDIFFERENT: mod += 10; break; + case PL_PLEASED: mod += 20 ; break; + case PL_DELIGHTED: mod += 35 ; break; + case PL_ECSTATIC: mod += 50 ; break; + default: break; + } + if (mod != 0) { + whichgod = R_GODMERCY; + } + } else if ((attr == A_CON) && godprayedto(R_GODLIFE)) { + enum PIETYLEV plev; + plev = getpietylev(R_GODLIFE, NULL, NULL); + switch (plev) { + case PL_INDIFFERENT: mod += 5; break; + case PL_PLEASED: mod += 10 ; break; + case PL_DELIGHTED: mod += 15 ; break; + case PL_ECSTATIC: mod += 20 ; break; + default: break; + } + if (mod != 0) { + whichgod = R_GODLIFE; + } + } else if ((attr == A_IQ) && godprayedto(R_GODMAGIC)) { + enum PIETYLEV plev; + plev = getpietylev(R_GODMAGIC, NULL, NULL); + switch (plev) { + case PL_ENRAGED: mod -= 20; break; + case PL_FURIOUS: mod -= 10; break; + case PL_ANGRY: mod -= 5; break; + case PL_TOLERATED: break; + case PL_INDIFFERENT: mod += 10; break; + case PL_PLEASED: mod += 20 ; break; + case PL_DELIGHTED: mod += 30 ; break; + case PL_ECSTATIC: mod += 50 ; break; + default: break; + } + if (mod != 0) { + whichgod = R_GODMAGIC; + } + } + + if (retgodid) { + *retgodid = whichgod; + } + + return mod; +} + + // returns average damage per turn, modified by accuracy int getavgdam(lifeform_t *lf, int forxp) { obpile_t *op; diff --git a/lf.h b/lf.h index d756da4..cf35a59 100644 --- a/lf.h +++ b/lf.h @@ -174,6 +174,7 @@ int getattpoints(lifeform_t *lf); int getattr(lifeform_t *lf, enum ATTRIB attr); enum ATTRBRACKET getattrbracket(int attrval, enum ATTRIB whichatt, /*@null@*/char *buf); int real_getattr(lifeform_t *lf, enum ATTRIB attr, int ignoreattrset); +int getattrgodmod(enum ATTRIB attr, enum RACE *retgodid); int getavgdam(lifeform_t *lf, int forxp); enum CASTTYPE getcasttype(lifeform_t *lf, enum OBTYPE sid); int getdistspotmod(lifeform_t *lf, cell_t *c);