# HG changeset patch # User Matti Hamalainen # Date 1586570540 -10800 # Node ID 3a67c8425d1b1a4e05b2d36b01a6ba8f8354a7a8 # Parent 63eb4661d13c1ae3f7501f20a7ccd9319091e582 Clean up the code a bit, use the CTI_* constants defined in maputils/www/world.inc.php for accessing the continentList array. diff -r 63eb4661d13c -r 3a67c8425d1b tools/makegmaps.php --- a/tools/makegmaps.php Thu Oct 19 18:02:37 2017 +0300 +++ b/tools/makegmaps.php Sat Apr 11 05:02:20 2020 +0300 @@ -117,15 +117,15 @@ // Calculate worldmap coordinates from continent coordinates -function stGetWorldCoords($cont, $xp, $yp, &$xc, &$yc) +function stGetWorldCoords($cname, $xp, $yp, &$xc, &$yc) { global $worldMap, $continentList; - if (!isset($continentList[$cont])) + if (!isset($continentList[$cname])) return FALSE; - $xc = $worldMap["ox"] + $continentList[$cont][1] + $xp - 1; - $yc = $worldMap["oy"] + $continentList[$cont][2] + $yp - 1; + $xc = $worldMap["ox"] + $continentList[$cname][CTI_XOFFS] + $xp - 1; + $yc = $worldMap["oy"] + $continentList[$cname][CTI_YOFFS] + $yp - 1; return TRUE; } @@ -399,16 +399,16 @@ $str .= "};\n"; $str .= "var pmapContinents =\n[\n"; -foreach ($continentList as $name => $data) -if ($data[4] && $data[7]) +foreach ($continentList as $cname => $cdata) +if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) { $str .= sprintf(" [%-15s, %5d, %5d, %5d, %5d, %5d, %5d],\n", - "\"".$data[0]."\"", - $data[1], - $data[2], - $data[1] + $data[5] - 1, - $data[2] + $data[6] - 1, - $data[5], $data[6]); + "\"".$cdata[CTI_NAME]."\"", + $cdata[CTI_XOFFS], + $cdata[CTI_YOFFS], + $cdata[CTI_XOFFS] + $cdata[CTI_WIDTH] - 1, + $cdata[CTI_YOFFS] + $cdata[CTI_HEIGHT] - 1, + $cdata[CTI_WIDTH], $cdata[CTI_HEIGHT]); } $str .= "];\n"; @@ -425,16 +425,16 @@ { $tmp = escapeshellcmd($binMkLoc)." -v -o ".escapeshellarg($cfg["pathGMap"].$mdata[0])." -G ".$mode." "; - foreach ($continentList as $name => $data) + foreach ($continentList as $cname => $cdata) { - if ($data[4] && $data[7]) + if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) { // has a map $tmp .= - "-l ".escapeshellarg($cfg["pathLocFiles"].$name.".loc")." ". - "-c ".escapeshellarg($data[0])." ". - "-x ".escapeshellarg($worldMap["ox"] + $data[1] + $mdata[1])." ". - "-y ".escapeshellarg($worldMap["oy"] + $data[2] + $mdata[2])." "; + "-l ".escapeshellarg($cfg["pathLocFiles"].$cname.".loc")." ". + "-c ".escapeshellarg($cdata[CTI_NAME])." ". + "-x ".escapeshellarg($worldMap["ox"] + $cdata[CTI_XOFFS] + $mdata[1])." ". + "-y ".escapeshellarg($worldMap["oy"] + $cdata[CTI_YOFFS] + $mdata[2])." "; } } @@ -452,17 +452,17 @@ $qdata = []; -foreach ($tradelanePoints as $name => $data) +foreach ($tradelanePoints as $tname => $tlane) { - $html = "TRADELANE WPT
".htmlentities($name); + $html = "TRADELANE WPT
".htmlentities($tname); - if (!stGetWorldCoords($data[0], $data[1], $data[2], $xc, $yc)) - die("Invalid tradelane waypoint '".$name."', continent '".$data[0]."' not defined.\n"); + if (!stGetWorldCoords($tlane[0], $tlane[1], $tlane[2], $xc, $yc)) + die("Invalid tradelane waypoint '".$tname."', continent '".$tlane[0]."' not defined.\n"); $qdata[] = [ "x" => $xc, "y" => $yc, - "name" => $name, + "name" => $tname, "html" => $html, "continent" => "", "type" => "tradelane", @@ -506,7 +506,7 @@ // // Generate PNG maps // -function makeMap($inFilename, $outFilename, $zlevel, $data) +function makeMap($inFilename, $outFilename, $zlevel, $cdata) { global $mapPalette, $fontFile, $fontSize; @@ -519,8 +519,8 @@ // Derp $zoom = pow(2, $zlevel - 1); - $width = $data[5]; - $height = $data[6]; + $width = $cdata[CTI_WIDTH]; + $height = $cdata[CTI_HEIGHT]; // Create image and assign colors if (($im = imagecreate($width*$zoom, $height*$zoom)) === FALSE) @@ -582,26 +582,26 @@ } echo "Generating basic map data...\n"; -foreach ($continentList as $name => $data) -if ($data[4] && $data[7]) +foreach ($continentList as $cname => $cdata) +if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) { - $inFilename = $cfg["pathRawMaps"].$name.$rawSuffix; + $inFilename = $cfg["pathRawMaps"].$cname.$rawSuffix; if (!file_exists($inFilename)) { - $inFilename = $cfg["pathRawMaps"].$name.$rawAltSuffix; + $inFilename = $cfg["pathRawMaps"].$cname.$rawAltSuffix; if (!file_exists($inFilename)) - die("Required file '".$cfg["pathRawMaps"].$name."(".$rawSuffix."|".$rawAltSuffix.")' does not exist.\n"); + die("Required file '".$cfg["pathRawMaps"].$cname."(".$rawSuffix."|".$rawAltSuffix.")' does not exist.\n"); } $inMtime = filemtime($inFilename); for ($zoom = 1; $zoom <= 5; $zoom++) { - $outFilename = $cfg["pathImageCache"].$name."_".($zoom + 4).".png"; + $outFilename = $cfg["pathImageCache"].$cname."_".($zoom + 4).".png"; $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1; - echo "- ".$name." (".$data[0]."): "; + echo "- ".$cname." (".$cdata[CTI_NAME]."): "; if ($inMtime > $outMtime) { - $res = makeMap($inFilename, $outFilename, $zoom, $data); + $res = makeMap($inFilename, $outFilename, $zoom, $cdata); echo ($res ? "OK" : "FAIL")."\n"; } else @@ -615,11 +615,11 @@ */ echo "\nGenerating scaled small map data...\n"; $mapScales = ["50", "25", "12.5", "6.25", "3.125"]; -foreach ($continentList as $name => $data) -if ($data[4] && $data[7]) +foreach ($continentList as $cname => &$cdata) +if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) { $n = count($mapScales); - $inFilename = $cfg["pathImageCache"].$name."_".$n.".png"; + $inFilename = $cfg["pathImageCache"].$cname."_".$n.".png"; if (!file_exists($inFilename)) { die("Required file '".$inFilename."' does not exist.\n"); @@ -629,7 +629,7 @@ foreach ($mapScales as $scale) { $n--; - $outFilename = $cfg["pathImageCache"].$name."_".$n.".png"; + $outFilename = $cfg["pathImageCache"].$cname."_".$n.".png"; $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1; echo "* ".$inFilename." -> ".$outFilename.": "; @@ -667,15 +667,15 @@ $drawn = false; $im = false; - foreach ($continentList as $continent => $data) + foreach ($continentList as $cname => &$cdata) { - if (!$data[4] || !$data[7]) + if (!$cdata[CTI_HAS_MAP] || !$cdata[CTI_REG_CONT]) continue; - $cx = $data[1] + $worldMap["ox"]; - $cy = $data[2] + $worldMap["oy"]; - $cw = $data[5]; - $ch = $data[6]; + $cx = $cdata[CTI_XOFFS] + $worldMap["ox"]; + $cy = $cdata[CTI_YOFFS] + $worldMap["oy"]; + $cw = $cdata[CTI_WIDTH]; + $ch = $cdata[CTI_HEIGHT]; $tx = -($cx*$scale - $x*$tileDim); $ty = -($cy*$scale - $y*$tileDim); @@ -692,7 +692,7 @@ $im = imagecreate($tileDim, $tileDim); if ($im === false || get_resource_type($im) != "gd") die("\nCould not create GD image resource open dim=".$tileDim. - " for zoom=".$zoom.", continent=".$continent."\n"); + " for zoom=".$zoom.", continent=".$cname."\n"); $sea = imagecolorallocate($im, 51, 51, 170); imagefilledrectangle($im, 0, 0, $tileDim, $tileDim, $sea); @@ -736,7 +736,7 @@ if ($im !== false) { - imagecopy($im, $mapData[$continent], $xx, $yy, $tx, $ty, $dx, $dy); + imagecopy($im, $mapData[$cname], $xx, $yy, $tx, $ty, $dx, $dy); $drawn = TRUE; } } @@ -779,14 +779,14 @@ $mh = ceil( $worldMap["h"] * $scale); $mapMtime = -1; - foreach ($continentList as $continent => &$data) - if ($data[4] && $data[7]) + foreach ($continentList as $cname => &$cdata) + if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) { - $mapFile = $cfg["pathImageCache"].$continent."_".$zoom2.".png"; - $mapData[$continent] = imagecreatefrompng($mapFile); - if ($mapData[$continent] === FALSE || - get_resource_type($mapData[$continent]) != "gd") - die("Not an GD image resource ".$mapData[$continent]." in '".$mapFile."'\n"); + $mapFile = $cfg["pathImageCache"].$cname."_".$zoom2.".png"; + $mapData[$cname] = imagecreatefrompng($mapFile); + if ($mapData[$cname] === FALSE || + get_resource_type($mapData[$cname]) != "gd") + die("Not an GD image resource ".$mapData[$cname]." in '".$mapFile."'\n"); $tmp = filemtime($mapFile); if ($tmp > $mapMtime) @@ -802,10 +802,10 @@ echo "\n"; // Free image data for each continent - foreach($continentList as $continent => $data) + foreach ($continentList as $cname => &$cdata) { - if ($data[4] && $data[7]) - imagedestroy($mapData[$continent]); + if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) + imagedestroy($mapData[$cname]); } }