OSDN Git Service

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