OSDN Git Service

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