summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/state.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-28 08:27:29 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-28 08:27:29 +0000
commit3205c9289fd9ff8bcf739903a49215f75212128e (patch)
tree6a9b4a29e9e8bd96d4e8b87934d17ce84987a8e0 /crawl-ref/source/state.cc
parentdc3aa32db050e7923a4e802b874fccd997c1d6c6 (diff)
downloadcrawl-ref-3205c9289fd9ff8bcf739903a49215f75212128e.tar.gz
crawl-ref-3205c9289fd9ff8bcf739903a49215f75212128e.zip
crawl_state now keeps track of whether or not the current code is being
executed because of a god's actions, and if so which god (with "actions" not including god-supplied invocations). Currently only used to prevent Xom from being amused/stimulated by his own actions. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2235 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/state.cc')
-rw-r--r--crawl-ref/source/state.cc102
1 files changed, 102 insertions, 0 deletions
diff --git a/crawl-ref/source/state.cc b/crawl-ref/source/state.cc
index 03cd5817db..25e314eda6 100644
--- a/crawl-ref/source/state.cc
+++ b/crawl-ref/source/state.cc
@@ -240,3 +240,105 @@ void game_state::reset_cmd_again()
prev_cmd_keys.clear();
}
+
+///////////////////////////////////////////////////////////
+// Keeping track of which god is currently doing something
+///////////////////////////////////////////////////////////
+
+god_act_state::god_act_state()
+{
+ reset();
+}
+
+void god_act_state::reset()
+{
+ which_god = GOD_NO_GOD;
+ retribution = false;
+ depth = 0;
+}
+
+bool game_state::is_god_acting() const
+{
+ ASSERT(god_act.depth >= 0);
+ ASSERT(!(god_act.depth > 0 && god_act.which_god == GOD_NO_GOD));
+ ASSERT(!(god_act.depth == 0 && god_act.which_god != GOD_NO_GOD));
+ ASSERT(!(god_act.depth == 0 && god_act_stack.size() > 0));
+
+ return (god_act.depth > 0);
+}
+
+bool game_state::is_god_retribution() const
+{
+ ASSERT(is_god_acting());
+
+ return (god_act.retribution);
+}
+
+god_type game_state::which_god_acting() const
+{
+ return god_act.which_god;
+}
+
+void game_state::inc_god_acting(bool is_retribution)
+{
+ inc_god_acting(you.religion, is_retribution);
+}
+
+void game_state::inc_god_acting(god_type which_god, bool is_retribution)
+{
+ ASSERT(which_god != GOD_NO_GOD);
+
+ if (god_act.which_god != GOD_NO_GOD &&
+ god_act.which_god != which_god)
+ {
+ ASSERT(god_act.depth >= 1);
+
+ god_act_stack.push_back(god_act);
+ god_act.reset();
+ }
+
+ god_act.which_god = which_god;
+ god_act.retribution = is_retribution;
+ god_act.depth++;
+}
+
+void game_state::dec_god_acting()
+{
+ dec_god_acting(you.religion);
+}
+
+void game_state::dec_god_acting(god_type which_god)
+{
+ ASSERT(which_god != GOD_NO_GOD);
+ ASSERT(god_act.depth > 0);
+ ASSERT(god_act.which_god == which_god);
+
+ god_act.depth--;
+
+ if (god_act.depth == 0)
+ {
+ god_act.reset();
+ if (god_act_stack.size() > 0)
+ {
+ god_act = god_act_stack[god_act_stack.size() - 1];
+ god_act_stack.pop_back();
+ ASSERT(god_act.depth >= 1);
+ ASSERT(god_act.which_god != GOD_NO_GOD);
+ ASSERT(god_act.which_god != which_god);
+ }
+ }
+}
+
+void game_state::clear_god_acting()
+{
+ ASSERT(!is_god_acting());
+ ASSERT(god_act_stack.size() == 0);
+
+ god_act.reset();
+}
+
+std::vector<god_act_state> game_state::other_gods_acting() const
+{
+ ASSERT(is_god_acting());
+ return god_act_stack;
+}