/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Timothy C. Stoehr.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* score.c
*
* This source herein may be modified and/or distributed by anybody who
* so desires, with the following restrictions:
* 1.) No portion of this notice shall be removed.
* 2.) Credit shall not be taken for the creation of this source.
* 3.) This code is not to be traded, sold, or used for personal
* gain or profit.
*
*/
clear();
mvaddstr(10, 11, "@ @ @@@ @ @ @ @ @ @@@ @ @ @");
mvaddstr(11, 11, " @ @ @ @ @ @ @ @ @ @ @ @@ @ @");
mvaddstr(12, 11, " @ @ @ @ @ @ @ @ @ @ @ @ @ @");
mvaddstr(13, 11, " @ @ @ @ @ @ @ @ @ @ @ @@");
mvaddstr(14, 11, " @ @@@ @@@ @@ @@ @@@ @ @ @");
mvaddstr(17, 11, "Congratulations, you have been admitted to the");
mvaddstr(18, 11, "Fighters' Guild. You return home, sell all your");
mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
messagef(0, "%s", ""); /* gcc objects to just "" */
messagef(0, "%s", ""); /* gcc objects to just "" */
id_all();
sell_pack();
put_scores(NULL, WIN);
}
void
quit(boolean from_intrpt)
{
char buf[DCOLS];
short i, orow, ocol;
boolean mc;
orow = ocol = 0;
mc = FALSE;
md_ignore_signals();
if (from_intrpt) {
orow = rogue.row;
ocol = rogue.col;
mc = msg_cleared;
for (i = 0; i < DCOLS; i++) {
buf[i] = mvinch(0, i);
}
}
check_message();
messagef(1, "really quit?");
if (rgetchar() != 'y') {
md_heed_signals();
check_message();
if (from_intrpt) {
for (i = 0; i < DCOLS; i++) {
mvaddch(0, i, buf[i]);
}
msg_cleared = mc;
move(orow, ocol);
refresh();
}
return;
}
if (from_intrpt) {
clean_up(byebye_string);
}
check_message();
killed_by(NULL, QUIT);
}
/*
* The score file on disk is up to ten entries of the form
* score block [80 bytes]
* nickname block [30 bytes]
*
* The score block is to be parsed as follows:
* bytes 0-1 Rank (" 1" to "10")
* bytes 2-4 space padding
* bytes 5-15 Score/gold
* byte 15 up to a ':' Login name
* past the ':' Death mechanism
*
* The nickname block is an alternate name to be printed in place of the
* login name. Both blocks are supposed to contain a null-terminator.
*/
/* If there are other nulls in the score block, file is corrupt */
if (strlen(score_block)!=sizeof(score_block)-1) {
sf_error();
}
/* but this is NOT true of the nickname block */
for (numscores = 0; numscores < NUM_SCORE_ENTRIES; numscores++) {
if (read_score_entry(&scores[numscores], fp) == 0) {
break;
}
}
/* Search the score list. */
for (i=0; i<numscores; i++) {
if (!strcmp(scores[i].username, login_name)) {
/* found our score */
if (rogue.gold < scores[i].gold) {
/* we didn't do as well as last time */
score_only = 1;
} else {
/* we did better; mark entry for removal */
found_player = i;
}
break;
}
}
/* Remove a superseded entry, if any. */
if (found_player != -1) {
numscores--;
for (i = found_player; i < numscores; i++) {
scores[i] = scores[i+1];
}
}
/* If we're going to insert ourselves, do it now */
if (!score_only) {
/* if we aren't better than anyone, add at end. */
rank = numscores;
/* Otherwise, find our slot. */
for (i = 0; i < numscores; i++) {
if (rogue.gold >= scores[i].gold) {
rank = i;
break;
}
}
if (rank < NUM_SCORE_ENTRIES) {
/* Open up a slot */
for (i = numscores; i > rank; i--) {
scores[i] = scores[i-1];
}
numscores++;
/* Put our info in the slot */
make_score(&scores[rank], monster, other);
}
/* Now rewrite the score file */
md_ignore_signals();
rewind(fp);
(void)xxx(1);
for (i = 0; i < numscores; i++) {
write_score_entry(&scores[i], i, fp);
}
}
md_lock(0);
fclose(fp);
if (other) {
switch(other) {
case HYPOTHERMIA:
death = "died of hypothermia";
break;
case STARVATION:
death = "died of starvation";
break;
case POISON_DART:
death = "killed by a dart";
break;
case QUIT:
death = "quit";
break;
case WIN:
death = "a total winner";
break;
case KFIRE:
death = "killed by fire";
break;
}
} else {
const char *mn, *article;
static int
get_value(const object *obj)
{
short wc;
int val;
val = 0;
wc = obj->which_kind;
switch(obj->what_is) {
case WEAPON:
val = id_weapons[wc].value;
if ((wc == ARROW) || (wc == DAGGER) || (wc == SHURIKEN) ||
(wc == DART)) {
val *= obj->quantity;
}
val += (obj->d_enchant * 85);
val += (obj->hit_enchant * 85);
break;
case ARMOR:
val = id_armors[wc].value;
val += (obj->d_enchant * 75);
if (obj->is_protected) {
val += 200;
}
break;
case WAND:
val = id_wands[wc].value * (obj->class + 1);
break;
case SCROL:
val = id_scrolls[wc].value * obj->quantity;
break;
case POTION:
val = id_potions[wc].value * obj->quantity;
break;
case AMULET:
val = 5000;
break;
case RING:
val = id_rings[wc].value * (obj->class + 1);
break;
}
if (val <= 0) {
val = 10;
}
return(val);
}
static void
id_all(void)
{
short i;
for (i = 0; i < SCROLS; i++) {
id_scrolls[i].id_status = IDENTIFIED;
}
for (i = 0; i < WEAPONS; i++) {
id_weapons[i].id_status = IDENTIFIED;
}
for (i = 0; i < ARMORS; i++) {
id_armors[i].id_status = IDENTIFIED;
}
for (i = 0; i < WANDS; i++) {
id_wands[i].id_status = IDENTIFIED;
}
for (i = 0; i < POTIONS; i++) {
id_potions[i].id_status = IDENTIFIED;
}
}
void
xxxx(char *buf, short n)
{
short i;
unsigned char c;
for (i = 0; i < n; i++) {
/* It does not matter if accuracy is lost during this assignment */
c = (unsigned char)xxx(0);
buf[i] ^= c;
}
}
long
xxx(boolean st)
{
static long f, s;
long r;
if (st) {
f = 37;
s = 7;
return(0L);
}
r = ((f * s) + 9337) % 8887;
f = s;
s = r;
return(r);
}
static void
center(short row, const char *buf)
{
short margin;