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.1.1.2 by elmex, Wed Feb 22 18:01:23 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.1.1.2 2006/02/22 18:01:23 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
220#endif 220#endif
221 tl->total_chance += t->chance; 221 tl->total_chance += t->chance;
222 } 222 }
223 } 223 }
224 } else 224 } else
225 LOG(llevError,"Treasure-list didn't understand: %s, line %d\n",buf, line); 225 LOG(llevError,"Treasure-list %s didn't understand: %s, line %d\n", filename, buf, line);
226 } 226 }
227 close_and_delete(fp, comp); 227 close_and_delete(fp, comp);
228 228
229#ifdef TREASURE_DEBUG 229#ifdef TREASURE_DEBUG
230 /* Perform some checks on how valid the treasure data actually is. 230 /* Perform some checks on how valid the treasure data actually is.
478 { 0, 0, 0, 0,100}, /*30*/ 478 { 0, 0, 0, 0,100}, /*30*/
479 { 0, 0, 0, 0,100}, /*31*/ 479 { 0, 0, 0, 0,100}, /*31*/
480}; 480};
481 481
482 482
483/* calculate the appropriate level for wands staves and scrolls. If 483/* calculate the appropriate level for wands staves and scrolls.
484 * retmult is 1, return the multiplier, not the level, for computing value
485 * This code presumes that op has had its spell object created (in op->inv) 484 * This code presumes that op has had its spell object created (in op->inv)
486 */ 485 *
486 * elmex Wed Aug 9 17:44:59 CEST 2006:
487 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
488 */
487 489
488int level_for_item(const object *op, int difficulty, int retmult) 490int level_for_item(const object *op, int difficulty)
489{ 491{
490 int level, mult, olevel; 492 int mult = 0, olevel = 0;
491 493
492 mult = 0;
493 if (!op->inv) { 494 if (!op->inv)
495 {
494 LOG(llevError,"level_for_item: Object %s has no inventory!\n", op->name); 496 LOG(llevError,"level_for_item: Object %s has no inventory!\n", op->name);
495 return 0; 497 return 0;
496 } 498 }
497 level = op->inv->level;
498 499
499 /* Basically, we set mult to the lowest spell increase attribute that is 500 olevel = op->inv->level + (double) difficulty * (1 - drand48 () * drand48 () * 2);
500 * not zero - zero's mean no modification is done, so we don't want those.
501 * given we want non zero results, we can't just use a few MIN's here.
502 */
503 mult = op->inv->dam_modifier;
504 if (op->inv->range_modifier && (op->inv->range_modifier<mult || mult == 0))
505 mult = op->inv->range_modifier;
506 if (op->inv->duration_modifier && (op->inv->duration_modifier < mult || mult==0))
507 mult = op->inv->duration_modifier;
508 501
509 if (mult == 0) 502 if (olevel <= 0)
510 mult = 5; 503 olevel = rndm (1, MIN (op->inv->level, 1));
511 504
512 if (retmult) 505 if (olevel > MAXLEVEL)
513 return mult; 506 olevel = MAXLEVEL;
514 507
515 olevel = mult * rndm(0, difficulty) + level;
516 if (olevel > MAXLEVEL) olevel = MAXLEVEL;
517
518 return olevel; 508 return olevel;
519} 509}
520 510
521/* 511/*
522 * Based upon the specified difficulty and upon the difftomagic_list array, 512 * Based upon the specified difficulty and upon the difftomagic_list array,
523 * a random magical bonus is returned. This is used when determine 513 * a random magical bonus is returned. This is used when determine
524 * 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 *
525 */ 520 */
526 521
527int magic_from_difficulty(int difficulty) 522int magic_from_difficulty(int difficulty)
528{ 523{
529 int percent,loop; 524 int percent = 0, magic = 0;
525 int scaled_diff = ((double) difficulty / settings.max_level) * 31;
530 526
531 difficulty--; 527 scaled_diff--;
532 if(difficulty<0)
533 difficulty=0;
534 528
529 if(scaled_diff < 0)
530 scaled_diff = 0;
531
535 if (difficulty>=DIFFLEVELS) 532 if (scaled_diff >= DIFFLEVELS)
536 difficulty=DIFFLEVELS-1; 533 scaled_diff = DIFFLEVELS-1;
537 534
538 percent = RANDOM()%100; 535 percent = RANDOM()%100;
539 536
540 for(loop=0;loop<(MAXMAGIC+1);++loop) { 537 for(magic = 0; magic < (MAXMAGIC + 1); magic++)
538 {
541 percent -= difftomagic_list[difficulty][loop]; 539 percent -= difftomagic_list[scaled_diff][magic];
540
542 if (percent<0) 541 if (percent < 0)
543 break; 542 break;
544 } 543 }
545 if (loop==(MAXMAGIC+1)) { 544
545 if (magic == (MAXMAGIC + 1))
546 {
546 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);
547 loop=0; 548 magic = 0;
548 } 549 }
550
551 magic = (RANDOM() % 3) ? magic : -magic;
552
549/* 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); */
550 return (RANDOM()%3)?loop:-loop; 554
555 return magic;
551} 556}
552 557
553/* 558/*
554 * Sets magical bonus in an object, and recalculates the effect on 559 * Sets magical bonus in an object, and recalculates the effect on
555 * the armour variable, and the effect on speed of armour. 560 * the armour variable, and the effect on speed of armour.
971 * change by level, just set the wand to the level of 976 * change by level, just set the wand to the level of
972 * the spell, and value calculation is simpler. 977 * the spell, and value calculation is simpler.
973 */ 978 */
974 if (op->inv->duration_modifier || op->inv->dam_modifier || 979 if (op->inv->duration_modifier || op->inv->dam_modifier ||
975 op->inv->range_modifier) { 980 op->inv->range_modifier) {
976 op->level = level_for_item(op, difficulty, 0); 981 op->level = level_for_item(op, difficulty);
977 op->value= op->value* op->inv->value * (op->level +50)/ 982 op->value= op->value* op->inv->value * (op->level +50)/
978 (op->inv->level + 50); 983 (op->inv->level + 50);
979 } 984 }
980 else { 985 else {
981 op->level = op->inv->level; 986 op->level = op->inv->level;
982 op->value = op->value * op->inv->value; 987 op->value = op->value * op->inv->value;
983 } 988 }
984 break; 989 break;
985 990
986 case ROD: 991 case ROD:
987 op->level = level_for_item(op, difficulty, 0); 992 op->level = level_for_item(op, difficulty);
988 /* Add 50 to both level an divisor to keep prices a little more 993 /* Add 50 to both level an divisor to keep prices a little more
989 * reasonable. Otherwise, a high level version of a low level 994 * reasonable. Otherwise, a high level version of a low level
990 * spell can be worth tons a money (eg, level 20 rod, level 2 spell = 995 * spell can be worth tons a money (eg, level 20 rod, level 2 spell =
991 * 10 time multiplier). This way, the value are a bit more reasonable. 996 * 10 time multiplier). This way, the value are a bit more reasonable.
992 */ 997 */
999 1004
1000 op->stats.hp = op->stats.maxhp; 1005 op->stats.hp = op->stats.maxhp;
1001 break; 1006 break;
1002 1007
1003 case SCROLL: 1008 case SCROLL:
1004 op->level = level_for_item(op, difficulty, 0); 1009 op->level = level_for_item(op, difficulty);
1005 op->value= op->value * op->inv->value * (op->level +50) / (op->inv->level + 50); 1010 op->value= op->value * op->inv->value * (op->level +50) / (op->inv->level + 50);
1006 /* add exp so reading them properly gives xp */ 1011 /* add exp so reading them properly gives xp */
1007 op->stats.exp = op->value/5; 1012 op->stats.exp = op->value/5;
1008 op->nrof = op->inv->nrof; 1013 op->nrof = op->inv->nrof;
1009 break; 1014 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines