Mercurial > hg > early-roguelike
comparison rogue3/rip.c @ 0:527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
| author | edwarj4 |
|---|---|
| date | Tue, 13 Oct 2009 13:33:34 +0000 |
| parents | |
| children | d388234c4ce9 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:527e2150eaf0 |
|---|---|
| 1 /* | |
| 2 * File for the fun ends | |
| 3 * Death or a total win | |
| 4 * | |
| 5 * @(#)rip.c 3.13 (Berkeley) 6/16/81 | |
| 6 * | |
| 7 * Rogue: Exploring the Dungeons of Doom | |
| 8 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 9 * All rights reserved. | |
| 10 * | |
| 11 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 12 */ | |
| 13 | |
| 14 #include <stdlib.h> | |
| 15 #include <errno.h> | |
| 16 #include <time.h> | |
| 17 #include <signal.h> | |
| 18 #include <ctype.h> | |
| 19 #include <sys/types.h> | |
| 20 #include <fcntl.h> | |
| 21 #include <string.h> | |
| 22 #include "curses.h" | |
| 23 #include "machdep.h" | |
| 24 #include "rogue.h" | |
| 25 | |
| 26 static char *rip[] = { | |
| 27 " __________", | |
| 28 " / \\", | |
| 29 " / REST \\", | |
| 30 " / IN \\", | |
| 31 " / PEACE \\", | |
| 32 " / \\", | |
| 33 " | |", | |
| 34 " | |", | |
| 35 " | killed by a |", | |
| 36 " | |", | |
| 37 " | 1980 |", | |
| 38 " *| * * * | *", | |
| 39 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", | |
| 40 0 | |
| 41 }; | |
| 42 | |
| 43 char *killname(); | |
| 44 | |
| 45 /* | |
| 46 * death: | |
| 47 * Do something really fun when he dies | |
| 48 */ | |
| 49 | |
| 50 void | |
| 51 death(int monst) | |
| 52 { | |
| 53 char **dp = rip, *killer; | |
| 54 struct tm *lt; | |
| 55 time_t date; | |
| 56 char buf[80]; | |
| 57 | |
| 58 time(&date); | |
| 59 lt = localtime(&date); | |
| 60 clear(); | |
| 61 move(8, 0); | |
| 62 while (*dp) | |
| 63 printw("%s\n", *dp++); | |
| 64 mvaddstr(14, 28-(((int)strlen(whoami)+1)/2), whoami); | |
| 65 purse -= purse/10; | |
| 66 sprintf(buf, "%d Au", purse); | |
| 67 mvaddstr(15, 28-(((int)strlen(buf)+1)/2), buf); | |
| 68 killer = killname(monst); | |
| 69 mvaddstr(17, 28-(((int)strlen(killer)+1)/2), killer); | |
| 70 mvaddstr(16, 33, vowelstr(killer)); | |
| 71 sprintf(prbuf, "%4d", 1900+lt->tm_year); | |
| 72 mvaddstr(18, 26, prbuf); | |
| 73 move(LINES-1, 0); | |
| 74 draw(stdscr); | |
| 75 score(purse, 0, monst); | |
| 76 exit(0); | |
| 77 } | |
| 78 | |
| 79 /* | |
| 80 * score -- figure score and post it. | |
| 81 */ | |
| 82 | |
| 83 void | |
| 84 open_score(void) | |
| 85 { | |
| 86 #ifdef SCOREFILE | |
| 87 char *scorefile = SCOREFILE; | |
| 88 | |
| 89 if (scoreboard != NULL) { | |
| 90 rewind(scoreboard); | |
| 91 return; | |
| 92 } | |
| 93 | |
| 94 scoreboard = fopen(scorefile, "r+"); | |
| 95 | |
| 96 if ((scoreboard == NULL) && (errno == ENOENT)) | |
| 97 { | |
| 98 scoreboard = fopen(scorefile, "w+"); | |
| 99 md_chmod(scorefile,0664); | |
| 100 } | |
| 101 | |
| 102 if (scoreboard == NULL) { | |
| 103 fprintf(stderr, "Could not open %s for writing: %s\n", scorefile, strerror(errno)); | |
| 104 fflush(stderr); | |
| 105 } | |
| 106 #else | |
| 107 scoreboard = NULL; | |
| 108 #endif | |
| 109 } | |
| 110 | |
| 111 /* VARARGS2 */ | |
| 112 void | |
| 113 score(int amount, int flags, int monst) | |
| 114 { | |
| 115 static struct sc_ent { | |
| 116 int sc_score; | |
| 117 char sc_name[80]; | |
| 118 int sc_flags; | |
| 119 int sc_level; | |
| 120 char sc_login[8]; | |
| 121 int sc_monster; | |
| 122 } top_ten[10]; | |
| 123 struct sc_ent *scp; | |
| 124 int i; | |
| 125 struct sc_ent *sc2; | |
| 126 FILE *outf; | |
| 127 char *killer; | |
| 128 int prflags = 0; | |
| 129 static char *reason[] = { | |
| 130 "killed", | |
| 131 "quit", | |
| 132 "A total winner", | |
| 133 }; | |
| 134 char scoreline[100]; | |
| 135 int rogue_ver = 0, scorefile_ver = 0; | |
| 136 | |
| 137 /* | |
| 138 * Open file and read list | |
| 139 */ | |
| 140 | |
| 141 if (scoreboard == NULL) | |
| 142 return; | |
| 143 | |
| 144 outf = scoreboard; | |
| 145 | |
| 146 for (scp = top_ten; scp <= &top_ten[9]; scp++) | |
| 147 { | |
| 148 scp->sc_score = 0; | |
| 149 for (i = 0; i < 80; i++) | |
| 150 scp->sc_name[i] = rnd(255); | |
| 151 scp->sc_flags = RN; | |
| 152 scp->sc_level = RN; | |
| 153 scp->sc_monster = RN; | |
| 154 scp->sc_login[0] = '\0'; | |
| 155 } | |
| 156 | |
| 157 signal(SIGINT, SIG_DFL); | |
| 158 if ((flags != -1) && (flags != 1)) | |
| 159 { | |
| 160 mvaddstr(LINES-1, 0, "[Press return to continue]"); | |
| 161 draw(stdscr); | |
| 162 prbuf[0] = 0; | |
| 163 get_str(prbuf, stdscr); | |
| 164 endwin(); | |
| 165 } | |
| 166 if (wizard) | |
| 167 if (strcmp(prbuf, "names") == 0) | |
| 168 prflags = 1; | |
| 169 else if (strcmp(prbuf, "edit") == 0) | |
| 170 prflags = 2; | |
| 171 | |
| 172 md_lockfile(outf); | |
| 173 | |
| 174 encread(scoreline, 100, outf); | |
| 175 (void) sscanf(scoreline, "R%d %d\n", &rogue_ver, &scorefile_ver); | |
| 176 | |
| 177 if ((rogue_ver == 36) && (scorefile_ver == 2)) | |
| 178 for(i = 0; i < 10; i++) | |
| 179 |
