OSDN Git Service

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