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/acr.cc | 75 ++++++++++++++------------------------------ crawl-ref/source/delay.cc | 4 +++ crawl-ref/source/externs.h | 2 ++ crawl-ref/source/misc.cc | 42 +++++++++++++++++++++++++ crawl-ref/source/misc.h | 2 ++ crawl-ref/source/player.cc | 1 + crawl-ref/source/religion.cc | 30 +++++++----------- 7 files changed, 85 insertions(+), 71 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 485183bffe..0c50ab5ed9 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -138,9 +138,6 @@ char info[ INFO_SIZE ]; // messaging queue extern'd everywhere {dlb} int stealth; // externed in view.cc char use_colour = 1; -bool just_autoprayed = false; -bool about_to_autopray = false; - // set to true once a new game starts or an old game loads bool game_has_started = false; @@ -839,33 +836,30 @@ static void input() if (Options.tut_just_triggered) Options.tut_just_triggered = false; - if (Options.tutorial_events[TUT_SEEN_MONSTER]) - i_feel_safe(); // can trigger tutorial as side effect - - if (Options.tutorial_events[TUT_RUN_AWAY] - && 2*you.hp < you.hp_max && !i_feel_safe()) + if ( i_feel_safe() ) { - learned_something_new(TUT_RUN_AWAY); - } + if (Options.tutorial_events[TUT_RUN_AWAY] && 2*you.hp < you.hp_max ) + learned_something_new(TUT_RUN_AWAY); - if (Options.tutorial_left && i_feel_safe()) - { - if ( 2*you.hp < you.hp_max - || 2*you.magic_points < you.max_magic_points ) - { - tutorial_healing_reminder(); - } - else if (you.running < RMODE_REST_DURATION && - Options.tutorial_events[TUT_SHIFT_RUN] && - you.num_turns >= 200) - { - learned_something_new(TUT_SHIFT_RUN); - } - else if (you.running < RMODE_REST_DURATION && - Options.tutorial_events[TUT_MAP_VIEW] && - you.num_turns >= 500) + if (Options.tutorial_left) { - learned_something_new(TUT_MAP_VIEW); + if ( 2*you.hp < you.hp_max + || 2*you.magic_points < you.max_magic_points ) + { + tutorial_healing_reminder(); + } + else if (you.running < RMODE_REST_DURATION && + Options.tutorial_events[TUT_SHIFT_RUN] && + you.num_turns >= 200) + { + learned_something_new(TUT_SHIFT_RUN); + } + else if (you.running < RMODE_REST_DURATION && + Options.tutorial_events[TUT_MAP_VIEW] && + you.num_turns >= 500) + { + learned_something_new(TUT_MAP_VIEW); + } } } @@ -890,6 +884,8 @@ static void input() return; } + do_autopray(); // this might set you.turn_is_over + if ( you.turn_is_over ) { world_reacts(); @@ -1601,7 +1597,6 @@ static void decrement_durations() else if (you.duration[DUR_PRAYER] == 1) { mpr( "Your prayer is over.", MSGCH_PRAY, you.religion ); - about_to_autopray = true; you.duration[DUR_PRAYER] = 0; } @@ -2342,30 +2337,6 @@ static void world_reacts() static command_type get_next_cmd() { - if (Options.autoprayer_on && you.duration[DUR_PRAYER] == 0 && - just_autoprayed == false && you.religion != GOD_NO_GOD && - grid_altar_god( grd[you.x_pos][you.y_pos] ) == GOD_NO_GOD && - i_feel_safe()) - { - just_autoprayed = true; - about_to_autopray = false; - return CMD_PRAY; - } - if ( just_autoprayed && you.duration[DUR_PRAYER] == 0 ) - { - /* oops */ - mpr("Autoprayer failed, deactivating.", MSGCH_WARN); - Options.autoprayer_on = false; - } - just_autoprayed = false; - if ( Options.autoprayer_on && about_to_autopray && - you.religion != GOD_NO_GOD && - you.duration[DUR_PRAYER] == 0 ) - { - mpr("Autoprayer not resuming prayer.", MSGCH_WARN); - about_to_autopray = false; - } - #if DEBUG_DIAGNOSTICS // save hunger at start of round // for use with hunger "delta-meter" in output.cc diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc index fdc04f3360..a9335e2e72 100644 --- a/crawl-ref/source/delay.cc +++ b/crawl-ref/source/delay.cc @@ -288,6 +288,10 @@ void handle_delay( void ) // Run delays and Lua delays don't have a specific end time. if (is_run_delay(delay.type)) { + // Hack - allow autoprayer to trigger during run delays + if ( do_autopray() ) + return; + handle_run_delays(delay); return; } diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index a222cee91b..e03b950a8f 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -499,6 +499,8 @@ public: bool banished; // flag signaling that the player is due a visit to the // Abyss. + + bool just_autoprayed; // autopray just kicked in unsigned char prev_targ; char your_name[kNameLen]; 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; + } +} diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h index cc0b1e0fc7..cd706748c9 100644 --- a/crawl-ref/source/misc.h +++ b/crawl-ref/source/misc.h @@ -195,4 +195,6 @@ void set_colours_from_monsters(); int str_to_shoptype(const std::string &s); +bool do_autopray(); + #endif diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index ae4d70e039..7cccd7b502 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -4476,6 +4476,7 @@ void player::init() your_name[0] = 0; banished = false; + just_autoprayed = false; berserk_penalty = 0; berserker = 0; conf = 0; diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index 85ee1d99bd..b7dec5523c 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -593,7 +593,7 @@ static void do_god_gift() void pray(void) { - unsigned char was_praying = you.duration[DUR_PRAYER]; + const bool was_praying = (you.duration[DUR_PRAYER] != 0); if (silenced(you.x_pos, you.y_pos)) { @@ -601,15 +601,15 @@ void pray(void) return; } - // all prayers take time + // almost all prayers take time you.turn_is_over = true; - if (you.religion != GOD_NO_GOD - && grid_altar_god(grd[you.x_pos][you.y_pos]) == you.religion) + const god_type altar_god = grid_altar_god(grd[you.x_pos][you.y_pos]); + if (you.religion != GOD_NO_GOD && altar_god == you.religion) { altar_prayer(); } - else if (grid_altar_god(grd[you.x_pos][you.y_pos]) != GOD_NO_GOD) + else if (altar_god != GOD_NO_GOD) { if (you.species == SP_DEMIGOD) { @@ -622,13 +622,9 @@ void pray(void) if (you.religion == GOD_NO_GOD) { - strcpy(info, "You spend a moment contemplating the meaning of "); - - if (you.is_undead) - strcat(info, "un"); - - strcat(info, "life."); - mpr(info, MSGCH_PRAY); + mprf(MSGCH_PRAY, + "You spend a moment contemplating the meaning of %slife.", + you.is_undead ? "un" : ""); // Zen meditation is timeless. you.turn_is_over = false; @@ -660,14 +656,11 @@ void pray(void) return; } - strcpy( info, "You offer a prayer to " ); - strcat( info, god_name( you.religion ) ); - strcat( info, "." ); - mpr(info, MSGCH_PRAY); + mprf(MSGCH_PRAY, "You offer a prayer to %s.", god_name(you.religion)); you.duration[DUR_PRAYER] = 9 + (random2(you.piety) / 20) + (random2(you.piety) / 20); - + if (player_under_penance()) simple_god_message(" demands penance!"); else @@ -693,8 +686,7 @@ void pray(void) } #if DEBUG_DIAGNOSTICS - snprintf( info, INFO_SIZE, "piety: %d", you.piety ); - mpr( info, MSGCH_DIAGNOSTICS ); + mprf(MSGCH_DIAGNOSTICS, "piety: %d", you.piety ); #endif if (!was_praying) -- cgit v1.2.3-54-g00ecf