OSDN Git Service

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