summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/misc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/misc.cc')
-rw-r--r--crawl-ref/source/misc.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 8e0845748b..f545c5184f 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -53,6 +53,7 @@
#include "ouch.h"
#include "overmap.h"
#include "player.h"
+#include "religion.h"
#include "shopping.h"
#include "skills.h"
#include "skills2.h"
@@ -2199,3 +2200,44 @@ int str_to_shoptype(const std::string &s)
}
return (-1);
}
+
+/* Decides whether autoprayer Right Now is a good idea. */
+static bool should_autopray()
+{
+ if ( Options.autoprayer_on == false ||
+ you.religion == GOD_NO_GOD ||
+ you.duration[DUR_PRAYER] ||
+ grid_altar_god( grd[you.x_pos][you.y_pos] ) != GOD_NO_GOD ||
+ !i_feel_safe() )
+ return false;
+
+ // We already know that we're not praying now. So if you
+ // just autoprayed, there's a problem.
+ if ( you.just_autoprayed )
+ {
+ mpr("Autoprayer failed, deactivating.", MSGCH_WARN);
+ Options.autoprayer_on = false;
+ return false;
+ }
+
+ return true;
+}
+
+/* Actually performs autoprayer. */
+bool do_autopray()
+{
+ if ( you.turn_is_over ) // can happen with autopickup, I think
+ return false;
+
+ if ( should_autopray() )
+ {
+ pray();
+ you.just_autoprayed = true;
+ return true;
+ }
+ else
+ {
+ you.just_autoprayed = false;
+ return false;
+ }
+}