2 * @brief ゲームプレイのメインルーチン
6 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
7 * This software may be copied and distributed for educational, research, and
8 * not for profit purposes provided that this copyright and statement are
9 * included in all such copies.
10 * 2013 Deskull rearranged comment for Doxygen.
13 #include "core/game-play.h"
14 #include "autopick/autopick-pref-processor.h"
15 #include "birth/character-builder.h"
16 #include "birth/inventory-initializer.h"
17 #include "cmd-io/cmd-gameoption.h"
18 #include "core/asking-player.h"
19 #include "core/game-closer.h"
20 #include "core/player-processor.h"
21 #include "core/player-update-types.h"
22 #include "core/score-util.h"
23 #include "core/scores.h"
24 #include "core/speed-table.h"
25 #include "core/stuff-handler.h"
26 #include "core/visuals-reseter.h"
27 #include "core/window-redrawer.h"
28 #include "dungeon/dungeon-processor.h"
29 #include "flavor/object-flavor.h"
30 #include "floor/cave.h"
31 #include "floor/floor-changer.h"
32 #include "floor/floor-events.h"
33 #include "floor/floor-leaver.h"
34 #include "floor/floor-mode-changer.h"
35 #include "floor/floor-save.h"
36 #include "floor/floor-util.h"
37 #include "floor/wild.h"
38 #include "game-option/cheat-options.h"
39 #include "game-option/input-options.h"
40 #include "game-option/play-record-options.h"
41 #include "game-option/runtime-arguments.h"
42 #include "grid/feature.h"
43 #include "grid/grid.h"
44 #include "info-reader/fixed-map-parser.h"
46 #include "io/input-key-acceptor.h"
47 #include "io/input-key-processor.h"
48 #include "io/read-pref-file.h"
49 #include "io/record-play-movie.h"
50 #include "io/screen-util.h"
51 #include "io/signal-handlers.h"
52 #include "io/write-diary.h"
53 #include "load/load.h"
54 #include "main/sound-of-music.h"
55 #include "market/arena-info-table.h"
56 #include "market/bounty.h"
57 #include "market/building-initializer.h"
58 #include "monster-floor/monster-generator.h"
59 #include "monster-floor/monster-lite.h"
60 #include "monster-floor/monster-remover.h"
61 #include "monster-floor/place-monster-types.h"
62 #include "monster-race/monster-race.h"
63 #include "monster-race/race-indice-types.h"
64 #include "monster/monster-util.h"
65 #include "player-info/race-types.h"
66 #include "player/player-class.h"
67 #include "player/player-personality-types.h"
68 #include "player/player-skill.h"
69 #include "player/player-status.h"
70 #include "player/process-name.h"
71 #include "racial/racial-android.h"
72 #include "realm/realm-names-table.h"
73 #include "save/save.h"
74 #include "spell/spells-status.h"
75 #include "spell/technic-info-table.h"
76 #include "status/buff-setter.h"
77 #include "store/home.h"
78 #include "store/store-util.h"
79 #include "store/store.h"
80 #include "sv-definition/sv-weapon-types.h"
81 #include "system/angband-version.h"
82 #include "system/floor-type-definition.h"
83 #include "system/monster-race-definition.h"
84 #include "system/monster-type-definition.h"
85 #include "system/object-type-definition.h"
86 #include "system/player-type-definition.h"
87 #include "target/target-checker.h"
88 #include "term/gameterm.h"
89 #include "term/screen-processor.h"
90 #include "util/angband-files.h"
91 #include "view/display-messages.h"
92 #include "view/display-player.h"
93 #include "window/main-window-util.h"
94 #include "wizard/wizard-special-process.h"
95 #include "world/world.h"
97 static void restore_windows(player_type *player_ptr)
99 player_ptr->hack_mutation = false;
100 current_world_ptr->character_icky_depth = 1;
101 term_activate(angband_term[0]);
102 angband_term[0]->resize_hook = resize_map;
103 for (MONSTER_IDX i = 1; i < 8; i++)
105 angband_term[i]->resize_hook = redraw_window;
107 (void)term_set_cursor(0);
110 static void send_waiting_record(player_type *player_ptr)
112 if (!player_ptr->wait_report_score)
116 if (!get_check_strict(player_ptr, _("待機していたスコア登録を今行ないますか?", "Do you register score now? "), CHECK_NO_HISTORY))
119 player_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
120 update_creature(player_ptr);
121 player_ptr->is_dead = true;
122 current_world_ptr->start_time = (uint32_t)time(nullptr);
123 signals_ignore_tstp();
124 current_world_ptr->character_icky_depth = 1;
125 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
126 highscore_fd = fd_open(buf, O_RDWR);
128 /* 町名消失バグ対策(#38205)のためここで世界マップ情報を読み出す */
129 parse_fixed_map(player_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
130 bool success = send_world_score(player_ptr, true, display_player);
131 if (!success && !get_check_strict(player_ptr, _("スコア登録を諦めますか?", "Do you give up score registration? "), CHECK_NO_HISTORY)) {
132 prt(_("引き続き待機します。", "standing by for future registration..."), 0, 0);
135 player_ptr->wait_report_score = false;
136 top_twenty(player_ptr);
137 if (!save_player(player_ptr, SAVE_TYPE_CLOSE_GAME))
138 msg_print(_("セーブ失敗!", "death save failed!"));
141 (void)fd_close(highscore_fd);
143 signals_handle_tstp();
147 static void init_random_seed(player_type *player_ptr, bool new_game)
149 bool init_random_seed = false;
150 if (!current_world_ptr->character_loaded) {
152 current_world_ptr->character_dungeon = false;
153 init_random_seed = true;
154 init_saved_floors(player_ptr, false);
156 init_saved_floors(player_ptr, true);
159 process_player_name(player_ptr);
161 if (init_random_seed)
165 static void init_world_floor_info(player_type *player_ptr)
167 current_world_ptr->character_dungeon = false;
168 floor_type *floor_ptr = player_ptr->current_floor_ptr;
169 floor_ptr->dun_level = 0;
170 floor_ptr->inside_quest = 0;
171 floor_ptr->inside_arena = false;
172 player_ptr->phase_out = false;
174 current_world_ptr->seed_flavor = randint0(0x10000000);
175 current_world_ptr->seed_town = randint0(0x10000000);
176 player_birth(player_ptr);
177 counts_write(player_ptr, 2, 0);
178 player_ptr->count = 0;
180 determine_bounty_uniques(player_ptr);
181 determine_daily_bounty(player_ptr, false);
182 wipe_o_list(floor_ptr);
186 * @brief フロア情報をゲームロード時に復帰
188 * 1.0.9 以前はセーブ前に player_ptr->riding = -1 としていたので、再設定が必要だった。
189 * もう不要だが、以前のセーブファイルとの互換のために残しておく。
191 static void restore_world_floor_info(player_type *player_ptr)
194 exe_write_diary(player_ptr, DIARY_GAMESTART, 1, _(" ----ゲーム再開----", " --- Restarted Game ---"));
196 if (player_ptr->riding == -1) {
197 player_ptr->riding = 0;
198 floor_type *floor_ptr = player_ptr->current_floor_ptr;
199 for (MONSTER_IDX i = floor_ptr->m_max; i > 0; i--) {
200 if (player_bold(player_ptr, floor_ptr->m_list[i].fy, floor_ptr->m_list[i].fx)) {
201 player_ptr->riding = i;
208 static void reset_world_info(player_type *player_ptr)
210 current_world_ptr->creating_savefile = false;
211 player_ptr->teleport_town = false;
212 player_ptr->sutemi = false;
213 current_world_ptr->timewalk_m_idx = 0;
214 player_ptr->now_damaged = false;
216 current_world_ptr->start_time = time(nullptr) - 1;
217 record_o_name[0] = '\0';
220 static void set_wizard_mode_by_argument(player_type *player_ptr)
225 if (enter_wizard_mode(player_ptr)) {
226 current_world_ptr->wizard = true;
227 if (player_ptr->is_dead || !player_ptr->y || !player_ptr->x) {
228 init_saved_floors(player_ptr, true);
229 player_ptr->current_floor_ptr->inside_quest = 0;
230 player_ptr->y = player_ptr->x = 10;
236 if (player_ptr->is_dead)
237 quit("Already dead.");
240 static void generate_wilderness(player_type *player_ptr)
242 floor_type *floor_ptr = player_ptr->current_floor_ptr;
243 if ((floor_ptr->dun_level == 0) && floor_ptr->inside_quest)
246 parse_fixed_map(player_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
247 init_flags = INIT_ONLY_BUILDINGS;
248 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
249 select_floor_music(player_ptr);
252 static void change_floor_if_error(player_type *player_ptr)
254 if (!current_world_ptr->character_dungeon) {
255 change_floor(player_ptr);
259 if (player_ptr->panic_save == 0)
262 if (!player_ptr->y || !player_ptr->x) {
263 msg_print(_("プレイヤーの位置がおかしい。フロアを再生成します。", "What a strange player location, regenerate the dungeon floor."));
264 change_floor(player_ptr);
267 if (!player_ptr->y || !player_ptr->x)
268 player_ptr->y = player_ptr->x = 10;
270 player_ptr->panic_save = 0;
273 static void generate_world(player_type *player_ptr, bool new_game)
275 reset_world_info(player_ptr);
276 floor_type *floor_ptr = player_ptr->current_floor_ptr;
277 panel_row_min = floor_ptr->height;
278 panel_col_min = floor_ptr->width;
280 if (player_ptr->pclass != CLASS_SORCERER) {
281 if (player_ptr->pseikaku == PERSONALITY_SEXY)
282 s_info[player_ptr->pclass].w_max[TV_HAFTED - TV_WEAPON_BEGIN][SV_WHIP] = WEAPON_EXP_MASTER;
283 if (player_ptr->prace == player_race_type::MERFOLK) {
284 s_info[player_ptr->pclass].w_max[TV_POLEARM - TV_WEAPON_BEGIN][SV_TRIDENT] = WEAPON_EXP_MASTER;
285 s_info[player_ptr->pclass].w_max[TV_POLEARM - TV_WEAPON_BEGIN][SV_TRIFURCATE_SPEAR] = WEAPON_EXP_MASTER;
289 set_floor_and_wall(player_ptr->dungeon_idx);
291 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
293 set_wizard_mode_by_argument(player_ptr);
294 generate_wilderness(player_ptr);
295 change_floor_if_error(player_ptr);
296 current_world_ptr->character_generated = true;
297 current_world_ptr->character_icky_depth = 0;
302 sprintf(buf, _("%sに降り立った。", "arrived in %s."), map_name(player_ptr));
303 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, buf);
306 static void init_io(player_type *player_ptr)
308 term_xtra(TERM_XTRA_REACT, 0);
309 player_ptr->window_flags = PW_ALL;
310 handle_stuff(player_ptr);
311 if (arg_force_original)
312 rogue_like_commands = false;
314 if (arg_force_roguelike)
315 rogue_like_commands = true;
318 static void init_riding_pet(player_type *player_ptr, bool new_game)
320 if (!new_game || ((player_ptr->pclass != CLASS_CAVALRY) && (player_ptr->pclass != CLASS_BEASTMASTER)))
323 MONRACE_IDX pet_r_idx = ((player_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
324 monster_race *r_ptr = &r_info[pet_r_idx];
325 place_monster_aux(player_ptr, 0, player_ptr->y, player_ptr->x - 1, pet_r_idx, (PM_FORCE_PET | PM_NO_KAGE));
326 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[hack_m_idx_ii];
327 m_ptr->mspeed = r_ptr->speed;
328 m_ptr->maxhp = r_ptr->hdice * (r_ptr->hside + 1) / 2;
329 m_ptr->max_maxhp = m_ptr->maxhp;
330 m_ptr->hp = r_ptr->hdice * (r_ptr->hside + 1) / 2;
331 m_ptr->dealt_damage = 0;
332 m_ptr->energy_need = ENERGY_NEED() + ENERGY_NEED();
335 static void decide_arena_death(player_type *player_ptr)
337 if (!player_ptr->playing || !player_ptr->is_dead)
340 floor_type *floor_ptr = player_ptr->current_floor_ptr;
341 if (!floor_ptr->inside_arena) {
342 if ((current_world_ptr->wizard || cheat_live) && !get_check(_("死にますか? ", "Die? ")))
343 cheat_death(player_ptr);
348 floor_ptr->inside_arena = false;
349 if (player_ptr->arena_number > MAX_ARENA_MONS)
350 player_ptr->arena_number++;
352 player_ptr->arena_number = -1 - player_ptr->arena_number;
354 player_ptr->is_dead = false;
356 player_ptr->chp_frac = 0;
357 player_ptr->exit_bldg = true;
358 reset_tim_flags(player_ptr);
359 prepare_change_floor_mode(player_ptr, CFM_SAVE_FLOORS | CFM_RAND_CONNECT);
360 leave_floor(player_ptr);
363 static void process_game_turn(player_type *player_ptr)
365 bool load_game = true;
366 floor_type *floor_ptr = player_ptr->current_floor_ptr;
368 process_dungeon(player_ptr, load_game);
369 current_world_ptr->character_xtra = true;
370 handle_stuff(player_ptr);
371 current_world_ptr->character_xtra = false;
373 health_track(player_ptr, 0);
374 forget_lite(floor_ptr);
375 forget_view(floor_ptr);
376 clear_mon_lite(floor_ptr);
377 if (!player_ptr->playing && !player_ptr->is_dead)
380 wipe_o_list(floor_ptr);
381 if (!player_ptr->is_dead)
382 wipe_monsters_list(player_ptr);
386 decide_arena_death(player_ptr);
387 if (player_ptr->is_dead)
390 change_floor(player_ptr);
395 * @brief 1ゲームプレイの主要ルーチン / Actually play a game
396 * @param player_ptr プレーヤーへの参照ポインタ
397 * @param new_game 新規にゲームを始めたかどうか
398 * @param browsing_movie ムービーモードか
400 * If the "new_game" parameter is true, then, after loading the
401 * savefile, we will commit suicide, if necessary, to allow the
402 * player to start a new game.
404 void play_game(player_type *player_ptr, bool new_game, bool browsing_movie)
406 if (browsing_movie) {
407 reset_visuals(player_ptr);
412 restore_windows(player_ptr);
413 if (!load_savedata(player_ptr, &new_game))
414 quit(_("セーブファイルが壊れています", "broken savefile"));
416 extract_option_vars();
417 send_waiting_record(player_ptr);
418 current_world_ptr->creating_savefile = new_game;
419 init_random_seed(player_ptr, new_game);
421 init_world_floor_info(player_ptr);
423 restore_world_floor_info(player_ptr);
425 generate_world(player_ptr, new_game);
426 player_ptr->playing = true;
427 reset_visuals(player_ptr);
428 load_all_pref_files(player_ptr);
430 player_outfit(player_ptr);
433 if (player_ptr->chp < 0 && !cheat_immortal)
434 player_ptr->is_dead = true;
436 if (player_ptr->prace == player_race_type::ANDROID)
437 calc_android_exp(player_ptr);
439 init_riding_pet(player_ptr, new_game);
440 (void)combine_and_reorder_home(player_ptr, STORE_HOME);
441 (void)combine_and_reorder_home(player_ptr, STORE_MUSEUM);
442 select_floor_music(player_ptr);
443 process_game_turn(player_ptr);
444 close_game(player_ptr);