private function loadNearebyLocation() { $resources = array(); for ($i = -1; $i <= 1; $i++) { for ($j = -1; $j <= 1; $j++) { $land = Dolumar_Map_Location::getLocation($this->tileLocationX + $i, $this->tileLocationY + $j); $benefit = $land->getIncomeBonus(); foreach ($benefit as $k => $v) { if (!isset($resources[$k])) { $resources[$k] = $v; } else { $resources[$k] += $v; } } } } return $resources; }
public function checkBuildLocation($village, $x, $y, $bradius = MAXBUILDINGRADIUS) { $db = Neuron_DB_Database::getInstance(); $x = floor($x); $y = floor($y); $distance = MAXBUILDINGRADIUS * MAXBUILDINGRADIUS; /* $l = $db->query (" SELECT 1 FROM (SELECT 1) t WHERE EXISTS ( SELECT * FROM map_buildings WHERE ((xas - $x) * (xas - $x)) + ((yas - $y) * (yas - $y)) < ($distance) AND buildingType = 1 AND destroyDate = 0 ) "); */ $query = "\n\t\t\tSELECT\n\t\t\t\t1\n\t\t\tFROM \n\t\t\t\t(SELECT 1) t\n\t\t\tWHERE EXISTS\n\t\t\t(\n\t\t\t\tSELECT\n\t\t\t\t\txas\n\t\t\t\tFROM\n\t\t\t\t\tmap_buildings\n\t\t\t\tWHERE\n\t\t\t\t\txas BETWEEN " . ($x - $bradius) . " AND " . ($x + $bradius) . "\n\t\t\t\t\tAND yas BETWEEN " . ($y - $bradius) . " AND " . ($y + $bradius) . "\n\t\t\t\t\tAND (buildingType = 1 OR buildingType = 3) \n\t\t\t\t\tAND destroyDate = 0\n\t\t\t)\n\t\t"; $l = $db->query($query); if (count($l) > 0) { return array(false, 'minimalRange'); } $location = Dolumar_Map_Location::getLocation($x, $y); if ($location->canBuildBuilding()) { return array(true, array($x, $y)); } else { return array(false, 'minimalRange'); } }
} // 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++) { $j = 0; for ($y = $startY; $y <= $endY; $y++) { // Check for building if (isset($buildings[$x]) && isset($buildings[$x][$y])) { $color = color_cache($im, $buildings[$x][$y][0]->getMapColor()); } else { $location = Dolumar_Map_Location::getLocation($x, $y); $c = $location->getHeightIntencity(); $col = $location->getMapColor(); $col[0] = floor($col[0] * $c); $col[1] = floor($col[1] * $c); $col[2] = floor($col[2] * $c); $color = color_cache($im, $col); } imagerectangle($im, $i, $j, $i + 1, $j + 1, $color); $j++; } $i++; } imagepng($im, $file); imagepng($im); }
public function getLocation($x, $y, $hasObjects) { return Dolumar_Map_Location::getLocation($x, $y, $hasObjects); }
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; }
public function checkBuildLocation($village, $x, $y) { $db = Neuron_Core_Database::__getInstance(); $range = $village->getBuildingRadius(); /* $townCenter = $db->select ( 'map_buildings', array ('xas, yas'), "buildingType = '1' AND village = '".$village->getId ()."'" ); */ $townCenter = $village->buildings->getTownCenter(); if ($townCenter) { $size = $this->getSize(); // Don't allow buildings spreading over multiple tiles. if ($size[0] > 0.5) { $x = floor($x); } if ($size[1] > 0.5) { $y = floor($y); } // Check for range $loc = $townCenter->getLocation(); $d = sqrt(pow($loc[0] - $x, 2) + pow($loc[1] - $y, 2)); // Niet goed: te ver van het town center if ($d > $range) { return array(false, 'outOfRange', array($range)); } else { // Check for other buildings in the area $location = Dolumar_Map_Location::getLocation($x, $y); $chk = $db->select('map_buildings', array('bid'), "xas > ('" . $x . "' - sizeX) AND xas < '" . ($x + $size[0]) . "' " . "AND yas > ('" . $y . "' - sizeY) AND yas < '" . ($y + $size[1]) . "' " . "AND destroyDate = '0'"); // Alles is okay if (count($chk) == 0 && $location->canBuildBuilding()) { return array(true, array($x, $y)); } else { return array(false, 'buildingOverlap'); } } } else { return array(false, 'townCenterNotFound'); } }
function getBackgroundImage($x, $y, $tilesToLoad, $usecache = true) { global $color_cache; $cachename = 'i' . intval($_GET['x']) . 'p' . intval($_GET['y']) . $tilesToLoad . '.png'; $cache = Neuron_Core_Cache::__getInstance('minimapbg/'); if ($usecache && $cache->hasCache($cachename, 0)) { $img = $cache->getFileName($cachename); return imagecreatefrompng($img); } else { $color_cache = array(); // Build the new background image. $tileSizeX = 8; $tileSizeY = $tileSizeX / 2; $halfTileX = floor($tileSizeX / 2); $halfTileY = floor($tileSizeY / 2); $im = imagecreate($tileSizeX * $tilesToLoad, $tileSizeY * $tilesToLoad); $background = imagecolorallocate($im, 0, 0, 0); $switchpoint = $tilesToLoad; $loadExtra = 1; $startX = ($x + $y) * $switchpoint; $startY = ($x - $y) * $switchpoint; for ($i = 0 - $loadExtra - 1; $i < $switchpoint * 2 + $loadExtra + 1; $i++) { if ($i > $switchpoint) { $offset = ($i - $switchpoint) * 2; } else { $offset = 0; } $colStart = 0 - $i + $offset - $loadExtra; $colEnd = $i - $offset + $loadExtra + 1; //$output['sq'][$sQ]['tl'][$i] = array (); $tx = $startX + $i; $white = imagecolorallocate($im, 255, 255, 255); for ($j = $colStart - 1; $j < $colEnd + 1; $j++) { $ty = $startY - $j; $px = round(($i - $j) * floor($tileSizeX / 2)); $py = round(($i + $j) * floor($tileSizeY / 2)); // Check for building /* if (isset ($buildings[$tx]) && isset ($buildings[$tx][$ty])) { $color = color_cache ($im, $buildings[$tx][$ty][0]->getMapColor ()); } else { */ $location = Dolumar_Map_Location::getLocation($tx, $ty); $c = $location->getHeightIntencity(); $col = $location->getMapColor(); $col[0] = floor($col[0] * $c); $col[1] = floor($col[1] * $c); $col[2] = floor($col[2] * $c); $color = color_cache($im, $col); //} $punten = array($px + $halfTileX, $py, $px + $tileSizeX, $py + $halfTileY, $px + $halfTileX, $py + $tileSizeY, $px, $py + $halfTileY); imagefilledpolygon($im, $punten, 4, $color); } } ob_start(); imagepng($im, null); $cache->setCache($cachename, ob_get_clean()); return $im; } }