OSDN Git Service

[Refactor] #37353 cmd-mane.h を作成して変数宣言移動。 mane.c を cmd-mane.c に改名。
[hengband/hengband.git] / src / cmd-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 "monsterrace-hook.h"
15 #include "player-status.h"
16
17 #define TECHNIC_HISSATSU (REALM_HISSATSU - MIN_TECHNIC)
18
19
20 /*!
21  * @brief 使用可能な剣術を選択する /
22  * Allow user to choose a blade arts.
23  * @param sn 選択した特殊技能ID、キャンセルの場合-1、不正な選択の場合-2を返す
24  * @return 発動可能な魔法を選択した場合TRUE、キャンセル処理か不正な選択が行われた場合FALSEを返す。
25  * @details
26  * If a valid spell is chosen, saves it in '*sn' and returns TRUE\n
27  * If the user hits escape, returns FALSE, and set '*sn' to -1\n
28  * If there are no legal choices, returns FALSE, and sets '*sn' to -2\n
29  *\n
30  * The "prompt" should be "cast", "recite", or "study"\n
31  * The "known" should be TRUE for cast/pray, FALSE for study\n
32  *\n
33  * nb: This function has a (trivial) display bug which will be obvious\n
34  * when you run it. It's probably easy to fix but I haven't tried,\n
35  * sorry.\n
36  */
37 static int get_hissatsu_power(SPELL_IDX *sn)
38 {
39         SPELL_IDX i;
40         int j = 0;
41         int num = 0;
42         POSITION y = 1;
43         POSITION x = 15;
44         PLAYER_LEVEL plev = p_ptr->lev;
45         int ask = TRUE;
46         char choice;
47         char out_val[160];
48         SPELL_IDX sentaku[32];
49         concptr p = _("必殺剣", "special attack");
50         COMMAND_CODE code;
51         magic_type spell;
52         bool flag, redraw;
53         int menu_line = (use_menu ? 1 : 0);
54
55         /* Assume cancelled */
56         *sn = (-1);
57
58         /* Get the spell, if available */
59         if (repeat_pull(&code))
60         {
61                 *sn = (SPELL_IDX)code;
62                 /* Verify the spell */
63                 if (technic_info[TECHNIC_HISSATSU][*sn].slevel <= plev)
64                 {
65                         /* Success */
66                         return (TRUE);
67                 }
68         }
69
70         /* 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         choice = always_show_list ? ESCAPE : 1;
92
93         while (!flag)
94         {
95                 if(choice==ESCAPE) choice = ' '; 
96                 else if( !get_com(out_val, &choice, FALSE) )break;
97
98                 if (use_menu && choice != ' ')
99                 {
100                         switch(choice)
101                         {
102                                 case '0':
103                                 {
104                                         screen_load();
105                                         return (FALSE);
106                                 }
107
108                                 case '8':
109                                 case 'k':
110                                 case 'K':
111                                 {
112                                         do
113                                         {
114                                                 menu_line += 31;
115                                                 if (menu_line > 32) menu_line -= 32;
116                                         } while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))));
117                                         break;
118                                 }
119
120                                 case '2':
121                                 case 'j':
122                                 case 'J':
123                                 {
124                                         do
125                                         {
126                                                 menu_line++;
127                                                 if (menu_line > 32) menu_line -= 32;
128                                         } while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))));
129                                         break;
130                                 }
131
132                                 case '4':
133                                 case 'h':
134                                 case 'H':
135                                 case '6':
136                                 case 'l':
137                                 case 'L':
138                                 {
139                                         bool reverse = FALSE;
140                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
141                                         if (menu_line > 16)
142                                         {
143                                                 menu_line -= 16;
144                                                 reverse = TRUE;
145                                         }
146                                         else menu_line+=16;
147                                         while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))))
148                                         {
149                                                 if (reverse)
150                                                 {
151                                                         menu_line--;
152                                                         if (menu_line < 2) reverse = FALSE;
153                                                 }
154                                                 else
155                                                 {
156                                                         menu_line++;
157                                                         if (menu_line > 31) reverse = TRUE;
158                                                 }
159                                         }
160                                         break;
161                                 }
162
163                                 case 'x':
164                                 case 'X':
165                                 case '\r':
166                                 case '\n':
167                                 {
168                                         i = menu_line - 1;
169                                         ask = FALSE;
170                                         break;
171                                 }
172                         }
173                 }
174                 /* Request redraw */
175                 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
176                 {
177                         /* Show the list */
178                         if (!redraw || use_menu)
179                         {
180                                 char psi_desc[80];
181                                 int line;
182                                 redraw = TRUE;
183                                 if (!use_menu) screen_save();
184
185                                 /* Display a list of spells */
186                                 prt("", y, x);
187                                 put_str(_("名前              Lv  MP      名前              Lv  MP ", 
188                                                   "name              Lv  SP      name              Lv  SP "), y, x + 5);
189                                 prt("", y+1, x);
190                                 /* Dump the spells */
191                                 for (i = 0, line = 0; i < 32; i++)
192                                 {
193                                         spell = technic_info[TECHNIC_HISSATSU][i];
194
195                                         if (spell.slevel > PY_MAX_LEVEL) continue;
196                                         line++;
197                                         if (!(p_ptr->spell_learned1 >> i)) break;
198
199                                         /* Access the spell */
200                                         if (spell.slevel > plev)   continue;
201                                         if (!(p_ptr->spell_learned1 & (1L << i))) continue;
202                                         if (use_menu)
203                                         {
204                                                 if (i == (menu_line-1))
205                                                         strcpy(psi_desc, _("  》", "  > "));
206                                                 else strcpy(psi_desc, "    ");
207                                                 
208                                         }
209                                         else
210                                         {
211                                                 char letter;
212                                                 if (line <= 26)
213                                                         letter = I2A(line-1);
214                                                 else
215                                                         letter = '0' + line - 27;
216                                                 sprintf(psi_desc, "  %c)",letter);
217                                         }
218
219                                         /* Dump the spell --(-- */
220                                         strcat(psi_desc, format(" %-18s%2d %3d",
221                                                 do_spell(REALM_HISSATSU, i, SPELL_NAME),
222                                                 spell.slevel, spell.smana));
223                                         prt(psi_desc, y + (line%17) + (line >= 17), x+(line/17)*30);
224                                         prt("", y + (line%17) + (line >= 17) + 1, x+(line/17)*30);
225                                 }
226                         }
227
228                         /* Hide the list */
229                         else
230                         {
231                                 /* Hide list */
232                                 redraw = FALSE;
233                                 screen_load();
234                         }
235
236                         /* Redo asking */
237                         continue;
238                 }
239
240                 if (!use_menu)
241                 {
242                         if (isalpha(choice))
243                         {
244                                 /* Note verify */
245                                 ask = (isupper(choice));
246
247                                 /* Lowercase */
248                                 if (ask) choice = (char)tolower(choice);
249
250                                 /* Extract request */
251                                 i = (islower(choice) ? A2I(choice) : -1);
252                         }
253                         else
254                         {
255                                 ask = FALSE; /* Can't uppercase digits */
256
257                                 i = choice - '0' + 26;
258                         }
259                 }
260
261                 /* Totally Illegal */
262                 if ((i < 0) || (i >= 32) || !(p_ptr->spell_learned1 & (1 << sentaku[i])))
263                 {
264                         bell();
265                         continue;
266                 }
267
268                 j = sentaku[i];
269
270                 /* Verify it */
271                 if (ask)
272                 {
273                         char tmp_val[160];
274
275                         /* Prompt */
276                         (void) strnfmt(tmp_val, 78, _("%sを使いますか?", "Use %s? "), do_spell(REALM_HISSATSU, j, SPELL_NAME));
277
278                         /* Belay that order */
279                         if (!get_check(tmp_val)) continue;
280                 }
281
282                 /* Stop the loop */
283                 flag = TRUE;
284         }
285         if (redraw) screen_load();
286
287         p_ptr->window |= (PW_SPELL);
288         handle_stuff();
289
290         /* Abort if needed */
291         if (!flag) return (FALSE);
292
293         /* Save the choice */
294         (*sn) = j;
295
296         repeat_push((COMMAND_CODE)j);
297
298         /* Success */
299         return (TRUE);
300 }
301
302
303 /*!
304  * @brief 剣術コマンドのメインルーチン
305  * @return なし
306  */
307 void do_cmd_hissatsu(void)
308 {
309         SPELL_IDX       n = 0;
310         magic_type      spell;
311
312         if (cmd_limit_confused(p_ptr)) return;
313         if (!has_melee_weapon(INVEN_RARM) && !has_melee_weapon(INVEN_LARM))
314         {
315                 if (flush_failure) flush();
316                 msg_print(_("武器を持たないと必殺技は使えない!", "You need to wield a weapon!"));
317                 return;
318         }
319         if (!p_ptr->spell_learned1)
320         {
321                 msg_print(_("何も技を知らない。", "You don't know any special attacks."));
322                 return;
323         }
324
325         if (p_ptr->special_defense & KATA_MASK)
326         {
327                 set_action(ACTION_NONE);
328         }
329
330         if (!get_hissatsu_power(&n)) return;
331
332         spell = technic_info[TECHNIC_HISSATSU][n];
333
334         /* Verify "dangerous" spells */
335         if (spell.smana > p_ptr->csp)
336         {
337                 if (flush_failure) flush();
338                 /* Warning */
339                 msg_print(_("MPが足りません。", "You do not have enough mana to use this power."));
340                 msg_print(NULL);
341                 return;
342         }
343
344         sound(SOUND_ZAP);
345
346         if (!do_spell(REALM_HISSATSU, n, SPELL_CAST)) return;
347
348         take_turn(p_ptr, 100);
349
350         /* Use some mana */
351         p_ptr->csp -= spell.smana;
352
353         /* Limit */
354         if (p_ptr->csp < 0) p_ptr->csp = 0;
355         p_ptr->redraw |= (PR_MANA);
356         p_ptr->window |= (PW_PLAYER | PW_SPELL);
357 }
358
359
360 /*!
361  * @brief 剣術コマンドの学習
362  * @return なし
363  */
364 void do_cmd_gain_hissatsu(void)
365 {
366         OBJECT_IDX item;
367         int i, j;
368
369         object_type *o_ptr;
370         concptr q, s;
371
372         bool gain = FALSE;
373
374         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
375         {
376                 set_action(ACTION_NONE);
377         }
378
379         if (p_ptr->blind || no_lite())
380         {
381                 msg_print(_("目が見えない!", "You cannot see!"));
382                 return;
383         }
384
385         if (cmd_limit_confused(p_ptr)) return;
386
387         if (!(p_ptr->new_spells))
388         {
389                 msg_print(_("新しい必殺技を覚えることはできない!", "You cannot learn any new special attacks!"));
390                 return;
391         }
392
393 #ifdef JP
394         msg_format("あと %d 種の必殺技を学べる。", p_ptr->new_spells);
395 #else
396         msg_format("You can learn %d new special attack%s.", p_ptr->new_spells, (p_ptr->new_spells == 1?"":"s"));
397 #endif
398
399         item_tester_tval = TV_HISSATSU_BOOK;
400
401         q = _("どの書から学びますか? ", "Study which book? ");
402         s = _("読める書がない。", "You have no books that you can read.");
403
404         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
405         if (!o_ptr) return;
406
407         for (i = o_ptr->sval * 8; i < o_ptr->sval * 8 + 8; i++)
408         {
409                 if (p_ptr->spell_learned1 & (1L << i)) continue;
410                 if (technic_info[TECHNIC_HISSATSU][i].slevel > p_ptr->lev) continue;
411
412                 p_ptr->spell_learned1 |= (1L << i);
413                 p_ptr->spell_worked1 |= (1L << i);
414                 msg_format(_("%sの技を覚えた。", "You have learned the special attack of %s."), do_spell(REALM_HISSATSU, i, SPELL_NAME));
415                 for (j = 0; j < 64; j++)
416                 {
417                         /* Stop at the first empty space */
418                         if (p_ptr->spell_order[j] == 99) break;
419                 }
420                 p_ptr->spell_order[j] = i;
421                 gain = TRUE;
422         }
423
424         if (!gain)
425         {
426                 msg_print(_("何も覚えられなかった。", "You were not able to learn any special attacks."));
427         }
428         else
429         {
430                 take_turn(p_ptr, 100);
431         }
432
433         p_ptr->update |= (PU_SPELLS);
434 }
435
436