1 #include "save/monster-writer.h"
2 #include "load/old/monster-flag-types-savefile50.h"
3 #include "monster-race/monster-race.h"
4 #include "monster/monster-info.h"
5 #include "monster/monster-status.h"
6 #include "save/save-util.h"
7 #include "system/monster-race-definition.h"
8 #include "system/monster-type-definition.h"
9 #include "util/bit-flags-calculator.h"
10 #include "util/quarks.h"
12 static void write_monster_flags(monster_type *m_ptr, BIT_FLAGS *flags)
14 if (!is_original_ap(m_ptr))
15 set_bits(*flags, SaveDataMonsterFlagType::AP_R_IDX);
18 set_bits(*flags, SaveDataMonsterFlagType::SUB_ALIGN);
20 if (monster_csleep_remaining(m_ptr))
21 set_bits(*flags, SaveDataMonsterFlagType::CSLEEP);
23 if (monster_fast_remaining(m_ptr))
24 set_bits(*flags, SaveDataMonsterFlagType::FAST);
26 if (monster_slow_remaining(m_ptr))
27 set_bits(*flags, SaveDataMonsterFlagType::SLOW);
29 if (monster_stunned_remaining(m_ptr))
30 set_bits(*flags, SaveDataMonsterFlagType::STUNNED);
32 if (monster_confused_remaining(m_ptr))
33 set_bits(*flags, SaveDataMonsterFlagType::CONFUSED);
35 if (monster_fear_remaining(m_ptr))
36 set_bits(*flags, SaveDataMonsterFlagType::MONFEAR);
39 set_bits(*flags, SaveDataMonsterFlagType::TARGET_Y);
42 set_bits(*flags, SaveDataMonsterFlagType::TARGET_X);
44 if (monster_invulner_remaining(m_ptr))
45 set_bits(*flags, SaveDataMonsterFlagType::INVULNER);
47 if (m_ptr->smart.any())
48 set_bits(*flags, SaveDataMonsterFlagType::SMART);
51 set_bits(*flags, SaveDataMonsterFlagType::EXP);
53 if (m_ptr->mflag2.any())
54 set_bits(*flags, SaveDataMonsterFlagType::MFLAG2);
57 set_bits(*flags, SaveDataMonsterFlagType::NICKNAME);
59 if (m_ptr->parent_m_idx)
60 set_bits(*flags, SaveDataMonsterFlagType::PARENT);
65 static void write_monster_info(monster_type *m_ptr, const BIT_FLAGS flags)
68 if (any_bits(flags, SaveDataMonsterFlagType::FAST)) {
69 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
73 if (any_bits(flags, SaveDataMonsterFlagType::SLOW)) {
74 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
78 if (any_bits(flags, SaveDataMonsterFlagType::STUNNED)) {
79 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
83 if (any_bits(flags, SaveDataMonsterFlagType::CONFUSED)) {
84 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
88 if (any_bits(flags, SaveDataMonsterFlagType::MONFEAR)) {
89 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
93 if (any_bits(flags, SaveDataMonsterFlagType::TARGET_Y))
94 wr_s16b((int16_t)m_ptr->target_y);
96 if (any_bits(flags, SaveDataMonsterFlagType::TARGET_X))
97 wr_s16b((int16_t)m_ptr->target_x);
99 if (any_bits(flags, SaveDataMonsterFlagType::INVULNER)) {
100 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
104 if (any_bits(flags, SaveDataMonsterFlagType::SMART))
105 wr_FlagGroup(m_ptr->smart, wr_byte);
107 if (any_bits(flags, SaveDataMonsterFlagType::EXP))
110 if (any_bits(flags, SaveDataMonsterFlagType::MFLAG2))
111 wr_FlagGroup(m_ptr->mflag2, wr_byte);
113 if (any_bits(flags, SaveDataMonsterFlagType::NICKNAME))
114 wr_string(quark_str(m_ptr->nickname));
116 if (any_bits(flags, SaveDataMonsterFlagType::PARENT))
117 wr_s16b(m_ptr->parent_m_idx);
121 * @brief モンスター情報を書き込む / Write a "monster" record
122 * @param m_ptr モンスター情報保存元ポインタ
124 void wr_monster(monster_type *m_ptr)
126 BIT_FLAGS flags = 0x00000000;
127 write_monster_flags(m_ptr, &flags);
129 wr_s16b(m_ptr->r_idx);
130 wr_byte((byte)m_ptr->fy);
131 wr_byte((byte)m_ptr->fx);
132 wr_s16b((int16_t)m_ptr->hp);
133 wr_s16b((int16_t)m_ptr->maxhp);
134 wr_s16b((int16_t)m_ptr->max_maxhp);
135 wr_u32b(m_ptr->dealt_damage);
137 if (any_bits(flags, SaveDataMonsterFlagType::AP_R_IDX))
138 wr_s16b(m_ptr->ap_r_idx);
140 if (any_bits(flags, SaveDataMonsterFlagType::SUB_ALIGN))
141 wr_byte(m_ptr->sub_align);
143 if (any_bits(flags, SaveDataMonsterFlagType::CSLEEP))
144 wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
146 wr_byte((byte)m_ptr->mspeed);
147 wr_s16b(m_ptr->energy_need);
148 write_monster_info(m_ptr, flags);
152 * @brief モンスターの思い出を書き込む / Write a "lore" record
153 * @param r_idx モンスター種族ID
155 void wr_lore(MONRACE_IDX r_idx)
157 auto *r_ptr = &r_info[r_idx];
158 wr_s16b((int16_t)r_ptr->r_sights);
159 wr_s16b((int16_t)r_ptr->r_deaths);
160 wr_s16b((int16_t)r_ptr->r_pkills);
161 wr_s16b((int16_t)r_ptr->r_akills);
162 wr_s16b((int16_t)r_ptr->r_tkills);
164 wr_byte(r_ptr->r_wake);
165 wr_byte(r_ptr->r_ignore);
167 byte tmp8u = r_ptr->r_can_evolve ? 1 : 0;
170 wr_byte((byte)r_ptr->r_drop_gold);
171 wr_byte((byte)r_ptr->r_drop_item);
173 wr_byte(0); /* unused now */
174 wr_byte(r_ptr->r_cast_spell);
176 wr_byte(r_ptr->r_blows[0]);
177 wr_byte(r_ptr->r_blows[1]);
178 wr_byte(r_ptr->r_blows[2]);
179 wr_byte(r_ptr->r_blows[3]);
181 wr_u32b(r_ptr->r_flags1);
182 wr_u32b(r_ptr->r_flags2);
183 wr_u32b(r_ptr->r_flags3);
184 wr_u32b(r_ptr->r_flagsr);
185 wr_FlagGroup(r_ptr->r_ability_flags, wr_byte);
186 wr_FlagGroup(r_ptr->r_aura_flags, wr_byte);
187 wr_FlagGroup(r_ptr->r_behavior_flags, wr_byte);
189 wr_byte((byte)r_ptr->max_num);
190 wr_s16b(r_ptr->floor_id);
192 wr_s16b(r_ptr->defeat_level);
193 wr_u32b(r_ptr->defeat_time);