--- deliantra/server/common/treasure.C 2008/04/21 23:35:24 1.74
+++ deliantra/server/common/treasure.C 2010/04/28 19:49:50 1.108
@@ -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[];
@@ -47,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
*/
@@ -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 (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,12 +270,8 @@
{
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);
-
- if (flags & GT_UPDATE_INV)
- if (object *tmp = creator->in_player ())
- esrv_send_item (tmp, op);
}
}
@@ -315,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;
@@ -372,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;
@@ -448,6 +445,7 @@
LOG (llevError, "In generate treasure, created multiple objects.\n");
ob->destroy ();
+
return tmp;
}
@@ -500,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)
@@ -514,7 +512,7 @@
if (olevel <= 0)
olevel = rndm (1, op->inv->level);
- return min (olevel, MAXLEVEL);
+ return min (olevel, MAXLEVEL_TREASURE);
}
/*
@@ -527,23 +525,16 @@
* weird integer between 1-31.
*
*/
-int
+static int
magic_from_difficulty (int difficulty)
{
- int percent = 0, magic = 0;
- int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS);
-
- scaled_diff--;
-
- if (scaled_diff < 0)
- scaled_diff = 0;
+ int scaled_diff = lerp (difficulty, 0, settings.max_level, 0, DIFFLEVELS - 1);
+ scaled_diff = clamp (scaled_diff, 0, DIFFLEVELS - 1);
- if (scaled_diff >= DIFFLEVELS)
- scaled_diff = DIFFLEVELS - 1;
+ int percent = rndm (100);
+ int magic;
- percent = rndm (100);
-
- for (magic = 0; magic < (MAXMAGIC + 1); magic++)
+ for (magic = 0; magic <= MAXMAGIC; magic++)
{
percent -= difftomagic_list[scaled_diff][magic];
@@ -551,7 +542,7 @@
break;
}
- if (magic == (MAXMAGIC + 1))
+ if (magic > MAXMAGIC)
{
LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty);
magic = 0;
@@ -569,7 +560,6 @@
* This function doesn't work properly, should add use of archetypes
* to make it truly absolute.
*/
-
void
set_abs_magic (object *op, int magic)
{
@@ -584,14 +574,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;
}
}
@@ -604,16 +597,16 @@
static void
set_magic (int difficulty, object *op, int max_magic, int flags)
{
- int i;
+ int i = magic_from_difficulty (difficulty);
- i = magic_from_difficulty (difficulty);
if ((flags & GT_ONLY_GOOD) && i < 0)
i = -i;
- if (i > max_magic)
- i = max_magic;
+
+ i = min (i, max_magic);
+
set_abs_magic (op, i);
if (i < 0)
- SET_FLAG (op, FLAG_CURSED);
+ op->set_flag (FLAG_CURSED);
}
/*
@@ -624,31 +617,25 @@
* 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)
- {
- if (!(rndm (21)))
- r = 20 + rndm (2);
- else
- {
- if (rndm (2))
- r = 10;
- else
- r = 11 + rndm (9);
- }
- }
+ if (!rndm (21))
+ r = 20 + rndm (2);
+ else if (rndm (2))
+ r = 10;
+ else
+ r = 11 + rndm (9);
switch (r)
{
- /* Redone by MSW 2000-11-26 to have much less code. Also,
- * bonuses and penalties will stack and add to existing values.
- * of the item.
- */
+ /* Redone by MSW 2000-11-26 to have much less code. Also,
+ * bonuses and penalties will stack and add to existing values.
+ * of the item.
+ */
case 0:
case 1:
case 2:
@@ -698,8 +685,9 @@
*/
if (bonus < 0)
val = 2 * -val - rndm (b);
- if (val > 35)
- val = 35; /* Upper limit */
+
+ val = min (35, val); /* Upper limit */
+
b = 0;
while (op->resist[resist_table[resist]] != 0 && b < 4)
@@ -717,7 +705,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 +718,7 @@
case 21:
if (op->type == AMULET)
{
- SET_FLAG (op, FLAG_REFL_MISSILE);
+ op->set_flag (FLAG_REFL_MISSILE);
op->value *= 9;
}
else
@@ -742,14 +730,14 @@
case 22:
op->stats.exp += bonus; /* Speed! */
- op->value = (op->value * 2) / 3;
+ op->value = op->value * 2 / 3;
break;
}
if (bonus > 0)
- op->value *= 2 * bonus;
+ op->value = 2 * op->value * bonus;
else
- op->value = -(op->value * 2 * bonus) / 3;
+ op->value = -2 * op->value * bonus / 3;
}
/*
@@ -760,22 +748,36 @@
* rings and amulets.
* Another scheme is used to calculate the magic of weapons and armours.
*/
-int
+static int
get_magic (int diff)
{
- int i;
+ diff = min (3, diff);
- if (diff < 3)
- diff = 3;
-
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
if (rndm (diff))
return i;
return 4;
}
-#define DICE2 (get_magic(2)==2?2:1)
+/* 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 +821,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 +890,7 @@
}
/* materialtype modifications. Note we allow this on artifacts. */
- set_materialname (op, difficulty, NULL);
+ select_material (op, difficulty);
if (flags & GT_MINIMAL)
{
@@ -910,15 +911,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 +931,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,17 +949,18 @@
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
{
- op->name = "potion";
- op->name_pl = "potions";
+ op->name = shstr_potion;
+ op->name_pl = shstr_potions;
}
if (!(flags & GT_ONLY_GOOD) && rndm (2))
- SET_FLAG (op, FLAG_CURSED);
+ op->set_flag (FLAG_CURSED);
+
break;
}
@@ -969,45 +969,39 @@
op->value *= 5; /* Since it's not just decoration */
case RING:
- if (!op->arch) // wtf? schmorp
- {
- op->destroy ();
- op = 0;
- break;
- }
-
if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */
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)))
+ 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;
set_ring_bonus (op, d);
- if (!(rndm (4)))
+ 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;
+
set_ring_bonus (op, d);
}
}
- 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;
@@ -1019,7 +1013,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;
@@ -1032,23 +1026,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;
@@ -1086,11 +1084,12 @@
* 10 time multiplier). This way, the value are a bit more reasonable.
*/
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;
@@ -1115,8 +1114,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;
}
@@ -1137,7 +1136,7 @@
* Allocate and return the pointer to an empty artifactlist structure.
*/
static artifactlist *
-get_empty_artifactlist (void)
+get_empty_artifactlist ()
{
return salloc0 ();
}
@@ -1146,7 +1145,7 @@
* Allocate and return the pointer to an empty artifact structure.
*/
static artifact *
-get_empty_artifact (void)
+get_empty_artifact ()
{
return salloc0 ();
}
@@ -1169,10 +1168,9 @@
* 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];
artifact *art = NULL;
artifactlist *al;
@@ -1181,8 +1179,7 @@
else
has_been_inited = 1;
- sprintf (filename, "%s/artifacts", settings.datadir);
- object_thawer f (filename);
+ object_thawer f (settings.datadir, "artifacts");
if (!f)
return;
@@ -1199,11 +1196,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;
@@ -1277,8 +1274,6 @@
LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance);
#endif
}
-
- LOG (llevDebug, "done.\n");
}
/*
@@ -1288,8 +1283,6 @@
void
add_abilities (object *op, object *change)
{
- int i, tmp;
-
if (change->face != blank_face)
{
#ifdef TREASURE_VERBOSE
@@ -1298,46 +1291,46 @@
op->face = change->face;
}
- for (i = 0; i < NUM_STATS; i++)
+ for (int i = 0; i < NUM_STATS; i++)
change_attr_value (&(op->stats), i, change->stats.stat (i));
- op->attacktype |= change->attacktype;
- op->path_attuned |= change->path_attuned;
+ op->attacktype |= change->attacktype;
+ op->path_attuned |= change->path_attuned;
op->path_repelled |= change->path_repelled;
- op->path_denied |= change->path_denied;
- 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)
- set_abs_magic (op, -op->magic);
+ op->path_denied |= change->path_denied;
+ op->move_type |= change->move_type;
+ op->stats.luck += change->stats.luck;
+
+ static const struct copyflags : object::flags_t
+ {
+ copyflags ()
+ {
+ set (FLAG_CURSED);
+ set (FLAG_DAMNED);
+ set (FLAG_LIFESAVE);
+ set (FLAG_REFL_SPELL);
+ set (FLAG_STEALTH);
+ set (FLAG_XRAYS);
+ set (FLAG_BLIND);
+ set (FLAG_SEE_IN_DARK);
+ set (FLAG_REFL_MISSILE);
+ set (FLAG_MAKE_INVIS);
+ }
+ } copyflags;
+
+ // we might want to just copy, but or'ing is what the original code did
+ op->flag |= change->flag & copyflags;
- 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_CURSED] || change->flag [FLAG_DAMNED]) && op->magic > 0)
+ set_abs_magic (op, -op->magic);
- 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))
- op->speed = 0.0;
+ if (!op->flag [FLAG_ALIVE])
+ op->speed = 0.;
op->set_speed (op->speed);
}
@@ -1346,8 +1339,8 @@
op->nrof = rndm (change->nrof) + 1;
op->stats.exp += change->stats.exp; /* Speed modifier */
- op->stats.wc += change->stats.wc;
- op->stats.ac += change->stats.ac;
+ op->stats.wc += change->stats.wc;
+ op->stats.ac += change->stats.ac;
if (change->other_arch)
{
@@ -1357,15 +1350,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;
}
@@ -1391,33 +1382,33 @@
op->stats.maxsp += change->stats.maxsp;
if (change->stats.food < 0)
- op->stats.food = -(change->stats.food);
+ op->stats.food = -change->stats.food;
else
op->stats.food += change->stats.food;
if (change->level < 0)
- op->level = -(change->level);
+ op->level = -change->level;
else
op->level += change->level;
if (change->gen_sp_armour < 0)
- op->gen_sp_armour = -(change->gen_sp_armour);
+ op->gen_sp_armour = -change->gen_sp_armour;
else
- op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100;
+ op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100;
op->item_power = change->item_power;
- for (i = 0; i < NROFATTACKS; i++)
- if (change->resist[i])
- op->resist[i] += change->resist[i];
+ for (int i = 0; i < NROFATTACKS; i++)
+ op->resist[i] += change->resist[i];
if (change->stats.dam)
{
if (change->stats.dam < 0)
- op->stats.dam = (-change->stats.dam);
+ op->stats.dam = -change->stats.dam;
else if (op->stats.dam)
{
- tmp = (signed char) (((int) op->stats.dam * (int) change->stats.dam) / 10);
+ int tmp = op->stats.dam * change->stats.dam / 10;
+
if (tmp == op->stats.dam)
{
if (change->stats.dam < 10)
@@ -1433,25 +1424,25 @@
if (change->weight)
{
if (change->weight < 0)
- op->weight = (-change->weight);
+ op->weight = -change->weight;
else
- op->weight = (op->weight * (change->weight)) / 100;
+ op->weight = op->weight * change->weight / 100;
}
if (change->last_sp)
{
if (change->last_sp < 0)
- op->last_sp = (-change->last_sp);
+ op->last_sp = -change->last_sp;
else
- op->last_sp = (signed char) (((int) op->last_sp * (int) change->last_sp) / (int) 100);
+ op->last_sp = op->last_sp * (int)change->last_sp / 100;
}
if (change->gen_sp_armour)
{
if (change->gen_sp_armour < 0)
- op->gen_sp_armour = (-change->gen_sp_armour);
+ op->gen_sp_armour = -change->gen_sp_armour;
else
- op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100);
+ op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100;
}
op->value *= change->value;
@@ -1459,8 +1450,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;
@@ -1514,20 +1505,18 @@
void
give_artifact_abilities (object *op, object *artifct)
{
- char new_name[MAX_BUF];
+ op->title = format ("of %s", &artifct->name);
- sprintf (new_name, "of %s", &artifct->name);
- op->title = new_name;
add_abilities (op, artifct); /* Give out the bonuses */
#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;
@@ -1547,11 +1536,9 @@
void
generate_artifact (object *op, int difficulty)
{
- artifactlist *al;
artifact *art;
- int i;
- al = find_artifactlist (op->type);
+ artifactlist *al = find_artifactlist (op->type);
if (al == NULL)
{
@@ -1561,7 +1548,7 @@
return;
}
- for (i = 0; i < ARTIFACT_TRIES; i++)
+ for (int i = 0; i < ARTIFACT_TRIES; i++)
{
int roll = rndm (al->total_chance);
@@ -1579,9 +1566,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 */
@@ -1609,31 +1598,25 @@
void
fix_flesh_item (object *item, object *donor)
{
- char tmpbuf[MAX_BUF];
- int i;
-
if (item->type == FLESH && donor)
{
/* change the name */
- sprintf (tmpbuf, "%s's %s", &donor->name, &item->name);
- item->name = tmpbuf;
- sprintf (tmpbuf, "%s's %s", &donor->name, &item->name_pl);
- item->name_pl = tmpbuf;
+ item->name = format ("%s's %s", &donor->name, &item->name);
+ item->name_pl = format ("%s's %s", &donor->name, &item->name_pl);
/* weight is FLESH weight/100 * donor */
- if ((item->weight = (signed long) (((double) item->weight / (double) 100.0) * (double) donor->weight)) == 0)
- item->weight = 1;
+ item->weight = max (1, item->weight * donor->weight / 100);
/* value is multiplied by level of donor */
item->value *= isqrt (donor->level * 2);
/* food value */
- item->stats.food += (donor->stats.hp / 100) + donor->stats.Con;
+ item->stats.food += donor->stats.hp / 100 + donor->stats.Con;
/* flesh items inherit some abilities of donor, but not
* full effect.
*/
- for (i = 0; i < NROFATTACKS; i++)
+ for (int i = 0; i < NROFATTACKS; i++)
item->resist[i] = donor->resist[i] / 2;
/* item inherits donor's level (important for quezals) */
@@ -1642,30 +1625,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;
+ if (donor->attacktype & AT_ACID)
+ item->stats.hp = -item->stats.food;
- return 0;
+ item->set_flag (FLAG_NO_STEAL);
+ }
}
-void
+static void
free_treasurestruct (treasure *t)
{
if (t->next) free_treasurestruct (t->next);
@@ -1675,7 +1643,7 @@
delete t;
}
-void
+static void
free_charlinks (linked_char *lc)
{
if (lc->next)
@@ -1684,45 +1652,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);
-}