From 3205c9289fd9ff8bcf739903a49215f75212128e Mon Sep 17 00:00:00 2001 From: zelgadis Date: Fri, 28 Sep 2007 08:27:29 +0000 Subject: 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 --- crawl-ref/source/state.cc | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'crawl-ref/source/state.cc') 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 game_state::other_gods_acting() const +{ + ASSERT(is_god_acting()); + return god_act_stack; +} -- cgit v1.2.3-54-g00ecf