diff --git a/defs.h b/defs.h index 9e0d7c8..3866910 100644 --- a/defs.h +++ b/defs.h @@ -266,6 +266,8 @@ // >= MAXFLAGS #define MAXCANDIDATES 2048 +#define LASTSHORTCUT 9 + #define MAXCHOICES 400 #define MAXDEPTH 25 // max dungeon depth #define MAXDIR_ORTH 4 diff --git a/io.c b/io.c index da18a61..7736482 100644 --- a/io.c +++ b/io.c @@ -13255,26 +13255,28 @@ void showlfstats(lifeform_t *lf, int showall) { getflags(lf->flags, retflag, &nretflags, F_NOBODYPART, F_NONE); for (i = 0; i < nretflags; i++) { bp = retflag[i]->val[0]; - if (bp == BP_RIGHTFINGER) { - if (!lfhasflagval(lf, F_NOBODYPART, BP_HANDS, NA, NA, NULL)) { + if (retflag[i]->lifetime != FROMINJURY) { + if (bp == BP_RIGHTFINGER) { + if (!lfhasflagval(lf, F_NOBODYPART, BP_HANDS, NA, NA, NULL)) { + missingbp[nmissingbp] = bp; + nmissingbp++; + } + } else if (bp == BP_LEFTFINGER) { + if (!lfhasflagval(lf, F_NOBODYPART, BP_HANDS, NA, NA, NULL) && + !lfhasflagval(lf, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL) + ) { + missingbp[nmissingbp] = bp; + nmissingbp++; + } + } else if (bp == BP_SECWEAPON) { + if (!lfhasflagval(lf, F_NOBODYPART, BP_HANDS, NA, NA, NULL)) { + missingbp[nmissingbp] = bp; + nmissingbp++; + } + } else { missingbp[nmissingbp] = bp; nmissingbp++; } - } else if (bp == BP_LEFTFINGER) { - if (!lfhasflagval(lf, F_NOBODYPART, BP_HANDS, NA, NA, NULL) && - !lfhasflagval(lf, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL) - ) { - missingbp[nmissingbp] = bp; - nmissingbp++; - } - } else if (bp == BP_SECWEAPON) { - if (!lfhasflagval(lf, F_NOBODYPART, BP_HANDS, NA, NA, NULL)) { - missingbp[nmissingbp] = bp; - nmissingbp++; - } - } else { - missingbp[nmissingbp] = bp; - nmissingbp++; } } diff --git a/lf.c b/lf.c index d459a32..a2ee84f 100644 --- a/lf.c +++ b/lf.c @@ -9401,16 +9401,34 @@ int getnaturalflightheight(lifeform_t *lf) { return 0; } +// returns a number from 1 - LASTSHORTCUT containing the first avilaable shortcut slot. +// +// if none available, return NA. +// int getnextshortcut(lifeform_t *lf) { flag_t *retflag[MAXCANDIDATES]; - int nretflags,i,min = 0; + int nretflags,i,slotnum = 0; + // get all currently assigned shortcuts getflags(lf->flags, retflag, &nretflags, F_SHORTCUT, F_NONE); - for (i = 0; i < nretflags; i++) { - if (retflag[i]->val[0] > min) { - min = retflag[i]->val[0]; + + // use 1=10 instead of 0=9, so that '0' is last. + for (slotnum = 1; slotnum <= (LASTSHORTCUT+1); slotnum++) { + int found = B_FALSE; + // technically this is faster than using hasflagval() + for (i = 0; i < nretflags; i++) { + if (retflag[i]->val[0] == slotnum) { + found = B_TRUE; + break; + } + } + if (!found) { + // this slot is available + if (slotnum == 10) slotnum = 0; + return slotnum; } } - return min + 1; + + return NA; } int getnightvisrange(lifeform_t *lf) { @@ -16758,18 +16776,36 @@ void autolearnspellsfrombook(lifeform_t *lf, object_t *book) { } } -void autoshortcut(lifeform_t *lf, enum OBTYPE spellid) { +// If spellid = OT_NONE, automatically assign slots for all job/race/skill abilities, +// starting at 'startslot' +// +// If spellid = , auto assign a shortcut just for that one. Use 'startslot' +// if given, otherwise pick the next available one. +// +void autoshortcut(lifeform_t *lf, enum OBTYPE spellid, int startslot) { flag_t *retflag[MAXCANDIDATES],*f; int nretflags,i; - int min = 1; + int min = 0; objecttype_t *ot = NULL; + + + if (startslot == NA) { + min = getnextshortcut(lf); + if (min == NA) return; + } else { + min = startslot; + } + if (min == 10) min = 0; + limit(&min, 0, LASTSHORTCUT); + getflags(lf->flags, retflag, &nretflags, F_CANCAST, F_CANWILL, F_NONE); - min = getnextshortcut(lf); - for (i = 0; (i < nretflags) && (min < 10); i++) { + for (i = 0; (i < nretflags) && (min <= LASTSHORTCUT); i++) { f = retflag[i]; ot = findot(f->val[0]); if (!ot) continue; + // already have a shortcut for this? + if (lfhasflagval(lf, F_SHORTCUT, NA, NA, NA, ot->name)) continue; if (spellid == OT_NONE) { // autoshortcut everything from your job/race @@ -16779,6 +16815,7 @@ void autoshortcut(lifeform_t *lf, enum OBTYPE spellid) { if (!lfhasflagval(lf, F_SHORTCUT, NA, NA, NA, ot->name)) { addflag(lf->flags, F_SHORTCUT, min, NA, NA, ot->name); min = getnextshortcut(lf); + if (min == NA) return; } } } else { diff --git a/lf.h b/lf.h index 530e0a0..54a8267 100644 --- a/lf.h +++ b/lf.h @@ -30,7 +30,7 @@ int askforinfo(lifeform_t *lf, int diffmod); char *assignnpcname(flagpile_t *fp); int attrincreasable(enum ATTRIB a); void autolearnspellsfrombook(lifeform_t *lf, object_t *book); -void autoshortcut(lifeform_t *lf, enum OBTYPE spellid); +void autoshortcut(lifeform_t *lf, enum OBTYPE spellid, int startslot); void autoskill(lifeform_t *lf); void autospells(lifeform_t *lf, int howmany); void autotarget(lifeform_t *lf); diff --git a/nexus.c b/nexus.c index b67392c..4347154 100644 --- a/nexus.c +++ b/nexus.c @@ -496,10 +496,13 @@ int main(int argc, char **argv) { } - // we always want 'cook' to be shortcut number one. - autoshortcut(player, OT_A_COOK); + // some abilities should always use certain shortcut numbers + autoshortcut(player, OT_A_TRAIN, 9); + autoshortcut(player, OT_A_TIPTOE, 0); + autoshortcut(player, OT_A_COOK, 1); + autoshortcut(player, OT_S_SIXTHSENSE, 6); // populate the remainder with our other abilities - autoshortcut(player, OT_NONE); + autoshortcut(player, OT_NONE, NA); getplayernamefull(pname); snprintf(welcomemsg, BUFLEN, "Greetings %s, welcome to nexus!", pname);