OSDN Git Service

[Refactor] #37353 混乱時のコマンド制限処理を cmd_limit_confused() に統合。 / Integrate command limitat...
[hengband/hengband.git] / src / hissatsu.c
1 /*!
2  * @file hissatsu.c
3  * @brief 剣術の実装 / Blade arts
4  * @date 2014/01/17
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7  * This software may be copied and distributed for educational, research,\n
8  * and not for profit purposes provided that this copyright and statement\n
9  * are included in all such copies.  Other copyrights may also apply.\n
10  * 2014 Deskull rearranged comment for Doxygen.\n
11  */
12
13 #include "angband.h"
14 #include "monsterrace-hook.h"
15 #include "player-status.h"
16
17 #define TECHNIC_HISSATSU (REALM_HISSATSU - MIN_TECHNIC)
18
19
20 /*!
21  * @brief 使用可能な剣術を選択する /
22  * Allow user to choose a blade arts.
23  * @param sn 選択した特殊技能ID、キャンセルの場合-1、不正な選択の場合-2を返す
24  * @return 発動可能な魔法を選択した場合TRUE、キャンセル処理か不正な選択が行われた場合FALSEを返す。
25  * @details
26  * If a valid spell is chosen, saves it in '*sn' and returns TRUE\n
27  * If the user hits escape, returns FALSE, and set '*sn' to -1\n
28  * If there are no legal choices, returns FALSE, and sets '*sn' to -2\n
29  *\n
30  * The "prompt" should be "cast", "recite", or "study"\n
31  * The "known" should be TRUE for cast/pray, FALSE for study\n
32  *\n
33  * nb: This function has a (trivial) display bug which will be obvious\n
34  * when you run it. It's probably easy to fix but I haven't tried,\n
35  * sorry.\n
36  */
37 static int get_hissatsu_power(SPELL_IDX *sn)
38 {
39         SPELL_IDX i;
40         int j = 0;
41         int num = 0;
42         POSITION y = 1;
43         POSITION x = 15;
44         PLAYER_LEVEL plev = p_ptr->lev;
45         int ask = TRUE;
46         char choice;
47         char out_val[160];
48         SPELL_IDX sentaku[32];
49         concptr p = _("必殺剣", "special attack");
50         COMMAND_CODE code;
51         magic_type spell;
52         bool flag, redraw;
53         int menu_line = (use_menu ? 1 : 0);
54
55         /* Assume cancelled */
56         *sn = (-1);
57
58         /* Get the spell, if available */
59         if (repeat_pull(&code))
60         {
61                 *sn = (SPELL_IDX)code;
62                 /* Verify the spell */
63                 if (technic_info[TECHNIC_HISSATSU][*sn].slevel <= plev)
64                 {
65                         /* Success */
66                         return (TRUE);
67                 }
68         }
69
70         /* Nothing chosen yet */
71         flag = FALSE;
72
73         /* No redraw yet */
74         redraw = FALSE;
75
76         for (i = 0; i < 32; i++)
77         {
78                 if (technic_info[TECHNIC_HISSATSU][i].slevel <= PY_MAX_LEVEL)
79                 {
80                         sentaku[num] = i;
81                         num++;
82                 }
83         }
84
85         /* Build a prompt (accept all spells) */
86         (void) strnfmt(out_val, 78, 
87                        _("(%^s %c-%c, '*'で一覧, ESC) どの%sを使いますか?", "(%^ss %c-%c, *=List, ESC=exit) Use which %s? "),
88                        p, I2A(0), "abcdefghijklmnopqrstuvwxyz012345"[num-1], p);
89
90         if (use_menu) screen_save();
91
92         /* Get a spell from the user */
93
94         choice= always_show_list ? ESCAPE:1 ;
95         while (!flag)
96         {
97                 if(choice==ESCAPE) choice = ' '; 
98                 else if( !get_com(out_val, &choice, FALSE) )break;
99
100                 if (use_menu && choice != ' ')
101                 {
102                         switch(choice)
103                         {
104                                 case '0':
105                                 {
106                                         screen_load();
107                                         return (FALSE);
108                                 }
109
110                                 case '8':
111                                 case 'k':
112                                 case 'K':
113                                 {
114                                         do
115                                         {
116                                                 menu_line += 31;
117                                                 if (menu_line > 32) menu_line -= 32;
118                                         } while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))));
119                                         break;
120                                 }
121
122                                 case '2':
123                                 case 'j':
124                                 case 'J':
125                                 {
126                                         do
127                                         {
128                                                 menu_line++;
129                                                 if (menu_line > 32) menu_line -= 32;
130                                         } while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))));
131                                         break;
132                                 }
133
134                                 case '4':
135                                 case 'h':
136                                 case 'H':
137                                 case '6':
138                                 case 'l':
139                                 case 'L':
140                                 {
141                                         bool reverse = FALSE;
142                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
143                                         if (menu_line > 16)
144                                         {
145                                                 menu_line -= 16;
146                                                 reverse = TRUE;
147                                         }
148                                         else menu_line+=16;
149                                         while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))))
150                                         {
151                                                 if (reverse)
152                                                 {
153                                                         menu_line--;
154                                                         if (menu_line < 2) reverse = FALSE;
155                                                 }
156                                                 else
157                                                 {
158                                                         menu_line++;
159                                                         if (menu_line > 31) reverse = TRUE;
160                                                 }
161                                         }
162                                         break;
163                                 }
164
165                                 case 'x':
166                                 case 'X':
167                                 case '\r':
168                                 case '\n':
169                                 {
170                                         i = menu_line - 1;
171                                         ask = FALSE;
172                                         break;
173                                 }
174                         }
175                 }
176                 /* Request redraw */
177                 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
178                 {
179                         /* Show the list */
180                         if (!redraw || use_menu)
181                         {
182                                 char psi_desc[80];
183                                 int line;
184
185                                 /* Show list */
186                                 redraw = TRUE;
187                                 if (!use_menu) screen_save();
188
189                                 /* Display a list of spells */
190                                 prt("", y, x);
191                                 put_str(_("名前              Lv  MP      名前              Lv  MP ", 
192                                                   "name              Lv  SP      name              Lv  SP "), y, x + 5);
193                                 prt("", y+1, x);
194                                 /* Dump the spells */
195                                 for (i = 0, line = 0; i < 32; i++)
196                                 {
197                                         spell = technic_info[TECHNIC_HISSATSU][i];
198
199                                         if (spell.slevel > PY_MAX_LEVEL) continue;
200                                         line++;
201                                         if (!(p_ptr->spell_learned1 >> i)) break;
202
203                                         /* Access the spell */
204                                         if (spell.slevel > plev)   continue;
205                                         if (!(p_ptr->spell_learned1 & (1L << i))) continue;
206                                         if (use_menu)
207                                         {
208                                                 if (i == (menu_line-1))
209                                                         strcpy(psi_desc, _("  》", "  > "));
210                                                 else strcpy(psi_desc, "    ");
211                                                 
212                                         }
213                                         else
214                                         {
215                                                 char letter;
216                                                 if (line <= 26)
217                                                         letter = I2A(line-1);
218                                                 else
219                                                         letter = '0' + line - 27;
220                                                 sprintf(psi_desc, "  %c)",letter);
221                                         }
222
223                                         /* Dump the spell --(-- */
224                                         strcat(psi_desc, format(" %-18s%2d %3d",
225                                                 do_spell(REALM_HISSATSU, i, SPELL_NAME),
226                                                 spell.slevel, spell.smana));
227                                         prt(psi_desc, y + (line%17) + (line >= 17), x+(line/17)*30);
228                                         prt("", y + (line%17) + (line >= 17) + 1, x+(line/17)*30);
229                                 }
230                         }
231
232                         /* Hide the list */
233                         else
234                         {
235                                 /* Hide list */
236                                 redraw = FALSE;
237                                 screen_load();
238                         }
239
240                         /* Redo asking */
241                         continue;
242                 }
243
244                 if (!use_menu)
245                 {
246                         if (isalpha(choice))
247                         {
248                                 /* Note verify */
249                                 ask = (isupper(choice));
250
251                                 /* Lowercase */
252                                 if (ask) choice = (char)tolower(choice);
253
254                                 /* Extract request */
255                                 i = (islower(choice) ? A2I(choice) : -1);
256                         }
257                         else
258                         {
259                                 ask = FALSE; /* Can't uppercase digits */
260
261                                 i = choice - '0' + 26;
262                         }
263                 }
264
265                 /* Totally Illegal */
266                 if ((i < 0) || (i >= 32) || !(p_ptr->spell_learned1 & (1 << sentaku[i])))
267                 {
268                         bell();
269                         continue;
270                 }
271
272                 j = sentaku[i];
273
274                 /* Verify it */
275                 if (ask)
276                 {
277                         char tmp_val[160];
278
279                         /* Prompt */
280                         (void) strnfmt(tmp_val, 78, _("%sを使いますか?", "Use %s? "), do_spell(REALM_HISSATSU, j, SPELL_NAME));
281
282                         /* Belay that order */
283                         if (!get_check(tmp_val)) continue;
284                 }
285
286                 /* Stop the loop */
287                 flag = TRUE;
288         }
289         if (redraw) screen_load();
290
291         p_ptr->window |= (PW_SPELL);
292         handle_stuff();
293
294         /* Abort if needed */
295         if (!flag) return (FALSE);
296
297         /* Save the choice */
298         (*sn) = j;
299
300         repeat_push((COMMAND_CODE)j);
301
302         /* Success */
303         return (TRUE);
304 }
305
306
307 /*!
308  * @brief 剣術コマンドのメインルーチン
309  * @return なし
310  */
311 void do_cmd_hissatsu(void)
312 {
313         SPELL_IDX       n = 0;
314         magic_type      spell;
315
316         if (cmd_limit_confused(p_ptr)) return;
317         if (!has_melee_weapon(INVEN_RARM) && !has_melee_weapon(INVEN_LARM))
318         {
319                 if (flush_failure) flush();
320                 msg_print(_("武器を持たないと必殺技は使えない!", "You need to wield a weapon!"));
321                 return;
322         }
323         if (!p_ptr->spell_learned1)
324         {
325                 msg_print(_("何も技を知らない。", "You don't know any special attacks."));
326                 return;
327         }
328
329         if (p_ptr->special_defense & KATA_MASK)
330         {
331                 set_action(ACTION_NONE);
332         }
333
334         /* get power */
335         if (!get_hissatsu_power(&n)) return;
336
337         spell = technic_info[TECHNIC_HISSATSU][n];
338
339         /* Verify "dangerous" spells */
340         if (spell.smana > p_ptr->csp)
341         {
342                 if (flush_failure) flush();
343                 /* Warning */
344                 msg_print(_("MPが足りません。", "You do not have enough mana to use this power."));
345                 msg_print(NULL);
346                 return;
347         }
348
349         sound(SOUND_ZAP);
350
351         /* Cast the spell */
352         if (!do_spell(REALM_HISSATSU, n, SPELL_CAST)) return;
353
354         p_ptr->energy_use = 100;
355
356         /* Use some mana */
357         p_ptr->csp -= spell.smana;
358
359         /* Limit */
360         if (p_ptr->csp < 0) p_ptr->csp = 0;
361         p_ptr->redraw |= (PR_MANA);
362
363         p_ptr->window |= (PW_PLAYER);
364         p_ptr->window |= (PW_SPELL);
365 }
366
367
368 /*!
369  * @brief 剣術コマンドの学習
370  * @return なし
371  */
372 void do_cmd_gain_hissatsu(void)
373 {
374         OBJECT_IDX item;
375         int i, j;
376
377         object_type *o_ptr;
378         concptr q, s;
379
380         bool gain = FALSE;
381
382         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
383         {
384                 set_action(ACTION_NONE);
385         }
386
387         if (p_ptr->blind || no_lite())
388         {
389                 msg_print(_("目が見えない!", "You cannot see!"));
390                 return;
391         }
392
393         if (cmd_limit_confused(p_ptr)) return;
394
395         if (!(p_ptr->new_spells))
396         {
397                 msg_print(_("新しい必殺技を覚えることはできない!", "You cannot learn any new special attacks!"));
398                 return;
399         }
400
401 #ifdef JP
402         if( p_ptr->new_spells < 10 ){
403                 msg_format("あと %d つの必殺技を学べる。", p_ptr->new_spells);
404         }else{
405                 msg_format("あと %d 個の必殺技を学べる。", p_ptr->new_spells);
406         }
407 #else
408         msg_format("You can learn %d new special attack%s.", p_ptr->new_spells,
409                 (p_ptr->new_spells == 1?"":"s"));
410 #endif
411
412         item_tester_tval = TV_HISSATSU_BOOK;
413
414         q = _("どの書から学びますか? ", "Study which book? ");
415         s = _("読める書がない。", "You have no books that you can read.");
416
417         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
418         if (!o_ptr) return;
419
420         for (i = o_ptr->sval * 8; i < o_ptr->sval * 8 + 8; i++)
421         {
422                 if (p_ptr->spell_learned1 & (1L << i)) continue;
423                 if (technic_info[TECHNIC_HISSATSU][i].slevel > p_ptr->lev) continue;
424
425                 p_ptr->spell_learned1 |= (1L << i);
426                 p_ptr->spell_worked1 |= (1L << i);
427                 msg_format(_("%sの技を覚えた。", "You have learned the special attack of %s."), do_spell(REALM_HISSATSU, i, SPELL_NAME));
428                 for (j = 0; j < 64; j++)
429                 {
430                         /* Stop at the first empty space */
431                         if (p_ptr->spell_order[j] == 99) break;
432                 }
433                 p_ptr->spell_order[j] = i;
434                 gain = TRUE;
435         }
436
437         /* No gain ... */
438         if (!gain)
439                 msg_print(_("何も覚えられなかった。", "You were not able to learn any special attacks."));
440
441         else
442                 p_ptr->energy_use = 100;
443
444         p_ptr->update |= (PU_SPELLS);
445 }
446
447
448 /*!
449  * @brief 剣術のスレイ倍率計算を行う /
450  * Calcurate magnification of hissatsu technics
451  * @param mult 剣術のスレイ効果以前に算出している多要素の倍率(/10倍)
452  * @param flgs 剣術に使用する武器のスレイフラグ配列
453  * @param m_ptr 目標となるモンスターの構造体参照ポインタ
454  * @param mode 剣術のスレイ型ID
455  * @return スレイの倍率(/10倍)
456  */
457 MULTIPLY mult_hissatsu(MULTIPLY mult, BIT_FLAGS *flgs, monster_type *m_ptr, BIT_FLAGS mode)
458 {
459         monster_race *r_ptr = &r_info[m_ptr->r_idx];
460
461         /* Burning Strike (Fire) */
462         if (mode == HISSATSU_FIRE)
463         {
464                 /* Notice immunity */
465                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
466                 {
467                         if (is_original_ap_and_seen(m_ptr))
468                         {
469                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
470                         }
471                 }
472
473                 /* Otherwise, take the damage */
474                 else if (have_flag(flgs, TR_BRAND_FIRE))
475                 {
476                         if (r_ptr->flags3 & RF3_HURT_FIRE)
477                         {
478                                 if (mult < 70) mult = 70;
479                                 if (is_original_ap_and_seen(m_ptr))
480                                 {
481                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
482                                 }
483                         }
484                         else if (mult < 35) mult = 35;
485                 }
486                 else
487                 {
488                         if (r_ptr->flags3 & RF3_HURT_FIRE)
489                         {
490                                 if (mult < 50) mult = 50;
491                                 if (is_original_ap_and_seen(m_ptr))
492                                 {
493                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
494                                 }
495                         }
496                         else if (mult < 25) mult = 25;
497                 }
498         }
499
500         /* Serpent's Tongue (Poison) */
501         if (mode == HISSATSU_POISON)
502         {
503                 /* Notice immunity */
504                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
505                 {
506                         if (is_original_ap_and_seen(m_ptr))
507                         {
508                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
509                         }
510                 }
511
512                 /* Otherwise, take the damage */
513                 else if (have_flag(flgs, TR_BRAND_POIS))
514                 {
515                         if (mult < 35) mult = 35;
516                 }
517                 else
518                 {
519                         if (mult < 25) mult = 25;
520                 }
521         }
522
523         /* Zammaken (Nonliving Evil) */
524         if (mode == HISSATSU_ZANMA)
525         {
526                 if (!monster_living(m_ptr->r_idx) && (r_ptr->flags3 & RF3_EVIL))
527                 {
528                         if (mult < 15) mult = 25;
529                         else if (mult < 50) mult = MIN(50, mult+20);
530                 }
531         }
532
533         /* Rock Smash (Hurt Rock) */
534         if (mode == HISSATSU_HAGAN)
535         {
536                 if (r_ptr->flags3 & RF3_HURT_ROCK)
537                 {
538                         if (is_original_ap_and_seen(m_ptr))
539                         {
540                                 r_ptr->r_flags3 |= RF3_HURT_ROCK;
541                         }
542                         if (mult == 10) mult = 40;
543                         else if (mult < 60) mult = 60;
544                 }
545         }
546
547         /* Midare-Setsugekka (Cold) */
548         if (mode == HISSATSU_COLD)
549         {
550                 /* Notice immunity */
551                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
552                 {
553                         if (is_original_ap_and_seen(m_ptr))
554                         {
555                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
556                         }
557                 }
558                 /* Otherwise, take the damage */
559                 else if (have_flag(flgs, TR_BRAND_COLD))
560                 {
561                         if (r_ptr->flags3 & RF3_HURT_COLD)
562                         {
563                                 if (mult < 70) mult = 70;
564                                 if (is_original_ap_and_seen(m_ptr))
565                                 {
566                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
567                                 }
568                         }
569                         else if (mult < 35) mult = 35;
570                 }
571                 else
572                 {
573                         if (r_ptr->flags3 & RF3_HURT_COLD)
574                         {
575                                 if (mult < 50) mult = 50;
576                                 if (is_original_ap_and_seen(m_ptr))
577                                 {
578                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
579                                 }
580                         }
581                         else if (mult < 25) mult = 25;
582                 }
583         }
584
585         /* Lightning Eagle (Elec) */
586         if (mode == HISSATSU_ELEC)
587         {
588                 /* Notice immunity */
589                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
590                 {
591                         if (is_original_ap_and_seen(m_ptr))
592                         {
593                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
594                         }
595                 }
596
597                 /* Otherwise, take the damage */
598                 else if (have_flag(flgs, TR_BRAND_ELEC))
599                 {
600                         if (mult < 70) mult = 70;
601                 }
602                 else
603                 {
604                         if (mult < 50) mult = 50;
605                 }
606         }
607
608         /* Bloody Maelstrom */
609         if ((mode == HISSATSU_SEKIRYUKA) && p_ptr->cut && monster_living(m_ptr->r_idx))
610         {
611                 MULTIPLY tmp = MIN(100, MAX(10, p_ptr->cut / 10));
612                 if (mult < tmp) mult = tmp;
613         }
614
615         /* Keiun-Kininken */
616         if (mode == HISSATSU_UNDEAD)
617         {
618                 if (r_ptr->flags3 & RF3_UNDEAD)
619                 {
620                         if (is_original_ap_and_seen(m_ptr))
621                         {
622                                 r_ptr->r_flags3 |= RF3_UNDEAD;
623                         }
624                         if (mult == 10) mult = 70;
625                         else if (mult < 140) mult = MIN(140, mult+60);
626                 }
627                 if (mult == 10) mult = 40;
628                 else if (mult < 60) mult = MIN(60, mult+30);
629         }
630
631         if (mult > 150) mult = 150;
632
633         return mult;
634 }