comparison rogue4/rip.c @ 12:9535a08ddc39

Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
author edwarj4
date Sat, 24 Oct 2009 16:52:52 +0000
parents
children 4967c46f1320
comparison
equal deleted inserted replaced
11:949d558c2162 12:9535a08ddc39
1 /*
2 * File for the fun ends
3 * Death or a total win
4 *
5 * @(#)rip.c 4.28 (Berkeley) 4/12/82
6 *
7 * Rogue: Exploring the Dungeons of Doom
8 * Copyright (C) 1980, 1981, 1982 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 <curses.h>
15 #include <time.h>
16 #include <signal.h>
17 #include <sys/types.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include "rogue.h"
21
22 static char *rip[] = {
23 " __________",
24 " / \\",
25 " / REST \\",
26 " / IN \\",
27 " / PEACE \\",
28 " / \\",
29 " | |",
30 " | |",
31 " | killed by a |",
32 " | |",
33 " | 1980 |",
34 " *| * * * | *",
35 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______",
36 0
37 };
38
39 /*
40 * score:
41 * Figure score and post it.
42 */
43 /* VARARGS2 */
44 score(amount, flags, monst)
45 int amount, flags;
46 char monst;
47 {
48 register struct sc_ent *scp;
49 register int i;
50 register struct sc_ent *sc2;
51 register FILE *outf;
52 register int prflags = 0;
53 register void (*fp)(int);
54 register int uid;
55 char scoreline[MAXSTR + 100];
56
57 static struct sc_ent {
58 char sc_name[MAXSTR];
59 unsigned int sc_flags;
60 unsigned int sc_uid;
61 unsigned short sc_monster;
62 unsigned short sc_score;
63 unsigned short sc_level;
64 } top_ten[10];
65 static char *reason[] = {
66 "killed",
67 "quit",
68 "A total winner",
69 };
70 void endit();
71
72 start_score();
73
74 if (fd >= 0)
75 outf = md_fdopen(fd, "wb");
76 else
77 return;
78
79 for (scp = top_ten; scp <= &top_ten[9]; scp++)
80 {
81 scp->sc_score = 0;
82 for (i = 0; i < MAXSTR; i++)
83 scp->sc_name[i] = rnd(255);
84 scp->sc_flags = RN;
85 scp->sc_level = RN;
86 scp->sc_monster = RN;
87 scp->sc_uid = RN;
88 }
89
90 signal(SIGINT, SIG_DFL);
91 if (flags != -1
92 #ifdef WIZARD
93 || wizard
94 #endif
95 )
96 {
97 mvaddstr(LINES - 1, 0 , "[Press return to continue]");
98 refresh();
99 wgetnstr(stdscr,prbuf,80);
100 move(LINES - 1, 0);
101 clrtoeol();
102 refresh();
103 endwin();
104 }
105 #ifdef WIZARD
106 if (wizard)
107 if (strcmp(prbuf, "names") == 0)
108 prflags = 1;
109 else if (strcmp(prbuf, "edit") == 0)
110 prflags = 2;
111 #endif
112 for(i=0; i<10; i++)
113 {
114 encread((char *) &top_ten[i].sc_name, MAXSTR, fd);
115 scoreline[0] = '\0';
116 encread((char *) scoreline, 100, fd);
117 sscanf(scoreline, "%d %d %hd %hd %hd", &top_ten[i].sc_flags,
118 &top_ten[i].sc_uid, &top_ten[i].sc_monster, &top_ten[i].sc_score,
119 &top_ten[i].sc_level);
120 }
121 /*
122 * Insert her in list if need be
123 */
124 sc2 = NULL;
125 if (!noscore)
126 {
127 uid = md_getuid();
128
129 for (scp = top_ten; scp <= &top_ten[9]; scp++)
130 if (amount > scp->sc_score)
131 break;
132 #ifdef LIMIT_TOPTEN
133 else if (flags != 2 && scp->sc_uid == uid && scp->sc_flags != 2)
134 scp = &top_ten[9] + 1; /* only one score per nowin uid */
135 #endif
136 if (scp <= &top_ten[9])
137 {
138 #ifdef LIMIT_TOPTEN
139 if (flags != 2)
140 for (sc2 = scp; sc2 <= &top_ten[9]; sc2++)
141 {
142 if (sc2->sc_uid == uid && sc2->sc_flags != 2)
143 break;
144 }
145 else
146 #endif
147 sc2 = &top_ten[9];
148 while (sc2 > scp)
149 {
150 *sc2 = sc2[-1];
151 sc2--;
152 }
153 scp->sc_score = amount;
154 strncpy(scp->sc_name, whoami, MAXSTR);
155 scp->sc_flags = flags;
156 if (flags == 2)
157 scp->sc_level = max_level;
158 else
159 scp->sc_level = level;
160 scp->sc_monster = monst;
161 scp->sc_uid = uid;
162 sc2 = scp;
163 }
164 }
165 /*
166 * Print the list
167 */
168 printf("Top Ten Rogueists:\nRank\tScore\tName\n");
169 for (scp = top_ten; scp <= &top_ten[9]; scp++)
170 {
171 if (scp->sc_score) {
172 printf("%d\t%d\t%s: %s on level %d", scp - top_ten + 1,
173 scp->sc_score, scp->sc_name, reason[scp->sc_flags],
174 scp->sc_level);
175 if (scp->sc_flags == 0)
176 printf(" by %s", killname((char) scp->sc_monster, TRUE));