Advertisement
sanovskiy

WarpDrive PHP Navigator

Aug 19th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1. <style>
  2. .jump.striked{text-decoration:line-through;}
  3. </style>
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
  5. <form>
  6. Current X: <input name="curX" value="<?=@$_REQUEST["curX"]?>"><br/>
  7. Current Z: <input name="curZ" value="<?=@$_REQUEST["curZ"]?>"><br/>
  8. Dst X: <input name="dstX" value="<?=@$_REQUEST["dstX"]?>"><br/>
  9. Dst Z: <input name="dstZ" value="<?=@$_REQUEST["dstZ"]?>"><br/>
  10. <label><input type="checkbox" name="no_hyper" value="1"<?=@$_REQUEST["no_hyper"]?' checked="checked"':''?> /> no Hyperspace</label><br/>
  11. <input type="submit"/>
  12. </form>
  13. <?
  14. define("MAXWARP",1280);
  15. define("MAXLONGWARP",128000);
  16. define("LONGMULT",100);
  17. $noHyper = @$_REQUEST["no_hyper"]?true:false;
  18. if (isset($_REQUEST['curX'])){
  19.     $cX = intval($_REQUEST['curX'])?intval($_REQUEST['curX']):0;
  20.     $cZ = intval($_REQUEST['curZ'])?intval($_REQUEST['curZ']):0;
  21.     $X = intval($_REQUEST['dstX'])?intval($_REQUEST['dstX']):0;
  22.     $Z = intval($_REQUEST['dstZ'])?intval($_REQUEST['dstZ']):0;
  23.    
  24.     $trX="<b>W</b>est";
  25.     if ($X>$cX){
  26.         $trX="<b>E</b>ast";
  27.     }
  28.     $trZ="<b>N</b>orth";
  29.     if ($Z>$cZ){
  30.         $trZ="<b>S</b>outh";
  31.     }
  32.    
  33.     $dX = abs($X-$cX);
  34.     $dZ = abs($Z-$cZ);
  35.    
  36.     $jumps = array();
  37.     echo "dX: ".$dX."<br/>";
  38.     echo "dZ: ".$dZ."<br/>";
  39.     while($dX>0){
  40.         if ($dX>MAXWARP){
  41.             if ($noHyper){
  42.                 $jumps[] = "Jump ".MAXWARP." to ".$trX;
  43.                 $dX-=MAXWARP;
  44.                 continue;
  45.             }
  46.             if ($dX>MAXLONGWARP){
  47.                 $jumps[] = "Hyperjump ".floor(MAXLONGWARP/LONGMULT)." to ".$trX." (".MAXLONGWARP.")";
  48.                 $dX-=MAXLONGWARP;
  49.                 continue;
  50.             }
  51.             $jumps[] = "Hyperjump ".floor($dX/LONGMULT)." to ".$trX." (".(floor($dX/LONGMULT)*LONGMULT).")";
  52.             $dX-=floor($dX/LONGMULT)*LONGMULT;
  53.             continue;
  54.         }
  55.         $jumps[] = "Jump ".$dX." to ".$trX;
  56.         $dX-=$dX;
  57.     }
  58.     while($dZ>0){
  59.         if ($dZ>MAXWARP){
  60.             if ($noHyper){
  61.                 $jumps[] = "Jump ".MAXWARP." to ".$trZ;
  62.                 $dZ-=MAXWARP;
  63.                 continue;
  64.             }      
  65.             if ($dZ>MAXLONGWARP){
  66.                 $jumps[] = "Hyperjump ".floor(MAXLONGWARP/LONGMULT)." to ".$trZ." (".MAXLONGWARP.")";
  67.                 $dZ-=MAXLONGWARP;
  68.                 continue;
  69.             }
  70.             $jumps[] = "Hyperjump ".floor($dZ/LONGMULT)." to ".$trZ." (".(floor($dZ/LONGMULT)*LONGMULT).")";
  71.             $dZ-=floor($dZ/LONGMULT)*LONGMULT;
  72.             continue;
  73.         }
  74.         $jumps[] = "Jump ".$dZ." to ".$trZ;
  75.         $dZ-=$dZ;
  76.     }
  77.     ?><div style="font-size:22px;"><?
  78.     foreach ($jumps as $jump){
  79.         echo '<div class="strikeable"><label><input type="checkbox" class="strikeonchange" /><span class="jump">'.$jump."</span></label></div>";
  80.     }
  81.     ?></div><?
  82. }?>
  83. <script>
  84.     $(function(){
  85.         $('.strikeonchange').change(function(){
  86.             if (this.checked){
  87.                 $(this).parent().find('.jump').addClass('striked');
  88.             } else {
  89.                 $(this).parent().find('.jump').removeClass('striked');
  90.             }
  91.         });
  92.     })
  93. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement