1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <sproto.h> |
26 | #include <sproto.h> |
27 | |
27 | |
… | |
… | |
41 | |
41 | |
42 | /* |
42 | /* |
43 | * spool works mostly like strtok(char *, ":"), but it can also |
43 | * spool works mostly like strtok(char *, ":"), but it can also |
44 | * log a specified error message if something goes wrong. |
44 | * log a specified error message if something goes wrong. |
45 | */ |
45 | */ |
46 | |
46 | static char * |
47 | char * |
|
|
48 | spool (char *bp, char *error) |
47 | spool (char *bp, const char *error) |
49 | { |
48 | { |
50 | static char *prev_pos = NULL; |
49 | static char *prev_pos = NULL; |
51 | char *next_pos; |
50 | char *next_pos; |
52 | |
51 | |
53 | if (bp == NULL) |
52 | if (bp == NULL) |
… | |
… | |
76 | |
75 | |
77 | /* |
76 | /* |
78 | * Does what it says, copies the contents of the first score structure |
77 | * Does what it says, copies the contents of the first score structure |
79 | * to the second one. |
78 | * to the second one. |
80 | */ |
79 | */ |
81 | |
|
|
82 | static void |
80 | static void |
83 | copy_score (score *sc1, score *sc2) |
81 | copy_score (score *sc1, score *sc2) |
84 | { |
82 | { |
85 | assign (sc2->name , sc1->name); |
83 | assign (sc2->name , sc1->name); |
86 | assign (sc2->title , sc1->title); |
84 | assign (sc2->title , sc1->title); |
… | |
… | |
94 | |
92 | |
95 | /* |
93 | /* |
96 | * Writes the given score structure to a static buffer, and returns |
94 | * Writes the given score structure to a static buffer, and returns |
97 | * a pointer to it. |
95 | * a pointer to it. |
98 | */ |
96 | */ |
99 | |
|
|
100 | static char * |
97 | static char * |
101 | put_score (score *sc) |
98 | put_score (score *sc) |
102 | { |
99 | { |
103 | static char buf[MAX_BUF]; |
100 | static char buf[MAX_BUF]; |
104 | |
101 | |
… | |
… | |
170 | static char retbuf[MAX_BUF]; |
167 | static char retbuf[MAX_BUF]; |
171 | |
168 | |
172 | if (!strncmp (sc->killer, "quit", MAX_NAME)) |
169 | if (!strncmp (sc->killer, "quit", MAX_NAME)) |
173 | sprintf (retbuf, "%3d %10lld %s the %s quit the game on map %s [%d][%d][%d].", |
170 | sprintf (retbuf, "%3d %10lld %s the %s quit the game on map %s [%d][%d][%d].", |
174 | sc->position, (long long) sc->exp, sc->name, sc->title, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace); |
171 | sc->position, (long long) sc->exp, sc->name, sc->title, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace); |
175 | else if (!strncmp (sc->killer, "left", MAX_NAME)) |
172 | else if (!strncmp (sc->killer, "leaving", MAX_NAME)) |
176 | sprintf (retbuf, "%3d %10lld %s the %s left the game on map %s [%d][%d][%d].", |
173 | sprintf (retbuf, "%3d %10lld %s the %s left the game on map %s [%d][%d][%d].", |
177 | sc->position, (long long) sc->exp, sc->name, sc->title, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace); |
174 | sc->position, (long long) sc->exp, sc->name, sc->title, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace); |
178 | else |
175 | else |
179 | sprintf (retbuf, "%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].", |
176 | sprintf (retbuf, "%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].", |
180 | sc->position, (long long) sc->exp, sc->name, sc->title, sc->killer, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace); |
177 | sc->position, (long long) sc->exp, sc->name, sc->title, sc->killer, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace); |
|
|
178 | |
181 | return retbuf; |
179 | return retbuf; |
182 | } |
180 | } |
183 | |
181 | |
184 | /* |
182 | /* |
185 | * add_score() adds the given score-structure to the high-score list, but |
183 | * add_score() adds the given score-structure to the high-score list, but |
… | |
… | |
268 | if (op->stats.exp == 0) |
266 | if (op->stats.exp == 0) |
269 | return; |
267 | return; |
270 | |
268 | |
271 | assign (new_score.name, op->name); |
269 | assign (new_score.name, op->name); |
272 | assign (new_score.title, op->title.length () ? &op->title : op->contr->title); |
270 | assign (new_score.title, op->title.length () ? &op->title : op->contr->title); |
273 | assign (new_score.killer, op->contr->killer[0] ? op->contr->killer : "a dungeon collapse"); |
271 | assign (new_score.killer, op->contr->killer_name ()); |
274 | assign (new_score.maplevel, op->map ? op->map->name ? &op->map->name : &op->map->path : ""); |
272 | assign (new_score.maplevel, op->map ? op->map->name ? &op->map->name : &op->map->path : ""); |
275 | |
273 | |
276 | new_score.exp = op->stats.exp; |
274 | new_score.exp = op->stats.exp; |
277 | new_score.maxhp = op->stats.maxhp; |
275 | new_score.maxhp = op->stats.maxhp; |
278 | new_score.maxsp = op->stats.maxsp; |
276 | new_score.maxsp = op->stats.maxsp; |
… | |
… | |
308 | /* displays the high score file. object is the calling object |
306 | /* displays the high score file. object is the calling object |
309 | * (null if being called via command line.) max is the maximum |
307 | * (null if being called via command line.) max is the maximum |
310 | * number of scores to display. match, if set, is the name or class |
308 | * number of scores to display. match, if set, is the name or class |
311 | * to match to. |
309 | * to match to. |
312 | */ |
310 | */ |
313 | |
311 | static void |
314 | void |
|
|
315 | display_high_score (object *op, int max, const char *match) |
312 | display_high_score (object *op, int max, const char *match) |
316 | { |
313 | { |
317 | const size_t maxchar = 80; |
314 | const size_t maxchar = 80; |
318 | FILE *fp; |
315 | FILE *fp; |
319 | char buf[MAX_BUF], *scorebuf, *bp, *cp; |
316 | char buf[MAX_BUF], *scorebuf, *bp, *cp; |
… | |
… | |
326 | LOG (llevError, "Cannot open highscore file %s: %s\n", buf, strerror (errno)); |
323 | LOG (llevError, "Cannot open highscore file %s: %s\n", buf, strerror (errno)); |
327 | if (op != NULL) |
324 | if (op != NULL) |
328 | new_draw_info (NDI_UNIQUE, 0, op, "There is no highscore file."); |
325 | new_draw_info (NDI_UNIQUE, 0, op, "There is no highscore file."); |
329 | return; |
326 | return; |
330 | } |
327 | } |
331 | if (op != NULL) |
328 | |
332 | clear_win_info (op); |
|
|
333 | new_draw_info (NDI_UNIQUE, 0, op, "Nr Score Who [max hp][max sp][max grace]"); |
329 | new_draw_info (NDI_UNIQUE, 0, op, "Nr Score Who [max hp][max sp][max grace]"); |
334 | |
330 | |
335 | while (fgets (buf, MAX_BUF, fp) != NULL) |
331 | while (fgets (buf, MAX_BUF, fp) != NULL) |
336 | { |
332 | { |
337 | if (j >= HIGHSCORE_LENGTH || i >= (max - 1)) |
333 | if (j >= HIGHSCORE_LENGTH || i >= (max - 1)) |
338 | break; |
334 | break; |
|
|
335 | |
339 | if ((sc = get_score (buf)) == NULL) |
336 | if ((sc = get_score (buf)) == NULL) |
340 | break; |
337 | break; |
|
|
338 | |
341 | sc->position = ++j; |
339 | sc->position = ++j; |
342 | if (match == NULL) |
340 | if (match == NULL) |
343 | { |
341 | { |
344 | scorebuf = draw_one_high_score (sc); |
342 | scorebuf = draw_one_high_score (sc); |
345 | i++; |
343 | i++; |
… | |
… | |
352 | i++; |
350 | i++; |
353 | } |
351 | } |
354 | else |
352 | else |
355 | continue; |
353 | continue; |
356 | } |
354 | } |
|
|
355 | |
357 | /* Replaced what seemed to an overly complicated word wrap method |
356 | /* Replaced what seemed to an overly complicated word wrap method |
358 | * still word wraps, but assumes at most 2 lines of data. |
357 | * still word wraps, but assumes at most 2 lines of data. |
359 | * mw - 2-12-97 |
358 | * mw - 2-12-97 |
360 | */ |
359 | */ |
361 | assign (buf, scorebuf); |
360 | assign (buf, scorebuf); |
… | |
… | |
384 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
383 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
385 | } |
384 | } |
386 | |
385 | |
387 | close_and_delete (fp, comp); |
386 | close_and_delete (fp, comp); |
388 | } |
387 | } |
|
|
388 | |