summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-29 12:57:33 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-29 12:57:33 +0000
commit942a2a13a9bbe4672247b37e58a53abfc4ca4db5 (patch)
treead0535ec1aae75b8898eaa74b29836d53a2e157b /crawl-ref
parente5713cc0c97db9275c105a0a5a9e76c738fd0d25 (diff)
downloadcrawl-ref-942a2a13a9bbe4672247b37e58a53abfc4ca4db5.tar.gz
crawl-ref-942a2a13a9bbe4672247b37e58a53abfc4ca4db5.zip
Clean up potion effects as per [2544231]; get rid of the "power == 40 means
it's a potion" hack. Fix security issue in dumping code (never dump a string without using %s.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8846 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/abl-show.cc8
-rw-r--r--crawl-ref/source/debug.cc38
-rw-r--r--crawl-ref/source/decks.cc8
-rw-r--r--crawl-ref/source/it_use2.cc42
-rw-r--r--crawl-ref/source/it_use2.h26
-rw-r--r--crawl-ref/source/item_use.cc52
-rw-r--r--crawl-ref/source/spl-mis.cc2
7 files changed, 68 insertions, 108 deletions
diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc
index ce87fb2f07..6c09050df8 100644
--- a/crawl-ref/source/abl-show.cc
+++ b/crawl-ref/source/abl-show.cc
@@ -1436,7 +1436,7 @@ static bool _do_ability(const ability_def& abil)
return (false);
}
- potion_effect( POT_INVISIBILITY, 2 * you.skills[SK_EVOCATIONS] + 5 );
+ potion_effect(POT_INVISIBILITY, 2 * you.skills[SK_EVOCATIONS] + 5);
contaminate_player( 1 + random2(3), true );
exercise( SK_EVOCATIONS, 1 );
break;
@@ -1447,7 +1447,7 @@ static bool _do_ability(const ability_def& abil)
break;
case ABIL_EVOKE_LEVITATE: // ring, boots, randarts
- potion_effect( POT_LEVITATION, 2 * you.skills[SK_EVOCATIONS] + 30 );
+ potion_effect(POT_LEVITATION, 2 * you.skills[SK_EVOCATIONS] + 30);
exercise( SK_EVOCATIONS, 1 );
break;
@@ -1601,12 +1601,12 @@ static bool _do_ability(const ability_def& abil)
break;
case ABIL_OKAWARU_MIGHT:
- potion_effect( POT_MIGHT, you.skills[SK_INVOCATIONS] * 8 );
+ potion_effect(POT_MIGHT, you.skills[SK_INVOCATIONS] * 8);
exercise(SK_INVOCATIONS, 1 + random2(3));
break;
case ABIL_OKAWARU_HASTE:
- potion_effect( POT_SPEED, you.skills[SK_INVOCATIONS] * 8 );
+ potion_effect(POT_SPEED, you.skills[SK_INVOCATIONS] * 8);
exercise(SK_INVOCATIONS, 3 + random2(7));
break;
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index b9a4b42436..0a98fdafda 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -1926,32 +1926,20 @@ void wizard_make_object_randart()
return;
}
- int j;
- // Set j == equipment slot of chosen item, remove old randart benefits.
- for (j = 0; j < NUM_EQUIP; j++)
- {
- if (you.equip[j] == i)
- {
- if (j == EQ_WEAPON)
- you.wield_change = true;
-
- if (is_random_artefact( item ))
- unuse_randart( i );
- break;
- }
- }
+ if (you.weapon() == &item)
+ you.wield_change = true;
if (is_random_artefact(item))
{
if (!yesno("Is already a randart; wipe and re-use?"))
{
- canned_msg( MSG_OK );
- // If equipped, re-apply benefits.
- if (j != NUM_EQUIP)
- use_randart( i );
+ canned_msg(MSG_OK);
return;
}
+ if (item_is_equipped(item))
+ unuse_randart(item);
+
item.special = 0;
item.flags &= ~ISFLAG_RANDART;
item.props.clear();
@@ -1960,7 +1948,7 @@ void wizard_make_object_randart()
mpr("Fake item as gift from which god (ENTER to leave alone): ",
MSGCH_PROMPT);
char name[80];
- if (!cancelable_get_line( name, sizeof( name ) ) && name[0])
+ if (!cancelable_get_line(name, sizeof( name )) && name[0])
{
god_type god = string_to_god(name, false);
if (god == GOD_NO_GOD)
@@ -1980,7 +1968,7 @@ void wizard_make_object_randart()
return;
}
}
- else if (!make_item_randart( item ))
+ else if (!make_item_randart(item))
{
mpr("Failed to turn item into randart.");
return;
@@ -1993,10 +1981,10 @@ void wizard_make_object_randart()
}
// If equipped, apply new randart benefits.
- if (j != NUM_EQUIP)
- use_randart( i );
+ if (item_is_equipped(item))
+ use_randart(item);
- mpr( item.name(DESC_INVENTORY_EQUIP).c_str() );
+ mpr(item.name(DESC_INVENTORY_EQUIP).c_str());
}
#endif
@@ -5964,7 +5952,7 @@ static void _debug_dump_lua_markers(FILE *file)
fprintf(file, "Lua marker %d at (%d, %d):\n",
i, marker->pos.x, marker->pos.y);
fprintf(file, "{{{{\n");
- fprintf(file, result.c_str());
+ fprintf(file, "%s", result.c_str());
fprintf(file, "}}}}\n");
}
}
@@ -5982,7 +5970,7 @@ static void _debug_dump_lua_persist(FILE* file)
else
result = "persist_to_string() returned nothing";
- fprintf(file, result.c_str());
+ fprintf(file, "%s", result.c_str());
}
void do_crash_dump()
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index a8a95a2441..d6e119a473 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -1839,9 +1839,9 @@ static void _elixir_card(int power, deck_rarity_type rarity)
if (power_level == 0)
{
if (coinflip())
- potion_effect( POT_HEAL_WOUNDS, 40 ); // power doesn't matter
+ potion_effect(POT_HEAL_WOUNDS, 40); // power doesn't matter
else
- cast_regen( random2(power / 4) );
+ cast_regen(random2(power / 4));
}
else if (power_level == 1)
{
@@ -2572,9 +2572,7 @@ static void _genie_card(int power, deck_rarity_type rarity)
{
mpr("A genie takes form and thunders: "
"\"You disturbed me, fool!\"");
- // Use 41, not 40, to tell potion_effect() that this isn't a
- // real potion.
- potion_effect( coinflip() ? POT_DEGENERATION : POT_DECAY, 41 );
+ potion_effect(coinflip() ? POT_DEGENERATION : POT_DECAY, 40);
}
}
diff --git a/crawl-ref/source/it_use2.cc b/crawl-ref/source/it_use2.cc
index 3be9292bcb..93d4c080a1 100644
--- a/crawl-ref/source/it_use2.cc
+++ b/crawl-ref/source/it_use2.cc
@@ -38,16 +38,15 @@ REVISION("$Rev$");
#include "xom.h"
// From an actual potion, pow == 40 -- bwr
-bool potion_effect( potion_type pot_eff, int pow, bool was_known )
+bool potion_effect(potion_type pot_eff, int pow, bool drank_it, bool was_known)
{
bool effect = true; // current behaviour is all potions id on quaffing
- if (pow > 150)
- pow = 150;
+ pow = std::min(pow, 150);
const int factor = (you.species == SP_VAMPIRE
- && you.hunger_state < HS_SATIATED && pow == 40 ? 2
- : 1);
+ && you.hunger_state < HS_SATIATED
+ && drank_it ? 2 : 1);
switch (pot_eff)
{
@@ -263,7 +262,7 @@ bool potion_effect( potion_type pot_eff, int pow, bool was_known )
break;
case POT_DEGENERATION:
- if (pow == 40)
+ if (drank_it)
mpr("There was something very wrong with that liquid!");
if (lose_stat(STAT_RANDOM, (1 + random2avg(4, 2)) / factor, false,
@@ -385,12 +384,11 @@ bool potion_effect( potion_type pot_eff, int pow, bool was_known )
}
return (effect);
-} // end potion_effect()
+}
bool unwield_item(bool showMsgs)
{
- const int unw = you.equip[EQ_WEAPON];
- if (unw == -1)
+ if (!you.weapon())
return (false);
if (you.duration[DUR_BERSERKER])
@@ -399,7 +397,9 @@ bool unwield_item(bool showMsgs)
return (false);
}
- if (!safe_to_remove_or_wear(you.inv[unw], true))
+ item_def& item = *you.weapon();
+
+ if (!safe_to_remove_or_wear(item, true))
return (false);
you.equip[EQ_WEAPON] = -1;
@@ -407,8 +407,6 @@ bool unwield_item(bool showMsgs)
you.wield_change = true;
you.m_quiver->on_weapon_changed();
- item_def &item(you.inv[unw]);
-
if (item.base_type == OBJ_MISCELLANY
&& item.sub_type == MISC_LANTERN_OF_SHADOWS )
{
@@ -449,7 +447,7 @@ bool unwield_item(bool showMsgs)
const int brand = get_weapon_brand( item );
if (is_random_artefact( item ))
- unuse_randart(unw);
+ unuse_randart(item);
if (brand != SPWPN_NORMAL)
{
@@ -519,8 +517,7 @@ bool unwield_item(bool showMsgs)
}
}
}
-
- if (item.base_type == OBJ_STAVES && item.sub_type == STAFF_POWER)
+ else if (item.base_type == OBJ_STAVES && item.sub_type == STAFF_POWER)
{
calc_mp();
mpr("You feel your mana capacity decrease.");
@@ -529,15 +526,15 @@ bool unwield_item(bool showMsgs)
you.attribute[ATTR_WEAPON_SWAP_INTERRUPTED] = 0;
return (true);
-} // end unwield_item()
+}
// This does *not* call ev_mod!
-void unwear_armour(char unw)
+void unwear_armour(int slot)
{
you.redraw_armour_class = true;
you.redraw_evasion = true;
- item_def &item(you.inv[unw]);
+ item_def &item(you.inv[slot]);
switch (get_armour_ego_type( item ))
{
@@ -618,13 +615,8 @@ void unwear_armour(char unw)
break;
}
- if (is_random_artefact( you.inv[unw] ))
- unuse_randart(unw);
-}
-
-void unuse_randart(unsigned char unw)
-{
- unuse_randart( you.inv[unw] );
+ if (is_random_artefact(item))
+ unuse_randart(item);
}
void unuse_randart(const item_def &item)
diff --git a/crawl-ref/source/it_use2.h b/crawl-ref/source/it_use2.h
index 8ae3e6002c..80bc1bf5b3 100644
--- a/crawl-ref/source/it_use2.h
+++ b/crawl-ref/source/it_use2.h
@@ -12,29 +12,13 @@
#include "externs.h"
-
-/* ***********************************************************************
- * called from: ability - beam - decks - item_use - misc - religion -
- * spell - spells - spells1
- * *********************************************************************** */
-bool potion_effect(potion_type pot_eff, int pow, bool was_known = true);
-
-/* ***********************************************************************
- * called from: item_use
- * *********************************************************************** */
-void unuse_randart(unsigned char unw);
+// drank_it should be true for real potion effects (as opposed
+// to abilities which duplicate such effects.)
+bool potion_effect(potion_type pot_eff, int pow,
+ bool drank_it = false, bool was_known = true);
void unuse_randart(const item_def &item);
-
-/* ***********************************************************************
- * called from: item_use - transfor
- * *********************************************************************** */
-void unwear_armour(char unw);
-
-
-/* ***********************************************************************
- * called from: decks - it_use3 - item_use - items - spells3 - transfor
- * *********************************************************************** */
+void unwear_armour(int slot);
bool unwield_item(bool showMsgs = true);
#endif
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index c7679d014b..e124618f5e 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -4022,10 +4022,8 @@ void prompt_inscribe_item()
inscribe_item(you.inv[item_slot], true);
}
-void drink( int slot )
+void drink(int slot)
{
- int item_slot;
-
if (you.is_undead == US_UNDEAD)
{
mpr("You can't drink.");
@@ -4060,36 +4058,34 @@ void drink( int slot )
return;
}
- if (slot != -1)
- item_slot = slot;
- else
+ if (slot == -1)
{
- item_slot = prompt_invent_item("Drink which item?",
- MT_INVLIST, OBJ_POTIONS,
- true, true, true, 0, -1, NULL,
- OPER_QUAFF);
+ slot = prompt_invent_item("Drink which item?",
+ MT_INVLIST, OBJ_POTIONS,
+ true, true, true, 0, -1, NULL,
+ OPER_QUAFF);
+ if (prompt_failed(slot))
+ return;
}
- if (prompt_failed(item_slot))
- return;
+ item_def& potion = you.inv[slot];
- if (you.inv[item_slot].base_type != OBJ_POTIONS)
+ if (potion.base_type != OBJ_POTIONS)
{
mpr("You can't drink that!");
return;
}
- const bool alreadyknown = item_type_known(you.inv[item_slot]);
+ const bool alreadyknown = item_type_known(potion);
if (alreadyknown && you.hunger_state == HS_ENGORGED
- && (is_blood_potion(you.inv[item_slot])
- || you.inv[item_slot].sub_type == POT_PORRIDGE))
+ && (is_blood_potion(potion) || potion.sub_type == POT_PORRIDGE))
{
mpr("You are much too full right now.");
return;
}
- if (alreadyknown && you.inv[item_slot].sub_type == POT_BERSERK_RAGE
+ if (alreadyknown && potion.sub_type == POT_BERSERK_RAGE
&& !berserk_check_wielded_weapon())
{
return;
@@ -4101,17 +4097,18 @@ void drink( int slot )
const bool dangerous = (player_in_a_dangerous_place()
&& you.experience_level > 1);
- if (potion_effect(static_cast<potion_type>(you.inv[item_slot].sub_type),
- 40, alreadyknown))
+ // Identify item and type.
+ if (potion_effect(static_cast<potion_type>(potion.sub_type),
+ 40, true, alreadyknown))
{
- set_ident_flags(you.inv[item_slot], ISFLAG_IDENT_MASK);
-
- set_ident_type( you.inv[item_slot], ID_KNOWN_TYPE );
+ set_ident_flags(potion, ISFLAG_IDENT_MASK);
+ set_ident_type(potion, ID_KNOWN_TYPE);
}
else
{
- set_ident_type( you.inv[item_slot], ID_TRIED_TYPE );
+ set_ident_type(potion, ID_TRIED_TYPE);
}
+
if (!alreadyknown && dangerous)
{
// Xom loves it when you drink an unknown potion and there is
@@ -4119,12 +4116,13 @@ void drink( int slot )
xom_is_stimulated(255);
}
- if (is_blood_potion(you.inv[item_slot]))
+ if (is_blood_potion(potion))
{
// Always drink oldest potion.
- remove_oldest_blood_potion(you.inv[item_slot]);
+ remove_oldest_blood_potion(potion);
}
- dec_inv_item_quantity( item_slot, 1 );
+
+ dec_inv_item_quantity(slot, 1);
you.turn_is_over = true;
if (you.species != SP_VAMPIRE)
@@ -4203,7 +4201,7 @@ bool _drink_fountain()
// Good gods do not punish for bad random effects. However, they do
// punish drinking from a fountain of blood.
- potion_effect(fountain_effect, 100, feat != DNGN_FOUNTAIN_SPARKLING);
+ potion_effect(fountain_effect, 100, true, feat != DNGN_FOUNTAIN_SPARKLING);
bool gone_dry = false;
if (feat == DNGN_FOUNTAIN_BLUE)
diff --git a/crawl-ref/source/spl-mis.cc b/crawl-ref/source/spl-mis.cc
index 133e460037..3ba48c3c87 100644
--- a/crawl-ref/source/spl-mis.cc
+++ b/crawl-ref/source/spl-mis.cc
@@ -594,7 +594,7 @@ void MiscastEffect::_potion_effect(int pot_eff, int pot_pow)
{
if (target->atype() == ACT_PLAYER)
{
- potion_effect(static_cast<potion_type>(pot_eff), pot_pow, false);
+ potion_effect(static_cast<potion_type>(pot_eff), pot_pow, false, false);
return;
}