OSDN Git Service

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