• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revisionb2de0a3011ff4677b864d0f0b47a61eaa261a149 (tree)
Time2019-02-18 23:03:24
AuthorDeskull <deskull@user...>
CommiterDeskull

Log Message

[Refactor] #37353 トラベル処理の関数を player-move.c にまとめる。 / Move travel functions to player-move.c.

Change Summary

Incremental Difference

--- a/src/cmd2.c
+++ b/src/cmd2.c
@@ -2854,242 +2854,3 @@ bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
28542854
28552855 return TRUE;
28562856 }
2857-
2858-
2859-#ifdef TRAVEL
2860-/*
2861- * Hack: travel command
2862- */
2863-#define TRAVEL_UNABLE 9999
2864-
2865-static int flow_head = 0;
2866-static int flow_tail = 0;
2867-static POSITION temp2_x[MAX_SHORT];
2868-static POSITION temp2_y[MAX_SHORT];
2869-
2870-/*!
2871- * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information
2872- * @return なし
2873- */
2874-void forget_travel_flow(void)
2875-{
2876- POSITION x, y;
2877- /* Check the entire dungeon / Forget the old data */
2878- for (y = 0; y < cur_hgt; y++)
2879- {
2880- for (x = 0; x < cur_wid; x++)
2881- {
2882-
2883- travel.cost[y][x] = MAX_SHORT;
2884- }
2885- }
2886- travel.y = travel.x = 0;
2887-}
2888-
2889-/*!
2890- * @brief トラベル処理中に地形に応じた移動コスト基準を返す
2891- * @param y 該当地点のY座標
2892- * @param x 該当地点のX座標
2893- * @return コスト値
2894- */
2895-static int travel_flow_cost(POSITION y, POSITION x)
2896-{
2897- feature_type *f_ptr = &f_info[grid_array[y][x].feat];
2898- int cost = 1;
2899-
2900- /* Avoid obstacles (ex. trees) */
2901- if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
2902-
2903- /* Water */
2904- if (have_flag(f_ptr->flags, FF_WATER))
2905- {
2906- if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
2907- }
2908-
2909- /* Lava */
2910- if (have_flag(f_ptr->flags, FF_LAVA))
2911- {
2912- int lava = 2;
2913- if (!p_ptr->resist_fire) lava *= 2;
2914- if (!p_ptr->levitation) lava *= 2;
2915- if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
2916-
2917- cost += lava;
2918- }
2919-
2920- /* Detected traps and doors */
2921- if (grid_array[y][x].info & (CAVE_MARK))
2922- {
2923- if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
2924- if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
2925- }
2926-
2927- return (cost);
2928-}
2929-
2930-/*!
2931- * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
2932- * @param y 目標地点のY座標
2933- * @param x 目標地点のX座標
2934- * @param n 現在のコスト
2935- * @param wall プレイヤーが壁の中にいるならばTRUE
2936- * @return なし
2937- */
2938-static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
2939-{
2940- grid_type *g_ptr = &grid_array[y][x];
2941- feature_type *f_ptr = &f_info[g_ptr->feat];
2942- int old_head = flow_head;
2943- int add_cost = 1;
2944- int base_cost = (n % TRAVEL_UNABLE);
2945- int from_wall = (n / TRAVEL_UNABLE);
2946- int cost;
2947-
2948- /* Ignore out of bounds */
2949- if (!in_bounds(y, x)) return;
2950-
2951- /* Ignore unknown grid except in wilderness */
2952- if (dun_level > 0 && !(g_ptr->info & CAVE_KNOWN)) return;
2953-
2954- /* Ignore "walls" and "rubble" (include "secret doors") */
2955- if (have_flag(f_ptr->flags, FF_WALL) ||
2956- have_flag(f_ptr->flags, FF_CAN_DIG) ||
2957- (have_flag(f_ptr->flags, FF_DOOR) && grid_array[y][x].mimic) ||
2958- (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
2959- {
2960- if (!wall || !from_wall) return;
2961- add_cost += TRAVEL_UNABLE;
2962- }
2963- else
2964- {
2965- add_cost = travel_flow_cost(y, x);
2966- }
2967-
2968- cost = base_cost + add_cost;
2969-
2970- /* Ignore lower cost entries */
2971- if (travel.cost[y][x] <= cost) return;
2972-
2973- /* Save the flow cost */
2974- travel.cost[y][x] = cost;
2975-
2976- /* Enqueue that entry */
2977- temp2_y[flow_head] = y;
2978- temp2_x[flow_head] = x;
2979-
2980- /* Advance the queue */
2981- if (++flow_head == MAX_SHORT) flow_head = 0;
2982-
2983- /* Hack -- notice overflow by forgetting new entry */
2984- if (flow_head == flow_tail) flow_head = old_head;
2985-
2986- return;
2987-}
2988-
2989-/*!
2990- * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
2991- * @param ty 目標地点のY座標
2992- * @param tx 目標地点のX座標
2993- * @return なし
2994- */
2995-static void travel_flow(POSITION ty, POSITION tx)
2996-{
2997- POSITION x, y;
2998- DIRECTION d;
2999- bool wall = FALSE;
3000- feature_type *f_ptr = &f_info[grid_array[p_ptr->y][p_ptr->x].feat];
3001-
3002- /* Reset the "queue" */
3003- flow_head = flow_tail = 0;
3004-
3005- /* is player in the wall? */
3006- if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
3007-
3008- /* Start at the target grid */
3009- travel_flow_aux(ty, tx, 0, wall);
3010-
3011- /* Now process the queue */
3012- while (flow_head != flow_tail)
3013- {
3014- /* Extract the next entry */
3015- y = temp2_y[flow_tail];
3016- x = temp2_x[flow_tail];
3017-
3018- /* Forget that entry */
3019- if (++flow_tail == MAX_SHORT) flow_tail = 0;
3020-
3021- /* Ignore too far entries */
3022- //if (distance(ty, tx, y, x) > 100) continue;
3023-
3024- /* Add the "children" */
3025- for (d = 0; d < 8; d++)
3026- {
3027- /* Add that child if "legal" */
3028- travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
3029- }
3030- }
3031-
3032- /* Forget the flow info */
3033- flow_head = flow_tail = 0;
3034-}
3035-
3036-/*!
3037- * @brief トラベル処理のメインルーチン
3038- * @return なし
3039- */
3040-void do_cmd_travel(void)
3041-{
3042- POSITION x, y;
3043- int i;
3044- POSITION dx, dy, sx, sy;
3045- feature_type *f_ptr;
3046-
3047- if (travel.x != 0 && travel.y != 0 &&
3048- get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
3049- {
3050- y = travel.y;
3051- x = travel.x;
3052- }
3053- else if (!tgt_pt(&x, &y)) return;
3054-
3055- if ((x == p_ptr->x) && (y == p_ptr->y))
3056- {
3057- msg_print(_("すでにそこにいます!", "You are already there!!"));
3058- return;
3059- }
3060-
3061- f_ptr = &f_info[grid_array[y][x].feat];
3062-
3063- if ((grid_array[y][x].info & CAVE_MARK) &&
3064- (have_flag(f_ptr->flags, FF_WALL) ||
3065- have_flag(f_ptr->flags, FF_CAN_DIG) ||
3066- (have_flag(f_ptr->flags, FF_DOOR) && grid_array[y][x].mimic)))
3067- {
3068- msg_print(_("そこには行くことができません!", "You cannot travel there!"));
3069- return;
3070- }
3071-
3072- forget_travel_flow();
3073- travel_flow(y, x);
3074-
3075- travel.x = x;
3076- travel.y = y;
3077-
3078- /* Travel till 255 steps */
3079- travel.run = 255;
3080-
3081- /* Paranoia */
3082- travel.dir = 0;
3083-
3084- /* Decides first direction */
3085- dx = abs(p_ptr->x - x);
3086- dy = abs(p_ptr->y - y);
3087- sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
3088- sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
3089-
3090- for (i = 1; i <= 9; i++)
3091- {
3092- if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
3093- }
3094-}
3095-#endif
--- a/src/player-move.c
+++ b/src/player-move.c
@@ -2254,3 +2254,242 @@ void travel_step(void)
22542254 Term_xtra(TERM_XTRA_DELAY, delay_factor);
22552255 }
22562256 #endif
2257+
2258+
2259+#ifdef TRAVEL
2260+/*
2261+ * Hack: travel command
2262+ */
2263+#define TRAVEL_UNABLE 9999
2264+
2265+static int flow_head = 0;
2266+static int flow_tail = 0;
2267+static POSITION temp2_x[MAX_SHORT];
2268+static POSITION temp2_y[MAX_SHORT];
2269+
2270+/*!
2271+ * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information
2272+ * @return なし
2273+ */
2274+void forget_travel_flow(void)
2275+{
2276+ POSITION x, y;
2277+ /* Check the entire dungeon / Forget the old data */
2278+ for (y = 0; y < cur_hgt; y++)
2279+ {
2280+ for (x = 0; x < cur_wid; x++)
2281+ {
2282+
2283+ travel.cost[y][x] = MAX_SHORT;
2284+ }
2285+ }
2286+ travel.y = travel.x = 0;
2287+}
2288+
2289+/*!
2290+ * @brief トラベル処理中に地形に応じた移動コスト基準を返す
2291+ * @param y 該当地点のY座標
2292+ * @param x 該当地点のX座標
2293+ * @return コスト値
2294+ */
2295+static int travel_flow_cost(POSITION y, POSITION x)
2296+{
2297+ feature_type *f_ptr = &f_info[grid_array[y][x].feat];
2298+ int cost = 1;
2299+
2300+ /* Avoid obstacles (ex. trees) */
2301+ if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
2302+
2303+ /* Water */
2304+ if (have_flag(f_ptr->flags, FF_WATER))
2305+ {
2306+ if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
2307+ }
2308+
2309+ /* Lava */
2310+ if (have_flag(f_ptr->flags, FF_LAVA))
2311+ {
2312+ int lava = 2;
2313+ if (!p_ptr->resist_fire) lava *= 2;
2314+ if (!p_ptr->levitation) lava *= 2;
2315+ if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
2316+
2317+ cost += lava;
2318+ }
2319+
2320+ /* Detected traps and doors */
2321+ if (grid_array[y][x].info & (CAVE_MARK))
2322+ {
2323+ if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
2324+ if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
2325+ }
2326+
2327+ return (cost);
2328+}
2329+
2330+/*!
2331+ * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
2332+ * @param y 目標地点のY座標
2333+ * @param x 目標地点のX座標
2334+ * @param n 現在のコスト
2335+ * @param wall プレイヤーが壁の中にいるならばTRUE
2336+ * @return なし
2337+ */
2338+static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
2339+{
2340+ grid_type *g_ptr = &grid_array[y][x];
2341+ feature_type *f_ptr = &f_info[g_ptr->feat];
2342+ int old_head = flow_head;
2343+ int add_cost = 1;
2344+ int base_cost = (n % TRAVEL_UNABLE);
2345+ int from_wall = (n / TRAVEL_UNABLE);
2346+ int cost;
2347+
2348+ /* Ignore out of bounds */
2349+ if (!in_bounds(y, x)) return;
2350+
2351+ /* Ignore unknown grid except in wilderness */
2352+ if (dun_level > 0 && !(g_ptr->info & CAVE_KNOWN)) return;
2353+
2354+ /* Ignore "walls" and "rubble" (include "secret doors") */
2355+ if (have_flag(f_ptr->flags, FF_WALL) ||
2356+ have_flag(f_ptr->flags, FF_CAN_DIG) ||
2357+ (have_flag(f_ptr->flags, FF_DOOR) && grid_array[y][x].mimic) ||
2358+ (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
2359+ {
2360+ if (!wall || !from_wall) return;
2361+ add_cost += TRAVEL_UNABLE;
2362+ }
2363+ else
2364+ {
2365+ add_cost = travel_flow_cost(y, x);
2366+ }
2367+
2368+ cost = base_cost + add_cost;
2369+
2370+ /* Ignore lower cost entries */
2371+ if (travel.cost[y][x] <= cost) return;
2372+
2373+ /* Save the flow cost */
2374+ travel.cost[y][x] = cost;
2375+
2376+ /* Enqueue that entry */
2377+ temp2_y[flow_head] = y;
2378+ temp2_x[flow_head] = x;
2379+
2380+ /* Advance the queue */
2381+ if (++flow_head == MAX_SHORT) flow_head = 0;
2382+
2383+ /* Hack -- notice overflow by forgetting new entry */
2384+ if (flow_head == flow_tail) flow_head = old_head;
2385+
2386+ return;
2387+}
2388+
2389+/*!
2390+ * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
2391+ * @param ty 目標地点のY座標
2392+ * @param tx 目標地点のX座標
2393+ * @return なし
2394+ */
2395+static void travel_flow(POSITION ty, POSITION tx)
2396+{
2397+ POSITION x, y;
2398+ DIRECTION d;
2399+ bool wall = FALSE;
2400+ feature_type *f_ptr = &f_info[grid_array[p_ptr->y][p_ptr->x].feat];
2401+
2402+ /* Reset the "queue" */
2403+ flow_head = flow_tail = 0;
2404+
2405+ /* is player in the wall? */
2406+ if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
2407+
2408+ /* Start at the target grid */
2409+ travel_flow_aux(ty, tx, 0, wall);
2410+
2411+ /* Now process the queue */
2412+ while (flow_head != flow_tail)
2413+ {
2414+ /* Extract the next entry */
2415+ y = temp2_y[flow_tail];
2416+ x = temp2_x[flow_tail];
2417+
2418+ /* Forget that entry */
2419+ if (++flow_tail == MAX_SHORT) flow_tail = 0;
2420+
2421+ /* Ignore too far entries */
2422+ //if (distance(ty, tx, y, x) > 100) continue;
2423+
2424+ /* Add the "children" */
2425+ for (d = 0; d < 8; d++)
2426+ {
2427+ /* Add that child if "legal" */
2428+ travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
2429+ }
2430+ }
2431+
2432+ /* Forget the flow info */
2433+ flow_head = flow_tail = 0;
2434+}
2435+
2436+/*!
2437+ * @brief トラベル処理のメインルーチン
2438+ * @return なし
2439+ */
2440+void do_cmd_travel(void)
2441+{
2442+ POSITION x, y;
2443+ int i;
2444+ POSITION dx, dy, sx, sy;
2445+ feature_type *f_ptr;
2446+
2447+ if (travel.x != 0 && travel.y != 0 &&
2448+ get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
2449+ {
2450+ y = travel.y;
2451+ x = travel.x;
2452+ }
2453+ else if (!tgt_pt(&x, &y)) return;
2454+
2455+ if ((x == p_ptr->x) && (y == p_ptr->y))
2456+ {
2457+ msg_print(_("すでにそこにいます!", "You are already there!!"));
2458+ return;
2459+ }
2460+
2461+ f_ptr = &f_info[grid_array[y][x].feat];
2462+
2463+ if ((grid_array[y][x].info & CAVE_MARK) &&
2464+ (have_flag(f_ptr->flags, FF_WALL) ||
2465+ have_flag(f_ptr->flags, FF_CAN_DIG) ||
2466+ (have_flag(f_ptr->flags, FF_DOOR) && grid_array[y][x].mimic)))
2467+ {
2468+ msg_print(_("そこには行くことができません!", "You cannot travel there!"));
2469+ return;
2470+ }
2471+
2472+ forget_travel_flow();
2473+ travel_flow(y, x);
2474+
2475+ travel.x = x;
2476+ travel.y = y;
2477+
2478+ /* Travel till 255 steps */
2479+ travel.run = 255;
2480+
2481+ /* Paranoia */
2482+ travel.dir = 0;
2483+
2484+ /* Decides first direction */
2485+ dx = abs(p_ptr->x - x);
2486+ dy = abs(p_ptr->y - y);
2487+ sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
2488+ sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
2489+
2490+ for (i = 1; i <= 9; i++)
2491+ {
2492+ if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
2493+ }
2494+}
2495+#endif
Show on old repository browser