OSDN Git Service

Merge pull request #716 from sikabane-works/release/3.0.0Alpha16
[hengbandforosx/hengbandosx.git] / src / load / player-info-loader.cpp
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"
18
19 void rd_base_info(player_type *creature_ptr)
20 {
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)) {
24         char buf[1024];
25         rd_string(buf, sizeof buf);
26         if (buf[0])
27             creature_ptr->last_message = string_make(buf);
28     }
29
30     load_quick_start();
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]));
34
35     byte tmp8u;
36     rd_byte(&tmp8u);
37     creature_ptr->prace = (player_race_type)tmp8u;
38
39     rd_byte(&tmp8u);
40     creature_ptr->pclass = (player_class_type)tmp8u;
41
42     rd_byte(&tmp8u);
43     creature_ptr->pseikaku = (player_personality_type)tmp8u;
44
45     rd_byte(&creature_ptr->psex);
46     rd_byte(&tmp8u);
47     creature_ptr->realm1 = (REALM_IDX)tmp8u;
48
49     rd_byte(&tmp8u);
50     creature_ptr->realm2 = (REALM_IDX)tmp8u;
51
52     rd_byte(&tmp8u);
53     if (h_older_than(0, 4, 4))
54         set_zangband_realm(creature_ptr);
55
56     rd_byte(&tmp8u);
57     creature_ptr->hitdie = (DICE_SID)tmp8u;
58     rd_u16b(&creature_ptr->expfact);
59
60     rd_s16b(&creature_ptr->age);
61     rd_s16b(&creature_ptr->ht);
62     rd_s16b(&creature_ptr->wt);
63 }
64
65 void rd_experience(player_type *creature_ptr)
66 {
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;
70     else
71         rd_s32b(&creature_ptr->max_max_exp);
72
73     rd_s32b(&creature_ptr->exp);
74     if (h_older_than(1, 7, 0, 3))
75         set_exp_frac_old(creature_ptr);
76     else
77         rd_u32b(&creature_ptr->exp_frac);
78
79     rd_s16b(&creature_ptr->lev);
80     for (int i = 0; i < 64; i++)
81         rd_s16b(&creature_ptr->spell_exp[i]);
82
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;
86
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]);
91
92     for (int i = 0; i < GINOU_MAX; i++)
93         rd_s16b(&creature_ptr->skill_exp[i]);
94 }
95
96 static void set_spells(player_type *creature_ptr)
97 {
98     for (int i = 0; i < MAX_SPELLS; i++)
99         rd_s32b(&creature_ptr->magic_num1[i]);
100
101     for (int i = 0; i < MAX_SPELLS; i++)
102         rd_byte(&creature_ptr->magic_num2[i]);
103
104     if (h_older_than(1, 3, 0, 1))
105         set_spells_old(creature_ptr);
106 }
107
108 void rd_skills(player_type *creature_ptr)
109 {
110     if (h_older_than(0, 4, 1))
111         set_zangband_skill(creature_ptr);
112
113     if (h_older_than(0, 3, 14))
114         set_zangband_spells(creature_ptr);
115     else
116         set_spells(creature_ptr);
117
118     if (music_singing_any(creature_ptr))
119         creature_ptr->action = ACTION_SING;
120 }
121
122 static void set_race(player_type *creature_ptr)
123 {
124     byte tmp8u;
125     rd_byte(&tmp8u);
126     creature_ptr->start_race = (player_race_type)tmp8u;
127     s32b tmp32s;
128     rd_s32b(&tmp32s);
129     creature_ptr->old_race1 = (BIT_FLAGS)tmp32s;
130     rd_s32b(&tmp32s);
131     creature_ptr->old_race2 = (BIT_FLAGS)tmp32s;
132     rd_s16b(&creature_ptr->old_realm);
133 }
134
135 void rd_race(player_type *creature_ptr)
136 {
137     if (h_older_than(1, 0, 7)) {
138         set_zangband_race(creature_ptr);
139         return;
140     }
141
142     set_race(creature_ptr);
143 }
144
145 void rd_bounty_uniques(player_type *creature_ptr)
146 {
147     if (h_older_than(0, 0, 3)) {
148         set_zangband_bounty_uniques(creature_ptr);
149         return;
150     }
151
152     for (int i = 0; i < MAX_BOUNTY; i++)
153         rd_s16b(&current_world_ptr->bounty_r_idx[i]);
154 }
155
156 /*!
157  * @brief 腕力などの基本ステータス情報を読み込む
158  * @param creature_ptr プレーヤーへの参照ポインタ
159  * @return なし
160  */
161 static void rd_base_status(player_type *creature_ptr)
162 {
163     for (int i = 0; i < A_MAX; i++)
164         rd_s16b(&creature_ptr->stat_max[i]);
165
166     for (int i = 0; i < A_MAX; i++)
167         rd_s16b(&creature_ptr->stat_max_max[i]);
168
169     for (int i = 0; i < A_MAX; i++)
170         rd_s16b(&creature_ptr->stat_cur[i]);
171 }
172
173 static void set_imitation(player_type *creature_ptr)
174 {
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;
179         }
180
181         creature_ptr->mane_num = 0;
182         return;
183     }
184
185     if (h_older_than(0, 2, 3)) {
186         s16b tmp16s;
187         const int OLD_MAX_MANE = 22;
188         for (int i = 0; i < OLD_MAX_MANE; i++) {
189             rd_s16b(&tmp16s);
190             rd_s16b(&tmp16s);
191         }
192
193         for (int i = 0; i < MAX_MANE; i++) {
194             creature_ptr->mane_spell[i] = -1;
195             creature_ptr->mane_dam[i] = 0;
196         }
197
198         rd_s16b(&tmp16s);
199         creature_ptr->mane_num = 0;
200         return;
201     }
202
203     for (int i = 0; i < MAX_MANE; i++) {
204         s16b tmp16s;
205         rd_s16b(&tmp16s);
206         creature_ptr->mane_spell[i] = (SPELL_IDX)tmp16s;
207         rd_s16b(&tmp16s);
208         creature_ptr->mane_dam[i] = (SPELL_IDX)tmp16s;
209     }
210
211     rd_s16b(&creature_ptr->mane_num);
212 }
213
214 static void rd_phase_out(player_type *creature_ptr)
215 {
216     s16b tmp16s;
217     rd_s16b(&tmp16s);
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;
222     else {
223         rd_s16b(&tmp16s);
224         creature_ptr->phase_out = (bool)tmp16s;
225     }
226 }
227
228 static void rd_arena(player_type *creature_ptr)
229 {
230     if (h_older_than(0, 0, 3))
231         update_gambling_monsters(creature_ptr);
232     else
233         set_gambling_monsters();
234
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;
240
241     rd_phase_out(creature_ptr);
242     byte tmp8u;
243     rd_byte(&creature_ptr->exit_bldg);
244     rd_byte(&tmp8u);
245
246     s16b tmp16s;
247     rd_s16b(&tmp16s);
248     creature_ptr->oldpx = (POSITION)tmp16s;
249     rd_s16b(&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;
254     }
255 }
256
257 /*!
258  * @brief プレーヤーの最大HP/現在HPを読み込む
259  * @param creature_ptr プレーヤーへの参照ポインタ
260  * @return なし
261  */
262 static void rd_hp(player_type *creature_ptr)
263 {
264     if (h_older_than(1, 7, 0, 3)) {
265         set_hp_old(creature_ptr);
266         return;
267     }
268
269     rd_s32b(&creature_ptr->mhp);
270     rd_s32b(&creature_ptr->chp);
271     rd_u32b(&creature_ptr->chp_frac);
272 }
273
274 /*!
275  * @brief プレーヤーの最大MP/現在MPを読み込む
276  * @param creature_ptr プレーヤーへの参照ポインタ
277  * @return なし
278  */
279 static void rd_mana(player_type *creature_ptr)
280 {
281     if (h_older_than(1, 7, 0, 3)) {
282         set_mana_old(creature_ptr);
283         return;
284     }
285
286     rd_s32b(&creature_ptr->msp);
287     rd_s32b(&creature_ptr->csp);
288     rd_u32b(&creature_ptr->csp_frac);
289 }
290
291 /*!
292  * @brief プレーヤーのバッドステータス (と空腹)を読み込む
293  * @param creature_ptr プレーヤーへの参照ポインタ
294  * @return なし
295  */
296 static void rd_bad_status(player_type *creature_ptr)
297 {
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" */
304 }
305
306 static void rd_energy(player_type *creature_ptr)
307 {
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;
311
312     if (h_older_than(2, 1, 2, 0))
313         creature_ptr->enchant_energy_need = 0;
314     else
315         rd_s16b(&creature_ptr->enchant_energy_need);
316 }
317
318 /*!
319  * @brief プレーヤーのグッド/バッドステータスを読み込む
320  * @param creature_ptr プレーヤーへの参照ポインタ
321  * @return なし
322  * @todo 明らかに関数名がビッグワードだが他に思いつかなかった
323  */
324 static void rd_status(player_type *creature_ptr)
325 {
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;
337     else
338         rd_s16b(&creature_ptr->ult_res);
339 }
340
341 static void rd_tsuyoshi(player_type *creature_ptr)
342 {
343     if (h_older_than(0, 0, 2))
344         creature_ptr->tsuyoshi = 0;
345     else
346         rd_s16b(&creature_ptr->tsuyoshi);
347 }
348
349 static void set_timed_effects(player_type *creature_ptr)
350 {
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;
363     else
364         rd_s16b(&creature_ptr->magicdef);
365
366     rd_s16b(&creature_ptr->tim_res_nether);
367     if (h_older_than(0, 4, 11))
368         set_zangband_mimic(creature_ptr);
369     else {
370         rd_s16b(&creature_ptr->tim_res_time);
371
372         byte tmp8u;
373         rd_byte(&tmp8u);
374         creature_ptr->mimic_form = (IDX)tmp8u;
375         rd_s16b(&creature_ptr->tim_mimic);
376         rd_s16b(&creature_ptr->tim_sh_fire);
377     }
378
379     if (h_older_than(1, 0, 99))
380         set_zangband_holy_aura(creature_ptr);
381     else {
382         rd_s16b(&creature_ptr->tim_sh_holy);
383         rd_s16b(&creature_ptr->tim_eyeeye);
384     }
385
386     if (h_older_than(1, 0, 3))
387         set_zangband_reflection(creature_ptr);
388     else {
389         rd_s16b(&creature_ptr->tim_reflect);
390         rd_s16b(&creature_ptr->multishadow);
391         rd_s16b(&creature_ptr->dustrobe);
392     }
393 }
394
395 static void set_mutations(player_type *creature_ptr)
396 {
397     if (loading_savefile_version_is_older_than(2)) {
398         for (int i = 0; i < 3; i++) {
399             u32b tmp32u;
400             rd_u32b(&tmp32u);
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];
407                 }
408             }
409         }
410     } else {
411         rd_FlagGroup(creature_ptr->muta, rd_byte);
412     }
413 }
414
415 static void set_virtues(player_type *creature_ptr)
416 {
417     for (int i = 0; i < 8; i++)
418         rd_s16b(&creature_ptr->virtues[i]);
419
420     for (int i = 0; i < 8; i++)
421         rd_s16b(&creature_ptr->vir_types[i]);
422 }
423
424 /*!
425  * @brief 各種時限効果を読み込む
426  * @param creature_ptr プレーヤーへの参照ポインタ
427  * @return なし
428  */
429 static void rd_timed_effects(player_type *creature_ptr)
430 {
431     set_timed_effects(creature_ptr);
432     rd_s16b(&creature_ptr->chaos_patron);
433     set_mutations(creature_ptr);
434     set_virtues(creature_ptr);
435 }
436
437 static void rd_player_status(player_type *creature_ptr)
438 {
439     rd_base_status(creature_ptr);
440     strip_bytes(24);
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);
448     rd_dummy1();
449     rd_hp(creature_ptr);
450     rd_mana(creature_ptr);
451     rd_s16b(&creature_ptr->max_plv);
452     rd_dungeons(creature_ptr);
453     strip_bytes(8);
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);
476 }
477
478 void rd_player_info(player_type *creature_ptr)
479 {
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);
487 }