From 9e78aa2fbdeb70a835a056f30fa604db074064da Mon Sep 17 00:00:00 2001
From: wheals <shm.mark@gmail.com>
Date: Tue, 17 Dec 2013 14:27:30 -0500
Subject: [PATCH] The +7,+7 tipstaff of Order {silver, rMut}

This patch is mostly based off of Grunt's lajatang of the Silver Moon patch, at
least in code. pubby suggested that it be a tipstaff, which i just made a base
type redefine that is identical to a lajatang, but without slashing. (Yes, it
seems that tipstaves are really more and M&F type weapon than a staff; see
??realism of crawl for an explanation.

I gave it rMut as something interesting and as a possible reason to keep it
around even if it isn't the best weapon against many things. Credit to argonaut
for unintentionally helping me find the player_equip_unrand() function.
---
 crawl-ref/source/actor.cc                |  4 +++-
 crawl-ref/source/art-data.txt            | 12 ++++++++++++
 crawl-ref/source/art-func.h              | 27 +++++++++++++++++++++++++++
 crawl-ref/source/dat/descript/unrand.txt | 10 ++++++++++
 crawl-ref/source/rltiles/dc-player.txt   |  1 +
 crawl-ref/source/throw.cc                |  6 +++---
 crawl-ref/source/throw.h                 |  3 +++
 7 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/crawl-ref/source/actor.cc b/crawl-ref/source/actor.cc
index 43f1fff..d21dd67 100644
--- a/crawl-ref/source/actor.cc
+++ b/crawl-ref/source/actor.cc
@@ -4,6 +4,7 @@
 #include "actor.h"
 #include "areas.h"
 #include "artefact.h"
+#include "art-enum.h"
 #include "attack.h"
 #include "coord.h"
 #include "env.h"
@@ -330,7 +331,8 @@ bool actor::no_cast(bool calc_unid, bool items) const
 
 bool actor::rmut_from_item(bool calc_unid) const
 {
-    return wearing(EQ_AMULET, AMU_RESIST_MUTATION, calc_unid);
+    return wearing(EQ_AMULET, AMU_RESIST_MUTATION, calc_unid)
+           || is_player() && player_equip_unrand(UNRAND_TIPSTAFF);
 }
 
 bool actor::evokable_berserk(bool calc_unid) const
diff --git a/crawl-ref/source/art-data.txt b/crawl-ref/source/art-data.txt
index 77c4e69..72840f4 100644
--- a/crawl-ref/source/art-data.txt
+++ b/crawl-ref/source/art-data.txt
@@ -1117,6 +1117,18 @@ PLUS:    +2
 BRAND:   SPARM_ARCHMAGI
 STEALTH: -20
 
+ENUM:    TIPSTAFF
+NAME:    tipstaff of Order
+OBJ:     OBJ_WEAPONS/WPN_QUARTERSTAFF
+TYPE:    tipstaff
+INSCRIP: silver, rMut
+COLOUR:  ETC_SILVER
+PLUS:    7/7
+BASE_ACC: -6
+BASE_DAM: +6
+BASE_DELAY: +1
+VALUE:   1000
+
 # This is the first of two amulets used to test suppression aura.
 # Together, they confer every randart effect except for a few that are
 # determined explicitly by checking whether a certain amulet is worn
diff --git a/crawl-ref/source/art-func.h b/crawl-ref/source/art-func.h
index 90a741f..d58c4ae 100644
--- a/crawl-ref/source/art-func.h
+++ b/crawl-ref/source/art-func.h
@@ -36,6 +36,7 @@
 #include "spl-miscast.h"   // For Staff of Wucad Mu and Scythe of Curses miscasts
 #include "spl-summoning.h" // For Zonguldrok animating dead
 #include "terrain.h"       // For storm bow
+#include "throw.h"         // For Crescent Moon silver damage
 
 /*******************
  * Helper functions.
@@ -934,3 +935,29 @@ static void _ELEMENTAL_STAFF_melee_effects(item_def* item, actor* attacker,
          defender->name(DESC_THE).c_str());
     defender->hurt(attacker, d);
 }
+
+///////////////////////////////////////////////////
+
+static void _TIPSTAFF_equip(item_def *item, bool *show_msgs, bool unmeld)
+{
+    _equip_mpr(show_msgs, "You feel Zin shielding your body from chaos.");
+}
+
+static void _TIPSTAFF_melee_effects(item_def* item, actor* attacker,
+                                         actor* defender, bool mondied, int dam)
+{
+    if (!mondied)
+    {
+        int tempdam = dam;
+        bolt tempbeam;
+        string msg = "";
+        silver_damages_victim(tempbeam, defender, tempdam, msg);
+        if (tempdam > dam)
+        {
+            tempdam -= dam;
+            if (you.can_see(defender))
+                mpr(msg.c_str());
+            defender->hurt(attacker, tempdam);
+        }
+    }
+}
diff --git a/crawl-ref/source/dat/descript/unrand.txt b/crawl-ref/source/dat/descript/unrand.txt
index 0d51d65..3150fb9 100644
--- a/crawl-ref/source/dat/descript/unrand.txt
+++ b/crawl-ref/source/dat/descript/unrand.txt
@@ -507,6 +507,16 @@ effects from the residual hexes and magical energies it was once subjected to
 on a daily basis; spellcasters able to get a handle on its power, however, will
 find it enhances their spell power.
 %%%%
+tipstaff of Order
+
+Legend says that once the staff was the favored weapon of the many priests of
+Zin. Long ago Zin bestowed this gift upon a favored worshipper.
+
+Its hefty silver shaft makes it harm even monsters not vulnerable to silver
+more than a normal quarterstaff, but slows down attacks with it slightly. It
+is also said to provide its wielder with a rare boon, a resistance to the
+chaos Zin abhors.
+%%%%
 milk chocolate
 
 This item is a debugging aid, granting a vast array of mostly beneficial
diff --git a/crawl-ref/source/rltiles/dc-player.txt b/crawl-ref/source/rltiles/dc-player.txt
index 35c02b0..f320ce9 100644
--- a/crawl-ref/source/rltiles/dc-player.txt
+++ b/crawl-ref/source/rltiles/dc-player.txt
@@ -516,6 +516,7 @@ elemental_staff ELEMENTAL_STAFF
 asmodeus ASMODEUS
 dispater DISPATER
 olgreb OLGREB
+crescent_moon CRESCENT_MOON
 ## axes
 axe_trog AXE_TROG
 arga ARGA
diff --git a/crawl-ref/source/throw.cc b/crawl-ref/source/throw.cc
index 04427f2..710cc58 100644
--- a/crawl-ref/source/throw.cc
+++ b/crawl-ref/source/throw.cc
@@ -612,8 +612,8 @@ static bool _item_penetrates_victim(const bolt &beam, int &used)
     return true;
 }
 
-static bool _silver_damages_victim(bolt &beam, actor* victim, int &dmg,
-                                   string &dmg_msg)
+bool silver_damages_victim(bolt &beam, actor* victim, int &dmg,
+                           string &dmg_msg)
 {
     int mutated = 0;
 
@@ -1201,7 +1201,7 @@ static bool _setup_missile_beam(const actor *agent, bolt &beam, item_def &item,
     ASSERT(beam.flavour == BEAM_MISSILE || !is_artefact(item));
 
     if (silver)
-        beam.damage_funcs.push_back(_silver_damages_victim);
+        beam.damage_funcs.push_back(silver_damages_victim);
     if (poisoned)
         beam.hit_funcs.push_back(_poison_hit_victim);
     if (penetrating)
diff --git a/crawl-ref/source/throw.h b/crawl-ref/source/throw.h
index 32453d4..c413657 100644
--- a/crawl-ref/source/throw.h
+++ b/crawl-ref/source/throw.h
@@ -34,6 +34,9 @@ int get_ammo_to_shoot(int item, dist &target, bool teleport = false);
 void fire_thing(int item = -1);
 void throw_item_no_quiver(void);
 
+bool silver_damages_victim(bolt &beam, actor* victim, int &dmg,
+                           string &dmg_msg);
+
 bool throw_it(bolt &pbolt, int throw_2, bool teleport = false,
               int acc_bonus = 0, dist *target = NULL);
 
-- 
1.8.1.4

