1 | /* |
1 | /* |
2 | * static char *rcsid_hiscore_c = |
2 | * static char *rcsid_hiscore_c = |
3 | * "$Id: hiscore.C,v 1.1 2006/08/13 17:16:04 elmex Exp $"; |
3 | * "$Id: hiscore.C,v 1.2 2006/08/29 08:01:37 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
165 | |
165 | |
166 | static char * draw_one_high_score(score *sc) { |
166 | static char * draw_one_high_score(score *sc) { |
167 | static char retbuf[MAX_BUF]; |
167 | static char retbuf[MAX_BUF]; |
168 | |
168 | |
169 | if(!strncmp(sc->killer,"quit",MAX_NAME)) |
169 | if(!strncmp(sc->killer,"quit",MAX_NAME)) |
170 | 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].", |
171 | sc->position,sc->exp,sc->name,sc->title,sc->maplevel,sc->maxhp,sc->maxsp, |
171 | sc->position,sc->exp,sc->name,sc->title,sc->maplevel,sc->maxhp,sc->maxsp, |
172 | sc->maxgrace); |
172 | sc->maxgrace); |
173 | else if(!strncmp(sc->killer,"left",MAX_NAME)) |
173 | else if(!strncmp(sc->killer,"left",MAX_NAME)) |
174 | sprintf(retbuf,"%3d %10lld %s the %s left the game on map %s [%d][%d][%d].", |
174 | sprintf(retbuf,"%3d %10lld %s the %s left the game on map %s [%d][%d][%d].", |
175 | sc->position,sc->exp,sc->name,sc->title,sc->maplevel,sc->maxhp,sc->maxsp, |
175 | sc->position,sc->exp,sc->name,sc->title,sc->maplevel,sc->maxhp,sc->maxsp, |
176 | sc->maxgrace); |
176 | sc->maxgrace); |
177 | else |
177 | else |
178 | sprintf(retbuf,"%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].", |
178 | sprintf(retbuf,"%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].", |
179 | sc->position,sc->exp,sc->name,sc->title,sc->killer,sc->maplevel, |
179 | sc->position,sc->exp,sc->name,sc->title,sc->killer,sc->maplevel, |
180 | sc->maxhp,sc->maxsp,sc->maxgrace); |
180 | sc->maxhp,sc->maxsp,sc->maxgrace); |
181 | return retbuf; |
181 | return retbuf; |
182 | } |
182 | } |
183 | /* |
183 | /* |
… | |
… | |
249 | void check_score(object *op) { |
249 | void check_score(object *op) { |
250 | score new_score; |
250 | score new_score; |
251 | score *old_score; |
251 | score *old_score; |
252 | |
252 | |
253 | if(op->stats.exp==0) |
253 | if(op->stats.exp==0) |
254 | return; |
254 | return; |
255 | |
255 | |
256 | if(!op->contr->name_changed) { |
256 | if(!op->contr->name_changed) { |
257 | if(op->stats.exp>0) { |
257 | if(op->stats.exp>0) { |
258 | new_draw_info(NDI_UNIQUE, 0,op,"As you haven't changed your name, you won't"); |
258 | new_draw_info(NDI_UNIQUE, 0,op,"As you haven't changed your name, you won't"); |
259 | new_draw_info(NDI_UNIQUE, 0,op,"get into the high-score list."); |
259 | new_draw_info(NDI_UNIQUE, 0,op,"get into the high-score list."); |
260 | } |
260 | } |
261 | return; |
261 | return; |
262 | } |
262 | } |
263 | if(QUERY_FLAG(op,FLAG_WAS_WIZ)) { |
263 | if(QUERY_FLAG(op,FLAG_WAS_WIZ)) { |
264 | new_draw_info(NDI_UNIQUE, 0,op,"Since you have been in wizard mode,"); |
264 | new_draw_info(NDI_UNIQUE, 0,op,"Since you have been in wizard mode,"); |
265 | new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list."); |
265 | new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list."); |
266 | return; |
266 | return; |
267 | } |
267 | } |
268 | if (op->contr->explore) { |
268 | if (op->contr->explore) { |
269 | new_draw_info(NDI_UNIQUE, 0,op,"Since you were in explore mode,"); |
269 | new_draw_info(NDI_UNIQUE, 0,op,"Since you were in explore mode,"); |
270 | new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list."); |
270 | new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list."); |
271 | return; |
271 | return; |
272 | } |
272 | } |
273 | strncpy(new_score.name,op->name,BIG_NAME); |
273 | strncpy(new_score.name,op->name,BIG_NAME); |
274 | new_score.name[BIG_NAME-1] = '\0'; |
274 | new_score.name[BIG_NAME-1] = '\0'; |
275 | strncpy(new_score.title,op->contr->own_title,BIG_NAME); |
275 | strncpy(new_score.title,op->contr->own_title,BIG_NAME); |
276 | if(new_score.title[0]=='\0') |
276 | if(new_score.title[0]=='\0') |
277 | strncpy(new_score.title,op->contr->title,BIG_NAME); |
277 | strncpy(new_score.title,op->contr->title,BIG_NAME); |
278 | new_score.title[BIG_NAME-1] = '\0'; |
278 | new_score.title[BIG_NAME-1] = '\0'; |
279 | strncpy(new_score.killer,op->contr->killer,BIG_NAME); |
279 | strncpy(new_score.killer,op->contr->killer,BIG_NAME); |
280 | if(new_score.killer[0]=='\0') |
280 | if(new_score.killer[0]=='\0') |
281 | strcpy(new_score.killer,"a dungeon collapse"); |
281 | strcpy(new_score.killer,"a dungeon collapse"); |
282 | new_score.killer[BIG_NAME-1] = '\0'; |
282 | new_score.killer[BIG_NAME-1] = '\0'; |
283 | new_score.exp=op->stats.exp; |
283 | new_score.exp=op->stats.exp; |
284 | if(op->map == NULL) |
284 | if(op->map == NULL) |
285 | *new_score.maplevel = '\0'; |
285 | *new_score.maplevel = '\0'; |
286 | else { |
286 | else { |
287 | strncpy(new_score.maplevel, |
287 | strncpy(new_score.maplevel, |
288 | op->map->name?op->map->name:op->map->path, |
288 | op->map->name?op->map->name:op->map->path, |
289 | BIG_NAME-1); |
289 | BIG_NAME-1); |
290 | new_score.maplevel[BIG_NAME-1] = '\0'; |
290 | new_score.maplevel[BIG_NAME-1] = '\0'; |
291 | } |
291 | } |
292 | new_score.maxhp=(int) op->stats.maxhp; |
292 | new_score.maxhp=(int) op->stats.maxhp; |
293 | new_score.maxsp=(int) op->stats.maxsp; |
293 | new_score.maxsp=(int) op->stats.maxsp; |
294 | new_score.maxgrace=(int) op->stats.maxgrace; |
294 | new_score.maxgrace=(int) op->stats.maxgrace; |
295 | if((old_score=add_score(&new_score))==NULL) { |
295 | if((old_score=add_score(&new_score))==NULL) { |
296 | new_draw_info(NDI_UNIQUE, 0,op,"Error in the highscore list."); |
296 | new_draw_info(NDI_UNIQUE, 0,op,"Error in the highscore list."); |
297 | return; |
297 | return; |
298 | } |
298 | } |
299 | if(new_score.position == -1) { |
299 | if(new_score.position == -1) { |
300 | new_score.position = HIGHSCORE_LENGTH+1; /* Not strictly correct... */ |
300 | new_score.position = HIGHSCORE_LENGTH+1; /* Not strictly correct... */ |
301 | if(!strcmp(old_score->name,new_score.name)) |
301 | if(!strcmp(old_score->name,new_score.name)) |
302 | new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last highscore:"); |
302 | new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last highscore:"); |
303 | else |
303 | else |
304 | new_draw_info(NDI_UNIQUE, 0,op,"You didn't enter the highscore list:"); |
304 | new_draw_info(NDI_UNIQUE, 0,op,"You didn't enter the highscore list:"); |
305 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); |
305 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); |
306 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); |
306 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); |
307 | return; |
307 | return; |
308 | } |
308 | } |
309 | if(old_score->exp>=new_score.exp) |
309 | if(old_score->exp>=new_score.exp) |
310 | new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last score:"); |
310 | new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last score:"); |
311 | else |
311 | else |
312 | new_draw_info(NDI_UNIQUE, 0,op,"You beat your last score:"); |
312 | new_draw_info(NDI_UNIQUE, 0,op,"You beat your last score:"); |
313 | |
313 | |
314 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); |
314 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); |
315 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); |
315 | new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); |
316 | } |
316 | } |
317 | |
317 | |
… | |
… | |
330 | int i=0,j=0,comp; |
330 | int i=0,j=0,comp; |
331 | score *sc; |
331 | score *sc; |
332 | |
332 | |
333 | sprintf(buf,"%s/%s",settings.localdir,HIGHSCORE); |
333 | sprintf(buf,"%s/%s",settings.localdir,HIGHSCORE); |
334 | if((fp=open_and_uncompress(buf,0,&comp))==NULL) { |
334 | if((fp=open_and_uncompress(buf,0,&comp))==NULL) { |
335 | LOG(llevError, "Cannot open highscore file %s: %s\n", buf, strerror_local(errno)); |
335 | LOG(llevError, "Cannot open highscore file %s: %s\n", buf, strerror_local(errno)); |
336 | if(op!=NULL) |
336 | if(op!=NULL) |
337 | new_draw_info(NDI_UNIQUE, 0,op,"There is no highscore file."); |
337 | new_draw_info(NDI_UNIQUE, 0,op,"There is no highscore file."); |
338 | return; |
338 | return; |
339 | } |
339 | } |
340 | if(op != NULL) |
340 | if(op != NULL) |
341 | clear_win_info(op); |
341 | clear_win_info(op); |
342 | new_draw_info(NDI_UNIQUE, 0,op,"Nr Score Who [max hp][max sp][max grace]"); |
342 | new_draw_info(NDI_UNIQUE, 0,op,"Nr Score Who [max hp][max sp][max grace]"); |
343 | |
343 | |
344 | while(fgets(buf,MAX_BUF,fp)!=NULL) { |
344 | while(fgets(buf,MAX_BUF,fp)!=NULL) { |
345 | if(j>=HIGHSCORE_LENGTH||i>=(max-1)) |
345 | if(j>=HIGHSCORE_LENGTH||i>=(max-1)) |
346 | break; |
346 | break; |
347 | if((sc=get_score(buf))==NULL) |
347 | if((sc=get_score(buf))==NULL) |
348 | break; |
348 | break; |
349 | sc->position=++j; |
349 | sc->position=++j; |
350 | if (match==NULL) { |
350 | if (match==NULL) { |
351 | scorebuf=draw_one_high_score(sc); |
351 | scorebuf=draw_one_high_score(sc); |
352 | i++; |
352 | i++; |
353 | } else { |
353 | } else { |
354 | if (!strcasecmp(sc->name, match) || !strcasecmp(sc->title, match)) { |
354 | if (!strcasecmp(sc->name, match) || !strcasecmp(sc->title, match)) { |
355 | scorebuf=draw_one_high_score(sc); |
355 | scorebuf=draw_one_high_score(sc); |
356 | i++; |
356 | i++; |
357 | } |
357 | } |
358 | else continue; |
358 | else continue; |
359 | } |
359 | } |
360 | /* Replaced what seemed to an overly complicated word wrap method |
360 | /* Replaced what seemed to an overly complicated word wrap method |
361 | * still word wraps, but assumes at most 2 lines of data. |
361 | * still word wraps, but assumes at most 2 lines of data. |
362 | * mw - 2-12-97 |
362 | * mw - 2-12-97 |
363 | */ |
363 | */ |
364 | strncpy(buf,scorebuf,MAX_BUF); |
364 | strncpy(buf,scorebuf,MAX_BUF); |
365 | buf[MAX_BUF-1] = '\0'; |
365 | buf[MAX_BUF-1] = '\0'; |
366 | cp=buf; |
366 | cp=buf; |
367 | while (strlen(cp)> maxchar) { |
367 | while (strlen(cp)> maxchar) { |
368 | bp = cp+maxchar-1; |
368 | bp = cp+maxchar-1; |
369 | while (*bp != ' ' && bp>cp) bp--; |
369 | while (*bp != ' ' && bp>cp) bp--; |
370 | *bp='\0'; |
370 | *bp='\0'; |
371 | if (op == NULL) { |
371 | if (op == NULL) { |
372 | LOG(llevDebug, "%s\n", cp); |
372 | LOG(llevDebug, "%s\n", cp); |
373 | } |
373 | } |
374 | else { |
374 | else { |
375 | new_draw_info(NDI_UNIQUE, 0,op,cp); |
375 | new_draw_info(NDI_UNIQUE, 0,op,cp); |
376 | } |
376 | } |
377 | sprintf(buf, " %s", bp+1); |
377 | sprintf(buf, " %s", bp+1); |
378 | cp = buf; |
378 | cp = buf; |
379 | i++; |
379 | i++; |
380 | } |
380 | } |
381 | if(op == NULL) |
381 | if(op == NULL) |
382 | LOG(llevDebug, "%s\n", buf); |
382 | LOG(llevDebug, "%s\n", buf); |
383 | else |
383 | else |
384 | new_draw_info(NDI_UNIQUE, 0,op,buf); |
384 | new_draw_info(NDI_UNIQUE, 0,op,buf); |
385 | } |
385 | } |
386 | close_and_delete(fp, comp); |
386 | close_and_delete(fp, comp); |
387 | } |
387 | } |