--- deliantra/server/common/treasure.C 2009/10/15 16:00:37 1.87 +++ deliantra/server/common/treasure.C 2010/04/11 00:34:05 1.104 @@ -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[]; @@ -53,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 */ @@ -93,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 @@ -257,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); } } @@ -269,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); } } @@ -311,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; @@ -368,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; @@ -497,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) @@ -524,7 +525,7 @@ * weird integer between 1-31. * */ -int +static int magic_from_difficulty (int difficulty) { int percent = 0, magic = 0; @@ -613,7 +614,7 @@ i = max_magic; set_abs_magic (op, i); if (i < 0) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); } /* @@ -624,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) @@ -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 @@ -760,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; @@ -775,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)) @@ -819,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), @@ -889,7 +905,7 @@ } /* materialtype modifications. Note we allow this on artifacts. */ - set_materialname (op, difficulty, NULL); + select_material (op, difficulty); if (flags & GT_MINIMAL) { @@ -910,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; @@ -930,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; } @@ -950,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 @@ -960,7 +974,8 @@ } if (!(flags & GT_ONLY_GOOD) && rndm (2)) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); + break; } @@ -973,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; @@ -991,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; @@ -1012,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; @@ -1035,8 +1050,8 @@ /* 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; @@ -1082,9 +1097,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; @@ -1109,8 +1124,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; } @@ -1131,7 +1146,7 @@ * Allocate and return the pointer to an empty artifactlist structure. */ static artifactlist * -get_empty_artifactlist (void) +get_empty_artifactlist () { return salloc0 (); } @@ -1140,7 +1155,7 @@ * Allocate and return the pointer to an empty artifact structure. */ static artifact * -get_empty_artifact (void) +get_empty_artifact () { return salloc0 (); } @@ -1163,7 +1178,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]; @@ -1193,11 +1208,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; @@ -1302,35 +1317,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); @@ -1354,9 +1369,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; } @@ -1450,8 +1466,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; @@ -1513,12 +1529,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; @@ -1639,28 +1655,11 @@ if (donor->attacktype & AT_ACID) item->stats.hp = -1 * item->stats.food; - SET_FLAG (item, FLAG_NO_STEAL); + item->set_flag (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; -} - -void +static void free_treasurestruct (treasure *t) { if (t->next) free_treasurestruct (t->next); @@ -1670,7 +1669,7 @@ delete t; } -void +static void free_charlinks (linked_char *lc) { if (lc->next) @@ -1679,7 +1678,7 @@ delete lc; } -void +static void free_artifact (artifact *at) { if (at->next) free_artifact (at->next); @@ -1690,34 +1689,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); -}