summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2007-12-01 18:30:23 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2007-12-01 18:30:23 +0000
commit37ffd29a84d48b08c2ef799a271f3ab83202a03a (patch)
treeb38cd8507f2b67cb339ce0879e9a1fc1e58e44f0 /crawl-ref
parentae715f40ef49bd3e81a59847cb642bf7b328d3de (diff)
downloadcrawl-ref-37ffd29a84d48b08c2ef799a271f3ab83202a03a.tar.gz
crawl-ref-37ffd29a84d48b08c2ef799a271f3ab83202a03a.zip
Add one more cleanup of protection from harm. Since there's more than
one type of it now, expand god_protects_from_harm() to include the logic for when certain gods do it. Also, as brought up on crawl-ref-discuss, make Elyvilon do it both casually and during prayer. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2959 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/describe.cc28
-rw-r--r--crawl-ref/source/ouch.cc10
-rw-r--r--crawl-ref/source/religion.cc33
-rw-r--r--crawl-ref/source/religion.h11
4 files changed, 58 insertions, 24 deletions
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 87e2f4991b..c3b3a9f301 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -4276,23 +4276,27 @@ void describe_god( god_type which_god, bool give_title )
textcolor(colour);
// mv: some gods can protect you from harm
- // The chance for doing so is:
- // one_chance_in(10) || you.piety > random2(1000)
- // Note that it's not depending on penance.
- // Btw. I'm not sure how to explain such divine protection
- // because god isn't really protecting player - he only sometimes
- // saves his life (probably it shouldn't be displayed at all).
+ // I'm not sure how to explain such divine protection because
+ // god isn't really protecting player - he only sometimes saves
+ // his life (probably it shouldn't be displayed at all).
// What about this?
bool have_any = false;
- if (god_protects_from_harm(which_god))
+ if (harm_protection_type hpt =
+ god_protects_from_harm(which_god, false))
{
+ const char *how = (you.piety >= 150) ? "carefully" :
+ (you.piety >= 90) ? "often" :
+ (you.piety >= 30) ? "sometimes" :
+ "occasionally";
+ const char *when =
+ (hpt == HPT_PRAYING) ? " during prayer" :
+ (hpt == HPT_PRAYING_PLUS_ANYTIME) ? ", especially during prayer" :
+ "";
+
have_any = true;
- cprintf( "%s %s watches over you." EOL, god_name(which_god),
- (you.piety >= 150) ? "carefully":
- (you.piety >= 90) ? "often" :
- (you.piety >= 30) ? "sometimes" :
- "occasionally");
+ cprintf( "%s %s watches over you%s." EOL, god_name(which_god),
+ how, when );
}
if (which_god == GOD_ZIN && you.piety >= 30)
diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc
index 2459ee687c..537b481097 100644
--- a/crawl-ref/source/ouch.cc
+++ b/crawl-ref/source/ouch.cc
@@ -787,14 +787,8 @@ void ouch( int dam, int death_source, kill_method_type death_type,
{
if (dam >= you.hp && god_protects_from_harm(you.religion))
{
- if ((you.religion == GOD_ZIN || you.religion == GOD_SHINING_ONE)
- && (one_chance_in(10) || you.piety > random2(1000))
- || (you.religion == GOD_ELYVILON || you.religion == GOD_YREDELEMNUL)
- && you.duration[DUR_PRAYER] && random2(you.piety) >= 30)
- {
- simple_god_message( " protects you from harm!" );
- return;
- }
+ simple_god_message( " protects you from harm!" );
+ return;
}
dec_hp( dam, true );
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 5cb96c2c4c..d7cdd7361b 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -3451,10 +3451,37 @@ bool god_hates_butchery(god_type god)
return (god == GOD_ELYVILON);
}
-bool god_protects_from_harm(god_type god)
+harm_protection_type god_protects_from_harm(god_type god, bool actual)
{
- return (god == GOD_ZIN || god == GOD_SHINING_ONE ||
- god == GOD_ELYVILON || god == GOD_YREDELEMNUL);
+ const int min_piety = piety_breakpoint(0);
+ bool praying = (you.duration[DUR_PRAYER] &&
+ random2(you.piety) >= min_piety);
+ bool anytime = (one_chance_in(10) || you.piety > random2(1000));
+
+ // If actual is true, return HPT_NONE if the given god can protect
+ // the player from harm, but doesn't actually do so.
+ switch (god)
+ {
+ case GOD_YREDELEMNUL:
+ if (!actual || praying)
+ return (you.piety >= min_piety) ? HPT_PRAYING :
+ HPT_NONE;
+ break;
+ case GOD_ZIN:
+ case GOD_SHINING_ONE:
+ if (!actual || anytime)
+ return HPT_ANYTIME;
+ break;
+ case GOD_ELYVILON:
+ if (!actual || praying || anytime)
+ return (you.piety >= min_piety) ? HPT_PRAYING_PLUS_ANYTIME :
+ HPT_ANYTIME;
+ break;
+ default:
+ break;
+ }
+
+ return HPT_NONE;
}
void god_smites_you(god_type god, kill_method_type death_type,
diff --git a/crawl-ref/source/religion.h b/crawl-ref/source/religion.h
index bce7b64b39..989f2b716a 100644
--- a/crawl-ref/source/religion.h
+++ b/crawl-ref/source/religion.h
@@ -23,6 +23,15 @@
class actor;
class monsters;
+enum harm_protection_type
+{
+ HPT_NONE = 0,
+ HPT_PRAYING,
+ HPT_ANYTIME,
+ HPT_PRAYING_PLUS_ANYTIME,
+ NUM_HPTS
+};
+
bool is_priest_god(god_type god);
void simple_god_message( const char *event, god_type which_deity = GOD_NO_GOD );
int piety_breakpoint(int i);
@@ -47,7 +56,7 @@ int piety_rank(int piety = -1);
void offer_items();
bool god_likes_butchery(god_type god);
bool god_hates_butchery(god_type god);
-bool god_protects_from_harm(god_type god);
+harm_protection_type god_protects_from_harm(god_type god, bool actual = true);
void god_smites_you(god_type god, kill_method_type death_type,
const char *message = NULL);
void divine_retribution(god_type god);