132689Sbostic /* 2*36704Sbostic * Copyright (c) 1988 The Regents of the University of California. 3*36704Sbostic * All rights reserved. 4*36704Sbostic * 5*36704Sbostic * This code is derived from software contributed to Berkeley by 6*36704Sbostic * Timothy C. Stoehr. 7*36704Sbostic * 8*36704Sbostic * Redistribution and use in source and binary forms are permitted 9*36704Sbostic * provided that the above copyright notice and this paragraph are 10*36704Sbostic * duplicated in all such forms and that any documentation, 11*36704Sbostic * advertising materials, and other materials related to such 12*36704Sbostic * distribution and use acknowledge that the software was developed 13*36704Sbostic * by the University of California, Berkeley. The name of the 14*36704Sbostic * University may not be used to endorse or promote products derived 15*36704Sbostic * from this software without specific prior written permission. 16*36704Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17*36704Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18*36704Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19*36704Sbostic */ 20*36704Sbostic 21*36704Sbostic #ifndef lint 22*36704Sbostic static char sccsid[] = "@(#)message.c 5.2 (Berkeley) 02/07/89"; 23*36704Sbostic #endif /* not lint */ 24*36704Sbostic 25*36704Sbostic /* 2632689Sbostic * message.c 2732689Sbostic * 2832689Sbostic * This source herein may be modified and/or distributed by anybody who 2932689Sbostic * so desires, with the following restrictions: 3032689Sbostic * 1.) No portion of this notice shall be removed. 3132689Sbostic * 2.) Credit shall not be taken for the creation of this source. 3232689Sbostic * 3.) This code is not to be traded, sold, or used for personal 3332689Sbostic * gain or profit. 3432689Sbostic * 3532689Sbostic */ 3632689Sbostic 3732689Sbostic #include <stdio.h> 3832689Sbostic #include "rogue.h" 3932689Sbostic 4032689Sbostic char msgs[NMESSAGES][DCOLS] = {"", "", "", "", ""}; 4132689Sbostic short msg_col = 0, imsg = -1; 4232689Sbostic boolean msg_cleared = 1, rmsg = 0; 4332689Sbostic char hunger_str[8] = ""; 4432689Sbostic char *more = "-more-"; 4532689Sbostic 4632689Sbostic extern boolean cant_int, did_int, interrupted, save_is_interactive; 4732689Sbostic extern short add_strength; 4832689Sbostic extern short cur_level; 4932689Sbostic 5032689Sbostic message(msg, intrpt) 5132689Sbostic char *msg; 5232689Sbostic boolean intrpt; 5332689Sbostic { 5432689Sbostic cant_int = 1; 5532689Sbostic 5632689Sbostic if (!save_is_interactive) { 5732689Sbostic return; 5832689Sbostic } 5932689Sbostic if (intrpt) { 6032689Sbostic interrupted = 1; 6132689Sbostic md_slurp(); 6232689Sbostic } 6332689Sbostic 6432689Sbostic if (!msg_cleared) { 6532689Sbostic mvaddstr(MIN_ROW-1, msg_col, more); 6632689Sbostic refresh(); 6732689Sbostic wait_for_ack(); 6832689Sbostic check_message(); 6932689Sbostic } 7032689Sbostic if (!rmsg) { 7132689Sbostic imsg = (imsg + 1) % NMESSAGES; 7232689Sbostic (void) strcpy(msgs[imsg], msg); 7332689Sbostic } 7432689Sbostic mvaddstr(MIN_ROW-1, 0, msg); 7532689Sbostic addch(' '); 7632689Sbostic refresh(); 7732689Sbostic msg_cleared = 0; 7832689Sbostic msg_col = strlen(msg); 7932689Sbostic 8032689Sbostic cant_int = 0; 8132689Sbostic 8232689Sbostic if (did_int) { 8332689Sbostic did_int = 0; 8432689Sbostic onintr(); 8532689Sbostic } 8632689Sbostic } 8732689Sbostic 8832689Sbostic remessage(c) 8932689Sbostic short c; 9032689Sbostic { 9132689Sbostic if (imsg != -1) { 9232689Sbostic check_message(); 9332689Sbostic rmsg = 1; 9432689Sbostic while (c > imsg) { 9532689Sbostic c -= NMESSAGES; 9632689Sbostic } 9732689Sbostic message(msgs[((imsg - c) % NMESSAGES)], 0); 9832689Sbostic rmsg = 0; 9932689Sbostic move(rogue.row, rogue.col); 10032689Sbostic refresh(); 10132689Sbostic } 10232689Sbostic } 10332689Sbostic 10432689Sbostic check_message() 10532689Sbostic { 10632689Sbostic if (msg_cleared) { 10732689Sbostic return; 10832689Sbostic } 10932689Sbostic move(MIN_ROW-1, 0); 11032689Sbostic clrtoeol(); 11132689Sbostic refresh(); 11232689Sbostic msg_cleared = 1; 11332689Sbostic } 11432689Sbostic 11532689Sbostic get_input_line(prompt, insert, buf, if_cancelled, add_blank, do_echo) 11632689Sbostic char *prompt, *buf, *insert; 11732689Sbostic char *if_cancelled; 11832689Sbostic boolean add_blank; 11932689Sbostic boolean do_echo; 12032689Sbostic { 12132689Sbostic short ch; 12232689Sbostic short i = 0, n; 12332689Sbostic 12432689Sbostic message(prompt, 0); 12532689Sbostic n = strlen(prompt); 12632689Sbostic 12732689Sbostic if (insert[0]) { 12832689Sbostic mvaddstr(0, n + 1, insert); 12932689Sbostic (void) strcpy(buf, insert); 13032689Sbostic i = strlen(insert); 13132689Sbostic move(0, (n + i + 1)); 13232689Sbostic refresh(); 13332689Sbostic } 13432689Sbostic 13532689Sbostic while (((ch = rgetchar()) != '\r') && (ch != '\n') && (ch != CANCEL)) { 13632689Sbostic if ((ch >= ' ') && (ch <= '~') && (i < MAX_TITLE_LENGTH-2)) { 13732689Sbostic if ((ch != ' ') || (i > 0)) { 13832689Sbostic buf[i++] = ch; 13932689Sbostic if (do_echo) { 14032689Sbostic addch(ch); 14132689Sbostic } 14232689Sbostic } 14332689Sbostic } 14432689Sbostic if ((ch == '\b') && (i > 0)) { 14532689Sbostic if (do_echo) { 14632689Sbostic mvaddch(0, i + n, ' '); 14732689Sbostic move(MIN_ROW-1, i+n); 14832689Sbostic } 14932689Sbostic i--; 15032689Sbostic } 15132689Sbostic refresh(); 15232689Sbostic } 15332689Sbostic check_message(); 15432689Sbostic if (add_blank) { 15532689Sbostic buf[i++] = ' '; 15632689Sbostic } else { 15732689Sbostic while ((i > 0) && (buf[i-1] == ' ')) { 15832689Sbostic i--; 15932689Sbostic } 16032689Sbostic } 16132689Sbostic 16232689Sbostic buf[i] = 0; 16332689Sbostic 16432689Sbostic if ((ch == CANCEL) || (i == 0) || ((i == 1) && add_blank)) { 16532689Sbostic if (if_cancelled) { 16632689Sbostic message(if_cancelled, 0); 16732689Sbostic } 16832689Sbostic return(0); 16932689Sbostic } 17032689Sbostic return(i); 17132689Sbostic } 17232689Sbostic 17332689Sbostic rgetchar() 17432689Sbostic { 17532689Sbostic register ch; 17632689Sbostic 17732689Sbostic for(;;) { 17832689Sbostic ch = getchar(); 17932689Sbostic 18032689Sbostic switch(ch) { 18132689Sbostic case '\022': 18232689Sbostic wrefresh(curscr); 18332689Sbostic break; 18432689Sbostic #ifdef UNIX_BSD4_2 18532689Sbostic case '\032': 18632689Sbostic printf(CL); 18732689Sbostic fflush(stdout); 18832689Sbostic tstp(); 18932689Sbostic break; 19032689Sbostic #endif 19132689Sbostic case '&': 19232689Sbostic save_screen(); 19332689Sbostic break; 19432689Sbostic default: 19532689Sbostic return(ch); 19632689Sbostic } 19732689Sbostic } 19832689Sbostic } 19932689Sbostic /* 20032689Sbostic Level: 99 Gold: 999999 Hp: 999(999) Str: 99(99) Arm: 99 Exp: 21/10000000 Hungry 20132689Sbostic 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 20232689Sbostic */ 20332689Sbostic 20432689Sbostic print_stats(stat_mask) 20532689Sbostic register stat_mask; 20632689Sbostic { 20732689Sbostic char buf[16]; 20832689Sbostic boolean label; 20932689Sbostic int row = DROWS - 1; 21032689Sbostic 21132689Sbostic label = (stat_mask & STAT_LABEL) ? 1 : 0; 21232689Sbostic 21332689Sbostic if (stat_mask & STAT_LEVEL) { 21432689Sbostic if (label) { 21532689Sbostic mvaddstr(row, 0, "Level: "); 21632689Sbostic } 21732689Sbostic /* max level taken care of in make_level() */ 21832689Sbostic sprintf(buf, "%d", cur_level); 21932689Sbostic mvaddstr(row, 7, buf); 22032689Sbostic pad(buf, 2); 22132689Sbostic } 22232689Sbostic if (stat_mask & STAT_GOLD) { 22332689Sbostic if (label) { 22432689Sbostic mvaddstr(row, 10, "Gold: "); 22532689Sbostic } 22632689Sbostic if (rogue.gold > MAX_GOLD) { 22732689Sbostic rogue.gold = MAX_GOLD; 22832689Sbostic } 22932689Sbostic sprintf(buf, "%ld", rogue.gold); 23032689Sbostic mvaddstr(row, 16, buf); 23132689Sbostic pad(buf, 6); 23232689Sbostic } 23332689Sbostic if (stat_mask & STAT_HP) { 23432689Sbostic if (label) { 23532689Sbostic mvaddstr(row, 23, "Hp: "); 23632689Sbostic } 23732689Sbostic if (rogue.hp_max > MAX_HP) { 23832689Sbostic rogue.hp_current -= (rogue.hp_max - MAX_HP); 23932689Sbostic rogue.hp_max = MAX_HP; 24032689Sbostic } 24132689Sbostic sprintf(buf, "%d(%d)", rogue.hp_current, rogue.hp_max); 24232689Sbostic mvaddstr(row, 27, buf); 24332689Sbostic pad(buf, 8); 24432689Sbostic } 24532689Sbostic if (stat_mask & STAT_STRENGTH) { 24632689Sbostic if (label) { 24732689Sbostic mvaddstr(row, 36, "Str: "); 24832689Sbostic } 24932689Sbostic if (rogue.str_max > MAX_STRENGTH) { 25032689Sbostic rogue.str_current -= (rogue.str_max - MAX_STRENGTH); 25132689Sbostic rogue.str_max = MAX_STRENGTH; 25232689Sbostic } 25332689Sbostic sprintf(buf, "%d(%d)", (rogue.str_current + add_strength), 25432689Sbostic rogue.str_max); 25532689Sbostic mvaddstr(row, 41, buf); 25632689Sbostic pad(buf, 6); 25732689Sbostic } 25832689Sbostic if (stat_mask & STAT_ARMOR) { 25932689Sbostic if (label) { 26032689Sbostic mvaddstr(row, 48, "Arm: "); 26132689Sbostic } 26232689Sbostic if (rogue.armor && (rogue.armor->d_enchant > MAX_ARMOR)) { 26332689Sbostic rogue.armor->d_enchant = MAX_ARMOR; 26432689Sbostic } 26532689Sbostic sprintf(buf, "%d", get_armor_class(rogue.armor)); 26632689Sbostic mvaddstr(row, 53, buf); 26732689Sbostic pad(buf, 2); 26832689Sbostic } 26932689Sbostic if (stat_mask & STAT_EXP) { 27032689Sbostic if (label) { 27132689Sbostic mvaddstr(row, 56, "Exp: "); 27232689Sbostic } 27332689Sbostic if (rogue.exp_points > MAX_EXP) { 27432689Sbostic rogue.exp_points = MAX_EXP; 27532689Sbostic } 27632689Sbostic if (rogue.exp > MAX_EXP_LEVEL) { 27732689Sbostic rogue.exp = MAX_EXP_LEVEL; 27832689Sbostic } 27932689Sbostic sprintf(buf, "%d/%ld", rogue.exp, rogue.exp_points); 28032689Sbostic mvaddstr(row, 61, buf); 28132689Sbostic pad(buf, 11); 28232689Sbostic } 28332689Sbostic if (stat_mask & STAT_HUNGER) { 28432689Sbostic mvaddstr(row, 73, hunger_str); 28532689Sbostic clrtoeol(); 28632689Sbostic } 28732689Sbostic refresh(); 28832689Sbostic } 28932689Sbostic 29032689Sbostic pad(s, n) 29132689Sbostic char *s; 29232689Sbostic short n; 29332689Sbostic { 29432689Sbostic short i; 29532689Sbostic 29632689Sbostic for (i = strlen(s); i < n; i++) { 29732689Sbostic addch(' '); 29832689Sbostic } 29932689Sbostic } 30032689Sbostic 30132689Sbostic save_screen() 30232689Sbostic { 30332689Sbostic FILE *fp; 30432689Sbostic short i, j; 30532689Sbostic char buf[DCOLS+2]; 30632689Sbostic boolean found_non_blank; 30732689Sbostic 30832689Sbostic if ((fp = fopen("rogue.screen", "w")) != NULL) { 30932689Sbostic for (i = 0; i < DROWS; i++) { 31032689Sbostic found_non_blank = 0; 31132689Sbostic for (j = (DCOLS - 1); j >= 0; j--) { 31232689Sbostic buf[j] = mvinch(i, j); 31332689Sbostic if (!found_non_blank) { 31432689Sbostic if ((buf[j] != ' ') || (j == 0)) { 31532689Sbostic buf[j + ((j == 0) ? 0 : 1)] = 0; 31632689Sbostic found_non_blank = 1; 31732689Sbostic } 31832689Sbostic } 31932689Sbostic } 32032689Sbostic fputs(buf, fp); 32132689Sbostic putc('\n', fp); 32232689Sbostic } 32332689Sbostic fclose(fp); 32432689Sbostic } else { 32532689Sbostic sound_bell(); 32632689Sbostic } 32732689Sbostic } 32832689Sbostic 32932689Sbostic sound_bell() 33032689Sbostic { 33132689Sbostic putchar(7); 33232689Sbostic fflush(stdout); 33332689Sbostic } 33432689Sbostic 33532689Sbostic boolean 33632689Sbostic is_digit(ch) 33732689Sbostic short ch; 33832689Sbostic { 33932689Sbostic return((ch >= '0') && (ch <= '9')); 34032689Sbostic } 34132689Sbostic 34232689Sbostic r_index(str, ch, last) 34332689Sbostic char *str; 34432689Sbostic int ch; 34532689Sbostic boolean last; 34632689Sbostic { 34732689Sbostic int i = 0; 34832689Sbostic 34932689Sbostic if (last) { 35032689Sbostic for (i = strlen(str) - 1; i >= 0; i--) { 35132689Sbostic if (str[i] == ch) { 35232689Sbostic return(i); 35332689Sbostic } 35432689Sbostic } 35532689Sbostic } else { 35632689Sbostic for (i = 0; str[i]; i++) { 35732689Sbostic if (str[i] == ch) { 35832689Sbostic return(i); 35932689Sbostic } 36032689Sbostic } 36132689Sbostic } 36232689Sbostic return(-1); 36332689Sbostic } 364