summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spells2.cc
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-08 16:01:04 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-08 16:01:04 +0000
commit9855f61a84eb903023abc21be286d74d8857b58d (patch)
tree7e5198f96eb8284e0abc2d18196238798e7a3161 /crawl-ref/source/spells2.cc
parent33199ca0b4dd31e06e643b8bb33b3c59de2a4d96 (diff)
downloadcrawl-ref-9855f61a84eb903023abc21be286d74d8857b58d.tar.gz
crawl-ref-9855f61a84eb903023abc21be286d74d8857b58d.zip
Clean up dancing_weapon().
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5594 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/spells2.cc')
-rw-r--r--crawl-ref/source/spells2.cc85
1 files changed, 85 insertions, 0 deletions
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index b3809f28e0..e50002258d 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -39,6 +39,7 @@
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
+#include "it_use2.h"
#include "message.h"
#include "misc.h"
#include "monplace.h"
@@ -2340,6 +2341,90 @@ bool cast_conjure_ball_lightning(int pow, bool god_gift)
return (success);
}
+bool dancing_weapon(int pow, bool god_gift, bool force_hostile,
+ bool quiet_failure)
+{
+ bool success = true;
+
+ const int dur = std::min(2 + (random2(pow) / 5), 6);
+
+ const int wpn = you.equip[EQ_WEAPON];
+
+ // See if wielded item is appropriate.
+ if (wpn == -1
+ || you.inv[wpn].base_type != OBJ_WEAPONS
+ || is_range_weapon(you.inv[wpn])
+ || is_fixed_artefact(you.inv[wpn]))
+ {
+ success = false;
+ }
+
+ // See if we can get an mitm for the dancing weapon.
+ const int i = get_item_slot();
+
+ if (i == NON_ITEM)
+ success = false;
+
+ int monster;
+
+ if (success)
+ {
+ // Cursed weapons become hostile.
+ const bool friendly = (!force_hostile && !item_cursed(you.inv[wpn]));
+
+ monster =
+ create_monster(
+ mgen_data(MONS_DANCING_WEAPON,
+ friendly ? BEH_FRIENDLY : BEH_HOSTILE,
+ dur, you.pos(),
+ friendly ? you.pet_target : MHITYOU,
+ god_gift ? MF_GOD_GIFT : 0));
+
+ if (monster == -1)
+ success = false;
+ }
+
+ if (!success)
+ {
+ destroy_item(i);
+
+ if (!quiet_failure)
+ {
+ if (wpn != -1)
+ mpr("Your weapon vibrates crazily for a second.");
+ else
+ msg::stream << "Your " << your_hand(true) << " twitch."
+ << std::endl;
+ }
+
+ return (false);
+ }
+
+ // We are successful. Unwield the weapon, removing any wield effects.
+ unwield_item();
+
+ // Copy the unwielded item.
+ mitm[i] = you.inv[wpn];
+ mitm[i].quantity = 1;
+ mitm[i].x = 0;
+ mitm[i].y = 0;
+ mitm[i].link = NON_ITEM;
+
+ // Mark the weapon as thrown, so that we'll autograb it when the
+ // tango's done.
+ mitm[i].flags |= ISFLAG_THROWN;
+
+ mprf("%s dances into the air!", you.inv[wpn].name(DESC_CAP_YOUR).c_str());
+
+ you.inv[wpn].quantity = 0;
+
+ menv[monster].inv[MSLOT_WEAPON] = i;
+ menv[monster].colour = mitm[i].colour;
+ burden_change();
+
+ return (true);
+}
+
// Makhleb or Kikubaaqudgha sends a demonic buddy (or enemy) for a
// follower.
bool summon_demon_type(monster_type mon, int pow, bool god_gift)