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