OSDN Git Service

[Refactor] #39970 Separated world-turn-processor.c/h from core.c
authorHourier <hourier@users.sourceforge.jp>
Sun, 10 May 2020 13:04:09 +0000 (22:04 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 10 May 2020 13:04:09 +0000 (22:04 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/core.c
src/world/world-turn-processor.c [new file with mode: 0644]
src/world/world-turn-processor.h [new file with mode: 0644]

index 9902cd3..9f5aa05 100644 (file)
     <ClCompile Include="..\..\src\wizard\wizard-special-process.c" />\r
     <ClCompile Include="..\..\src\world.c" />\r
     <ClCompile Include="..\..\src\world\world-movement-processor.c" />\r
+    <ClCompile Include="..\..\src\world\world-turn-processor.c" />\r
     <ClCompile Include="..\..\src\z-form.c" />\r
     <ClCompile Include="..\..\src\z-rand.c" />\r
     <ClCompile Include="..\..\src\z-term.c" />\r
     <ClInclude Include="..\..\src\wizard\wizard-special-process.h" />\r
     <ClInclude Include="..\..\src\wizard\wizard-spoiler.h" />\r
     <ClInclude Include="..\..\src\world\world-movement-processor.h" />\r
+    <ClInclude Include="..\..\src\world\world-turn-processor.h" />\r
     <ClInclude Include="japanese.h" />\r
   </ItemGroup>\r
   <ItemGroup>\r
index 5d7fedf..8e8b93d 100644 (file)
     <ClCompile Include="..\..\src\world\world-movement-processor.c">
       <Filter>world</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\world\world-turn-processor.c">
+      <Filter>world</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\world\world-movement-processor.h">
       <Filter>world</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\world\world-turn-processor.h">
+      <Filter>world</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 0a812a6..eddc8af 100644 (file)
@@ -272,6 +272,7 @@ hengband_SOURCES = \
        wizard/wizard-special-process.c wizard/wizard-special-process.h \
        \
        world/world-movement-processor.c world/world-movement-processor.h \
+       world/world-turn-processor.c world/world-turn-processor.h \
 
 EXTRA_hengband_SOURCES = \
        angband.ico angband.rc ang_eng.rc maid-x11.c main-win.c \
index 2637f54..d75990a 100644 (file)
 #include "core/output-updater.h"
 #include "core/game-closer.h"
 #include "core/turn-compensator.h"
-#include "inventory/simple-appraiser.h"
 #include "core/hp-mp-regenerator.h"
-#include "core/hp-mp-processor.h"
-#include "mutation/mutation-processor.h"
-#include "object/lite-processor.h"
-#include "core/magic-effects-timeout-reducer.h"
-#include "inventory/inventory-curse.h"
-#include "inventory/recharge-processor.h"
 #include "io/input-key-processor.h"
 #include "core/player-processor.h"
-#include "player/digestion-processor.h"
-#include "world/world-movement-processor.h"
+#include "world/world-turn-processor.h"
 
-#include "cmd/cmd-save.h"
 #include "cmd/cmd-dump.h"
 
-
  /*!
   * todo どこからも呼ばれていない。main関数辺りに移設するか、そもそもコメントでいいと思われる
   * コピーライト情報 / Link a copyright message into the executable
@@ -109,233 +99,6 @@ concptr ANGBAND_GRAF = "ascii";
 int init_flags;
 
 /*!
- * @brief 10ゲームターンが進行する毎にゲーム世界全体の処理を行う。
- * / Handle certain things once every 10 game turns
- * @param player_ptr プレーヤーへの参照ポインタ
- * @return なし
- */
-static void process_world(player_type *player_ptr)
-{
-       const s32b A_DAY = TURNS_PER_TICK * TOWN_DAWN;
-       s32b prev_turn_in_today = ((current_world_ptr->game_turn - TURNS_PER_TICK) % A_DAY + A_DAY / 4) % A_DAY;
-       int prev_min = (1440 * prev_turn_in_today / A_DAY) % 60;
-
-       int day, hour, min;
-       extract_day_hour_min(player_ptr, &day, &hour, &min);
-       update_dungeon_feeling(player_ptr);
-
-       /* 帰還無しモード時のレベルテレポバグ対策 / Fix for level teleport bugs on ironman_downward.*/
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (ironman_downward && (player_ptr->dungeon_idx != DUNGEON_ANGBAND && player_ptr->dungeon_idx != 0))
-       {
-               floor_ptr->dun_level = 0;
-               player_ptr->dungeon_idx = 0;
-               prepare_change_floor_mode(player_ptr, CFM_FIRST_FLOOR | CFM_RAND_PLACE);
-               floor_ptr->inside_arena = FALSE;
-               player_ptr->wild_mode = FALSE;
-               player_ptr->leaving = TRUE;
-       }
-
-       if (player_ptr->phase_out && !player_ptr->leaving)
-       {
-               int win_m_idx = 0;
-               int number_mon = 0;
-               for (int i2 = 0; i2 < floor_ptr->width; ++i2)
-               {
-                       for (int j2 = 0; j2 < floor_ptr->height; j2++)
-                       {
-                               grid_type *g_ptr = &floor_ptr->grid_array[j2][i2];
-                               if ((g_ptr->m_idx > 0) && (g_ptr->m_idx != player_ptr->riding))
-                               {
-                                       number_mon++;
-                                       win_m_idx = g_ptr->m_idx;
-                               }
-                       }
-               }
-
-               if (number_mon == 0)
-               {
-                       msg_print(_("相打ちに終わりました。", "Nothing survived."));
-                       msg_print(NULL);
-                       player_ptr->energy_need = 0;
-                       update_gambling_monsters(player_ptr);
-               }
-               else if ((number_mon - 1) == 0)
-               {
-                       GAME_TEXT m_name[MAX_NLEN];
-                       monster_type *wm_ptr;
-                       wm_ptr = &floor_ptr->m_list[win_m_idx];
-                       monster_desc(player_ptr, m_name, wm_ptr, 0);
-                       msg_format(_("%sが勝利した!", "%s won!"), m_name);
-                       msg_print(NULL);
-
-                       if (win_m_idx == (sel_monster + 1))
-                       {
-                               msg_print(_("おめでとうございます。", "Congratulations."));
-                               msg_format(_("%d$を受け取った。", "You received %d gold."), battle_odds);
-                               player_ptr->au += battle_odds;
-                       }
-                       else
-                       {
-                               msg_print(_("残念でした。", "You lost gold."));
-                       }
-
-                       msg_print(NULL);
-                       player_ptr->energy_need = 0;
-                       update_gambling_monsters(player_ptr);
-               }
-               else if (current_world_ptr->game_turn - floor_ptr->generated_turn == 150 * TURNS_PER_TICK)
-               {
-                       msg_print(_("申し分けありませんが、この勝負は引き分けとさせていただきます。", "This battle ended in a draw."));
-                       player_ptr->au += kakekin;
-                       msg_print(NULL);
-                       player_ptr->energy_need = 0;
-                       update_gambling_monsters(player_ptr);
-               }
-       }
-
-       if (current_world_ptr->game_turn % TURNS_PER_TICK) return;
-
-       if (autosave_t && autosave_freq && !player_ptr->phase_out)
-       {
-               if (!(current_world_ptr->game_turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
-                       do_cmd_save_game(player_ptr, TRUE);
-       }
-
-       if (floor_ptr->monster_noise && !ignore_unview)
-       {
-               msg_print(_("何かが聞こえた。", "You hear noise."));
-       }
-
-       if (!floor_ptr->dun_level && !floor_ptr->inside_quest && !player_ptr->phase_out && !floor_ptr->inside_arena)
-       {
-               if (!(current_world_ptr->game_turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2)))
-               {
-                       bool dawn = (!(current_world_ptr->game_turn % (TURNS_PER_TICK * TOWN_DAWN)));
-                       if (dawn) day_break(player_ptr);
-                       else night_falls(player_ptr);
-
-               }
-       }
-       else if ((vanilla_town || (lite_town && !floor_ptr->inside_quest && !player_ptr->phase_out && !floor_ptr->inside_arena)) && floor_ptr->dun_level)
-       {
-               if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * STORE_TICKS)))
-               {
-                       if (one_in_(STORE_SHUFFLE))
-                       {
-                               int n;
-                               do
-                               {
-                                       n = randint0(MAX_STORES);
-                               } while ((n == STORE_HOME) || (n == STORE_MUSEUM));
-
-                               for (FEAT_IDX i = 1; i < max_f_idx; i++)
-                               {
-                                       feature_type *f_ptr = &f_info[i];
-                                       if (!f_ptr->name) continue;
-                                       if (!have_flag(f_ptr->flags, FF_STORE)) continue;
-
-                                       if (f_ptr->subtype == n)
-                                       {
-                                               if (cheat_xtra)
-                                                       msg_format(_("%sの店主をシャッフルします。", "Shuffle a Shopkeeper of %s."), f_name + f_ptr->name);
-
-                                               store_shuffle(player_ptr, n);
-                                               break;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       if (one_in_(d_info[player_ptr->dungeon_idx].max_m_alloc_chance) &&
-               !floor_ptr->inside_arena && !floor_ptr->inside_quest && !player_ptr->phase_out)
-       {
-               (void)alloc_monster(player_ptr, MAX_SIGHT + 5, 0);
-       }
-
-       if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 10)) && !player_ptr->phase_out)
-               regenerate_monsters(player_ptr);
-       if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 3)))
-               regenerate_captured_monsters(player_ptr);
-
-       if (!player_ptr->leaving)
-       {
-               for (int i = 0; i < MAX_MTIMED; i++)
-               {
-                       if (floor_ptr->mproc_max[i] > 0) process_monsters_mtimed(player_ptr, i);
-               }
-       }
-
-       if (!hour && !min)
-       {
-               if (min != prev_min)
-               {
-                       exe_write_diary(player_ptr, DIARY_DIALY, 0, NULL);
-                       determine_daily_bounty(player_ptr, FALSE);
-               }
-       }
-
-       /*
-        * Nightmare mode activates the TY_CURSE at midnight
-        * Require exact minute -- Don't activate multiple times in a minute
-        */
-       if (ironman_nightmare && (min != prev_min))
-       {
-               if ((hour == 23) && !(min % 15))
-               {
-                       disturb(player_ptr, FALSE, TRUE);
-                       switch (min / 15)
-                       {
-                       case 0:
-                               msg_print(_("遠くで不気味な鐘の音が鳴った。", "You hear a distant bell toll ominously."));
-                               break;
-
-                       case 1:
-                               msg_print(_("遠くで鐘が二回鳴った。", "A distant bell sounds twice."));
-                               break;
-
-                       case 2:
-                               msg_print(_("遠くで鐘が三回鳴った。", "A distant bell sounds three times."));
-                               break;
-
-                       case 3:
-                               msg_print(_("遠くで鐘が四回鳴った。", "A distant bell tolls four times."));
-                               break;
-                       }
-               }
-
-               if (!hour && !min)
-               {
-                       disturb(player_ptr, TRUE, TRUE);
-                       msg_print(_("遠くで鐘が何回も鳴り、死んだような静けさの中へ消えていった。", "A distant bell tolls many times, fading into an deathly silence."));
-                       if (player_ptr->wild_mode)
-                       {
-                               player_ptr->oldpy = randint1(MAX_HGT - 2);
-                               player_ptr->oldpx = randint1(MAX_WID - 2);
-                               change_wild_mode(player_ptr, TRUE);
-                               take_turn(player_ptr, 100);
-
-                       }
-
-                       player_ptr->invoking_midnight_curse = TRUE;
-               }
-       }
-
-       starve_player(player_ptr);
-       process_player_hp_mp(player_ptr);
-       reduce_magic_effects_timeout(player_ptr);
-       reduce_lite_life(player_ptr);
-       process_world_aux_mutation(player_ptr);
-       execute_cursed_items_effect(player_ptr);
-       recharge_magic_items(player_ptr);
-       sense_inventory1(player_ptr);
-       sense_inventory2(player_ptr);
-       process_world_aux_movement(player_ptr);
-}
-
-
-/*!
  * process_player()、process_world() をcore.c から移設するのが先.
  * process_upkeep_with_speed() はこの関数と同じところでOK
  * @brief 現在プレイヤーがいるダンジョンの全体処理 / Interact with the current dungeon level.
diff --git a/src/world/world-turn-processor.c b/src/world/world-turn-processor.c
new file mode 100644 (file)
index 0000000..698553a
--- /dev/null
@@ -0,0 +1,217 @@
+#include "angband.h"
+#include "world/world-turn-processor.h"
+#include "world.h"
+#include "dungeon.h"
+#include "market/store.h"
+#include "market/store-util.h"
+#include "io/write-diary.h"
+#include "floor-events.h"
+#include "core/hp-mp-regenerator.h"
+#include "cmd/cmd-save.h"
+#include "monster-status.h"
+#include "player-move.h"
+#include "wild.h"
+#include "player/digestion-processor.h"
+#include "core/hp-mp-processor.h"
+#include "core/magic-effects-timeout-reducer.h"
+#include "object/lite-processor.h"
+#include "mutation/mutation-processor.h"
+#include "inventory/inventory-curse.h"
+#include "inventory/recharge-processor.h"
+#include "inventory/simple-appraiser.h"
+#include "world/world-movement-processor.h"
+
+/*!
+ * @brief 10ゲームターンが進行する毎にゲーム世界全体の処理を行う。
+ * / Handle certain things once every 10 game turns
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @return なし
+ */
+void process_world(player_type* player_ptr)
+{
+    const s32b A_DAY = TURNS_PER_TICK * TOWN_DAWN;
+    s32b prev_turn_in_today = ((current_world_ptr->game_turn - TURNS_PER_TICK) % A_DAY + A_DAY / 4) % A_DAY;
+    int prev_min = (1440 * prev_turn_in_today / A_DAY) % 60;
+
+    int day, hour, min;
+    extract_day_hour_min(player_ptr, &day, &hour, &min);
+    update_dungeon_feeling(player_ptr);
+
+    /* 帰還無しモード時のレベルテレポバグ対策 / Fix for level teleport bugs on ironman_downward.*/
+    floor_type* floor_ptr = player_ptr->current_floor_ptr;
+    if (ironman_downward && (player_ptr->dungeon_idx != DUNGEON_ANGBAND && player_ptr->dungeon_idx != 0)) {
+        floor_ptr->dun_level = 0;
+        player_ptr->dungeon_idx = 0;
+        prepare_change_floor_mode(player_ptr, CFM_FIRST_FLOOR | CFM_RAND_PLACE);
+        floor_ptr->inside_arena = FALSE;
+        player_ptr->wild_mode = FALSE;
+        player_ptr->leaving = TRUE;
+    }
+
+    if (player_ptr->phase_out && !player_ptr->leaving) {
+        int win_m_idx = 0;
+        int number_mon = 0;
+        for (int i2 = 0; i2 < floor_ptr->width; ++i2) {
+            for (int j2 = 0; j2 < floor_ptr->height; j2++) {
+                grid_type* g_ptr = &floor_ptr->grid_array[j2][i2];
+                if ((g_ptr->m_idx > 0) && (g_ptr->m_idx != player_ptr->riding)) {
+                    number_mon++;
+                    win_m_idx = g_ptr->m_idx;
+                }
+            }
+        }
+
+        if (number_mon == 0) {
+            msg_print(_("相打ちに終わりました。", "Nothing survived."));
+            msg_print(NULL);
+            player_ptr->energy_need = 0;
+            update_gambling_monsters(player_ptr);
+        } else if ((number_mon - 1) == 0) {
+            GAME_TEXT m_name[MAX_NLEN];
+            monster_type* wm_ptr;
+            wm_ptr = &floor_ptr->m_list[win_m_idx];
+            monster_desc(player_ptr, m_name, wm_ptr, 0);
+            msg_format(_("%sが勝利した!", "%s won!"), m_name);
+            msg_print(NULL);
+
+            if (win_m_idx == (sel_monster + 1)) {
+                msg_print(_("おめでとうございます。", "Congratulations."));
+                msg_format(_("%d$を受け取った。", "You received %d gold."), battle_odds);
+                player_ptr->au += battle_odds;
+            } else {
+                msg_print(_("残念でした。", "You lost gold."));
+            }
+
+            msg_print(NULL);
+            player_ptr->energy_need = 0;
+            update_gambling_monsters(player_ptr);
+        } else if (current_world_ptr->game_turn - floor_ptr->generated_turn == 150 * TURNS_PER_TICK) {
+            msg_print(_("申し分けありませんが、この勝負は引き分けとさせていただきます。", "This battle ended in a draw."));
+            player_ptr->au += kakekin;
+            msg_print(NULL);
+            player_ptr->energy_need = 0;
+            update_gambling_monsters(player_ptr);
+        }
+    }
+
+    if (current_world_ptr->game_turn % TURNS_PER_TICK)
+        return;
+
+    if (autosave_t && autosave_freq && !player_ptr->phase_out) {
+        if (!(current_world_ptr->game_turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
+            do_cmd_save_game(player_ptr, TRUE);
+    }
+
+    if (floor_ptr->monster_noise && !ignore_unview) {
+        msg_print(_("何かが聞こえた。", "You hear noise."));
+    }
+
+    if (!floor_ptr->dun_level && !floor_ptr->inside_quest && !player_ptr->phase_out && !floor_ptr->inside_arena) {
+        if (!(current_world_ptr->game_turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2))) {
+            bool dawn = (!(current_world_ptr->game_turn % (TURNS_PER_TICK * TOWN_DAWN)));
+            if (dawn)
+                day_break(player_ptr);
+            else
+                night_falls(player_ptr);
+        }
+    } else if ((vanilla_town || (lite_town && !floor_ptr->inside_quest && !player_ptr->phase_out && !floor_ptr->inside_arena)) && floor_ptr->dun_level) {
+        if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * STORE_TICKS))) {
+            if (one_in_(STORE_SHUFFLE)) {
+                int n;
+                do {
+                    n = randint0(MAX_STORES);
+                } while ((n == STORE_HOME) || (n == STORE_MUSEUM));
+
+                for (FEAT_IDX i = 1; i < max_f_idx; i++) {
+                    feature_type* f_ptr = &f_info[i];
+                    if (!f_ptr->name)
+                        continue;
+                    if (!have_flag(f_ptr->flags, FF_STORE))
+                        continue;
+
+                    if (f_ptr->subtype == n) {
+                        if (cheat_xtra)
+                            msg_format(_("%sの店主をシャッフルします。", "Shuffle a Shopkeeper of %s."), f_name + f_ptr->name);
+
+                        store_shuffle(player_ptr, n);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    if (one_in_(d_info[player_ptr->dungeon_idx].max_m_alloc_chance) && !floor_ptr->inside_arena && !floor_ptr->inside_quest && !player_ptr->phase_out) {
+        (void)alloc_monster(player_ptr, MAX_SIGHT + 5, 0);
+    }
+
+    if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 10)) && !player_ptr->phase_out)
+        regenerate_monsters(player_ptr);
+    if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 3)))
+        regenerate_captured_monsters(player_ptr);
+
+    if (!player_ptr->leaving) {
+        for (int i = 0; i < MAX_MTIMED; i++) {
+            if (floor_ptr->mproc_max[i] > 0)
+                process_monsters_mtimed(player_ptr, i);
+        }
+    }
+
+    if (!hour && !min) {
+        if (min != prev_min) {
+            exe_write_diary(player_ptr, DIARY_DIALY, 0, NULL);
+            determine_daily_bounty(player_ptr, FALSE);
+        }
+    }
+
+    /*
+        * Nightmare mode activates the TY_CURSE at midnight
+        * Require exact minute -- Don't activate multiple times in a minute
+        */
+    if (ironman_nightmare && (min != prev_min)) {
+        if ((hour == 23) && !(min % 15)) {
+            disturb(player_ptr, FALSE, TRUE);
+            switch (min / 15) {
+            case 0:
+                msg_print(_("遠くで不気味な鐘の音が鳴った。", "You hear a distant bell toll ominously."));
+                break;
+
+            case 1:
+                msg_print(_("遠くで鐘が二回鳴った。", "A distant bell sounds twice."));
+                break;
+
+            case 2:
+                msg_print(_("遠くで鐘が三回鳴った。", "A distant bell sounds three times."));
+                break;
+
+            case 3:
+                msg_print(_("遠くで鐘が四回鳴った。", "A distant bell tolls four times."));
+                break;
+            }
+        }
+
+        if (!hour && !min) {
+            disturb(player_ptr, TRUE, TRUE);
+            msg_print(_("遠くで鐘が何回も鳴り、死んだような静けさの中へ消えていった。", "A distant bell tolls many times, fading into an deathly silence."));
+            if (player_ptr->wild_mode) {
+                player_ptr->oldpy = randint1(MAX_HGT - 2);
+                player_ptr->oldpx = randint1(MAX_WID - 2);
+                change_wild_mode(player_ptr, TRUE);
+                take_turn(player_ptr, 100);
+            }
+
+            player_ptr->invoking_midnight_curse = TRUE;
+        }
+    }
+
+    starve_player(player_ptr);
+    process_player_hp_mp(player_ptr);
+    reduce_magic_effects_timeout(player_ptr);
+    reduce_lite_life(player_ptr);
+    process_world_aux_mutation(player_ptr);
+    execute_cursed_items_effect(player_ptr);
+    recharge_magic_items(player_ptr);
+    sense_inventory1(player_ptr);
+    sense_inventory2(player_ptr);
+    process_world_aux_movement(player_ptr);
+}
diff --git a/src/world/world-turn-processor.h b/src/world/world-turn-processor.h
new file mode 100644 (file)
index 0000000..89739fb
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+void process_world(player_type* player_ptr);