summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan O'Rear <stefanor@cox.net>2010-01-02 14:58:18 -0800
committerStefan O'Rear <stefanor@cox.net>2010-01-02 15:08:50 -0800
commit74a7f0850963676d0ee82a427653562980694a78 (patch)
tree16d3afcc8c59176340347bdf860217950beaa953
parentd54de77e23c945c5d34e7d9e04fefece29f9f7e2 (diff)
downloadcrawl-ref-74a7f0850963676d0ee82a427653562980694a78.tar.gz
crawl-ref-74a7f0850963676d0ee82a427653562980694a78.zip
Decouple rod recharge from availability of player MP (Mantis 300)
-rw-r--r--crawl-ref/source/effects.cc57
-rw-r--r--crawl-ref/source/effects.h1
-rw-r--r--crawl-ref/source/main.cc64
3 files changed, 59 insertions, 63 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 3402037d7e..109539cc75 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -70,6 +70,7 @@
#include "stuff.h"
#include "terrain.h"
#include "traps.h"
+#include "travel.h"
#include "tutorial.h"
#include "view.h"
#include "shout.h"
@@ -4237,6 +4238,7 @@ void update_level(double elapsedTime)
update_corpses(elapsedTime);
shoals_apply_tides(turns);
+ recharge_rods((long)turns, true);
if (env.sanctuary_time)
{
@@ -4845,3 +4847,58 @@ void update_corpses(double elapsedTime)
}
}
}
+
+static void _recharge_rod( item_def &rod, long aut, bool in_inv )
+{
+ if (!item_is_rod(rod) || rod.plus >= rod.plus2)
+ return;
+
+ const int charge = rod.plus / ROD_CHARGE_MULT;
+
+ int rate = ((charge + 1) * ROD_CHARGE_MULT) / 10;
+
+ rate *= (10 + skill_bump( SK_EVOCATIONS ));
+ rate = div_rand_round( rate, 100 );
+ rate = div_rand_round( rate * aut, 10 );
+
+ if (rate < 5)
+ rate = 5;
+ else if (rate > ROD_CHARGE_MULT / 2)
+ rate = ROD_CHARGE_MULT / 2;
+
+ if (rod.plus / ROD_CHARGE_MULT != (rod.plus + rate) / ROD_CHARGE_MULT)
+ {
+ if (item_is_equipped( rod, true ))
+ you.wield_change = true;
+ }
+
+ rod.plus += rate;
+ if (rod.plus > rod.plus2)
+ rod.plus = rod.plus2;
+
+ if (in_inv && rod.plus == rod.plus2)
+ {
+ msg::stream << "Your " << rod.name(DESC_QUALNAME) << " has recharged."
+ << std::endl;
+ if (is_resting())
+ stop_running();
+ }
+
+ return;
+}
+
+void recharge_rods(long aut, bool level_only)
+{
+ if (!level_only)
+ {
+ for (int item = 0; item < ENDOFPACK; ++item)
+ {
+ _recharge_rod( you.inv[item], aut, true );
+ }
+ }
+
+ for (int item = 0; item < MAX_ITEMS; ++item)
+ {
+ _recharge_rod( mitm[item], aut, false );
+ }
+}
diff --git a/crawl-ref/source/effects.h b/crawl-ref/source/effects.h
index dbabe6cd48..b1e6808198 100644
--- a/crawl-ref/source/effects.h
+++ b/crawl-ref/source/effects.h
@@ -96,5 +96,6 @@ bool vitrify_area(int radius);
void update_corpses(double elapsedTime);
void update_level(double elapsedTime);
void handle_time();
+void recharge_rods(long aut, bool floor_only);
#endif
diff --git a/crawl-ref/source/main.cc b/crawl-ref/source/main.cc
index 2d64a7aa6f..fd4dd7b94e 100644
--- a/crawl-ref/source/main.cc
+++ b/crawl-ref/source/main.cc
@@ -719,68 +719,6 @@ static void _start_running( int dir, int mode )
you.running.initialise(dir, mode);
}
-static bool _recharge_rod( item_def &rod, bool wielded )
-{
- if (!item_is_rod(rod) || rod.plus >= rod.plus2 || !enough_mp(1, true))
- return (false);
-
- const int charge = rod.plus / ROD_CHARGE_MULT;
-
- int rate = ((charge + 1) * ROD_CHARGE_MULT) / 10;
-
- rate *= (10 + skill_bump( SK_EVOCATIONS ));
- rate = div_rand_round( rate, 100 );
-
- if (rate < 5)
- rate = 5;
- else if (rate > ROD_CHARGE_MULT / 2)
- rate = ROD_CHARGE_MULT / 2;
-
- // If not wielded, the rod charges far more slowly.
- if (!wielded)
- rate /= 5;
- // Shields hamper recharging for wielded rods.
- else if (you.shield())
- rate /= 2;
-
- if (rod.plus / ROD_CHARGE_MULT != (rod.plus + rate) / ROD_CHARGE_MULT)
- {
- dec_mp(1);
- if (wielded)
- you.wield_change = true;
- }
-
- rod.plus += rate;
- if (rod.plus > rod.plus2)
- rod.plus = rod.plus2;
-
- if (wielded && rod.plus == rod.plus2)
- {
- mpr("Your rod has recharged.");
- if (is_resting())
- stop_running();
- }
-
- return (true);
-}
-
-static void _recharge_rods()
-{
- const int wielded = you.equip[EQ_WEAPON];
- if (wielded != -1 && _recharge_rod( you.inv[wielded], true ))
- return;
-
- for (int i = 0; i < ENDOFPACK; ++i)
- {
- if (i != wielded && you.inv[i].is_valid()
- && one_chance_in(3)
- && _recharge_rod( you.inv[i], false ))
- {
- return;
- }
- }
-}
-
static bool _cmd_is_repeatable(command_type cmd, bool is_again = false)
{
switch (cmd)
@@ -2880,7 +2818,7 @@ void world_reacts()
_regenerate_hp_and_mp(you.time_taken);
// If you're wielding a rod, it'll gradually recharge.
- _recharge_rods();
+ recharge_rods(you.time_taken, false);
viewwindow(true);