summaryrefslogtreecommitdiff
path: root/src/squelch/object_status.cc
blob: e020614fc516bff25ef4f84f03f47ec3bcc9058c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "tome/squelch/object_status_fwd.hpp"
#include "tome/squelch/object_status.hpp"

#include "../inventory.hpp"
#include "../object1.hpp"
#include "../object2.hpp"
#include "../object_type.hpp"
#include "../object_flag.hpp"
#include "../variable.hpp"

namespace squelch {

EnumStringMap<status_type> &status_mapping()
{
	// TODO: This is quite ugly and leads to valgrind complaints
	static auto m = new EnumStringMap<status_type> {
		{ 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" }
	};
	return *m;
}

status_type object_status(object_type *o_ptr)
{
	if (!object_known_p(o_ptr))
	{
		return status_type::NONE;
	}
	else
	{
		s16b slot = wield_slot_ideal(o_ptr, true);

		if (artifact_p(o_ptr))
		{
			if (!(o_ptr->art_flags & TR_CURSED))
			{
				return status_type::SPECIAL;
			}
			else
			{
				return status_type::TERRIBLE;
			}
		}
		else if ((o_ptr->name2 > 0) ||
			 (o_ptr->name2b > 0))
		{
			if (!(o_ptr->art_flags & TR_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
		{
			return status_type::AVERAGE;
		}
	}
}

} // namespace