OSDN Git Service

#37287 (2.2.0.40) cmd1.c内のC4457警告に対応。 / Deal C4457 warning in cmd1.c.
[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(int *sn)
36 {
37         int             i, j = 0;
38         int             num = 0;
39         int             y = 1;
40         int             x = 15;
41         int             plev = p_ptr->lev;
42         int             ask = TRUE;
43         char            choice;
44         char            out_val[160];
45         char sentaku[32];
46         cptr            p = _("必殺剣", "special attack");
47
48         magic_type spell;
49         bool            flag, redraw;
50         int menu_line = (use_menu ? 1 : 0);
51
52         /* Assume cancelled */
53         *sn = (-1);
54
55 #ifdef ALLOW_REPEAT /* TNB */
56
57         /* Get the spell, if available */
58         if (repeat_pull(sn))
59         {
60                 /* Verify the spell */
61                 if (technic_info[TECHNIC_HISSATSU][*sn].slevel <= plev)
62                 {
63                         /* Success */
64                         return (TRUE);
65                 }
66         }
67
68 #endif /* ALLOW_REPEAT -- TNB */
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
188                                 /* Save the screen */
189                                 if (!use_menu) screen_save();
190
191                                 /* Display a list of spells */
192                                 prt("", y, x);
193                                 put_str(_("名前              Lv  MP      名前              Lv  MP ", 
194                                                   "name              Lv  SP      name              Lv  SP "), y, x + 5);
195                                 prt("", y+1, x);
196                                 /* Dump the spells */
197                                 for (i = 0, line = 0; i < 32; i++)
198                                 {
199                                         spell = technic_info[TECHNIC_HISSATSU][i];
200
201                                         if (spell.slevel > PY_MAX_LEVEL) continue;
202                                         line++;
203                                         if (!(p_ptr->spell_learned1 >> i)) break;
204
205                                         /* Access the spell */
206                                         if (spell.slevel > plev)   continue;
207                                         if (!(p_ptr->spell_learned1 & (1L << i))) continue;
208                                         if (use_menu)
209                                         {
210                                                 if (i == (menu_line-1))
211                                                         strcpy(psi_desc, _("  》", "  > "));
212                                                 else strcpy(psi_desc, "    ");
213                                                 
214                                         }
215                                         else
216                                         {
217                                                 char letter;
218                                                 if (line <= 26)
219                                                         letter = I2A(line-1);
220                                                 else
221                                                         letter = '0' + line - 27;
222                                                 sprintf(psi_desc, "  %c)",letter);
223                                         }
224
225                                         /* Dump the spell --(-- */
226                                         strcat(psi_desc, format(" %-18s%2d %3d",
227                                                 do_spell(REALM_HISSATSU, i, SPELL_NAME),
228                                                 spell.slevel, spell.smana));
229                                         prt(psi_desc, y + (line%17) + (line >= 17), x+(line/17)*30);
230                                         prt("", y + (line%17) + (line >= 17) + 1, x+(line/17)*30);
231                                 }
232                         }
233
234                         /* Hide the list */
235                         else
236                         {
237                                 /* Hide list */
238                                 redraw = FALSE;
239
240                                 /* Restore the screen */
241                                 screen_load();
242                         }
243
244                         /* Redo asking */
245                         continue;
246                 }
247
248                 if (!use_menu)
249                 {
250                         if (isalpha(choice))
251                         {
252                                 /* Note verify */
253                                 ask = (isupper(choice));
254
255                                 /* Lowercase */
256                                 if (ask) choice = tolower(choice);
257
258                                 /* Extract request */
259                                 i = (islower(choice) ? A2I(choice) : -1);
260                         }
261                         else
262                         {
263                                 ask = FALSE; /* Can't uppercase digits */
264
265                                 i = choice - '0' + 26;
266                         }
267                 }
268
269                 /* Totally Illegal */
270                 if ((i < 0) || (i >= 32) || !(p_ptr->spell_learned1 & (1 << sentaku[i])))
271                 {
272                         bell();
273                         continue;
274                 }
275
276                 j = sentaku[i];
277
278                 /* Verify it */
279                 if (ask)
280                 {
281                         char tmp_val[160];
282
283                         /* Prompt */
284                         (void) strnfmt(tmp_val, 78, _("%sを使いますか?", "Use %s? "), do_spell(REALM_HISSATSU, j, SPELL_NAME));
285
286                         /* Belay that order */
287                         if (!get_check(tmp_val)) continue;
288                 }
289
290                 /* Stop the loop */
291                 flag = TRUE;
292         }
293
294         /* Restore the screen */
295         if (redraw) screen_load();
296
297         /* Show choices */
298         p_ptr->window |= (PW_SPELL);
299
300         /* Window stuff */
301         window_stuff();
302
303
304         /* Abort if needed */
305         if (!flag) return (FALSE);
306
307         /* Save the choice */
308         (*sn) = j;
309
310 #ifdef ALLOW_REPEAT /* TNB */
311
312         repeat_push(*sn);
313
314 #endif /* ALLOW_REPEAT -- TNB */
315
316         /* Success */
317         return (TRUE);
318 }
319
320
321 /*!
322  * @brief 剣術コマンドのメインルーチン
323  * @return なし
324  */
325 void do_cmd_hissatsu(void)
326 {
327         int             n = 0;
328         magic_type      spell;
329
330
331         /* not if confused */
332         if (p_ptr->confused)
333         {
334                 msg_print(_("混乱していて集中できない!", "You are too confused!"));
335                 return;
336         }
337         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM))
338         {
339                 if (flush_failure) flush();
340                 msg_print(_("武器を持たないと必殺技は使えない!", "You need to wield a weapon!"));
341                 return;
342         }
343         if (!p_ptr->spell_learned1)
344         {
345                 msg_print(_("何も技を知らない。", "You don't know any special attacks."));
346                 return;
347         }
348
349         if (p_ptr->special_defense & KATA_MASK)
350         {
351                 set_action(ACTION_NONE);
352         }
353
354         /* get power */
355         if (!get_hissatsu_power(&n)) return;
356
357         spell = technic_info[TECHNIC_HISSATSU][n];
358
359         /* Verify "dangerous" spells */
360         if (spell.smana > p_ptr->csp)
361         {
362                 if (flush_failure) flush();
363                 /* Warning */
364                 msg_print(_("MPが足りません。", "You do not have enough mana to use this power."));
365                 msg_print(NULL);
366                 return;
367         }
368
369         sound(SOUND_ZAP);
370
371         /* Cast the spell */
372         if (!do_spell(REALM_HISSATSU, n, SPELL_CAST)) return;
373
374         /* Take a turn */
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         int item, i, j;
399
400         object_type *o_ptr;
401         cptr q, s;
402
403         bool gain = FALSE;
404
405         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
406         {
407                 set_action(ACTION_NONE);
408         }
409
410         if (p_ptr->blind || no_lite())
411         {
412                 msg_print(_("目が見えない!", "You cannot see!"));
413                 return;
414         }
415
416         if (p_ptr->confused)
417         {
418                 msg_print(_("混乱していて読めない!", "You are too confused!"));
419                 return;
420         }
421
422         if (!(p_ptr->new_spells))
423         {
424                 msg_print(_("新しい必殺技を覚えることはできない!", "You cannot learn any new special attacks!"));
425                 return;
426         }
427
428 #ifdef JP
429         if( p_ptr->new_spells < 10 ){
430                 msg_format("あと %d つの必殺技を学べる。", p_ptr->new_spells);
431         }else{
432                 msg_format("あと %d 個の必殺技を学べる。", p_ptr->new_spells);
433         }
434 #else
435         msg_format("You can learn %d new special attack%s.", p_ptr->new_spells,
436                 (p_ptr->new_spells == 1?"":"s"));
437 #endif
438
439         item_tester_tval = TV_HISSATSU_BOOK;
440
441         /* Get an item */
442         q = _("どの書から学びますか? ", "Study which book? ");
443         s = _("読める書がない。", "You have no books that you can read.");
444
445         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
446
447         /* Get the item (in the pack) */
448         if (item >= 0)
449         {
450                 o_ptr = &inventory[item];
451         }
452
453         /* Get the item (on the floor) */
454         else
455         {
456                 o_ptr = &o_list[0 - item];
457         }
458
459         for (i = o_ptr->sval * 8; i < o_ptr->sval * 8 + 8; i++)
460         {
461                 if (p_ptr->spell_learned1 & (1L << i)) continue;
462                 if (technic_info[TECHNIC_HISSATSU][i].slevel > p_ptr->lev) continue;
463
464                 p_ptr->spell_learned1 |= (1L << i);
465                 p_ptr->spell_worked1 |= (1L << i);
466                 msg_format(_("%sの技を覚えた。", "You have learned the special attack of %s."), do_spell(REALM_HISSATSU, i, SPELL_NAME));
467                 for (j = 0; j < 64; j++)
468                 {
469                         /* Stop at the first empty space */
470                         if (p_ptr->spell_order[j] == 99) break;
471                 }
472                 p_ptr->spell_order[j] = i;
473                 gain = TRUE;
474         }
475
476         /* No gain ... */
477         if (!gain)
478                 msg_print(_("何も覚えられなかった。", "You were not able to learn any special attacks."));
479
480         /* Take a turn */
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 s16b mult_hissatsu(int mult, u32b *flgs, monster_type *m_ptr, int 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                 int 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 }