summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--images/marks/Snap.pngbin0 -> 610 bytes
-rw-r--r--includes/mapclass.php3
-rw-r--r--includes/mapoftheday.php2
-rw-r--r--includes/maps.php167
-rw-r--r--pages/mapeditor.php39
5 files changed, 120 insertions, 91 deletions
diff --git a/images/marks/Snap.png b/images/marks/Snap.png
new file mode 100644
index 0000000..010ee9c
--- /dev/null
+++ b/images/marks/Snap.png
Binary files differ
diff --git a/includes/mapclass.php b/includes/mapclass.php
index 8e9f28e..2da7e11 100644
--- a/includes/mapclass.php
+++ b/includes/mapclass.php
@@ -53,7 +53,8 @@ class map {
}
}
-
+
+
public function applyMapFromOldCode($code) {
//echo "decoding mapcode: [$code]";
$this->code = $code;
diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php
index 0158b4f..1611bc7 100644
--- a/includes/mapoftheday.php
+++ b/includes/mapoftheday.php
@@ -1 +1 @@
-<?php include_once('maps.php'); include_once('sqlEmbedded.php'); include_once('playerStats.php'); include_once('constants.php'); include_once('mapclass.php'); include_once('chats.php'); /** * Returns the Map Of The Day with the given type (index). Generates new maps if necessary. */ function mapOfTheDay($type = MapType::Simple) { //TODO del comments //echo "[Seeking maptype $type]"; $map = getMapOfTheDayInternal($type); if($map == null) { //Map doesn't exist, so we generate the maps and try again generateNewMapsOfTheDay(); $map = getMapOfTheDayInternal($type); } //else echo "[Found $type]"; return $map; } /** * Returns the map of the day of the given type, or null if not found. * Do not call outside of mapoftheday.php */ function getMapOfTheDayInternal($type) { //The ORDER BY and LIMIT probably shouldn't be necessary, since there should only be one active map of each //type at a time anyways.. $sql = " SELECT maps.ID, maps.code FROM `mapOfTheDay` INNER JOIN `maps` ON mapOfTheDay.mapID = maps.ID WHERE `mapType` = $type AND mapOfTheDay.mapExpireTime > NOW() ORDER BY mapOfTheDay.mapDate DESC LIMIT 1 "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); set_time_limit(0); $lock = acquireMotdLock(); try { //Double check that we still need to generate a new map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $latestSpecialMap = getMapOfTheDayInternal(MapType::Special); $latestWeeklyMap = getMapOfTheDayInternal(MapType::Weekly); if($latestSpecialMap != null && $latestWeeklyMap != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps $mapCode = array(); if($latestSpecialMap == null) { $mapCode[MapType::Simple] = generateNewMapCode(MapType::Simple); $mapCode[MapType::Normal] = generateNewMapCode(MapType::Normal); $mapCode[MapType::Complex] = generateNewMapCode(MapType::Complex); $mapCode[MapType::Special] = generateNewMapCode(MapType::Special); } //The weekly maps might not need to be generated tonight. Check if it does first if($latestWeeklyMap == null) { $mapCode[MapType::Weekly] = generateNewMapCode(MapType::Weekly); } //Add the actual maps to the DB addNewMapsToDB($mapCode); //Update the player-statistics if($latestSpecialMap == null) { //Add points for yesterday's maps if we just created the daily maps addStatsForYesterdaysMaps(); } if($latestWeeklyMap == null) { //Add points for the weekly map, which is created at noon rather than midnight addStatsForMiddayMaps(); //Note that there could potentially be an issue adding points twice if server goes from noon on Saturday //(or whenever we generate the new weekly map) to midnight the next morning without anyone visiting the site. //That's probably not going to be an issue on the production site, however... } } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and returns its "map code" */ function generateNewMapCode($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case MapType::Simple: $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0, 'Simple'); break; case MapType::Normal: $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0, 'Normal'); break; case MapType::Complex: $map = getRandomComplexMap(); break; case MapType::Special: $map = getRandomSpecialMap(); break; case MapType::Weekly: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } return GenerateMapCode($map); } function addNewMapsToDB($mapCode) { foreach($mapCode as $code) { $map = new map($code); $codeSafe = mysql_escape_string($code); $nameSafe = mysql_escape_string($map->name); $codeValuesAry[] = " ('$codeSafe', '$nameSafe')"; } $codeValues = implode(",", $codeValuesAry); //Insert all the maps at once. $sql = "INSERT INTO `maps` (`code`, `name`) VALUES $codeValues"; //Did we succeed? $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting maps, offending SQL: $sql"); } //Get the ID of the first insert. $mapIDI = mysql_insert_id(); foreach ($mapCode as $type => $code) { if($type == MapType::Weekly) { //Weekly map lasts MAP_EXPIRE_TIME_WEEKLY days. We also want to offset by 12 hours $numHours = 24*MAP_EXPIRE_TIME_WEEKLY + 12; $expireTime = "ADDDATE(CURDATE(), INTERVAL $numHours HOUR)"; } else { //All other maps are assumed to last one day $expireTime = 'ADDDATE(CURDATE(), INTERVAL 1 DAY)'; } $mapOfTheDayAry[] = "('$mapIDI', '$type', CURDATE(), $expireTime)"; $mapIDI++; } $mapOfTheDayValues = implode(",", $mapOfTheDayAry); $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`, `mapExpireTime`) VALUES $mapOfTheDayValues "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay SQL: $sql"); } else { //Post it in the chat! addchat(null, "New maps added!"); } } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2), 'Complex'); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. // Disabled maps: 12, 14 $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13); //FORCE: //$random = 13; $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Finite $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: //Dualing paths $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: //Unlimited $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== //===================================== case 11: //Thirty Too $thirtyTooShape[] = 's??????????????????Xf'; $thirtyTooShape[] = '????????????????????X'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = 'x????????????????????'; $thirtyTooShape[] = 'fx??????????????????S'; $thirtyTooShape = insertPoint($thirtyTooShape, 'atupppp'); $myparams['checkpoints'] = 2; $myparams['teleports'] = 1; $myparams['rockchance'] = 20; $myparams['walls'] = 32; $myparams['name'] = 'Thirty Too'; $map = GenerateShapedMap($thirtyTooShape, $myparams); break; //===================================== case 12: //InFinite $inFinite[] = "s?????????????????otf"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????omf"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????ogf"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????oif"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????okf"; $inFinite = insertPoint($inFinite, 'unjhl'); $myparams['checkpoints'] = 0; $myparams['teleports'] = 5; $myparams['rockchance'] = 7; $myparams['walls'] = weight(10, 11, 12, 13); $myparams['name'] = 'InFinite'; $map = GenerateShapedMap($inFinite, $myparams); break; //===================================== case 13: //Edge case $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase = insertPoint($edgeCase, 'sfab'); $edgeCase = insertPoint($edgeCase, weight('tu', 'tumn', 'c')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 2; $myparams['rockchance'] = 8; $myparams['walls'] = weight(16, 17, 18, 19, 20, 21); $myparams['name'] = 'Edge Case'; $map = GenerateShapedMap($edgeCase, $myparams); break; //===================================== //===================================== case 14: //OrderINg $orderIng[] = "s?????????????????fqu"; $orderIng[] = "s?????????????????fqn"; $orderIng[] = "s?????????????????fqh"; $orderIng[] = "s?????????????????fqi"; $orderIng[] = "s?????????????????fqk"; $orderIng[] = "s?????????????????fqa"; $orderIng[] = "s?????????????????fqb"; $orderIng[] = "s?????????????????fqc"; $orderIng[] = "s?????????????????fqd"; $orderIng[] = "s?????????????????fqf"; $orderIng = insertPoint($orderIng, 'abcdtmgjl'); $orderIng = insertPoint($orderIng, weight('', '', '', '', '', '', '', 'tmg')); $myparams['checkpoints'] = 4; $myparams['teleports'] = 5; $myparams['rockchance'] = 7; $myparams['walls'] = weight(16, 17, 18, 19, 20, 21); $myparams['name'] = 'OrderINg'; $map = GenerateShapedMap($orderIng, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0); //FORCE: $random = 0; $shape = array(); $params = array(); switch ($random) { case 0: $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); break; case 1: $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage = insertPoint($mirrorImage, 'abcdetnglrrrrr'); $mirrorImageB = $mirrorImage; foreach ($mirrorImageB as &$value) { $value = str_replace("t", "u", $value); $value = str_replace("n", "m", $value); $value = str_replace("g", "h", $value); $value = str_replace("l", "k", $value); $value = str_replace("f", "s", $value); $value = str_replace("S", "f", $value); } $mirrorImage[] = "qqqqqqqqqqqqqqqqqqqqqqqqq"; $mirrorImage = array_merge($mirrorImage, $mirrorImageB); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 400; $myparams['walls'] = 999; $myparams['name'] = 'Mirror Image'; $map = GenerateShapedMap($mirrorImage, $myparams); break; } return $map; } ?> \ No newline at end of file
+<?php include_once('maps.php'); include_once('sqlEmbedded.php'); include_once('playerStats.php'); include_once('constants.php'); include_once('mapclass.php'); include_once('chats.php'); /** * Returns the Map Of The Day with the given type (index). Generates new maps if necessary. */ function mapOfTheDay($type = MapType::Simple) { //TODO del comments //echo "[Seeking maptype $type]"; $map = getMapOfTheDayInternal($type); if($map == null) { //Map doesn't exist, so we generate the maps and try again generateNewMapsOfTheDay(); $map = getMapOfTheDayInternal($type); } //else echo "[Found $type]"; return $map; } /** * Returns the map of the day of the given type, or null if not found. * Do not call outside of mapoftheday.php */ function getMapOfTheDayInternal($type) { //The ORDER BY and LIMIT probably shouldn't be necessary, since there should only be one active map of each //type at a time anyways.. $sql = " SELECT maps.ID, maps.code FROM `mapOfTheDay` INNER JOIN `maps` ON mapOfTheDay.mapID = maps.ID WHERE `mapType` = $type AND mapOfTheDay.mapExpireTime > NOW() ORDER BY mapOfTheDay.mapDate DESC LIMIT 1 "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); set_time_limit(0); $lock = acquireMotdLock(); try { //Double check that we still need to generate a new map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $latestSpecialMap = getMapOfTheDayInternal(MapType::Special); $latestWeeklyMap = getMapOfTheDayInternal(MapType::Weekly); if($latestSpecialMap != null && $latestWeeklyMap != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps $mapCode = array(); if($latestSpecialMap == null) { $mapCode[MapType::Simple] = generateNewMapCode(MapType::Simple); $mapCode[MapType::Normal] = generateNewMapCode(MapType::Normal); $mapCode[MapType::Complex] = generateNewMapCode(MapType::Complex); $mapCode[MapType::Special] = generateNewMapCode(MapType::Special); } //The weekly maps might not need to be generated tonight. Check if it does first if($latestWeeklyMap == null) { $mapCode[MapType::Weekly] = generateNewMapCode(MapType::Weekly); } //Add the actual maps to the DB addNewMapsToDB($mapCode); //Update the player-statistics if($latestSpecialMap == null) { //Add points for yesterday's maps if we just created the daily maps addStatsForYesterdaysMaps(); } if($latestWeeklyMap == null) { //Add points for the weekly map, which is created at noon rather than midnight addStatsForMiddayMaps(); //Note that there could potentially be an issue adding points twice if server goes from noon on Saturday //(or whenever we generate the new weekly map) to midnight the next morning without anyone visiting the site. //That's probably not going to be an issue on the production site, however... } } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and returns its "map code" */ function generateNewMapCode($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case MapType::Simple: $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0, 'Simple'); break; case MapType::Normal: $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0, 'Normal'); break; case MapType::Complex: $map = getRandomComplexMap(); break; case MapType::Special: $map = getRandomSpecialMap(); break; case MapType::Weekly: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } return GenerateMapCode($map); } function addNewMapsToDB($mapCode) { foreach($mapCode as $code) { $map = new map($code); $codeSafe = mysql_escape_string($code); $nameSafe = mysql_escape_string($map->name); $codeValuesAry[] = " ('$codeSafe', '$nameSafe')"; } $codeValues = implode(",", $codeValuesAry); //Insert all the maps at once. $sql = "INSERT INTO `maps` (`code`, `name`) VALUES $codeValues"; //Did we succeed? $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting maps, offending SQL: $sql"); } //Get the ID of the first insert. $mapIDI = mysql_insert_id(); foreach ($mapCode as $type => $code) { if($type == MapType::Weekly) { //Weekly map lasts MAP_EXPIRE_TIME_WEEKLY days. We also want to offset by 12 hours $numHours = 24*MAP_EXPIRE_TIME_WEEKLY + 12; $expireTime = "ADDDATE(CURDATE(), INTERVAL $numHours HOUR)"; } else { //All other maps are assumed to last one day $expireTime = 'ADDDATE(CURDATE(), INTERVAL 1 DAY)'; } $mapOfTheDayAry[] = "('$mapIDI', '$type', CURDATE(), $expireTime)"; $mapIDI++; } $mapOfTheDayValues = implode(",", $mapOfTheDayAry); $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`, `mapExpireTime`) VALUES $mapOfTheDayValues "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay SQL: $sql"); } else { //Post it in the chat! addchat(null, "New maps added!"); } } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2), 'Complex'); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. // Disabled maps: 12, 14 $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13); //FORCE: $random = 15; $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Finite $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: //Dualing paths $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: //Unlimited $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== //===================================== case 11: //Thirty Too $thirtyTooShape[] = 's??????????????????Xf'; $thirtyTooShape[] = '????????????????????X'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = '?????????????????????'; $thirtyTooShape[] = 'x????????????????????'; $thirtyTooShape[] = 'fx??????????????????S'; $thirtyTooShape = insertPoint($thirtyTooShape, 'atupppp'); $myparams['checkpoints'] = 2; $myparams['teleports'] = 1; $myparams['rockchance'] = 20; $myparams['walls'] = 32; $myparams['name'] = 'Thirty Too'; $map = GenerateShapedMap($thirtyTooShape, $myparams); break; //===================================== case 12: //InFinite $inFinite[] = "s?????????????????otf"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????omf"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????ogf"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????oif"; $inFinite[] = "s?????????????????oof"; $inFinite[] = "s?????????????????okf"; $inFinite = insertPoint($inFinite, 'unjhl'); $myparams['checkpoints'] = 0; $myparams['teleports'] = 5; $myparams['rockchance'] = 7; $myparams['walls'] = weight(10, 11, 12, 13); $myparams['name'] = 'InFinite'; $map = GenerateShapedMap($inFinite, $myparams); break; //===================================== case 13: //Edge case $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "??????qqqqqqq??????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase[] = "???????????????????"; $edgeCase = insertPoint($edgeCase, 'sfab'); $edgeCase = insertPoint($edgeCase, weight('tu', 'tumn', 'c')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 2; $myparams['rockchance'] = 8; $myparams['walls'] = weight(16, 17, 18, 19, 20, 21); $myparams['name'] = 'Edge Case'; $map = GenerateShapedMap($edgeCase, $myparams); break; //===================================== //===================================== case 14: //OrderINg $orderIng[] = "s?????????????????fqu"; $orderIng[] = "s?????????????????fqn"; $orderIng[] = "s?????????????????fqh"; $orderIng[] = "s?????????????????fqi"; $orderIng[] = "s?????????????????fqk"; $orderIng[] = "s?????????????????fqa"; $orderIng[] = "s?????????????????fqb"; $orderIng[] = "s?????????????????fqc"; $orderIng[] = "s?????????????????fqd"; $orderIng[] = "s?????????????????fqf"; $orderIng = insertPoint($orderIng, 'abcdtmgjl'); $orderIng = insertPoint($orderIng, weight('', '', '', '', '', '', '', 'tmg')); $myparams['checkpoints'] = 4; $myparams['teleports'] = 5; $myparams['rockchance'] = 7; $myparams['walls'] = weight(16, 17, 18, 19, 20, 21); $myparams['name'] = 'OrderINg'; $map = GenerateShapedMap($orderIng, $myparams); break; //===================================== //===================================== case 15: //rooms $rooms[] = "?????q?????q?????q?????"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "????ooo???ooo???ooo????"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "??o??q??o??q??o??q??o??"; $rooms[] = "qqoqqqqqoqqqqqoqqqqqoqq"; $rooms[] = "??o??q??o??q??o??q??o??"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "????ooo???ooo???ooo????"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "??o??q??o??q??o??q??o??"; $rooms[] = "qqoqqqqqoqqqqqoqqqqqoqq"; $rooms[] = "??o??q??o??q??o??q??o??"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "????ooo???ooo???ooo????"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "??o??q??o??q??o??q??o??"; $rooms[] = "qqoqqqqqoqqqqqoqqqqqoqq"; $rooms[] = "??o??q??o??q??o??q??o??"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "????ooo???ooo???ooo????"; $rooms[] = "?????q?????q?????q?????"; $rooms[] = "??o??q??o??q??o??q??o??"; $rooms = insertPoint($rooms, 'abtumnghsf'); $rooms = insertPoint($rooms, weight('', '', '', '', '', '', '', 'c')); $rooms = insertPoint($rooms, weight('', '', '', '', '', '', '', 'ij')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 4; $myparams['rockchance'] = 17; $myparams['walls'] = weight(19, 20, 21); $myparams['name'] = 'rooms'; $map = GenerateShapedMap($rooms, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0); //FORCE: $random = 0; $shape = array(); $params = array(); switch ($random) { case 0: $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); break; case 1: $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage[] = "fo???????????????????oS"; $mirrorImage = insertPoint($mirrorImage, 'abcdetnglrrrrr'); $mirrorImageB = $mirrorImage; foreach ($mirrorImageB as &$value) { $value = str_replace("t", "u", $value); $value = str_replace("n", "m", $value); $value = str_replace("g", "h", $value); $value = str_replace("l", "k", $value); $value = str_replace("f", "s", $value); $value = str_replace("S", "f", $value); } $mirrorImage[] = "qqqqqqqqqqqqqqqqqqqqqqqqq"; $mirrorImage = array_merge($mirrorImage, $mirrorImageB); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 400; $myparams['walls'] = 999; $myparams['name'] = 'Mirror Image'; $map = GenerateShapedMap($mirrorImage, $myparams); break; } return $map; } ?> \ No newline at end of file
diff --git a/includes/maps.php b/includes/maps.php
index 5ccb033..5be674e 100644
--- a/includes/maps.php
+++ b/includes/maps.php
@@ -363,92 +363,99 @@ function GenerateMap($width, $height, $rockchance, $numBlocks = -1, $cp = -1, $t
if ($rockchance < 2) $rockchance = 2;
//== Possibility of inf loop here, if the map is too small.
- do {
- $randvalue = rand(1, ($width * $height));
- //As long as it isn't the first, or last column.
- //if ((($randvalue +1) % ($rows)) > 1) {
- //As long as it isn't in the first, 2nd, last and 2nd to last column.
- if ((($randvalue +2) % ($width)) > 3) {
- $unique[] = $randvalue;
- $unique = array_unique($unique);
- $unique = array_values($unique);
+ try {
+ $x = 0;
+ do {
+ $x++;
+ $randvalue = rand(1, ($width * $height));
+ //As long as it isn't the first, or last column.
+ //if ((($randvalue +1) % ($rows)) > 1) {
+ //As long as it isn't in the first, 2nd, last and 2nd to last column.
+ if ((($randvalue +2) % ($width)) > 3) {
+ $unique[] = $randvalue;
+ $unique = array_unique($unique);
+ $unique = array_values($unique);
+ }
+ } while (count($unique) < ($cp+$tp) AND $x < 10);
+
+ //Prepare our checkpoint and teleport names.
+ $cpnames = Array("a", "b", "c", "d", "e");
+ // in out in out etc.
+ $tpnames = Array("t", "u", "m", "n", 'g', 'h', 'i', 'j', 'k', 'l');
+
+ $teleport = Array();
+ $checkpoint = Array();
+ //Assign our checkpoints and teleports a unique position on the map.
+ $i = 0;
+ for($p = 0; $p < $cp; $p++) {
+ $checkpoint[$cpnames[$p]] = $unique[$i];
+ $i++;
+ }
+ for($p = 0; $p < $tp; $p++) {
+ $teleport[$tpnames[$p]] = $unique[$i];
+ $i++;
}
- } while (count($unique) < ($cp+$tp) );
-
- //Prepare our checkpoint and teleport names.
- $cpnames = Array("a", "b", "c", "d", "e");
- // in out in out etc.
- $tpnames = Array("t", "u", "m", "n", 'g', 'h', 'i', 'j', 'k', 'l');
-
- $teleport = Array();
- $checkpoint = Array();
- //Assign our checkpoints and teleports a unique position on the map.
- $i = 0;
- for($p = 0; $p < $cp; $p++) {
- $checkpoint[$cpnames[$p]] = $unique[$i];
- $i++;
- }
- for($p = 0; $p < $tp; $p++) {
- $teleport[$tpnames[$p]] = $unique[$i];
- $i++;
- }
- $rocks = 0; //Number of rocks in the maze.
+ $rocks = 0; //Number of rocks in the maze.
- // We need to make sure the map we construct is valid.
- // so we throw this in a do-while the map is invalid.
- do {
- $p = -1;
- //Begin loop to populate grid.
- for( $y = 1; $y <= $height; $y++) { //Number of Rows
- for( $x = 0; $x < $width; $x++) { //Number of Columns
- $p++;
- //Start and Finish squares.
- if ($x == 0) {
- //if ($x == 0 AND $y == 1) {
- //if ($x == 0 AND rand(1,3) == 1) {
- $grid[$y][$x] = "s";
- } elseif ($x == $width - 1) {
- //} elseif ($x == $rows - 1 AND $y == intval(($cols + 1) * .5) ) {
- //} elseif ($x == $rows - 1 AND rand(1,3) == 1) {
- $grid[$y][$x] = "f";
- //Randomly Placed Rocks
- } elseif (rand(1, $rockchance) == 2) {
- $grid[$y][$x] = "r";
- $rocks++;
- //TODO: rock count could be off if covered by checkpoint.
- //Just a normal square.
- } else {
- $grid[$y][$x] = "o";
- }
- //Absolutely placed points; Checkpoints.
- foreach ($checkpoint as $key => $v) {
- if ($v == $p) {
- $grid[$y][$x] = $key;
+ // We need to make sure the map we construct is valid.
+ // so we throw this in a do-while the map is invalid.
+ $x = 0;
+ do {
+ $x++;
+ $p = -1;
+ //Begin loop to populate grid.
+ for( $y = 1; $y <= $height; $y++) { //Number of Rows
+ for( $x = 0; $x < $width; $x++) { //Number of Columns
+ $p++;
+ //Start and Finish squares.
+ if ($x == 0) {
+ //if ($x == 0 AND $y == 1) {
+ //if ($x == 0 AND rand(1,3) == 1) {
+ $grid[$y][$x] = "s";
+ } elseif ($x == $width - 1) {
+ //} elseif ($x == $rows - 1 AND $y == intval(($cols + 1) * .5) ) {
+ //} elseif ($x == $rows - 1 AND rand(1,3) == 1) {
+ $grid[$y][$x] = "f";
+ //Randomly Placed Rocks
+ } elseif (rand(1, $rockchance) == 2) {
+ $grid[$y][$x] = "r";
+ $rocks++;
+ //TODO: rock count could be off if covered by checkpoint.
+ //Just a normal square.
+ } else {
+ $grid[$y][$x] = "o";
}
- } //Teleports too
- foreach ($teleport as $key => $v) {
- if ($v == $p) {
- $grid[$y][$x] = $key;
+ //Absolutely placed points; Checkpoints.
+ foreach ($checkpoint as $key => $v) {
+ if ($v == $p) {
+ $grid[$y][$x] = $key;
+ }
+ } //Teleports too
+ foreach ($teleport as $key => $v) {
+ if ($v == $p) {
+ $grid[$y][$x] = $key;
+ }
}
- }
-
- } //Rows
- } //Cols
- //Fill $grid[0] with header information
- $grid[0][0] = $width;
- $grid[0][1] = $height;
- $grid[0][2] = count($checkpoint);
- $grid[0][3] = $rocks;
- $grid[0][4] = $numBlocks;
- $grid[0][5] = count($teleport);
- $grid[0][6] = $mapName;
-
- //Validate map
- $path = routePath($grid, true);
- //Only repeat if it's blocked.
- } while ($path['blocked'] == true);
+ } //Rows
+ } //Cols
+ //Fill $grid[0] with header information
+ $grid[0][0] = $width;
+ $grid[0][1] = $height;
+ $grid[0][2] = count($checkpoint);
+ $grid[0][3] = $rocks;
+ $grid[0][4] = $numBlocks;
+ $grid[0][5] = count($teleport);
+ $grid[0][6] = $mapName;
+
+ //Validate map
+ $path = routePath($grid, true);
+ //Only repeat if it's blocked. - And if it's tried less than 200 times.
+ } while ($path['blocked'] == true AND $x < 10);
+ } catch (Exception $e) {
+ echo 'Caught exception: ', $e->getMessage(), "\n";
+ }
return $grid;
}
diff --git a/pages/mapeditor.php b/pages/mapeditor.php
index b6f4b57..ec02bb6 100644
--- a/pages/mapeditor.php
+++ b/pages/mapeditor.php
@@ -1,10 +1,13 @@
<?php
include_once('./includes/maps.php');
include_once('./includes/mapclass.php');
+include_once('./includes/mapoftheday.php');
//Self-ajax.
if ($_REQUEST['mapByCode']) {
$map = new map($_REQUEST['mapByCode']);
+ $map->oldCode = $map->getOldCode();
+ $map->code = $map->getCode();
echo json_encode($map);
exit;
}
@@ -17,24 +20,40 @@ if ($_REQUEST['mapByMap']) {
$map->$key = $value;
}
//Store the code in the object
- $code = $map->getOldCode();
- $map->code = $code;
+ $map->oldCode = $map->getOldCode();
+ $map->code = $map->getCode();
echo json_encode($map);
exit;
}
if ($_REQUEST['genMap']) {
-//function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1, $mapName = '') {
- $map = GenerateMap($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['rockChance'], $_REQUEST['wallCount'], $_REQUEST['checkpoints'] % 6, $_REQUEST['teleports'] % 6);
- //$map = GenerateMap($_REQUEST['height'], $_REQUEST['width'], $_REQUEST['rockChance'], 0, 0, 0);
- //$map = insertPoint($map, $_REQUEST['points'], 'o');
+
+ $map = GenerateMap(
+ normalizeNumber($_REQUEST['width'], 50, 6),
+ normalizeNumber($_REQUEST['height'], 50, 6),
+ normalizeNumber($_REQUEST['rockChance'], 999, 5),
+ normalizeNumber($_REQUEST['wallCount'], 9999, 0),
+ normalizeNumber($_REQUEST['checkpoints'], 5, 0),
+ normalizeNumber($_REQUEST['teleports'], 5, 0)
+ );
+
+ //$map = getRandomSpecialMap();
+
$code = GenerateMapCode($map);
+
$map = new map($code);
+ $map->oldCode = $map->getOldCode();
+ $map->code = $map->getCode();
echo json_encode($map);
exit;
}
-
+function normalizeNumber($numberToFix, $upperBound, $lowerBound) {
+ if (!is_int($numberToFix + 0)) return $lowerBound;
+ if ($numberToFix < $lowerBound) return $lowerBound;
+ if ($numberToFix > $upperBound) return $upperBound;
+ return $numberToFix;
+}
//Add's a new custom challenge map - returns mapid
@@ -221,6 +240,7 @@ function loadPlayableMap() {
playableMap.ID = -1;
$('#playableMapDisplay').html(mapAsHTML(playableMap, 960));
$('#playableMapCodeDisplay').val(playableMap.code);
+ $('#playableMapCodeDisplayOLD').val(playableMap.oldCode);
isLoadingMap = false;
}
});
@@ -322,7 +342,7 @@ function constructTiles(width, height, baseMap) {
</form>
</div>
- <form><div>
+ <form onsubmit='return false'><div>
<div class='' id='' style='float:left; width:340px;height:450px;'>
<fieldset style='width:300px'>
@@ -391,7 +411,8 @@ function constructTiles(width, height, baseMap) {
<div class="divide"><strong>Playable Map</strong></div>
<div style='clear:both;'></div>
<div class='wrapper'>
- MapCode: <input id='playableMapCodeDisplay' size="100" type="text" value="" class="forminput"/>
+ OLD MapCode: <input id='playableMapCodeDisplayOLD' size="100" type="text" value="" class="forminput"/>
+ <br/>NEW MapCode: <input id='playableMapCodeDisplay' size="100" type="text" value="" class="forminput"/>
</div>
<div id='playableMapDisplay' style='float:left;'>
Returned map goes here.