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