OSDN Git Service

[Refactor] #1489 Moved player-class.* and player-class-types.h to player-info/
[hengbandforosx/hengbandosx.git] / src / spell / spells-status.cpp
1 /*!
2  * @brief スピード等のステータスに影響のある魔法の処理
3  * @date 2019/01/22
4  * @author deskull
5  */
6
7 #include "spell/spells-status.h"
8 #include "avatar/avatar.h"
9 #include "cmd-action/cmd-spell.h"
10 #include "cmd-item/cmd-magiceat.h"
11 #include "core/player-redraw-types.h"
12 #include "core/player-update-types.h"
13 #include "core/stuff-handler.h"
14 #include "core/window-redrawer.h"
15 #include "effect/effect-characteristics.h"
16 #include "flavor/flavor-describer.h"
17 #include "flavor/object-flavor-types.h"
18 #include "floor/cave.h"
19 #include "floor/floor-object.h"
20 #include "floor/geometry.h"
21 #include "grid/feature-flag-types.h"
22 #include "hpmp/hp-mp-processor.h"
23 #include "inventory/inventory-object.h"
24 #include "inventory/inventory-slot-types.h"
25 #include "main/sound-definitions-table.h"
26 #include "main/sound-of-music.h"
27 #include "mind/mind-force-trainer.h"
28 #include "monster/monster-describer.h"
29 #include "object/object-kind-hook.h"
30 #include "object/object-kind.h"
31 #include "player-info/class-info.h"
32 #include "player-status/player-energy.h"
33 #include "player/attack-defense-types.h"
34 #include "spell-kind/spells-launcher.h"
35 #include "spell-kind/spells-teleport.h"
36 #include "spell-kind/spells-world.h"
37 #include "spell/spell-types.h"
38 #include "status/action-setter.h"
39 #include "status/bad-status-setter.h"
40 #include "status/base-status.h"
41 #include "status/body-improvement.h"
42 #include "status/buff-setter.h"
43 #include "status/experience.h"
44 #include "status/shape-changer.h"
45 #include "status/sight-setter.h"
46 #include "system/floor-type-definition.h"
47 #include "system/grid-type-definition.h"
48 #include "system/monster-type-definition.h"
49 #include "system/object-type-definition.h"
50 #include "system/player-type-definition.h"
51 #include "target/target-getter.h"
52 #include "util/bit-flags-calculator.h"
53 #include "view/display-messages.h"
54
55 /*!
56  * @brief モンスター回復処理
57  * @param caster_ptr プレーヤーへの参照ポインタ
58  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
59  * @param dam 威力
60  * @return 作用が実際にあった場合TRUEを返す
61  */
62 bool heal_monster(player_type *caster_ptr, DIRECTION dir, HIT_POINT dam)
63 {
64     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
65     return (project_hook(caster_ptr, GF_OLD_HEAL, dir, dam, flg));
66 }
67
68 /*!
69  * @brief モンスター加速処理
70  * @param caster_ptr プレーヤーへの参照ポインタ
71  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
72  * @param power 効力
73  * @return 作用が実際にあった場合TRUEを返す
74  */
75 bool speed_monster(player_type *caster_ptr, DIRECTION dir, int power)
76 {
77     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
78     return (project_hook(caster_ptr, GF_OLD_SPEED, dir, power, flg));
79 }
80
81 /*!
82  * @brief モンスター減速処理
83  * @param caster_ptr プレーヤーへの参照ポインタ
84  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
85  * @param power 効力
86  * @return 作用が実際にあった場合TRUEを返す
87  */
88 bool slow_monster(player_type *caster_ptr, DIRECTION dir, int power)
89 {
90     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
91     return (project_hook(caster_ptr, GF_OLD_SLOW, dir, power, flg));
92 }
93
94 /*!
95  * @brief モンスター催眠処理
96  * @param caster_ptr プレーヤーへの参照ポインタ
97  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
98  * @param power 効力
99  * @return 作用が実際にあった場合TRUEを返す
100  */
101 bool sleep_monster(player_type *caster_ptr, DIRECTION dir, int power)
102 {
103     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
104     return (project_hook(caster_ptr, GF_OLD_SLEEP, dir, power, flg));
105 }
106
107 /*!
108  * @brief モンスター拘束(STASIS)処理
109  * @param caster_ptr プレーヤーへの参照ポインタ
110  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
111  * @return 作用が実際にあった場合TRUEを返す
112  * @details 威力はプレイヤーレベル*2に固定
113  */
114 bool stasis_monster(player_type *caster_ptr, DIRECTION dir)
115 {
116     return (fire_ball_hide(caster_ptr, GF_STASIS, dir, caster_ptr->lev * 2, 0));
117 }
118
119 /*!
120  * @brief 邪悪なモンスター拘束(STASIS)処理
121  * @param caster_ptr プレーヤーへの参照ポインタ
122  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
123  * @return 作用が実際にあった場合TRUEを返す
124  * @details 威力はプレイヤーレベル*2に固定
125  */
126 bool stasis_evil(player_type *caster_ptr, DIRECTION dir)
127 {
128     return (fire_ball_hide(caster_ptr, GF_STASIS_EVIL, dir, caster_ptr->lev * 2, 0));
129 }
130
131 /*!
132  * @brief モンスター混乱処理
133  * @param caster_ptr プレーヤーへの参照ポインタ
134  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
135  * @param plev プレイヤーレベル(=効力)
136  * @return 作用が実際にあった場合TRUEを返す
137  */
138 bool confuse_monster(player_type *caster_ptr, DIRECTION dir, PLAYER_LEVEL plev)
139 {
140     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
141     return (project_hook(caster_ptr, GF_OLD_CONF, dir, plev, flg));
142 }
143
144 /*!
145  * @brief モンスター朦朧処理
146  * @param caster_ptr プレーヤーへの参照ポインタ
147  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
148  * @param plev プレイヤーレベル(=効力)
149  * @return 作用が実際にあった場合TRUEを返す
150  */
151 bool stun_monster(player_type *caster_ptr, DIRECTION dir, PLAYER_LEVEL plev)
152 {
153     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
154     return (project_hook(caster_ptr, GF_STUN, dir, plev, flg));
155 }
156
157 /*!
158  * @brief チェンジモンスター処理
159  * @param caster_ptr プレーヤーへの参照ポインタ
160  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
161  * @param power 効力
162  * @return 作用が実際にあった場合TRUEを返す
163  */
164 bool poly_monster(player_type *caster_ptr, DIRECTION dir, int power)
165 {
166     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
167     bool tester = (project_hook(caster_ptr, GF_OLD_POLY, dir, power, flg));
168     if (tester)
169         chg_virtue(caster_ptr, V_CHANCE, 1);
170     return (tester);
171 }
172
173 /*!
174  * @brief クローンモンスター処理
175  * @param caster_ptr プレーヤーへの参照ポインタ
176  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
177  * @return 作用が実際にあった場合TRUEを返す
178  */
179 bool clone_monster(player_type *caster_ptr, DIRECTION dir)
180 {
181     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
182     return (project_hook(caster_ptr, GF_OLD_CLONE, dir, 0, flg));
183 }
184
185 /*!
186  * @brief モンスター恐慌処理
187  * @param caster_ptr プレーヤーへの参照ポインタ
188  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
189  * @param plev プレイヤーレベル(=効力)
190  * @return 作用が実際にあった場合TRUEを返す
191  */
192 bool fear_monster(player_type *caster_ptr, DIRECTION dir, PLAYER_LEVEL plev)
193 {
194     BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
195     return (project_hook(caster_ptr, GF_TURN_ALL, dir, plev, flg));
196 }
197
198 bool time_walk(player_type *creature_ptr)
199 {
200     if (creature_ptr->timewalk) {
201         msg_print(_("既に時は止まっている。", "Time is already stopped."));
202         return false;
203     }
204
205     creature_ptr->timewalk = true;
206     msg_print(_("「時よ!」", "You yell 'Time!'"));
207     //  msg_print(_("「『ザ・ワールド』!時は止まった!」", "You yell 'The World! Time has stopped!'"));
208     msg_print(nullptr);
209
210     creature_ptr->energy_need -= 1000 + (100 + creature_ptr->csp - 50) * TURNS_PER_TICK / 10;
211     creature_ptr->redraw |= (PR_MAP);
212     creature_ptr->update |= (PU_MONSTERS);
213     creature_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
214     handle_stuff(creature_ptr);
215     return true;
216 }
217
218 /*!
219  * @brief プレイヤーのヒットダイスを振る / Role Hitpoints
220  * @param creature_ptr プレーヤーへの参照ポインタ
221  * @param options スペル共通オプション
222  */
223 void roll_hitdice(player_type *creature_ptr, spell_operation options)
224 {
225     HIT_POINT min_value = creature_ptr->hitdie + ((PY_MAX_LEVEL + 2) * (creature_ptr->hitdie + 1)) * 3 / 8;
226     HIT_POINT max_value = creature_ptr->hitdie + ((PY_MAX_LEVEL + 2) * (creature_ptr->hitdie + 1)) * 5 / 8;
227
228     /* Rerate */
229     while (true) {
230         /* Pre-calculate level 1 hitdice */
231         creature_ptr->player_hp[0] = (HIT_POINT)creature_ptr->hitdie;
232
233         for (int i = 1; i < 4; i++) {
234             creature_ptr->player_hp[0] += randint1(creature_ptr->hitdie);
235         }
236
237         /* Roll the hitpoint values */
238         for (int i = 1; i < PY_MAX_LEVEL; i++) {
239             creature_ptr->player_hp[i] = creature_ptr->player_hp[i - 1] + randint1(creature_ptr->hitdie);
240         }
241
242         /* Require "valid" hitpoints at highest level */
243         if ((creature_ptr->player_hp[PY_MAX_LEVEL - 1] >= min_value) && (creature_ptr->player_hp[PY_MAX_LEVEL - 1] <= max_value))
244             break;
245     }
246
247     creature_ptr->knowledge &= ~(KNOW_HPRATE);
248
249     PERCENTAGE percent
250         = (int)(((long)creature_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) / (2 * creature_ptr->hitdie + ((PY_MAX_LEVEL - 1 + 3) * (creature_ptr->hitdie + 1))));
251
252     /* Update and redraw hitpoints */
253     creature_ptr->update |= (PU_HP);
254     creature_ptr->redraw |= (PR_HP);
255     creature_ptr->window_flags |= (PW_PLAYER);
256
257     if (!(options & SPOP_NO_UPDATE))
258         handle_stuff(creature_ptr);
259
260     if (!(options & SPOP_DISPLAY_MES))
261         return;
262
263     if (options & SPOP_DEBUG) {
264         msg_format(_("現在の体力ランクは %d/100 です。", "Your life rate is %d/100 now."), percent);
265         creature_ptr->knowledge |= KNOW_HPRATE;
266         return;
267     }
268
269     msg_print(_("体力ランクが変わった。", "Life rate has changed."));
270 }
271
272 bool life_stream(player_type *creature_ptr, bool message, bool virtue_change)
273 {
274     if (virtue_change) {
275         chg_virtue(creature_ptr, V_VITALITY, 1);
276         chg_virtue(creature_ptr, V_UNLIFE, -5);
277     }
278
279     if (message) {
280         msg_print(_("体中に生命力が満ちあふれてきた!", "You feel life flow through your body!"));
281     }
282
283     restore_level(creature_ptr);
284     (void)set_poisoned(creature_ptr, 0);
285     (void)set_blind(creature_ptr, 0);
286     (void)set_confused(creature_ptr, 0);
287     (void)set_image(creature_ptr, 0);
288     (void)set_stun(creature_ptr, 0);
289     (void)set_cut(creature_ptr, 0);
290     (void)set_paralyzed(creature_ptr, 0);
291     (void)restore_all_status(creature_ptr);
292     (void)set_shero(creature_ptr, 0, true);
293     handle_stuff(creature_ptr);
294     hp_player(creature_ptr, 5000);
295
296     return true;
297 }
298
299 bool heroism(player_type *creature_ptr, int base)
300 {
301     bool ident = false;
302     if (set_afraid(creature_ptr, 0))
303         ident = true;
304     if (set_hero(creature_ptr, creature_ptr->hero + randint1(base) + base, false))
305         ident = true;
306     if (hp_player(creature_ptr, 10))
307         ident = true;
308     return ident;
309 }
310
311 bool berserk(player_type *creature_ptr, int base)
312 {
313     bool ident = false;
314     if (set_afraid(creature_ptr, 0))
315         ident = true;
316     if (set_shero(creature_ptr, creature_ptr->shero + randint1(base) + base, false))
317         ident = true;
318     if (hp_player(creature_ptr, 30))
319         ident = true;
320     return ident;
321 }
322
323 bool cure_light_wounds(player_type *creature_ptr, DICE_NUMBER dice, DICE_SID sides)
324 {
325     bool ident = false;
326     if (hp_player(creature_ptr, damroll(dice, sides)))
327         ident = true;
328     if (set_blind(creature_ptr, 0))
329         ident = true;
330     if (set_cut(creature_ptr, creature_ptr->cut - 10))
331         ident = true;
332     if (set_shero(creature_ptr, 0, true))
333         ident = true;
334     return ident;
335 }
336
337 bool cure_serious_wounds(player_type *creature_ptr, DICE_NUMBER dice, DICE_SID sides)
338 {
339     bool ident = false;
340     if (hp_player(creature_ptr, damroll(dice, sides)))
341         ident = true;
342     if (set_blind(creature_ptr, 0))
343         ident = true;
344     if (set_confused(creature_ptr, 0))
345         ident = true;
346     if (set_cut(creature_ptr, (creature_ptr->cut / 2) - 50))
347         ident = true;
348     if (set_shero(creature_ptr, 0, true))
349         ident = true;
350     return ident;
351 }
352
353 bool cure_critical_wounds(player_type *creature_ptr, HIT_POINT pow)
354 {
355     bool ident = false;
356     if (hp_player(creature_ptr, pow))
357         ident = true;
358     if (set_blind(creature_ptr, 0))
359         ident = true;
360     if (set_confused(creature_ptr, 0))
361         ident = true;
362     if (set_poisoned(creature_ptr, 0))
363         ident = true;
364     if (set_stun(creature_ptr, 0))
365         ident = true;
366     if (set_cut(creature_ptr, 0))
367         ident = true;
368     if (set_shero(creature_ptr, 0, true))
369         ident = true;
370     return ident;
371 }
372
373 bool true_healing(player_type *creature_ptr, HIT_POINT pow)
374 {
375     bool ident = false;
376     if (hp_player(creature_ptr, pow))
377         ident = true;
378     if (set_blind(creature_ptr, 0))
379         ident = true;
380     if (set_confused(creature_ptr, 0))
381         ident = true;
382     if (set_poisoned(creature_ptr, 0))
383         ident = true;
384     if (set_stun(creature_ptr, 0))
385         ident = true;
386     if (set_cut(creature_ptr, 0))
387         ident = true;
388     if (set_image(creature_ptr, 0))
389         ident = true;
390     return ident;
391 }
392
393 bool restore_mana(player_type *creature_ptr, bool magic_eater)
394 {
395     if (creature_ptr->pclass == CLASS_MAGIC_EATER && magic_eater) {
396         int i;
397         for (i = 0; i < EATER_EXT * 2; i++) {
398             creature_ptr->magic_num1[i] += (creature_ptr->magic_num2[i] < 10) ? EATER_CHARGE * 3 : creature_ptr->magic_num2[i] * EATER_CHARGE / 3;
399             if (creature_ptr->magic_num1[i] > creature_ptr->magic_num2[i] * EATER_CHARGE)
400                 creature_ptr->magic_num1[i] = creature_ptr->magic_num2[i] * EATER_CHARGE;
401         }
402
403         for (; i < EATER_EXT * 3; i++) {
404             KIND_OBJECT_IDX k_idx = lookup_kind(TV_ROD, i - EATER_EXT * 2);
405             creature_ptr->magic_num1[i]
406                 -= ((creature_ptr->magic_num2[i] < 10) ? EATER_ROD_CHARGE * 3 : creature_ptr->magic_num2[i] * EATER_ROD_CHARGE / 3) * k_info[k_idx].pval;
407             if (creature_ptr->magic_num1[i] < 0)
408                 creature_ptr->magic_num1[i] = 0;
409         }
410
411         msg_print(_("頭がハッキリとした。", "You feel your head clear."));
412         creature_ptr->window_flags |= (PW_PLAYER);
413         return true;
414     }
415
416     if (creature_ptr->csp >= creature_ptr->msp)
417         return false;
418
419     creature_ptr->csp = creature_ptr->msp;
420     creature_ptr->csp_frac = 0;
421     msg_print(_("頭がハッキリとした。", "You feel your head clear."));
422     creature_ptr->redraw |= (PR_MANA);
423     creature_ptr->window_flags |= (PW_PLAYER);
424     creature_ptr->window_flags |= (PW_SPELL);
425     return true;
426 }
427
428 bool restore_all_status(player_type *creature_ptr)
429 {
430     bool ident = false;
431     if (do_res_stat(creature_ptr, A_STR))
432         ident = true;
433     if (do_res_stat(creature_ptr, A_INT))
434         ident = true;
435     if (do_res_stat(creature_ptr, A_WIS))
436         ident = true;
437     if (do_res_stat(creature_ptr, A_DEX))
438         ident = true;
439     if (do_res_stat(creature_ptr, A_CON))
440         ident = true;
441     if (do_res_stat(creature_ptr, A_CHR))
442         ident = true;
443     return ident;
444 }
445
446 bool fishing(player_type *creature_ptr)
447 {
448     DIRECTION dir;
449     if (!get_direction(creature_ptr, &dir, false, false))
450         return false;
451     POSITION y = creature_ptr->y + ddy[dir];
452     POSITION x = creature_ptr->x + ddx[dir];
453     creature_ptr->fishing_dir = dir;
454     if (!cave_has_flag_bold(creature_ptr->current_floor_ptr, y, x, FF::WATER)) {
455         msg_print(_("そこは水辺ではない。", "You can't fish here."));
456         return false;
457     }
458
459     if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
460         GAME_TEXT m_name[MAX_NLEN];
461         monster_desc(creature_ptr, m_name, &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx], 0);
462         msg_format(_("%sが邪魔だ!", "%^s is standing in your way."), m_name);
463         PlayerEnergy(creature_ptr).reset_player_turn();
464         return false;
465     }
466
467     set_action(creature_ptr, ACTION_FISH);
468     creature_ptr->redraw |= (PR_STATE);
469     return true;
470 }
471
472 /*!
473  * @brief 装備を脱ぎ捨てて小宇宙を燃やす
474  * @param creature_ptr プレイヤー情報への参照ポインタ
475  * @param o_ptr_ptr 脱ぐ装備品への参照ポインタのポインタ
476  * @return 脱いだらTRUE、脱がなかったらFALSE
477  * @details
478  * 脱いで落とした装備にtimeoutを設定するために装備品のアドレスを返す。
479  */
480 bool cosmic_cast_off(player_type *creature_ptr, object_type **o_ptr_ptr)
481 {
482     object_type *o_ptr = (*o_ptr_ptr);
483
484     /* Cast off activated item */
485     INVENTORY_IDX slot;
486     for (slot = INVEN_MAIN_HAND; slot <= INVEN_FEET; slot++) {
487         if (o_ptr == &creature_ptr->inventory_list[slot])
488             break;
489     }
490
491     if (slot > INVEN_FEET)
492         return false;
493
494     object_type forge;
495     (&forge)->copy_from(o_ptr);
496     inven_item_increase(creature_ptr, slot, (0 - o_ptr->number));
497     inven_item_optimize(creature_ptr, slot);
498
499     OBJECT_IDX old_o_idx = drop_near(creature_ptr, &forge, 0, creature_ptr->y, creature_ptr->x);
500     *o_ptr_ptr = &creature_ptr->current_floor_ptr->o_list[old_o_idx];
501
502     GAME_TEXT o_name[MAX_NLEN];
503     describe_flavor(creature_ptr, o_name, &forge, OD_NAME_ONLY);
504     msg_format(_("%sを脱ぎ捨てた。", "You cast off %s."), o_name);
505     sound(SOUND_TAKE_OFF);
506
507     /* Get effects */
508     msg_print(_("「燃え上がれ俺の小宇宙!」", "You say, 'Burn up my cosmo!"));
509     int t = 20 + randint1(20);
510     (void)set_blind(creature_ptr, creature_ptr->blind + t);
511     (void)set_afraid(creature_ptr, 0);
512     (void)set_tim_esp(creature_ptr, creature_ptr->tim_esp + t, false);
513     (void)set_tim_regen(creature_ptr, creature_ptr->tim_regen + t, false);
514     (void)set_hero(creature_ptr, creature_ptr->hero + t, false);
515     (void)set_blessed(creature_ptr, creature_ptr->blessed + t, false);
516     (void)set_fast(creature_ptr, creature_ptr->fast + t, false);
517     (void)set_shero(creature_ptr, creature_ptr->shero + t, false);
518     if (creature_ptr->pclass == CLASS_FORCETRAINER) {
519         set_current_ki(creature_ptr, true, creature_ptr->lev * 5 + 190);
520         msg_print(_("気が爆発寸前になった。", "Your force absorbs the explosion."));
521     }
522
523     return true;
524 }
525
526 /*!
527  * @brief プレイヤーの因果混乱処理 / Apply Nexus
528  * @param m_ptr 因果混乱をプレイヤーに与えたモンスターの情報参照ポインタ
529  */
530 void apply_nexus(monster_type *m_ptr, player_type *target_ptr)
531 {
532     switch (randint1(7)) {
533     case 1:
534     case 2:
535     case 3: {
536         teleport_player(target_ptr, 200, TELEPORT_PASSIVE);
537         break;
538     }
539
540     case 4:
541     case 5: {
542         teleport_player_to(target_ptr, m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
543         break;
544     }
545
546     case 6: {
547         if (randint0(100) < target_ptr->skill_sav) {
548             msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
549             break;
550         }
551
552         teleport_level(target_ptr, 0);
553         break;
554     }
555
556     case 7: {
557         if (randint0(100) < target_ptr->skill_sav) {
558             msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
559             break;
560         }
561
562         msg_print(_("体がねじれ始めた...", "Your body starts to scramble..."));
563         status_shuffle(target_ptr);
564         break;
565     }
566     }
567 }
568
569 /*!
570  * @brief プレイヤーのステータスシャッフル処理
571  * @param creature_ptr プレーヤーへの参照ポインタ
572  */
573 void status_shuffle(player_type *creature_ptr)
574 {
575     /* Pick a pair of stats */
576     int i = randint0(A_MAX);
577     int j;
578
579     //!< @todo ここのループは一体何をしている?
580     for (j = i; j == i; j = randint0(A_MAX)) /* loop */
581         ;
582
583     BASE_STATUS max1 = creature_ptr->stat_max[i];
584     BASE_STATUS cur1 = creature_ptr->stat_cur[i];
585     BASE_STATUS max2 = creature_ptr->stat_max[j];
586     BASE_STATUS cur2 = creature_ptr->stat_cur[j];
587
588     creature_ptr->stat_max[i] = max2;
589     creature_ptr->stat_cur[i] = cur2;
590     creature_ptr->stat_max[j] = max1;
591     creature_ptr->stat_cur[j] = cur1;
592
593     for (int k = 0; k < A_MAX; k++) {
594         if (creature_ptr->stat_max[k] > creature_ptr->stat_max_max[k])
595             creature_ptr->stat_max[k] = creature_ptr->stat_max_max[k];
596         if (creature_ptr->stat_cur[k] > creature_ptr->stat_max_max[k])
597             creature_ptr->stat_cur[k] = creature_ptr->stat_max_max[k];
598     }
599
600     creature_ptr->update |= PU_BONUS;
601 }