OSDN Git Service

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