OSDN Git Service

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