]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/score.c
1 /* $NetBSD: score.c,v 1.11 2003/08/07 09:37:40 agc 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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: score.c,v 1.11 2003/08/07 09:37:40 agc Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
58 #include "pathnames.h"
61 killed_by(monster
, other
)
62 const object
*monster
;
70 rogue
.gold
= ((rogue
.gold
* 9) / 10);
76 (void) strcpy(buf
, "died of hypothermia");
79 (void) strcpy(buf
, "died of starvation");
82 (void) strcpy(buf
, "killed by a dart");
85 (void) strcpy(buf
, "quit");
88 (void) strcpy(buf
, "killed by fire");
92 (void) strcpy(buf
, "Killed by ");
93 if (is_vowel(m_names
[monster
->m_char
- 'A'][0])) {
94 (void) strcat(buf
, "an ");
96 (void) strcat(buf
, "a ");
98 (void) strcat(buf
, m_names
[monster
->m_char
- 'A']);
100 (void) strcat(buf
, " with ");
101 sprintf(buf
+strlen(buf
), "%ld gold", rogue
.gold
);
102 if ((!other
) && (!no_skull
)) {
104 mvaddstr(4, 32, "__---------__");
105 mvaddstr(5, 30, "_~ ~_");
106 mvaddstr(6, 29, "/ \\");
107 mvaddstr(7, 28, "~ ~");
108 mvaddstr(8, 27, "/ \\");
109 mvaddstr(9, 27, "| XXXX XXXX |");
110 mvaddstr(10, 27, "| XXXX XXXX |");
111 mvaddstr(11, 27, "| XXX XXX |");
112 mvaddstr(12, 28, "\\ @ /");
113 mvaddstr(13, 29, "--\\ @@@ /--");
114 mvaddstr(14, 30, "| | @@@ | |");
115 mvaddstr(15, 30, "| | | |");
116 mvaddstr(16, 30, "| vvVvvvvvvvVvv |");
117 mvaddstr(17, 30, "| ^^^^^^^^^^^ |");
118 mvaddstr(18, 31, "\\_ _/");
119 mvaddstr(19, 33, "~---------~");
120 center(21, nick_name
);
126 put_scores(monster
, other
);
132 unwield(rogue
.weapon
); /* disarm and relax */
134 un_put_on(rogue
.left_ring
);
135 un_put_on(rogue
.right_ring
);
138 mvaddstr(10, 11, "@ @ @@@ @ @ @ @ @ @@@ @ @ @");
139 mvaddstr(11, 11, " @ @ @ @ @ @ @ @ @ @ @ @@ @ @");
140 mvaddstr(12, 11, " @ @ @ @ @ @ @ @ @ @ @ @ @ @");
141 mvaddstr(13, 11, " @ @ @ @ @ @ @ @ @ @ @ @@");
142 mvaddstr(14, 11, " @ @@@ @@@ @@ @@ @@@ @ @ @");
143 mvaddstr(17, 11, "Congratulations, you have been admitted to the");
144 mvaddstr(18, 11, "Fighters' Guild. You return home, sell all your");
145 mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
150 put_scores((object
*) 0, WIN
);
171 for (i
= 0; i
< DCOLS
; i
++) {
172 buf
[i
] = mvinch(0, i
);
176 message("really quit?", 1);
177 if (rgetchar() != 'y') {
181 for (i
= 0; i
< DCOLS
; i
++) {
182 mvaddch(0, i
, buf
[i
]);
191 clean_up(byebye_string
);
194 killed_by((object
*) 0, QUIT
);
198 put_scores(monster
, other
)
199 const object
*monster
;
202 short i
, n
, rank
= 10, x
, ne
= 0, found_player
= -1;
204 char n_names
[10][30];
208 boolean dopause
= score_only
;
213 if ((fp
= fopen(_PATH_SCOREFILE
, "r+")) == NULL
&&
214 (fp
= fopen(_PATH_SCOREFILE
, "w+")) == NULL
) {
216 message("cannot read/write/create score file", 0);
223 for (i
= 0; i
< 10; i
++) {
224 if (((n
= fread(scores
[i
], sizeof(char), 80, fp
)) < 80) && (n
!= 0)) {
228 if ((n
= fread(n_names
[i
], sizeof(char), 30, fp
)) < 30) {
231 xxxx(n_names
[i
], 30);
236 if ((!score_only
) && (found_player
== -1)) {
237 if (!name_cmp(scores
[i
]+15, login_name
)) {
239 while (scores
[i
][x
] == ' ') {
242 s
= lget_number(scores
[i
] + x
);
243 if (rogue
.gold
< s
) {
251 if (found_player
!= -1) {
253 for (i
= found_player
; i
< ne
; i
++) {
254 (void) strcpy(scores
[i
], scores
[i
+1]);
255 (void) strcpy(n_names
[i
], n_names
[i
+1]);
259 for (i
= 0; i
< ne
; i
++) {
261 while (scores
[i
][x
] == ' ') {
264 s
= lget_number(scores
[i
] + x
);
266 if (rogue
.gold
>= s
) {
273 } else if ((ne
< 10) && (rank
== 10)) {
277 insert_score(scores
, n_names
, nick_name
, rank
, ne
,
287 mvaddstr(3, 30, "Top Ten Rogueists");
288 mvaddstr(8, 0, "Rank Score Name");
294 for (i
= 0; i
< ne
; i
++) {
303 scores
[i
][1] = i
+ '1';
305 nickize(buf
, scores
[i
], n_names
[i
]);
306 mvaddstr(i
+10, 0, buf
);
309 fwrite(scores
[i
], sizeof(char), 80, fp
);
310 xxxx(n_names
[i
], 30);
311 fwrite(n_names
[i
], sizeof(char), 30, fp
);
328 insert_score(scores
, n_names
, n_name
, rank
, n
, monster
, other
)
333 const object
*monster
;
340 for (i
= n
; i
> rank
; i
--) {
341 if ((i
< 10) && (i
> 0)) {
342 (void) strcpy(scores
[i
], scores
[i
-1]);
343 (void) strcpy(n_names
[i
], n_names
[i
-1]);
347 sprintf(buf
, "%2d %6ld %s: ", rank
+1, (long)rogue
.gold
,
353 (void) strcat(buf
, "died of hypothermia");
356 (void) strcat(buf
, "died of starvation");
359 (void) strcat(buf
, "killed by a dart");
362 (void) strcat(buf
, "quit");
365 (void) strcat(buf
, "a total winner");
368 (void) strcat(buf
, "killed by fire");
372 (void) strcat(buf
, "killed by ");
373 if (is_vowel(m_names
[monster
->m_char
- 'A'][0])) {
374 (void) strcat(buf
, "an ");
376 (void) strcat(buf
, "a ");
378 (void) strcat(buf
, m_names
[monster
->m_char
- 'A']);
380 sprintf(buf
+strlen(buf
), " on level %d ", max_level
);
381 if ((other
!= WIN
) && has_amulet()) {
382 (void) strcat(buf
, "with amulet");
384 for (i
= strlen(buf
); i
< 79; i
++) {
388 (void) strcpy(scores
[rank
], buf
);
389 (void) strcpy(n_names
[rank
], n_name
);
396 return( (ch
== 'a') ||
410 obj
= rogue
.pack
.next_object
;
413 mvaddstr(1, 0, "Value Item");
416 if (obj
->what_is
!= FOOD
) {
418 val
= get_value(obj
);
422 sprintf(buf
, "%5d ", val
);
423 get_desc(obj
, buf
+11);
424 mvaddstr(row
++, 0, buf
);
427 obj
= obj
->next_object
;
430 if (rogue
.gold
> MAX_GOLD
) {
431 rogue
.gold
= MAX_GOLD
;
444 wc
= obj
->which_kind
;
446 switch(obj
->what_is
) {
448 val
= id_weapons
[wc
].value
;
449 if ((wc
== ARROW
) || (wc
== DAGGER
) || (wc
== SHURIKEN
) ||
451 val
*= obj
->quantity
;
453 val
+= (obj
->d_enchant
* 85);
454 val
+= (obj
->hit_enchant
* 85);
457 val
= id_armors
[wc
].value
;
458 val
+= (obj
->d_enchant
* 75);
459 if (obj
->is_protected
) {
464 val
= id_wands
[wc
].value
* (obj
->class + 1);
467 val
= id_scrolls
[wc
].value
* obj
->quantity
;
470 val
= id_potions
[wc
].value
* obj
->quantity
;
476 val
= id_rings
[wc
].value
* (obj
->class + 1);
490 for (i
= 0; i
< SCROLS
; i
++) {
491 id_scrolls
[i
].id_status
= IDENTIFIED
;
493 for (i
= 0; i
< WEAPONS
; i
++) {
494 id_weapons
[i
].id_status
= IDENTIFIED
;
496 for (i
= 0; i
< ARMORS
; i
++) {
497 id_armors
[i
].id_status
= IDENTIFIED
;
499 for (i
= 0; i
< WANDS
; i
++) {
500 id_wands
[i
].id_status
= IDENTIFIED
;
502 for (i
= 0; i
< POTIONS
; i
++) {
503 id_potions
[i
].id_status
= IDENTIFIED
;
515 while(s1
[i
] != ':') {
532 for (i
= 0; i
< n
; i
++) {
534 /* It does not matter if accuracy is lost during this assignment */
535 c
= (unsigned char) xxx(0);
553 r
= ((f
* s
) + 9337) % 8887;
560 nickize(buf
, score
, n_name
)
562 const char *score
, *n_name
;
567 (void) strcpy(buf
, score
);
569 (void) strncpy(buf
, score
, 16);
571 while (score
[i
] != ':') {
575 (void) strcpy(buf
+15, n_name
);
579 buf
[j
++] = score
[i
++];
593 margin
= ((DCOLS
- strlen(buf
)) / 2);
594 mvaddstr(row
, margin
, buf
);
602 clean_up("sorry, score file is out of order");