--- deliantra/server/common/treasure.C 2008/09/29 10:32:50 1.82 +++ deliantra/server/common/treasure.C 2010/04/21 09:30:07 1.106 @@ -1,22 +1,23 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team - * Copyright (©) 1992,2007 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2002 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992 Frank Tore Johansen * - * Deliantra 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 3 of the License, or - * (at your option) any later version. + * Deliantra is free software: you can redistribute it and/or modify it under + * the terms of the Affero GNU General Public License as published by the + * Free Software Foundation, either version 3 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, see . + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . * * The authors can be reached via e-mail to */ @@ -34,7 +35,6 @@ #include #include -#include extern char *spell_mapping[]; @@ -52,6 +52,20 @@ static tl_map_t tl_map; +//TODO: class method +static void free_treasurestruct (treasure *t); // bleh desu +static void +clear (treasurelist *tl) +{ + if (tl->items) + { + free_treasurestruct (tl->items); + tl->items = 0; + } + + tl->total_chance = 0; +} + /* * Searches for the given treasurelist */ @@ -92,19 +106,6 @@ return tl; } -//TODO: class method -void -clear (treasurelist *tl) -{ - if (tl->items) - { - free_treasurestruct (tl->items); - tl->items = 0; - } - - tl->total_chance = 0; -} - #ifdef TREASURE_DEBUG /* recursived checks the linked list. Treasurelist is passed only * so that the treasure name can be printed out @@ -256,11 +257,12 @@ op->expand_tail (); - if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y)) + if (!creator->is_on_map () + || (op->weight && op->blocked (creator->map, creator->x, creator->y))) op->destroy (); else { - SET_FLAG (op, FLAG_OBJ_ORIGINAL); + op->flag [FLAG_OBJ_ORIGINAL] = true; op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); } } @@ -268,7 +270,7 @@ { op = creator->insert (op); - if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) + if ((flags & GT_APPLY) && creator->flag [FLAG_MONSTER]) monster_check_apply (creator, op); } } @@ -310,7 +312,7 @@ { if (t->item && (t->item->invisible != 0 || !(flag & GT_INVISIBLE))) { - object *tmp = arch_to_object (t->item); + object *tmp = t->item->instance (); if (t->nrof && tmp->nrof <= 1) tmp->nrof = rndm (t->nrof) + 1; @@ -367,7 +369,7 @@ } else if (t->item && (t->item->invisible != 0 || flag != GT_INVISIBLE)) { - if (object *tmp = arch_to_object (t->item)) + if (object *tmp = t->item->instance ()) { if (t->nrof && tmp->nrof <= 1) tmp->nrof = rndm (t->nrof) + 1; @@ -496,7 +498,7 @@ * elmex Wed Aug 9 17:44:59 CEST 2006: * Removed multiplicator, too many high-level items were generated on low-difficulty maps. */ -int +static int level_for_item (const object *op, int difficulty) { if (!op->inv) @@ -510,7 +512,7 @@ if (olevel <= 0) olevel = rndm (1, op->inv->level); - return min (olevel, MAXLEVEL); + return min (olevel, MAXLEVEL_TREASURE); } /* @@ -523,7 +525,7 @@ * weird integer between 1-31. * */ -int +static int magic_from_difficulty (int difficulty) { int percent = 0, magic = 0; @@ -612,7 +614,7 @@ i = max_magic; set_abs_magic (op, i); if (i < 0) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); } /* @@ -623,10 +625,9 @@ * other bonuses previously rolled and ones the item might natively have. * 2) Add code to deal with new PR method. */ -void +static void set_ring_bonus (object *op, int bonus) { - int r = rndm (bonus > 0 ? 25 : 11); if (op->type == AMULET) @@ -716,7 +717,7 @@ case 20: if (op->type == AMULET) { - SET_FLAG (op, FLAG_REFL_SPELL); + op->set_flag (FLAG_REFL_SPELL); op->value *= 11; } else @@ -729,7 +730,7 @@ case 21: if (op->type == AMULET) { - SET_FLAG (op, FLAG_REFL_MISSILE); + op->set_flag (FLAG_REFL_MISSILE); op->value *= 9; } else @@ -759,7 +760,7 @@ * rings and amulets. * Another scheme is used to calculate the magic of weapons and armours. */ -int +static int get_magic (int diff) { int i; @@ -774,6 +775,23 @@ return 4; } +/* special_potion() - so that old potion code is still done right. */ +static int +special_potion (object *op) +{ + 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 (int i = 0; i < NROFATTACKS; i++) + if (op->resist[i]) + return 1; + + return 0; +} + #define DICE2 (get_magic(2)==2?2:1) #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) @@ -818,8 +836,7 @@ op->randomitems = 0; } - if (difficulty < 1) - difficulty = 1; + max_it (difficulty, 1); if (INVOKE_OBJECT (ADD_BONUS, op, ARG_OBJECT (creator != op ? creator : 0), @@ -888,7 +905,7 @@ } /* materialtype modifications. Note we allow this on artifacts. */ - set_materialname (op, difficulty, NULL); + select_material (op, difficulty); if (flags & GT_MINIMAL) { @@ -909,15 +926,15 @@ case SHIELD: case HELMET: case CLOAK: - if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) + if (op->flag [FLAG_CURSED] && !(rndm (4))) set_ring_bonus (op, -DICE2); break; case BRACERS: - if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)) + if (!rndm (op->flag [FLAG_CURSED] ? 5 : 20)) { - set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); - if (!QUERY_FLAG (op, FLAG_CURSED)) + set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); + if (!op->flag [FLAG_CURSED]) op->value *= 3; } break; @@ -929,9 +946,7 @@ /* Handle healing and magic power potions */ if (op->stats.sp && !op->randomitems) { - object *tmp; - - tmp = get_archetype (spell_mapping[op->stats.sp]); + object *tmp = get_archetype (spell_mapping[op->stats.sp]); insert_ob_in_ob (tmp, op); op->stats.sp = 0; } @@ -949,7 +964,7 @@ if (op->inv && op->randomitems) { /* value multiplier is same as for scrolls */ - op->value = (op->value * op->inv->value); + op->value *= op->inv->value; op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); } else @@ -959,7 +974,8 @@ } if (!(flags & GT_ONLY_GOOD) && rndm (2)) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); + break; } @@ -972,16 +988,16 @@ break; if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); - set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); + set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); if (op->type != RING) /* Amulets have only one ability */ break; if (!(rndm (4))) { - int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; + int d = (rndm (2) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; if (d > 0) op->value *= 3; @@ -990,7 +1006,7 @@ if (!(rndm (4))) { - int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; + int d = (rndm (3) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; if (d > 0) op->value *= 5; @@ -998,8 +1014,8 @@ } } - if (GET_ANIM_ID (op)) - SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); + if (op->animation_id) + op->set_anim_frame (rndm (op->anim_frames ())); break; @@ -1011,7 +1027,7 @@ if (!op->msg && rndm (10)) { /* set the book level properly */ - if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) + if (creator->level == 0 || creator->flag [FLAG_ALIVE]) { if (op->map && op->map->difficulty) op->level = rndm (op->map->difficulty) + rndm (10) + 1; @@ -1024,23 +1040,27 @@ tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); /* books w/ info are worth more! */ op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); - /* creator related stuff */ - - /* for library, chained books. Note that some monsters have no_pick - * set - we don't want to set no pick in that case. - */ - if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) - SET_FLAG (op, FLAG_NO_PICK); - if (creator->slaying && !op->slaying) /* for check_inv floors */ - op->slaying = creator->slaying; /* add exp so reading it gives xp (once) */ op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; } + + /* creator related stuff */ + + /* for library, chained books. Note that some monsters have no_pick + * set - we don't want to set no pick in that case. + */ + if (creator->flag [FLAG_NO_PICK] && !creator->flag [FLAG_MONSTER]) + op->set_flag (FLAG_NO_PICK); + if (creator->slaying && !op->slaying) /* for check_inv floors */ + op->slaying = creator->slaying; break; case SPELLBOOK: - op->value = op->value * op->inv->value; + op->value *= + pow ((op->inv->value > 0 ? op->inv->value : 1) + * op->inv->level, + 1.5); /* add exp so learning gives xp */ op->level = op->inv->level; op->stats.exp = op->value; @@ -1080,9 +1100,9 @@ op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); /* maxhp is used to denote how many 'charges' the rod holds before */ if (op->stats.maxhp) - op->stats.maxhp *= MAX (op->inv->stats.sp, op->inv->stats.grace); + op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); else - op->stats.maxhp = 2 * MAX (op->inv->stats.sp, op->inv->stats.grace); + op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); op->stats.hp = op->stats.maxhp; break; @@ -1107,8 +1127,8 @@ if (flags & GT_STARTEQUIP) { - if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !QUERY_FLAG (op, FLAG_IS_THROWN)) - SET_FLAG (op, FLAG_STARTEQUIP); + if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !op->flag [FLAG_IS_THROWN]) + op->set_flag (FLAG_STARTEQUIP); else if (op->type != MONEY) op->value = 0; } @@ -1129,7 +1149,7 @@ * Allocate and return the pointer to an empty artifactlist structure. */ static artifactlist * -get_empty_artifactlist (void) +get_empty_artifactlist () { return salloc0 (); } @@ -1138,7 +1158,7 @@ * Allocate and return the pointer to an empty artifact structure. */ static artifact * -get_empty_artifact (void) +get_empty_artifact () { return salloc0 (); } @@ -1161,7 +1181,7 @@ * Builds up the lists of artifacts from the file in the libdir. */ void -init_artifacts (void) +init_artifacts () { static int has_been_inited = 0; char filename[MAX_BUF]; @@ -1191,11 +1211,11 @@ if (!strcmp (f.get_str (), "all")) break; - char *next, *cp = f.get_str (); - + const char *cp = f.get_str (); + char *next; do { - if ((next = strchr (cp, ','))) + if ((next = (char *)strchr (cp, ','))) *next++ = '\0'; linked_char *tmp = new linked_char; @@ -1300,35 +1320,35 @@ op->move_type |= change->move_type; op->stats.luck += change->stats.luck; - if (QUERY_FLAG (change, FLAG_CURSED)) - SET_FLAG (op, FLAG_CURSED); - if (QUERY_FLAG (change, FLAG_DAMNED)) - SET_FLAG (op, FLAG_DAMNED); - if ((QUERY_FLAG (change, FLAG_CURSED) || QUERY_FLAG (change, FLAG_DAMNED)) && op->magic > 0) + if (change->flag [FLAG_CURSED]) + op->set_flag (FLAG_CURSED); + if (change->flag [FLAG_DAMNED]) + op->set_flag (FLAG_DAMNED); + if ((change->flag [FLAG_CURSED] || change->flag [FLAG_DAMNED]) && op->magic > 0) set_abs_magic (op, -op->magic); - if (QUERY_FLAG (change, FLAG_LIFESAVE)) - SET_FLAG (op, FLAG_LIFESAVE); - if (QUERY_FLAG (change, FLAG_REFL_SPELL)) - SET_FLAG (op, FLAG_REFL_SPELL); - if (QUERY_FLAG (change, FLAG_STEALTH)) - SET_FLAG (op, FLAG_STEALTH); - if (QUERY_FLAG (change, FLAG_XRAYS)) - SET_FLAG (op, FLAG_XRAYS); - if (QUERY_FLAG (change, FLAG_BLIND)) - SET_FLAG (op, FLAG_BLIND); - if (QUERY_FLAG (change, FLAG_SEE_IN_DARK)) - SET_FLAG (op, FLAG_SEE_IN_DARK); - if (QUERY_FLAG (change, FLAG_REFL_MISSILE)) - SET_FLAG (op, FLAG_REFL_MISSILE); - if (QUERY_FLAG (change, FLAG_MAKE_INVIS)) - SET_FLAG (op, FLAG_MAKE_INVIS); + if (change->flag [FLAG_LIFESAVE]) + op->set_flag (FLAG_LIFESAVE); + if (change->flag [FLAG_REFL_SPELL]) + op->set_flag (FLAG_REFL_SPELL); + if (change->flag [FLAG_STEALTH]) + op->set_flag (FLAG_STEALTH); + if (change->flag [FLAG_XRAYS]) + op->set_flag (FLAG_XRAYS); + if (change->flag [FLAG_BLIND]) + op->set_flag (FLAG_BLIND); + if (change->flag [FLAG_SEE_IN_DARK]) + op->set_flag (FLAG_SEE_IN_DARK); + if (change->flag [FLAG_REFL_MISSILE]) + op->set_flag (FLAG_REFL_MISSILE); + if (change->flag [FLAG_MAKE_INVIS]) + op->set_flag (FLAG_MAKE_INVIS); - if (QUERY_FLAG (change, FLAG_STAND_STILL)) + if (change->flag [FLAG_STAND_STILL]) { - CLEAR_FLAG (op, FLAG_ANIMATE); + op->clr_flag (FLAG_ANIMATE); /* so artifacts will join */ - if (!QUERY_FLAG (op, FLAG_ALIVE)) + if (!op->flag [FLAG_ALIVE]) op->speed = 0.0; op->set_speed (op->speed); @@ -1352,9 +1372,10 @@ /* Remove any spells this object currently has in it */ op->destroy_inv (false); - object *tmp = arch_to_object (change->other_arch); + object *tmp = change->other_arch->instance (); insert_ob_in_ob (tmp, op); } + /* No harm setting this for potions/horns */ op->other_arch = change->other_arch; } @@ -1448,8 +1469,8 @@ if (change->materials) op->materials = change->materials; - if (change->materialname) - op->materialname = change->materialname; + if (change->material != MATERIAL_NULL) + op->material = change->material; if (change->slaying) op->slaying = change->slaying; @@ -1511,12 +1532,12 @@ #if 0 /* Bit verbose, but keep it here until next time I need it... */ { - char identified = QUERY_FLAG (op, FLAG_IDENTIFIED); + char identified = op->flag [FLAG_IDENTIFIED]; - SET_FLAG (op, FLAG_IDENTIFIED); + op->set_flag (FLAG_IDENTIFIED); LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); if (!identified) - CLEAR_FLAG (op, FLAG_IDENTIFIED); + op->clr_flag (FLAG_IDENTIFIED); } #endif return; @@ -1568,9 +1589,11 @@ #endif return; } - if (!strcmp (art->item->name, "NONE")) + + if (art->item->name == shstr_NONE) return; - if (FABS (op->magic) < art->item->magic) + + if (fabs (op->magic) < art->item->magic) continue; /* Not magic enough to be this item */ /* Map difficulty not high enough */ @@ -1631,30 +1654,15 @@ /* if donor has some attacktypes, the flesh is poisonous */ if (donor->attacktype & AT_POISON) item->type = POISON; + if (donor->attacktype & AT_ACID) item->stats.hp = -1 * item->stats.food; - SET_FLAG (item, FLAG_NO_STEAL); - } -} -/* special_potion() - so that old potion code is still done right. */ -int -special_potion (object *op) -{ - 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 (int i = 0; i < NROFATTACKS; i++) - if (op->resist[i]) - return 1; - - return 0; + item->set_flag (FLAG_NO_STEAL); + } } -void +static void free_treasurestruct (treasure *t) { if (t->next) free_treasurestruct (t->next); @@ -1664,7 +1672,7 @@ delete t; } -void +static void free_charlinks (linked_char *lc) { if (lc->next) @@ -1673,7 +1681,7 @@ delete lc; } -void +static void free_artifact (artifact *at) { if (at->next) free_artifact (at->next); @@ -1684,34 +1692,3 @@ sfree (at); } -void -free_artifactlist (artifactlist *al) -{ - artifactlist *nextal; - - for (al = first_artifactlist; al; al = nextal) - { - nextal = al->next; - - if (al->items) - free_artifact (al->items); - - sfree (al); - } -} - -void -free_all_treasures (void) -{ - treasurelist *tl, *next; - - for (tl = first_treasurelist; tl; tl = next) - { - clear (tl); - - next = tl->next; - delete tl; - } - - free_artifactlist (first_artifactlist); -}