Changeset 632
- Timestamp:
- 12/22/07 17:16:00 (8 months ago)
- Files:
-
- trunk/src/death.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/death.c
r631 r632 20 20 21 21 22 23 /*24 * Centers a string within a 31 character string25 */26 static void center_string(char *buf, size_t len, cptr str)27 {28 int i, j;29 30 /* Total length */31 i = strlen(str);32 33 /* Necessary border */34 j = 15 - i / 2;35 36 /* Mega-Hack */37 strnfmt(buf, len, "%*s%s%*s", j, "", str, 31 - i - j, "");38 }39 40 41 42 43 44 22 /* 45 23 * Hack - save the time of death … … 48 26 49 27 50 /* 51 * Display a "tomb-stone" 28 29 /* 30 * Write formatted string `fmt` on line `y`, centred between points x1 and x2. 31 */ 32 static void put_str_centred(int y, int x1, int x2, const char *fmt, ...) 33 { 34 va_list vp; 35 char *tmp; 36 size_t len; 37 int x; 38 39 /* Format into the (growable) tmp */ 40 va_start(vp, fmt); 41 tmp = vformat(fmt, vp); 42 va_end(vp); 43 44 /* Centre now */ 45 len = strlen(tmp); 46 x = x1 + ((x2-x1)/2 - len/2); 47 48 put_str(tmp, y, x); 49 } 50 51 52 /* 53 * Display the tombstone 52 54 */ 53 55 static void print_tomb(void) 54 56 { 55 cptr p; 56 57 char tmp[160]; 57 ang_file *fp; 58 58 char buf[1024]; 59 60 ang_file *fp; 61 62 int line = 7; 63 64 65 /* Clear screen */ 59 int line = 0; 60 61 66 62 Term_clear(); 67 63 … … 70 66 fp = file_open(buf, MODE_READ, -1); 71 67 72 /* Dump */73 68 if (fp) 74 69 { 75 int i = 0;76 77 /* Dump the file to the screen */78 70 while (file_getl(fp, buf, sizeof(buf))) 79 put_str(buf, i++, 0);71 put_str(buf, line++, 0); 80 72 81 73 file_close(fp); 82 74 } 83 75 84 85 /* Get the right total */ 76 line = 7; 77 78 put_str_centred(line++, 8, 8+31, "%s", op_ptr->full_name); 79 put_str_centred(line++, 8, 8+31, "the"); 86 80 if (p_ptr->total_winner) 87 p = "Magnificent";81 put_str_centred(line++, 8, 8+31, "Magnificent"); 88 82 else 89 p = c_text + cp_ptr->title[(p_ptr->lev - 1) / 5]; 90 91 center_string(buf, sizeof(buf), op_ptr->full_name); 92 put_str(buf, line++, 8); 93 94 center_string(buf, sizeof(buf), "the"); 95 put_str(buf, line++, 8); 96 97 center_string(buf, sizeof(buf), p); 98 put_str(buf, line++, 8); 83 put_str_centred(line++, 8, 8+31, "%s", c_text + cp_ptr->title[(p_ptr->lev - 1) / 5]); 99 84 100 85 line++; 101 86 102 center_string(buf, sizeof(buf), c_name + cp_ptr->name); 103 put_str(buf, line++, 8); 104 105 strnfmt(tmp, sizeof(tmp), "Level: %d", (int)p_ptr->lev); 106 center_string(buf, sizeof(buf), tmp); 107 put_str(buf, line++, 8); 108 109 strnfmt(tmp, sizeof(tmp), "Exp: %ld", (long)p_ptr->exp); 110 center_string(buf, sizeof(buf), tmp); 111 put_str(buf, line++, 8); 112 113 strnfmt(tmp, sizeof(tmp), "AU: %ld", (long)p_ptr->au); 114 center_string(buf, sizeof(buf), tmp); 115 put_str(buf, line++, 8); 116 117 strnfmt(tmp, sizeof(tmp), "Killed on Level %d", p_ptr->depth); 118 center_string(buf, sizeof(buf), tmp); 119 put_str(buf, line++, 8); 120 121 strnfmt(tmp, sizeof(tmp), "by %s.", p_ptr->died_from); 122 center_string(buf, sizeof(buf), tmp); 123 put_str(buf, line++, 8); 87 put_str_centred(line++, 8, 8+31, "%s", c_name + cp_ptr->name); 88 put_str_centred(line++, 8, 8+31, "Level: %d", (int)p_ptr->lev); 89 put_str_centred(line++, 8, 8+31, "Exp: %d", (int)p_ptr->exp); 90 put_str_centred(line++, 8, 8+31, "AU: %d", (int)p_ptr->au); 91 put_str_centred(line++, 8, 8+31, "Killed on Level %d", p_ptr->depth); 92 put_str_centred(line++, 8, 8+31, "by %s.", p_ptr->died_from); 124 93 125 94 line++; 126 95 127 strnfmt(tmp, sizeof(tmp), "%-.24s", ctime(&death_time)); 128 center_string(buf, sizeof(buf), tmp); 129 put_str(buf, line++, 8); 130 } 131 132 133 /* 134 * Hack - Know inventory and home items upon death 96 put_str_centred(line++, 8, 8+31, "by %-.24s", ctime(&death_time)); 97 } 98 99 100 /* 101 * Know inventory and home items upon death 135 102 */ 136 103 static void death_knowledge(void) 137 104 { 105 store_type *st_ptr = &store[STORE_HOME]; 106 object_type *o_ptr; 107 138 108 int i; 139 109 140 object_type *o_ptr;141 142 store_type *st_ptr = &store[STORE_HOME];143 144 145 /* Hack -- Know everything in the inven/equip */146 110 for (i = 0; i < INVEN_TOTAL; i++) 147 111 { 148 112 o_ptr = &inventory[i]; 149 150 /* Skip non-objects */151 113 if (!o_ptr->k_idx) continue; 152 114 153 /* Aware and Known */154 115 object_aware(o_ptr); 155 116 object_known(o_ptr); 156 157 /* Fully known */ 158 o_ptr->ident |= (IDENT_KNOWN); 159 } 160 161 /* Hack -- Know everything in the home */ 117 } 118 162 119 for (i = 0; i < st_ptr->stock_num; i++) 163 120 { 164 121 o_ptr = &st_ptr->stock[i]; 165 166 /* Skip non-objects */167 122 if (!o_ptr->k_idx) continue; 168 123 169 /* Aware and Known */170 124 object_aware(o_ptr); 171 125 object_known(o_ptr); 172 173 /* Fully known */174 o_ptr->ident |= (IDENT_KNOWN);175 126 } 176 127 177 128 /* Hack -- Recalculate bonuses */ 178 129 p_ptr->update |= (PU_BONUS); 179 180 /* Handle stuff */181 130 handle_stuff(); 182 131 } … … 185 134 186 135 /* 187 * Display the winner file136 * Display the winner crown 188 137 */ 189 138 static void display_winner(void) 190 139 { 191 140 char buf[1024]; 192 char tmp[1024];193 141 ang_file *fp; 194 142 … … 219 167 } 220 168 221 strnfmt(buf, sizeof(buf), "All Hail the Mighty %s!", sp_ptr->winner); 222 center_string(tmp, sizeof(tmp), buf); 223 put_str(tmp, i++, (wid/2) - (31/2)); 169 put_str_centred(i, 0, wid, "All Hail the Mighty %s!", sp_ptr->winner); 224 170 225 171 flush(); … … 228 174 229 175 230 231 232 233 234 176 /* 177 * Menu command: dump character dump to file. 178 */ 235 179 static void death_file(void *unused, const char *title) 236 180 { 237 181 char ftmp[80]; 238 182 strnfmt(ftmp, sizeof(ftmp), "%s.txt", op_ptr->base_name); 183 184 (void)unused; 185 (void)title; 239 186 240 187 if (!get_string("File name: ", ftmp, sizeof(ftmp))) … … 261 208 } 262 209 210 /* 211 * Menu command: view character dump and inventory. 212 */ 263 213 static void death_info(void *unused, const char *title) 264 214 { … … 266 216 object_type *o_ptr; 267 217 store_type *st_ptr = &store[STORE_HOME]; 218 219 (void)unused; 220 (void)title; 268 221 269 222 … … 349 302 } 350 303 304 /* 305 * Menu command: peruse pre-death messages. 306 */ 351 307 static void death_messages(void *unused, const char *title) 352 308 { 309 (void)unused; 310 (void)title; 311 353 312 screen_save(); 354 313 do_cmd_messages(); … … 356 315 } 357 316 317 /* 318 * Menu command: see top twenty scores. 319 */ 358 320 static void death_scores(void *unused, const char *title) 359 321 { 322 (void)unused; 323 (void)title; 324 360 325 screen_save(); 361 326 top_twenty(); … … 363 328 } 364 329 330 /* 331 * Menu command: examine items in the inventory. 332 */ 365 333 static void death_examine(void *unused, const char *title) 366 334 { 367 335 int item; 368 336 cptr q, s; 337 338 (void)unused; 339 (void)title; 369 340 370 341 … … 382 353 { 383 354 object_type *o_ptr = &inventory[item]; 384 385 /* "Know" */386 o_ptr->ident |= IDENT_KNOWN;387 355 388 356 /* Describe */ … … 404 372 } 405 373 406 menu_type death_menu; 407 374 375 /* 376 * Menu structures for the death menu. 377 */ 378 static menu_type death_menu; 408 379 static const menu_action death_actions[] = 409 380 { … … 416 387 }; 417 388 418 419 420 421 static char tag_death_main(menu_type *menu, int oid) 422 { 423 if (death_actions[oid].id) 424 return death_actions[oid].id; 425 426 return 0; 427 } 428 429 static int valid_death_main(menu_type *menu, int oid) 430 { 431 if (death_actions[oid].name) 432 return 1; 433 434 return 0; 435 } 436 437 static void display_death_main(menu_type *menu, int oid, bool cursor, int row, int col, int width) 389 /* Return the tag for a menu entry */ 390 static char death_menu_tag(menu_type *menu, int oid) 391 { 392 (void)menu; 393 return death_actions[oid].id; 394 } 395 396 /* Display a menu entry */ 397 static void death_menu_display(menu_type *menu, int oid, bool cursor, int row, int col, int width) 438 398 { 439 399 byte attr = curs_attrs[CURS_KNOWN][(int)cursor]; 440 441 if (death_actions[oid].name) 442 c_prt(attr, death_actions[oid].name, row, col); 443 } 444 400 (void)menu; 401 (void)width; 402 c_prt(attr, death_actions[oid].name, row, col); 403 } 445 404 446 405 static const menu_iter death_iter = 447 406 { 448 407 0, 449 tag_death_main,450 valid_death_main,451 d isplay_death_main,408 death_menu_tag, 409 NULL, 410 death_menu_display, 452 411 NULL 453 412 }; … … 461 420 void death_screen(void) 462 421 { 463 bool wants_to_quit = FALSE; 464 465 422 menu_type *menu; 423 const char cmd_keys[] = { ARROW_LEFT, ARROW_RIGHT, '\0' }; 424 const region area = { 51, 2, 0, 6 }; 425 426 int cursor = 0; 427 ui_event_data c = EVENT_EMPTY; 428 429 430 /* Retire in the town in a good state */ 466 431 if (p_ptr->total_winner) 467 432 { 468 /* Retire in the town in a good state */469 433 p_ptr->depth = 0; 470 434 my_strcpy(p_ptr->died_from, "Ripe Old Age", sizeof(p_ptr->died_from)); … … 485 449 /* Get time of death */ 486 450 (void)time(&death_time); 487 488 /* You are dead */489 451 print_tomb(); 490 491 /* Hack - Know everything upon death */492 452 death_knowledge(); 493 494 /* Enter player in high score list */495 453 enter_score(&death_time); 496 454 497 /* Flush all input keys*/455 /* Flush all input and output */ 498 456 flush(); 499 500 /* Flush messages */501 457 message_flush(); 502 458 503 459 504 /* Initialize the menus */ 505 menu_type *menu; 506 const char cmd_keys[] = { ARROW_LEFT, ARROW_RIGHT, '\0' }; 507 const region area = { 51, 2, 0, 6 }; 508 509 int cursor = 0; 510 ui_event_data c = EVENT_EMPTY; 511 512 513 /* options screen selection menu */ 460 /* Initialize the menu */ 514 461 menu = &death_menu; 515 462 WIPE(menu, menu_type); … … 537 484 } 538 485 } 539 540
