diff options
author | Bardur Arantsson <bardur@scientician.net> | 2015-04-15 19:12:41 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2015-04-15 19:12:41 +0200 |
commit | 8b2be5adc24ffdecc7bb5d8ed08be12a7590bc46 (patch) | |
tree | 52f137bd6e83baa12ad60b50c4710d04a7559cb2 /src/object_filter.cc | |
parent | edede30a361f34d8c2f1d5de45adeac9392f41b9 (diff) |
Rework object list filters to avoid global variables
Diffstat (limited to 'src/object_filter.cc')
-rw-r--r-- | src/object_filter.cc | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/object_filter.cc b/src/object_filter.cc new file mode 100644 index 00000000..8d87213d --- /dev/null +++ b/src/object_filter.cc @@ -0,0 +1,97 @@ +#include "object_filter.hpp" +#include "object1.hpp" +#include "object2.hpp" + +namespace object_filter { + +object_filter_t TVal(byte tval) { + return [=](object_type const *o_ptr) -> bool { + return o_ptr->tval == tval; + }; +} + +object_filter_t SVal(byte sval) { + return [=](object_type const *o_ptr) -> bool { + return o_ptr->sval == sval; + }; +} + +object_filter_t HasFlag3(u32b mask) { + return [=](object_type const *o_ptr) -> bool { + // Extract the flags + u32b f1, f2, f3, f4, f5, esp; + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + // Does the item have the flag? + return (f3 & mask); + }; +} + +object_filter_t HasFlag4(u32b mask) { + return [=](object_type const *o_ptr) -> bool { + // Extract the flags + u32b f1, f2, f3, f4, f5, esp; + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + // Does the item have the flag? + return (f4 & mask); + }; +} + +object_filter_t HasFlag5(u32b mask) { + return [=](object_type const *o_ptr) -> bool { + // Extract the flags + u32b f1, f2, f3, f4, f5, esp; + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + // Does the item have the flag? + return (f5 & mask); + }; +} + +object_filter_t IsArtifact() { + return [](object_type const *o_ptr) -> bool { + return o_ptr->name1 > 0; + }; +} + +object_filter_t IsArtifactP() { + return [](object_type const *o_ptr) -> bool { + return artifact_p(o_ptr); + }; +} + +object_filter_t IsEgo() { + return [](object_type const *o_ptr) -> bool { + return ego_item_p(o_ptr); + }; +} + +object_filter_t IsKnown() { + return [](object_type const *o_ptr) -> bool { + return object_known_p(o_ptr); + }; +} + +object_filter_t True() { + return [](object_type const *o_ptr) -> bool { + return true; + }; +} + +object_filter_t Not(object_filter_t p) { + return [=](object_type const *o_ptr) -> bool { + return !p(o_ptr); + }; +} + +object_filter_t And() { + return [](object_type const *) -> bool { + return true; + }; +} + +object_filter_t Or() { + return [](object_type const *) -> bool { + return false; + }; +} + +} |