pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src/worldmap pingus.cxx,1.20,1.21


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/worldmap pingus.cxx,1.20,1.21
Date: 15 Oct 2002 22:14:44 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv7948/worldmap

Modified Files:
        pingus.cxx 
Log Message:
added missing check for self references

Index: pingus.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.cxx,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- pingus.cxx  15 Oct 2002 22:09:55 -0000      1.20
+++ pingus.cxx  15 Oct 2002 22:14:42 -0000      1.21
@@ -94,16 +94,24 @@
     {
       const PathfinderResult& res = path->get_path (current_node, target);
 
-      std::cout << "XXXXXXX Path cost: " << res.cost << std::endl;
-      node_path = res.path;
+      if (res.path.empty())
+        {
+          // No path could be found
+          return false;
+        }
+      else
+        {
+          std::cout << "XXXXXXX Path cost: " << res.cost << std::endl;
+          node_path = res.path;
 
-      // Simulate that we just reached current_node, then update the edge_path
-      target_node = node_path.back(); // equal to current_node;
-      node_path.pop_back();
-      update_edge_path();
+          // Simulate that we just reached current_node, then update the 
edge_path
+          target_node = node_path.back(); // equal to current_node;
+          node_path.pop_back();
+          update_edge_path();
 
-      current_node = NoNode;
-      return true;
+          current_node = NoNode;
+          return true;
+        }
     }
   else // pingu between two nodes
     {
@@ -123,24 +131,40 @@
         }
       else
         {
-          PathfinderResult node_path1 = path->get_path (source_node, target);
-          PathfinderResult node_path2 = path->get_path (target_node, target);
+          const PathfinderResult& node_path1 = path->get_path (source_node, 
target);
+          const PathfinderResult& node_path2 = path->get_path (target_node, 
target);
        
-          // Select the shorter path
-          if (node_path1.cost + edge_path_position
-              < node_path2.cost + (edge_path.length() - edge_path_position))
-            { // walk to source node, which means to reverse the pingu
-              node_path = node_path1.path;
-
-              // Reverse the pingu
-              std::swap(target_node, source_node);
-              edge_path.reverse();
-              edge_path_position = edge_path.length() - edge_path_position;
+          // Check that a path exist
+          if (node_path1.path.empty())
+            {
+              if (node_path2.path.empty())
+                {
+                  return false;
+                }
+              else
+                {
+                  node_path = node_path2.path;
+                }
             }
           else
-            { // walk to target_node
-              node_path = node_path2.path;
+            {
+              // Select the shorter path
+              if (node_path1.cost + edge_path_position
+                  < node_path2.cost + (edge_path.length() - 
edge_path_position))
+                { // walk to source node, which means to reverse the pingu
+                  node_path = node_path1.path;
+
+                  // Reverse the pingu
+                  std::swap(target_node, source_node);
+                  edge_path.reverse();
+                  edge_path_position = edge_path.length() - edge_path_position;
+                }
+              else
+                { // walk to target_node
+                  node_path = node_path2.path;
+                }
             }
+
           // Pop the first element on the stack, since we are already 
targeting it
           node_path.pop_back();
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]