OSDN Git Service

[Refactor] #38997 display_koff() にplayer_type *引数を追加 / Added player_type * argument...
[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.h"
15 #include "util.h"
16
17 #include "monsterrace-hook.h"
18 #include "player-status.h"
19 #include "player-effects.h"
20 #include "player-inventory.h"
21 #include "spells.h"
22
23 #include "cmd-basic.h"
24 #include "cmd-spell.h"
25 #include "view-mainwindow.h"
26
27 #define TECHNIC_HISSATSU (REALM_HISSATSU - MIN_TECHNIC)
28
29
30 /*!
31  * @brief 使用可能な剣術を選択する /
32  * Allow user to choose a blade arts.
33  * @param sn 選択した特殊技能ID、キャンセルの場合-1、不正な選択の場合-2を返す
34  * @return 発動可能な魔法を選択した場合TRUE、キャンセル処理か不正な選択が行われた場合FALSEを返す。
35  * @details
36  * If a valid spell is chosen, saves it in '*sn' and returns TRUE\n
37  * If the user hits escape, returns FALSE, and set '*sn' to -1\n
38  * If there are no legal choices, returns FALSE, and sets '*sn' to -2\n
39  *\n
40  * The "prompt" should be "cast", "recite", or "study"\n
41  * The "known" should be TRUE for cast/pray, FALSE for study\n
42  *\n
43  * nb: This function has a (trivial) display bug which will be obvious\n
44  * when you run it. It's probably easy to fix but I haven't tried,\n
45  * sorry.\n
46  */
47 static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
48 {
49         SPELL_IDX i;
50         int j = 0;
51         int num = 0;
52         POSITION y = 1;
53         POSITION x = 15;
54         PLAYER_LEVEL plev = creature_ptr->lev;
55         int ask = TRUE;
56         char choice;
57         char out_val[160];
58         SPELL_IDX sentaku[32];
59         concptr p = _("必殺剣", "special attack");
60         COMMAND_CODE code;
61         magic_type spell;
62         bool flag, redraw;
63         int menu_line = (use_menu ? 1 : 0);
64
65         /* Assume cancelled */
66         *sn = (-1);
67
68         /* Get the spell, if available */
69         if (repeat_pull(&code))
70         {
71                 *sn = (SPELL_IDX)code;
72                 /* Verify the spell */
73                 if (technic_info[TECHNIC_HISSATSU][*sn].slevel <= plev)
74                 {
75                         /* Success */
76                         return (TRUE);
77                 }
78         }
79
80         flag = FALSE;
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(!(creature_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(!(creature_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(!(creature_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 (!(creature_ptr->spell_learned1 >> i)) break;
205
206                                         /* Access the spell */
207                                         if (spell.slevel > plev)   continue;
208                                         if (!(creature_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                                                 exe_spell(creature_ptr, 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) || !(creature_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? "), exe_spell(creature_ptr, 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         creature_ptr->window |= (PW_SPELL);
295         handle_stuff(creature_ptr);
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(player_type *creature_ptr)
315 {
316         SPELL_IDX       n = 0;
317         magic_type      spell;
318
319         if (cmd_limit_confused(creature_ptr)) return;
320         if (!has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
321         {
322                 if (flush_failure) flush();
323                 msg_print(_("武器を持たないと必殺技は使えない!", "You need to wield a weapon!"));
324                 return;
325         }
326         if (!creature_ptr->spell_learned1)
327         {
328                 msg_print(_("何も技を知らない。", "You don't know any special attacks."));
329                 return;
330         }
331
332         if (creature_ptr->special_defense & KATA_MASK)
333         {
334                 set_action(creature_ptr, ACTION_NONE);
335         }
336
337         if (!get_hissatsu_power(creature_ptr, &n)) return;
338
339         spell = technic_info[TECHNIC_HISSATSU][n];
340
341         /* Verify "dangerous" spells */
342         if (spell.smana > creature_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 (!exe_spell(creature_ptr, REALM_HISSATSU, n, SPELL_CAST)) return;
354
355         take_turn(creature_ptr, 100);
356
357         /* Use some mana */
358         creature_ptr->csp -= spell.smana;
359
360         /* Limit */
361         if (creature_ptr->csp < 0) creature_ptr->csp = 0;
362         creature_ptr->redraw |= (PR_MANA);
363         creature_ptr->window |= (PW_PLAYER | PW_SPELL);
364 }
365
366
367 /*!
368  * @brief 剣術コマンドの学習
369  * @return なし
370  */
371 void do_cmd_gain_hissatsu(player_type *creature_ptr)
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 (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
382         {
383                 set_action(creature_ptr, ACTION_NONE);
384         }
385
386         if (cmd_limit_blind(creature_ptr)) return;
387         if (cmd_limit_confused(creature_ptr)) return;
388
389         if (!(creature_ptr->new_spells))
390         {
391                 msg_print(_("新しい必殺技を覚えることはできない!", "You cannot learn any new special attacks!"));
392                 return;
393         }
394
395 #ifdef JP
396         msg_format("あと %d 種の必殺技を学べる。", creature_ptr->new_spells);
397 #else
398         msg_format("You can learn %d new special attack%s.", creature_ptr->new_spells, (creature_ptr->new_spells == 1?"":"s"));
399 #endif
400
401         q = _("どの書から学びますか? ", "Study which book? ");
402         s = _("読める書がない。", "You have no books that you can read.");
403
404         o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_HISSATSU_BOOK);
405         if (!o_ptr) return;
406
407         for (i = o_ptr->sval * 8; i < o_ptr->sval * 8 + 8; i++)
408         {
409                 if (creature_ptr->spell_learned1 & (1L << i)) continue;
410                 if (technic_info[TECHNIC_HISSATSU][i].slevel > creature_ptr->lev) continue;
411
412                 creature_ptr->spell_learned1 |= (1L << i);
413                 creature_ptr->spell_worked1 |= (1L << i);
414                 msg_format(_("%sの技を覚えた。", "You have learned the special attack of %s."), exe_spell(creature_ptr, REALM_HISSATSU, i, SPELL_NAME));
415                 for (j = 0; j < 64; j++)
416                 {
417                         /* Stop at the first empty space */
418                         if (creature_ptr->spell_order[j] == 99) break;
419                 }
420                 creature_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(creature_ptr, 100);
431         }
432
433         creature_ptr->update |= (PU_SPELLS);
434 }
435
436