summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-11-24 09:40:16 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-24 11:05:13 +0100
commit5648dce61108e9c5059f390a1c9b28a68ce0b439 (patch)
tree9343bf0b18644cd9e603ee23340f4744320f8979 /crawl-ref/source
parentf8bbfc037a9f75e06a51fc9f1fc48c2f3d9572e1 (diff)
downloadcrawl-ref-5648dce61108e9c5059f390a1c9b28a68ce0b439.tar.gz
crawl-ref-5648dce61108e9c5059f390a1c9b28a68ce0b439.zip
Add ternary logic type maybe_bool.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/enum.h7
-rw-r--r--crawl-ref/source/stuff.cc26
-rw-r--r--crawl-ref/source/stuff.h4
3 files changed, 37 insertions, 0 deletions
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index c970478866..d14fd76c9a 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -3167,6 +3167,13 @@ enum montravel_target_type
MTRAV_KNOWN_UNREACHABLE // As above, and the player knows this.
};
+enum maybe_bool
+{
+ B_FALSE,
+ B_MAYBE,
+ B_TRUE
+};
+
#ifdef USE_TILE
enum screen_mode
{
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index f7f93c67a7..f3d24c6f25 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -936,3 +936,29 @@ int random_rod_subtype()
{
return STAFF_FIRST_ROD + random2(NUM_STAVES - STAFF_FIRST_ROD);
}
+
+maybe_bool frombool(bool b)
+{
+ return (b ? B_TRUE : B_FALSE);
+}
+
+bool tobool(maybe_bool mb)
+{
+ ASSERT (mb != B_MAYBE);
+ return (mb == B_TRUE);
+}
+
+bool tobool(maybe_bool mb, bool def)
+{
+ switch (mb)
+ {
+ case B_TRUE:
+ return (true);
+ case B_FALSE:
+ return (false);
+ case B_MAYBE:
+ default:
+ return (def);
+ }
+}
+
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 11fea7beed..5bfcebdcd2 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -97,4 +97,8 @@ int integer_sqrt(int value);
int random_rod_subtype();
+maybe_bool frombool(bool b);
+bool tobool(maybe_bool mb, bool def);
+bool tobool(maybe_bool mb);
+
#endif