--- deliantra/server/common/treasure.C 2008/01/22 15:53:01 1.69
+++ deliantra/server/common/treasure.C 2010/04/07 19:54:45 1.102
@@ -1,22 +1,23 @@
/*
* This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
- * Copyright (©) 2005,2006,2007 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,8 +35,6 @@
#include
#include
-#include
-#include
extern char *spell_mapping[];
@@ -48,12 +47,25 @@
treasurelist *,
str_hash,
str_equal,
- slice_allocator< std::pair >,
- true
+ slice_allocator< std::pair >
> tl_map_t;
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
*/
@@ -94,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
@@ -141,12 +140,19 @@
for (;;)
{
- coroapi::cede_to_tick_every (10);
+ coroapi::cede_to_tick ();
switch (f.kw)
{
case KW_arch:
- t->item = archetype::get (f.get_str ());
+ t->item = archetype::find (f.get_str ());
+
+ if (!t->item)
+ {
+ f.parse_warn ("treasure references unknown archetype");
+ t->item = archetype::empty;
+ }
+
break;
case KW_list: f.get (t->name); break;
@@ -170,13 +176,19 @@
default:
if (!f.parse_error ("treasurelist", t->name))
- return 0;
+ goto error;
return t;
}
f.next ();
}
+
+ // not reached
+
+error:
+ delete t;
+ return 0;
}
/*
@@ -245,7 +257,7 @@
op->expand_tail ();
- if (op->blocked (creator->map, creator->x, creator->y))
+ if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y))
op->destroy ();
else
{
@@ -259,10 +271,6 @@
if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
monster_check_apply (creator, op);
-
- if (flags & GT_UPDATE_INV)
- if (object *tmp = creator->in_player ())
- esrv_send_item (tmp, op);
}
}
@@ -303,7 +311,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;
@@ -360,7 +368,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;
@@ -436,6 +444,7 @@
LOG (llevError, "In generate treasure, created multiple objects.\n");
ob->destroy ();
+
return tmp;
}
@@ -488,7 +497,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)
@@ -515,7 +524,7 @@
* weird integer between 1-31.
*
*/
-int
+static int
magic_from_difficulty (int difficulty)
{
int percent = 0, magic = 0;
@@ -572,14 +581,17 @@
if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */
magic = (-magic);
+
op->weight = (op->arch->weight * (100 - magic * 10)) / 100;
}
else
{
if (op->type == ARMOUR)
ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100;
+
if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */
magic = (-magic);
+
op->weight = (op->weight * (100 - magic * 10)) / 100;
}
}
@@ -612,10 +624,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)
@@ -748,7 +759,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;
@@ -763,6 +774,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))
@@ -807,8 +835,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),
@@ -818,7 +845,7 @@
if (!(flags & GT_MINIMAL))
{
- if (op->arch == crown_arch)
+ if (IS_ARCH (op->arch, crown))
{
set_magic (difficulty, op, max_magic, flags);
num_enchantments = calc_item_power (op, 1);
@@ -833,8 +860,7 @@
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 */
+ || difficulty >= settings.max_level) /* high difficulties always generate an artifact, used for shop_floors or treasures */
generate_artifact (op, difficulty);
}
@@ -878,7 +904,7 @@
}
/* materialtype modifications. Note we allow this on artifacts. */
- set_materialname (op, difficulty, NULL);
+ select_material (op, difficulty);
if (flags & GT_MINIMAL)
{
@@ -886,9 +912,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;
}
@@ -921,9 +945,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;
}
@@ -941,7 +963,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
@@ -952,22 +974,16 @@
if (!(flags & GT_ONLY_GOOD) && rndm (2))
SET_FLAG (op, FLAG_CURSED);
+
break;
}
case AMULET:
- if (op->arch == amulet_arch)
+ if (IS_ARCH (op->arch, amulet))
op->value *= 5; /* Since it's not just decoration */
case RING:
- if (op->arch == NULL)
- {
- op->destroy ();
- op = 0;
- break;
- }
-
- if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */
+ if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */
break;
if (!(flags & GT_ONLY_GOOD) && !(rndm (3)))
@@ -997,8 +1013,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;
@@ -1023,19 +1039,20 @@
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 (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;
break;
case SPELLBOOK:
@@ -1079,9 +1096,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;
@@ -1128,7 +1145,7 @@
* Allocate and return the pointer to an empty artifactlist structure.
*/
static artifactlist *
-get_empty_artifactlist (void)
+get_empty_artifactlist ()
{
return salloc0 ();
}
@@ -1137,7 +1154,7 @@
* Allocate and return the pointer to an empty artifact structure.
*/
static artifact *
-get_empty_artifact (void)
+get_empty_artifact ()
{
return salloc0 ();
}
@@ -1157,132 +1174,10 @@
}
/*
- * For debugging purposes. Dumps all tables.
- */
-void
-dump_artifacts (void)
-{
- artifactlist *al;
- artifact *art;
- linked_char *next;
-
- fprintf (logfile, "\n");
- for (al = first_artifactlist; al != NULL; al = al->next)
- {
- fprintf (logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance);
- for (art = al->items; art != NULL; art = art->next)
- {
- fprintf (logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", &art->item->name, art->difficulty, art->chance);
- if (art->allowed != NULL)
- {
- fprintf (logfile, "\tallowed combinations:");
- for (next = art->allowed; next != NULL; next = next->next)
- fprintf (logfile, "%s,", &next->name);
- fprintf (logfile, "\n");
- }
- }
- }
- fprintf (logfile, "\n");
-}
-
-/*
- * For debugging purposes. Dumps all treasures recursively (see below).
- */
-void
-dump_monster_treasure_rec (const char *name, treasure *t, int depth)
-{
- treasurelist *tl;
- int i;
-
- if (depth > 100)
- return;
-
- while (t)
- {
- if (t->name)
- {
- for (i = 0; i < depth; i++)
- fprintf (logfile, " ");
-
- fprintf (logfile, "{ (list: %s)\n", &t->name);
-
- tl = treasurelist::find (t->name);
- 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);
- }
- else
- {
- for (i = 0; i < depth; i++)
- fprintf (logfile, " ");
-
- if (t->item && t->item->type == FLESH)
- fprintf (logfile, "%s's %s\n", name, &t->item->object::name);
- else
- fprintf (logfile, "%s\n", &t->item->object::name);
- }
-
- 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)
- {
- 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;
- }
-}
-
-/*
- * For debugging purposes. Dumps all treasures for a given monster.
- * Created originally by Raphael Quinet for debugging the alchemy code.
- */
-void
-dump_monster_treasure (const char *name)
-{
- archetype *at;
- int found;
-
- found = 0;
- fprintf (logfile, "\n");
-
- for_all_archetypes (at)
- if (!strcasecmp (at->object::name, name) && at->title == NULL)
- {
- fprintf (logfile, "treasures for %s (arch: %s)\n", &at->object::name, &at->archname);
- if (at->randomitems != NULL)
- dump_monster_treasure_rec (at->object::name, at->randomitems->items, 1);
- else
- fprintf (logfile, "(nothing)\n");
-
- fprintf (logfile, "\n");
- found++;
- }
-
- if (found == 0)
- fprintf (logfile, "No objects have the name %s!\n\n", name);
-}
-
-/*
* 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];
@@ -1312,11 +1207,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;
@@ -1470,15 +1365,13 @@
*/
if (op->type == HORN || op->type == POTION)
{
- object *tmp_obj;
-
/* Remove any spells this object currently has in it */
- while (op->inv)
- op->inv->destroy ();
+ op->destroy_inv (false);
- tmp_obj = arch_to_object (change->other_arch);
- insert_ob_in_ob (tmp_obj, op);
+ 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;
}
@@ -1572,8 +1465,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;
@@ -1692,9 +1585,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 */
@@ -1755,30 +1650,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;
-}
-
-void
+static void
free_treasurestruct (treasure *t)
{
if (t->next) free_treasurestruct (t->next);
@@ -1788,7 +1668,7 @@
delete t;
}
-void
+static void
free_charlinks (linked_char *lc)
{
if (lc->next)
@@ -1797,45 +1677,14 @@
delete lc;
}
-void
+static void
free_artifact (artifact *at)
{
if (at->next) free_artifact (at->next);
if (at->allowed) free_charlinks (at->allowed);
- at->item->destroy (1);
+ at->item->destroy ();
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);
-}