--- deliantra/server/common/treasure.c 2006/02/03 07:11:41 1.1 +++ deliantra/server/common/treasure.c 2006/08/10 16:53:34 1.3.2.1 @@ -157,7 +157,7 @@ /* recursived checks the linked list. Treasurelist is passed only * so that the treasure name can be printed out */ -static void check_treasurelist(treasure *t, treasurelist *tl) +static void check_treasurelist(const treasure *t, const treasurelist *tl) { if (t->item==NULL && t->name==NULL) LOG(llevError,"Treasurelist %s has element with no name or archetype\n", tl->name); @@ -222,7 +222,7 @@ } } } else - LOG(llevError,"Treasure-list didn't understand: %s, line %d\n",buf, line); + LOG(llevError,"Treasure-list %s didn't understand: %s, line %d\n", filename, buf, line); } close_and_delete(fp, comp); @@ -480,74 +480,79 @@ }; -/* calculate the appropriate level for wands staves and scrolls. If - * retmult is 1, return the multiplier, not the level, for computing value +/* calculate the appropriate level for wands staves and scrolls. * This code presumes that op has had its spell object created (in op->inv) + * + * elmex Wed Aug 9 17:44:59 CEST 2006: + * Removed multiplicator, too many high-level items were generated on low-difficulty maps. */ -int level_for_item(object *op, int difficulty, int retmult) +int level_for_item(const object *op, int difficulty) { - int level, mult, olevel; + int mult = 0, olevel = 0; - mult = 0; - if (!op->inv) { - LOG(llevError,"level_for_item: Object %s has no inventory!\n", op->name); - return 0; + if (!op->inv) + { + LOG(llevError,"level_for_item: Object %s has no inventory!\n", op->name); + return 0; } - level = op->inv->level; - /* Basically, we set mult to the lowest spell increase attribute that is - * not zero - zero's mean no modification is done, so we don't want those. - * given we want non zero results, we can't just use a few MIN's here. - */ - mult = op->inv->dam_modifier; - if (op->inv->range_modifier && (op->inv->range_modifierinv->range_modifier; - if (op->inv->duration_modifier && (op->inv->duration_modifier < mult || mult==0)) - mult = op->inv->duration_modifier; - - if (mult == 0) - mult = 5; + olevel = op->inv->level + (double) difficulty * (1 - drand48 () * drand48 () * 2); - if (retmult) - return mult; + if (olevel <= 0) + olevel = rndm (1, MIN (op->inv->level, 1)); - olevel = mult * rndm(0, difficulty) + level; - if (olevel > MAXLEVEL) olevel = MAXLEVEL; + if (olevel > MAXLEVEL) + olevel = MAXLEVEL; - return olevel; + return olevel; } /* * Based upon the specified difficulty and upon the difftomagic_list array, * a random magical bonus is returned. This is used when determine * the magical bonus created on specific maps. + * + * elmex Thu Aug 10 18:45:44 CEST 2006: + * Scaling difficulty by max_level, as difficulty is a level and not some + * weird integer between 1-31. + * */ int magic_from_difficulty(int difficulty) { - int percent,loop; + int percent = 0, magic = 0; + int scaled_diff = ((double) difficulty / settings.max_level) * 31; - difficulty--; - if(difficulty<0) - difficulty=0; + scaled_diff--; - if (difficulty>=DIFFLEVELS) - difficulty=DIFFLEVELS-1; + if(scaled_diff < 0) + scaled_diff = 0; + + if (scaled_diff >= DIFFLEVELS) + scaled_diff = DIFFLEVELS-1; percent = RANDOM()%100; - for(loop=0;loop<(MAXMAGIC+1);++loop) { - percent -= difftomagic_list[difficulty][loop]; - if (percent<0) - break; - } - if (loop==(MAXMAGIC+1)) { - LOG(llevError,"Warning, table for difficulty %d bad.\n",difficulty); - loop=0; - } -/* LOG(llevDebug, "Chose magic %d for difficulty %d\n", loop, difficulty);*/ - return (RANDOM()%3)?loop:-loop; + for(magic = 0; magic < (MAXMAGIC + 1); magic++) + { + percent -= difftomagic_list[scaled_diff][magic]; + + if (percent < 0) + break; + } + + if (magic == (MAXMAGIC + 1)) + { + LOG(llevError,"Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); + magic = 0; + } + + magic = (RANDOM() % 3) ? magic : -magic; + + /* LOG(llevDebug, "Chose magic %d for difficulty (scaled %d) %d\n", magic, scaled_diff, difficulty); */ + + return magic; } /* @@ -973,7 +978,7 @@ */ if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier) { - op->level = level_for_item(op, difficulty, 0); + op->level = level_for_item(op, difficulty); op->value= op->value* op->inv->value * (op->level +50)/ (op->inv->level + 50); } @@ -984,7 +989,7 @@ break; case ROD: - op->level = level_for_item(op, difficulty, 0); + op->level = level_for_item(op, difficulty); /* Add 50 to both level an divisor to keep prices a little more * reasonable. Otherwise, a high level version of a low level * spell can be worth tons a money (eg, level 20 rod, level 2 spell = @@ -1001,7 +1006,7 @@ break; case SCROLL: - op->level = level_for_item(op, difficulty, 0); + op->level = level_for_item(op, difficulty); op->value= op->value * op->inv->value * (op->level +50) / (op->inv->level + 50); /* add exp so reading them properly gives xp */ op->stats.exp = op->value/5;