OSDN Git Service

[Refactor] #37353 mind.h を作成して宣言を externs.h から分離。 Makefile.am 修正。
[hengband/hengband.git] / src / dungeon.c
index 71154a6..bae5cd1 100644 (file)
  */
 
 #include "angband.h"
+#include "birth.h"
 #include "cmd-activate.h"
 #include "cmd-eat.h"
+#include "cmd-hissatsu.h"
 #include "cmd-item.h"
 #include "cmd-magiceat.h"
+#include "cmd-mane.h"
 #include "cmd-quaff.h"
 #include "cmd-read.h"
 #include "cmd-smith.h"
 #include "cmd-zaprod.h"
 #include "cmd-zapwand.h"
 #include "cmd-pet.h"
+#include "cmd-basic.h"
+#include "snipe.h"
 #include "floor.h"
 #include "floor-events.h"
+#include "grid.h"
 #include "object-curse.h"
+#include "object-flavor.h"
 #include "store.h"
+#include "spells.h"
 #include "spells-summon.h"
 #include "spells-object.h"
 #include "spells-status.h"
 #include "spells-floor.h"
-#include "monsterrace-hook.h"
+#include "mind.h"
 #include "world.h"
 #include "mutation.h"
 #include "quest.h"
 #include "realm-hex.h"
 #include "object-hook.h"
 #include "wild.h"
+#include "monster-process.h"
+#include "monster-status.h"
+#include "monsterrace-hook.h"
+#include "floor-save.h"
 
+#include "view-mainwindow.h"
+#include "dungeon-file.h"
+#include "files.h"
+#include "player-effects.h"
 
 static bool load = TRUE; /*!<ロード処理中の分岐フラグ*/
 static int wild_regen = 20; /*!<広域マップ移動時の自然回復処理カウンタ(広域マップ1マス毎に20回処理を基本とする)*/
@@ -579,11 +595,7 @@ static void pattern_teleport(void)
        {
                return;
        }
-
-       /* Paranoia */
        if (command_arg < min_level) command_arg = (COMMAND_ARG)min_level;
-
-       /* Paranoia */
        if (command_arg > max_level) command_arg = (COMMAND_ARG)max_level;
 
        /* Accept request */
@@ -869,9 +881,7 @@ static void regen_monsters(void)
                monster_type *m_ptr = &current_floor_ptr->m_list[i];
                monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
-
-               /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Allow regeneration (if needed) */
                if (m_ptr->hp < m_ptr->maxhp)
@@ -2418,9 +2428,7 @@ static void process_world_aux_mutation(void)
                {
                        monster_type *m_ptr = &current_floor_ptr->m_list[monster];
                        monster_race *r_ptr = &r_info[m_ptr->r_idx];
-
-                       /* Paranoia -- Skip dead monsters */
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
 
                        if (r_ptr->level >= p_ptr->lev)
                        {
@@ -3025,235 +3033,6 @@ static void process_world_aux_movement(void)
        }
 }
 
-
-/*!
- * @brief 指定したモンスターに隣接しているモンスターの数を返す。
- * / Count number of adjacent monsters
- * @param m_idx 隣接数を調べたいモンスターのID
- * @return 隣接しているモンスターの数
- */
-static int get_monster_crowd_number(MONSTER_IDX m_idx)
-{
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
-       POSITION my = m_ptr->fy;
-       POSITION mx = m_ptr->fx;
-       int i;
-       int count = 0;
-
-       for (i = 0; i < 7; i++)
-       {
-               int ay = my + ddy_ddd[i];
-               int ax = mx + ddx_ddd[i];
-
-               if (!in_bounds(ay, ax)) continue;
-
-               /* Count number of monsters */
-               if (current_floor_ptr->grid_array[ay][ax].m_idx > 0) count++;
-       }
-
-       return count;
-}
-
-
-
-/*!
- * ダンジョンの雰囲気を計算するための非線形基準値 / Dungeon rating is no longer linear
- */
-#define RATING_BOOST(delta) (delta * delta + 50 * delta)
-
-/*!
- * @brief ダンジョンの雰囲気を算出する。
- * / Examine all monsters and unidentified objects, and get the feeling of current dungeon floor
- * @return 算出されたダンジョンの雰囲気ランク
- */
-static byte get_dungeon_feeling(void)
-{
-       const int base = 10;
-       int rating = 0;
-       IDX i;
-
-       /* Hack -- no feeling in the town */
-       if (!current_floor_ptr->dun_level) return 0;
-
-       /* Examine each monster */
-       for (i = 1; i < m_max; i++)
-       {
-               monster_type *m_ptr = &current_floor_ptr->m_list[i];
-               monster_race *r_ptr;
-               int delta = 0;
-
-               /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
-
-               /* Ignore pet */
-               if (is_pet(m_ptr)) continue;
-
-               r_ptr = &r_info[m_ptr->r_idx];
-
-               /* Unique monsters */
-               if (r_ptr->flags1 & (RF1_UNIQUE))
-               {
-                       /* Nearly out-of-depth unique monsters */
-                       if (r_ptr->level + 10 > current_floor_ptr->dun_level)
-                       {
-                               /* Boost rating by twice delta-depth */
-                               delta += (r_ptr->level + 10 - current_floor_ptr->dun_level) * 2 * base;
-                       }
-               }
-               else
-               {
-                       /* Out-of-depth monsters */
-                       if (r_ptr->level > current_floor_ptr->dun_level)
-                       {
-                               /* Boost rating by delta-depth */
-                               delta += (r_ptr->level - current_floor_ptr->dun_level) * base;
-                       }
-               }
-
-               /* Unusually crowded monsters get a little bit of rating boost */
-               if (r_ptr->flags1 & RF1_FRIENDS)
-               {
-                       if (5 <= get_monster_crowd_number(i)) delta += 1;
-               }
-               else
-               {
-                       if (2 <= get_monster_crowd_number(i)) delta += 1;
-               }
-
-
-               rating += RATING_BOOST(delta);
-       }
-
-       /* Examine each unidentified object */
-       for (i = 1; i < o_max; i++)
-       {
-               object_type *o_ptr = &current_floor_ptr->o_list[i];
-               object_kind *k_ptr = &k_info[o_ptr->k_idx];
-               int delta = 0;
-
-               /* Skip dead objects */
-               if (!o_ptr->k_idx) continue;
-
-               /* Skip known objects */
-               if (object_is_known(o_ptr))
-               {
-                       /* Touched? */
-                       if (o_ptr->marked & OM_TOUCHED) continue;
-               }
-
-               /* Skip pseudo-known objects */
-               if (o_ptr->ident & IDENT_SENSE) continue;
-
-               /* Ego objects */
-               if (object_is_ego(o_ptr))
-               {
-                       ego_item_type *e_ptr = &e_info[o_ptr->name2];
-
-                       delta += e_ptr->rating * base;
-               }
-
-               /* Artifacts */
-               if (object_is_artifact(o_ptr))
-               {
-                       PRICE cost = object_value_real(o_ptr);
-
-                       delta += 10 * base;
-                       if (cost > 10000L) delta += 10 * base;
-                       if (cost > 50000L) delta += 10 * base;
-                       if (cost > 100000L) delta += 10 * base;
-
-                       /* Special feeling */
-                       if (!preserve_mode) return 1;
-               }
-
-               if (o_ptr->tval == TV_DRAG_ARMOR) delta += 30 * base;
-               if (o_ptr->tval == TV_SHIELD && o_ptr->sval == SV_DRAGON_SHIELD) delta += 5 * base;
-               if (o_ptr->tval == TV_GLOVES && o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) delta += 5 * base;
-               if (o_ptr->tval == TV_BOOTS && o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) delta += 5 * base;
-               if (o_ptr->tval == TV_HELM && o_ptr->sval == SV_DRAGON_HELM) delta += 5 * base;
-               if (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_SPEED && !object_is_cursed(o_ptr)) delta += 25 * base;
-               if (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_LORDLY && !object_is_cursed(o_ptr)) delta += 15 * base;
-               if (o_ptr->tval == TV_AMULET && o_ptr->sval == SV_AMULET_THE_MAGI && !object_is_cursed(o_ptr)) delta += 15 * base;
-
-               /* Out-of-depth objects */
-               if (!object_is_cursed(o_ptr) && !object_is_broken(o_ptr) && k_ptr->level > current_floor_ptr->dun_level)
-               {
-                       /* Rating increase */
-                       delta += (k_ptr->level - current_floor_ptr->dun_level) * base;
-               }
-
-               rating += RATING_BOOST(delta);
-       }
-
-
-       if (rating > RATING_BOOST(1000)) return 2;
-       if (rating > RATING_BOOST(800)) return 3;
-       if (rating > RATING_BOOST(600)) return 4;
-       if (rating > RATING_BOOST(400)) return 5;
-       if (rating > RATING_BOOST(300)) return 6;
-       if (rating > RATING_BOOST(200)) return 7;
-       if (rating > RATING_BOOST(100)) return 8;
-       if (rating > RATING_BOOST(0)) return 9;
-
-       return 10;
-}
-
-/*!
- * @brief ダンジョンの雰囲気を更新し、変化があった場合メッセージを表示する
- * / Update dungeon feeling, and announce it if changed
- * @return なし
- */
-static void update_dungeon_feeling(void)
-{
-       byte new_feeling;
-       int quest_num;
-       int delay;
-
-       /* No feeling on the surface */
-       if (!current_floor_ptr->dun_level) return;
-
-       /* No feeling in the arena */
-       if (p_ptr->inside_battle) return;
-
-       /* Extract delay time */
-       delay = MAX(10, 150 - p_ptr->skill_fos) * (150 - current_floor_ptr->dun_level) * TURNS_PER_TICK / 100;
-
-       /* Not yet felt anything */
-       if (current_world_ptr->game_turn < p_ptr->feeling_turn + delay && !cheat_xtra) return;
-
-       /* Extract quest number (if any) */
-       quest_num = quest_number(current_floor_ptr->dun_level);
-
-       /* No feeling in a quest */
-       if (quest_num &&
-           (is_fixed_quest_idx(quest_num) &&
-            !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
-              !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) return;
-
-
-       /* Get new dungeon feeling */
-       new_feeling = get_dungeon_feeling();
-
-       /* Remember last time updated */
-       p_ptr->feeling_turn = current_world_ptr->game_turn;
-
-       /* No change */
-       if (p_ptr->feeling == new_feeling) return;
-
-       /* Dungeon feeling is changed */
-       p_ptr->feeling = new_feeling;
-
-       /* Announce feeling */
-       do_cmd_feeling();
-
-       select_floor_music();
-
-       /* Update the level indicator */
-       p_ptr->redraw |= (PR_DEPTH);
-
-       if (disturb_minor) disturb(FALSE, FALSE);
-}
-
 /*!
  * @brief 10ゲームターンが進行する毎にゲーム世界全体の処理を行う。
  * / Handle certain things once every 10 game turns
@@ -3308,7 +3087,7 @@ static void process_world(void)
                        msg_print(_("相打ちに終わりました。", "They have kill each other at the same time."));
                        msg_print(NULL);
                        p_ptr->energy_need = 0;
-                       battle_monsters();
+                       update_gambling_monsters();
                }
                else if ((number_mon-1) == 0)
                {
@@ -3333,7 +3112,7 @@ static void process_world(void)
                        }
                        msg_print(NULL);
                        p_ptr->energy_need = 0;
-                       battle_monsters();
+                       update_gambling_monsters();
                }
                else if (current_world_ptr->game_turn - current_floor_ptr->generated_turn == 150 * TURNS_PER_TICK)
                {
@@ -3341,7 +3120,7 @@ static void process_world(void)
                        p_ptr->au += kakekin;
                        msg_print(NULL);
                        p_ptr->energy_need = 0;
-                       battle_monsters();
+                       update_gambling_monsters();
                }
        }
 
@@ -4628,7 +4407,7 @@ static void process_player(void)
                {
                        monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
 
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
 
                        m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
                        update_monster(m_idx, FALSE);
@@ -4992,9 +4771,7 @@ static void process_player(void)
                                        monster_race *r_ptr;
 
                                        m_ptr = &current_floor_ptr->m_list[m_idx];
-
-                                       /* Skip dead monsters */
-                                       if (!m_ptr->r_idx) continue;
+                                       if (!monster_is_valid(m_ptr)) continue;
 
                                        /* Skip unseen monsters */
                                        if (!m_ptr->ml) continue;
@@ -5026,9 +4803,7 @@ static void process_player(void)
                                {
                                        monster_type *m_ptr;
                                        m_ptr = &current_floor_ptr->m_list[m_idx];
-
-                                       /* Skip dead monsters */
-                                       if (!m_ptr->r_idx) continue;
+                                       if (!monster_is_valid(m_ptr)) continue;
 
                                        /* Nice monsters get mean */
                                        if (m_ptr->mflag & MFLAG_NICE)
@@ -5241,7 +5016,7 @@ static void dungeon(bool load_game)
                if (load_game)
                {
                        p_ptr->energy_need = 0;
-                       battle_monsters();
+                       update_gambling_monsters();
                }
                else
                {
@@ -6096,7 +5871,7 @@ void prevent_turn_overflow(void)
        rollback_turns = TURNS_PER_TICK * TOWN_DAWN * rollback_days;
 
        if (current_world_ptr->game_turn > rollback_turns) current_world_ptr->game_turn -= rollback_turns;
-       else current_world_ptr->game_turn = 1; /* Paranoia */
+       else current_world_ptr->game_turn = 1;
        if (current_floor_ptr->generated_turn > rollback_turns) current_floor_ptr->generated_turn -= rollback_turns;
        else current_floor_ptr->generated_turn = 1;
        if (old_battle > rollback_turns) old_battle -= rollback_turns;
@@ -6124,3 +5899,122 @@ void prevent_turn_overflow(void)
                }
        }
 }
+
+/*!
+ * @brief ゲーム終了処理 /
+ * Close up the current game (player may or may not be dead)
+ * @return なし
+ * @details
+ * <pre>
+ * This function is called only from "main.c" and "signals.c".
+ * </pre>
+ */
+void close_game(void)
+{
+       char buf[1024];
+       bool do_send = TRUE;
+
+       /*      concptr p = "[i:キャラクタの情報, f:ファイル書き出し, t:スコア, x:*鑑定*, ESC:ゲーム終了]"; */
+       handle_stuff();
+
+       /* Flush the messages */
+       msg_print(NULL);
+
+       /* Flush the input */
+       flush();
+
+
+       /* No suspending now */
+       signals_ignore_tstp();
+
+
+       /* Hack -- Character is now "icky" */
+       character_icky = TRUE;
+
+
+       /* Build the filename */
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
+
+       /* Grab permissions */
+       safe_setuid_grab();
+
+       /* Open the high score file, for reading/writing */
+       highscore_fd = fd_open(buf, O_RDWR);
+
+       /* Drop permissions */
+       safe_setuid_drop();
+
+       /* Handle death */
+       if (p_ptr->is_dead)
+       {
+               /* Handle retirement */
+               if (p_ptr->total_winner) kingly();
+
+               /* Save memories */
+               if (!cheat_save || get_check(_("死んだデータをセーブしますか? ", "Save death? ")))
+               {
+                       if (!save_player()) msg_print(_("セーブ失敗!", "death save failed!"));
+               }
+               else do_send = FALSE;
+
+               /* You are dead */
+               print_tomb();
+
+               flush();
+
+               /* Show more info */
+               show_info();
+               Term_clear();
+
+               if (check_score())
+               {
+                       if ((!send_world_score(do_send)))
+                       {
+                               if (get_check_strict(_("後でスコアを登録するために待機しますか?", "Stand by for later score registration? "),
+                                       (CHECK_NO_ESCAPE | CHECK_NO_HISTORY)))
+                               {
+                                       p_ptr->wait_report_score = TRUE;
+                                       p_ptr->is_dead = FALSE;
+                                       if (!save_player()) msg_print(_("セーブ失敗!", "death save failed!"));
+                               }
+                       }
+                       if (!p_ptr->wait_report_score)
+                               (void)top_twenty();
+               }
+               else if (highscore_fd >= 0)
+               {
+                       display_scores_aux(0, 10, -1, NULL);
+               }
+#if 0
+               /* Dump bones file */
+               make_bones();
+#endif
+       }
+
+       /* Still alive */
+       else
+       {
+               /* Save the game */
+               do_cmd_save_game(FALSE);
+
+               /* Prompt for scores */
+               prt(_("リターンキーか ESC キーを押して下さい。", "Press Return (or Escape)."), 0, 40);
+               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_EXIT);
+
+               /* Predict score (or ESCAPE) */
+               if (inkey() != ESCAPE) predict_score();
+       }
+
+
+       /* Shut the high score file */
+       (void)fd_close(highscore_fd);
+
+       /* Forget the high score fd */
+       highscore_fd = -1;
+
+       /* Kill all temporal files */
+       clear_saved_floor_files();
+
+       /* Allow suspending now */
+       signals_handle_tstp();
+}