From 05778102b466f438185552dfb314423635fdf8a6 Mon Sep 17 00:00:00 2001 From: haranp Date: Tue, 13 Mar 2007 20:24:52 +0000 Subject: Fix for 1661786: autoprayer now works with run delays. Perhaps we should a note to the docs mentioning the possibility of setting runrest_ignore_message appropriately to make it work well with autoprayer. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1032 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/misc.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'crawl-ref/source/misc.cc') 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; + } +} -- cgit v1.2.3-54-g00ecf