OSDN Git Service

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