# 2.11BSD#431 - /usr/src/games/rogue/message.c

##### Functions

    check_message     X
    get_input_line    X
    is_digit          X
    message           X
    pad               X
    print_stats       X
    r_index           X
    remessage         X
    rgetchar          X
    save_screen       X
    sound_bell        X

##### Variables

    hunger_str        X
    more              X
    msg_col           X
    msgs              X

       1: /*
       2:  * message.c
       3:  *
       4:  * This source herein may be modified and/or distributed by anybody who
       5:  * so desires, with the following restrictions:
       6:  *    1.)  No portion of this notice shall be removed.
       7:  *    2.)  Credit shall not be taken for the creation of this source.
       8:  *    3.)  This code is not to be traded, sold, or used for personal
       9:  *         gain or profit.
      10:  *
      11:  */
      12:
      13: #ifndef lint
      14: static char sccsid[] = "@(#)message.c	5.1 (Berkeley) 11/25/87";
      15: #endif /* not lint */
      16:
      17: #include <stdio.h>
      18: #include "rogue.h"
      19:
      20: char msgs[NMESSAGES][DCOLS] = {"", "", "", "", ""};
      21: short msg_col = 0, imsg = -1;
      22: boolean msg_cleared = 1, rmsg = 0;
      23: char hunger_str[8] = "";
      24: char *more = "-more-";
      25:
      26: extern boolean cant_int, did_int, interrupted, save_is_interactive;
      27: extern short add_strength;
      28: extern short cur_level;
      29:
      30: message(msg, intrpt)
      31: char *msg;
      32: boolean intrpt;
      33: {
      34:     cant_int = 1;
      35:
      36:     if (!save_is_interactive) {
      37:         return;
      38:     }
      39:     if (intrpt) {
      40:         interrupted = 1;
      41:         md_slurp();
      42:     }
      43:
      44:     if (!msg_cleared) {
      45:         mvaddstr(MIN_ROW-1, msg_col, more);
      46:         refresh();
      47:         wait_for_ack();
      48:         check_message();
      49:     }
      50:     if (!rmsg) {
      51:         imsg = (imsg + 1) % NMESSAGES;
      52:         (void) strcpy(msgs[imsg], msg);
      53:     }
      54:     mvaddstr(MIN_ROW-1, 0, msg);
      55:     addch(' ');
      56:     refresh();
      57:     msg_cleared = 0;
      58:     msg_col = strlen(msg);
      59:
      60:     cant_int = 0;
      61:
      62:     if (did_int) {
      63:         did_int = 0;
      64:         onintr();
      65:     }
      66: }
      67:
      68: remessage(c)
      69: short c;
      70: {
      71:     if (imsg != -1) {
      72:         check_message();
      73:         rmsg = 1;
      74:         while (c > imsg) {
      75:             c -= NMESSAGES;
      76:         }
      77:         message(msgs[((imsg - c) % NMESSAGES)], 0);
      78:         rmsg = 0;
      79:         move(rogue.row, rogue.col);
      80:         refresh();
      81:     }
      82: }
      83:
      84: check_message()
      85: {
      86:     if (msg_cleared) {
      87:         return;
      88:     }
      89:     move(MIN_ROW-1, 0);
      90:     clrtoeol();
      91:     refresh();
      92:     msg_cleared = 1;
      93: }
      94:
      95: get_input_line(prompt, insert, buf, if_cancelled, add_blank, do_echo)
      96: char *prompt, *buf, *insert;
      97: char *if_cancelled;
      98: boolean add_blank;
      99: boolean do_echo;
     100: {
     101:     short ch;
     102:     short i = 0, n;
     103:
     104:     message(prompt, 0);
     105:     n = strlen(prompt);
     106:
     107:     if (insert[0]) {
     108:         mvaddstr(0, n + 1, insert);
     109:         (void) strcpy(buf, insert);
     110:         i = strlen(insert);
     111:         move(0, (n + i + 1));
     112:         refresh();
     113:     }
     114:
     115:     while (((ch = rgetchar()) != '\r') && (ch != '\n') && (ch != CANCEL)) {
     116:         if ((ch >= ' ') && (ch <= '~') && (i < MAX_TITLE_LENGTH-2)) {
     117:             if ((ch != ' ') || (i > 0)) {
     118:                 buf[i++] = ch;
     119:                 if (do_echo) {
     120:                     addch(ch);
     121:                 }
     122:             }
     123:         }
     124:         if ((ch == '\b') && (i > 0)) {
     125:             if (do_echo) {
     126:                 mvaddch(0, i + n, ' ');
     127:                 move(MIN_ROW-1, i+n);
     128:             }
     129:             i--;
     130:         }
     131:         refresh();
     132:     }
     133:     check_message();
     134:     if (add_blank) {
     135:         buf[i++] = ' ';
     136:     } else {
     137:         while ((i > 0) && (buf[i-1] == ' ')) {
     138:             i--;
     139:         }
     140:     }
     141:
     142:     buf[i] = 0;
     143:
     144:     if ((ch == CANCEL) || (i == 0) || ((i == 1) && add_blank)) {
     145:         if (if_cancelled) {
     146:             message(if_cancelled, 0);
     147:         }
     148:         return(0);
     149:     }
     150:     return(i);
     151: }
     152:
     153: rgetchar()
     154: {
     155:     register ch;
     156:
     157:     for(;;) {
     158:         ch = getchar();
     159:
     160:         switch(ch) {
     161:         case '\022':
     162:             wrefresh(curscr);
     163:             break;
     164: #ifdef UNIX_BSD4_2
     165:         case '\032':
     166:             printf(CL);
     167:             fflush(stdout);
     168:             tstp();
     169:             break;
     170: #endif
     171:         case '&':
     172:             save_screen();
     173:             break;
     174:         default:
     175:             return(ch);
     176:         }
     177:     }
     178: }
     179: /*
     180: Level: 99 Gold: 999999 Hp: 999(999) Str: 99(99) Arm: 99 Exp: 21/10000000 Hungry
     181: 0    5    1    5    2    5    3    5    4    5    5    5    6    5    7    5
     182: */
     183:
     184: print_stats(stat_mask)
     185: register stat_mask;
     186: {
     187:     char buf[16];
     188:     boolean label;
     189:     int row = DROWS - 1;
     190:
     191:     label = (stat_mask & STAT_LABEL) ? 1 : 0;
     192:
     193:     if (stat_mask & STAT_LEVEL) {
     194:         if (label) {
     195:             mvaddstr(row, 0, "Level: ");
     196:         }
     197:         /* max level taken care of in make_level() */
     198:         sprintf(buf, "%d", cur_level);
     199:         mvaddstr(row, 7, buf);
     200:         pad(buf, 2);
     201:     }
     202:     if (stat_mask & STAT_GOLD) {
     203:         if (label) {
     204:             mvaddstr(row, 10, "Gold: ");
     205:         }
     206:         if (rogue.gold > MAX_GOLD) {
     207:             rogue.gold = MAX_GOLD;
     208:         }
     209:         sprintf(buf, "%ld", rogue.gold);
     210:         mvaddstr(row, 16, buf);
     211:         pad(buf, 6);
     212:     }
     213:     if (stat_mask & STAT_HP) {
     214:         if (label) {
     215:             mvaddstr(row, 23, "Hp: ");
     216:         }
     217:         if (rogue.hp_max > MAX_HP) {
     218:             rogue.hp_current -= (rogue.hp_max - MAX_HP);
     219:             rogue.hp_max = MAX_HP;
     220:         }
     221:         sprintf(buf, "%d(%d)", rogue.hp_current, rogue.hp_max);
     222:         mvaddstr(row, 27, buf);
     223:         pad(buf, 8);
     224:     }
     225:     if (stat_mask & STAT_STRENGTH) {
     226:         if (label) {
     227:             mvaddstr(row, 36, "Str: ");
     228:         }
     229:         if (rogue.str_max > MAX_STRENGTH) {
     230:             rogue.str_current -= (rogue.str_max - MAX_STRENGTH);
     231:             rogue.str_max = MAX_STRENGTH;
     232:         }
     233:         sprintf(buf, "%d(%d)", (rogue.str_current + add_strength),
     234:             rogue.str_max);
     235:         mvaddstr(row, 41, buf);
     236:         pad(buf, 6);
     237:     }
     238:     if (stat_mask & STAT_ARMOR) {
     239:         if (label) {
     240:             mvaddstr(row, 48, "Arm: ");
     241:         }
     242:         if (rogue.armor && (rogue.armor->d_enchant > MAX_ARMOR)) {
     243:             rogue.armor->d_enchant = MAX_ARMOR;
     244:         }
     245:         sprintf(buf, "%d", get_armor_class(rogue.armor));
     246:         mvaddstr(row, 53, buf);
     247:         pad(buf, 2);
     248:     }
     249:     if (stat_mask & STAT_EXP) {
     250:         if (label) {
     251:             mvaddstr(row, 56, "Exp: ");
     252:         }
     253:         if (rogue.exp_points > MAX_EXP) {
     254:             rogue.exp_points = MAX_EXP;
     255:         }
     256:         if (rogue.exp > MAX_EXP_LEVEL) {
     257:             rogue.exp = MAX_EXP_LEVEL;
     258:         }
     259:         sprintf(buf, "%d/%ld", rogue.exp, rogue.exp_points);
     260:         mvaddstr(row, 61, buf);
     261:         pad(buf, 11);
     262:     }
     263:     if (stat_mask & STAT_HUNGER) {
     264:         mvaddstr(row, 73, hunger_str);
     265:         clrtoeol();
     266:     }
     267:     refresh();
     268: }
     269:
     270: pad(s, n)
     271: char *s;
     272: short n;
     273: {
     274:     short i;
     275:
     276:     for (i = strlen(s); i < n; i++) {
     277:         addch(' ');
     278:     }
     279: }
     280:
     281: save_screen()
     282: {
     283:     FILE *fp;
     284:     short i, j;
     285:     char buf[DCOLS+2];
     286:     boolean found_non_blank;
     287:
     288:     if ((fp = fopen("rogue.screen", "w")) != NULL) {
     289:         for (i = 0; i < DROWS; i++) {
     290:             found_non_blank = 0;
     291:             for (j = (DCOLS - 1); j >= 0; j--) {
     292:                 buf[j] = mvinch(i, j);
     293:                 if (!found_non_blank) {
     294:                     if ((buf[j] != ' ') || (j == 0)) {
     295:                         buf[j + ((j == 0) ? 0 : 1)] = 0;
     296:                         found_non_blank = 1;
     297:                     }
     298:                 }
     299:             }
     300:             fputs(buf, fp);
     301:             putc('\n', fp);
     302:         }
     303:         fclose(fp);
     304:     } else {
     305:         sound_bell();
     306:     }
     307: }
     308:
     309: sound_bell()
     310: {
     311:     putchar(7);
     312:     fflush(stdout);
     313: }
     314:
     315: boolean
     316: is_digit(ch)
     317: short ch;
     318: {
     319:     return((ch >= '0') && (ch <= '9'));
     320: }
     321:
     322: r_index(str, ch, last)
     323: char *str;
     324: int ch;
     325: boolean last;
     326: {
     327:     int i = 0;
     328:
     329:     if (last) {
     330:         for (i = strlen(str) - 1; i >= 0; i--) {
     331:             if (str[i] == ch) {
     332:                 return(i);
     333:             }
     334:         }
     335:     } else {
     336:         for (i = 0; str[i]; i++) {
     337:             if (str[i] == ch) {
     338:                 return(i);
     339:             }
     340:         }
     341:     }
     342:     return(-1);
     343: }

#### Defined functions

check_message defined in line 84; used 31 times

- in line 48, 72, 133
- in /usr/src/games/rogue/hit.c line 301
- in /usr/src/games/rogue/init.c line 185
- in /usr/src/games/rogue/inventory.c line 238, 298, 316, 367, 674, 735
- in /usr/src/games/rogue/move.c line 292
- in /usr/src/games/rogue/object.c line 687
- in /usr/src/games/rogue/pack.c line 259, 266
- in /usr/src/games/rogue/play.c line 46
- in /usr/src/games/rogue/ring.c line 71-75(2), 85, 130
- in /usr/src/games/rogue/save.c line 54
- in /usr/src/games/rogue/score.c line 136-140(2), 154
- in /usr/src/games/rogue/spec_hit.c line 327
- in /usr/src/games/rogue/throw.c line 38, 45
- in /usr/src/games/rogue/trap.c line 163
- in /usr/src/games/rogue/use.c line 346
- in /usr/src/games/rogue/zap.c line 39, 46

get_input_line defined in line 95; used 4 times

- in /usr/src/games/rogue/object.c line 728
- in /usr/src/games/rogue/pack.c line 417
- in /usr/src/games/rogue/save.c line 50
- in /usr/src/games/rogue/zap.c line 195

is_digit defined in line 315; used 5 times

- in /usr/src/games/rogue/curses.c line 505, 545, 580
- in /usr/src/games/rogue/play.c line 202
- in /usr/src/games/rogue/rogue.h line 410

message defined in line 30; used 199 times

- in line 77, 104, 146
- in /usr/src/games/rogue/hit.c line 54, 61, 271, 297, 311, 417
- in /usr/src/games/rogue/init.c line 186
- in /usr/src/games/rogue/inventory.c line 189, 239, 299, 317, 368, 611, 619, 650, 656, 667, 737
- in /usr/src/games/rogue/level.c line 718, 731-736(2), 744-748(2), 779, 830
- in /usr/src/games/rogue/machdep.c line 512-515(2)
- in /usr/src/games/rogue/monster.c line 651, 783
- in /usr/src/games/rogue/move.c line 53-55(2), 126, 288, 345-350(2), 356, 365, 371, 444, 452
- in /usr/src/games/rogue/object.c line 216, 586, 679-682(2), 745
- in /usr/src/games/rogue/pack.c line 73-78(2), 84, 101, 118-122(2), 129-134(2), 140, 148, 169, 242-247(2), 277, 284-289(2), 300, 309-313(2), 319, 349, 358, 364-373(3), 408-412(2), 514-519(2), 527
- in /usr/src/games/rogue/play.c line 34, 181, 213, 220, 227, 234, 244, 251, 258
- in /usr/src/games/rogue/ring.c line 43, 50-58(3), 64, 76, 87, 123, 137, 143-152(3), 217-225(3), 233
- in /usr/src/games/rogue/save.c line 55, 77, 350
- in /usr/src/games/rogue/score.c line 88-90(2), 110-111(2), 137, 173, 276-278(2), 384, 542
- in /usr/src/games/rogue/spec_hit.c line 68-73(2), 94, 106, 126, 176, 329, 368, 403, 436
- in /usr/src/games/rogue/throw.c line 34, 48-52(2), 221
- in /usr/src/games/rogue/trap.c line 68, 77, 85, 100-104(2), 158, 175-177(2), 234
- in /usr/src/games/rogue/use.c line 50-59(3), 68-75(3), 85, 92, 99, 105, 114-128(4), 136, 163-172(3), 185, 194, 201-210(3), 219-232(4), 244, 250, 344-345(2), 355, 371-375(2), 381-388(3), 423-427(3), 476, 482, 513, 521, 569
- in /usr/src/games/rogue/zap.c line 35, 49-57(3), 163, 193, 201-203(2), 259, 297, 313, 319, 330, 337, 348

pad defined in line 270; used 6 times

- in line 200, 211, 223, 236, 247, 261

print_stats defined in line 184; used 24 times

- in /usr/src/games/rogue/hit.c line 132-137(2)
- in /usr/src/games/rogue/level.c line 786-789(2)
- in /usr/src/games/rogue/main.c line 37
- in /usr/src/games/rogue/move.c line 346-351(2), 357, 571
- in /usr/src/games/rogue/pack.c line 97, 145, 285, 321
- in /usr/src/games/rogue/ring.c line 297
- in /usr/src/games/rogue/spec_hit.c line 74, 127, 370, 418
- in /usr/src/games/rogue/throw.c line 62
- in /usr/src/games/rogue/trap.c line 94
- in /usr/src/games/rogue/use.c line 144, 204, 394
- in /usr/src/games/rogue/zap.c line 234

r_index defined in line 322; used 1 times

- in /usr/src/games/rogue/object.c line 684

remessage defined in line 68; used 1 times

- in /usr/src/games/rogue/play.c line 119

rgetchar defined in line 153; used 18 times

- in line 115
- in /usr/src/games/rogue/hit.c line 294
- in /usr/src/games/rogue/inventory.c line 669
- in /usr/src/games/rogue/move.c line 285
- in /usr/src/games/rogue/object.c line 684
- in /usr/src/games/rogue/pack.c line 231, 250
- in /usr/src/games/rogue/play.c line 44, 120, 201
- in /usr/src/games/rogue/ring.c line 66, 125
- in /usr/src/games/rogue/room.c line 487, 542
- in /usr/src/games/rogue/score.c line 138
- in /usr/src/games/rogue/throw.c line 31
- in /usr/src/games/rogue/trap.c line 160
- in /usr/src/games/rogue/zap.c line 32

save_screen defined in line 281; used 1 times

- in line 172

sound_bell defined in line 309; used 13 times

- in line 305
- in /usr/src/games/rogue/hit.c line 295
- in /usr/src/games/rogue/move.c line 286
- in /usr/src/games/rogue/object.c line 685, 736
- in /usr/src/games/rogue/pack.c line 252
- in /usr/src/games/rogue/room.c line 509, 524, 550
- in /usr/src/games/rogue/save.c line 351
- in /usr/src/games/rogue/throw.c line 32
- in /usr/src/games/rogue/trap.c line 161
- in /usr/src/games/rogue/zap.c line 33

#### Defined variables

hunger_str defined in line 23; used 10 times

- in line 264
- in /usr/src/games/rogue/move.c line 344-356(6)
- in /usr/src/games/rogue/save.c line 86, 148
- in /usr/src/games/rogue/use.c line 393

more defined in line 24; used 2 times

- in line 45
- in /usr/src/games/rogue/inventory.c line 278

msg_col defined in line 21; used 2 times

- in line 45, 58

msgs defined in line 20; used 2 times

- in line 52, 77

sccsid defined in line 14; never used

Last modified: 1987-11-26 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 2062 |