OSDN Git Service

[Refactor] #2617 a_info を、FixedArtifactType をキーとするmapに変更した
[hengbandforosx/hengbandosx.git] / src / object / object-value-calc.cpp
1 #include "object/object-value-calc.h"
2 #include "artifact/artifact-info.h"
3 #include "object-enchant/activation-info-table.h"
4 #include "object-enchant/object-ego.h"
5 #include "object-enchant/tr-types.h"
6 #include "object-enchant/trc-types.h"
7 #include "object/object-flags.h"
8 #include "object/object-kind.h"
9 #include "system/artifact-type-definition.h"
10 #include "system/object-type-definition.h"
11 #include "system/player-type-definition.h"
12 #include "util/bit-flags-calculator.h"
13
14 /*!
15  * @brief オブジェクトのフラグ類から価格を算出する /
16  * Return the value of the flags the object has...
17  * @param o_ptr フラグ価格を確認したいオブジェクトの構造体参照ポインタ
18  * @param plusses フラグに与える価格の基本重み
19  * @return オブジェクトのフラグ価格
20  */
21 PRICE flag_cost(const ObjectType *o_ptr, int plusses)
22 {
23     PRICE total = 0;
24     auto *k_ptr = &k_info[o_ptr->k_idx];
25     auto flgs = object_flags(o_ptr);
26
27     /*
28      * Exclude fixed flags of the base item.
29      * pval bonuses of base item will be treated later.
30      */
31     flgs.reset(k_ptr->flags);
32
33     if (o_ptr->is_fixed_artifact()) {
34         const auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
35         flgs.reset(a_ref.flags);
36     } else if (o_ptr->is_ego()) {
37         const auto &e_ref = e_info[o_ptr->ego_idx];
38         flgs.reset(e_ref.flags);
39     }
40
41     /*
42      * Calucurate values of remaining flags
43      */
44     if (flgs.has(TR_STR)) {
45         total += (1500 * plusses);
46     }
47     if (flgs.has(TR_INT)) {
48         total += (1500 * plusses);
49     }
50     if (flgs.has(TR_WIS)) {
51         total += (1500 * plusses);
52     }
53     if (flgs.has(TR_DEX)) {
54         total += (1500 * plusses);
55     }
56     if (flgs.has(TR_CON)) {
57         total += (1500 * plusses);
58     }
59     if (flgs.has(TR_CHR)) {
60         total += (750 * plusses);
61     }
62     if (flgs.has(TR_MAGIC_MASTERY)) {
63         total += (600 * plusses);
64     }
65     if (flgs.has(TR_STEALTH)) {
66         total += (250 * plusses);
67     }
68     if (flgs.has(TR_SEARCH)) {
69         total += (100 * plusses);
70     }
71     if (flgs.has(TR_INFRA)) {
72         total += (150 * plusses);
73     }
74     if (flgs.has(TR_TUNNEL)) {
75         total += (175 * plusses);
76     }
77     if ((flgs.has(TR_SPEED)) && (plusses > 0)) {
78         total += (10000 + (2500 * plusses));
79     }
80     if ((flgs.has(TR_BLOWS)) && (plusses > 0)) {
81         total += (10000 + (2500 * plusses));
82     }
83
84     PRICE tmp_cost = 0;
85     int count = 0;
86     if (flgs.has(TR_CHAOTIC)) {
87         total += 5000;
88         count++;
89     }
90     if (flgs.has(TR_BRAND_MAGIC)) {
91         total += 1000;
92         count++;
93     }
94     if (flgs.has(TR_VAMPIRIC)) {
95         total += 6500;
96         count++;
97     }
98     if (flgs.has(TR_FORCE_WEAPON)) {
99         tmp_cost += 2500;
100         count++;
101     }
102     if (flgs.has(TR_KILL_ANIMAL)) {
103         tmp_cost += 2800;
104         count++;
105     } else if (flgs.has(TR_SLAY_ANIMAL)) {
106         tmp_cost += 1800;
107         count++;
108     }
109     if (flgs.has(TR_KILL_EVIL)) {
110         tmp_cost += 3300;
111         count++;
112     } else if (flgs.has(TR_SLAY_EVIL)) {
113         tmp_cost += 2300;
114         count++;
115     }
116     if (flgs.has(TR_KILL_GOOD)) {
117         tmp_cost += 2800;
118         count++;
119     } else if (flgs.has(TR_SLAY_GOOD)) {
120         tmp_cost += 1800;
121         count++;
122     }
123     if (flgs.has(TR_KILL_HUMAN)) {
124         tmp_cost += 2800;
125         count++;
126     } else if (flgs.has(TR_SLAY_HUMAN)) {
127         tmp_cost += 1800;
128         count++;
129     }
130     if (flgs.has(TR_KILL_UNDEAD)) {
131         tmp_cost += 2800;
132         count++;
133     } else if (flgs.has(TR_SLAY_UNDEAD)) {
134         tmp_cost += 1800;
135         count++;
136     }
137     if (flgs.has(TR_KILL_DEMON)) {
138         tmp_cost += 2800;
139         count++;
140     } else if (flgs.has(TR_SLAY_DEMON)) {
141         tmp_cost += 1800;
142         count++;
143     }
144     if (flgs.has(TR_KILL_ORC)) {
145         tmp_cost += 2500;
146         count++;
147     } else if (flgs.has(TR_SLAY_ORC)) {
148         tmp_cost += 1500;
149         count++;
150     }
151     if (flgs.has(TR_KILL_TROLL)) {
152         tmp_cost += 2800;
153         count++;
154     } else if (flgs.has(TR_SLAY_TROLL)) {
155         tmp_cost += 1800;
156         count++;
157     }
158     if (flgs.has(TR_KILL_GIANT)) {
159         tmp_cost += 2800;
160         count++;
161     } else if (flgs.has(TR_SLAY_GIANT)) {
162         tmp_cost += 1800;
163         count++;
164     }
165     if (flgs.has(TR_KILL_DRAGON)) {
166         tmp_cost += 2800;
167         count++;
168     } else if (flgs.has(TR_SLAY_DRAGON)) {
169         tmp_cost += 1800;
170         count++;
171     }
172
173     if (flgs.has(TR_VORPAL)) {
174         tmp_cost += 2500;
175         count++;
176     }
177     if (flgs.has(TR_IMPACT)) {
178         tmp_cost += 2500;
179         count++;
180     }
181     if (flgs.has(TR_EARTHQUAKE)) {
182         tmp_cost += 2500;
183         count++;
184     }
185     if (flgs.has(TR_BRAND_POIS)) {
186         tmp_cost += 3800;
187         count++;
188     }
189     if (flgs.has(TR_BRAND_ACID)) {
190         tmp_cost += 3800;
191         count++;
192     }
193     if (flgs.has(TR_BRAND_ELEC)) {
194         tmp_cost += 3800;
195         count++;
196     }
197     if (flgs.has(TR_BRAND_FIRE)) {
198         tmp_cost += 2500;
199         count++;
200     }
201     if (flgs.has(TR_BRAND_COLD)) {
202         tmp_cost += 2500;
203         count++;
204     }
205     total += (tmp_cost * count);
206
207     if (flgs.has(TR_SUST_STR)) {
208         total += 850;
209     }
210     if (flgs.has(TR_SUST_INT)) {
211         total += 850;
212     }
213     if (flgs.has(TR_SUST_WIS)) {
214         total += 850;
215     }
216     if (flgs.has(TR_SUST_DEX)) {
217         total += 850;
218     }
219     if (flgs.has(TR_SUST_CON)) {
220         total += 850;
221     }
222     if (flgs.has(TR_SUST_CHR)) {
223         total += 250;
224     }
225     if (flgs.has(TR_RIDING)) {
226         total += 0;
227     }
228     if (flgs.has(TR_EASY_SPELL)) {
229         total += 1500;
230     }
231     if (flgs.has(TR_THROW)) {
232         total += 5000;
233     }
234     if (flgs.has(TR_FREE_ACT)) {
235         total += 4500;
236     }
237     if (flgs.has(TR_HOLD_EXP)) {
238         total += 8500;
239     }
240
241     tmp_cost = 0;
242     count = 0;
243     if (flgs.has(TR_IM_ACID)) {
244         tmp_cost += 15000;
245         count += 2;
246     }
247     if (flgs.has(TR_IM_ELEC)) {
248         tmp_cost += 15000;
249         count += 2;
250     }
251     if (flgs.has(TR_IM_FIRE)) {
252         tmp_cost += 15000;
253         count += 2;
254     }
255     if (flgs.has(TR_IM_COLD)) {
256         tmp_cost += 15000;
257         count += 2;
258     }
259     if (flgs.has(TR_REFLECT)) {
260         tmp_cost += 5000;
261         count += 2;
262     }
263     if (flgs.has(TR_RES_ACID)) {
264         tmp_cost += 500;
265         count++;
266     }
267     if (flgs.has(TR_RES_ELEC)) {
268         tmp_cost += 500;
269         count++;
270     }
271     if (flgs.has(TR_RES_FIRE)) {
272         tmp_cost += 500;
273         count++;
274     }
275     if (flgs.has(TR_RES_COLD)) {
276         tmp_cost += 500;
277         count++;
278     }
279     if (flgs.has(TR_RES_POIS)) {
280         tmp_cost += 1000;
281         count += 2;
282     }
283     if (flgs.has(TR_RES_FEAR)) {
284         tmp_cost += 1000;
285         count += 2;
286     }
287     if (flgs.has(TR_RES_LITE)) {
288         tmp_cost += 800;
289         count += 2;
290     }
291     if (flgs.has(TR_RES_DARK)) {
292         tmp_cost += 800;
293         count += 2;
294     }
295     if (flgs.has(TR_RES_BLIND)) {
296         tmp_cost += 900;
297         count += 2;
298     }
299     if (flgs.has(TR_RES_CONF)) {
300         tmp_cost += 900;
301         count += 2;
302     }
303     if (flgs.has(TR_RES_SOUND)) {
304         tmp_cost += 900;
305         count += 2;
306     }
307     if (flgs.has(TR_RES_SHARDS)) {
308         tmp_cost += 900;
309         count += 2;
310     }
311     if (flgs.has(TR_RES_NETHER)) {
312         tmp_cost += 900;
313         count += 2;
314     }
315     if (flgs.has(TR_RES_NEXUS)) {
316         tmp_cost += 900;
317         count += 2;
318     }
319     if (flgs.has(TR_RES_CHAOS)) {
320         tmp_cost += 1000;
321         count += 2;
322     }
323     if (flgs.has(TR_RES_DISEN)) {
324         tmp_cost += 2000;
325         count += 2;
326     }
327     if (flgs.has(TR_RES_TIME)) {
328         tmp_cost += 2000;
329         count += 2;
330     }
331     if (flgs.has(TR_RES_WATER)) {
332         tmp_cost += 2000;
333         count += 2;
334     }
335     total += (tmp_cost * count);
336
337     if (flgs.has(TR_RES_CURSE)) {
338         total += 7500;
339     }
340     if (flgs.has(TR_SH_FIRE)) {
341         total += 5000;
342     }
343     if (flgs.has(TR_SH_ELEC)) {
344         total += 5000;
345     }
346     if (flgs.has(TR_SH_COLD)) {
347         total += 5000;
348     }
349     if (flgs.has(TR_NO_TELE)) {
350         total -= 10000;
351     }
352     if (flgs.has(TR_NO_MAGIC)) {
353         total += 2500;
354     }
355     if (flgs.has(TR_TY_CURSE)) {
356         total -= 15000;
357     }
358     if (flgs.has(TR_HIDE_TYPE)) {
359         total += 0;
360     }
361     if (flgs.has(TR_SHOW_MODS)) {
362         total += 0;
363     }
364     if (flgs.has(TR_LEVITATION)) {
365         total += 1250;
366     }
367     if (flgs.has(TR_LITE_1)) {
368         total += 1500;
369     }
370     if (flgs.has(TR_LITE_2)) {
371         total += 2500;
372     }
373     if (flgs.has(TR_LITE_3)) {
374         total += 4000;
375     }
376     if (flgs.has(TR_LITE_M1)) {
377         total -= 1500;
378     }
379     if (flgs.has(TR_LITE_M2)) {
380         total -= 2500;
381     }
382     if (flgs.has(TR_LITE_M3)) {
383         total -= 4000;
384     }
385     if (flgs.has(TR_SEE_INVIS)) {
386         total += 2000;
387     }
388     if (flgs.has(TR_TELEPATHY)) {
389         total += 20000;
390     }
391     if (flgs.has(TR_ESP_ANIMAL)) {
392         total += 1000;
393     }
394     if (flgs.has(TR_ESP_UNDEAD)) {
395         total += 1000;
396     }
397     if (flgs.has(TR_ESP_DEMON)) {
398         total += 1000;
399     }
400     if (flgs.has(TR_ESP_ORC)) {
401         total += 1000;
402     }
403     if (flgs.has(TR_ESP_TROLL)) {
404         total += 1000;
405     }
406     if (flgs.has(TR_ESP_GIANT)) {
407         total += 1000;
408     }
409     if (flgs.has(TR_ESP_DRAGON)) {
410         total += 1000;
411     }
412     if (flgs.has(TR_ESP_HUMAN)) {
413         total += 1000;
414     }
415     if (flgs.has(TR_ESP_EVIL)) {
416         total += 15000;
417     }
418     if (flgs.has(TR_ESP_GOOD)) {
419         total += 2000;
420     }
421     if (flgs.has(TR_ESP_NONLIVING)) {
422         total += 2000;
423     }
424     if (flgs.has(TR_ESP_UNIQUE)) {
425         total += 10000;
426     }
427     if (flgs.has(TR_SLOW_DIGEST)) {
428         total += 750;
429     }
430     if (flgs.has(TR_REGEN)) {
431         total += 2500;
432     }
433     if (flgs.has(TR_WARNING)) {
434         total += 2000;
435     }
436     if (flgs.has(TR_DEC_MANA)) {
437         total += 10000;
438     }
439     if (flgs.has(TR_XTRA_MIGHT)) {
440         total += 2250;
441     }
442     if (flgs.has(TR_XTRA_SHOTS)) {
443         total += 10000;
444     }
445     if (flgs.has(TR_IGNORE_ACID)) {
446         total += 100;
447     }
448     if (flgs.has(TR_IGNORE_ELEC)) {
449         total += 100;
450     }
451     if (flgs.has(TR_IGNORE_FIRE)) {
452         total += 100;
453     }
454     if (flgs.has(TR_IGNORE_COLD)) {
455         total += 100;
456     }
457     if (flgs.has(TR_ACTIVATE)) {
458         total += 100;
459     }
460     if (flgs.has(TR_DRAIN_EXP)) {
461         total -= 12500;
462     }
463     if (flgs.has(TR_DRAIN_HP)) {
464         total -= 12500;
465     }
466     if (flgs.has(TR_DRAIN_MANA)) {
467         total -= 12500;
468     }
469     if (flgs.has(TR_CALL_ANIMAL)) {
470         total -= 12500;
471     }
472     if (flgs.has(TR_CALL_DEMON)) {
473         total -= 10000;
474     }
475     if (flgs.has(TR_CALL_DRAGON)) {
476         total -= 10000;
477     }
478     if (flgs.has(TR_CALL_UNDEAD)) {
479         total -= 10000;
480     }
481     if (flgs.has(TR_COWARDICE)) {
482         total -= 5000;
483     }
484     if (flgs.has(TR_LOW_MELEE)) {
485         total -= 5000;
486     }
487     if (flgs.has(TR_LOW_AC)) {
488         total -= 5000;
489     }
490     if (flgs.has(TR_HARD_SPELL)) {
491         total -= 15000;
492     }
493     if (flgs.has(TR_FAST_DIGEST)) {
494         total -= 10000;
495     }
496     if (flgs.has(TR_SLOW_REGEN)) {
497         total -= 10000;
498     }
499     if (flgs.has(TR_TELEPORT)) {
500         if (o_ptr->is_cursed()) {
501             total -= 7500;
502         } else {
503             total += 250;
504         }
505     }
506     if (flgs.has(TR_VUL_CURSE)) {
507         total -= 7500;
508     }
509
510     if (flgs.has(TR_AGGRAVATE)) {
511         total -= 10000;
512     }
513     if (flgs.has(TR_BLESSED)) {
514         total += 750;
515     }
516     if (o_ptr->curse_flags.has(CurseTraitType::ADD_L_CURSE)) {
517         total -= 5000;
518     }
519     if (o_ptr->curse_flags.has(CurseTraitType::ADD_H_CURSE)) {
520         total -= 12500;
521     }
522     if (o_ptr->curse_flags.has(CurseTraitType::CURSED)) {
523         total -= 5000;
524     }
525     if (o_ptr->curse_flags.has(CurseTraitType::HEAVY_CURSE)) {
526         total -= 12500;
527     }
528     if (o_ptr->curse_flags.has(CurseTraitType::PERSISTENT_CURSE)) {
529         total -= 12500;
530     }
531     if (o_ptr->curse_flags.has(CurseTraitType::PERMA_CURSE)) {
532         total -= 15000;
533     }
534
535     /* Also, give some extra for activatable powers... */
536     if (o_ptr->art_name && (o_ptr->art_flags.has(TR_ACTIVATE))) {
537         auto act_ptr = find_activation_info(o_ptr);
538         if (act_ptr.has_value()) {
539             total += act_ptr.value()->value;
540         }
541     }
542
543     return total;
544 }