# HG changeset patch # User Matti Hamalainen # Date 1394570449 -7200 # Node ID 876e9bb593d5c89ecdca245b9e3c71904c123d4d # Parent d68111417b8eb1d20055307cd73df49178189b6f Move less time-consuming stuff earlier in the script. diff -r d68111417b8e -r 876e9bb593d5 tools/makegmaps.php --- a/tools/makegmaps.php Tue Mar 11 22:34:26 2014 +0200 +++ b/tools/makegmaps.php Tue Mar 11 22:40:49 2014 +0200 @@ -156,6 +156,7 @@ die("Error writing continent data to ".$continentJS."\n"); + /* * Generate marker files from LOC data */ @@ -182,6 +183,99 @@ } +/* Calculate worldmap coordinates from continent coordinates + */ +function getWorldCoords($cont, $xp, $yp, &$xc, &$yc) +{ + global $worldMap, $continentList; + + if (!isset($continentList[$cont])) + return FALSE; + + $xc = $worldMap["ox"] + $continentList[$cont][1] + $xp - 1; + $yc = $worldMap["oy"] + $continentList[$cont][2] + $yp - 1; + return TRUE; +} + + +/* Get worldmap coordinates for a given tradelane waypoint + */ +function getWaypointCoords($waypoint, &$xc, &$yc) +{ + global $tradelanePoints; + + if (!isset($tradelanePoints[$waypoint])) + return FALSE; + + return getWorldCoords($tradelanePoints[$waypoint][0], + $tradelanePoints[$waypoint][1], $tradelanePoints[$waypoint][2], $xc, $yc); +} + + +function outputJSON($qfilename, $qdata) +{ + if (file_put_contents($qfilename, json_encode($qdata), LOCK_EX) === FALSE) + die("Could not write to file '".$qfilename."'.\n"); +} + + +/* Export tradelane waypoint data + */ +if (!isset($tradelanePoints)) + die("PHP array \$tradelanePoints not set, '$config' is old or incompatible.\n"); + +echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n"; + +$qdata = array(); + +foreach ($tradelanePoints as $name => $data) +{ + $html = "TRADELANE WPT
".htmlentities($name); + + if (!getWorldCoords($data[0], $data[1], $data[2], $xc, $yc)) + die("Invalid tradelane waypoint '".$name."', continent '".$data[0]."' not defined.\n"); + + $qdata[] = array( + "x" => $xc, + "y" => $yc, + "name" => $name, + "html" => $html, + "continent" => "", + "type" => "tradelane" + ); +} + +outputJSON($tradelaneOut, $qdata); + + +/* Export tradelane polyline data + */ +echo "\nCreating tradelane polyline data '".$tradelaneOverlay."' ...\n"; +if (!isset($tradelaneDefs)) + die("PHP array \$tradelaneDefs not set, '$config' is old or incompatible.\n"); + +$qdata = array(); +foreach ($tradelaneDefs as $index => $points) +{ + $qline = array(); + + foreach ($points as $point) + { + if (!getWaypointCoords($point, $xc, $yc)) + die("Invalid tradelane definition #$index: waypoint '".$point."' not defined.\n"); + + $qline[] = array( + "x" => $xc, + "y" => $yc + ); + } + + $qdata[] = $qline; +} + + +outputJSON($tradelaneOverlay, $qdata); + /* * Generate PNG maps */ @@ -330,99 +424,6 @@ } -/* Calculate worldmap coordinates from continent coordinates - */ -function getWorldCoords($cont, $xp, $yp, &$xc, &$yc) -{ - global $worldMap, $continentList; - - if (!isset($continentList[$cont])) - return FALSE; - - $xc = $worldMap["ox"] + $continentList[$cont][1] + $xp - 1; - $yc = $worldMap["oy"] + $continentList[$cont][2] + $yp - 1; - return TRUE; -} - - -/* Get worldmap coordinates for a given tradelane waypoint - */ -function getWaypointCoords($waypoint, &$xc, &$yc) -{ - global $tradelanePoints; - - if (!isset($tradelanePoints[$waypoint])) - return FALSE; - - return getWorldCoords($tradelanePoints[$waypoint][0], - $tradelanePoints[$waypoint][1], $tradelanePoints[$waypoint][2], $xc, $yc); -} - - -function outputJSON($qfilename, $qdata) -{ - if (file_put_contents($qfilename, json_encode($qdata), LOCK_EX) === FALSE) - die("Could not write to file '".$qfilename."'.\n"); -} - - -/* Export tradelane waypoint data - */ -if (!isset($tradelanePoints)) - die("PHP array \$tradelanePoints not set, '$config' is old or incompatible.\n"); - -echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n"; - -$qdata = array(); - -foreach ($tradelanePoints as $name => $data) -{ - $html = "TRADELANE WPT
".htmlentities($name); - - if (!getWorldCoords($data[0], $data[1], $data[2], $xc, $yc)) - die("Invalid tradelane waypoint '".$name."', continent '".$data[0]."' not defined.\n"); - - $qdata[] = array( - "x" => $xc, - "y" => $yc, - "name" => $name, - "html" => $html, - "continent" => "", - "type" => "tradelane" - ); -} - -outputJSON($tradelaneOut, $qdata); - - -/* Export tradelane polyline data - */ -echo "\nCreating tradelane polyline data '".$tradelaneOverlay."' ...\n"; -if (!isset($tradelaneDefs)) - die("PHP array \$tradelaneDefs not set, '$config' is old or incompatible.\n"); - -$qdata = array(); -foreach ($tradelaneDefs as $index => $points) -{ - $qline = array(); - - foreach ($points as $point) - { - if (!getWaypointCoords($point, $xc, $yc)) - die("Invalid tradelane definition #$index: waypoint '".$point."' not defined.\n"); - - $qline[] = array( - "x" => $xc, - "y" => $yc - ); - } - - $qdata[] = $qline; -} - - -outputJSON($tradelaneOverlay, $qdata); - /* * Build tiles */