1 #include "save/monster-writer.h"
2 #include "load/savedata-flag-types.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/quarks.h"
11 static void write_monster_flags(monster_type *m_ptr, BIT_FLAGS *flags)
13 if (!is_original_ap(m_ptr))
14 *flags |= SAVE_MON_AP_R_IDX;
17 *flags |= SAVE_MON_SUB_ALIGN;
19 if (monster_csleep_remaining(m_ptr))
20 *flags |= SAVE_MON_CSLEEP;
22 if (monster_fast_remaining(m_ptr))
23 *flags |= SAVE_MON_FAST;
25 if (monster_slow_remaining(m_ptr))
26 *flags |= SAVE_MON_SLOW;
28 if (monster_stunned_remaining(m_ptr))
29 *flags |= SAVE_MON_STUNNED;
31 if (monster_confused_remaining(m_ptr))
32 *flags |= SAVE_MON_CONFUSED;
34 if (monster_fear_remaining(m_ptr))
35 *flags |= SAVE_MON_MONFEAR;
38 *flags |= SAVE_MON_TARGET_Y;
41 *flags |= SAVE_MON_TARGET_X;
43 if (monster_invulner_remaining(m_ptr))
44 *flags |= SAVE_MON_INVULNER;
46 if (m_ptr->smart.any())
47 *flags |= SAVE_MON_SMART;
50 *flags |= SAVE_MON_EXP;
52 if (m_ptr->mflag2.any())
53 *flags |= SAVE_MON_MFLAG2;
56 *flags |= SAVE_MON_NICKNAME;
58 if (m_ptr->parent_m_idx)
59 *flags |= SAVE_MON_PARENT;
64 static void write_monster_info(monster_type *m_ptr, const BIT_FLAGS flags)
67 if (flags & SAVE_MON_FAST) {
68 tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
72 if (flags & SAVE_MON_SLOW) {
73 tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
77 if (flags & SAVE_MON_STUNNED) {
78 tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
82 if (flags & SAVE_MON_CONFUSED) {
83 tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
87 if (flags & SAVE_MON_MONFEAR) {
88 tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
92 if (flags & SAVE_MON_TARGET_Y)
93 wr_s16b((s16b)m_ptr->target_y);
95 if (flags & SAVE_MON_TARGET_X)
96 wr_s16b((s16b)m_ptr->target_x);
98 if (flags & SAVE_MON_INVULNER) {
99 tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
103 if (flags & SAVE_MON_SMART)
104 wr_FlagGroup(m_ptr->smart, wr_byte);
106 if (flags & SAVE_MON_EXP)
109 if (flags & SAVE_MON_MFLAG2)
110 wr_FlagGroup(m_ptr->mflag2, wr_byte);
112 if (flags & SAVE_MON_NICKNAME)
113 wr_string(quark_str(m_ptr->nickname));
115 if (flags & SAVE_MON_PARENT)
116 wr_s16b(m_ptr->parent_m_idx);
120 * @brief モンスター情報を書き込む / Write a "monster" record
121 * @param m_ptr モンスター情報保存元ポインタ
123 void wr_monster(monster_type *m_ptr)
125 BIT_FLAGS flags = 0x00000000;
126 write_monster_flags(m_ptr, &flags);
128 wr_s16b(m_ptr->r_idx);
129 wr_byte((byte)m_ptr->fy);
130 wr_byte((byte)m_ptr->fx);
131 wr_s16b((s16b)m_ptr->hp);
132 wr_s16b((s16b)m_ptr->maxhp);
133 wr_s16b((s16b)m_ptr->max_maxhp);
134 wr_u32b(m_ptr->dealt_damage);
136 if (flags & SAVE_MON_AP_R_IDX)
137 wr_s16b(m_ptr->ap_r_idx);
139 if (flags & SAVE_MON_SUB_ALIGN)
140 wr_byte(m_ptr->sub_align);
142 if (flags & SAVE_MON_CSLEEP)
143 wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
145 wr_byte((byte)m_ptr->mspeed);
146 wr_s16b(m_ptr->energy_need);
147 write_monster_info(m_ptr, flags);
151 * @brief モンスターの思い出を書き込む / Write a "lore" record
152 * @param r_idx モンスター種族ID
154 void wr_lore(MONRACE_IDX r_idx)
156 monster_race *r_ptr = &r_info[r_idx];
157 wr_s16b((s16b)r_ptr->r_sights);
158 wr_s16b((s16b)r_ptr->r_deaths);
159 wr_s16b((s16b)r_ptr->r_pkills);
160 wr_s16b((s16b)r_ptr->r_akills);
161 wr_s16b((s16b)r_ptr->r_tkills);
163 wr_byte(r_ptr->r_wake);
164 wr_byte(r_ptr->r_ignore);
166 wr_byte(r_ptr->r_xtra1);
167 wr_byte(r_ptr->r_xtra2);
169 wr_byte((byte)r_ptr->r_drop_gold);
170 wr_byte((byte)r_ptr->r_drop_item);
172 wr_byte(0); /* unused now */
173 wr_byte(r_ptr->r_cast_spell);
175 wr_byte(r_ptr->r_blows[0]);
176 wr_byte(r_ptr->r_blows[1]);
177 wr_byte(r_ptr->r_blows[2]);
178 wr_byte(r_ptr->r_blows[3]);
180 wr_u32b(r_ptr->r_flags1);
181 wr_u32b(r_ptr->r_flags2);
182 wr_u32b(r_ptr->r_flags3);
183 wr_u32b(r_ptr->r_flagsr);
184 wr_FlagGroup(r_ptr->r_ability_flags, wr_byte);
186 wr_byte((byte)r_ptr->max_num);
187 wr_s16b(r_ptr->floor_id);
189 wr_s16b(r_ptr->defeat_level);
190 wr_u32b(r_ptr->defeat_time);