1 /**
2  * \file obj-properties.h
3  * \brief definitions and functions for object flags and modifiers
4  *
5  * Copyright (c) 2014 Chris Carr, Nick McConnell
6  *
7  * This work is free software; you can redistribute it and/or modify it
8  * under the terms of either:
9  *
10  * a) the GNU General Public License as published by the Free Software
11  *    Foundation, version 2, or
12  *
13  * b) the "Angband licence":
14  *    This software may be copied and distributed for educational, research,
15  *    and not for profit purposes provided that this copyright and statement
16  *    are included in all such copies.  Other copyrights may also apply.
17  */
18 #ifndef INCLUDED_OBJPROPERTIES_H
19 #define INCLUDED_OBJPROPERTIES_H
20 
21 #include "z-file.h"
22 #include "z-bitflag.h"
23 
24 /**
25  * ------------------------------------------------------------------------
26  * Constants
27  * ------------------------------------------------------------------------ */
28 
29 /**
30  * The values for the "tval" field of various objects.
31  *
32  * This value is the primary means by which items are sorted in the
33  * player inventory, followed by "sval" and "cost".
34  */
35 enum
36 {
37 	#define TV(a, b, c) TV_##a,
38 	#include "list-tvals.h"
39 	#undef TV
40 
41 	TV_MAX
42 };
43 
44 /**
45  * The object flags
46  */
47 enum {
48 	OF_NONE,
49 	#define OF(a) OF_##a,
50     #include "list-object-flags.h"
51     #undef OF
52 };
53 
54 /**
55  * The object kind flags
56  */
57 enum {
58     #define KF(a, b) KF_##a,
59     #include "list-kind-flags.h"
60     #undef KF
61 };
62 
63 /**
64  * The object modifiers
65  */
66 enum {
67 	#define STAT(a) OBJ_MOD_##a,
68     #include "list-stats.h"
69     #undef STAT
70     #define OBJ_MOD(a) OBJ_MOD_##a,
71     #include "list-object-modifiers.h"
72     #undef OBJ_MOD
73 	OBJ_MOD_MAX
74 };
75 
76 /* Where the stats start in modifiers */
77 #define OBJ_MOD_MIN_STAT OBJ_MOD_STR
78 
79 /**
80  * The object flag types
81  */
82 enum object_flag_type {
83 	OFT_NONE = 0,	/* placeholder flag */
84 	OFT_SUST,		/* sustains a stat */
85 	OFT_PROT,		/* protection from an effect */
86 	OFT_MISC,		/* a good property, suitable for ego items */
87 	OFT_LIGHT,		/* applicable only to light sources */
88 	OFT_MELEE,		/* applicable only to melee weapons */
89 	OFT_BAD,		/* an undesirable flag */
90 	OFT_DIG,		/* applicable only to diggers */
91 	OFT_THROW,		/* applicable only to throwables */
92 
93 	OFT_MAX
94 };
95 
96 /**
97  * How object flags are IDd
98  */
99 enum object_flag_id {
100 	OFID_NONE = 0,		/* never shown */
101 	OFID_NORMAL,		/* normal ID on use */
102 	OFID_TIMED,			/* obvious after time */
103 	OFID_WIELD			/* obvious on wield */
104 };
105 
106 /**
107  * The object property types
108  */
109 enum obj_property_type {
110 	OBJ_PROPERTY_NONE = 0,
111 	OBJ_PROPERTY_STAT,
112 	OBJ_PROPERTY_MOD,
113 	OBJ_PROPERTY_FLAG,
114 	OBJ_PROPERTY_IGNORE,
115 	OBJ_PROPERTY_RESIST,
116 	OBJ_PROPERTY_VULN,
117 	OBJ_PROPERTY_IMM,
118 	OBJ_PROPERTY_MAX
119 };
120 
121 #define OF_SIZE                	FLAG_SIZE(OF_MAX)
122 
123 #define of_has(f, flag)        	flag_has_dbg(f, OF_SIZE, flag, #f, #flag)
124 #define of_next(f, flag)       	flag_next(f, OF_SIZE, flag)
125 #define of_count(f)             flag_count(f, OF_SIZE)
126 #define of_is_empty(f)         	flag_is_empty(f, OF_SIZE)
127 #define of_is_full(f)          	flag_is_full(f, OF_SIZE)
128 #define of_is_inter(f1, f2)    	flag_is_inter(f1, f2, OF_SIZE)
129 #define of_is_subset(f1, f2)   	flag_is_subset(f1, f2, OF_SIZE)
130 #define of_is_equal(f1, f2)    	flag_is_equal(f1, f2, OF_SIZE)
131 #define of_on(f, flag)         	flag_on_dbg(f, OF_SIZE, flag, #f, #flag)
132 #define of_off(f, flag)        	flag_off(f, OF_SIZE, flag)
133 #define of_wipe(f)             	flag_wipe(f, OF_SIZE)
134 #define of_setall(f)           	flag_setall(f, OF_SIZE)
135 #define of_negate(f)           	flag_negate(f, OF_SIZE)
136 #define of_copy(f1, f2)        	flag_copy(f1, f2, OF_SIZE)
137 #define of_union(f1, f2)       	flag_union(f1, f2, OF_SIZE)
138 #define of_inter(f1, f2)       	flag_inter(f1, f2, OF_SIZE)
139 #define of_diff(f1, f2)        	flag_diff(f1, f2, OF_SIZE)
140 
141 #define KF_SIZE                	FLAG_SIZE(KF_MAX)
142 
143 #define kf_has(f, flag)        	flag_has_dbg(f, KF_SIZE, flag, #f, #flag)
144 #define kf_next(f, flag)       	flag_next(f, KF_SIZE, flag)
145 #define kf_is_empty(f)         	flag_is_empty(f, KF_SIZE)
146 #define kf_is_full(f)          	flag_is_full(f, KF_SIZE)
147 #define kf_is_inter(f1, f2)    	flag_is_inter(f1, f2, KF_SIZE)
148 #define kf_is_subset(f1, f2)   	flag_is_subset(f1, f2, KF_SIZE)
149 #define kf_is_equal(f1, f2)    	flag_is_equal(f1, f2, KF_SIZE)
150 #define kf_on(f, flag)         	flag_on_dbg(f, KF_SIZE, flag, #f, #flag)
151 #define kf_off(f, flag)        	flag_off(f, KF_SIZE, flag)
152 #define kf_wipe(f)             	flag_wipe(f, KF_SIZE)
153 #define kf_setall(f)           	flag_setall(f, KF_SIZE)
154 #define kf_negate(f)           	flag_negate(f, KF_SIZE)
155 #define kf_copy(f1, f2)        	flag_copy(f1, f2, KF_SIZE)
156 #define kf_union(f1, f2)       	flag_union(f1, f2, KF_SIZE)
157 #define kf_inter(f1, f2)       	flag_inter(f1, f2, KF_SIZE)
158 #define kf_diff(f1, f2)        	flag_diff(f1, f2, KF_SIZE)
159 
160 
161 /**
162  * ------------------------------------------------------------------------
163  * Structures
164  * ------------------------------------------------------------------------ */
165 
166 /**
167  * The object property structure
168  */
169 struct obj_property {
170 	struct obj_property *next;
171 	int type;				/* type of property */
172 	int subtype;			/* subtype of property */
173 	int id_type;			/* how the property is identified (flags only?) */
174 	int index;				/* index of the property for its type */
175 	int power;				/* base power rating */
176 	int mult;				/* relative weight rating */
177 	int type_mult[TV_MAX];	/* relative weight rating specific to object type */
178 	char *name;				/* property name */
179 	char *adjective;		/* adjective for property */
180 	char *neg_adj;			/* adjective for negative of property */
181 	char *msg;				/* message on noticing property */
182 	char *desc;				/* extra text for object info */
183 };
184 
185 extern struct obj_property *obj_properties;
186 
187 /**
188  * ------------------------------------------------------------------------
189  * Functions
190  * ------------------------------------------------------------------------ */
191 struct obj_property *lookup_obj_property(int type, int index);
192 void create_obj_flag_mask(bitflag *f, int id, ...);
193 void flag_message(int flag, char *name);
194 int sustain_flag(int stat);
195 
196 #endif /* !INCLUDED_OBJPROPERTIES_H */
197