Example #1
0
 public function getObjects($squarePoints, $radius)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     // Let's replace this :)
     $out = array();
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($squarePoints, max($radius, 3));
     $objects = array();
     foreach ($buildingSQL as $buildingV) {
         $profiler->start('Initializing building');
         $profiler->start('Fetching building race object');
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $profiler->stop();
         $profiler->start('Fetching building object');
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $village = Dolumar_Players_Village::getVillage($buildingV['village']);
         $b->setVillage($village);
         $profiler->stop();
         $profiler->start('Setting data');
         $b->setData($buildingV['bid'], $buildingV);
         if ($buildingV['destroyDate'] > 0 && $buildingV['destroyDate'] < NOW) {
             $b->setDestroyed(true);
         }
         $profiler->stop();
         $profiler->start('Assigning building to array');
         //$buildings[floor ($buildingV['xas'])][floor ($buildingV['yas'])][] = $b;
         $objects[] = new Dolumar_Map_Object($b);
         $profiler->stop();
         $profiler->stop();
     }
     return $objects;
 }
 if (file_exists($file)) {
     if (filectime($file) > time() - 60 * 60 * 24 * 31) {
         $parseNew = isset($_GET['parseNew']);
         if ($parseNew) {
             unlink($file);
         } else {
             echo file_get_contents($file);
         }
     } else {
         unlink($file);
     }
 }
 if ($parseNew) {
     // Load buildings from SQL
     $points = array(array($_GET['x'] * $imageSize + $imageSize / 2, $_GET['y'] * $imageSize + $imageSize / 2));
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($points, $imageSize);
     $buildings = array();
     foreach ($buildingSQL as $buildingV) {
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $b->setData($buildingV['bid'], $buildingV);
         $buildings[floor($buildingV['xas'])][floor($buildingV['yas'])][] = $b;
     }
     // Add buildings
     $startX = $_GET['x'] * $imageSize;
     $endX = $startX + $imageSize;
     $startY = $_GET['y'] * $imageSize;
     $endY = $startY + $imageSize;
     $im = imagecreate($imageSize, $imageSize);
     $i = 0;
     for ($x = $startX; $x <= $endX; $x++) {
Example #3
0
 public static function getSnapshot($x, $y, $width, $height, $zoom)
 {
     $stats = Neuron_Core_Stats::__getInstance();
     $fZoom = $zoom / 100;
     // Make a bigger image
     $width = $width / $fZoom;
     $height = $height / $fZoom;
     $floatZoom = 1;
     $tileSizeX = 200 * $floatZoom;
     $tileSizeY = $tileSizeX / 2;
     $halfTileX = $tileSizeX / 2;
     $halfTileY = $tileSizeY / 2;
     $offsetX = ceil($tileSizeX / 2);
     $offsetY = ceil($tileSizeY / 2);
     $loadExtra = 1;
     $switchpoint = max(ceil($width / ($tileSizeX * 1)), ceil($height / $tileSizeY));
     $im = imagecreatetruecolor($width, $height);
     list($startX, $startY) = self::getStartposition($x, $y, $width, $height, $tileSizeX, $tileSizeY);
     $locations = array(array($startX + $switchpoint / 2, $startY - $switchpoint / 2));
     // Load buildings from SQL
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($locations, $switchpoint + 15);
     $buildings = array();
     foreach ($buildingSQL as $buildingV) {
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $village = Dolumar_Players_Village::getVillage($buildingV['village']);
         $b->setVillage($village);
         $b->setData($buildingV['bid'], $buildingV);
         $buildings[floor($buildingV['xas'])][floor($buildingV['yas'])][] = $b;
     }
     for ($i = 0 - $loadExtra; $i <= $switchpoint * 2; $i++) {
         if ($i > $switchpoint) {
             $offset = ($i - $switchpoint + 1) * 2;
         } else {
             $offset = 0;
         }
         $colStart = 0 - $i + $offset - $loadExtra;
         $colEnd = $i - $offset + $loadExtra + 1;
         //$output['regions'][$sQ]['tiles'][$i] = array ();
         $tx = $startX + $i;
         for ($j = $colStart; $j < $colEnd; $j++) {
             $ty = $startY - $j;
             $px = ($i - $j) * $offsetX;
             $py = ($i + $j) * $offsetY;
             // Check for building
             $hasBuildings = isset($buildings[$tx]) && isset($buildings[$tx][$ty]);
             $location = Dolumar_Map_Location::getLocation($tx, $ty, $hasBuildings);
             $image = $location->getImage();
             $sImagePath = IMAGE_PATH . 'tiles/' . $image['image'] . '.gif';
             //die ($sImagePath);
             self::drawSnapshotImage($im, $sImagePath, $px, $py, $floatZoom);
             //checkBuildings ($buildings, $sQ, $i, $j, $tx, $ty);
             if ($hasBuildings) {
                 foreach ($buildings[$tx][$ty] as $building) {
                     $short = $building->getIsoImage();
                     $url = $building->getImagePath();
                     $offset = $building->getTileOffset();
                     $fakeurl = IMAGE_PATH . 'sprites/' . $short . '.png';
                     //echo "---\n";
                     //echo $url . "\n";
                     //echo $fakeurl . "\n";
                     $oi = $i + $offset[0];
                     $oj = $j + $offset[1];
                     $pox = round(($oi - $oj) * floor($tileSizeX / 2));
                     $poy = round(($oi + $oj) * floor($tileSizeY / 2));
                     self::drawSnapshotImage($im, $url, $pox + $stats->get('offsetx', $short, 'images', 0) * $floatZoom, $poy + $stats->get('offsety', $short, 'images', 0) * $floatZoom, $floatZoom, false);
                 }
             }
         }
     }
     // Resize the image
     $newwidth = $width * $fZoom;
     $newheight = $height * $fZoom;
     $newimg = imagecreatetruecolor($newwidth, $newheight);
     imagecopyresampled($newimg, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     return $newimg;
 }
 $y = $_GET['y'];
 $im = getBackgroundImage($x, $y, $tilesToLoad);
 $color_cache = array();
 // Build the new background image.
 $tileSizeX = 8;
 $tileSizeY = $tileSizeX / 2;
 $halfTileX = floor($tileSizeX / 2);
 $halfTileY = floor($tileSizeY / 2);
 $switchpoint = $tilesToLoad;
 $loadExtra = 1;
 $startX = ($x + $y) * $switchpoint;
 $startY = ($x - $y) * $switchpoint;
 $db = Neuron_Core_Database::__getInstance();
 $locations = array(array($startX + $switchpoint / 2, $startY - $switchpoint / 2));
 // Load buildings from SQL
 $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($locations, $switchpoint + 25);
 foreach ($buildingSQL as $buildingV) {
     $race = Dolumar_Races_Race::getRace($buildingV['race']);
     $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
     $b->setData($buildingV['bid'], $buildingV);
     //$buildings[floor ($buildingV['xas'])][floor ($buildingV['yas'])][] = $b;
     $x = floor($buildingV['xas']);
     $y = floor($buildingV['yas']);
     $color = color_cache($im, $b->getMapColor());
     $i = $x - $startX;
     $j = $startY - $y;
     $px = round(($i - $j) * floor($tileSizeX / 2));
     $py = round(($i + $j) * floor($tileSizeY / 2));
     $tileSizeX = 8;
     $tileSizeY = $tileSizeX / 2;
     $halfTileX = floor($tileSizeX / 2);