If you can meditate, don't prevent resting while caffienated.

Clarify args and description of gotosleep() vs. fallasleep()
This commit is contained in:
Rob Pearce 2016-07-07 12:13:08 +10:00
parent 43c20fbbaf
commit d5254e25aa
5 changed files with 52 additions and 44 deletions

11
ai.c
View File

@ -1560,13 +1560,7 @@ int ai_healing(lifeform_t *lf) {
if (ispeaceful(lf) && !isundead(lf)) {
int sleepval = 18;
if (modcounter(lf->flags, 1) >= sleepval) {
// we say that this ISNT on purpose, because otherwise
// we'll wake up as soon as we're healed. in this case
// we actually want to sleep forever (or until woken).
if (!gotosleep(lf, B_FALSE)) {
// force this since when not on purpose, gotosleep wont
// take time.
taketime(lf, getactspeed(lf));
if (!gotosleep(lf, B_NOWAKEWHENHEALED)) {
return B_TRUE; // success
}
}
@ -1605,8 +1599,7 @@ int ai_healing(lifeform_t *lf) {
} else {
// if it's "night time" for us, sleep forever.
// otehrwise just sleep until we're healed
if (!gotosleep(lf, issleepingtimefor(lf) ? B_TRUE : B_FALSE)) {
taketime(lf, getactspeed(lf)); // to make sure our turn ends
if (!gotosleep(lf, issleepingtimefor(lf) ? B_WAKEWHENHEALED : B_NOWAKEWHENHEALED)) {
return B_TRUE; // success
}
}

3
defs.h
View File

@ -114,6 +114,9 @@
#define B_RETAINATTR (-1)
#define B_MODATTR (0)
#define B_WAKEWHENHEALED (-1)
#define B_NOWAKEWHENHEALED (0)
// askobject args
#define B_DONTINCLUDENOTHING (0)

1
io.c
View File

@ -8605,7 +8605,6 @@ void makespellchoicelist(prompt_t *pr, lifeform_t *lf, char *ques, char *ques2,
}
}
if (includeit) {
int cost;
int found = B_FALSE;

79
lf.c
View File

@ -6469,7 +6469,8 @@ int fall(lifeform_t *lf, lifeform_t *fromlf, int announce) {
}
// if you are going to sleep on purpose, use 'gotosleep'.
// this function is for when it is forced upon you by a spell, etc.
//
// this function is for when sleep/unconsciousness is forced upon you by a spell, etc.
int fallasleep(lifeform_t *lf, enum SLEEPTYPE how, int howlong) {
flag_t *f;
f = lfhasflag(lf, F_ASLEEP);
@ -6481,15 +6482,17 @@ int fallasleep(lifeform_t *lf, enum SLEEPTYPE how, int howlong) {
}
}
if ((how == ST_ASLEEP) && lfhasflag(lf, F_CAFFEINATED)) {
if (isplayer(lf)) {
msg("You feel momentarily tired.");
} else if (cansee(player, lf)) {
char lfname[BUFLEN];
getlfname(lf, lfname);
msg("%s looks momentarily tired.", lfname);
}
return B_TRUE;
if (how == ST_ASLEEP) {
if (lfhasflag(lf, F_CAFFEINATED) || isundead(lf)) {
if (isplayer(lf)) {
msg("You feel momentarily tired.");
} else if (cansee(player, lf)) {
char lfname[BUFLEN];
getlfname(lf, lfname);
msg("%s looks momentarily tired.", lfname);
}
return B_TRUE;
}
}
loseconcentration(lf);
interrupt(lf);
@ -13514,37 +13517,47 @@ void givestartskills(lifeform_t *lf, flagpile_t *fp) {
}
int gotosleep(lifeform_t *lf, int onpurpose) {
// go to sleep/rest/start meditating on purpose. If from a spell effect etc, use fallasleep().
int gotosleep(lifeform_t *lf, int wakewhenhealed) {
char lightid[BUFLEN];
strcpy(lightid, "");
if (lfhasflag(lf, F_CAFFEINATED)) {
if (isplayer(lf)) {
msg("Your caffeine high prevents you from sleeping.");
if (!lfhasflag(lf, F_MEDITATES)) {
if (isundead(lf)) {
if (isplayer(lf)) {
msg("The undead do not require sleep!");
}
return B_TRUE;
}
if (lfhasflag(lf, F_CAFFEINATED)) {
if (isplayer(lf)) {
msg("Your caffeine high prevents you from sleeping.");
}
return B_TRUE;
}
return B_TRUE;
}
if (onpurpose) {
taketime(lf, getactspeed(lf));
if (getattrbracket(getattr(lf, A_WIS), A_WIS, NULL) >= AT_GTAVERAGE) {
object_t *o;
// turn off light sources first
for (o = lf->pack->first ; o ; o = o->next) {
if (hasflag(o->flags, F_LIGHTSOURCE) && hasflag(o->flags, F_ACTIVATED)) {
if (!strlen(lightid)) {
// first one.
if (isplayer(lf)) {
char ch;
ch = askchar("Turn off your light sources before resting?", "yn","y", B_TRUE, B_FALSE);
if (ch != 'y') break;
}
sprintf(lightid, "%ld", o->id);
taketime(lf, getactspeed(lf));
if (getattrbracket(getattr(lf, A_WIS), A_WIS, NULL) >= AT_GTAVERAGE) {
object_t *o;
// turn off light sources first
for (o = lf->pack->first ; o ; o = o->next) {
if (hasflag(o->flags, F_LIGHTSOURCE) && hasflag(o->flags, F_ACTIVATED)) {
if (!strlen(lightid)) {
// first one.
if (isplayer(lf)) {
char ch;
ch = askchar("Turn off your light sources before resting?", "yn","y", B_TRUE, B_FALSE);
if (ch != 'y') break;
}
turnoff(lf, o);
sprintf(lightid, "%ld", o->id);
}
turnoff(lf, o);
}
}
}
addflag(lf->flags, F_ASLEEP, B_TRUE, lfhasflag(lf, F_MEDITATES) ? ST_MEDITATING : ST_ASLEEP, onpurpose ? B_TRUE : NA, lightid);
addflag(lf->flags, F_ASLEEP, B_TRUE, lfhasflag(lf, F_MEDITATES) ? ST_MEDITATING : ST_ASLEEP, wakewhenhealed ? B_TRUE : NA, lightid);
return B_FALSE;
}
@ -20955,7 +20968,7 @@ int startresting(lifeform_t *lf, int willtrain) {
addflag(lf->flags, F_TRAINING, 0, traincounter, NA, NULL);
}
} else {
if (gotosleep(lf, B_TRUE)) {
if (gotosleep(lf, B_WAKEWHENHEALED)) {
// failed
return B_TRUE;
}

2
lf.h
View File

@ -331,7 +331,7 @@ flag_t *giveskilllev(lifeform_t *lf, enum SKILL id, enum SKILLLEVEL slev);
void givestartobs(lifeform_t *lf, object_t *targob, flagpile_t *fp);
void givestartskills(lifeform_t *lf, flagpile_t *fp);
map_t *gotolev(lifeform_t *lf, int depth, object_t *fromstairs);
int gotosleep(lifeform_t *lf, int onpurpose);
int gotosleep(lifeform_t *lf, int wakewhenhealed);
void growhydrahead(lifeform_t *lf, int announce);
void losehydrahead(lifeform_t *lf);
flag_t *hasbleedinginjury(lifeform_t *lf, enum BODYPART bp);