From b05113a48a2031282b5f4e65b97407a7bc8438c1 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 19 Jun 2012 20:03:42 +0200 Subject: C++: Move Automatizer to C++ --- src/squelch/object_status.cc | 149 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src/squelch/object_status.cc (limited to 'src/squelch/object_status.cc') diff --git a/src/squelch/object_status.cc b/src/squelch/object_status.cc new file mode 100644 index 00000000..53d2055a --- /dev/null +++ b/src/squelch/object_status.cc @@ -0,0 +1,149 @@ +#include "tome/squelch/object_status_fwd.hpp" +#include "tome/squelch/object_status.hpp" + +#include "angband.h" + +namespace squelch { + +EnumStringMap &status_mapping() +{ + // TODO: This is quite ugly and leads to valgrind complaints + static auto m = new EnumStringMap { + { status_type::BAD, "bad" }, + { status_type::VERY_BAD, "very bad" }, + { status_type::AVERAGE, "average" }, + { status_type::GOOD, "good" }, + { status_type::VERY_GOOD, "very good" }, + { status_type::SPECIAL, "special" }, + { status_type::TERRIBLE, "terrible" }, + { status_type::NONE, "none" }, + { status_type::CHEST_EMPTY, "(empty chest)" }, + { status_type::CHEST_DISARMED, "(disarmed chest)" } }; + return *m; +} + +status_type object_status(object_type *o_ptr) +{ + if (!object_known_p(o_ptr)) + { + switch (o_ptr->sense) + { + case SENSE_CURSED: return status_type::BAD; + case SENSE_WORTHLESS: return status_type::VERY_BAD; + case SENSE_AVERAGE: return status_type::AVERAGE; + case SENSE_GOOD_LIGHT: return status_type::GOOD; + case SENSE_GOOD_HEAVY: return status_type::GOOD; + case SENSE_EXCELLENT: return status_type::VERY_GOOD; + case SENSE_SPECIAL: return status_type::SPECIAL; + case SENSE_TERRIBLE: return status_type::TERRIBLE; + default: return status_type::NONE; + } + } + else + { + s16b slot = wield_slot_ideal(o_ptr, TRUE); + + if (artifact_p(o_ptr)) + { + if (!(o_ptr->ident & IDENT_CURSED)) + { + return status_type::SPECIAL; + } + else + { + return status_type::TERRIBLE; + } + } + else if ((o_ptr->name2 > 0) || + (o_ptr->name2b > 0)) + { + if (!(o_ptr->ident & IDENT_CURSED)) + { + return status_type::VERY_GOOD; + } + else + { + return status_type::VERY_BAD; + } + } + else if ((slot == INVEN_WIELD) || + (slot == INVEN_BOW) || + (slot == INVEN_AMMO) || + (slot == INVEN_TOOL)) + { + if (o_ptr->to_h + o_ptr->to_d < 0) + { + return status_type::BAD; + } + else if (o_ptr->to_h + o_ptr->to_d > 0) + { + return status_type::GOOD; + } + else + { + return status_type::AVERAGE; + } + } + else if ((slot >= INVEN_BODY) && + (slot <= INVEN_FEET)) + { + if (o_ptr->to_a < 0) + { + return status_type::BAD; + } + else if (o_ptr->to_a > 0) + { + return status_type::GOOD; + } + else + { + return status_type::AVERAGE; + } + } + else if (slot == INVEN_RING) + { + if ((o_ptr->to_d + o_ptr->to_h < 0) || + (o_ptr->to_a < 0) || + (o_ptr->pval < 0)) + { + return status_type::BAD; + } + else + { + return status_type::AVERAGE; + } + } + else if (slot == INVEN_NECK) + { + if (o_ptr->pval < 0) + { + return status_type::BAD; + } + else + { + return status_type::AVERAGE; + } + } + else if (o_ptr->tval == TV_CHEST) + { + if (o_ptr->pval == 0) + { + return status_type::CHEST_EMPTY; + } + else if (o_ptr->pval < 0) + { + return status_type::CHEST_DISARMED; + } + else + { + return status_type::AVERAGE; + } + } + else + { + return status_type::AVERAGE; + } + } +} + +} // namespace -- cgit v1.2.3