Go to the documentation of this file.
19 #define _GNU_SOURCE // strcasestr() is a GNU extension in string.h
27 #include <sys/types.h>
72 snprintf(
buf, size,
"%s:%s:%" FMT64 ":%s:%s:%d:%d:%d", sc->
name, sc->
title, sc->
exp, sc->
killer, sc->
maplevel, sc->
maxhp, sc->
maxsp, sc->
maxgrace);
96 fprintf(fp,
"%s\n",
buf);
117 cp = strchr(bp,
'\n');
162 if (strcmp(sc->
killer,
"quit") == 0 || strcmp(sc->
killer,
"left") == 0) {
165 }
else if (strcmp(sc->
killer,
"a dungeon collapse") == 0) {
169 s1 =
"was killed by";
172 snprintf(
buf, size,
"[fixed]%3d %10" FMT64 "[print] %s%s%s %s %s on map %s <%d><%d><%d>.",
173 sc->
position, sc->
exp, sc->
name, sc->
title[0]==
',' ?
"" :
" ", sc->
title, s1, s2, sc->
maplevel, sc->
maxhp, sc->
maxsp, sc->
maxgrace);
192 memset(old_score, 0,
sizeof(*old_score));
198 table->
entry[i] = *new_score;
203 *old_score = table->
entry[i];
205 table->
entry[i] = *new_score;
222 table->
entry[i] = *new_score;
227 while (i > 0 && new_score->
exp >= table->
entry[i-1].
exp) {
256 fp = fopen(table->
fname,
"r");
258 if (errno == ENOENT) {
261 LOG(
llevError,
"Cannot open highscore file %s: %s\n", table->
fname, strerror(errno));
282 memset(&table->
entry[i], 0,
sizeof(table->
entry[i]));
354 if (
op->stats.exp == 0 || !
op->contr->name_changed)
360 "Since you have been in wizard mode, "
361 "you can't enter the high-score list.");
364 if (!
op->stats.exp) {
367 "You don't deserve to save your character yet.");
376 if (new_score.
killer[0] ==
'\0') {
377 strcpy(new_score.
killer,
"a dungeon collapse");
380 if (
op->map == NULL) {
387 new_score.
maxsp = (
int)
op->stats.maxsp;
391 if (!
tmp->stats.exp)
continue;
392 new_score.
exp =
tmp->stats.exp;
395 if (!quiet && new_score.
exp > old_score.
exp) {
397 "You improved your rating in %s: %" FMT64,
tmp->name, new_score.
exp);
406 new_score.
exp =
op->stats.exp;
419 message =
"You didn't enter the highscore list:";
421 message =
"You entered the highscore list:";
424 message =
"You left the highscore list:";
425 else if (new_score.
exp > old_score.
exp)
426 message =
"You beat your last score:";
428 message =
"You didn't beat your last score:";
455 int skill_min,skill_max;
459 if (strncmp(
match,
"-s", 2) == 0 ) {
463 if (strchr(
match,
' ')) {
476 "Could not match '%.*s' to a skill", len,
match);
483 if ( max < 100 && max > 10 )
max = 10;
488 skill_min = skill_max = skill_match;
489 if (skill_match == -1) {
500 if (skill < skill_min || skill > skill_max)
continue;
510 "Overall high scores:");
513 "High scores for the skill [color=red]%s[/color]:",
hiscore_tables[skill].skill_name);
516 "[fixed]Rank Score [print]Who <max hp><max sp><max grace>");
static void hiscore_load(score_table *table)
static char * draw_one_high_score(const score *sc, char *buf, size_t size)
void LOG(LogLevel logLevel, const char *format,...)
int of_close(OutputFile *of)
FILE * of_open(OutputFile *of, const char *fname)
#define QUERY_FLAG(xyz, p)
int get_skill_client_code(const char *skill_name)
static event_registration c
static void add_score(score_table *table, score *new_score, score *old_score)
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
#define PROFILE_BEGIN(expr)
#define MSG_TYPE_COMMAND_ERROR
static score_table hiscore_tables[MAX_SKILLS+1]
#define MSG_TYPE_ADMIN_HISCORE
#define PROFILE_END(var, expr)
score entry[HIGHSCORE_LENGTH]
size_t split_string(char *str, char *array[], size_t array_size, char sep)
static void hiscore_save(const score_table *table)
static int get_score(char *bp, score *sc)
const char * skill_names[MAX_SKILLS]
void hiscore_display(object *op, int max, const char *match)
static void put_score(const score *sc, char *buf, size_t size)
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
void hiscore_check(object *op, int quiet)
#define MSG_TYPE_APPLY_ERROR
#define FOR_INV_PREPARE(op_, it_)
void player_get_title(const player *pl, char *buf, size_t bufsize)