Mercurial > hg > early-roguelike
comparison arogue5/rip.c @ 63:0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Thu, 09 Aug 2012 22:58:48 +0000 |
| parents | |
| children | 7aff18a8d508 |
comparison
equal
deleted
inserted
replaced
| 62:0ef99244acb8 | 63:0ed67132cf10 |
|---|---|
| 1 /* | |
| 2 * File for the fun ends | |
| 3 * Death or a total win | |
| 4 * | |
| 5 * Advanced Rogue | |
| 6 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
| 7 * All rights reserved. | |
| 8 * | |
| 9 * Based on "Rogue: Exploring the Dungeons of Doom" | |
| 10 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 11 * All rights reserved. | |
| 12 * | |
| 13 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 14 */ | |
| 15 | |
| 16 /* Print flags for scoring */ | |
| 17 #define REALLIFE 1 /* Print out machine and logname */ | |
| 18 #define EDITSCORE 2 /* Edit the current score file */ | |
| 19 #define ADDSCORE 3 /* Add a new score */ | |
| 20 | |
| 21 #include <fcntl.h> | |
| 22 #include <stdio.h> | |
| 23 #include <stdlib.h> | |
| 24 #include "curses.h" | |
| 25 #include <time.h> | |
| 26 #include <signal.h> | |
| 27 #include <ctype.h> | |
| 28 #include <sys/types.h> | |
| 29 #include "network.h" | |
| 30 #include "rogue.h" | |
| 31 #include "mach_dep.h" | |
| 32 | |
| 33 /* | |
| 34 * If you change this structure, change the compatibility routines | |
| 35 * scoreout() and scorein() to reflect the change. Also update SCORELEN. | |
| 36 */ | |
| 37 | |
| 38 struct sc_ent { | |
| 39 unsigned long sc_score; | |
| 40 char sc_name[LINELEN]; | |
| 41 char sc_system[SYSLEN]; | |
| 42 char sc_login[LOGLEN]; | |
| 43 short sc_flgs; | |
| 44 short sc_level; | |
| 45 short sc_ctype; | |
| 46 short sc_monster; | |
| 47 short sc_quest; | |
| 48 }; | |
| 49 | |
| 50 #define SCORELEN \ | |
| 51 (sizeof(unsigned long) + LINELEN + SYSLEN + LOGLEN + 5*sizeof(short)) | |
| 52 | |
| 53 static char *rip[] = { | |
| 54 " __________", | |
| 55 " / \\", | |
| 56 " / REST \\", | |
| 57 " / IN \\", | |
| 58 " / PEACE \\", | |
| 59 " / \\", | |
| 60 " | |", | |
| 61 " | |", | |
| 62 " | killed by |", | |
| 63 " | |", | |
| 64 " | 1984 |", | |
| 65 " *| * * * | *", | |
| 66 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", | |
| 67 0 | |
| 68 }; | |
| 69 | |
| 70 char *killname(); | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 void | |
| 77 byebye(sig) | |
| 78 int sig; | |
| 79 { | |
| 80 NOOP(sig); | |
| 81 if (!isendwin()) { | |
| 82 clear(); | |
| 83 endwin(); | |
| 84 } | |
| 85 printf("\n"); | |
| 86 exit(0); | |
| 87 } | |
| 88 | |
| 89 | |
| 90 /* | |
| 91 * death: | |
| 92 * Do something really fun when he dies | |
| 93 */ | |
| 94 | |
| 95 death(monst) | |
| 96 register short monst; | |
| 97 { | |
| 98 register char **dp = rip, *killer; | |
| 99 register struct tm *lt; | |
| 100 time_t date; | |
| 101 char buf[80]; | |
| 102 struct tm *localtime(); | |
| 103 | |
| 104 time(&date); | |
| 105 lt = localtime(&date); | |
| 106 clear(); | |
| 107 move(8, 0); | |
| 108 while (*dp) | |
| 109 printw("%s\n", *dp++); | |
| 110 mvaddstr(14, 28-((strlen(whoami)+1)/2), whoami); | |
| 111 sprintf(buf, "%lu Points", pstats.s_exp ); | |
| 112 mvaddstr(15, 28-((strlen(buf)+1)/2), buf); | |
| 113 killer = killname(monst); | |
| 114 mvaddstr(17, 28-((strlen(killer)+1)/2), killer); | |
| 115 mvaddstr(18, 26, (sprintf(prbuf, "%4d", 1900+lt->tm_year), prbuf)); | |
| 116 move(LINES-1, 0); | |
| 117 refresh(); | |
| 118 score(pstats.s_exp, KILLED, monst); | |
| 119 exit(0); | |
| 120 } | |
| 121 | |
| 122 char * | |
| 123 killname(monst) | |
| 124 register short monst; | |
| 125 { | |
| 126 static char mons_name[LINELEN]; | |
| 127 int i; | |
| 128 | |
| 129 if (monst > NUMMONST) return("a strange monster"); | |
| 130 | |
| 131 if (monst >= 0) { | |
| 132 switch (monsters[monst].m_name[0]) { | |
| 133 case 'a': | |
| 134 case 'e': | |
| 135 case 'i': | |
| 136 case 'o': | |
| 137 case 'u': | |
| 138 sprintf(mons_name, "an %s", monsters[monst].m_name); | |
| 139 break; | |
| 140 default: | |
| 141 sprintf(mons_name, "a %s", monsters[monst].m_name); | |
| 142 } | |
| 143 return(mons_name); | |
| 144 } | |
| 145 for (i = 0; i< DEATHNUM; i++) { | |
| 146 if (deaths[i].reason == monst) | |
| 147 break; | |
| 148 } | |
| 149 if (i >= DEATHNUM) | |
| 150 return ("strange death"); | |
| 151 return (deaths[i].name); | |
| 152 } | |
| 153 | |
| 154 | |
| 155 /* | |
| 156 * score -- figure score and post it. | |
| 157 */ | |
| 158 | |
| 159 /* VARARGS2 */ | |
| 160 score(amount, flags, monst) | |
| 161 unsigned long amount; | |
| 162 short monst; | |
| 163 { | |
| 164 static struct sc_ent top_ten[NUMSCORE]; | |
| 165 register struct sc_ent *scp; | |
| 166 register int i; | |
| 167 register struct sc_ent *sc2; | |
| 168 register FILE *outf; | |
| 169 register char *killer; | |
| 170 register int prflags = 0; | |
| 171 register int fd; | |
| 172 short upquest = 0, wintype = 0, uplevel = 0, uptype = 0; /* For network updating */ | |
| 173 char upsystem[SYSLEN], uplogin[LOGLEN]; | |
| 174 char *thissys; /* Holds the name of this system */ | |
| 175 char *compatstr=NULL; /* Holds scores for writing compatible score files */ | |
| 176 #define REASONLEN 3 | |
| 177 static char *reason[] = { | |
| 178 "killed", | |
| 179 "quit", | |
| 180 "A total winner", | |
| 181 "somehow left", | |
| 182 }; | |
| 183 char *packend; | |
| 184 memset(top_ten,0,sizeof(top_ten)); | |
| 185 signal(SIGINT, byebye); | |
| 186 if (flags != WINNER && flags != SCOREIT && flags != UPDATE) { | |
| 187 if (flags == CHICKEN) | |
| 188 packend = "when you quit"; | |
| 189 else | |
| 190 packend = "at your untimely demise"; | |
| 191 mvaddstr(LINES - 1, 0, retstr); | |
| 192 refresh(); | |
| 193 wgetnstr(cw,prbuf,80); | |
| 194 showpack(packend); | |
| 195 } | |
| 196 purse = 0; /* Steal all the gold */ | |
| 197 | |
| 198 /* | |
| 199 * Open file and read list | |
| 200 */ | |
| 201 | |
| 202 if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) | |
| 203 { | |
| 204 printf("\nCannot open score_file.\n"); | |
| 205 return; | |
| 206 } | |
| 207 outf = (FILE *) fdopen(fd, "w"); | |
| 208 | |
| 209 /* Get this system's name */ | |
| 210 thissys = md_gethostname(); | |
| 211 | |
| 212 for (scp = top_ten; scp <= &top_ten[NUMSCORE-1]; scp++) | |
| 213 { | |
| 214 scp->sc_score = 0L; | |
| 215 for (i = 0; i < 80; i++) | |
| 216 scp->sc_name[i] = rnd(255); | |
| 217 scp->sc_quest= RN; | |
| 218 scp->sc_flgs = RN; | |
| 219 scp->sc_level = RN; | |
| 220 scp->sc_monster = RN; | |
| 221 scp->sc_ctype = 0; | |
| 222 strncpy(scp->sc_system, thissys, SYSLEN); | |
| 223 scp->sc_login[0] = '\0'; | |
| 224 } | |
| 225 | |
| 226 /* | |
| 227 * If this is a SCOREIT optin (rogue -s), don't call byebye. The | |
| 228 * endwin() call in byebye() will result in a core dump. | |
| 229 */ | |
| 230 if (flags == SCOREIT) signal(SIGINT, SIG_DFL); | |
| 231 else signal(SIGINT, byebye); | |
| 232 | |
| 233 if (flags != SCOREIT && flags != UPDATE) | |
| 234 { | |
| 235 mvaddstr(LINES - 1, 0, retstr); | |
| 236 refresh(); | |
| 237 fflush(stdout); | |
| 238 wgetnstr(stdscr,prbuf,80); | |
| 239 } | |
| 240 | |
| 241 /* Check for special options */ | |
| 242 if (strcmp(prbuf, "names") == 0) | |
| 243 prflags = REALLIFE; | |
| 244 #ifdef WIZARD | |
| 245 else if (wizard) { | |
| 246 if (strcmp(prbuf, "edit") == 0) prflags = EDITSCORE; | |
| 247 else if (strcmp(prbuf, "add") == 0) { | |
| 248 prflags = ADDSCORE; | |
| 249 waswizard = FALSE; /* We want the new score recorded */ | |
| 250 } | |
| 251 } | |
| 252 #endif | |
| 253 | |
| 254 /* Read the score and convert it to a compatible format */ | |
| 255 scorein(top_ten, fd); /* Convert it */ | |
| 256 | |
| 257 /* Get some values if this is an update */ | |
| 258 if (flags == UPDATE) { | |
| 259 int errcheck, errors = 0; | |
| 260 | |
| 261 upquest = (short) netread(&errcheck, sizeof(short), stdin); | |
| 262 if (errcheck) errors++; | |
| 263 | |
| 264 if (fread(whoami, 1, LINELEN, stdin) != LINELEN) errors++; | |
| 265 | |
| 266 wintype = (short) netread(&errcheck, sizeof(short), stdin); | |
| 267 if (errcheck) errors++; | |
| 268 | |
| 269 uplevel = (short) netread(&errcheck, sizeof(short), stdin); | |
| 270 if (errcheck) errors++; | |
| 271 | |
| 272 uptype = (short) netread(&errcheck, sizeof(short), stdin); | |
| 273 if (errcheck) errors++; | |
| 274 | |
| 275 if (fread(upsystem, 1, SYSLEN, stdin) != SYSLEN) | |
| 276 errors++; | |
| 277 if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN) | |
| 278 errors++; | |
| 279 | |
| 280 if (errors) { | |
| 281 fclose(outf); | |
| 282 free(compatstr); | |
| 283 return; | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 /* | |
| 288 * Insert player in list if need be | |
| 289 */ | |
| 290 if (!waswizard) { | |
| 291 char *login = NULL; | |
| 292 | |
| 293 if (flags != UPDATE) { | |
| 294 login = md_getusername(); | |
| 295 } | |
| 296 | |
| 297 if (flags == UPDATE) | |
| 298 (void) update(top_ten, amount, upquest, whoami, wintype, | |
| 299 uplevel, monst, uptype, upsystem, uplogin); | |
| 300 else { | |
| 301 #ifdef WIZARD | |
| 302 if (prflags == ADDSCORE) { /* Overlay characteristic by new ones */ | |
| 303 char buffer[80]; | |
| 304 int atoi(); | |
| 305 | |
| 306 clear(); | |
| 307 mvaddstr(1, 0, "Score: "); | |
| 308 mvaddstr(2, 0, "Quest (number): "); | |
| 309 mvaddstr(3, 0, "Name: "); | |
| 310 mvaddstr(4, 0, "System: "); | |
| 311 mvaddstr(5, 0, "Login: "); | |
| 312 mvaddstr(6, 0, "Level: "); | |
| 313 mvaddstr(7, 0, "Char type: "); | |
| 314 mvaddstr(8, 0, "Result: "); | |
| 315 | |
| 316 /* Get the score */ | |
| 317 move(1, 7); | |
| 318 get_str(buffer, stdscr); | |
| 319 amount = atol(buffer); | |
| 320 | |
| 321 /* Get the character's quest -- must be a number */ | |
| 322 move(2, 16); | |
| 323 get_str(buffer, stdscr); | |
| 324 quest_item = atoi(buffer); | |
| 325 | |
| 326 /* Get the character's name */ | |
| 327 move(3, 6); | |
| 328 get_str(buffer, stdscr); | |
| 329 strncpy(whoami, buffer, LINELEN); | |
| 330 | |
| 331 /* Get the system */ | |
| 332 move(4, 8); | |
| 333 get_str(buffer, stdscr); | |
| 334 strncpy(thissys, buffer, SYSLEN); | |
| 335 | |
| 336 /* Get the login */ | |
| 337 move(5, 7); | |
| 338 get_str(buffer, stdscr); | |
| 339 strncpy(login, buffer, LOGLEN); | |
| 340 | |
| 341 /* Get the level */ | |
| 342 move(6, 7); | |
| 343 get_str(buffer, stdscr); | |
| 344 level = max_level = (short) atoi(buffer); | |
| 345 | |
| 346 /* Get the character type */ | |
| 347 move(7, 11); | |
| 348 get_str(buffer, stdscr); | |
| 349 switch (buffer[0]) { | |
| 350 case 'F': | |
| 351 case 'f': | |
| 352 default: | |
| 353 player.t_ctype = C_FIGHTER; | |
| 354 break; | |
| 355 | |
| 356 case 'C': | |
| 357 case 'c': | |
| 358 player.t_ctype = C_CLERIC; | |
| 359 break; | |
| 360 | |
| 361 case 'M': | |
| 362 case 'm': | |
| 363 player.t_ctype = C_MAGICIAN; | |
| 364 break; | |
| 365 | |
| 366 case 'T': | |
| 367 case 't': | |
| 368 player.t_ctype = C_THIEF; | |
| 369 break; | |
| 370 } | |
| 371 | |
| 372 /* Get the win type */ | |
| 373 move(8, 8); | |
| 374 get_str(buffer, stdscr); | |
| 375 switch (buffer[0]) { | |
| 376 case 'W': | |
| 377 case 'w': | |
| 378 case 'T': | |
| 379 case 't': | |
| 380 flags = WINNER; | |
