--- deliantra/server/common/treasure.C 2006/12/26 20:04:09 1.29 +++ deliantra/server/common/treasure.C 2007/02/07 02:04:46 1.36 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The authors can be reached via e-mail at -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The authors can be reached via e-mail at + */ #define ALLOWED_COMBINATION @@ -158,13 +159,11 @@ 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); if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); /* find_treasurelist will print out its own error message */ if (t->name && *t->name) - (void) find_treasurelist (t->name); + find_treasurelist (t->name); if (t->next) check_treasurelist (t->next, tl); if (t->next_yes) @@ -334,11 +333,11 @@ { object *tmp; - if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) + if ((int) t->chance >= 100 || (rndm (100) + 1) < (int) t->chance) { if (t->name) { - if (strcmp (t->name, "NONE") && difficulty >= t->magic) + if (difficulty >= t->magic) { treasurelist *tl = find_treasurelist (t->name); if (tl) @@ -347,11 +346,12 @@ } else { - if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) + if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))) { tmp = arch_to_object (t->item); if (t->nrof && tmp->nrof <= 1) - tmp->nrof = RANDOM () % ((int) t->nrof) + 1; + tmp->nrof = rndm (t->nrof) + 1; + fix_generated_item (tmp, op, difficulty, t->magic, flag); change_treasure (t, tmp); put_treasure (tmp, op, flag); @@ -369,9 +369,9 @@ } void -create_one_treasure (treasurelist * tl, object *op, int flag, int difficulty, int tries) +create_one_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries) { - int value = RANDOM () % tl->total_chance; + int value = rndm (tl->total_chance); treasure *t; if (tries++ > 100) @@ -397,9 +397,6 @@ if (t->name) { - if (!strcmp (t->name, "NONE")) - return; - if (difficulty >= t->magic) { treasurelist *tl = find_treasurelist (t->name); @@ -412,7 +409,7 @@ return; } - if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) + if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE)) { object *tmp = arch_to_object (t->item); @@ -420,7 +417,7 @@ return; if (t->nrof && tmp->nrof <= 1) - tmp->nrof = RANDOM () % ((int) t->nrof) + 1; + tmp->nrof = rndm (t->nrof) + 1; fix_generated_item (tmp, op, difficulty, t->magic, flag); change_treasure (t, tmp); @@ -436,7 +433,7 @@ * to do that. */ void -create_treasure (treasurelist * t, object *op, int flag, int difficulty, int tries) +create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries) { if (tries++ > 100) @@ -444,10 +441,10 @@ LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); return; } - if (t->total_chance) - create_one_treasure (t, op, flag, difficulty, tries); + if (tl->total_chance) + create_one_treasure (tl, op, flag, difficulty, tries); else - create_all_treasures (t->items, op, flag, difficulty, tries); + create_all_treasures (tl->items, op, flag, difficulty, tries); } /* This is similar to the old generate treasure function. However, @@ -456,13 +453,13 @@ * inserted into, and then return that treausre */ object * -generate_treasure (treasurelist *t, int difficulty) +generate_treasure (treasurelist *tl, int difficulty) { difficulty = clamp (difficulty, 1, settings.max_level); object *ob = object::create (), *tmp; - create_treasure (t, ob, 0, difficulty, 0); + create_treasure (tl, ob, 0, difficulty, 0); /* Don't want to free the object we are about to return */ tmp = ob->inv; @@ -576,7 +573,7 @@ if (scaled_diff >= DIFFLEVELS) scaled_diff = DIFFLEVELS - 1; - percent = RANDOM () % 100; + percent = rndm (100); for (magic = 0; magic < (MAXMAGIC + 1); magic++) { @@ -592,7 +589,7 @@ magic = 0; } - magic = (RANDOM () % 3) ? magic : -magic; + magic = (rndm (3)) ? magic : -magic; /* LOG(llevDebug, "Chose magic %d for difficulty (scaled %d) %d\n", magic, scaled_diff, difficulty); */ return magic; @@ -617,7 +614,7 @@ if (op->type == ARMOUR) ARMOUR_SPEED (op) = (ARMOUR_SPEED (&op->arch->clone) * (100 + magic * 10)) / 100; - if (magic < 0 && !(RANDOM () % 3)) /* You can't just check the weight always */ + if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ magic = (-magic); op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100; } @@ -625,7 +622,7 @@ { if (op->type == ARMOUR) ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; - if (magic < 0 && !(RANDOM () % 3)) /* You can't just check the weight always */ + if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ magic = (-magic); op->weight = (op->weight * (100 - magic * 10)) / 100; } @@ -664,18 +661,18 @@ set_ring_bonus (object *op, int bonus) { - int r = RANDOM () % (bonus > 0 ? 25 : 11); + int r = rndm (bonus > 0 ? 25 : 11); if (op->type == AMULET) { - if (!(RANDOM () % 21)) - r = 20 + RANDOM () % 2; + if (!(rndm (21))) + r = 20 + rndm (2); else { - if (RANDOM () & 2) + if (rndm (2)) r = 10; else - r = 11 + RANDOM () % 9; + r = 11 + rndm (9); } } @@ -722,10 +719,10 @@ case 18: case 19: { - int b = 5 + FABS (bonus), val, resist = RANDOM () % num_resist_table; + int b = 5 + abs (bonus), val, resist = rndm (num_resist_table); /* Roughly generate a bonus between 100 and 35 (depending on the bonus) */ - val = 10 + RANDOM () % b + RANDOM () % b + RANDOM () % b + RANDOM () % b; + val = 10 + rndm (b) + rndm (b) + rndm (b) + rndm (b); /* Cursed items need to have higher negative values to equal out with * positive values for how protections work out. Put another @@ -733,16 +730,17 @@ * even values. */ if (bonus < 0) - val = 2 * -val - RANDOM () % b; + val = 2 * -val - rndm (b); if (val > 35) val = 35; /* Upper limit */ b = 0; + while (op->resist[resist_table[resist]] != 0 && b < 4) - { - resist = RANDOM () % num_resist_table; - } + resist = rndm (num_resist_table); + if (b == 4) return; /* Not able to find a free resistance */ + op->resist[resist_table[resist]] = val; /* We should probably do something more clever here to adjust value * based on how good a resistance we gave. @@ -780,6 +778,7 @@ op->value = (op->value * 2) / 3; break; } + if (bonus > 0) op->value *= 2 * bonus; else @@ -794,7 +793,6 @@ * rings and amulets. * Another scheme is used to calculate the magic of weapons and armours. */ - int get_magic (int diff) { @@ -802,14 +800,16 @@ if (diff < 3) diff = 3; + for (i = 0; i < 4; i++) - if (RANDOM () % diff) + if (rndm (diff)) return i; + return 4; } #define DICE2 (get_magic(2)==2?2:1) -#define DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3) +#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) /* * fix_generated_item(): This is called after an item is generated, in @@ -880,7 +880,9 @@ num_enchantments = calc_item_power (op, 1); - if ((!was_magic && !(RANDOM () % CHANCE_FOR_ARTIFACT)) || op->type == HORN || difficulty >= settings.max_level) /* high difficulties always generate an artifact, + if ((!was_magic && !rndm (CHANCE_FOR_ARTIFACT)) + || op->type == HORN + || difficulty >= settings.max_level) /* high difficulties always generate an artifact, * used for shop_floors or treasures */ generate_artifact (op, difficulty); } @@ -948,12 +950,12 @@ case SHIELD: case HELMET: case CLOAK: - if (QUERY_FLAG (op, FLAG_CURSED) && !(RANDOM () % 4)) + if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) set_ring_bonus (op, -DICE2); break; case BRACERS: - if (!(RANDOM () % (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20))) + if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)) { set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); if (!QUERY_FLAG (op, FLAG_CURSED)) @@ -989,7 +991,7 @@ { /* value multiplier is same as for scrolls */ op->value = (op->value * op->inv->value); - op->level = op->inv->level / 2 + RANDOM () % difficulty + RANDOM () % difficulty; + op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); } else { @@ -997,7 +999,7 @@ op->name_pl = "potions"; } - if (!(flags & GT_ONLY_GOOD) && RANDOM () % 2) + if (!(flags & GT_ONLY_GOOD) && rndm (2)) SET_FLAG (op, FLAG_CURSED); break; } @@ -1017,7 +1019,7 @@ if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ break; - if (!(flags & GT_ONLY_GOOD) && !(RANDOM () % 3)) + if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) SET_FLAG (op, FLAG_CURSED); set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); @@ -1025,18 +1027,18 @@ if (op->type != RING) /* Amulets have only one ability */ break; - if (!(RANDOM () % 4)) + if (!(rndm (4))) { - int d = (RANDOM () % 2 || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; + int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; if (d > 0) op->value *= 3; set_ring_bonus (op, d); - if (!(RANDOM () % 4)) + if (!(rndm (4))) { - int d = (RANDOM () % 3 || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; + int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; if (d > 0) op->value *= 5; @@ -1045,7 +1047,7 @@ } if (GET_ANIM_ID (op)) - SET_ANIMATION (op, RANDOM () % ((int) NUM_ANIMATIONS (op))); + SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); break; @@ -1054,18 +1056,18 @@ * msg for it, and tailor its properties based on theĀ· * creator and/or map level we found it on. */ - if (!op->msg && RANDOM () % 10) + if (!op->msg && rndm (10)) { /* set the book level properly */ if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) { if (op->map && op->map->difficulty) - op->level = RANDOM () % (op->map->difficulty) + RANDOM () % 10 + 1; + op->level = rndm (op->map->difficulty) + rndm (10) + 1; else - op->level = RANDOM () % 20 + 1; + op->level = rndm (20) + 1; } else - op->level = RANDOM () % creator->level; + op->level = rndm (creator->level); tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); /* books w/ info are worth more! */ @@ -1178,14 +1180,14 @@ static artifactlist * get_empty_artifactlist (void) { - artifactlist *tl = (artifactlist *) malloc (sizeof (artifactlist)); + artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist)); - if (tl == NULL) + if (al == NULL) fatal (OUT_OF_MEMORY); - tl->next = NULL; - tl->items = NULL; - tl->total_chance = 0; - return tl; + al->next = NULL; + al->items = NULL; + al->total_chance = 0; + return al; } /* @@ -1195,16 +1197,16 @@ static artifact * get_empty_artifact (void) { - artifact *t = (artifact *) malloc (sizeof (artifact)); + artifact *a = (artifact *) malloc (sizeof (artifact)); - if (t == NULL) + if (a == NULL) fatal (OUT_OF_MEMORY); - t->item = NULL; - t->next = NULL; - t->chance = 0; - t->difficulty = 0; - t->allowed = NULL; - return t; + a->item = NULL; + a->next = NULL; + a->chance = 0; + a->difficulty = 0; + a->allowed = NULL; + return a; } /* @@ -1264,9 +1266,9 @@ if (depth > 100) return; - while (t != NULL) + while (t) { - if (t->name != NULL) + if (t->name) { for (i = 0; i < depth; i++) fprintf (logfile, " "); @@ -1282,25 +1284,28 @@ { for (i = 0; i < depth; i++) fprintf (logfile, " "); - if (t->item->clone.type == FLESH) + if (t->item && t->item->clone.type == FLESH) fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); else fprintf (logfile, "%s\n", &t->item->clone.name); } - if (t->next_yes != NULL) + + if (t->next_yes) { for (i = 0; i < depth; i++) fprintf (logfile, " "); fprintf (logfile, " (if yes)\n"); dump_monster_treasure_rec (name, t->next_yes, depth + 1); } - if (t->next_no != NULL) + + if (t->next_no) { for (i = 0; i < depth; i++) fprintf (logfile, " "); fprintf (logfile, " (if no)\n"); dump_monster_treasure_rec (name, t->next_no, depth + 1); } + t = t->next; } } @@ -1503,7 +1508,7 @@ } if (change->nrof) - op->nrof = RANDOM () % ((int) change->nrof) + 1; + op->nrof = rndm (change->nrof) + 1; op->stats.exp += change->stats.exp; /* Speed modifier */ op->stats.wc += change->stats.wc; @@ -1616,8 +1621,8 @@ op->value *= change->value; - if (change->material) - op->material = change->material; + if (change->materials) + op->materials = change->materials; if (change->materialname) op->materialname = change->materialname; @@ -1721,9 +1726,9 @@ for (i = 0; i < ARTIFACT_TRIES; i++) { - int roll = RANDOM () % al->total_chance; + int roll = rndm (al->total_chance); - for (art = al->items; art != NULL; art = art->next) + for (art = al->items; art; art = art->next) { roll -= art->chance; if (roll < 0) @@ -1810,16 +1815,13 @@ int special_potion (object *op) { - - int i; - if (op->attacktype) return 1; if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) return 1; - for (i = 0; i < NROFATTACKS; i++) + for (int i = 0; i < NROFATTACKS; i++) if (op->resist[i]) return 1;