1 #include "load/player-info-loader.h"
2 #include "cmd-building/cmd-building.h"
3 #include "load/angband-version-comparer.h"
4 #include "load/birth-loader.h"
5 #include "load/dummy-loader.h"
6 #include "load/load-util.h"
7 #include "load/load-v1-3-0.h"
8 #include "load/load-v1-7-0.h"
9 #include "load/load-zangband.h"
10 #include "load/player-attack-loader.h"
11 #include "load/world-loader.h"
12 #include "market/arena.h"
13 #include "mutation/mutation-calculator.h"
14 #include "player/attack-defense-types.h"
15 #include "player/player-skill.h"
16 #include "system/floor-type-definition.h"
17 #include "world/world.h"
19 void rd_base_info(player_type *creature_ptr)
21 rd_string(creature_ptr->name, sizeof(creature_ptr->name));
22 rd_string(creature_ptr->died_from, sizeof(creature_ptr->died_from));
23 if (!h_older_than(1, 7, 0, 1)) {
25 rd_string(buf, sizeof buf);
27 creature_ptr->last_message = string_make(buf);
31 const int max_history_lines = 4;
32 for (int i = 0; i < max_history_lines; i++)
33 rd_string(creature_ptr->history[i], sizeof(creature_ptr->history[i]));
37 creature_ptr->prace = (player_race_type)tmp8u;
40 creature_ptr->pclass = (player_class_type)tmp8u;
43 creature_ptr->pseikaku = (player_personality_type)tmp8u;
45 rd_byte(&creature_ptr->psex);
47 creature_ptr->realm1 = (REALM_IDX)tmp8u;
50 creature_ptr->realm2 = (REALM_IDX)tmp8u;
53 if (h_older_than(0, 4, 4))
54 set_zangband_realm(creature_ptr);
57 creature_ptr->hitdie = (DICE_SID)tmp8u;
58 rd_u16b(&creature_ptr->expfact);
60 rd_s16b(&creature_ptr->age);
61 rd_s16b(&creature_ptr->ht);
62 rd_s16b(&creature_ptr->wt);
65 void rd_experience(player_type *creature_ptr)
67 rd_s32b(&creature_ptr->max_exp);
68 if (h_older_than(1, 5, 4, 1))
69 creature_ptr->max_max_exp = creature_ptr->max_exp;
71 rd_s32b(&creature_ptr->max_max_exp);
73 rd_s32b(&creature_ptr->exp);
74 if (h_older_than(1, 7, 0, 3))
75 set_exp_frac_old(creature_ptr);
77 rd_u32b(&creature_ptr->exp_frac);
79 rd_s16b(&creature_ptr->lev);
80 for (int i = 0; i < 64; i++)
81 rd_s16b(&creature_ptr->spell_exp[i]);
83 if ((creature_ptr->pclass == CLASS_SORCERER) && h_older_than(0, 4, 2))
84 for (int i = 0; i < 64; i++)
85 creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
87 const int max_weapon_exp_size = h_older_than(0, 3, 6) ? 60 : 64;
88 for (int i = 0; i < 5; i++)
89 for (int j = 0; j < max_weapon_exp_size; j++)
90 rd_s16b(&creature_ptr->weapon_exp[i][j]);
92 for (int i = 0; i < GINOU_MAX; i++)
93 rd_s16b(&creature_ptr->skill_exp[i]);
96 static void set_spells(player_type *creature_ptr)
98 for (int i = 0; i < MAX_SPELLS; i++)
99 rd_s32b(&creature_ptr->magic_num1[i]);
101 for (int i = 0; i < MAX_SPELLS; i++)
102 rd_byte(&creature_ptr->magic_num2[i]);
104 if (h_older_than(1, 3, 0, 1))
105 set_spells_old(creature_ptr);
108 void rd_skills(player_type *creature_ptr)
110 if (h_older_than(0, 4, 1))
111 set_zangband_skill(creature_ptr);
113 if (h_older_than(0, 3, 14))
114 set_zangband_spells(creature_ptr);
116 set_spells(creature_ptr);
118 if (music_singing_any(creature_ptr))
119 creature_ptr->action = ACTION_SING;
122 static void set_race(player_type *creature_ptr)
126 creature_ptr->start_race = (player_race_type)tmp8u;
129 creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
131 creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
132 rd_s16b(&creature_ptr->old_realm);
135 void rd_race(player_type *creature_ptr)
137 if (h_older_than(1, 0, 7)) {
138 set_zangband_race(creature_ptr);
142 set_race(creature_ptr);
145 void rd_bounty_uniques(player_type *creature_ptr)
147 if (h_older_than(0, 0, 3)) {
148 set_zangband_bounty_uniques(creature_ptr);
152 for (int i = 0; i < MAX_BOUNTY; i++)
153 rd_s16b(¤t_world_ptr->bounty_r_idx[i]);
157 * @brief 腕力などの基本ステータス情報を読み込む
158 * @param creature_ptr プレーヤーへの参照ポインタ
161 static void rd_base_status(player_type *creature_ptr)
163 for (int i = 0; i < A_MAX; i++)
164 rd_s16b(&creature_ptr->stat_max[i]);
166 for (int i = 0; i < A_MAX; i++)
167 rd_s16b(&creature_ptr->stat_max_max[i]);
169 for (int i = 0; i < A_MAX; i++)
170 rd_s16b(&creature_ptr->stat_cur[i]);
173 static void set_imitation(player_type *creature_ptr)
175 if (h_older_than(0, 0, 1)) {
176 for (int i = 0; i < MAX_MANE; i++) {
177 creature_ptr->mane_spell[i] = -1;
178 creature_ptr->mane_dam[i] = 0;
181 creature_ptr->mane_num = 0;
185 if (h_older_than(0, 2, 3)) {
187 const int OLD_MAX_MANE = 22;
188 for (int i = 0; i < OLD_MAX_MANE; i++) {
193 for (int i = 0; i < MAX_MANE; i++) {
194 creature_ptr->mane_spell[i] = -1;
195 creature_ptr->mane_dam[i] = 0;
199 creature_ptr->mane_num = 0;
203 for (int i = 0; i < MAX_MANE; i++) {
206 creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
208 creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
211 rd_s16b(&creature_ptr->mane_num);
214 static void rd_phase_out(player_type *creature_ptr)
218 creature_ptr->current_floor_ptr->inside_arena = (bool)tmp16s;
219 rd_s16b(&creature_ptr->current_floor_ptr->inside_quest);
220 if (h_older_than(0, 3, 5))
221 creature_ptr->phase_out = FALSE;
224 creature_ptr->phase_out = (bool)tmp16s;
228 static void rd_arena(player_type *creature_ptr)
230 if (h_older_than(0, 0, 3))
231 update_gambling_monsters(creature_ptr);
233 set_gambling_monsters();
235 rd_s16b(&creature_ptr->town_num);
236 rd_s16b(&creature_ptr->arena_number);
237 if (h_older_than(1, 5, 0, 1))
238 if (creature_ptr->arena_number >= 99)
239 creature_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
241 rd_phase_out(creature_ptr);
243 rd_byte(&creature_ptr->exit_bldg);
248 creature_ptr->oldpx = (POSITION)tmp16s;
250 creature_ptr->oldpy = (POSITION)tmp16s;
251 if (h_older_than(0, 3, 13) && !is_in_dungeon(creature_ptr) && !creature_ptr->current_floor_ptr->inside_arena) {
252 creature_ptr->oldpy = 33;
253 creature_ptr->oldpx = 131;
258 * @brief プレーヤーの最大HP/現在HPを読み込む
259 * @param creature_ptr プレーヤーへの参照ポインタ
262 static void rd_hp(player_type *creature_ptr)
264 if (h_older_than(1, 7, 0, 3)) {
265 set_hp_old(creature_ptr);
269 rd_s32b(&creature_ptr->mhp);
270 rd_s32b(&creature_ptr->chp);
271 rd_u32b(&creature_ptr->chp_frac);
275 * @brief プレーヤーの最大MP/現在MPを読み込む
276 * @param creature_ptr プレーヤーへの参照ポインタ
279 static void rd_mana(player_type *creature_ptr)
281 if (h_older_than(1, 7, 0, 3)) {
282 set_mana_old(creature_ptr);
286 rd_s32b(&creature_ptr->msp);
287 rd_s32b(&creature_ptr->csp);
288 rd_u32b(&creature_ptr->csp_frac);
292 * @brief プレーヤーのバッドステータス (と空腹)を読み込む
293 * @param creature_ptr プレーヤーへの参照ポインタ
296 static void rd_bad_status(player_type *creature_ptr)
298 strip_bytes(2); /* Old "rest" */
299 rd_s16b(&creature_ptr->blind);
300 rd_s16b(&creature_ptr->paralyzed);
301 rd_s16b(&creature_ptr->confused);
302 rd_s16b(&creature_ptr->food);
303 strip_bytes(4); /* Old "food_digested" / "protection" */
306 static void rd_energy(player_type *creature_ptr)
308 rd_s16b(&creature_ptr->energy_need);
309 if (h_older_than(1, 0, 13))
310 creature_ptr->energy_need = 100 - creature_ptr->energy_need;
312 if (h_older_than(2, 1, 2, 0))
313 creature_ptr->enchant_energy_need = 0;
315 rd_s16b(&creature_ptr->enchant_energy_need);
319 * @brief プレーヤーのグッド/バッドステータスを読み込む
320 * @param creature_ptr プレーヤーへの参照ポインタ
322 * @todo 明らかに関数名がビッグワードだが他に思いつかなかった
324 static void rd_status(player_type *creature_ptr)
326 rd_s16b(&creature_ptr->fast);
327 rd_s16b(&creature_ptr->slow);
328 rd_s16b(&creature_ptr->afraid);
329 rd_s16b(&creature_ptr->cut);
330 rd_s16b(&creature_ptr->stun);
331 rd_s16b(&creature_ptr->poisoned);
332 rd_s16b(&creature_ptr->image);
333 rd_s16b(&creature_ptr->protevil);
334 rd_s16b(&creature_ptr->invuln);
335 if (h_older_than(0, 0, 0))
336 creature_ptr->ult_res = 0;
338 rd_s16b(&creature_ptr->ult_res);
341 static void rd_tsuyoshi(player_type *creature_ptr)
343 if (h_older_than(0, 0, 2))
344 creature_ptr->tsuyoshi = 0;
346 rd_s16b(&creature_ptr->tsuyoshi);
349 static void set_timed_effects(player_type *creature_ptr)
351 rd_s16b(&creature_ptr->tim_esp);
352 rd_s16b(&creature_ptr->wraith_form);
353 rd_s16b(&creature_ptr->resist_magic);
354 rd_s16b(&creature_ptr->tim_regen);
355 rd_s16b(&creature_ptr->tim_pass_wall);
356 rd_s16b(&creature_ptr->tim_stealth);
357 rd_s16b(&creature_ptr->tim_levitation);
358 rd_s16b(&creature_ptr->tim_sh_touki);
359 rd_s16b(&creature_ptr->lightspeed);
360 rd_s16b(&creature_ptr->tsubureru);
361 if (h_older_than(0, 4, 7))
362 creature_ptr->magicdef = 0;
364 rd_s16b(&creature_ptr->magicdef);
366 rd_s16b(&creature_ptr->tim_res_nether);
367 if (h_older_than(0, 4, 11))
368 set_zangband_mimic(creature_ptr);
370 rd_s16b(&creature_ptr->tim_res_time);
374 creature_ptr->mimic_form = (IDX)tmp8u;
375 rd_s16b(&creature_ptr->tim_mimic);
376 rd_s16b(&creature_ptr->tim_sh_fire);
379 if (h_older_than(1, 0, 99))
380 set_zangband_holy_aura(creature_ptr);
382 rd_s16b(&creature_ptr->tim_sh_holy);
383 rd_s16b(&creature_ptr->tim_eyeeye);
386 if (h_older_than(1, 0, 3))
387 set_zangband_reflection(creature_ptr);
389 rd_s16b(&creature_ptr->tim_reflect);
390 rd_s16b(&creature_ptr->multishadow);
391 rd_s16b(&creature_ptr->dustrobe);
395 static void set_mutations(player_type *creature_ptr)
397 if (loading_savefile_version_is_older_than(2)) {
398 for (int i = 0; i < 3; i++) {
401 std::bitset<32> rd_bits(tmp32u);
402 for (size_t j = 0; j < rd_bits.size(); j++) {
403 size_t pos = i * rd_bits.size() + j;
404 if (pos < creature_ptr->muta.size()) {
405 auto f = static_cast<MUTA>(pos);
406 creature_ptr->muta[f] = rd_bits[j];
411 rd_FlagGroup(creature_ptr->muta, rd_byte);
415 static void set_virtues(player_type *creature_ptr)
417 for (int i = 0; i < 8; i++)
418 rd_s16b(&creature_ptr->virtues[i]);
420 for (int i = 0; i < 8; i++)
421 rd_s16b(&creature_ptr->vir_types[i]);
426 * @param creature_ptr プレーヤーへの参照ポインタ
429 static void rd_timed_effects(player_type *creature_ptr)
431 set_timed_effects(creature_ptr);
432 rd_s16b(&creature_ptr->chaos_patron);
433 set_mutations(creature_ptr);
434 set_virtues(creature_ptr);
437 static void rd_player_status(player_type *creature_ptr)
439 rd_base_status(creature_ptr);
441 rd_s32b(&creature_ptr->au);
442 rd_experience(creature_ptr);
443 rd_skills(creature_ptr);
444 rd_race(creature_ptr);
445 set_imitation(creature_ptr);
446 rd_bounty_uniques(creature_ptr);
447 rd_arena(creature_ptr);
450 rd_mana(creature_ptr);
451 rd_s16b(&creature_ptr->max_plv);
452 rd_dungeons(creature_ptr);
454 rd_s16b(&creature_ptr->sc);
455 rd_s16b(&creature_ptr->concent);
456 rd_bad_status(creature_ptr);
457 rd_energy(creature_ptr);
458 rd_status(creature_ptr);
459 rd_s16b(&creature_ptr->hero);
460 rd_s16b(&creature_ptr->shero);
461 rd_s16b(&creature_ptr->shield);
462 rd_s16b(&creature_ptr->blessed);
463 rd_s16b(&creature_ptr->tim_invis);
464 rd_s16b(&creature_ptr->word_recall);
465 rd_alter_reality(creature_ptr);
466 rd_s16b(&creature_ptr->see_infra);
467 rd_s16b(&creature_ptr->tim_infra);
468 rd_s16b(&creature_ptr->oppose_fire);
469 rd_s16b(&creature_ptr->oppose_cold);
470 rd_s16b(&creature_ptr->oppose_acid);
471 rd_s16b(&creature_ptr->oppose_elec);
472 rd_s16b(&creature_ptr->oppose_pois);
473 rd_tsuyoshi(creature_ptr);
474 rd_timed_effects(creature_ptr);
475 creature_ptr->mutant_regenerate_mod = calc_mutant_regenerate_mod(creature_ptr);
478 void rd_player_info(player_type *creature_ptr)
480 rd_player_status(creature_ptr);
481 rd_special_attack(creature_ptr);
482 rd_special_action(creature_ptr);
483 rd_special_defense(creature_ptr);
484 rd_byte(&creature_ptr->knowledge);
485 rd_autopick(creature_ptr);
486 rd_action(creature_ptr);