Mercurial > hg > early-roguelike
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arogue5/rip.c Thu Aug 09 22:58:48 2012 +0000 @@ -0,0 +1,768 @@ +/* + * File for the fun ends + * Death or a total win + * + * Advanced Rogue + * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T + * All rights reserved. + * + * Based on "Rogue: Exploring the Dungeons of Doom" + * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman + * All rights reserved. + * + * See the file LICENSE.TXT for full copyright and licensing information. + */ + +/* Print flags for scoring */ +#define REALLIFE 1 /* Print out machine and logname */ +#define EDITSCORE 2 /* Edit the current score file */ +#define ADDSCORE 3 /* Add a new score */ + +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include "curses.h" +#include <time.h> +#include <signal.h> +#include <ctype.h> +#include <sys/types.h> +#include "network.h" +#include "rogue.h" +#include "mach_dep.h" + +/* + * If you change this structure, change the compatibility routines + * scoreout() and scorein() to reflect the change. Also update SCORELEN. + */ + +struct sc_ent { + unsigned long sc_score; + char sc_name[LINELEN]; + char sc_system[SYSLEN]; + char sc_login[LOGLEN]; + short sc_flgs; + short sc_level; + short sc_ctype; + short sc_monster; + short sc_quest; +}; + +#define SCORELEN \ + (sizeof(unsigned long) + LINELEN + SYSLEN + LOGLEN + 5*sizeof(short)) + +static char *rip[] = { +" __________", +" / \\", +" / REST \\", +" / IN \\", +" / PEACE \\", +" / \\", +" | |", +" | |", +" | killed by |", +" | |", +" | 1984 |", +" *| * * * | *", +" ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", + 0 +}; + +char *killname(); + + + + + +void +byebye(sig) +int sig; +{ + NOOP(sig); + if (!isendwin()) { + clear(); + endwin(); + } + printf("\n"); + exit(0); +} + + +/* + * death: + * Do something really fun when he dies + */ + +death(monst) +register short monst; +{ + register char **dp = rip, *killer; + register struct tm *lt; + time_t date; + char buf[80]; + struct tm *localtime(); + + time(&date); + lt = localtime(&date); + clear(); + move(8, 0); + while (*dp) + printw("%s\n", *dp++); + mvaddstr(14, 28-((strlen(whoami)+1)/2), whoami); + sprintf(buf, "%lu Points", pstats.s_exp ); + mvaddstr(15, 28-((strlen(buf)+1)/2), buf); + killer = killname(monst); + mvaddstr(17, 28-((strlen(killer)+1)/2), killer); + mvaddstr(18, 26, (sprintf(prbuf, "%4d", 1900+lt->tm_year), prbuf)); + move(LINES-1, 0); + refresh(); + score(pstats.s_exp, KILLED, monst); + exit(0); +} + +char * +killname(monst) +register short monst; +{ + static char mons_name[LINELEN]; + int i; + + if (monst > NUMMONST) return("a strange monster"); + + if (monst >= 0) { + switch (monsters[monst].m_name[0]) { + case 'a': + case 'e': + case 'i': + case 'o': + case 'u': + sprintf(mons_name, "an %s", monsters[monst].m_name); + break; + default: + sprintf(mons_name, "a %s", monsters[monst].m_name); + } + return(mons_name); + } + for (i = 0; i< DEATHNUM; i++) { + if (deaths[i].reason == monst) + break; + } + if (i >= DEATHNUM) + return ("strange death"); + return (deaths[i].name); +} + + +/* + * score -- figure score and post it. + */ + +/* VARARGS2 */ +score(amount, flags, monst) +unsigned long amount; +short monst; +{ + static struct sc_ent top_ten[NUMSCORE]; + register struct sc_ent *scp; + register int i; + register struct sc_ent *sc2; + register FILE *outf; + register char *killer; + register int prflags = 0; + register int fd; + short upquest = 0, wintype = 0, uplevel = 0, uptype = 0; /* For network updating */ + char upsystem[SYSLEN], uplogin[LOGLEN]; + char *thissys; /* Holds the name of this system */ + char *compatstr=NULL; /* Holds scores for writing compatible score files */ +#define REASONLEN 3 + static char *reason[] = { + "killed", + "quit", + "A total winner", + "somehow left", + }; + char *packend; + memset(top_ten,0,sizeof(top_ten)); + signal(SIGINT, byebye); + if (flags != WINNER && flags != SCOREIT && flags != UPDATE) { + if (flags == CHICKEN) + packend = "when you quit"; + else + packend = "at your untimely demise"; + mvaddstr(LINES - 1, 0, retstr); + refresh(); + wgetnstr(cw,prbuf,80); + showpack(packend); + } + purse = 0; /* Steal all the gold */ + + /* + * Open file and read list + */ + + if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) + { + printf("\nCannot open score_file.\n"); + return; + } + outf = (FILE *) fdopen(fd, "w"); + + /* Get this system's name */ + thissys = md_gethostname(); + + for (scp = top_ten; scp <= &top_ten[NUMSCORE-1]; scp++) + { + scp->sc_score = 0L; + for (i = 0; i < 80; i++) + scp->sc_name[i] = rnd(255); + scp->sc_quest= RN; + scp->sc_flgs = RN; + scp->sc_level = RN; + scp->sc_monster = RN; + scp->sc_ctype = 0; + strncpy(scp->sc_system, thissys, SYSLEN); + scp->sc_login[0] = '\0'; + } + + /* + * If this is a SCOREIT optin (rogue -s), don't call byebye. The + * endwin() call in byebye() will result in a core dump. + */ + if (flags == SCOREIT) signal(SIGINT, SIG_DFL); + else signal(SIGINT, byebye); + + if (flags != SCOREIT && flags != UPDATE) + { + mvaddstr(LINES - 1, 0, retstr); + refresh(); + fflush(stdout); + wgetnstr(stdscr,prbuf,80); + } + + /* Check for special options */ + if (strcmp(prbuf, "names") == 0) + prflags = REALLIFE; +#ifdef WIZARD + else if (wizard) { + if (strcmp(prbuf, "edit") == 0) prflags = EDITSCORE; + else if (strcmp(prbuf, "add") == 0) { + prflags = ADDSCORE; + waswizard = FALSE; /* We want the new score recorded */ + } + } +#endif + + /* Read the score and convert it to a compatible format */ + scorein(top_ten, fd); /* Convert it */ + + /* Get some values if this is an update */ + if (flags == UPDATE) { + int errcheck, errors = 0; + + upquest = (short) netread(&errcheck, sizeof(short), stdin); + if (errcheck) errors++; + + if (fread(whoami, 1, LINELEN, stdin) != LINELEN) errors++; + + wintype = (short) netread(&errcheck, sizeof(short), stdin); + if (errcheck) errors++; + + uplevel = (short) netread(&errcheck, sizeof(short), stdin); + if (errcheck) errors++; + + uptype = (short) netread(&errcheck, sizeof(short), stdin); + if (errcheck) errors++; + + if (fread(upsystem, 1, SYSLEN, stdin) != SYSLEN) + errors++; + if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN) + errors++; + + if (errors) { + fclose(outf); + free(compatstr); + return; + } + } + + /* + * Insert player in list if need be + */ + if (!waswizard) { + char *login = NULL; + + if (flags != UPDATE) { + login = md_getusername(); + } + + if (flags == UPDATE) + (void) update(top_ten, amount, upquest, whoami, wintype, + uplevel, monst, uptype, upsystem, uplogin); + else { +#ifdef WIZARD + if (prflags == ADDSCORE) { /* Overlay characteristic by new ones */ + char buffer[80]; + int atoi(); + + clear(); + mvaddstr(1, 0, "Score: "); + mvaddstr(2, 0, "Quest (number): "); + mvaddstr(3, 0, "Name: "); + mvaddstr(4, 0, "System: "); + mvaddstr(5, 0, "Login: "); + mvaddstr(6, 0, "Level: "); + mvaddstr(7, 0, "Char type: "); + mvaddstr(8, 0, "Result: "); + + /* Get the score */ + move(1, 7); + get_str(buffer, stdscr);
