OSDN Git Service

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