]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/score.c
1 /* $NetBSD: score.c,v 1.8 1999/09/12 09:02:23 jsm Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
44 __RCSID("$NetBSD: score.c,v 1.8 1999/09/12 09:02:23 jsm Exp $");
51 * This source herein may be modified and/or distributed by anybody who
52 * so desires, with the following restrictions:
53 * 1.) No portion of this notice shall be removed.
54 * 2.) Credit shall not be taken for the creation of this source.
55 * 3.) This code is not to be traded, sold, or used for personal
62 #include "pathnames.h"
65 killed_by(monster
, other
)
66 const object
*monster
;
74 rogue
.gold
= ((rogue
.gold
* 9) / 10);
80 (void) strcpy(buf
, "died of hypothermia");
83 (void) strcpy(buf
, "died of starvation");
86 (void) strcpy(buf
, "killed by a dart");
89 (void) strcpy(buf
, "quit");
92 (void) strcpy(buf
, "killed by fire");
96 (void) strcpy(buf
, "Killed by ");
97 if (is_vowel(m_names
[monster
->m_char
- 'A'][0])) {
98 (void) strcat(buf
, "an ");
100 (void) strcat(buf
, "a ");
102 (void) strcat(buf
, m_names
[monster
->m_char
- 'A']);
104 (void) strcat(buf
, " with ");
105 sprintf(buf
+strlen(buf
), "%ld gold", rogue
.gold
);
106 if ((!other
) && (!no_skull
)) {
108 mvaddstr(4, 32, "__---------__");
109 mvaddstr(5, 30, "_~ ~_");
110 mvaddstr(6, 29, "/ \\");
111 mvaddstr(7, 28, "~ ~");
112 mvaddstr(8, 27, "/ \\");
113 mvaddstr(9, 27, "| XXXX XXXX |");
114 mvaddstr(10, 27, "| XXXX XXXX |");
115 mvaddstr(11, 27, "| XXX XXX |");
116 mvaddstr(12, 28, "\\ @ /");
117 mvaddstr(13, 29, "--\\ @@@ /--");
118 mvaddstr(14, 30, "| | @@@ | |");
119 mvaddstr(15, 30, "| | | |");
120 mvaddstr(16, 30, "| vvVvvvvvvvVvv |");
121 mvaddstr(17, 30, "| ^^^^^^^^^^^ |");
122 mvaddstr(18, 31, "\\_ _/");
123 mvaddstr(19, 33, "~---------~");
124 center(21, nick_name
);
130 put_scores(monster
, other
);
136 unwield(rogue
.weapon
); /* disarm and relax */
138 un_put_on(rogue
.left_ring
);
139 un_put_on(rogue
.right_ring
);
142 mvaddstr(10, 11, "@ @ @@@ @ @ @ @ @ @@@ @ @ @");
143 mvaddstr(11, 11, " @ @ @ @ @ @ @ @ @ @ @ @@ @ @");
144 mvaddstr(12, 11, " @ @ @ @ @ @ @ @ @ @ @ @ @ @");
145 mvaddstr(13, 11, " @ @ @ @ @ @ @ @ @ @ @ @@");
146 mvaddstr(14, 11, " @ @@@ @@@ @@ @@ @@@ @ @ @");
147 mvaddstr(17, 11, "Congratulations, you have been admitted to the");
148 mvaddstr(18, 11, "Fighters' Guild. You return home, sell all your");
149 mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
154 put_scores((object
*) 0, WIN
);
175 for (i
= 0; i
< DCOLS
; i
++) {
176 buf
[i
] = mvinch(0, i
);
180 message("really quit?", 1);
181 if (rgetchar() != 'y') {
185 for (i
= 0; i
< DCOLS
; i
++) {
186 mvaddch(0, i
, buf
[i
]);
195 clean_up(byebye_string
);
198 killed_by((object
*) 0, QUIT
);
202 put_scores(monster
, other
)
203 const object
*monster
;
206 short i
, n
, rank
= 10, x
, ne
= 0, found_player
= -1;
208 char n_names
[10][30];
212 boolean pause
= score_only
;
217 if ((fp
= fopen(_PATH_SCOREFILE
, "r+")) == NULL
&&
218 (fp
= fopen(_PATH_SCOREFILE
, "w+")) == NULL
) {
220 message("cannot read/write/create score file", 0);
227 for (i
= 0; i
< 10; i
++) {
228 if (((n
= fread(scores
[i
], sizeof(char), 80, fp
)) < 80) && (n
!= 0)) {
232 if ((n
= fread(n_names
[i
], sizeof(char), 30, fp
)) < 30) {
235 xxxx(n_names
[i
], 30);
240 if ((!score_only
) && (found_player
== -1)) {
241 if (!name_cmp(scores
[i
]+15, login_name
)) {
243 while (scores
[i
][x
] == ' ') {
246 s
= lget_number(scores
[i
] + x
);
247 if (rogue
.gold
< s
) {
255 if (found_player
!= -1) {
257 for (i
= found_player
; i
< ne
; i
++) {
258 (void) strcpy(scores
[i
], scores
[i
+1]);
259 (void) strcpy(n_names
[i
], n_names
[i
+1]);
263 for (i
= 0; i
< ne
; i
++) {
265 while (scores
[i
][x
] == ' ') {
268 s
= lget_number(scores
[i
] + x
);
270 if (rogue
.gold
>= s
) {
277 } else if ((ne
< 10) && (rank
== 10)) {
281 insert_score(scores
, n_names
, nick_name
, rank
, ne
,
291 mvaddstr(3, 30, "Top Ten Rogueists");
292 mvaddstr(8, 0, "Rank Score Name");
298 for (i
= 0; i
< ne
; i
++) {
307 scores
[i
][1] = i
+ '1';
309 nickize(buf
, scores
[i
], n_names
[i
]);
310 mvaddstr(i
+10, 0, buf
);
313 fwrite(scores
[i
], sizeof(char), 80, fp
);
314 xxxx(n_names
[i
], 30);
315 fwrite(n_names
[i
], sizeof(char), 30, fp
);
332 insert_score(scores
, n_names
, n_name
, rank
, n
, monster
, other
)
337 const object
*monster
;
344 for (i
= n
; i
> rank
; i
--) {
345 if ((i
< 10) && (i
> 0)) {
346 (void) strcpy(scores
[i
], scores
[i
-1]);
347 (void) strcpy(n_names
[i
], n_names
[i
-1]);
351 sprintf(buf
, "%2d %6ld %s: ", rank
+1, (long)rogue
.gold
,
357 (void) strcat(buf
, "died of hypothermia");
360 (void) strcat(buf
, "died of starvation");
363 (void) strcat(buf
, "killed by a dart");
366 (void) strcat(buf
, "quit");
369 (void) strcat(buf
, "a total winner");
372 (void) strcpy(buf
, "killed by fire");
376 (void) strcat(buf
, "killed by ");
377 if (is_vowel(m_names
[monster
->m_char
- 'A'][0])) {
378 (void) strcat(buf
, "an ");
380 (void) strcat(buf
, "a ");
382 (void) strcat(buf
, m_names
[monster
->m_char
- 'A']);
384 sprintf(buf
+strlen(buf
), " on level %d ", max_level
);
385 if ((other
!= WIN
) && has_amulet()) {
386 (void) strcat(buf
, "with amulet");
388 for (i
= strlen(buf
); i
< 79; i
++) {
392 (void) strcpy(scores
[rank
], buf
);
393 (void) strcpy(n_names
[rank
], n_name
);
400 return( (ch
== 'a') ||
414 obj
= rogue
.pack
.next_object
;
417 mvaddstr(1, 0, "Value Item");
420 if (obj
->what_is
!= FOOD
) {
422 val
= get_value(obj
);
426 sprintf(buf
, "%5d ", val
);
427 get_desc(obj
, buf
+11);
428 mvaddstr(row
++, 0, buf
);
431 obj
= obj
->next_object
;
434 if (rogue
.gold
> MAX_GOLD
) {
435 rogue
.gold
= MAX_GOLD
;
448 wc
= obj
->which_kind
;
450 switch(obj
->what_is
) {
452 val
= id_weapons
[wc
].value
;
453 if ((wc
== ARROW
) || (wc
== DAGGER
) || (wc
== SHURIKEN
) ||
455 val
*= obj
->quantity
;
457 val
+= (obj
->d_enchant
* 85);
458 val
+= (obj
->hit_enchant
* 85);
461 val
= id_armors
[wc
].value
;
462 val
+= (obj
->d_enchant
* 75);
463 if (obj
->is_protected
) {
468 val
= id_wands
[wc
].value
* (obj
->class + 1);
471 val
= id_scrolls
[wc
].value
* obj
->quantity
;
474 val
= id_potions
[wc
].value
* obj
->quantity
;
480 val
= id_rings
[wc
].value
* (obj
->class + 1);
494 for (i
= 0; i
< SCROLS
; i
++) {
495 id_scrolls
[i
].id_status
= IDENTIFIED
;
497 for (i
= 0; i
< WEAPONS
; i
++) {
498 id_weapons
[i
].id_status
= IDENTIFIED
;
500 for (i
= 0; i
< ARMORS
; i
++) {
501 id_armors
[i
].id_status
= IDENTIFIED
;
503 for (i
= 0; i
< WANDS
; i
++) {
504 id_wands
[i
].id_status
= IDENTIFIED
;
506 for (i
= 0; i
< POTIONS
; i
++) {
507 id_potions
[i
].id_status
= IDENTIFIED
;
519 while(s1
[i
] != ':') {
536 for (i
= 0; i
< n
; i
++) {
538 /* It does not matter if accuracy is lost during this assignment */
539 c
= (unsigned char) xxx(0);
557 r
= ((f
* s
) + 9337) % 8887;
564 nickize(buf
, score
, n_name
)
566 const char *score
, *n_name
;
571 (void) strcpy(buf
, score
);
573 (void) strncpy(buf
, score
, 16);
575 while (score
[i
] != ':') {
579 (void) strcpy(buf
+15, n_name
);
583 buf
[j
++] = score
[i
++];
597 margin
= ((DCOLS
- strlen(buf
)) / 2);
598 mvaddstr(row
, margin
, buf
);
606 clean_up("sorry, score file is out of order");