OSDN Git Service

b9a9cd3de9e65704312ba984b048f97836df96f7
[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 "util.h"
15
16 #include "monsterrace-hook.h"
17 #include "player-status.h"
18 #include "player-effects.h"
19 #include "spells.h"
20
21 #include "cmd-basic.h"
22 #include "cmd-spell.h"
23
24 #define TECHNIC_HISSATSU (REALM_HISSATSU - MIN_TECHNIC)
25
26
27 /*!
28  * @brief 使用可能な剣術を選択する /
29  * Allow user to choose a blade arts.
30  * @param sn 選択した特殊技能ID、キャンセルの場合-1、不正な選択の場合-2を返す
31  * @return 発動可能な魔法を選択した場合TRUE、キャンセル処理か不正な選択が行われた場合FALSEを返す。
32  * @details
33  * If a valid spell is chosen, saves it in '*sn' and returns TRUE\n
34  * If the user hits escape, returns FALSE, and set '*sn' to -1\n
35  * If there are no legal choices, returns FALSE, and sets '*sn' to -2\n
36  *\n
37  * The "prompt" should be "cast", "recite", or "study"\n
38  * The "known" should be TRUE for cast/pray, FALSE for study\n
39  *\n
40  * nb: This function has a (trivial) display bug which will be obvious\n
41  * when you run it. It's probably easy to fix but I haven't tried,\n
42  * sorry.\n
43  */
44 static int get_hissatsu_power(SPELL_IDX *sn)
45 {
46         SPELL_IDX i;
47         int j = 0;
48         int num = 0;
49         POSITION y = 1;
50         POSITION x = 15;
51         PLAYER_LEVEL plev = p_ptr->lev;
52         int ask = TRUE;
53         char choice;
54         char out_val[160];
55         SPELL_IDX sentaku[32];
56         concptr p = _("必殺剣", "special attack");
57         COMMAND_CODE code;
58         magic_type spell;
59         bool flag, redraw;
60         int menu_line = (use_menu ? 1 : 0);
61
62         /* Assume cancelled */
63         *sn = (-1);
64
65         /* Get the spell, if available */
66         if (repeat_pull(&code))
67         {
68                 *sn = (SPELL_IDX)code;
69                 /* Verify the spell */
70                 if (technic_info[TECHNIC_HISSATSU][*sn].slevel <= plev)
71                 {
72                         /* Success */
73                         return (TRUE);
74                 }
75         }
76
77         /* Nothing chosen yet */
78         flag = FALSE;
79
80         /* No redraw yet */
81         redraw = FALSE;
82
83         for (i = 0; i < 32; i++)
84         {
85                 if (technic_info[TECHNIC_HISSATSU][i].slevel <= PY_MAX_LEVEL)
86                 {
87                         sentaku[num] = i;
88                         num++;
89                 }
90         }
91
92         /* Build a prompt (accept all spells) */
93         (void)strnfmt(out_val, 78,
94                 _("(%^s %c-%c, '*'で一覧, ESC) どの%sを使いますか?", "(%^ss %c-%c, *=List, ESC=exit) Use which %s? "),
95                 p, I2A(0), "abcdefghijklmnopqrstuvwxyz012345"[num - 1], p);
96
97         if (use_menu) screen_save();
98         choice = always_show_list ? ESCAPE : 1;
99
100         while (!flag)
101         {
102                 if(choice==ESCAPE) choice = ' '; 
103                 else if( !get_com(out_val, &choice, FALSE) )break;
104
105                 if (use_menu && choice != ' ')
106                 {
107                         switch(choice)
108                         {
109                                 case '0':
110                                 {
111                                         screen_load();
112                                         return (FALSE);
113                                 }
114
115                                 case '8':
116                                 case 'k':
117                                 case 'K':
118                                 {
119                                         do
120                                         {
121                                                 menu_line += 31;
122                                                 if (menu_line > 32) menu_line -= 32;
123                                         } while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))));
124                                         break;
125                                 }
126
127                                 case '2':
128                                 case 'j':
129                                 case 'J':
130                                 {
131                                         do
132                                         {
133                                                 menu_line++;
134                                                 if (menu_line > 32) menu_line -= 32;
135                                         } while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))));
136                                         break;
137                                 }
138
139                                 case '4':
140                                 case 'h':
141                                 case 'H':
142                                 case '6':
143                                 case 'l':
144                                 case 'L':
145                                 {
146                                         bool reverse = FALSE;
147                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
148                                         if (menu_line > 16)
149                                         {
150                                                 menu_line -= 16;
151                                                 reverse = TRUE;
152                                         }
153                                         else menu_line+=16;
154                                         while(!(p_ptr->spell_learned1 & (1L << (menu_line-1))))
155                                         {
156                                                 if (reverse)
157                                                 {
158                                                         menu_line--;
159                                                         if (menu_line < 2) reverse = FALSE;
160                                                 }
161                                                 else
162                                                 {
163                                                         menu_line++;
164                                                         if (menu_line > 31) reverse = TRUE;
165                                                 }
166                                         }
167                                         break;
168                                 }
169
170                                 case 'x':
171                                 case 'X':
172                                 case '\r':
173                                 case '\n':
174                                 {
175                                         i = menu_line - 1;
176                                         ask = FALSE;
177                                         break;
178                                 }
179                         }
180                 }
181                 /* Request redraw */
182                 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
183                 {
184                         /* Show the list */
185                         if (!redraw || use_menu)
186                         {
187                                 char psi_desc[80];
188                                 int line;
189                                 redraw = TRUE;
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                                 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         if (redraw) screen_load();
293
294         p_ptr->window |= (PW_SPELL);
295         handle_stuff();
296
297         /* Abort if needed */
298         if (!flag) return (FALSE);
299
300         /* Save the choice */
301         (*sn) = j;
302
303         repeat_push((COMMAND_CODE)j);
304
305         /* Success */
306         return (TRUE);
307 }
308
309
310 /*!
311  * @brief 剣術コマンドのメインルーチン
312  * @return なし
313  */
314 void do_cmd_hissatsu(void)
315 {
316         SPELL_IDX       n = 0;
317         magic_type      spell;
318
319         if (cmd_limit_confused(p_ptr)) return;
320         if (!has_melee_weapon(INVEN_RARM) && !has_melee_weapon(INVEN_LARM))
321         {
322                 if (flush_failure) flush();
323                 msg_print(_("武器を持たないと必殺技は使えない!", "You need to wield a weapon!"));
324                 return;
325         }
326         if (!p_ptr->spell_learned1)
327         {
328                 msg_print(_("何も技を知らない。", "You don't know any special attacks."));
329                 return;
330         }
331
332         if (p_ptr->special_defense & KATA_MASK)
333         {
334                 set_action(ACTION_NONE);
335         }
336
337         if (!get_hissatsu_power(&n)) return;
338
339         spell = technic_info[TECHNIC_HISSATSU][n];
340
341         /* Verify "dangerous" spells */
342         if (spell.smana > p_ptr->csp)
343         {
344                 if (flush_failure) flush();
345                 /* Warning */
346                 msg_print(_("MPが足りません。", "You do not have enough mana to use this power."));
347                 msg_print(NULL);
348                 return;
349         }
350
351         sound(SOUND_ZAP);
352
353         if (!do_spell(REALM_HISSATSU, n, SPELL_CAST)) return;
354
355         take_turn(p_ptr, 100);
356
357         /* Use some mana */
358         p_ptr->csp -= spell.smana;
359
360         /* Limit */
361         if (p_ptr->csp < 0) p_ptr->csp = 0;
362         p_ptr->redraw |= (PR_MANA);
363         p_ptr->window |= (PW_PLAYER | PW_SPELL);
364 }
365
366
367 /*!
368  * @brief 剣術コマンドの学習
369  * @return なし
370  */
371 void do_cmd_gain_hissatsu(void)
372 {
373         OBJECT_IDX item;
374         int i, j;
375
376         object_type *o_ptr;
377         concptr q, s;
378
379         bool gain = FALSE;
380
381         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
382         {
383                 set_action(ACTION_NONE);
384         }
385
386         if (p_ptr->blind || no_lite())
387         {
388                 msg_print(_("目が見えない!", "You cannot see!"));
389                 return;
390         }
391
392         if (cmd_limit_confused(p_ptr)) return;
393
394         if (!(p_ptr->new_spells))
395         {
396                 msg_print(_("新しい必殺技を覚えることはできない!", "You cannot learn any new special attacks!"));
397                 return;
398         }
399
400 #ifdef JP
401         msg_format("あと %d 種の必殺技を学べる。", p_ptr->new_spells);
402 #else
403         msg_format("You can learn %d new special attack%s.", p_ptr->new_spells, (p_ptr->new_spells == 1?"":"s"));
404 #endif
405
406         item_tester_tval = TV_HISSATSU_BOOK;
407
408         q = _("どの書から学びますか? ", "Study which book? ");
409         s = _("読める書がない。", "You have no books that you can read.");
410
411         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
412         if (!o_ptr) return;
413
414         for (i = o_ptr->sval * 8; i < o_ptr->sval * 8 + 8; i++)
415         {
416                 if (p_ptr->spell_learned1 & (1L << i)) continue;
417                 if (technic_info[TECHNIC_HISSATSU][i].slevel > p_ptr->lev) continue;
418
419                 p_ptr->spell_learned1 |= (1L << i);
420                 p_ptr->spell_worked1 |= (1L << i);
421                 msg_format(_("%sの技を覚えた。", "You have learned the special attack of %s."), do_spell(REALM_HISSATSU, i, SPELL_NAME));
422                 for (j = 0; j < 64; j++)
423                 {
424                         /* Stop at the first empty space */
425                         if (p_ptr->spell_order[j] == 99) break;
426                 }
427                 p_ptr->spell_order[j] = i;
428                 gain = TRUE;
429         }
430
431         if (!gain)
432         {
433                 msg_print(_("何も覚えられなかった。", "You were not able to learn any special attacks."));
434         }
435         else
436         {
437                 take_turn(p_ptr, 100);
438         }
439
440         p_ptr->update |= (PU_SPELLS);
441 }
442
443