diff options
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/enum.h | 7 | ||||
-rw-r--r-- | crawl-ref/source/stuff.cc | 26 | ||||
-rw-r--r-- | crawl-ref/source/stuff.h | 4 |
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 |