OSDN Git Service

ca9ee1864019baf7f93f14534aae5025c1a180b7
[hengband/hengband.git] / src / wizard / wizard-special-process.c
1 /*!
2  * @brief ウィザードモードの処理(特別処理中心) / Wizard commands
3  * @date 2014/09/07
4  * @author
5  * Copyright (c) 1997 Ben Harrison, and others<br>
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.<br>
9  * 2014 Deskull rearranged comment for Doxygen.<br>
10  */
11
12 #include "wizard/wizard-special-process.h"
13 #include "artifact/fixed-art-generator.h"
14 #include "birth/inventory-initializer.h"
15 #include "cmd-io/cmd-dump.h"
16 #include "cmd-io/cmd-help.h"
17 #include "cmd-io/cmd-save.h"
18 #include "cmd-visual/cmd-draw.h"
19 #include "core/asking-player.h"
20 #include "core/player-update-types.h"
21 #include "core/stuff-handler.h"
22 #include "core/window-redrawer.h"
23 #include "dungeon/dungeon.h"
24 #include "dungeon/quest.h"
25 #include "flavor/object-flavor.h"
26 #include "floor/floor-mode-changer.h"
27 #include "floor/floor-object.h"
28 #include "game-option/option-types-table.h"
29 #include "game-option/play-record-options.h"
30 #include "game-option/special-options.h"
31 #include "grid/grid.h"
32 #include "info-reader/fixed-map-parser.h"
33 #include "inventory/inventory-object.h"
34 #include "inventory/inventory-slot-types.h"
35 #include "io/files-util.h"
36 #include "io/input-key-requester.h"
37 #include "io/write-diary.h"
38 #include "market/arena.h"
39 #include "monster-floor/monster-remover.h"
40 #include "monster-floor/monster-summon.h"
41 #include "monster/monster-describer.h"
42 #include "monster/monster-description-types.h"
43 #include "monster/monster-info.h"
44 #include "monster/monster-status.h"
45 #include "monster/smart-learn-types.h"
46 #include "mutation/mutation-investor-remover.h"
47 #include "object-enchant/apply-magic.h"
48 #include "object-enchant/item-apply-magic.h"
49 #include "object-enchant/trc-types.h"
50 #include "object-enchant/trg-types.h"
51 #include "object/object-generator.h"
52 #include "object/object-kind.h"
53 #include "perception/object-perception.h"
54 #include "player-info/self-info.h"
55 #include "player/digestion-processor.h"
56 #include "player/patron.h"
57 #include "player/player-class.h"
58 #include "player/player-race-types.h"
59 #include "player/player-skill.h"
60 #include "player/player-status.h"
61 #include "player/player-status-table.h"
62 #include "spell-kind/spells-detection.h"
63 #include "spell-kind/spells-sight.h"
64 #include "spell-kind/spells-teleport.h"
65 #include "spell/spells-object.h"
66 #include "spell/spells-status.h"
67 #include "spell/spells-summon.h"
68 #include "status/experience.h"
69 #include "system/angband-version.h"
70 #include "system/artifact-type-definition.h"
71 #include "system/floor-type-definition.h"
72 #include "target/grid-selector.h"
73 #include "term/screen-processor.h"
74 #include "util/angband-files.h"
75 #include "util/bit-flags-calculator.h"
76 #include "util/int-char-converter.h"
77 #include "view/display-messages.h"
78 #include "wizard/tval-descriptions-table.h"
79 #include "wizard/wizard-spells.h"
80 #include "wizard/wizard-spoiler.h"
81 #include "world/world.h"
82
83 #define NUM_O_SET 8
84 #define NUM_O_BIT 32
85
86 /*!
87  * @brief プレイヤーを完全回復する /
88  * Cure everything instantly
89  * @return なし
90  */
91 void wiz_cure_all(player_type *creature_ptr)
92 {
93     (void)life_stream(creature_ptr, FALSE, FALSE);
94     (void)restore_mana(creature_ptr, TRUE);
95     (void)set_food(creature_ptr, PY_FOOD_MAX - 1);
96 }
97
98 /*!
99  * @brief ベースアイテムのウィザード生成のために大項目IDと小項目IDを取得する /
100  * Specify tval and sval (type and subtype of object) originally
101  * @return ベースアイテムID
102  * @details
103  * by RAK, heavily modified by -Bernd-
104  * This function returns the k_idx of an object type, or zero if failed
105  * List up to 50 choices in three columns
106  */
107 KIND_OBJECT_IDX wiz_create_itemtype(void)
108 {
109     term_clear();
110     int num;
111     TERM_LEN col, row;
112     char ch;
113     for (num = 0; (num < 80) && tvals[num].tval; num++) {
114         row = 2 + (num % 20);
115         col = 20 * (num / 20);
116         ch = listsym[num];
117         prt(format("[%c] %s", ch, tvals[num].desc), row, col);
118     }
119
120     int max_num = num;
121     if (!get_com("Get what type of object? ", &ch, FALSE))
122         return 0;
123
124     for (num = 0; num < max_num; num++)
125         if (listsym[num] == ch)
126             break;
127
128     if ((num < 0) || (num >= max_num))
129         return 0;
130
131     tval_type tval = tvals[num].tval;
132     concptr tval_desc = tvals[num].desc;
133     term_clear();
134     num = 0;
135     KIND_OBJECT_IDX choice[80];
136     char buf[160];
137     for (KIND_OBJECT_IDX i = 1; (num < 80) && (i < max_k_idx); i++) {
138         object_kind *k_ptr = &k_info[i];
139         if (k_ptr->tval != tval)
140             continue;
141
142         row = 2 + (num % 20);
143         col = 20 * (num / 20);
144         ch = listsym[num];
145         strcpy(buf, "                    ");
146         strip_name(buf, i);
147         prt(format("[%c] %s", ch, buf), row, col);
148         choice[num++] = i;
149     }
150
151     max_num = num;
152     if (!get_com(format("What Kind of %s? ", tval_desc), &ch, FALSE))
153         return 0;
154
155     for (num = 0; num < max_num; num++)
156         if (listsym[num] == ch)
157             break;
158
159     if ((num < 0) || (num >= max_num))
160         return 0;
161
162     return choice[num];
163 }
164
165 /*!
166  * @brief 任意のベースアイテム生成のメインルーチン /
167  * Wizard routine for creating objects          -RAK-
168  * @return なし
169  * @details
170  * Heavily modified to allow magification and artifactification  -Bernd-
171  *
172  * Note that wizards cannot create objects on top of other objects.
173  *
174  * Hack -- this routine always makes a "dungeon object", and applies
175  * magic to it, and attempts to decline cursed items.
176  */
177 void wiz_create_item(player_type *caster_ptr)
178 {
179     screen_save(caster_ptr);
180     OBJECT_IDX k_idx = wiz_create_itemtype();
181     screen_load(caster_ptr);
182     if (!k_idx)
183         return;
184
185     if (k_info[k_idx].gen_flags & TRG_INSTA_ART) {
186         for (ARTIFACT_IDX i = 1; i < max_a_idx; i++) {
187             if ((a_info[i].tval != k_info[k_idx].tval) || (a_info[i].sval != k_info[k_idx].sval))
188                 continue;
189
190             (void)create_named_art(caster_ptr, i, caster_ptr->y, caster_ptr->x);
191             msg_print("Allocated(INSTA_ART).");
192             return;
193         }
194     }
195
196     object_type forge;
197     object_type *q_ptr;
198     q_ptr = &forge;
199     object_prep(caster_ptr, q_ptr, k_idx);
200     apply_magic(caster_ptr, q_ptr, caster_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART);
201     (void)drop_near(caster_ptr, q_ptr, -1, caster_ptr->y, caster_ptr->x);
202     msg_print("Allocated.");
203 }
204
205 /*!
206  * @brief 指定されたIDの固定アーティファクトを生成する / Create the artifact of the specified number
207  * @param caster_ptr プレーヤーへの参照ポインタ
208  * @return なし
209  */
210 void wiz_create_named_art(player_type *caster_ptr)
211 {
212     char tmp_val[10] = "";
213     if (!get_string("Artifact ID:", tmp_val, 3))
214         return;
215
216     ARTIFACT_IDX a_idx = (ARTIFACT_IDX)atoi(tmp_val);
217     if ((a_idx < 0) || (a_idx >= max_a_idx))
218         a_idx = 0;
219
220     (void)create_named_art(caster_ptr, a_idx, caster_ptr->y, caster_ptr->x);
221     msg_print("Allocated.");
222 }
223
224 /*!
225  * @brief プレイヤーの現能力値を調整する / Change various "permanent" player variables.
226  * @param creature_ptr プレーヤーへの参照ポインタ
227  * @return なし
228  */
229 void wiz_change_status(player_type *creature_ptr)
230 {
231     int tmp_int;
232     char tmp_val[160];
233     char ppp[80];
234     for (int i = 0; i < A_MAX; i++) {
235         sprintf(ppp, "%s (3-%d): ", stat_names[i], creature_ptr->stat_max_max[i]);
236         sprintf(tmp_val, "%d", creature_ptr->stat_max[i]);
237         if (!get_string(ppp, tmp_val, 3))
238             return;
239
240         tmp_int = atoi(tmp_val);
241         if (tmp_int > creature_ptr->stat_max_max[i])
242             tmp_int = creature_ptr->stat_max_max[i];
243         else if (tmp_int < 3)
244             tmp_int = 3;
245
246         creature_ptr->stat_cur[i] = creature_ptr->stat_max[i] = (BASE_STATUS)tmp_int;
247     }
248
249     sprintf(tmp_val, "%d", WEAPON_EXP_MASTER);
250     if (!get_string(_("熟練度: ", "Proficiency: "), tmp_val, 9))
251         return;
252
253     s16b tmp_s16b = (s16b)atoi(tmp_val);
254     if (tmp_s16b < WEAPON_EXP_UNSKILLED)
255         tmp_s16b = WEAPON_EXP_UNSKILLED;
256
257     if (tmp_s16b > WEAPON_EXP_MASTER)
258         tmp_s16b = WEAPON_EXP_MASTER;
259
260     for (int j = 0; j <= TV_WEAPON_END - TV_WEAPON_BEGIN; j++) {
261         for (int i = 0; i < 64; i++) {
262             creature_ptr->weapon_exp[j][i] = tmp_s16b;
263             if (creature_ptr->weapon_exp[j][i] > s_info[creature_ptr->pclass].w_max[j][i])
264                 creature_ptr->weapon_exp[j][i] = s_info[creature_ptr->pclass].w_max[j][i];
265         }
266     }
267
268     for (int j = 0; j < 10; j++) {
269         creature_ptr->skill_exp[j] = tmp_s16b;
270         if (creature_ptr->skill_exp[j] > s_info[creature_ptr->pclass].s_max[j])
271             creature_ptr->skill_exp[j] = s_info[creature_ptr->pclass].s_max[j];
272     }
273
274     int k;
275     for (k = 0; k < 32; k++)
276         creature_ptr->spell_exp[k] = (tmp_s16b > SPELL_EXP_MASTER ? SPELL_EXP_MASTER : tmp_s16b);
277
278     for (; k < 64; k++)
279         creature_ptr->spell_exp[k] = (tmp_s16b > SPELL_EXP_EXPERT ? SPELL_EXP_EXPERT : tmp_s16b);
280
281     sprintf(tmp_val, "%ld", (long)(creature_ptr->au));
282     if (!get_string("Gold: ", tmp_val, 9))
283         return;
284
285     long tmp_long = atol(tmp_val);
286     if (tmp_long < 0)
287         tmp_long = 0L;
288
289     creature_ptr->au = tmp_long;
290     sprintf(tmp_val, "%ld", (long)(creature_ptr->max_exp));
291     if (!get_string("Experience: ", tmp_val, 9))
292         return;
293
294     tmp_long = atol(tmp_val);
295     if (tmp_long < 0)
296         tmp_long = 0L;
297
298     if (creature_ptr->prace == RACE_ANDROID)
299         return;
300
301     creature_ptr->max_exp = tmp_long;
302     creature_ptr->exp = tmp_long;
303     check_experience(creature_ptr);
304     do_cmd_redraw(creature_ptr);
305 }
306
307 /*!
308  * @brief 指定された地点の地形IDを変更する /
309  * Create desired feature
310  * @param creaturer_ptr プレーヤーへの参照ポインタ
311  * @return なし
312  */
313 void wiz_create_feature(player_type *creature_ptr)
314 {
315     POSITION y, x;
316     if (!tgt_pt(creature_ptr, &x, &y))
317         return;
318
319     grid_type *g_ptr;
320     g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
321     static int prev_feat = 0;
322     char tmp_val[160];
323     sprintf(tmp_val, "%d", prev_feat);
324
325     if (!get_string(_("地形: ", "Feature: "), tmp_val, 3))
326         return;
327
328     FEAT_IDX tmp_feat = (FEAT_IDX)atoi(tmp_val);
329     if (tmp_feat < 0)
330         tmp_feat = 0;
331     else if (tmp_feat >= max_f_idx)
332         tmp_feat = max_f_idx - 1;
333
334     static int prev_mimic = 0;
335     sprintf(tmp_val, "%d", prev_mimic);
336
337     if (!get_string(_("地形 (mimic): ", "Feature (mimic): "), tmp_val, 3))
338         return;
339
340     FEAT_IDX tmp_mimic = (FEAT_IDX)atoi(tmp_val);
341     if (tmp_mimic < 0)
342         tmp_mimic = 0;
343     else if (tmp_mimic >= max_f_idx)
344         tmp_mimic = max_f_idx - 1;
345
346     cave_set_feat(creature_ptr, y, x, tmp_feat);
347     g_ptr->mimic = (s16b)tmp_mimic;
348     feature_type *f_ptr;
349     f_ptr = &f_info[get_feat_mimic(g_ptr)];
350
351     if (have_flag(f_ptr->flags, FF_GLYPH) || have_flag(f_ptr->flags, FF_MINOR_GLYPH))
352         g_ptr->info |= CAVE_OBJECT;
353     else if (have_flag(f_ptr->flags, FF_MIRROR))
354         g_ptr->info |= CAVE_GLOW | CAVE_OBJECT;
355
356     note_spot(creature_ptr, y, x);
357     lite_spot(creature_ptr, y, x);
358     creature_ptr->update |= PU_FLOW;
359     prev_feat = tmp_feat;
360     prev_mimic = tmp_mimic;
361 }
362
363 /*!
364  * @brief 任意のダンジョン及び階層に飛ぶ /
365  * Go to any level
366  * @return なし
367  */
368 void wiz_jump_to_dungeon(player_type *creature_ptr)
369 {
370     if (command_arg <= 0) {
371         char ppp[80];
372         char tmp_val[160];
373         DUNGEON_IDX tmp_dungeon_type;
374         sprintf(ppp, "Jump which dungeon : ");
375         sprintf(tmp_val, "%d", creature_ptr->dungeon_idx);
376         if (!get_string(ppp, tmp_val, 2))
377             return;
378
379         tmp_dungeon_type = (DUNGEON_IDX)atoi(tmp_val);
380         if (!d_info[tmp_dungeon_type].maxdepth || (tmp_dungeon_type > current_world_ptr->max_d_idx))
381             tmp_dungeon_type = DUNGEON_ANGBAND;
382
383         sprintf(ppp, "Jump to level (0, %d-%d): ", (int)d_info[tmp_dungeon_type].mindepth, (int)d_info[tmp_dungeon_type].maxdepth);
384         sprintf(tmp_val, "%d", (int)creature_ptr->current_floor_ptr->dun_level);
385         if (!get_string(ppp, tmp_val, 10))
386             return;
387
388         command_arg = (COMMAND_ARG)atoi(tmp_val);
389         creature_ptr->dungeon_idx = tmp_dungeon_type;
390     }
391
392     if (command_arg < d_info[creature_ptr->dungeon_idx].mindepth)
393         command_arg = 0;
394
395     if (command_arg > d_info[creature_ptr->dungeon_idx].maxdepth)
396         command_arg = (COMMAND_ARG)d_info[creature_ptr->dungeon_idx].maxdepth;
397
398     msg_format("You jump to dungeon level %d.", command_arg);
399     if (autosave_l)
400         do_cmd_save_game(creature_ptr, TRUE);
401
402     creature_ptr->current_floor_ptr->dun_level = command_arg;
403     prepare_change_floor_mode(creature_ptr, CFM_RAND_PLACE);
404     if (!creature_ptr->current_floor_ptr->dun_level)
405         creature_ptr->dungeon_idx = 0;
406
407     creature_ptr->current_floor_ptr->inside_arena = FALSE;
408     creature_ptr->wild_mode = FALSE;
409     leave_quest_check(creature_ptr);
410     if (record_stair)
411         exe_write_diary(creature_ptr, DIARY_WIZ_TELE, 0, NULL);
412
413     creature_ptr->current_floor_ptr->inside_quest = 0;
414     free_turn(creature_ptr);
415     creature_ptr->energy_need = 0;
416     prepare_change_floor_mode(creature_ptr, CFM_FIRST_FLOOR);
417     creature_ptr->leaving = TRUE;
418 }
419
420 /*!
421  * @brief 全ベースアイテムを鑑定済みにする /
422  * Become aware of a lot of objects
423  * @param caster_ptr プレーヤーへの参照ポインタ
424  * @return なし
425  */
426 void wiz_learn_items_all(player_type *caster_ptr)
427 {
428     object_type forge;
429     object_type *q_ptr;
430     for (KIND_OBJECT_IDX i = 1; i < max_k_idx; i++) {
431         object_kind *k_ptr = &k_info[i];
432         if (k_ptr->level <= command_arg) {
433             q_ptr = &forge;
434             object_prep(caster_ptr, q_ptr, i);
435             object_aware(caster_ptr, q_ptr);
436         }
437     }
438 }
439
440 /*!
441  * @brief プレイヤーの職業を変更する
442  * @return なし
443  * @todo 魔法領域の再選択などがまだ不完全、要実装。
444  */
445 void wiz_reset_class(player_type *creature_ptr)
446 {
447     char ppp[80];
448     sprintf(ppp, "Class (0-%d): ", MAX_CLASS - 1);
449
450     char tmp_val[160];
451     sprintf(tmp_val, "%d", creature_ptr->pclass);
452
453     if (!get_string(ppp, tmp_val, 2))
454         return;
455
456     int tmp_int = atoi(tmp_val);
457     if (tmp_int < 0 || tmp_int >= MAX_CLASS)
458         return;
459
460     creature_ptr->pclass = (byte)tmp_int;
461     creature_ptr->window |= PW_PLAYER;
462     creature_ptr->update |= PU_BONUS | PU_HP | PU_MANA | PU_SPELLS;
463     handle_stuff(creature_ptr);
464 }
465
466 /*!
467  * @brief 現在のオプション設定をダンプ出力する /
468  * @param creature_ptr プレーヤーへの参照ポインタ
469  * Hack -- Dump option bits usage
470  * @return なし
471  */
472 void wiz_dump_options(void)
473 {
474     char buf[1024];
475     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "opt_info.txt");
476     FILE *fff;
477     fff = angband_fopen(buf, "a");
478     if (fff == NULL) {
479         msg_format(_("ファイル %s を開けませんでした。", "Failed to open file %s."), buf);
480         msg_print(NULL);
481         return;
482     }
483
484     int **exist;
485     C_MAKE(exist, NUM_O_SET, int *);
486     C_MAKE(*exist, NUM_O_BIT * NUM_O_SET, int);
487     for (int i = 1; i < NUM_O_SET; i++)
488         exist[i] = *exist + i * NUM_O_BIT;
489
490     for (int i = 0; option_info[i].o_desc; i++) {
491         const option_type *ot_ptr = &option_info[i];
492         if (ot_ptr->o_var)
493             exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1;
494     }
495
496     fprintf(fff, "[Option bits usage on Bakabakaband %d.%d.%d]\n\n", FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
497     fputs("Set - Bit (Page) Option Name\n", fff);
498     fputs("------------------------------------------------\n", fff);
499     for (int i = 0; i < NUM_O_SET; i++) {
500         for (int j = 0; j < NUM_O_BIT; j++) {
501             if (exist[i][j]) {
502                 const option_type *ot_ptr = &option_info[exist[i][j] - 1];
503                 fprintf(fff, "  %d -  %02d (%4d) %s\n", i, j, ot_ptr->o_page, ot_ptr->o_text);
504             } else {
505                 fprintf(fff, "  %d -  %02d\n", i, j);
506             }
507         }
508
509         fputc('\n', fff);
510     }
511
512     C_KILL(*exist, NUM_O_BIT * NUM_O_SET, int);
513     C_KILL(exist, NUM_O_SET, int *);
514     angband_fclose(fff);
515     msg_format(_("オプションbit使用状況をファイル %s に書き出しました。", "Option bits usage dump saved to file %s."), buf);
516 }
517
518 /*!
519  * @brief プレイ日数を変更する / Set gametime.
520  * @return 実際に変更を行ったらTRUEを返す
521  */
522 void set_gametime(void)
523 {
524     int tmp_int = 0;
525     char ppp[80], tmp_val[40];
526     sprintf(ppp, "Dungeon Turn (0-%ld): ", (long)current_world_ptr->dungeon_turn_limit);
527     sprintf(tmp_val, "%ld", (long)current_world_ptr->dungeon_turn);
528     if (!get_string(ppp, tmp_val, 10))
529         return;
530
531     tmp_int = atoi(tmp_val);
532     if (tmp_int >= current_world_ptr->dungeon_turn_limit)
533         tmp_int = current_world_ptr->dungeon_turn_limit - 1;
534     else if (tmp_int < 0)
535         tmp_int = 0;
536
537     current_world_ptr->dungeon_turn = current_world_ptr->game_turn = tmp_int;
538 }
539
540 /*!
541  * @brief プレイヤー近辺の全モンスターを消去する / Delete all nearby monsters
542  * @return なし
543  */
544 void wiz_zap_surrounding_monsters(player_type *caster_ptr)
545 {
546     for (MONSTER_IDX i = 1; i < caster_ptr->current_floor_ptr->m_max; i++) {
547         monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[i];
548         if (!monster_is_valid(m_ptr) || (i == caster_ptr->riding) || (m_ptr->cdis > MAX_SIGHT))
549             continue;
550
551         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname) {
552             GAME_TEXT m_name[MAX_NLEN];
553
554             monster_desc(caster_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
555             exe_write_diary(caster_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
556         }
557
558         delete_monster_idx(caster_ptr, i);
559     }
560 }
561
562 /*!
563  * @brief フロアに存在する全モンスターを消去する / Delete all monsters
564  * @param caster_ptr 術者の参照ポインタ
565  * @return なし
566  */
567 void wiz_zap_floor_monsters(player_type *caster_ptr)
568 {
569     for (MONSTER_IDX i = 1; i < caster_ptr->current_floor_ptr->m_max; i++) {
570         monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[i];
571         if (!monster_is_valid(m_ptr) || (i == caster_ptr->riding))
572             continue;
573
574         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname) {
575             GAME_TEXT m_name[MAX_NLEN];
576             monster_desc(caster_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
577             exe_write_diary(caster_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
578         }
579
580         delete_monster_idx(caster_ptr, i);
581     }
582 }