OSDN Git Service

[Refactor] #2807 Renamed monster-race-definition.h to monster-race-info.h
[hengbandforosx/hengbandosx.git] / src / load / old / load-v1-5-0.cpp
1 /*!
2  * @brief 変愚蛮怒 v1.5.0以前の旧いセーブデータを読み込む処理
3  * @date 2020/07/04
4  * @author Hourier
5  * @details 互換性を最大限に確保するため、基本的に関数分割は行わないものとする.
6  */
7
8 #include "load/old/load-v1-5-0.h"
9 #include "artifact/fixed-art-types.h"
10 #include "floor/floor-object.h"
11 #include "game-option/birth-options.h"
12 #include "grid/feature.h"
13 #include "grid/grid.h"
14 #include "grid/trap.h"
15 #include "load/angband-version-comparer.h"
16 #include "load/item/item-loader-factory.h"
17 #include "load/item/item-loader-version-types.h"
18 #include "load/load-util.h"
19 #include "load/monster/monster-loader-factory.h"
20 #include "load/old-feature-types.h"
21 #include "load/old/item-loader-savefile50.h"
22 #include "load/old/monster-loader-savefile50.h"
23 #include "mind/mind-weaponsmith.h"
24 #include "monster-floor/monster-move.h"
25 #include "monster-race/monster-race.h"
26 #include "monster-race/race-flags-resistance.h"
27 #include "monster-race/race-flags1.h"
28 #include "monster-race/race-flags3.h"
29 #include "monster-race/race-indice-types.h"
30 #include "monster/monster-flag-types.h"
31 #include "monster/monster-info.h"
32 #include "monster/monster-list.h"
33 #include "object-enchant/object-ego.h"
34 #include "object-enchant/old-ego-extra-values.h"
35 #include "object-enchant/tr-types.h"
36 #include "object-enchant/trc-types.h"
37 #include "object-enchant/trg-types.h"
38 #include "object/object-kind-hook.h"
39 #include "sv-definition/sv-armor-types.h"
40 #include "sv-definition/sv-lite-types.h"
41 #include "system/angband-exceptions.h"
42 #include "system/artifact-type-definition.h"
43 #include "system/baseitem-info-definition.h"
44 #include "system/dungeon-info.h"
45 #include "system/floor-type-definition.h"
46 #include "system/grid-type-definition.h"
47 #include "system/item-entity.h"
48 #include "system/monster-race-info.h"
49 #include "system/player-type-definition.h"
50 #include "util/bit-flags-calculator.h"
51 #include "util/enum-converter.h"
52 #include "util/quarks.h"
53 #include "world/world-object.h"
54 #include "world/world.h"
55
56 /* Old hidden trap flag */
57 static const BIT_FLAGS CAVE_TRAP = 0x8000;
58
59 const int OLD_QUEST_WATER_CAVE = 18; // 湖の洞窟.
60 const int QUEST_OLD_CASTLE = 27; // 古い城.
61 const int QUEST_ROYAL_CRYPT = 28; // 王家の墓.
62
63 /*!
64  * @brief アイテムオブジェクト1件を読み込む / Read an object
65  * @param o_ptr アイテムオブジェクト読み取り先ポインタ
66  */
67 void rd_item_old(ItemEntity *o_ptr)
68 {
69     o_ptr->k_idx = rd_s16b();
70
71     o_ptr->iy = rd_byte();
72     o_ptr->ix = rd_byte();
73
74     /* Type/Subtype */
75     o_ptr->tval = i2enum<ItemKindType>(rd_byte());
76     o_ptr->sval = rd_byte();
77
78     if (h_older_than(0, 4, 4)) {
79         if (o_ptr->tval == i2enum<ItemKindType>(100)) {
80             o_ptr->tval = ItemKindType::GOLD;
81         }
82         if (o_ptr->tval == i2enum<ItemKindType>(98)) {
83             o_ptr->tval = ItemKindType::MUSIC_BOOK;
84         }
85         if (o_ptr->tval == i2enum<ItemKindType>(110)) {
86             o_ptr->tval = ItemKindType::HISSATSU_BOOK;
87         }
88     }
89
90     o_ptr->pval = rd_s16b();
91     o_ptr->discount = rd_byte();
92     o_ptr->number = rd_byte();
93
94     o_ptr->weight = rd_s16b();
95
96     o_ptr->fixed_artifact_idx = i2enum<FixedArtifactId>(rd_byte());
97
98     o_ptr->ego_idx = i2enum<EgoType>(rd_byte());
99
100     o_ptr->timeout = rd_s16b();
101     o_ptr->to_h = rd_s16b();
102     o_ptr->to_d = rd_s16b();
103
104     o_ptr->to_a = rd_s16b();
105     o_ptr->ac = rd_s16b();
106     o_ptr->dd = rd_byte();
107
108     o_ptr->ds = rd_byte();
109
110     o_ptr->ident = rd_byte();
111     o_ptr->marked = rd_byte();
112
113     for (int i = 0, count = (h_older_than(1, 3, 0, 0) ? 3 : 4); i < count; i++) {
114         auto tmp32u = rd_u32b();
115         migrate_bitflag_to_flaggroup(o_ptr->art_flags, tmp32u, i * 32);
116     }
117
118     if (h_older_than(1, 3, 0, 0)) {
119         if (o_ptr->ego_idx == EgoType::TELEPATHY) {
120             o_ptr->art_flags.set(TR_TELEPATHY);
121         }
122     }
123
124     if (h_older_than(1, 0, 11)) {
125         // バージョン 1.0.11 以前は tr_type の 93, 94, 95 は現在と違い呪い等の別の用途で使用されていたので番号をハードコーディングする
126         o_ptr->curse_flags.clear();
127         if (o_ptr->ident & 0x40) {
128             o_ptr->curse_flags.set(CurseTraitType::CURSED);
129             if (o_ptr->art_flags.has(i2enum<tr_type>(94))) {
130                 o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE);
131             }
132             if (o_ptr->art_flags.has(i2enum<tr_type>(95))) {
133                 o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
134             }
135             if (o_ptr->is_fixed_artifact()) {
136                 const auto &a_ref = artifacts_info.at(o_ptr->fixed_artifact_idx);
137                 if (a_ref.gen_flags.has(ItemGenerationTraitType::HEAVY_CURSE)) {
138                     o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE);
139                 }
140                 if (a_ref.gen_flags.has(ItemGenerationTraitType::PERMA_CURSE)) {
141                     o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
142                 }
143             } else if (o_ptr->is_ego()) {
144                 const auto &e_ref = egos_info[o_ptr->ego_idx];
145                 if (e_ref.gen_flags.has(ItemGenerationTraitType::HEAVY_CURSE)) {
146                     o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE);
147                 }
148                 if (e_ref.gen_flags.has(ItemGenerationTraitType::PERMA_CURSE)) {
149                     o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
150                 }
151             }
152         }
153         o_ptr->art_flags.reset({ i2enum<tr_type>(93), i2enum<tr_type>(94), i2enum<tr_type>(95) });
154     } else {
155         auto tmp32u = rd_u32b();
156         migrate_bitflag_to_flaggroup(o_ptr->curse_flags, tmp32u);
157     }
158
159     o_ptr->held_m_idx = rd_s16b();
160     auto xtra1 = rd_byte(); // かつてエゴアイテムの情報を格納していた名残.
161     o_ptr->activation_id = i2enum<RandomArtActType>(rd_byte());
162
163     if (h_older_than(1, 0, 10)) {
164         if (xtra1 == enum2i<OldEgoType>(OldEgoType::XTRA_SUSTAIN)) {
165             switch (enum2i(o_ptr->activation_id) % 6) {
166             case 0:
167                 o_ptr->art_flags.set(TR_SUST_STR);
168                 break;
169             case 1:
170                 o_ptr->art_flags.set(TR_SUST_INT);
171                 break;
172             case 2:
173                 o_ptr->art_flags.set(TR_SUST_WIS);
174                 break;
175             case 3:
176                 o_ptr->art_flags.set(TR_SUST_DEX);
177                 break;
178             case 4:
179                 o_ptr->art_flags.set(TR_SUST_CON);
180                 break;
181             case 5:
182                 o_ptr->art_flags.set(TR_SUST_CHR);
183                 break;
184             }
185             o_ptr->activation_id = i2enum<RandomArtActType>(0);
186         } else if (xtra1 == enum2i<OldEgoType>(OldEgoType::XTRA_POWER)) {
187             switch (enum2i(o_ptr->activation_id) % 11) {
188             case 0:
189                 o_ptr->art_flags.set(TR_RES_BLIND);
190                 break;
191             case 1:
192                 o_ptr->art_flags.set(TR_RES_CONF);
193                 break;
194             case 2:
195                 o_ptr->art_flags.set(TR_RES_SOUND);
196                 break;
197             case 3:
198                 o_ptr->art_flags.set(TR_RES_SHARDS);
199                 break;
200             case 4:
201                 o_ptr->art_flags.set(TR_RES_NETHER);
202                 break;
203             case 5:
204                 o_ptr->art_flags.set(TR_RES_NEXUS);
205                 break;
206             case 6:
207                 o_ptr->art_flags.set(TR_RES_CHAOS);
208                 break;
209             case 7:
210                 o_ptr->art_flags.set(TR_RES_DISEN);
211                 break;
212             case 8:
213                 o_ptr->art_flags.set(TR_RES_POIS);
214                 break;
215             case 9:
216                 o_ptr->art_flags.set(TR_RES_DARK);
217                 break;
218             case 10:
219                 o_ptr->art_flags.set(TR_RES_LITE);
220                 break;
221             }
222             o_ptr->activation_id = i2enum<RandomArtActType>(0);
223         } else if (xtra1 == enum2i<OldEgoType>(OldEgoType::XTRA_ABILITY)) {
224             switch (enum2i(o_ptr->activation_id) % 8) {
225             case 0:
226                 o_ptr->art_flags.set(TR_LEVITATION);
227                 break;
228             case 1:
229                 o_ptr->art_flags.set(TR_LITE_1);
230                 break;
231             case 2:
232                 o_ptr->art_flags.set(TR_SEE_INVIS);
233                 break;
234             case 3:
235                 o_ptr->art_flags.set(TR_WARNING);
236                 break;
237             case 4:
238                 o_ptr->art_flags.set(TR_SLOW_DIGEST);
239                 break;
240             case 5:
241                 o_ptr->art_flags.set(TR_REGEN);
242                 break;
243             case 6:
244                 o_ptr->art_flags.set(TR_FREE_ACT);
245                 break;
246             case 7:
247                 o_ptr->art_flags.set(TR_HOLD_EXP);
248                 break;
249             }
250             o_ptr->activation_id = i2enum<RandomArtActType>(0);
251         }
252
253         xtra1 = 0;
254     }
255
256     if (h_older_than(0, 2, 3)) {
257         o_ptr->fuel = 0;
258         o_ptr->captured_monster_current_hp = 0;
259         o_ptr->smith_hit = 0;
260         o_ptr->smith_damage = 0;
261         o_ptr->captured_monster_max_hp = 0;
262         if (o_ptr->tval == ItemKindType::CHEST) {
263             o_ptr->chest_level = xtra1;
264         } else if (o_ptr->tval == ItemKindType::CAPTURE) {
265             o_ptr->captured_monster_speed = xtra1;
266         }
267
268         if (o_ptr->tval == ItemKindType::CAPTURE) {
269             const auto &r_ref = monraces_info[i2enum<MonsterRaceId>(o_ptr->pval)];
270             if (r_ref.flags1 & RF1_FORCE_MAXHP) {
271                 o_ptr->captured_monster_max_hp = maxroll(r_ref.hdice, r_ref.hside);
272             } else {
273                 o_ptr->captured_monster_max_hp = damroll(r_ref.hdice, r_ref.hside);
274             }
275             if (ironman_nightmare) {
276                 o_ptr->captured_monster_max_hp = std::min<short>(MONSTER_MAXHP, o_ptr->captured_monster_max_hp * 2L);
277             }
278
279             o_ptr->captured_monster_current_hp = o_ptr->captured_monster_max_hp;
280         }
281     } else {
282         auto xtra3 = rd_byte();
283         if (h_older_than(1, 3, 0, 1)) {
284             if (o_ptr->is_smith() && (xtra3 >= 1 + 96)) {
285                 auto mes = _("古いバージョンで鍛冶師をプレイしたデータは読み込めません。", "The save data from playing a weaponsmith on versions older than v3.0.0 Aplha38 can't be read.");
286                 throw SaveDataNotSupportedException(mes);
287             }
288         }
289
290         auto xtra4 = rd_s16b();
291         if (o_ptr->tval == ItemKindType::LITE) {
292             o_ptr->fuel = xtra4;
293         } else if (o_ptr->tval == ItemKindType::CAPTURE) {
294             o_ptr->captured_monster_current_hp = xtra4;
295         } else {
296             o_ptr->smith_hit = static_cast<byte>(xtra4 >> 8);
297             o_ptr->smith_damage = static_cast<byte>(xtra4 & 0x000f);
298         }
299
300         o_ptr->captured_monster_max_hp = rd_s16b();
301     }
302
303     if (h_older_than(1, 0, 5) && o_ptr->is_fuel()) {
304         o_ptr->fuel = o_ptr->pval;
305         o_ptr->pval = 0;
306     }
307
308     o_ptr->feeling = rd_byte();
309
310     char buf[128];
311     rd_string(buf, sizeof(buf));
312     if (buf[0]) {
313         o_ptr->inscription = quark_add(buf);
314     }
315
316     rd_string(buf, sizeof(buf));
317
318     /*!< @todo 元々このif文には末尾に";"が付いていた、バグかもしれない */
319     if (buf[0]) {
320         o_ptr->art_name = quark_add(buf);
321     }
322     {
323         auto tmp32s = rd_s32b();
324         strip_bytes(tmp32s);
325     }
326
327     if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) {
328         return;
329     }
330
331     if (h_older_than(0, 4, 10) && (o_ptr->ego_idx == EgoType::TWILIGHT)) {
332         o_ptr->k_idx = lookup_baseitem_id({ ItemKindType::SOFT_ARMOR, SV_TWILIGHT_ROBE });
333     }
334
335     if (h_older_than(0, 4, 9)) {
336         if (o_ptr->art_flags.has(TR_MAGIC_MASTERY)) {
337             o_ptr->art_flags.reset(TR_MAGIC_MASTERY);
338             o_ptr->art_flags.set(TR_DEC_MANA);
339         }
340     }
341
342     if (o_ptr->is_fixed_artifact()) {
343         const auto &a_ref = artifacts_info.at(o_ptr->fixed_artifact_idx);
344         if (a_ref.name.empty()) {
345             o_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
346         }
347     }
348
349     if (o_ptr->is_ego()) {
350         const auto &e_ref = egos_info[o_ptr->ego_idx];
351         if (e_ref.name.empty()) {
352             o_ptr->ego_idx = EgoType::NONE;
353         }
354     }
355 }
356
357 /*!
358  * @brief モンスターを読み込む / Read a monster
359  * @param player_ptr プレイヤーへの参照ポインタ
360  * @param m_ptr モンスター保存先ポインタ
361  */
362 void rd_monster_old(PlayerType *player_ptr, MonsterEntity *m_ptr)
363 {
364     m_ptr->r_idx = i2enum<MonsterRaceId>(rd_s16b());
365
366     if (h_older_than(1, 0, 12)) {
367         m_ptr->ap_r_idx = m_ptr->r_idx;
368     } else {
369         m_ptr->ap_r_idx = i2enum<MonsterRaceId>(rd_s16b());
370     }
371
372     if (h_older_than(1, 0, 14)) {
373         auto *r_ptr = &monraces_info[m_ptr->r_idx];
374
375         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
376         if (r_ptr->kind_flags.has(MonsterKindType::EVIL)) {
377             m_ptr->sub_align |= SUB_ALIGN_EVIL;
378         }
379         if (r_ptr->kind_flags.has(MonsterKindType::GOOD)) {
380             m_ptr->sub_align |= SUB_ALIGN_GOOD;
381         }
382     } else {
383         m_ptr->sub_align = rd_byte();
384     }
385
386     m_ptr->fy = rd_byte();
387     m_ptr->fx = rd_byte();
388     m_ptr->current_floor_ptr = player_ptr->current_floor_ptr;
389
390     m_ptr->hp = rd_s16b();
391     m_ptr->maxhp = rd_s16b();
392
393     if (h_older_than(1, 0, 5)) {
394         m_ptr->max_maxhp = m_ptr->maxhp;
395     } else {
396         m_ptr->max_maxhp = rd_s16b();
397     }
398     if (h_older_than(2, 1, 2, 1)) {
399         m_ptr->dealt_damage = 0;
400     } else {
401         m_ptr->dealt_damage = rd_s32b();
402     }
403
404     m_ptr->mtimed[MTIMED_CSLEEP] = rd_s16b();
405     m_ptr->mspeed = rd_byte();
406
407     if (h_older_than(0, 4, 2)) {
408         m_ptr->energy_need = rd_byte();
409     } else {
410         m_ptr->energy_need = rd_s16b();
411     }
412
413     if (h_older_than(1, 0, 13)) {
414         m_ptr->energy_need = 100 - m_ptr->energy_need;
415     }
416
417     if (h_older_than(0, 0, 7)) {
418         m_ptr->mtimed[MTIMED_FAST] = 0;
419         m_ptr->mtimed[MTIMED_SLOW] = 0;
420     } else {
421         m_ptr->mtimed[MTIMED_FAST] = rd_byte();
422         m_ptr->mtimed[MTIMED_SLOW] = rd_byte();
423     }
424
425     m_ptr->mtimed[MTIMED_STUNNED] = rd_byte();
426     m_ptr->mtimed[MTIMED_CONFUSED] = rd_byte();
427     m_ptr->mtimed[MTIMED_MONFEAR] = rd_byte();
428
429     if (h_older_than(0, 0, 10)) {
430         reset_target(m_ptr);
431     } else if (h_older_than(0, 0, 11)) {
432         strip_bytes(2);
433         reset_target(m_ptr);
434     } else {
435         m_ptr->target_y = rd_s16b();
436         m_ptr->target_x = rd_s16b();
437     }
438
439     m_ptr->mtimed[MTIMED_INVULNER] = rd_byte();
440
441     auto tmp32u = rd_u32b();
442     migrate_bitflag_to_flaggroup(m_ptr->smart, tmp32u);
443
444     // 3.0.0Alpha10以前のSM_CLONED(ビット位置22)、SM_PET(23)、SM_FRIEDLY(28)をMFLAG2に移行する
445     // ビット位置の定義はなくなるので、ビット位置の値をハードコードする。
446     std::bitset<32> rd_bits_smart(tmp32u);
447     m_ptr->mflag2[MonsterConstantFlagType::CLONED] = rd_bits_smart[22];
448     m_ptr->mflag2[MonsterConstantFlagType::PET] = rd_bits_smart[23];
449     m_ptr->mflag2[MonsterConstantFlagType::FRIENDLY] = rd_bits_smart[28];
450     m_ptr->smart.reset(i2enum<MonsterSmartLearnType>(22)).reset(i2enum<MonsterSmartLearnType>(23)).reset(i2enum<MonsterSmartLearnType>(28));
451
452     if (h_older_than(0, 4, 5)) {
453         m_ptr->exp = 0;
454     } else {
455         m_ptr->exp = rd_u32b();
456     }
457
458     if (h_older_than(0, 2, 2)) {
459         if (enum2i(m_ptr->r_idx) < 0) {
460             m_ptr->r_idx = i2enum<MonsterRaceId>(0 - enum2i(m_ptr->r_idx));
461             m_ptr->mflag2.set(MonsterConstantFlagType::KAGE);
462         }
463     } else {
464         auto tmp8u = rd_byte();
465         constexpr auto base = enum2i(MonsterConstantFlagType::KAGE);
466         migrate_bitflag_to_flaggroup(m_ptr->mflag2, tmp8u, base, 7);
467     }
468
469     if (h_older_than(1, 0, 12)) {
470         if (m_ptr->mflag2.has(MonsterConstantFlagType::KAGE)) {
471             m_ptr->ap_r_idx = MonsterRaceId::KAGE;
472         }
473     }
474
475     if (h_older_than(0, 1, 3)) {
476         m_ptr->nickname = 0;
477     } else {
478         char buf[128];
479         rd_string(buf, sizeof(buf));
480         if (buf[0]) {
481             m_ptr->nickname = quark_add(buf);
482         }
483     }
484
485     strip_bytes(1);
486 }
487
488 static void move_RF3_to_RFR(MonsterRaceInfo *r_ptr, const BIT_FLAGS rf3, const MonsterResistanceType rfr)
489 {
490     if (r_ptr->r_flags3 & rf3) {
491         r_ptr->r_flags3 &= ~rf3;
492         r_ptr->resistance_flags.set(rfr);
493     }
494 }
495
496 static void move_RF4_BR_to_RFR(MonsterRaceInfo *r_ptr, BIT_FLAGS f4, const BIT_FLAGS rf4_br, const MonsterResistanceType rfr)
497 {
498     if (f4 & rf4_br) {
499         r_ptr->resistance_flags.set(rfr);
500     }
501 }
502
503 /*!
504  * @brief モンスターの思い出を読み込む
505  * @param r_ptr モンスター種族情報への参照ポインタ
506  * @param r_idx モンスター種族ID
507  * @details 本来はr_idxからr_ptrを決定可能だが、互換性を優先するため元コードのままとする
508  */
509 void set_old_lore(MonsterRaceInfo *r_ptr, BIT_FLAGS f4, const MonsterRaceId r_idx)
510 {
511     r_ptr->r_resistance_flags.clear();
512     move_RF3_to_RFR(r_ptr, RF3_IM_ACID, MonsterResistanceType::IMMUNE_ACID);
513     move_RF3_to_RFR(r_ptr, RF3_IM_ELEC, MonsterResistanceType::IMMUNE_ELEC);
514     move_RF3_to_RFR(r_ptr, RF3_IM_FIRE, MonsterResistanceType::IMMUNE_FIRE);
515     move_RF3_to_RFR(r_ptr, RF3_IM_COLD, MonsterResistanceType::IMMUNE_COLD);
516     move_RF3_to_RFR(r_ptr, RF3_IM_POIS, MonsterResistanceType::IMMUNE_POISON);
517     move_RF3_to_RFR(r_ptr, RF3_RES_TELE, MonsterResistanceType::RESIST_TELEPORT);
518     move_RF3_to_RFR(r_ptr, RF3_RES_NETH, MonsterResistanceType::RESIST_NETHER);
519     move_RF3_to_RFR(r_ptr, RF3_RES_WATE, MonsterResistanceType::RESIST_WATER);
520     move_RF3_to_RFR(r_ptr, RF3_RES_PLAS, MonsterResistanceType::RESIST_PLASMA);
521     move_RF3_to_RFR(r_ptr, RF3_RES_NEXU, MonsterResistanceType::RESIST_NEXUS);
522     move_RF3_to_RFR(r_ptr, RF3_RES_DISE, MonsterResistanceType::RESIST_DISENCHANT);
523     move_RF3_to_RFR(r_ptr, RF3_RES_ALL, MonsterResistanceType::RESIST_ALL);
524
525     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_LITE, MonsterResistanceType::RESIST_LITE);
526     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_DARK, MonsterResistanceType::RESIST_DARK);
527     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_SOUN, MonsterResistanceType::RESIST_SOUND);
528     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_CHAO, MonsterResistanceType::RESIST_CHAOS);
529     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_TIME, MonsterResistanceType::RESIST_TIME);
530     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_INER, MonsterResistanceType::RESIST_INERTIA);
531     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_GRAV, MonsterResistanceType::RESIST_GRAVITY);
532     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_SHAR, MonsterResistanceType::RESIST_SHARDS);
533     move_RF4_BR_to_RFR(r_ptr, f4, RF4_BR_WALL, MonsterResistanceType::RESIST_FORCE);
534
535     if (f4 & RF4_BR_CONF) {
536         r_ptr->r_flags3 |= RF3_NO_CONF;
537     }
538
539     if (r_idx == MonsterRaceId::STORMBRINGER) {
540         r_ptr->r_resistance_flags.set(MonsterResistanceType::RESIST_CHAOS);
541     }
542
543     if (r_ptr->r_kind_flags.has(MonsterKindType::ORC)) {
544         r_ptr->r_resistance_flags.set(MonsterResistanceType::RESIST_DARK);
545     }
546 }
547
548 /*!
549  * @brief ダンジョン情報を読み込む / Read the dungeon (old method)
550  * @param player_ptr プレイヤーへの参照ポインタ
551  * @details
552  * The monsters/objects must be loaded in the same order
553  * that they were stored, since the actual indexes matter.
554  */
555 errr rd_dungeon_old(PlayerType *player_ptr)
556 {
557     auto *floor_ptr = player_ptr->current_floor_ptr;
558     floor_ptr->dun_level = rd_s16b();
559     if (h_older_than(0, 3, 8)) {
560         player_ptr->dungeon_idx = DUNGEON_ANGBAND;
561     } else {
562         player_ptr->dungeon_idx = rd_byte();
563     }
564
565     floor_ptr->base_level = floor_ptr->dun_level;
566     floor_ptr->base_level = rd_s16b();
567
568     floor_ptr->num_repro = rd_s16b();
569     player_ptr->y = rd_s16b();
570     player_ptr->x = rd_s16b();
571     if (h_older_than(0, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) {
572         player_ptr->y = 33;
573         player_ptr->x = 131;
574     }
575     floor_ptr->height = rd_s16b();
576     floor_ptr->width = rd_s16b();
577     strip_bytes(2); /* max_panel_rows */
578     strip_bytes(2); /* max_panel_cols */
579
580     int ymax = floor_ptr->height;
581     int xmax = floor_ptr->width;
582
583     for (int x = 0, y = 0; y < ymax;) {
584         uint16_t info;
585         auto count = rd_byte();
586         if (h_older_than(0, 3, 6)) {
587             info = rd_byte();
588         } else {
589             info = rd_u16b();
590             info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
591         }
592
593         for (int i = count; i > 0; i--) {
594             grid_type *g_ptr;
595             g_ptr = &floor_ptr->grid_array[y][x];
596             g_ptr->info = info;
597             if (++x >= xmax) {
598                 x = 0;
599                 if (++y >= ymax) {
600                     break;
601                 }
602             }
603         }
604     }
605
606     for (int x = 0, y = 0; y < ymax;) {
607         auto count = rd_byte();
608         auto tmp8u = rd_byte();
609         for (int i = count; i > 0; i--) {
610             grid_type *g_ptr;
611             g_ptr = &floor_ptr->grid_array[y][x];
612             g_ptr->feat = (int16_t)tmp8u;
613             if (++x >= xmax) {
614                 x = 0;
615                 if (++y >= ymax) {
616                     break;
617                 }
618             }
619         }
620     }
621
622     for (int x = 0, y = 0; y < ymax;) {
623         auto count = rd_byte();
624         auto tmp8u = rd_byte();
625         for (int i = count; i > 0; i--) {
626             grid_type *g_ptr;
627             g_ptr = &floor_ptr->grid_array[y][x];
628             g_ptr->mimic = (int16_t)tmp8u;
629             if (++x >= xmax) {
630                 x = 0;
631                 if (++y >= ymax) {
632                     break;
633                 }
634             }
635         }
636     }
637
638     for (int x = 0, y = 0; y < ymax;) {
639         auto count = rd_byte();
640         auto tmp16s = rd_s16b();
641         for (int i = count; i > 0; i--) {
642             grid_type *g_ptr;
643             g_ptr = &floor_ptr->grid_array[y][x];
644             g_ptr->special = tmp16s;
645             if (++x >= xmax) {
646                 x = 0;
647                 if (++y >= ymax) {
648                     break;
649                 }
650             }
651         }
652     }
653
654     if (h_older_than(1, 0, 99)) {
655         for (int y = 0; y < ymax; y++) {
656             for (int x = 0; x < xmax; x++) {
657                 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
658             }
659         }
660     }
661
662     if (h_older_than(1, 1, 1, 0)) {
663         for (int y = 0; y < ymax; y++) {
664             for (int x = 0; x < xmax; x++) {
665                 grid_type *g_ptr;
666                 g_ptr = &floor_ptr->grid_array[y][x];
667
668                 /* Very old */
669                 if (g_ptr->feat == OLD_FEAT_INVIS) {
670                     g_ptr->feat = feat_floor;
671                     g_ptr->info |= CAVE_TRAP;
672                 }
673
674                 /* Older than 1.1.1 */
675                 if (g_ptr->feat == OLD_FEAT_MIRROR) {
676                     g_ptr->feat = feat_floor;
677                     g_ptr->info |= CAVE_OBJECT;
678                 }
679             }
680         }
681     }
682
683     if (h_older_than(1, 3, 1, 0)) {
684         for (int y = 0; y < ymax; y++) {
685             for (int x = 0; x < xmax; x++) {
686                 grid_type *g_ptr;
687                 g_ptr = &floor_ptr->grid_array[y][x];
688
689                 /* Old CAVE_IN_MIRROR flag */
690                 if (g_ptr->info & CAVE_OBJECT) {
691                     g_ptr->mimic = feat_mirror;
692                 } else if ((g_ptr->feat == OLD_FEAT_RUNE_EXPLOSION) || (g_ptr->feat == OLD_FEAT_RUNE_PROTECTION)) {
693                     g_ptr->info |= CAVE_OBJECT;
694                     g_ptr->mimic = g_ptr->feat;
695                     g_ptr->feat = feat_floor;
696                 } else if (g_ptr->info & CAVE_TRAP) {
697                     g_ptr->info &= ~CAVE_TRAP;
698                     g_ptr->mimic = g_ptr->feat;
699                     g_ptr->feat = choose_random_trap(player_ptr);
700                 } else if (g_ptr->feat == OLD_FEAT_INVIS) {
701                     g_ptr->mimic = feat_floor;
702                     g_ptr->feat = feat_trap_open;
703                 }
704             }
705         }
706     }
707
708     /* Quest 18 was removed */
709     if (!vanilla_town) {
710         for (int y = 0; y < ymax; y++) {
711             for (int x = 0; x < xmax; x++) {
712                 grid_type *g_ptr;
713                 g_ptr = &floor_ptr->grid_array[y][x];
714
715                 if ((g_ptr->special == OLD_QUEST_WATER_CAVE) && !floor_ptr->dun_level) {
716                     if (g_ptr->feat == OLD_FEAT_QUEST_ENTER) {
717                         g_ptr->feat = feat_tree;
718                         g_ptr->special = 0;
719                     } else if (g_ptr->feat == OLD_FEAT_BLDG_1) {
720                         g_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
721                     }
722                 } else if ((g_ptr->feat == OLD_FEAT_QUEST_EXIT) && (floor_ptr->quest_number == i2enum<QuestId>(OLD_QUEST_WATER_CAVE))) {
723                     g_ptr->feat = feat_up_stair;
724                     g_ptr->special = 0;
725                 }
726             }
727         }
728     }
729
730     uint16_t limit;
731     limit = rd_u16b();
732     if (limit > w_ptr->max_o_idx) {
733         load_note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
734         return 151;
735     }
736
737     auto item_loader = ItemLoaderFactory::create_loader();
738     for (int i = 1; i < limit; i++) {
739         OBJECT_IDX o_idx = o_pop(floor_ptr);
740         if (i != o_idx) {
741             load_note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
742             return 152;
743         }
744
745         auto &item = floor_ptr->o_list[o_idx];
746         item_loader->rd_item(&item);
747         auto &list = get_o_idx_list_contains(floor_ptr, o_idx);
748         list.add(floor_ptr, o_idx);
749     }
750
751     limit = rd_u16b();
752     if (limit > w_ptr->max_m_idx) {
753         load_note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
754         return 161;
755     }
756
757     auto monster_loader = MonsterLoaderFactory::create_loader(player_ptr);
758     for (int i = 1; i < limit; i++) {
759         auto m_idx = m_pop(floor_ptr);
760         if (i != m_idx) {
761             load_note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
762             return 162;
763         }
764
765         auto m_ptr = &floor_ptr->m_list[m_idx];
766         monster_loader->rd_monster(m_ptr);
767         auto *g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
768         g_ptr->m_idx = m_idx;
769         m_ptr->get_real_r_ref().cur_num++;
770     }
771
772     if (h_older_than(0, 3, 13) && !floor_ptr->dun_level && !floor_ptr->inside_arena) {
773         w_ptr->character_dungeon = false;
774     } else {
775         w_ptr->character_dungeon = true;
776     }
777
778     return 0;
779 }