OSDN Git Service

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