From 9c8871bc3e50d51e3898ff5594b9d4f73f15c55b Mon Sep 17 00:00:00 2001 From: zelgadis Date: Tue, 20 Jan 2009 10:41:45 +0000 Subject: Make extra-sure that a monster won't be announced to have come into view, only to immediately move out of view, by introducing the notion of the currently acting monster to crawl_state, and only flushing out the "comes into view" message in mpr() for the currently acting monster. Not sure if it's worth it just for the sake of avoiding doing a "has this monster just now come into view" check in every place that a monster might issue a message, but at least this way we won't miss any places such a check should be placed. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8623 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/state.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'crawl-ref/source/state.cc') diff --git a/crawl-ref/source/state.cc b/crawl-ref/source/state.cc index c232b8f6f3..55cb88d0ff 100644 --- a/crawl-ref/source/state.cc +++ b/crawl-ref/source/state.cc @@ -374,6 +374,61 @@ std::vector game_state::other_gods_acting() const return god_act_stack; } +bool game_state::is_mon_acting() const +{ + return (mon_act != NULL); +} + +monsters* game_state::which_mon_acting() const +{ + return (mon_act); +} + +void game_state::inc_mon_acting(monsters* mon) +{ + ASSERT(!invalid_monster(mon)); + + if (mon_act != NULL) + mon_act_stack.push_back(mon_act); + + mon_act = mon; +} + +void game_state::dec_mon_acting(monsters* mon) +{ + ASSERT(mon_act == mon); + + mon_act = NULL; + + if (mon_act_stack.size() > 0) + { + mon_act = *(mon_act_stack.end()); + ASSERT(!invalid_monster(mon_act)); + mon_act_stack.pop_back(); + } +} + +void game_state::clear_mon_acting() +{ + mon_act = NULL; + mon_act_stack.clear(); +} + +void game_state::mon_gone(monsters* mon) +{ + for (unsigned int i = 0, size = mon_act_stack.size(); i < size; i++) + { + if (mon_act_stack[i] == mon) + { + mon_act_stack.erase(mon_act_stack.begin() + i); + i--; + } + } + + if (mon_act == mon) + dec_mon_acting(mon); +} + void game_state::dump(FILE* file) { fprintf(file, EOL "Game state:" EOL EOL); -- cgit v1.2.3-54-g00ecf