1 #include "artifact/random-art-resistance.h"
2 #include "artifact/random-art-bias-types.h"
3 #include "object-enchant/tr-types.h"
4 #include "system/object-type-definition.h"
5 #include "util/bit-flags-calculator.h"
7 static bool random_art_resistance_acid(object_type *o_ptr)
9 if (has_flag(o_ptr->art_flags, TR_RES_ACID))
12 add_flag(o_ptr->art_flags, TR_RES_ACID);
16 static bool random_art_immunity_acid(object_type *o_ptr)
18 if (!one_in_(BIAS_LUCK) || has_flag(o_ptr->art_flags, TR_IM_ACID))
21 add_flag(o_ptr->art_flags, TR_IM_ACID);
25 remove_flag(o_ptr->art_flags, TR_IM_ELEC);
26 remove_flag(o_ptr->art_flags, TR_IM_COLD);
27 remove_flag(o_ptr->art_flags, TR_IM_FIRE);
31 static bool random_art_resistance_elec(object_type *o_ptr)
33 if (has_flag(o_ptr->art_flags, TR_RES_ELEC))
36 add_flag(o_ptr->art_flags, TR_RES_ELEC);
40 static bool random_art_aura_elec(object_type *o_ptr)
42 if ((o_ptr->tval < TV_CLOAK) || (o_ptr->tval > TV_HARD_ARMOR) || has_flag(o_ptr->art_flags, TR_SH_ELEC))
45 add_flag(o_ptr->art_flags, TR_SH_ELEC);
49 static bool random_art_immunity_elec(object_type *o_ptr)
51 if (!one_in_(BIAS_LUCK) || has_flag(o_ptr->art_flags, TR_IM_ELEC))
54 add_flag(o_ptr->art_flags, TR_IM_ELEC);
58 remove_flag(o_ptr->art_flags, TR_IM_ACID);
59 remove_flag(o_ptr->art_flags, TR_IM_COLD);
60 remove_flag(o_ptr->art_flags, TR_IM_FIRE);
64 static bool random_art_resistance_fire(object_type *o_ptr)
66 if (has_flag(o_ptr->art_flags, TR_RES_FIRE))
69 add_flag(o_ptr->art_flags, TR_RES_FIRE);
73 static bool random_art_aura_fire(object_type *o_ptr)
75 if ((o_ptr->tval < TV_CLOAK) || (o_ptr->tval > TV_HARD_ARMOR) || has_flag(o_ptr->art_flags, TR_SH_FIRE))
78 add_flag(o_ptr->art_flags, TR_SH_FIRE);
82 static bool random_art_immunity_fire(object_type *o_ptr)
84 if (!one_in_(BIAS_LUCK) || has_flag(o_ptr->art_flags, TR_IM_FIRE))
87 add_flag(o_ptr->art_flags, TR_IM_FIRE);
91 remove_flag(o_ptr->art_flags, TR_IM_ELEC);
92 remove_flag(o_ptr->art_flags, TR_IM_COLD);
93 remove_flag(o_ptr->art_flags, TR_IM_ACID);
97 static bool random_art_resistance_cold(object_type *o_ptr)
99 if (has_flag(o_ptr->art_flags, TR_RES_COLD))
102 add_flag(o_ptr->art_flags, TR_RES_COLD);
106 static bool random_art_aura_cold(object_type *o_ptr)
108 if ((o_ptr->tval < TV_CLOAK) || (o_ptr->tval > TV_HARD_ARMOR) || has_flag(o_ptr->art_flags, TR_SH_COLD))
111 add_flag(o_ptr->art_flags, TR_SH_COLD);
115 static bool random_art_immunity_cold(object_type *o_ptr)
117 if (!one_in_(BIAS_LUCK) || has_flag(o_ptr->art_flags, TR_IM_COLD))
120 add_flag(o_ptr->art_flags, TR_IM_COLD);
121 if (one_in_(IM_LUCK))
124 remove_flag(o_ptr->art_flags, TR_IM_ELEC);
125 remove_flag(o_ptr->art_flags, TR_IM_COLD);
126 remove_flag(o_ptr->art_flags, TR_IM_ACID);
130 static bool random_art_resistance_pois(object_type *o_ptr)
132 if (has_flag(o_ptr->art_flags, TR_RES_POIS))
135 add_flag(o_ptr->art_flags, TR_RES_POIS);
139 static bool random_art_resistance_fear(object_type *o_ptr)
141 if (one_in_(3) || has_flag(o_ptr->art_flags, TR_RES_FEAR))
144 add_flag(o_ptr->art_flags, TR_RES_FEAR);
148 static bool random_art_resistance_no_magic(object_type *o_ptr)
150 if (!one_in_(3) || has_flag(o_ptr->art_flags, TR_NO_MAGIC))
153 add_flag(o_ptr->art_flags, TR_NO_MAGIC);
157 static bool random_art_resistance_nether(object_type *o_ptr)
159 if (has_flag(o_ptr->art_flags, TR_RES_NETHER))
162 add_flag(o_ptr->art_flags, TR_RES_NETHER);
166 static bool random_art_resistance_dark(object_type *o_ptr)
168 if (has_flag(o_ptr->art_flags, TR_RES_DARK))
171 add_flag(o_ptr->art_flags, TR_RES_DARK);
175 static bool random_art_resistance_chaos(object_type *o_ptr)
177 if (has_flag(o_ptr->art_flags, TR_RES_CHAOS))
180 add_flag(o_ptr->art_flags, TR_RES_CHAOS);
184 static bool random_art_resistance_confusion(object_type *o_ptr)
186 if (has_flag(o_ptr->art_flags, TR_RES_CONF))
189 add_flag(o_ptr->art_flags, TR_RES_CONF);
193 static bool random_art_resistance_disenchant(object_type *o_ptr)
195 if (has_flag(o_ptr->art_flags, TR_RES_DISEN))
198 add_flag(o_ptr->art_flags, TR_RES_DISEN);
202 static bool switch_random_art_resistance(object_type *o_ptr)
204 switch (o_ptr->artifact_bias) {
206 return random_art_resistance_acid(o_ptr) || random_art_immunity_acid(o_ptr);
208 return random_art_resistance_elec(o_ptr) || random_art_aura_elec(o_ptr) || random_art_immunity_elec(o_ptr);
210 return random_art_resistance_fire(o_ptr) || random_art_aura_fire(o_ptr) || random_art_immunity_fire(o_ptr);
212 return random_art_resistance_cold(o_ptr) || random_art_aura_cold(o_ptr) || random_art_immunity_cold(o_ptr);
214 return random_art_resistance_pois(o_ptr);
216 return random_art_resistance_fear(o_ptr) || random_art_resistance_no_magic(o_ptr);
217 case BIAS_NECROMANTIC:
218 return random_art_resistance_nether(o_ptr) || random_art_resistance_pois(o_ptr) || random_art_resistance_dark(o_ptr);
220 return random_art_resistance_chaos(o_ptr) || random_art_resistance_confusion(o_ptr) || random_art_resistance_disenchant(o_ptr);
227 static void set_weird_bias_acid(object_type *o_ptr)
229 if (!one_in_(WEIRD_LUCK)) {
230 random_resistance(o_ptr);
234 add_flag(o_ptr->art_flags, TR_IM_ACID);
235 if (!o_ptr->artifact_bias)
236 o_ptr->artifact_bias = BIAS_ACID;
240 static void set_weird_bias_elec(object_type *o_ptr)
242 if (!one_in_(WEIRD_LUCK)) {
243 random_resistance(o_ptr);
247 add_flag(o_ptr->art_flags, TR_IM_ELEC);
248 if (!o_ptr->artifact_bias)
249 o_ptr->artifact_bias = BIAS_ELEC;
253 static void set_weird_bias_cold(object_type *o_ptr)
255 if (!one_in_(WEIRD_LUCK)) {
256 random_resistance(o_ptr);
260 add_flag(o_ptr->art_flags, TR_IM_COLD);
261 if (!o_ptr->artifact_bias)
262 o_ptr->artifact_bias = BIAS_COLD;
266 static void set_weird_bias_fire(object_type *o_ptr)
268 if (!one_in_(WEIRD_LUCK)) {
269 random_resistance(o_ptr);
273 add_flag(o_ptr->art_flags, TR_IM_FIRE);
274 if (!o_ptr->artifact_bias)
275 o_ptr->artifact_bias = BIAS_FIRE;
278 static void set_bias_pois(object_type *o_ptr)
280 add_flag(o_ptr->art_flags, TR_RES_POIS);
281 if (!o_ptr->artifact_bias && !one_in_(4)) {
282 o_ptr->artifact_bias = BIAS_POIS;
286 if (!o_ptr->artifact_bias && one_in_(2)) {
287 o_ptr->artifact_bias = BIAS_NECROMANTIC;
291 if (!o_ptr->artifact_bias && one_in_(2))
292 o_ptr->artifact_bias = BIAS_ROGUE;
296 static void set_weird_bias_aura_elec(object_type *o_ptr)
298 if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
299 add_flag(o_ptr->art_flags, TR_SH_ELEC);
301 random_resistance(o_ptr);
303 if (!o_ptr->artifact_bias)
304 o_ptr->artifact_bias = BIAS_ELEC;
308 static void set_weird_bias_aura_fire(object_type *o_ptr)
310 if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
311 add_flag(o_ptr->art_flags, TR_SH_FIRE);
313 random_resistance(o_ptr);
315 if (!o_ptr->artifact_bias)
316 o_ptr->artifact_bias = BIAS_FIRE;
320 static void set_weird_bias_reflection(object_type *o_ptr)
322 if (o_ptr->tval == TV_SHIELD || o_ptr->tval == TV_CLOAK || o_ptr->tval == TV_HELM || o_ptr->tval == TV_HARD_ARMOR) {
323 add_flag(o_ptr->art_flags, TR_REFLECT);
327 random_resistance(o_ptr);
331 static void set_weird_bias_aura_cold(object_type *o_ptr)
333 if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
334 add_flag(o_ptr->art_flags, TR_SH_COLD);
336 random_resistance(o_ptr);
338 if (!o_ptr->artifact_bias)
339 o_ptr->artifact_bias = BIAS_COLD;
343 * @brief ランダムアーティファクト生成中、対象のオブジェクトに耐性を付加する。/ Add one resistance on generation of randam artifact.
344 * @details 優先的に付加される耐性がランダムアーティファクトバイアスに依存して存在する。
345 * 原則的候補は火炎、冷気、電撃、酸(以上免疫の可能性もあり)、
346 * 毒、閃光、暗黒、破片、轟音、盲目、混乱、地獄、カオス、劣化、恐怖、火オーラ、冷気オーラ、電撃オーラ、反射。
348 * @attention オブジェクトのtval、svalに依存したハードコーディング処理がある。
349 * @param o_ptr 対象のオブジェクト構造体ポインタ
352 void random_resistance(object_type *o_ptr)
354 if (switch_random_art_resistance(o_ptr))
357 switch (randint1(42)) {
359 set_weird_bias_acid(o_ptr);
362 set_weird_bias_elec(o_ptr);
365 set_weird_bias_cold(o_ptr);
368 set_weird_bias_fire(o_ptr);
373 add_flag(o_ptr->art_flags, TR_RES_ACID);
374 if (!o_ptr->artifact_bias)
375 o_ptr->artifact_bias = BIAS_ACID;
381 add_flag(o_ptr->art_flags, TR_RES_ELEC);
382 if (!o_ptr->artifact_bias)
383 o_ptr->artifact_bias = BIAS_ELEC;
389 add_flag(o_ptr->art_flags, TR_RES_FIRE);
390 if (!o_ptr->artifact_bias)
391 o_ptr->artifact_bias = BIAS_FIRE;
397 add_flag(o_ptr->art_flags, TR_RES_COLD);
398 if (!o_ptr->artifact_bias)
399 o_ptr->artifact_bias = BIAS_COLD;
404 set_bias_pois(o_ptr);
408 add_flag(o_ptr->art_flags, TR_RES_FEAR);
409 if (!o_ptr->artifact_bias && one_in_(3))
410 o_ptr->artifact_bias = BIAS_WARRIOR;
414 add_flag(o_ptr->art_flags, TR_RES_LITE);
417 add_flag(o_ptr->art_flags, TR_RES_DARK);
421 add_flag(o_ptr->art_flags, TR_RES_BLIND);
425 add_flag(o_ptr->art_flags, TR_RES_CONF);
426 if (!o_ptr->artifact_bias && one_in_(6))
427 o_ptr->artifact_bias = BIAS_CHAOS;
432 add_flag(o_ptr->art_flags, TR_RES_SOUND);
436 add_flag(o_ptr->art_flags, TR_RES_SHARDS);
440 add_flag(o_ptr->art_flags, TR_RES_NETHER);
441 if (!o_ptr->artifact_bias && one_in_(3))
442 o_ptr->artifact_bias = BIAS_NECROMANTIC;
447 add_flag(o_ptr->art_flags, TR_RES_NEXUS);
451 add_flag(o_ptr->art_flags, TR_RES_CHAOS);
452 if (!o_ptr->artifact_bias && one_in_(2))
453 o_ptr->artifact_bias = BIAS_CHAOS;
458 add_flag(o_ptr->art_flags, TR_RES_DISEN);
461 set_weird_bias_aura_elec(o_ptr);
464 set_weird_bias_aura_fire(o_ptr);
467 set_weird_bias_reflection(o_ptr);
470 set_weird_bias_aura_cold(o_ptr);