OSDN Git Service

[Refactor] have_flag() を has_flag() に改名. / Rename have_flag() to has_flag().
[hengbandforosx/hengbandosx.git] / src / object / object-value-calc.c
1 #include "object/object-value-calc.h"
2 #include "artifact/artifact-info.h"
3 #include "object-enchant/object-ego.h"
4 #include "object-enchant/tr-types.h"
5 #include "object-enchant/trc-types.h"
6 #include "object-hook/hook-checker.h"
7 #include "object-hook/hook-enchant.h"
8 #include "object/object-flags.h"
9 #include "object/object-kind.h"
10 #include "system/artifact-type-definition.h"
11 #include "util/bit-flags-calculator.h"
12
13 /*!
14  * @brief オブジェクトのフラグ類から価格を算出する /
15  * Return the value of the flags the object has...
16  * @param o_ptr フラグ価格を確認したいオブジェクトの構造体参照ポインタ
17  * @param plusses フラグに与える価格の基本重み
18  * @return オブジェクトのフラグ価格
19  */
20 PRICE flag_cost(player_type *player_ptr, object_type *o_ptr, int plusses)
21 {
22     PRICE total = 0;
23     BIT_FLAGS flgs[TR_FLAG_SIZE];
24     object_kind *k_ptr = &k_info[o_ptr->k_idx];
25     object_flags(player_ptr, o_ptr, flgs);
26
27     /*
28      * Exclude fixed flags of the base item.
29      * pval bonuses of base item will be treated later.
30      */
31     for (int i = 0; i < TR_FLAG_SIZE; i++)
32         flgs[i] &= ~(k_ptr->flags[i]);
33
34     if (object_is_fixed_artifact(o_ptr)) {
35         artifact_type *a_ptr = &a_info[o_ptr->name1];
36
37         for (int i = 0; i < TR_FLAG_SIZE; i++)
38             flgs[i] &= ~(a_ptr->flags[i]);
39     } else if (object_is_ego(o_ptr)) {
40         ego_item_type *e_ptr = &e_info[o_ptr->name2];
41
42         for (int i = 0; i < TR_FLAG_SIZE; i++)
43             flgs[i] &= ~(e_ptr->flags[i]);
44     }
45
46     /*
47      * Calucurate values of remaining flags
48      */
49     if (has_flag(flgs, TR_STR))
50         total += (1500 * plusses);
51     if (has_flag(flgs, TR_INT))
52         total += (1500 * plusses);
53     if (has_flag(flgs, TR_WIS))
54         total += (1500 * plusses);
55     if (has_flag(flgs, TR_DEX))
56         total += (1500 * plusses);
57     if (has_flag(flgs, TR_CON))
58         total += (1500 * plusses);
59     if (has_flag(flgs, TR_CHR))
60         total += (750 * plusses);
61     if (has_flag(flgs, TR_MAGIC_MASTERY))
62         total += (600 * plusses);
63     if (has_flag(flgs, TR_STEALTH))
64         total += (250 * plusses);
65     if (has_flag(flgs, TR_SEARCH))
66         total += (100 * plusses);
67     if (has_flag(flgs, TR_INFRA))
68         total += (150 * plusses);
69     if (has_flag(flgs, TR_TUNNEL))
70         total += (175 * plusses);
71     if ((has_flag(flgs, TR_SPEED)) && (plusses > 0))
72         total += (10000 + (2500 * plusses));
73     if ((has_flag(flgs, TR_BLOWS)) && (plusses > 0))
74         total += (10000 + (2500 * plusses));
75
76     PRICE tmp_cost = 0;
77     int count = 0;
78     if (has_flag(flgs, TR_CHAOTIC)) {
79         total += 5000;
80         count++;
81     }
82     if (has_flag(flgs, TR_VAMPIRIC)) {
83         total += 6500;
84         count++;
85     }
86     if (has_flag(flgs, TR_FORCE_WEAPON)) {
87         tmp_cost += 2500;
88         count++;
89     }
90     if (has_flag(flgs, TR_KILL_ANIMAL)) {
91         tmp_cost += 2800;
92         count++;
93     } else if (has_flag(flgs, TR_SLAY_ANIMAL)) {
94         tmp_cost += 1800;
95         count++;
96     }
97     if (has_flag(flgs, TR_KILL_EVIL)) {
98         tmp_cost += 3300;
99         count++;
100     } else if (has_flag(flgs, TR_SLAY_EVIL)) {
101         tmp_cost += 2300;
102         count++;
103     }
104     if (has_flag(flgs, TR_KILL_HUMAN)) {
105         tmp_cost += 2800;
106         count++;
107     } else if (has_flag(flgs, TR_SLAY_HUMAN)) {
108         tmp_cost += 1800;
109         count++;
110     }
111     if (has_flag(flgs, TR_KILL_UNDEAD)) {
112         tmp_cost += 2800;
113         count++;
114     } else if (has_flag(flgs, TR_SLAY_UNDEAD)) {
115         tmp_cost += 1800;
116         count++;
117     }
118     if (has_flag(flgs, TR_KILL_DEMON)) {
119         tmp_cost += 2800;
120         count++;
121     } else if (has_flag(flgs, TR_SLAY_DEMON)) {
122         tmp_cost += 1800;
123         count++;
124     }
125     if (has_flag(flgs, TR_KILL_ORC)) {
126         tmp_cost += 2500;
127         count++;
128     } else if (has_flag(flgs, TR_SLAY_ORC)) {
129         tmp_cost += 1500;
130         count++;
131     }
132     if (has_flag(flgs, TR_KILL_TROLL)) {
133         tmp_cost += 2800;
134         count++;
135     } else if (has_flag(flgs, TR_SLAY_TROLL)) {
136         tmp_cost += 1800;
137         count++;
138     }
139     if (has_flag(flgs, TR_KILL_GIANT)) {
140         tmp_cost += 2800;
141         count++;
142     } else if (has_flag(flgs, TR_SLAY_GIANT)) {
143         tmp_cost += 1800;
144         count++;
145     }
146     if (has_flag(flgs, TR_KILL_DRAGON)) {
147         tmp_cost += 2800;
148         count++;
149     } else if (has_flag(flgs, TR_SLAY_DRAGON)) {
150         tmp_cost += 1800;
151         count++;
152     }
153
154     if (has_flag(flgs, TR_VORPAL)) {
155         tmp_cost += 2500;
156         count++;
157     }
158     if (has_flag(flgs, TR_IMPACT)) {
159         tmp_cost += 2500;
160         count++;
161     }
162     if (has_flag(flgs, TR_BRAND_POIS)) {
163         tmp_cost += 3800;
164         count++;
165     }
166     if (has_flag(flgs, TR_BRAND_ACID)) {
167         tmp_cost += 3800;
168         count++;
169     }
170     if (has_flag(flgs, TR_BRAND_ELEC)) {
171         tmp_cost += 3800;
172         count++;
173     }
174     if (has_flag(flgs, TR_BRAND_FIRE)) {
175         tmp_cost += 2500;
176         count++;
177     }
178     if (has_flag(flgs, TR_BRAND_COLD)) {
179         tmp_cost += 2500;
180         count++;
181     }
182     total += (tmp_cost * count);
183
184     if (has_flag(flgs, TR_SUST_STR))
185         total += 850;
186     if (has_flag(flgs, TR_SUST_INT))
187         total += 850;
188     if (has_flag(flgs, TR_SUST_WIS))
189         total += 850;
190     if (has_flag(flgs, TR_SUST_DEX))
191         total += 850;
192     if (has_flag(flgs, TR_SUST_CON))
193         total += 850;
194     if (has_flag(flgs, TR_SUST_CHR))
195         total += 250;
196     if (has_flag(flgs, TR_RIDING))
197         total += 0;
198     if (has_flag(flgs, TR_EASY_SPELL))
199         total += 1500;
200     if (has_flag(flgs, TR_THROW))
201         total += 5000;
202     if (has_flag(flgs, TR_FREE_ACT))
203         total += 4500;
204     if (has_flag(flgs, TR_HOLD_EXP))
205         total += 8500;
206
207     tmp_cost = 0;
208     count = 0;
209     if (has_flag(flgs, TR_IM_ACID)) {
210         tmp_cost += 15000;
211         count += 2;
212     }
213     if (has_flag(flgs, TR_IM_ELEC)) {
214         tmp_cost += 15000;
215         count += 2;
216     }
217     if (has_flag(flgs, TR_IM_FIRE)) {
218         tmp_cost += 15000;
219         count += 2;
220     }
221     if (has_flag(flgs, TR_IM_COLD)) {
222         tmp_cost += 15000;
223         count += 2;
224     }
225     if (has_flag(flgs, TR_REFLECT)) {
226         tmp_cost += 5000;
227         count += 2;
228     }
229     if (has_flag(flgs, TR_RES_ACID)) {
230         tmp_cost += 500;
231         count++;
232     }
233     if (has_flag(flgs, TR_RES_ELEC)) {
234         tmp_cost += 500;
235         count++;
236     }
237     if (has_flag(flgs, TR_RES_FIRE)) {
238         tmp_cost += 500;
239         count++;
240     }
241     if (has_flag(flgs, TR_RES_COLD)) {
242         tmp_cost += 500;
243         count++;
244     }
245     if (has_flag(flgs, TR_RES_POIS)) {
246         tmp_cost += 1000;
247         count += 2;
248     }
249     if (has_flag(flgs, TR_RES_FEAR)) {
250         tmp_cost += 1000;
251         count += 2;
252     }
253     if (has_flag(flgs, TR_RES_LITE)) {
254         tmp_cost += 800;
255         count += 2;
256     }
257     if (has_flag(flgs, TR_RES_DARK)) {
258         tmp_cost += 800;
259         count += 2;
260     }
261     if (has_flag(flgs, TR_RES_BLIND)) {
262         tmp_cost += 900;
263         count += 2;
264     }
265     if (has_flag(flgs, TR_RES_CONF)) {
266         tmp_cost += 900;
267         count += 2;
268     }
269     if (has_flag(flgs, TR_RES_SOUND)) {
270         tmp_cost += 900;
271         count += 2;
272     }
273     if (has_flag(flgs, TR_RES_SHARDS)) {
274         tmp_cost += 900;
275         count += 2;
276     }
277     if (has_flag(flgs, TR_RES_NETHER)) {
278         tmp_cost += 900;
279         count += 2;
280     }
281     if (has_flag(flgs, TR_RES_NEXUS)) {
282         tmp_cost += 900;
283         count += 2;
284     }
285     if (has_flag(flgs, TR_RES_CHAOS)) {
286         tmp_cost += 1000;
287         count += 2;
288     }
289     if (has_flag(flgs, TR_RES_DISEN)) {
290         tmp_cost += 2000;
291         count += 2;
292     }
293     total += (tmp_cost * count);
294
295     if (has_flag(flgs, TR_SH_FIRE))
296         total += 5000;
297     if (has_flag(flgs, TR_SH_ELEC))
298         total += 5000;
299     if (has_flag(flgs, TR_SH_COLD))
300         total += 5000;
301     if (has_flag(flgs, TR_NO_TELE))
302         total -= 10000;
303     if (has_flag(flgs, TR_NO_MAGIC))
304         total += 2500;
305     if (has_flag(flgs, TR_TY_CURSE))
306         total -= 15000;
307     if (has_flag(flgs, TR_HIDE_TYPE))
308         total += 0;
309     if (has_flag(flgs, TR_SHOW_MODS))
310         total += 0;
311     if (has_flag(flgs, TR_LEVITATION))
312         total += 1250;
313     if (has_flag(flgs, TR_LITE_1))
314         total += 1500;
315     if (has_flag(flgs, TR_LITE_2))
316         total += 2500;
317     if (has_flag(flgs, TR_LITE_3))
318         total += 4000;
319     if (has_flag(flgs, TR_LITE_M1))
320         total -= 1500;
321     if (has_flag(flgs, TR_LITE_M2))
322         total -= 2500;
323     if (has_flag(flgs, TR_LITE_M3))
324         total -= 4000;
325     if (has_flag(flgs, TR_SEE_INVIS))
326         total += 2000;
327     if (has_flag(flgs, TR_TELEPATHY))
328         total += 20000;
329     if (has_flag(flgs, TR_ESP_ANIMAL))
330         total += 1000;
331     if (has_flag(flgs, TR_ESP_UNDEAD))
332         total += 1000;
333     if (has_flag(flgs, TR_ESP_DEMON))
334         total += 1000;
335     if (has_flag(flgs, TR_ESP_ORC))
336         total += 1000;
337     if (has_flag(flgs, TR_ESP_TROLL))
338         total += 1000;
339     if (has_flag(flgs, TR_ESP_GIANT))
340         total += 1000;
341     if (has_flag(flgs, TR_ESP_DRAGON))
342         total += 1000;
343     if (has_flag(flgs, TR_ESP_HUMAN))
344         total += 1000;
345     if (has_flag(flgs, TR_ESP_EVIL))
346         total += 15000;
347     if (has_flag(flgs, TR_ESP_GOOD))
348         total += 2000;
349     if (has_flag(flgs, TR_ESP_NONLIVING))
350         total += 2000;
351     if (has_flag(flgs, TR_ESP_UNIQUE))
352         total += 10000;
353     if (has_flag(flgs, TR_SLOW_DIGEST))
354         total += 750;
355     if (has_flag(flgs, TR_REGEN))
356         total += 2500;
357     if (has_flag(flgs, TR_WARNING))
358         total += 2000;
359     if (has_flag(flgs, TR_DEC_MANA))
360         total += 10000;
361     if (has_flag(flgs, TR_XTRA_MIGHT))
362         total += 2250;
363     if (has_flag(flgs, TR_XTRA_SHOTS))
364         total += 10000;
365     if (has_flag(flgs, TR_IGNORE_ACID))
366         total += 100;
367     if (has_flag(flgs, TR_IGNORE_ELEC))
368         total += 100;
369     if (has_flag(flgs, TR_IGNORE_FIRE))
370         total += 100;
371     if (has_flag(flgs, TR_IGNORE_COLD))
372         total += 100;
373     if (has_flag(flgs, TR_ACTIVATE))
374         total += 100;
375     if (has_flag(flgs, TR_DRAIN_EXP))
376         total -= 12500;
377     if (has_flag(flgs, TR_DRAIN_HP))
378         total -= 12500;
379     if (has_flag(flgs, TR_DRAIN_MANA))
380         total -= 12500;
381     if (has_flag(flgs, TR_CALL_ANIMAL))
382         total -= 12500;
383     if (has_flag(flgs, TR_CALL_DEMON))
384         total -= 10000;
385     if (has_flag(flgs, TR_CALL_DRAGON))
386         total -= 10000;
387     if (has_flag(flgs, TR_CALL_UNDEAD))
388         total -= 10000;
389     if (has_flag(flgs, TR_COWARDICE))
390         total -= 5000;
391     if (has_flag(flgs, TR_LOW_MELEE))
392         total -= 5000;
393     if (has_flag(flgs, TR_LOW_AC))
394         total -= 5000;
395     if (has_flag(flgs, TR_LOW_MAGIC))
396         total -= 15000;
397     if (has_flag(flgs, TR_FAST_DIGEST))
398         total -= 10000;
399     if (has_flag(flgs, TR_SLOW_REGEN))
400         total -= 10000;
401     if (has_flag(flgs, TR_TELEPORT)) {
402         if (object_is_cursed(o_ptr))
403             total -= 7500;
404         else
405             total += 250;
406     }
407
408     if (has_flag(flgs, TR_AGGRAVATE))
409         total -= 10000;
410     if (has_flag(flgs, TR_BLESSED))
411         total += 750;
412     if (o_ptr->curse_flags & TR_ADD_L_CURSE)
413         total -= 5000;
414     if (o_ptr->curse_flags & TR_ADD_H_CURSE)
415         total -= 12500;
416     if (o_ptr->curse_flags & TRC_CURSED)
417         total -= 5000;
418     if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
419         total -= 12500;
420     if (o_ptr->curse_flags & TRC_PERMA_CURSE)
421         total -= 15000;
422
423     /* Also, give some extra for activatable powers... */
424     if (o_ptr->art_name && (has_flag(o_ptr->art_flags, TR_ACTIVATE))) {
425         const activation_type *const act_ptr = find_activation_info(player_ptr, o_ptr);
426         if (act_ptr) {
427             total += act_ptr->value;
428         }
429     }
430
431     return total;
432 }