ClarkeRubber

Point Navigation

Feb 10th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2. include("systems.php");
  3.  
  4.  
  5. $History = array();
  6. $Path = null;
  7.  
  8. function moveOrigin($nextID, $targetID, $depth){
  9.     global $Systems, $History, $Path, $Destination;
  10.    
  11.     //NextID is the key for the next steps to be made off of.
  12.     $potentials = $Systems[$nextID]["JumpsTo"];
  13.     if(!empty($potentials)){
  14.         if(!in_array($targetID, $potentials)){ //Not at end location, therefore try next location
  15.             array_push($History, $nextID);
  16.             $depth++;
  17.             if($depth < 9){
  18.                 foreach($potentials as $value){
  19.                     if(!in_array($value, $History)){
  20.                         if(moveOrigin($value, $targetID, $History, $depth) == true){
  21.                             return true;
  22.                         }
  23.                     }
  24.                 }
  25.             }else{
  26.                 return;
  27.             }
  28.         }
  29.     }
  30. }
  31.  
  32. $origin = 30000142; //Get starting point
  33. $target = 30000001; //Get end point
  34.  
  35. moveOrigin($origin, $target, 0);
  36. array_push($History, $target);
  37.  
  38. $from = $Systems[$History[0]]["Name"];
  39. $to = $Systems[$History[Count($History) - 1]]["Name"];
  40.  
  41. echo "From: $from, To: $to -><br>";
  42.  
  43. foreach($History as $SystemID){
  44.     echo "{$Systems[$SystemID]["Name"]} ({$Systems[$SystemID]["Sec"]})<br>";
  45. };
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment