Annotation of 43BSDTahoe/games/rogue/message.c, revision 1.1.1.1

1.1       root        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: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.