Annotation of 43BSDReno/games/rogue/message.c, revision 1.1

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

unix.superglobalmegacorp.com

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