--- deliantra/server/common/treasure.C 2009/11/06 13:03:34 1.89 +++ deliantra/server/common/treasure.C 2010/04/21 09:30:07 1.106 @@ -1,9 +1,9 @@ /* * 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 Affero GNU General Public License as published by the @@ -35,7 +35,6 @@ #include #include -#include extern char *spell_mapping[]; @@ -258,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); } } @@ -270,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); } } @@ -312,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; @@ -369,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; @@ -512,7 +512,7 @@ if (olevel <= 0) olevel = rndm (1, op->inv->level); - return min (olevel, MAXLEVEL); + return min (olevel, MAXLEVEL_TREASURE); } /* @@ -614,7 +614,7 @@ i = max_magic; set_abs_magic (op, i); if (i < 0) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); } /* @@ -717,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 @@ -730,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 @@ -836,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), @@ -906,7 +905,7 @@ } /* materialtype modifications. Note we allow this on artifacts. */ - set_materialname (op, difficulty, NULL); + select_material (op, difficulty); if (flags & GT_MINIMAL) { @@ -927,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; @@ -947,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; } @@ -967,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 @@ -977,7 +974,8 @@ } if (!(flags & GT_ONLY_GOOD) && rndm (2)) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); + break; } @@ -990,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; @@ -1008,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; @@ -1029,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; @@ -1052,14 +1050,17 @@ /* 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->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; @@ -1099,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; @@ -1126,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; } @@ -1148,7 +1149,7 @@ * Allocate and return the pointer to an empty artifactlist structure. */ static artifactlist * -get_empty_artifactlist (void) +get_empty_artifactlist () { return salloc0 (); } @@ -1157,7 +1158,7 @@ * Allocate and return the pointer to an empty artifact structure. */ static artifact * -get_empty_artifact (void) +get_empty_artifact () { return salloc0 (); } @@ -1180,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]; @@ -1210,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; @@ -1319,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); @@ -1371,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; } @@ -1467,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; @@ -1530,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; @@ -1656,7 +1658,7 @@ if (donor->attacktype & AT_ACID) item->stats.hp = -1 * item->stats.food; - SET_FLAG (item, FLAG_NO_STEAL); + item->set_flag (FLAG_NO_STEAL); } } @@ -1690,34 +1692,3 @@ sfree (at); } -static 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); - } -} - -static 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); -}