Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.65 KB | None | 0 0
  1. public function getMap(Player $observer, int $width, int $height, int $inDegrees, int $size = 16){ // No compass
  2.         $to = (int)sqrt($size);
  3.         $centerPs = new Vector3($observer->x >> $to, 0, $observer->z >> $to);
  4.  
  5.         $map = [];
  6.  
  7.         $centerFaction = $this->factionInPoint($observer->getX(), $observer->getZ());
  8.         if($centerFaction == Null) $centerFaction = "Wilderness";
  9.  
  10.         $head = TF::GREEN . " (" . $centerPs->getX() . "," . $centerPs->getZ() . ") " . $centerFaction . " " . TF::WHITE;
  11.         $head = TF::GOLD . str_repeat("_", (($width - strlen($head)) / 2)) . ".[" . $head . TF::GOLD . "]." . str_repeat("_", (($width - strlen($head)) / 2));
  12.  
  13.         $map[] = $head;
  14.  
  15.         $halfWidth = $width / 2;
  16.         $halfHeight = $height / 2;
  17.         $width = $halfWidth * 2 + 1;
  18.         $height = $halfHeight * 2 + 1;
  19.  
  20.         $topLeftPs = new Vector3($centerPs->x + -$halfWidth, 0, $centerPs->z + -$halfHeight);
  21.  
  22.         // Get the compass
  23.         $asciiCompass = self::getASCIICompass($inDegrees, TF::RED, TF::GOLD);
  24.  
  25.         // Make room for the list of names
  26.         $height--;
  27.  
  28.         /** @var string[] $fList */
  29.         $fList = array();
  30.         $chrIdx = 0;
  31.         $overflown = false;
  32.         $chars = self::MAP_KEY_CHARS;
  33.  
  34.         // For each row
  35.         for ($dz = 0; $dz < $height; $dz++){
  36.             // Draw and add that row
  37.             $row = "";
  38.             for ($dx = 0; $dx < $width; $dx++){
  39.                 if($dx == $halfWidth && $dz == $halfHeight){
  40.                     $row .= (self::MAP_KEY_SEPARATOR);
  41.                     continue;
  42.                 }
  43.  
  44.                 if(!$overflown && $chrIdx >= strlen(self::MAP_KEY_CHARS)) $overflown = true;
  45.                 $herePs = $topLeftPs->add($dx, 0, $dz);
  46.                 $hereFaction = $this->factionInPoint($herePs->x << $to, $herePs->z << $to);
  47.                 $contains = in_array($hereFaction, $fList, true);
  48.                 if($hereFaction === NULL){
  49.                     $row .= self::MAP_KEY_WILDERNESS;
  50.                 } elseif(!$contains && $overflown){
  51.                     $row .= self::MAP_KEY_OVERFLOW;
  52.                 } else {
  53.                     if(!$contains) $fList[$chars{$chrIdx++}] = $hereFaction;
  54.                     $fchar = array_search($hereFaction, $fList);
  55.                     $row .= $this->getColorForTo($observer, $hereFaction) . $fchar;
  56.                 }
  57.             }
  58.  
  59.             $line = $row; // ... ---------------
  60.  
  61.             // Add the compass
  62.             if($dz == 0) $line = $asciiCompass[0] . "" . substr($row, 3 * strlen(self::MAP_KEY_SEPARATOR));
  63.             if($dz == 1) $line = $asciiCompass[1] . "" . substr($row, 3 * strlen(self::MAP_KEY_SEPARATOR));
  64.             if($dz == 2) $line = $asciiCompass[2] . "" . substr($row, 3 * strlen(self::MAP_KEY_SEPARATOR));
  65.  
  66.             $map[] = $line;
  67.         }
  68.         $fRow = "";
  69.         foreach ($fList as $char => $faction){
  70.             $fRow .= $this->getColorForTo($observer, $faction) . $char . ": " . $faction . " ";
  71.         }
  72.         if($overflown) $fRow .= self::MAP_OVERFLOW_MESSAGE;
  73.         $fRow = trim($fRow);
  74.         $map[] = $fRow;
  75.  
  76.         return $map;
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement