From 0bc557f2f54168a96bba2c7ef5bf36f2a67e03ad Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 6 Jun 2016 20:42:45 +1000 Subject: [PATCH] If you run out of stamina while flying, immediately stop flying. Don't require stamina to stop flying. --- defs.h | 2 +- lf.c | 24 ++++++++++++++++++------ lf.h | 2 +- spell.c | 16 ++++++---------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/defs.h b/defs.h index 4a9cd91..afa7986 100644 --- a/defs.h +++ b/defs.h @@ -3893,7 +3893,7 @@ enum FLAG { F_HOSTILE, // lf will attack the player if in sight F_FRIENDLY, // lf will attack all non-players if in sight F_FATALFOOD, // if lf eats food with id = v0, they die. - F_NATURALFLIGHT, // lf can fly natural using wings or similar + F_NATURALFLIGHT, // lf can fly naturally using wings or similar F_WANTS, // lf will try to pick up object type val0. // if val1 = B_COVETS, will even abandon attacks // for it! diff --git a/lf.c b/lf.c index 46c4820..10578a2 100644 --- a/lf.c +++ b/lf.c @@ -849,8 +849,13 @@ int cancast(lifeform_t *lf, enum OBTYPE oid, int *mpcost) { // do we have enough stamina to do this? stamcost = getstamcost(lf, oid); if (stamcost && (getstamina(lf) < stamcost) && !lfhasflag(lf, F_NOSTAM)) { - reason = E_NOSTAM; - return B_FALSE; + // exception: you can always stop flying + if ((oid == OT_A_FLY) && isflyingwithwings(lf)) { + // ok + } else { + reason = E_NOSTAM; + return B_FALSE; + } } return castable; @@ -14969,16 +14974,16 @@ flag_t *isfleeingfrom(lifeform_t *lf, lifeform_t *runfrom) { return lfhasflagval(lf, F_FLEEFROM, runfrom->id, NA, NA, NULL); } -int isflyingwithwings(lifeform_t *lf) { +flag_t *isflyingwithwings(lifeform_t *lf) { flag_t *retflag[MAXCANDIDATES]; int nretflags,i; getflags(lf->flags, retflag, &nretflags, F_FLYING, F_NONE); for (i = 0; i < nretflags; i++) { if (retflag[i]->lifetime == FROMABIL) { - return B_TRUE; + return retflag[i]; } } - return B_FALSE; + return NULL; } int isfreebp(lifeform_t *lf, enum BODYPART bp, object_t *whatfor) { @@ -19053,7 +19058,12 @@ void modstamina(lifeform_t *lf, float howmuch) { } if (getstamina(lf) == 0) { + flag_t *f; stopsprinting(lf); + f = isflyingwithwings(lf); + if (f) { + killflag(f); + } } } @@ -26081,7 +26091,6 @@ int unweild(lifeform_t *lf, object_t *o) { int useability(lifeform_t *lf, enum OBTYPE aid, lifeform_t *who, cell_t *where) { int rv; flag_t *cwflag; - float stamcost = 0; if (!cancast(lf, aid, NULL)) { if (isplayer(lf)) { // announce @@ -26109,6 +26118,8 @@ int useability(lifeform_t *lf, enum OBTYPE aid, lifeform_t *who, cell_t *where) return B_TRUE; } + /* Duplicate check. + stamcost = getstamcost(lf, aid); if (stamcost) { if (getstamina(lf) < stamcost) { @@ -26118,6 +26129,7 @@ int useability(lifeform_t *lf, enum OBTYPE aid, lifeform_t *who, cell_t *where) return B_TRUE; } } + */ if (aid != OT_A_FULLSHIELD) { killflagsofid(lf->flags, F_FULLSHIELD); diff --git a/lf.h b/lf.h index 54a8267..d812427 100644 --- a/lf.h +++ b/lf.h @@ -379,7 +379,7 @@ int isdeaf(lifeform_t *lf); object_t *isdualweilding(lifeform_t *lf); flag_t *isfleeing(lifeform_t *lf); flag_t *isfleeingfrom(lifeform_t *lf, lifeform_t *runfrom); -int isflyingwithwings(lifeform_t *lf); +flag_t *isflyingwithwings(lifeform_t *lf); int isfreebp(lifeform_t *lf, enum BODYPART bp, object_t *whatfor); int isfriendly(lifeform_t *lf); int isfullyhealed(lifeform_t *lf); diff --git a/spell.c b/spell.c index 4362c48..dcb626c 100644 --- a/spell.c +++ b/spell.c @@ -1370,18 +1370,14 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef target->hp = 0; killallobs(target->pack); } else if (abilid == OT_A_FLY) { - flag_t *retflag[MAXCANDIDATES],*f; - int nretflags,i; + flag_t *f; // already flying? stop. - getflags(user->flags, retflag, &nretflags, F_FLYING, F_NONE); - for (i = 0; i < nretflags; i++) { - f = retflag[i]; - if (f->lifetime == FROMABIL) { - killflag(f); - taketime(user, getactspeed(user)); - return B_FALSE; - } + f = isflyingwithwings(user); + if (f) { + killflag(f); + taketime(user, getactspeed(user)); + return B_FALSE; } if (isimmobile(user)) {