summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/externs.h1
-rw-r--r--crawl-ref/source/files.cc5
-rw-r--r--crawl-ref/source/player.cc1
-rw-r--r--crawl-ref/source/religion.cc41
-rw-r--r--crawl-ref/source/tags.cc6
5 files changed, 44 insertions, 10 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 0832dc7c9c..2e98e3fc99 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -703,6 +703,7 @@ public:
god_type religion;
unsigned char piety;
+ unsigned char piety_hysteresis; // amount of stored-up docking
unsigned char gift_timeout;
FixedVector<unsigned char, MAX_NUM_GODS> penance;
FixedVector<unsigned char, MAX_NUM_GODS> worshipped;
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index c656e2f596..0c4d6d4aa0 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -106,7 +106,10 @@ void save_level(int level_saved, level_area_type lt,
#define GHOST_MINOR_VERSION 1
#define LEVEL_MINOR_VERSION 1
-#define YOU_MINOR_VERSION 1
+
+// 1: starting version
+// 2: append piety_hysteresis to TAG_YOU
+#define YOU_MINOR_VERSION 2
const short GHOST_SIGNATURE = static_cast<short>( 0xDC55 );
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 2e0d3968fd..850030f30f 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -5208,6 +5208,7 @@ void player::init()
religion = GOD_NO_GOD;
piety = 0;
+ piety_hysteresis = 0;
gift_timeout = 0;
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 8052321cee..440244a305 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -85,6 +85,8 @@
# define DEBUG_PIETY 1
#endif
+#define PIETY_HYSTERESIS_LIMIT 1
+
// Item offer messages for the gods:
// & is replaced by "is" or "are" as appropriate for the item.
// % is replaced by "s" or "" as appropriate.
@@ -1093,7 +1095,7 @@ void pray()
do_god_gift(true);
#if DEBUG_DIAGNOSTICS
- mprf(MSGCH_DIAGNOSTICS, "piety: %d", you.piety );
+ mprf(MSGCH_DIAGNOSTICS, "piety: %d (-%d)", you.piety, you.piety_hysteresis );
#endif
} // end pray()
@@ -1756,10 +1758,6 @@ void gain_piety(int pgn)
}
}
-#if DEBUG_PIETY
- mprf(MSGCH_DIAGNOSTICS, "Piety increasing by %d", pgn);
-#endif
-
// slow down gain at upper levels of piety
if (you.religion != GOD_SIF_MUNA)
{
@@ -1783,6 +1781,20 @@ void gain_piety(int pgn)
}
}
+ // Apply hysteresis
+ {
+ // piety_hysteresis is the amount of _loss_ stored up, so this
+ // may look backwards.
+ const int old_hysteresis = you.piety_hysteresis;
+ you.piety_hysteresis = (unsigned char)std::max<int>(
+ 0, you.piety_hysteresis - pgn);
+ const int pgn_borrowed = (old_hysteresis - you.piety_hysteresis);
+ pgn -= pgn_borrowed;
+#if DEBUG_PIETY
+mprf(MSGCH_DIAGNOSTICS, "Piety increasing by %d (and %d taken from hysteresis)", pgn, pgn_borrowed);
+#endif
+ }
+
int old_piety = you.piety;
you.piety += pgn;
@@ -1971,8 +1983,8 @@ bool trog_burn_books()
const int next = mitm[i].link; // in case we can't get it later.
if (mitm[i].base_type == OBJ_BOOKS
- && mitm[i].sub_type != BOOK_MANUAL
- && mitm[i].sub_type != BOOK_DESTRUCTION)
+ && mitm[i].sub_type != BOOK_MANUAL
+ && mitm[i].sub_type != BOOK_DESTRUCTION)
{
mpr("Burning your own feet might not be such a smart idea!");
return (false);
@@ -2011,7 +2023,7 @@ bool trog_burn_books()
if (mitm[i].base_type != OBJ_BOOKS
|| mitm[i].sub_type == BOOK_MANUAL
- || mitm[i].sub_type == BOOK_DESTRUCTION)
+ || mitm[i].sub_type == BOOK_DESTRUCTION)
{
i = next;
continue;
@@ -2078,9 +2090,18 @@ void lose_piety(int pgn)
{
const int old_piety = you.piety;
+ // Apply hysteresis
+ {
+ const int old_hysteresis = you.piety_hysteresis;
+ you.piety_hysteresis = (unsigned char)std::min<int>(
+ PIETY_HYSTERESIS_LIMIT, you.piety_hysteresis + pgn);
+ const int pgn_borrowed = (you.piety_hysteresis - old_hysteresis);
+ pgn -= pgn_borrowed;
#if DEBUG_PIETY
- mprf(MSGCH_DIAGNOSTICS, "Piety decreasing by %d", pgn);
+ mprf(MSGCH_DIAGNOSTICS, "Piety decreasing by %d (and %d added to hysteresis)", pgn, pgn_borrowed);
#endif
+ }
+
if (you.piety - pgn < 0)
you.piety = 0;
@@ -3257,6 +3278,7 @@ void excommunication(void)
you.duration[DUR_PIETY_POOL] = 0; // your loss
you.religion = GOD_NO_GOD;
you.piety = 0;
+ you.piety_hysteresis = 0;
redraw_skill( you.your_name, player_title() );
mpr("You have lost your religion!");
@@ -3840,6 +3862,7 @@ void god_pitch(god_type which_god)
else
{
you.piety = 15; // to prevent near instant excommunication
+ you.piety_hysteresis = 0;
you.gift_timeout = 0;
}
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 7e54a35bef..3ab4284782 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -1004,6 +1004,9 @@ static void tag_construct_you(tagHeader &th)
marshallByte(th, you.beheld_by.size());
for (unsigned int k = 0; k < you.beheld_by.size(); k++)
marshallByte(th, you.beheld_by[k]);
+
+ // minorVersion 2 starts here
+ marshallByte(th, you.piety_hysteresis);
}
static void tag_construct_you_items(tagHeader &th)
@@ -1380,6 +1383,9 @@ static void tag_read_you(tagHeader &th, char minorVersion)
count_c = unmarshallByte(th);
for (i = 0; i < count_c; i++)
you.beheld_by.push_back(unmarshallByte(th));
+
+ if (minorVersion >= 2)
+ you.piety_hysteresis = unmarshallByte(th);
}
static void tag_read_you_items(tagHeader &th, char minorVersion)