OSDN Git Service

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