OSDN Git Service

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