Annotation of early-roguelike/srogue/io.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: * Various input/output functions
! 3: *
! 4: * @(#)io.c 9.0 (rdk) 7/17/84
! 5: *
! 6: * Super-Rogue
! 7: * Copyright (C) 1984 Robert D. Kindelberger
! 8: * All rights reserved.
! 9: *
! 10: * Based on "Rogue: Exploring the Dungeons of Doom"
! 11: * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
! 12: * All rights reserved.
! 13: *
! 14: * See the file LICENSE.TXT for full copyright and licensing information.
! 15: */
! 16:
! 17: #include <stdarg.h>
! 18: #include <ctype.h>
! 19: #include <string.h>
! 20: #include "rogue.h"
! 21: #include "rogue.ext"
! 22:
! 23: void doadd(char *fmt, va_list ap);
! 24:
! 25: /*
! 26: * msg:
! 27: * Display a message at the top of the screen.
! 28: */
! 29: static char msgbuf[BUFSIZ];
! 30: static int newpos = 0;
! 31:
! 32: void
! 33: msg(char *fmt, ...)
! 34: {
! 35: va_list ap;
! 36: /*
! 37: * if the string is "", just clear the line
! 38: */
! 39: if (*fmt == '\0') {
! 40: wmove(cw, 0, 0);
! 41: wclrtoeol(cw);
! 42: mpos = 0;
! 43: return;
! 44: }
! 45: /*
! 46: * otherwise add to the message and flush it out
! 47: */
! 48: va_start(ap, fmt);
! 49: doadd(fmt, ap);
! 50: va_end(ap);
! 51: endmsg();
! 52: }
! 53:
! 54: /*
! 55: * addmsg:
! 56: * Add things to the current message
! 57: */
! 58: void
! 59: addmsg(char *fmt, ...)
! 60: {
! 61: va_list ap;
! 62:
! 63: va_start(ap, fmt);
! 64: doadd(fmt, ap);
! 65: va_end(ap);
! 66: }
! 67:
! 68: /*
! 69: * endmsg:
! 70: * Display a new msg, giving him a chance to see the
! 71: * previous one if it is up there with the --More--
! 72: */
! 73: void
! 74: endmsg(void)
! 75: {
! 76: strcpy(huh, msgbuf);
! 77: if (mpos > 0) {
! 78: wmove(cw, 0, mpos);
! 79: waddstr(cw, morestr);
! 80: draw(cw);
! 81: wait_for(cw, ' ');
! 82: }
! 83: mvwaddstr(cw, 0, 0, msgbuf);
! 84: wclrtoeol(cw);
! 85: mpos = newpos;
! 86: newpos = 0;
! 87: draw(cw);
! 88: }
! 89:
! 90: /*
! 91: * doadd:
! 92: * Perform a printf into a buffer
! 93: */
! 94: void
! 95: doadd(char *fmt, va_list ap)
! 96: {
! 97: vsprintf(&msgbuf[newpos], fmt, ap);
! 98: newpos = strlen(msgbuf);
! 99: }
! 100:
! 101: /*
! 102: * step_ok:
! 103: * Returns TRUE if it is ok to step on ch
! 104: */
! 105: bool
! 106: step_ok(unsigned char ch)
! 107: {
! 108: if (dead_end(ch))
! 109: return FALSE;
! 110: else if (ch >= 32 && ch <= 127 && !isalpha(ch))
! 111: return TRUE;
! 112: return FALSE;
! 113: }
! 114:
! 115:
! 116: /*
! 117: * dead_end:
! 118: * Returns TRUE if you cant walk through that character
! 119: */
! 120: bool
! 121: dead_end(char ch)
! 122: {
! 123: if (ch == '-' || ch == '|' || ch == ' ' || ch == SECRETDOOR)
! 124: return TRUE;
! 125: else
! 126: return FALSE;
! 127: }
! 128:
! 129:
! 130: /*
! 131: * readchar:
! 132: * flushes stdout so that screen is up to date and then returns
! 133: * getchar.
! 134: */
! 135:
! 136: int
! 137: readchar(void)
! 138: {
! 139: char c;
! 140:
! 141: fflush(stdout);
! 142: return( md_readchar(cw) );
! 143: }
! 144:
! 145: char *hungstr[] = {
! 146: "",
! 147: " HUNGRY",
! 148: " STARVING",
! 149: " FAINTING",
! 150: };
! 151:
! 152: /*
! 153: * status:
! 154: * Display the important stats line. Keep the cursor where it was.
! 155: */
! 156: void
! 157: status(int fromfuse)
! 158: {
! 159: reg int totwght, carwght;
! 160: reg struct real *stef, *stre, *stmx;
! 161: reg char *pb;
! 162: int oy, ox, ch;
! 163: static char buf[LINLEN];
! 164: static char hwidth[] = { "%2d(%2d)" };
! 165:
! 166: /*
! 167: * If nothing has changed since the last time, then done
! 168: */
! 169: if (nochange)
! 170: return;
! 171: nochange = TRUE;
! 172: updpack(); /* get all weight info */
! 173: stef = &player.t_stats.s_ef;
! 174: stre = &player.t_stats.s_re;
! 175: stmx = &max_stats.s_re;
! 176: totwght = him->s_carry / 10;
! 177: carwght = him->s_pack / 10;
! 178: getyx(cw, oy, ox);
! 179: if (him->s_maxhp >= 100) {
! 180: hwidth[1] = '3'; /* if hit point >= 100 */
! 181: hwidth[5] = '3'; /* change %2d to %3d */
! 182: }
! 183: if (stre->a_str < stmx->a_str)
! 184: ch = '*';
! 185: else
! 186: ch = ' ';
! 187: sprintf(buf, "Str: %2d(%c%2d)", stef->a_str, ch, stre->a_str);
! 188: pb = &buf[strlen(buf)];
! 189: if (stre->a_dex < stmx->a_dex)
! 190: ch = '*';
! 191: else
! 192: ch = ' ';
! 193: sprintf(pb, " Dex: %2d(%c%2d)", stef->a_dex, ch, stre->a_dex);
! 194: pb = &buf[strlen(buf)];
! 195: if (stre->a_wis < stmx->a_wis)
! 196: ch = '*';
! 197: else
! 198: ch = ' ';
! 199: sprintf(pb, " Wis: %2d(%c%2d)", stef->a_wis, ch, stre->a_wis);
! 200: pb = &buf[strlen(buf)];
! 201: if (stre->a_con < stmx->a_con)
! 202: ch = '*';
! 203: else
! 204: ch = ' ';
! 205: sprintf(pb, " Con: %2d(%c%2d)", stef->a_con, ch, stre->a_con);
! 206: pb = &buf[strlen(buf)];
! 207: sprintf(pb, " Carry: %3d(%3d)", carwght, totwght);
! 208: mvwaddstr(cw, LINES - 1, 0, buf);
! 209: sprintf(buf, "Level: %d Gold: %5d Hp: ",level, purse);
! 210: pb = &buf[strlen(buf)];
! 211: sprintf(pb, hwidth, him->s_hpt, him->s_maxhp);
! 212: pb = &buf[strlen(buf)];
! 213: sprintf(pb," Ac: %-2d Exp: %d/%ld",cur_armor == NULL ? him->s_arm :
! 214: cur_armor->o_ac, him->s_lvl, him->s_exp);
! 215: carwght = (packvol * 100) / V_PACK;
! 216: pb = &buf[strlen(buf)];
! 217: sprintf(pb, " Vol: %3d%%", carwght);
! 218: mvwaddstr(cw, LINES - 2, 0, buf);
! 219: waddstr(cw, hungstr[hungry_state]);
! 220: wclrtoeol(cw);
! 221: wmove(cw, oy, ox);
! 222: }
! 223:
! 224: /*
! 225: * dispmax:
! 226: * Display the hero's maximum status
! 227: */
! 228: void
! 229: dispmax(void)
! 230: {
! 231: reg struct real *hmax;
! 232:
! 233: hmax = &max_stats.s_re;
! 234: msg("Maximums: Str = %d Dex = %d Wis = %d Con = %d",
! 235: hmax->a_str, hmax->a_dex, hmax->a_wis, hmax->a_con);
! 236: }
! 237:
! 238: /*
! 239: * illeg_ch:
! 240: * Returns TRUE if a char shouldn't show on the screen
! 241: */
! 242: bool
! 243: illeg_ch(unsigned char ch)
! 244: {
! 245: if (ch < 32 || ch > 127)
! 246: return TRUE;
! 247: if (ch >= '0' && ch <= '9')
! 248: return TRUE;
! 249: return FALSE;
! 250: }
! 251:
! 252: /*
! 253: * wait_for:
! 254: * Sit around until the guy types the right key
! 255: */
! 256: void
! 257: wait_for(WINDOW *win, char ch)
! 258: {
! 259: register char c;
! 260:
! 261: if (ch == '\n')
! 262: while ((c = wgetch(win)) != '\n' && c != '\r')
! 263: continue;
! 264: else
! 265: while (wgetch(win) != ch)
! 266: continue;
! 267: }
! 268:
! 269: #ifdef NEED_GETTIME
! 270: #include <stdio.h>
! 271: #include <time.h>
! 272:
! 273: /*
! 274: * gettime:
! 275: * This routine returns the current time as a string
! 276: */
! 277:
! 278: char *
! 279: gettime()
! 280: {
! 281: register char *timeptr;
! 282: long int now;
! 283:
! 284: time(&now); /* get current time */
! 285: timeptr = ctime(&now); /* convert to string */
! 286: return timeptr; /* return the string */
! 287: }
! 288: #endif
! 289:
! 290:
! 291: /*
! 292: * dbotline:
! 293: * Displays message on bottom line and waits for a space to return
! 294: */
! 295: void
! 296: dbotline(WINDOW *scr, char *message)
! 297: {
! 298: mvwaddstr(scr,LINES-1,0,message);
! 299: draw(scr);
! 300: wait_for(scr,' ');
! 301: }
! 302:
! 303:
! 304: /*
! 305: * restscr:
! 306: * Restores the screen to the terminal
! 307: */
! 308: void
! 309: restscr(WINDOW *scr)
! 310: {
! 311: clearok(scr,TRUE);
! 312: touchwin(scr);
! 313: }
! 314:
! 315: /*
! 316: * npch:
! 317: * Get the next char in line for inventories
! 318: */
! 319: char
! 320: npch(char ch)
! 321: {
! 322: reg char nch;
! 323: if (ch >= 'z')
! 324: nch = 'A';
! 325: else
! 326: nch = ch + 1;
! 327: return nch;
! 328: }
CVSweb