]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/score.c
2 * Copyright (c) 1988 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 /*static char sccsid[] = "from: @(#)score.c 5.5 (Berkeley) 6/1/90";*/
39 static char rcsid
[] = "$Id: score.c,v 1.4 1993/11/10 10:02:20 cgd Exp $";
45 * This source herein may be modified and/or distributed by anybody who
46 * so desires, with the following restrictions:
47 * 1.) No portion of this notice shall be removed.
48 * 2.) Credit shall not be taken for the creation of this source.
49 * 3.) This code is not to be traded, sold, or used for personal
56 #include "pathnames.h"
58 extern char login_name
[];
59 extern char *m_names
[];
60 extern short max_level
;
61 extern boolean score_only
, no_skull
, msg_cleared
;
62 extern char *byebye_string
, *nick_name
;
64 killed_by(monster
, other
)
73 rogue
.gold
= ((rogue
.gold
* 9) / 10);
79 (void) strcpy(buf
, "died of hypothermia");
82 (void) strcpy(buf
, "died of starvation");
85 (void) strcpy(buf
, "killed by a dart");
88 (void) strcpy(buf
, "quit");
91 (void) strcpy(buf
, "killed by fire");
95 (void) strcpy(buf
, "Killed by ");
96 if (is_vowel(m_names
[monster
->m_char
- 'A'][0])) {
97 (void) strcat(buf
, "an ");
99 (void) strcat(buf
, "a ");
101 (void) strcat(buf
, m_names
[monster
->m_char
- 'A']);
103 (void) strcat(buf
, " with ");
104 sprintf(buf
+strlen(buf
), "%ld gold", rogue
.gold
);
105 if ((!other
) && (!no_skull
)) {
107 mvaddstr(4, 32, "__---------__");
108 mvaddstr(5, 30, "_~ ~_");
109 mvaddstr(6, 29, "/ \\");
110 mvaddstr(7, 28, "~ ~");
111 mvaddstr(8, 27, "/ \\");
112 mvaddstr(9, 27, "| XXXX XXXX |");
113 mvaddstr(10, 27, "| XXXX XXXX |");
114 mvaddstr(11, 27, "| XXX XXX |");
115 mvaddstr(12, 28, "\\ @ /");
116 mvaddstr(13, 29, "--\\ @@@ /--");
117 mvaddstr(14, 30, "| | @@@ | |");
118 mvaddstr(15, 30, "| | | |");
119 mvaddstr(16, 30, "| vvVvvvvvvvVvv |");
120 mvaddstr(17, 30, "| ^^^^^^^^^^^ |");
121 mvaddstr(18, 31, "\\_ _/");
122 mvaddstr(19, 33, "~---------~");
123 center(21, nick_name
);
129 put_scores(monster
, other
);
134 unwield(rogue
.weapon
); /* disarm and relax */
136 un_put_on(rogue
.left_ring
);
137 un_put_on(rogue
.right_ring
);
140 mvaddstr(10, 11, "@ @ @@@ @ @ @ @ @ @@@ @ @ @");
141 mvaddstr(11, 11, " @ @ @ @ @ @ @ @ @ @ @ @@ @ @");
142 mvaddstr(12, 11, " @ @ @ @ @ @ @ @ @ @ @ @ @ @");
143 mvaddstr(13, 11, " @ @ @ @ @ @ @ @ @ @ @ @@");
144 mvaddstr(14, 11, " @ @@@ @@@ @@ @@ @@@ @ @ @");
145 mvaddstr(17, 11, "Congratulations, you have been admitted to the");
146 mvaddstr(18, 11, "Fighters' Guild. You return home, sell all your");
147 mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
152 put_scores((object
*) 0, WIN
);
170 for (i
= 0; i
< DCOLS
; i
++) {
171 buf
[i
] = mvinch(0, i
);
175 message("really quit?", 1);
176 if (rgetchar() != 'y') {
180 for (i
= 0; i
< DCOLS
; i
++) {
181 mvaddch(0, i
, buf
[i
]);
190 clean_up(byebye_string
);
193 killed_by((object
*) 0, QUIT
);
196 put_scores(monster
, other
)
200 short i
, n
, rank
= 10, x
, ne
= 0, found_player
= -1;
202 char n_names
[10][30];
206 boolean pause
= score_only
;
210 if ((fp
= fopen(_PATH_SCOREFILE
, "r+")) == NULL
&&
211 (fp
= fopen(_PATH_SCOREFILE
, "w+")) == NULL
) {
212 message("cannot read/write/create score file", 0);
218 for (i
= 0; i
< 10; i
++) {
219 if (((n
= fread(scores
[i
], sizeof(char), 80, fp
)) < 80) && (n
!= 0)) {
223 if ((n
= fread(n_names
[i
], sizeof(char), 30, fp
)) < 30) {
226 xxxx(n_names
[i
], 30);
231 if ((!score_only
) && (found_player
== -1)) {
232 if (!name_cmp(scores
[i
]+15, login_name
)) {
234 while (scores
[i
][x
] == ' ') {
237 s
= lget_number(scores
[i
] + x
);
238 if (rogue
.gold
< s
) {
246 if (found_player
!= -1) {
248 for (i
= found_player
; i
< ne
; i
++) {
249 (void) strcpy(scores
[i
], scores
[i
+1]);
250 (void) strcpy(n_names
[i
], n_names
[i
+1]);
254 for (i
= 0; i
< ne
; i
++) {
256 while (scores
[i
][x
] == ' ') {
259 s
= lget_number(scores
[i
] + x
);
261 if (rogue
.gold
>= s
) {
268 } else if ((ne
< 10) && (rank
== 10)) {
272 insert_score(scores
, n_names
, nick_name
, rank
, ne
, monster
,
282 mvaddstr(3, 30, "Top Ten Rogueists");
283 mvaddstr(8, 0, "Rank Score Name");
289 for (i
= 0; i
< ne
; i
++) {
298 scores
[i
][1] = i
+ '1';
300 nickize(buf
, scores
[i
], n_names
[i
]);
301 mvaddstr(i
+10, 0, buf
);
304 fwrite(scores
[i
], sizeof(char), 80, fp
);
305 xxxx(n_names
[i
], 30);
306 fwrite(n_names
[i
], sizeof(char), 30, fp
);
322 insert_score(scores
, n_names
, n_name
, rank
, n
, monster
, other
)
333 for (i
= n
; i
> rank
; i
--) {
334 if ((i
< 10) && (i
> 0)) {
335 (void) strcpy(scores
[i
], scores
[i
-1]);
336 (void) strcpy(n_names
[i
], n_names
[i
-1]);
340 sprintf(buf
, "%2d %6d %s: ", rank
+1, rogue
.gold
, login_name
);
345 (void) strcat(buf
, "died of hypothermia");
348 (void) strcat(buf
, "died of starvation");
351 (void) strcat(buf
, "killed by a dart");
354 (void) strcat(buf
, "quit");
357 (void) strcat(buf
, "a total winner");
360 (void) strcpy(buf
, "killed by fire");
364 (void) strcat(buf
, "killed by ");
365 if (is_vowel(m_names
[monster
->m_char
- 'A'][0])) {
366 (void) strcat(buf
, "an ");
368 (void) strcat(buf
, "a ");
370 (void) strcat(buf
, m_names
[monster
->m_char
- 'A']);
372 sprintf(buf
+strlen(buf
), " on level %d ", max_level
);
373 if ((other
!= WIN
) && has_amulet()) {
374 (void) strcat(buf
, "with amulet");
376 for (i
= strlen(buf
); i
< 79; i
++) {
380 (void) strcpy(scores
[rank
], buf
);
381 (void) strcpy(n_names
[rank
], n_name
);
387 return( (ch
== 'a') ||
400 obj
= rogue
.pack
.next_object
;
403 mvaddstr(1, 0, "Value Item");
406 if (obj
->what_is
!= FOOD
) {
408 val
= get_value(obj
);
412 sprintf(buf
, "%5d ", val
);
413 get_desc(obj
, buf
+11);
414 mvaddstr(row
++, 0, buf
);
417 obj
= obj
->next_object
;
420 if (rogue
.gold
> MAX_GOLD
) {
421 rogue
.gold
= MAX_GOLD
;
432 wc
= obj
->which_kind
;
434 switch(obj
->what_is
) {
436 val
= id_weapons
[wc
].value
;
437 if ((wc
== ARROW
) || (wc
== DAGGER
) || (wc
== SHURIKEN
) ||
439 val
*= obj
->quantity
;
441 val
+= (obj
->d_enchant
* 85);
442 val
+= (obj
->hit_enchant
* 85);
445 val
= id_armors
[wc
].value
;
446 val
+= (obj
->d_enchant
* 75);
447 if (obj
->is_protected
) {
452 val
= id_wands
[wc
].value
* (obj
->class + 1);
455 val
= id_scrolls
[wc
].value
* obj
->quantity
;
458 val
= id_potions
[wc
].value
* obj
->quantity
;
464 val
= id_rings
[wc
].value
* (obj
->class + 1);
477 for (i
= 0; i
< SCROLS
; i
++) {
478 id_scrolls
[i
].id_status
= IDENTIFIED
;
480 for (i
= 0; i
< WEAPONS
; i
++) {
481 id_weapons
[i
].id_status
= IDENTIFIED
;
483 for (i
= 0; i
< ARMORS
; i
++) {
484 id_armors
[i
].id_status
= IDENTIFIED
;
486 for (i
= 0; i
< WANDS
; i
++) {
487 id_wands
[i
].id_status
= IDENTIFIED
;
489 for (i
= 0; i
< POTIONS
; i
++) {
490 id_potions
[i
].id_status
= IDENTIFIED
;
500 while(s1
[i
] != ':') {
516 for (i
= 0; i
< n
; i
++) {
518 /* It does not matter if accuracy is lost during this assignment */
519 c
= (unsigned char) xxx(0);
537 r
= ((f
* s
) + 9337) % 8887;
543 nickize(buf
, score
, n_name
)
544 char *buf
, *score
, *n_name
;
549 (void) strcpy(buf
, score
);
551 (void) strncpy(buf
, score
, 16);
553 while (score
[i
] != ':') {
557 (void) strcpy(buf
+15, n_name
);
561 buf
[j
++] = score
[i
++];
574 margin
= ((DCOLS
- strlen(buf
)) / 2);
575 mvaddstr(row
, margin
, buf
);
582 clean_up("sorry, score file is out of order");