summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/uncancel.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2012-11-21 14:11:59 +0100
committerAdam Borowski <kilobyte@angband.pl>2012-11-21 14:11:59 +0100
commit58457ea65098736276e7220cc4eec07c3b9abf39 (patch)
tree2eefb8a30f353e0e1163f042beecfb1fefbbdec1 /crawl-ref/source/uncancel.cc
parent376ddfc049875365fb21d902f7529017d3d12022 (diff)
downloadcrawl-ref-58457ea65098736276e7220cc4eec07c3b9abf39.tar.gz
crawl-ref-58457ea65098736276e7220cc4eec07c3b9abf39.zip
Don't lose acquirement if you disconnect at the prompt.
People are quite likely to stop and think, consult ##crawl, etc. And thinking is tiresome, folks get distracted... and then it's a time-out, they turn the computer without thinking and go to sleep, etc. This adds a new mechanism: "uncancellables", which allows an action to restart when the game is loaded back.
Diffstat (limited to 'crawl-ref/source/uncancel.cc')
-rw-r--r--crawl-ref/source/uncancel.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/crawl-ref/source/uncancel.cc b/crawl-ref/source/uncancel.cc
new file mode 100644
index 0000000000..3a0eaff3bb
--- /dev/null
+++ b/crawl-ref/source/uncancel.cc
@@ -0,0 +1,42 @@
+/**
+ * @file
+ * @brief User interactions that need to be restarted if the game is forcibly
+ * saved (via SIGHUP/window close).
+**/
+
+#include "AppHdr.h"
+#include "acquire.h"
+#include "libutil.h"
+#include "player.h"
+#include "state.h"
+#include "uncancel.h"
+
+void add_uncancel(uncancellable_type kind, int arg)
+{
+ you.uncancel.push_back(pair<uncancellable_type, int>(kind, arg));
+}
+
+void run_uncancels()
+{
+ while (!you.uncancel.empty() && !crawl_state.seen_hups)
+ {
+ // changed to -1 if we pop prematurely
+ int act = you.uncancel.size() - 1;
+
+ // Beware of race conditions: it is not enough to check seen_hups,
+ // the action must actually fail as well! And if it fails but there
+ // was no HUP, it's due to some other reason.
+
+ int arg = you.uncancel[act].second;
+
+ switch (you.uncancel[act].first)
+ {
+ case UNC_ACQUIREMENT:
+ if (!acquirement(OBJ_RANDOM, arg) && crawl_state.seen_hups)
+ return;
+ }
+
+ if (act != -1)
+ erase_any(you.uncancel, act);
+ }
+}