ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/treasure.c
(Generate patch)

Comparing deliantra/server/common/treasure.c (file contents):
Revision 1.3 by elmex, Wed Aug 9 15:57:27 2006 UTC vs.
Revision 1.3.2.1 by elmex, Thu Aug 10 16:53:34 2006 UTC

1 1
2/* 2/*
3 * static char *rcs_treasure_c = 3 * static char *rcs_treasure_c =
4 * "$Id: treasure.c,v 1.3 2006/08/09 15:57:27 elmex Exp $"; 4 * "$Id: treasure.c,v 1.3.2.1 2006/08/10 16:53:34 elmex Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
510 510
511/* 511/*
512 * Based upon the specified difficulty and upon the difftomagic_list array, 512 * Based upon the specified difficulty and upon the difftomagic_list array,
513 * a random magical bonus is returned. This is used when determine 513 * a random magical bonus is returned. This is used when determine
514 * the magical bonus created on specific maps. 514 * the magical bonus created on specific maps.
515 *
516 * elmex Thu Aug 10 18:45:44 CEST 2006:
517 * Scaling difficulty by max_level, as difficulty is a level and not some
518 * weird integer between 1-31.
519 *
515 */ 520 */
516 521
517int magic_from_difficulty(int difficulty) 522int magic_from_difficulty(int difficulty)
518{ 523{
519 int percent,loop; 524 int percent = 0, magic = 0;
525 int scaled_diff = ((double) difficulty / settings.max_level) * 31;
520 526
521 difficulty--; 527 scaled_diff--;
522 if(difficulty<0)
523 difficulty=0;
524 528
529 if(scaled_diff < 0)
530 scaled_diff = 0;
531
525 if (difficulty>=DIFFLEVELS) 532 if (scaled_diff >= DIFFLEVELS)
526 difficulty=DIFFLEVELS-1; 533 scaled_diff = DIFFLEVELS-1;
527 534
528 percent = RANDOM()%100; 535 percent = RANDOM()%100;
529 536
530 for(loop=0;loop<(MAXMAGIC+1);++loop) { 537 for(magic = 0; magic < (MAXMAGIC + 1); magic++)
538 {
531 percent -= difftomagic_list[difficulty][loop]; 539 percent -= difftomagic_list[scaled_diff][magic];
540
532 if (percent<0) 541 if (percent < 0)
533 break; 542 break;
534 } 543 }
535 if (loop==(MAXMAGIC+1)) { 544
545 if (magic == (MAXMAGIC + 1))
546 {
536 LOG(llevError,"Warning, table for difficulty %d bad.\n",difficulty); 547 LOG(llevError,"Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty);
537 loop=0; 548 magic = 0;
538 } 549 }
550
551 magic = (RANDOM() % 3) ? magic : -magic;
552
539/* LOG(llevDebug, "Chose magic %d for difficulty %d\n", loop, difficulty);*/ 553 /* LOG(llevDebug, "Chose magic %d for difficulty (scaled %d) %d\n", magic, scaled_diff, difficulty); */
540 return (RANDOM()%3)?loop:-loop; 554
555 return magic;
541} 556}
542 557
543/* 558/*
544 * Sets magical bonus in an object, and recalculates the effect on 559 * Sets magical bonus in an object, and recalculates the effect on
545 * the armour variable, and the effect on speed of armour. 560 * the armour variable, and the effect on speed of armour.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines