--- deliantra/server/common/treasure.C 2006/09/12 18:15:34 1.17 +++ deliantra/server/common/treasure.C 2007/01/03 02:30:51 1.30 @@ -1,9 +1,3 @@ - -/* - * static char *rcs_treasure_c = - * "$Id: treasure.C,v 1.17 2006/09/12 18:15:34 root Exp $"; - */ - /* CrossFire, A Multiplayer game for X-windows @@ -24,7 +18,7 @@ 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-devel@real-time.com + The authors can be reached via e-mail at */ #define ALLOWED_COMBINATION @@ -60,13 +54,13 @@ warn_archetypes = 1; if (ring_arch == NULL) - ring_arch = find_archetype ("ring"); + ring_arch = archetype::find ("ring"); if (amulet_arch == NULL) - amulet_arch = find_archetype ("amulet"); + amulet_arch = archetype::find ("amulet"); if (staff_arch == NULL) - staff_arch = find_archetype ("staff"); + staff_arch = archetype::find ("staff"); if (crown_arch == NULL) - crown_arch = find_archetype ("crown"); + crown_arch = archetype::find ("crown"); warn_archetypes = prev_warn; } @@ -121,7 +115,7 @@ if (sscanf (cp, "arch %s", variable)) { - if ((t->item = find_archetype (variable)) == NULL) + if ((t->item = archetype::find (variable)) == NULL) LOG (llevError, "Treasure lacks archetype: %s\n", variable); } else if (sscanf (cp, "list %s", variable)) @@ -164,13 +158,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) @@ -266,7 +258,7 @@ if (!name_) return 0; - for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) + for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) if (name_ == tl->name) return tl; @@ -288,8 +280,6 @@ * abilities. This is used by summon spells, thus no summoned monsters * start with equipment, but only their abilities). */ - - static void put_treasure (object *op, object *creator, int flags) { @@ -302,17 +292,17 @@ */ if (flags & GT_ENVIRONMENT && op->type != SPELL) { - op->x = creator->x; - op->y = creator->y; SET_FLAG (op, FLAG_OBJ_ORIGINAL); - insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); + op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); } else { - op = insert_ob_in_ob (op, creator); + op = creator->insert (op); + if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) monster_check_apply (creator, op); - if ((flags & GT_UPDATE_INV) && (tmp = is_player_inv (creator)) != NULL) + + if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) esrv_send_item (tmp, op); } } @@ -346,12 +336,16 @@ { if (t->name) { - if (strcmp (t->name, "NONE") && difficulty >= t->magic) - create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); + if (difficulty >= t->magic) + { + treasurelist *tl = find_treasurelist (t->name); + if (tl) + create_treasure (tl, op, flag, difficulty, tries); + } } 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) @@ -401,18 +395,19 @@ if (t->name) { - if (!strcmp (t->name, "NONE")) - return; - if (difficulty >= t->magic) - create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); + { + treasurelist *tl = find_treasurelist (t->name); + if (tl) + create_treasure (tl, op, flag, difficulty, tries); + } else if (t->nrof) create_one_treasure (tl, op, flag, difficulty, tries); 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); @@ -436,7 +431,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 +439,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,21 +451,23 @@ * inserted into, and then return that treausre */ object * -generate_treasure (treasurelist * t, int difficulty) +generate_treasure (treasurelist *tl, int difficulty) { - object *ob = get_object (), *tmp; + 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; if (tmp != NULL) - remove_ob (tmp); + tmp->remove (); + if (ob->inv) - { - LOG (llevError, "In generate treasure, created multiple objects.\n"); - } - free_object (ob); + LOG (llevError, "In generate treasure, created multiple objects.\n"); + + ob->destroy (); return tmp; } @@ -857,6 +854,12 @@ if (difficulty < 1) difficulty = 1; + if (INVOKE_OBJECT (ADD_BONUS, op, + ARG_OBJECT (creator != op ? creator : 0), + ARG_INT (difficulty), ARG_INT (max_magic), + ARG_INT (flags))) + return; + if (!(flags & GT_MINIMAL)) { if (op->arch == crown_arch) @@ -1001,9 +1004,8 @@ case RING: if (op->arch == NULL) { - remove_ob (op); - free_object (op); - op = NULL; + op->destroy (); + op = 0; break; } @@ -1171,14 +1173,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; } /* @@ -1188,16 +1190,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; } /* @@ -1257,15 +1259,16 @@ if (depth > 100) return; - while (t != NULL) + while (t) { - if (t->name != NULL) + if (t->name) { for (i = 0; i < depth; i++) fprintf (logfile, " "); fprintf (logfile, "{ (list: %s)\n", &t->name); tl = find_treasurelist (t->name); - dump_monster_treasure_rec (name, tl->items, depth + 2); + if (tl) + dump_monster_treasure_rec (name, tl->items, depth + 2); for (i = 0; i < depth; i++) fprintf (logfile, " "); fprintf (logfile, "} (end of list: %s)\n", &t->name); @@ -1274,25 +1277,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; } } @@ -1392,7 +1398,7 @@ art->difficulty = (uint8) value; else if (!strncmp (cp, "Object", 6)) { - art->item = get_object (); + art->item = object::create (); if (!load_object (thawer, art->item, 0)) LOG (llevError, "Init_Artifacts: Could not load object.\n"); @@ -1491,7 +1497,7 @@ if (!QUERY_FLAG (op, FLAG_ALIVE)) op->speed = 0.0; - update_ob_speed (op); + op->set_speed (op->speed); } if (change->nrof) @@ -1513,11 +1519,7 @@ /* Remove any spells this object currently has in it */ while (op->inv) - { - tmp_obj = op->inv; - remove_ob (tmp_obj); - free_object (tmp_obj); - } + op->inv->destroy (); tmp_obj = arch_to_object (change->other_arch); insert_ob_in_ob (tmp_obj, op); @@ -1564,12 +1566,8 @@ op->item_power = change->item_power; for (i = 0; i < NROFATTACKS; i++) - { - if (change->resist[i]) - { - op->resist[i] += change->resist[i]; - } - } + if (change->resist[i]) + op->resist[i] += change->resist[i]; if (change->stats.dam) { @@ -1810,16 +1808,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; @@ -1857,7 +1852,7 @@ if (at->allowed) free_charlinks (at->allowed); - at->item->free (1); + at->item->destroy (1); delete at; } @@ -1867,7 +1862,7 @@ { artifactlist *nextal; - for (al = first_artifactlist; al != NULL; al = nextal) + for (al = first_artifactlist; al; al = nextal) { nextal = al->next;