- Implement proper up/down paging in showlfstats()

- getspellschoolknown() returning unpredictable results
- in Skill screen, show abbreviations on each line for ease of reading.
This commit is contained in:
Rob Pearce 2016-06-02 11:24:32 +10:00
parent 997d5f88a8
commit 321a5ae00c
5 changed files with 367 additions and 203 deletions

248
io.c
View File

@ -5840,6 +5840,14 @@ void dolook(cell_t *where, int onpurpose) {
}
}
void lfstatheading(char *headstr, int offset) {
char buf[BUFLEN];
snprintf(buf, BUFLEN, "%s%s", headstr, offset ? " (continued)" : "");
wattron(mainwin, A_UNDERLINE);
centre(mainwin, C_WHITE, 0, "SKILLS");
wattroff(mainwin, A_UNDERLINE);
}
char *makedesc_god(lifeform_t *god, char *retbuf) {
char thisline[BUFLEN];
char godname[BUFLEN];
@ -6109,12 +6117,13 @@ char *makedesc_job(job_t *j, char *retbuf) {
strcpy(thisline, "");
for (sk = firstskill ; sk ; sk = sk->next) {
char lev[BUFLEN];
char *lev = NULL;
enum SKILLLEVEL slev = PR_INEPT;
strcpy(lev, "");
f = hasflagval(j->flags, F_STARTSKILL, sk->id, NA, NA, NULL);
if (f) {
slev = f->val[1];
lev = getskilllevelabbr(slev);
/*
switch (slev) {
case PR_INEPT: strcpy(lev, "---"); break;
case PR_NOVICE: strcpy(lev, "Nov"); break;
@ -6124,8 +6133,9 @@ char *makedesc_job(job_t *j, char *retbuf) {
case PR_EXPERT: strcpy(lev, "Exp"); break;
case PR_MASTER: strcpy(lev, "Mst"); break;
}
*/
}
if (strlen(lev)) {
if (lev) {
char *p;
char buf[BUFLEN];
//char bufpad[BUFLEN];
@ -8785,6 +8795,7 @@ void dooptions(void) {
char part1[BUFLEN];
char promptstr[BUFLEN],cmdchars[BUFLENSMALL];
char ch;
int headinglines = 2;
int y,h,done = B_FALSE;
option_t *opt;
@ -8804,7 +8815,7 @@ void dooptions(void) {
while (!done) {
cls();
centre(mainwin,C_WHITE, 0, "OPTIONS");
y = 2;
y = headinglines;
ch = '\0';
for (opt = firstoption ; opt ; opt = opt->next) {
sprintf(part1, "%c - %s", opt->letter, opt->text);
@ -8812,7 +8823,8 @@ void dooptions(void) {
if (opt->enabled == opt->def) strcat(buf, " (default)");
wmove(mainwin, y, 0);
textwithcol(mainwin, buf);
if (opt->next && downline(&y, h, "INVENTORY", NULL, promptstr, cmdchars, &ch)) {
if (opt->next && downline(&y, h, headinglines, NULL)) {
//finished = B_TRUE;
break;
}
}
@ -9578,18 +9590,21 @@ int dothrow(obpile_t *op, object_t *o) {
return B_TRUE;
}
// returns TRUE if escape pressed
int downline(int *y, int h, char *heading, char *subheading, char *bottomstring, char *cmdchars, char *retchar) {
char headbuf[BUFLEN];
int ch;
// returns TRUE if we hit the bottom of the screen.
int downline(int *y, int h, int headinglines, int *nextoffset) {
int w;
w = getmaxx(mainwin);
/*
// this is the heading we'll print after going past the 'MORE' strong
snprintf(headbuf, w-1, "%s (continued)", heading);
(*y)++;
// are we aff the bottom of the screen?
if (*y >= (h-3)) {
// prompt to press a key
centre(mainwin,C_WHITE, h-2, MORESTRING);
if (bottomstring) {
if (bottomstring) { // show extra prompt if required.
centre(mainwin, C_WHITE, h-1, bottomstring);
}
ch = getch();
@ -9601,6 +9616,7 @@ int downline(int *y, int h, char *heading, char *subheading, char *bottomstring,
return B_TRUE;
}
// clear screen and print the heading
cls(); *y = 0;
centre(mainwin, C_WHITE, *y, headbuf);
@ -9611,6 +9627,17 @@ int downline(int *y, int h, char *heading, char *subheading, char *bottomstring,
}
}
return B_FALSE;
*/
(*y)++;
// are we aff the bottom of the screen?
if (*y >= (h-3)) {
if (nextoffset) *nextoffset = *y - headinglines - 2;
return B_TRUE;
} else {
if (nextoffset) *nextoffset = 0;
}
return B_FALSE;
}
@ -12269,6 +12296,7 @@ void showlfarmour(lifeform_t *lf) {
void showlfstats(lifeform_t *lf, int showall) {
int y = 0, y2 = 0, x2 = 40;
int startx,starty;
int headinglines = 2;
int x;
int arating, evasion;
int acc;
@ -12295,14 +12323,14 @@ void showlfstats(lifeform_t *lf, int showall) {
obpile_t *op = NULL;
char ch;
char mode = '@';
char promptstr[BUFLEN];
char promptstr[BUFLEN],navstr[BUFLEN];
char cmdchars[BUFLEN];
int done = B_FALSE;
enum SKILLLEVEL lorelev;
enum COLOUR lorecol;
int min,max;
flag_t *retflag[MAXCANDIDATES];
int nretflags;
int nretflags,offset = 0, nextoffset = 0;
h = getmaxy(mainwin);
@ -12325,29 +12353,6 @@ void showlfstats(lifeform_t *lf, int showall) {
showall = B_TRUE;
}
if (isplayer(lf) || showall) {
snprintf(promptstr, BUFLEN, "^h[^W@^n=stats ^WS^nkills ^WA^nbils ^WM^nagic ^WE^nffects %s%s^W?^n=describe ^WESC^n=quit^h]",
isplayer(lf) ? "^WG^nods " : "",
isplayer(lf) ? "" : "^WI^ntems " );
snprintf(cmdchars, BUFLEN, "@asme%s%s",isplayer(lf) ? "g" : "", isplayer(lf) ? "" : "i");
} else {
snprintf(cmdchars, BUFLEN, "@e?");
// can always see stats & effects
snprintf(promptstr, BUFLEN, "^h[^W@^n=stats ^WE^nffects ");
if (!isplayer(lf)) {
snprintf(buf, BUFLEN, "^WI^ntems ");
strcat(promptstr, buf);
strcat(cmdchars, "i");
}
if ((lorelev >= PR_ADEPT) || (getskill(player, SK_LORE_ARCANA) >= PR_ADEPT)) {
snprintf(buf, BUFLEN, "^WM^nagic ");
strcat(promptstr, buf);
strcat(cmdchars, "m");
}
snprintf(buf, BUFLEN, "^W?^n=describe ^WESC^n=quit]");
strcat(promptstr, buf);
}
while (!done) {
cls();
y = 0;
@ -12366,10 +12371,10 @@ void showlfstats(lifeform_t *lf, int showall) {
}
wattroff(mainwin, A_UNDERLINE);
x = 0;
centre(mainwin, C_MAGENTA, 1, "[Press ? for a full description]");
y = 2;
y2 = 2;
//centre(mainwin, C_MAGENTA, 1, "[Press ? for a full description]");
y = headinglines;
y2 = headinglines;
dammod = getstrdammod(lf);
//accmod = getstatmod(lf, A_AGI);
@ -13295,14 +13300,16 @@ void showlfstats(lifeform_t *lf, int showall) {
wrapprint(mainwin, &y, &x, 0, "Nothing obvious.");
}
} else if (mode == 'a') {
int count = 0;
wattron(mainwin, A_UNDERLINE);
centre(mainwin, C_WHITE, 0, "ABILITIES");
wattroff(mainwin, A_UNDERLINE);
y = 2;
y = headinglines;
for (ot = objecttype ; ot ; ot = ot->next) {
f = lfhasknownflagval(lf, F_CANWILL, ot->id, NA, NA, NULL);
if (f && (f->known)) {
if (count >= offset) {
char expirebuf[BUFLEN];
char eb2[BUFLEN],racestr[BUFLEN];
int needgrab = B_FALSE;
@ -13344,10 +13351,13 @@ void showlfstats(lifeform_t *lf, int showall) {
snprintf(buf, BUFLEN, "%s%s", ot->desc, eb2);
wprintw(mainwin, buf);
if (downline(&y, h, "ABILITIES", NULL, promptstr, cmdchars, &ch)) {
if (downline(&y, h, headinglines, &nextoffset)) {
nextoffset += offset;
break;
}
}
count++;
}
}
y++;
@ -13356,13 +13366,13 @@ void showlfstats(lifeform_t *lf, int showall) {
enum SKILLLEVEL slev;
skill_t *sk;
int finished = B_FALSE,dounknown;
int count = 0;
wattron(mainwin, A_UNDERLINE);
centre(mainwin, C_WHITE, 0, "SKILLS");
wattroff(mainwin, A_UNDERLINE);
y = 2;
lfstatheading("SKILLS", offset);
//ooooooo start of skills
y = headinglines;
// construct headings
snprintf(skilltitle, BUFLEN, "%-21s"," ");
for (i = PR_NOVICE; i <= PR_MASTER; i++) {
char toadd[BUFLEN], *sn;
@ -13383,7 +13393,8 @@ void showlfstats(lifeform_t *lf, int showall) {
}
doheading(mainwin, &y, 0, skilltitle);
// for each skill...
// go through and list each skill, known ones first.
count = 0;
for (dounknown = 0; dounknown <= 1; dounknown++) {
for (sk = firstskill ; sk ; sk = sk->next) {
char thisline[BUFLEN];
@ -13391,6 +13402,7 @@ void showlfstats(lifeform_t *lf, int showall) {
slev = getskill(lf, sk->id);
if (!dounknown && (slev != PR_INEPT)) {
if (count >= offset) {
char endbit[BUFLEN];
char basecolour = 'n';
int max;
@ -13411,11 +13423,35 @@ void showlfstats(lifeform_t *lf, int showall) {
} else*/
if (i <= max) {
if (i == slev) {
char blank[2],endchar[2];
int n,blanklen;
char *sn;
sn = getskilllevelabbr(slev);
if (ismaxedskill(lf, sk->id)) {
strcpy(blank, "*");
strcpy(endchar, "*");
blanklen = 7 - strlen(sn);
} else {
strcpy(blank, "=");
strcpy(endchar, "|");
blanklen = 7 - strlen(sn);
}
strcpy(toadd,"");
for (n = 0; n < blanklen; n++) {
strncat(toadd, blank, BUFLEN);
}
strncat(toadd, sn, BUFLEN);
strncat(toadd, blank, BUFLEN);
strncat(toadd, endchar, BUFLEN);
/*
if (ismaxedskill(lf, sk->id)) {
sprintf(toadd, "*********");
} else {
sprintf(toadd, "========|");
}
*/
} else if (i < slev) {
if (ismaxedskill(lf, sk->id)) {
sprintf(toadd, "*********");
@ -13433,7 +13469,11 @@ void showlfstats(lifeform_t *lf, int showall) {
wmove(mainwin, y, 0);
textwithcol(mainwin, thisline);
printed = B_TRUE;
}
count++;
} else if (dounknown && !slev && lfhasflagval(lf, F_CANLEARN, sk->id, NA, NA, NULL)) {
if (count >= offset) {
char toadd[BUFLEN];
int max;
// learnable skill
@ -13459,8 +13499,12 @@ void showlfstats(lifeform_t *lf, int showall) {
printed = B_TRUE;
}
count++;
}
if (printed) {
if (downline(&y, h, "SKILLS", skilltitle, promptstr, cmdchars, &ch)) {
if (downline(&y, h, headinglines, &nextoffset)) {
nextoffset += offset;
finished = B_TRUE;
break;
}
@ -13468,11 +13512,13 @@ void showlfstats(lifeform_t *lf, int showall) {
}
if (finished) break;
}
//oooooooooooo end of skills oooooooooo
} else if (mode == 'm') {
char subheading[BUFLEN];
int lev;
int anyfound;
int exitnow = B_FALSE;
int count = 0;
snprintf(subheading, BUFLEN, " %-4s%-26s%-15s%-13s%s","Lv","Spell", "School", "Power", "Cost");
@ -13489,6 +13535,7 @@ void showlfstats(lifeform_t *lf, int showall) {
if (thislev == lev) {
f = lfhasknownflagval(lf, F_CANCAST, ot->id, NA, NA, NULL);
if (f && (f->known)) {
if (count >= offset) {
char spellname[BUFLEN];
char mpbuf[BUFLEN];
char powerbuf[BUFLEN];
@ -13543,14 +13590,17 @@ void showlfstats(lifeform_t *lf, int showall) {
if (castable || !isplayer(lf)) unsetcol(mainwin, C_GREEN);
else unsetcol(mainwin, C_RED);
anyfound = B_TRUE;
if (downline(&y, h, "MAGIC", subheading, promptstr, cmdchars, &ch)) {
if (downline(&y, h, headinglines, &nextoffset)) {
nextoffset += offset;
exitnow = B_TRUE;
break;
}
} // end if count >= offset
count++;
}
}
}
}
} // end foreach obtype
}
if (!anyfound) {
mvwprintw(mainwin, y, 0, "%s cannot cast any spells.", you(lf));
@ -13643,7 +13693,6 @@ void showlfstats(lifeform_t *lf, int showall) {
}
}
// spells
nfound = 0;
for (f = lf->flags->first ; f ; f = f->next) {
@ -14766,7 +14815,7 @@ void showlfstats(lifeform_t *lf, int showall) {
}
wattroff(mainwin, A_UNDERLINE);
y = 2;
y = headinglines;
if ((lf == player) && lfhasflag(lf, F_NOPACK)) {
mvwprintw(mainwin, y, 0, "It cannot carry anything.");
} else if (countobs(lf->pack, B_FALSE)) {
@ -14790,7 +14839,8 @@ void showlfstats(lifeform_t *lf, int showall) {
mvwprintw(mainwin, y, 0, "%s", buf);
if (o->next && downline(&y, h, "INVENTORY", NULL, promptstr, cmdchars, &ch)) {
if (o->next && downline(&y, h, headinglines, &nextoffset)) {
nextoffset += offset;
break;
}
}
@ -14805,7 +14855,7 @@ void showlfstats(lifeform_t *lf, int showall) {
wattron(mainwin, A_UNDERLINE);
centre(mainwin, C_WHITE, 0, "GODS");
wattroff(mainwin, A_UNDERLINE);
y = 2;
y = headinglines;
snprintf(line, BUFLEN, "%-29s Worship? %-22s %s","God","Piety", "Happiness");
@ -14896,8 +14946,70 @@ void showlfstats(lifeform_t *lf, int showall) {
}
}
// wait for key
// display the prompt
if (isplayer(lf) || showall) {
snprintf(promptstr, BUFLEN, "^h[^W@^n=stats ^WS^nkills ^WA^nbils ^WM^nagic ^WE^nffects %s%s ^WESC^n=quit^h]",
isplayer(lf) ? "^WG^nods " : "",
isplayer(lf) ? "" : "^WI^ntems "
);
snprintf(cmdchars, BUFLEN, "@asme%s%s",isplayer(lf) ? "g" : "", isplayer(lf) ? "" : "i");
} else {
snprintf(cmdchars, BUFLEN, "@e");
// can always see stats & effects
snprintf(promptstr, BUFLEN, "^h[^W@^n=stats ^WE^nffects ");
if (!isplayer(lf)) {
snprintf(buf, BUFLEN, "^WI^ntems ");
strcat(promptstr, buf);
strcat(cmdchars, "i");
}
if ((lorelev >= PR_ADEPT) || (getskill(player, SK_LORE_ARCANA) >= PR_ADEPT)) {
snprintf(buf, BUFLEN, "^WM^nagic ");
strcat(promptstr, buf);
strcat(cmdchars, "m");
}
snprintf(buf, BUFLEN, "^WESC^n=quit]");
strcat(promptstr, buf);
}
switch (mode) {
case 'g': // help on gods
case 's': // help on skills
case '@': // help on current race
strcat(cmdchars, "?");
default:
break;
}
// are there other pages to go to (or go back to)?
strcpy(navstr, "");
if (nextoffset) {
strcat(cmdchars, "']}");
if (offset) {
strcat(cmdchars, "[{");
}
snprintf(buf, BUFLEN, "^W'^n=next page %s^W]^n=forward %s^W}^n=pgdn",
(offset) ? "^W[^n=back " : "",
(offset) ? "^W{^n=pgup " : "");
strncat(navstr, buf, BUFLEN);
} else if (offset) {
strcat(cmdchars, "'[{");
snprintf(buf, BUFLEN, "^W'^n=back to start ^W[^n=back ^W{^n=pgup");
strncat(navstr, buf, BUFLEN);
}
if (strlen(navstr)) {
centre(mainwin, C_GREY, h-3, "(%s)", navstr);
}
if (strchr(cmdchars, '?')) {
centre(mainwin, C_MAGENTA, 1, "[Press ? for a full description]");
}
centre(mainwin, C_WHITE, h-1, promptstr);
// wait for key
if (ch == '\0') {
ch = getch();
}
@ -14918,6 +15030,34 @@ void showlfstats(lifeform_t *lf, int showall) {
case 's':
case 'i':
mode = ch;
offset = 0;
nextoffset = 0;
break;
case '\'':
// go to next page, or back to start
if (nextoffset) {
offset = nextoffset;
} else {
offset = 0;
}
break;
case ']':
// go forward one line
offset++;
break;
case '[':
// go back one line
offset--;
break;
case '}':
// go forward one page
offset += 18;
limit (&offset, NA, nextoffset);
break;
case '{':
// go back one page
offset -= 18;
limit (&offset, 0, NA);
break;
case '?':
if (mode == 'g') { // help on gods

4
io.h
View File

@ -87,7 +87,8 @@ int dotakeoff(obpile_t *op);
int dothrow(obpile_t *op, object_t *o);
int dowear(obpile_t *op);
int doweild(obpile_t *op);
int downline(int *y, int h, char *heading, char *subheading, char *bottomstring, char *cmdchars, char *retchar);
//int downline(int *y, int h, char *heading, char *subheading, char *bottomstring, char *cmdchars, char *retchar);
int downline(int *y, int h, int headinglines, int *nextoffset);
void drawbar(WINDOW *win, char *title, int cur, int max, int realmax, int lossamt, enum COLOUR textcol, enum COLOUR textcolwithbg, int barbg, int lossbg);
void drawglyph(glyph_t *g, int x, int y);
//void drawunviscell(cell_t *cell, int x, int y);
@ -123,6 +124,7 @@ void initgfx(void);
void initprompt(prompt_t *p, char *q1);
int keycodetokey(int keycode, int escseqok);
void listobs(WINDOW *win, object_t **mylist, int *sellist, int *selcount, int firstob, int *counter, int lastline, int *y, char *myletters, int forpickup, int showpoints, object_t *sellshop, enum SHOPACTION sellaction);
void lfstatheading(char *headstr, int offset);
char *makedesc_god(lifeform_t *god, char *retbuf);
char *makedesc_job(job_t *j, char *retbuf);
char *makedesc_ob(object_t *o, char *retbuf);

20
lf.c
View File

@ -11496,6 +11496,26 @@ char *getskillname(enum SKILL id) {
return "?unknownskill?";
}
char *getskilllevelabbr(enum SKILLLEVEL sl) {
switch (sl) {
case PR_INEPT:
return "---";
case PR_NOVICE:
return "Nov";
case PR_BEGINNER:
return "Beg";
case PR_ADEPT:
return "Adp";
case PR_SKILLED:
return "Skl";
case PR_EXPERT:
return "Exp";
case PR_MASTER:
return "Mst";
}
return "???";
}
char *getskilllevelname(enum SKILLLEVEL sl) {
switch (sl) {
case PR_INEPT:

1
lf.h
View File

@ -306,6 +306,7 @@ long getspforpoint(lifeform_t *lf);
float getstatmod(lifeform_t *lf, enum ATTRIB att);
char *getskilldesc(enum SKILL id );
char *getskillname(enum SKILL id );
char *getskilllevelabbr(enum SKILLLEVEL sl);
char *getskilllevelname(enum SKILLLEVEL sl);
int getteachableskills(lifeform_t *teacher, lifeform_t *student, int *info, enum TRADEINFOTYPE *tradetype, int *ninfo );
int gettr(lifeform_t *lf);

View File

@ -15084,8 +15084,9 @@ enum SPELLSCHOOL getspellschoolknown(lifeform_t *lf, enum OBTYPE spellid) {
}
}
// pick one randomly
thisschool = poss2[rnd(0,nposs2-1)];
// pick the first one.
//thisschool = poss2[rnd(0,nposs2-1)];
thisschool = poss2[0];
} else {
// if we don't know any of the schools...
// just pick the first one.