Tidy up code around modification of player stats by god piety.

This commit is contained in:
Rob Pearce 2016-06-21 21:37:19 +10:00
parent bbc539c449
commit e4c3716387
5 changed files with 102 additions and 41 deletions

12
god.c
View File

@ -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;

1
god.h
View File

@ -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);

25
io.c
View File

@ -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)) {

104
lf.c
View File

@ -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;

1
lf.h
View File

@ -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);