OSDN Git Service

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