OSDN Git Service

#37287 #37353 (2.2.0.89) OBJECT_IDX 型を定義し、型の置換を継続中。 / Define OBJECT_IDX, 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 = 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         int item, 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         /* Take a turn */
482         else
483                 p_ptr->energy_use = 100;
484
485         p_ptr->update |= (PU_SPELLS);
486 }
487
488
489 /*!
490  * @brief 剣術のスレイ倍率計算を行う /
491  * Calcurate magnification of hissatsu technics
492  * @param mult 剣術のスレイ効果以前に算出している多要素の倍率(/10倍)
493  * @param flgs 剣術に使用する武器のスレイフラグ配列
494  * @param m_ptr 目標となるモンスターの構造体参照ポインタ
495  * @param mode 剣術のスレイ型ID
496  * @return スレイの倍率(/10倍)
497  */
498 s16b mult_hissatsu(int mult, u32b *flgs, monster_type *m_ptr, int mode)
499 {
500         monster_race *r_ptr = &r_info[m_ptr->r_idx];
501
502         /* Burning Strike (Fire) */
503         if (mode == HISSATSU_FIRE)
504         {
505                 /* Notice immunity */
506                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
507                 {
508                         if (is_original_ap_and_seen(m_ptr))
509                         {
510                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
511                         }
512                 }
513
514                 /* Otherwise, take the damage */
515                 else if (have_flag(flgs, TR_BRAND_FIRE))
516                 {
517                         if (r_ptr->flags3 & RF3_HURT_FIRE)
518                         {
519                                 if (mult < 70) mult = 70;
520                                 if (is_original_ap_and_seen(m_ptr))
521                                 {
522                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
523                                 }
524                         }
525                         else if (mult < 35) mult = 35;
526                 }
527                 else
528                 {
529                         if (r_ptr->flags3 & RF3_HURT_FIRE)
530                         {
531                                 if (mult < 50) mult = 50;
532                                 if (is_original_ap_and_seen(m_ptr))
533                                 {
534                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
535                                 }
536                         }
537                         else if (mult < 25) mult = 25;
538                 }
539         }
540
541         /* Serpent's Tongue (Poison) */
542         if (mode == HISSATSU_POISON)
543         {
544                 /* Notice immunity */
545                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
546                 {
547                         if (is_original_ap_and_seen(m_ptr))
548                         {
549                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
550                         }
551                 }
552
553                 /* Otherwise, take the damage */
554                 else if (have_flag(flgs, TR_BRAND_POIS))
555                 {
556                         if (mult < 35) mult = 35;
557                 }
558                 else
559                 {
560                         if (mult < 25) mult = 25;
561                 }
562         }
563
564         /* Zammaken (Nonliving Evil) */
565         if (mode == HISSATSU_ZANMA)
566         {
567                 if (!monster_living(r_ptr) && (r_ptr->flags3 & RF3_EVIL))
568                 {
569                         if (mult < 15) mult = 25;
570                         else if (mult < 50) mult = MIN(50, mult+20);
571                 }
572         }
573
574         /* Rock Smash (Hurt Rock) */
575         if (mode == HISSATSU_HAGAN)
576         {
577                 if (r_ptr->flags3 & RF3_HURT_ROCK)
578                 {
579                         if (is_original_ap_and_seen(m_ptr))
580                         {
581                                 r_ptr->r_flags3 |= RF3_HURT_ROCK;
582                         }
583                         if (mult == 10) mult = 40;
584                         else if (mult < 60) mult = 60;
585                 }
586         }
587
588         /* Midare-Setsugekka (Cold) */
589         if (mode == HISSATSU_COLD)
590         {
591                 /* Notice immunity */
592                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
593                 {
594                         if (is_original_ap_and_seen(m_ptr))
595                         {
596                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
597                         }
598                 }
599                 /* Otherwise, take the damage */
600                 else if (have_flag(flgs, TR_BRAND_COLD))
601                 {
602                         if (r_ptr->flags3 & RF3_HURT_COLD)
603                         {
604                                 if (mult < 70) mult = 70;
605                                 if (is_original_ap_and_seen(m_ptr))
606                                 {
607                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
608                                 }
609                         }
610                         else if (mult < 35) mult = 35;
611                 }
612                 else
613                 {
614                         if (r_ptr->flags3 & RF3_HURT_COLD)
615                         {
616                                 if (mult < 50) mult = 50;
617                                 if (is_original_ap_and_seen(m_ptr))
618                                 {
619                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
620                                 }
621                         }
622                         else if (mult < 25) mult = 25;
623                 }
624         }
625
626         /* Lightning Eagle (Elec) */
627         if (mode == HISSATSU_ELEC)
628         {
629                 /* Notice immunity */
630                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
631                 {
632                         if (is_original_ap_and_seen(m_ptr))
633                         {
634                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
635                         }
636                 }
637
638                 /* Otherwise, take the damage */
639                 else if (have_flag(flgs, TR_BRAND_ELEC))
640                 {
641                         if (mult < 70) mult = 70;
642                 }
643                 else
644                 {
645                         if (mult < 50) mult = 50;
646                 }
647         }
648
649         /* Bloody Maelstrom */
650         if ((mode == HISSATSU_SEKIRYUKA) && p_ptr->cut && monster_living(r_ptr))
651         {
652                 int tmp = MIN(100, MAX(10, p_ptr->cut / 10));
653                 if (mult < tmp) mult = tmp;
654         }
655
656         /* Keiun-Kininken */
657         if (mode == HISSATSU_UNDEAD)
658         {
659                 if (r_ptr->flags3 & RF3_UNDEAD)
660                 {
661                         if (is_original_ap_and_seen(m_ptr))
662                         {
663                                 r_ptr->r_flags3 |= RF3_UNDEAD;
664                         }
665                         if (mult == 10) mult = 70;
666                         else if (mult < 140) mult = MIN(140, mult+60);
667                 }
668                 if (mult == 10) mult = 40;
669                 else if (mult < 60) mult = MIN(60, mult+30);
670         }
671
672         if (mult > 150) mult = 150;
673
674         return mult;
675 }