--- deliantra/server/common/treasure.C 2009/11/29 10:55:18 1.97
+++ deliantra/server/common/treasure.C 2022/10/08 21:54:05 1.125
@@ -1,24 +1,25 @@
/*
* This file is part of Deliantra, the Roguelike Realtime MMORPG.
- *
- * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
- * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
- * Copyright (©) 1992,2007 Frank Tore Johansen
- *
+ *
+ * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
+ * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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
* 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 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
*/
@@ -35,7 +36,11 @@
#include
#include
-#include
+
+#include
+
+// used only by treasure.C, does not handle null arch ptrs
+#define IS_ARCH(arch,name) ((arch)->archname == shstr_ ## name)
extern char *spell_mapping[];
@@ -43,13 +48,14 @@
static void change_treasure (treasure *t, object *op); /* overrule default values */
-typedef std::tr1::unordered_map<
- const char *,
- treasurelist *,
- str_hash,
- str_equal,
- slice_allocator< std::pair >
-> tl_map_t;
+typedef ska::flat_hash_map
+ <
+ const char *,
+ treasurelist *,
+ str_hash,
+ str_equal,
+ slice_allocator< std::pair >
+ > tl_map_t;
static tl_map_t tl_map;
@@ -76,7 +82,7 @@
if (!name)
return 0;
- auto (i, tl_map.find (name));
+ auto i = tl_map.find (name);
if (i == tl_map.end ())
return 0;
@@ -217,7 +223,10 @@
{
if (t->next_yes || t->next_no)
{
- LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->archname : &t->name);
+ LOG (llevError, "Treasure %s is one item, but on treasure %s%s\n",
+ &tl->name,
+ t->item ? "item " : "",
+ t->item ? &t->item->archname : &t->name);
LOG (llevError, " the next_yes or next_no field is set\n");
}
@@ -258,11 +267,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 +280,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 +322,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 +379,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;
@@ -492,7 +502,7 @@
{ 0, 0, 0, 0, 100}, // 31
};
-/* calculate the appropriate level for wands staves and scrolls.
+/* calculate the appropriate level for wands staves and scrolls.
* This code presumes that op has had its spell object created (in op->inv)
*
* elmex Wed Aug 9 17:44:59 CEST 2006:
@@ -512,7 +522,7 @@
if (olevel <= 0)
olevel = rndm (1, op->inv->level);
- return min (olevel, MAXLEVEL);
+ return min (olevel, MAXLEVEL_TREASURE);
}
/*
@@ -528,20 +538,13 @@
static int
magic_from_difficulty (int difficulty)
{
- int percent = 0, magic = 0;
- int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS);
-
- scaled_diff--;
+ int scaled_diff = lerp (difficulty, 0, settings.max_level, 0, DIFFLEVELS - 1);
+ scaled_diff = clamp (scaled_diff, 0, DIFFLEVELS - 1);
- if (scaled_diff < 0)
- scaled_diff = 0;
+ int percent = rndm (100);
+ int magic;
- if (scaled_diff >= DIFFLEVELS)
- scaled_diff = DIFFLEVELS - 1;
-
- percent = rndm (100);
-
- for (magic = 0; magic < (MAXMAGIC + 1); magic++)
+ for (magic = 0; magic <= MAXMAGIC; magic++)
{
percent -= difftomagic_list[scaled_diff][magic];
@@ -549,7 +552,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;
@@ -567,7 +570,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)
{
@@ -605,16 +607,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);
}
/*
@@ -631,24 +633,19 @@
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 +695,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 +715,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 +728,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 +740,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;
}
/*
@@ -763,12 +761,9 @@
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;
@@ -792,7 +787,30 @@
return 0;
}
-#define DICE2 (get_magic(2)==2?2:1)
+static double
+value_factor_from_spell_item (object *spell, object *item)
+{
+ double factor =
+ pow ((spell->value > 0 ? spell->value : 1)
+ * spell->level, 1.5);
+
+ if (item) // this if for: wands/staffs/rods:
+ {
+ /* Old crossfire comment ahead:
+ * Add 50 to both level an divisor to keep prices a little more
+ * reasonable. Otherwise, a high level version of a low level
+ * spell can be worth tons a money (eg, level 20 rod, level 2 spell =
+ * 10 time multiplier). This way, the value are a bit more reasonable.
+ */
+
+ factor *= item->level + 50;
+ factor /= item->inv->level + 50;
+ }
+
+ return factor;
+}
+
+#define DICE2 (get_magic(2) == 2 ? 2 : 1)
#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3))
/*
@@ -802,8 +820,8 @@
*/
/* 4/28/96 added creator object from which op may now inherit properties based on
- * op->type. Right now, which stuff the creator passes on is object type
- * dependant. I know this is a spagetti manuever, but is there a cleaner
+ * op->type. Right now, which stuff the creator passes on is object type
+ * dependant. I know this is a spagetti manuever, but is there a cleaner
* way to do this? b.t. */
/*
@@ -913,7 +931,7 @@
/* Handle healing and magic power potions */
if (op->stats.sp && !op->randomitems)
{
- object *tmp = get_archetype (spell_mapping [op->stats.sp]);
+ object *tmp = archetype::get (spell_mapping [op->stats.sp]);
insert_ob_in_ob (tmp, op);
op->stats.sp = 0;
}
@@ -926,32 +944,32 @@
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;
case POTION:
{
- int too_many_tries = 0, is_special = 0;
+ int too_many_tries = 0;
/* Handle healing and magic power potions */
if (op->stats.sp && !op->randomitems)
{
- object *tmp = get_archetype (spell_mapping[op->stats.sp]);
+ object *tmp = archetype::get (spell_mapping[op->stats.sp]);
insert_ob_in_ob (tmp, op);
op->stats.sp = 0;
}
- while (!(is_special = special_potion (op)) && !op->inv)
+ while (!special_potion (op) && !op->inv)
{
generate_artifact (op, difficulty);
if (too_many_tries++ > 10)
@@ -969,12 +987,12 @@
}
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;
}
@@ -988,28 +1006,29 @@
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);
}
}
@@ -1027,7 +1046,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;
@@ -1050,14 +1069,15 @@
/* 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 *= value_factor_from_spell_item (op->inv, 0);
+
/* add exp so learning gives xp */
op->level = op->inv->level;
op->stats.exp = op->value;
@@ -1071,30 +1091,22 @@
op->stats.food = op->inv->nrof;
op->nrof = 1;
/* If the spell changes by level, choose a random level
- * for it, and adjust price. If the spell doesn't
- * change by level, just set the wand to the level of
- * the spell, and value calculation is simpler.
+ * for it.
*/
- if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier)
- {
- op->level = level_for_item (op, difficulty);
- op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
- }
+ if (op->inv->duration_modifier
+ || op->inv->dam_modifier
+ || op->inv->range_modifier)
+ op->level = level_for_item (op, difficulty);
else
- {
- op->level = op->inv->level;
- op->value = op->value * op->inv->value;
- }
+ op->level = op->inv->level;
+
+ op->value *= value_factor_from_spell_item (op->inv, op);
break;
case ROD:
op->level = level_for_item (op, difficulty);
- /* Add 50 to both level an divisor to keep prices a little more
- * reasonable. Otherwise, a high level version of a low level
- * spell can be worth tons a money (eg, level 20 rod, level 2 spell =
- * 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);
+ op->value *= value_factor_from_spell_item (op->inv, op);
+
/* 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);
@@ -1106,7 +1118,7 @@
case SCROLL:
op->level = level_for_item (op, difficulty);
- op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
+ op->value *= value_factor_from_spell_item (op->inv, op);
/* add exp so reading them properly gives xp */
op->stats.exp = op->value / 5;
@@ -1124,8 +1136,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;
}
@@ -1181,7 +1193,6 @@
init_artifacts ()
{
static int has_been_inited = 0;
- char filename[MAX_BUF];
artifact *art = NULL;
artifactlist *al;
@@ -1190,8 +1201,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;
@@ -1212,7 +1222,7 @@
char *next;
do
{
- if ((next = strchr (cp, ',')))
+ if ((next = (char *)strchr (cp, ',')))
*next++ = '\0';
linked_char *tmp = new linked_char;
@@ -1286,8 +1296,6 @@
LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance);
#endif
}
-
- LOG (llevDebug, "done.\n");
}
/*
@@ -1297,56 +1305,49 @@
void
add_abilities (object *op, object *change)
{
- int i, tmp;
-
if (change->face != blank_face)
- {
-#ifdef TREASURE_VERBOSE
- LOG (llevDebug, "add_abilities change face: %d\n", change->face);
-#endif
- op->face = change->face;
- }
+ 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);
}
@@ -1355,8 +1356,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)
{
@@ -1369,9 +1370,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;
}
@@ -1397,33 +1399,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)
@@ -1439,25 +1441,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;
@@ -1499,7 +1501,7 @@
name = tmp->name, neg = 0;
/* If we match name, then return the opposite of 'neg' */
- if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname)))
+ if (!strcmp (name, op->arch->archname))
return !neg;
/* Set success as true, since if the match was an inverse, it means
@@ -1520,20 +1522,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;
@@ -1553,11 +1553,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)
{
@@ -1567,7 +1565,7 @@
return;
}
- for (i = 0; i < ARTIFACT_TRIES; i++)
+ for (int i = 0; i < ARTIFACT_TRIES; i++)
{
int roll = rndm (al->total_chance);
@@ -1617,31 +1615,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) */
@@ -1652,9 +1644,9 @@
item->type = POISON;
if (donor->attacktype & AT_ACID)
- item->stats.hp = -1 * item->stats.food;
+ item->stats.hp = -item->stats.food;
- SET_FLAG (item, FLAG_NO_STEAL);
+ item->set_flag (FLAG_NO_STEAL);
}
}