Delete some unnecessary functions from travel_pathfind.
authorAliscans <crawl@thimk.info>
Mon, 15 Feb 2021 21:02:38 +0000 (21:02 +0000)
committerEdgar A. Bering IV <trizor@gmail.com>
Tue, 16 Feb 2021 18:00:27 +0000 (20:00 +0200)
Delete set_annotate_map() and set_distance_grid(), which were never used.

Replace travel_move() with travel_move in travel_pathfind. It was only called by pathfind(), which could access both.

Move _find_explore_status() into travel_pathfind (now called explore_statu()). As its purpose is to interrogate a travel_pathfind, it seems like a good fit.

Replace greedy_square(), unexplored_square() and get_unreachables() with the underlying variables. _find_explore_status() was the only function which read them, and it can now read the variables directly.

crawl-ref/source/travel.cc
crawl-ref/source/travel.h

index 853b7f5..4feb942 100644 (file)
@@ -726,22 +726,6 @@ static bool _level_has_unknown_transporters()
     return false;
 }
 
-// Determines if the level is fully explored.
-static int _find_explore_status(const travel_pathfind &tp)
-{
-    int explore_status = 0;
-
-    const coord_def greed = tp.greedy_square();
-    if (greed.x || greed.y)
-        explore_status |= EST_GREED_UNFULFILLED;
-
-    const coord_def unexplored = tp.unexplored_square();
-    if (unexplored.x || unexplored.y || !tp.get_unreachables().empty())
-        explore_status |= EST_PARTLY_EXPLORED;
-
-    return explore_status;
-}
-
 static void _set_target_square(const coord_def &target)
 {
     you.running.pos = target;
@@ -804,7 +788,7 @@ static void _explore_find_target_square()
     else
     {
         // No place to go? Report to the player.
-        const int estatus = _find_explore_status(tp);
+        const int estatus = tp.explore_status();
         const bool unknown_trans = _level_has_unknown_transporters();
         if (!estatus && !unknown_trans)
         {
@@ -1269,16 +1253,6 @@ void travel_pathfind::set_floodseed(const coord_def &seed, bool dblflood)
     double_flood = dblflood;
 }
 
-void travel_pathfind::set_annotate_map(bool annotate)
-{
-    annotate_map = annotate;
-}
-
-void travel_pathfind::set_distance_grid(travel_distance_grid_t grid)
-{
-    point_distance = grid;
-}
-
 void travel_pathfind::set_feature_vector(vector<coord_def> *feats)
 {
     features = feats;
@@ -1290,11 +1264,6 @@ void travel_pathfind::set_feature_vector(vector<coord_def> *feats)
     }
 }
 
-const coord_def travel_pathfind::travel_move() const
-{
-    return next_travel_move;
-}
-
 const coord_def travel_pathfind::explore_target() const
 {
     if (unexplored_dist != UNFOUND_DIST && greedy_dist != UNFOUND_DIST)
@@ -1310,16 +1279,6 @@ const coord_def travel_pathfind::explore_target() const
     return coord_def(0, 0);
 }
 
-const coord_def travel_pathfind::greedy_square() const
-{
-    return greedy_place;
-}
-
-const coord_def travel_pathfind::unexplored_square() const
-{
-    return unexplored_place;
-}
-
 // The travel algorithm is based on the NetHack travel code written by Warwick
 // Allison - used with his permission.
 coord_def travel_pathfind::pathfind(run_mode_type rmode, bool fallback_explore)
@@ -1443,7 +1402,7 @@ coord_def travel_pathfind::pathfind(run_mode_type rmode, bool fallback_explore)
             if (path_examine_point(circumference[circ_index][i]))
             {
                 if (runmode == RMODE_TRAVEL)
-                    return travel_move();
+                    return next_travel_move;
                 else if (runmode == RMODE_CONNECTIVITY
                          || !Options.explore_wall_bias)
                 {
@@ -1506,7 +1465,7 @@ coord_def travel_pathfind::pathfind(run_mode_type rmode, bool fallback_explore)
         }
     }
 
-    return runmode == RMODE_TRAVEL ? travel_move()
+    return runmode == RMODE_TRAVEL ? next_travel_move
                                    : explore_target();
 }
 
@@ -1548,11 +1507,6 @@ void travel_pathfind::get_features()
     }
 }
 
-const set<coord_def> travel_pathfind::get_unreachables() const
-{
-    return unreachables;
-}
-
 bool travel_pathfind::square_slows_movement(const coord_def &c)
 {
     // c is a known (explored) location - we never put unknown points in the
@@ -1872,6 +1826,23 @@ bool travel_pathfind::path_examine_point(const coord_def &c)
     return found_target;
 }
 
+// Determines if the level is fully explored.
+// This uses data provided by pathfind(), so that needs to be called first.
+int travel_pathfind::explore_status()
+{
+    int explore_status = 0;
+
+    const coord_def greed = greedy_place;
+    if (greed.x || greed.y)
+        explore_status |= EST_GREED_UNFULFILLED;
+
+    const coord_def unexplored = unexplored_place;
+    if (unexplored.x || unexplored.y || !unreachables.empty())
+        explore_status |= EST_PARTLY_EXPLORED;
+
+    return explore_status;
+}
+
 
 /**
  * Run the travel_pathfind algorithm, from the given position in floodout mode
index ccfe39d..d823edf 100644 (file)
@@ -501,21 +501,13 @@ public:
     // position) and destination.
     void set_src_dst(const coord_def &src, const coord_def &dst);
 
-    // Request that the point distance array be annotated with magic numbers for
-    // excludes and waypoints.
-    void set_annotate_map(bool annotate);
-
-    // Sets the travel_distance_grid_t to use instead of travel_point_distance.
-    void set_distance_grid(travel_distance_grid_t distgrid);
-
-    // Set feature vector to use; if non-nullptr, also sets annotate_map to true.
+    // Set feature vector to use; if non-nullptr, also sets annotate_map to
+    // true.
     void set_feature_vector(vector<coord_def> *features);
 
     // Extract features without pathfinding
     void get_features();
 
-    const set<coord_def> get_unreachables() const;
-
     // The next square to go to to move towards the travel destination. Return
     // value is undefined if pathfind was not called with RMODE_TRAVEL.
     const coord_def travel_move() const;
@@ -524,20 +516,14 @@ public:
     // pathfind was not called with RMODE_EXPLORE or RMODE_EXPLORE_GREEDY.
     const coord_def explore_target() const;
 
-    // Nearest greed-inducing square. Return value is undefined if
-    // pathfind was not called with RMODE_EXPLORE_GREEDY.
-    const coord_def greedy_square() const;
-
-    // Nearest unexplored territory. Return value is undefined if
-    // pathfind was not called with RMODE_EXPLORE or
-    // RMODE_EXPLORE_GREEDY.
-    const coord_def unexplored_square() const;
-
     inline void set_ignore_danger()
     {
         ignore_danger = true;
     }
 
+    // Determine if the level is fully explored, when called after pathfind().
+    int explore_status();
+
 protected:
     bool is_greed_inducing_square(const coord_def &c) const;
     bool path_examine_point(const coord_def &c);