comparison urogue/rip.c @ 256:c495a4f288c6

Import UltraRogue from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Tue, 31 Jan 2017 19:56:04 -0500
parents
children 911f0aa6e758
comparison
equal deleted inserted replaced
253:d9badb9c0179 256:c495a4f288c6
1 /*
2 rip.c - File for the fun ends Death or a total win
3
4 UltraRogue: The Ultimate Adventure in the Dungeons of Doom
5 Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong
6 All rights reserved.
7
8 Based on "Advanced Rogue"
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka
10 All rights reserved.
11
12 Based on "Rogue: Exploring the Dungeons of Doom"
13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
14 All rights reserved.
15
16 See the file LICENSE.TXT for full copyright and licensing information.
17 */
18
19 #include <string.h>
20 #include <stdlib.h>
21 #include <ctype.h>
22 #include <time.h>
23 #include "rogue.h"
24
25 static struct sc_ent
26 {
27 int sc_lvl;
28 long sc_score;
29 char sc_name[76];
30 long sc_gold;
31 int sc_flags;
32 int sc_level;
33 int sc_artifacts;
34 int sc_monster;
35 } top_ten[10];
36
37
38 static const char *rip[] =
39 {
40 " __________",
41 " / \\",
42 " / REST \\",
43 " / IN \\",
44 " / PEACE \\",
45 " / \\",
46 " | |",
47 " | |",
48 " | killed by |",
49 " | |",
50 " | 1993 |",
51 " *| * * * | *",
52 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______",
53 0
54 };
55
56 /*
57 death()
58 Do something really fun when he dies
59 */
60
61 void
62 death(int monst)
63 {
64 char **dp = (char **) rip, *killer;
65 struct tm *lt;
66 time_t date;
67 char buf[80];
68 int c;
69
70 if (is_wearing(R_RESURRECT) || rnd(wizard ? 3 : 67) == 0)
71 {
72 int die = TRUE;
73
74 if (resurrect-- == 0)
75 msg("You've run out of lives.");
76 else if (!save_resurrect(ring_value(R_RESURRECT)))
77 msg("Your attempt to return from the grave fails.");
78 else
79 {
80 struct linked_list *item;
81 struct linked_list *next_item;
82 struct object *obj;
83 int rm, flags;
84 coord pos;
85
86 die = FALSE;
87 msg("You feel a sudden warmth and then nothingness.");
88 teleport();
89
90 if (ring_value(R_RESURRECT) > 1 && rnd(10))
91 {
92 pstats.s_hpt = 2 * pstats.s_const;
93 pstats.s_const = max(pstats.s_const - 1, 3);
94 }
95 else
96 {
97 for (item = pack; item != NULL; item = next_item)
98 {
99 obj = OBJPTR(item);
100
101 if (obj->o_flags & ISOWNED || obj->o_flags & ISPROT)
102 {
103 next_item = next(item);
104 continue;
105 }
106
107 flags = obj->o_flags;
108 obj->o_flags &= ~ISCURSED;
109 dropcheck(obj);
110 obj->o_flags = flags;
111 next_item = next(item);
112 rem_pack(obj);
113
114 if (obj->o_type == ARTIFACT)
115 has_artifact &= ~(1 << obj->o_which);
116
117 do
118 {
119 rm = rnd_room();
120 rnd_pos(&rooms[rm], &pos);
121 }
122 while(winat(pos.y, pos.x) != FLOOR);
123
124 obj->o_pos = pos;
125 add_obj(item, obj->o_pos.y, obj->o_pos.x);
126 }
127
128 pstats.s_hpt = pstats.s_const;
129 pstats.s_const = max(pstats.s_const - roll(2, 2), 3);
130 }
131
132 chg_str(roll(1, 4), TRUE, FALSE);
133 pstats.s_lvl = max(pstats.s_lvl, 1);
134 no_command += 2 + rnd(4);
135
136 if (on(player, ISHUH))
137 lengthen_fuse(FUSE_UNCONFUSE, rnd(8) + HUHDURATION);
138 else
139 light_fuse(FUSE_UNCONFUSE, 0, rnd(8) + HUHDURATION, AFTER);
140
141 turn_on(player, ISHUH);
142 light(&hero);
143 }
144
145 if (die)
146 {
147 wmove(cw, mpos, 0);
148 waddstr(cw, morestr);
149 wrefresh(cw);
150 wait_for(' ');
151 }
152 else
153 return;
154 }
155
156 time(&date);
157 lt = localtime(&date);
158 clear();
159 wclear(cw);
160 move(8, 0);
161
162 while (*dp)
163 printw("%s\n", *dp++);
164
165 mvaddstr(14, 28 - ((int)(strlen(whoami) + 1) / 2), whoami);
166 sprintf(buf, "%d+%ld Points", pstats.s_lvl, pstats.s_exp);
167 mvaddstr(15, 28 - ((int)(strlen(buf) + 1) / 2), buf);
168 killer = killname(monst,buf);
169 mvaddstr(17, 28 - ((int)(strlen(killer) + 1) / 2), killer);
170 mvaddstr(18, 28, (sprintf(prbuf, "%2d", lt->tm_year), prbuf));
171 move(LINES - 1, 0);
172
173 mvaddstr(LINES - 1, 0, retstr);
174
175 while ((c = readcharw(stdscr)) != '\n' && c != '\r')
176 continue;
177 idenpack();
178 wrefresh(cw);
179 refresh();
180
181 score(pstats.s_exp, pstats.s_lvl, KILLED, monst);
182 byebye();
183 }
184
185 /*
186 score()
187 figure score and post it.
188 */
189
190 void
191 score(long amount, int lvl, int flags, int monst) /*ARGSUSED*/
192 {
193 struct sc_ent *scp=NULL, *sc2=NULL;
194 int i;
195 char *killer;
196 char buf[1024];
197
198 static const char *reason[] =
199 {
200 "killed",
201 "quit",
202 "a winner",
203 "a total winner"
204 };
205
206 char *packend;
207
208 if (flags != WINNER && flags != TOTAL && flags != SCOREIT)
209 {
210 if (flags == CHICKEN)
211 packend = "when you quit";
212 else
213 packend = "at your untimely demise";
214
215 noecho();
216 nl();
217 refresh();
218 showpack(packend);
219 }
220
221 /* Open file and read list */
222
223 if (fd_score == NULL)
224 {
225 printf("No score file opened\n");
226 return;
227 }
228
229 for (scp = top_ten; scp < &top_ten[10]; scp++)
230 {
231 scp->sc_lvl = 0L;
232 scp->sc_score = 0L;
233
234 for (i = 0; i < 76; i++)
235 scp->sc_name[i] = ucrnd(255);
236
237 scp->sc_gold = 0L;
238 scp->sc_flags = rnd(10);
239 scp->sc_level = rnd(10);
240 scp->sc_monster = srnd(10);
241 scp->sc_artifacts = 0;
242 }
243
244 if (flags != SCOREIT)
245 {
246 mvaddstr(LINES - 1, 0, retstr);
247 refresh();
248 fflush(stdout);
249 wait_for('\n');
250 }
251
252 fseek(fd_score, 0L, SEEK_SET);
253 fread(top_ten, sizeof(top_ten), 1, fd_score);
254
255 /* Insert player in list if need be */
256
257 if (!waswizard)
258 {
259 for (scp = top_ten; scp < &top_ten[10]; scp++)
260 {
261 if (lvl > scp->sc_lvl)
262 break;
263
264 if (lvl == scp->sc_lvl && amount > scp->sc_score)
265 break;
266 }
267
268 if (scp < &top_ten[10])
269 {
270 if (flags == WINNER)
271 sc2 = &top_ten[9]; /* LAST WINNER ALWAYS MAKES IT */
272
273 while (sc2 > scp)
274 {
275 *sc2 = sc2[-1];
276 sc2--;
277 }
278
279 scp->sc_lvl = lvl;
280 scp->sc_gold = purse;
281 scp->sc_score = amount;
282 strcpy(scp->sc_name, whoami);
283 strcat(scp->sc_name,", ");
284 strcat(scp->sc_name, which_class(player.t_ctype));
285 scp->sc_flags = flags;
286
287 if (flags == WINNER)
288 scp->sc_level = max_level;
289 else
290 scp->sc_level = level;
291
292 scp->sc_monster = monst;
293 scp->sc_artifacts = has_artifact;
294
295 sc2 = scp;
296 }
297 }
298
299 if (flags != SCOREIT)
300 {
301 clear();
302 refresh();
303 endwin();
304 }
305
306 /* Print the list */
307
308 printf("\nTop Ten Adventurers:\n%4s %15s %10s %s\n",
309 "Rank", "Score", "Gold", "Name");
310
311 for (scp = top_ten; scp < &top_ten[10]; scp++)
312 {
313 if (scp->sc_score)
314 {
315 char lev[20];
316
317 sprintf(lev, "%ld+%ld", scp->sc_lvl, scp->sc_score);
318 printf("%4d %15s %10ld %s:", scp - top_ten + 1,
319 lev,
320 scp->sc_gold,
321 scp->sc_name);
322
323 if (scp->sc_artifacts)
324 {
325 char thangs[80];
326 int n;
327 int first = TRUE;
328
329 thangs[0] = '\0';
330
331 for (n = 0; n <= maxartifact; n++)
332 {
333 if (scp->sc_artifacts & (1 << n))
334 {
335 if (strlen(thangs))
336 strcat(thangs, ", ");
337
338 if (first)
339 {
340 strcat(thangs, "retrieved ");
341 first = FALSE;
342 }
343
344 if (45 - strlen(thangs) < strlen(arts[n].ar_name))
345 {
346 printf("%s\n%32s", thangs," ");
347 thangs[0] = '\0';
348 }
349 strcat(thangs, arts[n].ar_name);
350 }
351 }
352
353 if (strlen(thangs))
354 printf("%s,", thangs);
355
356 printf("\n%32s"," ");
357 }
358
359 printf("%s on level %d",reason[scp->sc_flags],scp->sc_level);
360
361 if (scp->sc_flags == 0)
362 {
363 printf(" by \n%32s"," ");
364 killer = killname(scp->sc_monster, buf);
365 printf(" %s", killer);
366 }
367
368 putchar('\n');
369 }
370 }
371
372 if (sc2 != NULL)
373 {