{"action":"created","comment":{"url":"https://api.github.com/repos/wesnoth/wesnoth/pulls/comments/85229776","pull_request_review_id":5957465,"id":85229776,"diff_hunk":"@@ -1,200 +1,184 @@\n local helper = wesnoth.require \"lua/helper.lua\"\n+local MG = wesnoth.require \"lua/mapgen_helper.lua\"\n+local LS = wesnoth.require \"lua/location_set.lua\"\n local T = helper.set_wml_tag_metatable {}\n local random = wesnoth.random\n \n-local params = _G.params\n+local callbacks = {}\n \n-local map = {}\n+function callbacks.generate_map(params)\n+\tlocal map = MG.create_map(params.map_width, params.map_height, params.terrain_wall)\n \n-local function loc_to_index(x,y)\n-\treturn x + 1 + y * params.map_width\n-end\n-\n-local function index_to_loc(index)\n-\treturn (index -1) % params.map_width, math.floor((index -1) / params.map_width)\n-end\n-\n-for i = 1, params.map_width * params.map_height do\n-\ttable.insert(map, params.terrain_wall)\n-end\n---positions are 0-based to match the ingame locations.\n-local function set_tile_index(index, val)\n-\tif index < 1 or index > params.map_width * params.map_height then\n-\t\treturn\n-\tend\n-\tif map[index] == params.terrain_castle or map[index] == params.terrain_keep then\n-\t\treturn\n+\tlocal function build_chamber(x, y, locs_set, size, jagged)\n+\t\tif locs_set:get(x,y) or not map:on_board(x, y) or size == 0 then\n+\t\t\treturn\n+\t\tend\n+\t\tlocs_set:insert(x,y)\n+\t\tfor xn, yn in MG.adjacent_tiles(x, y) do\n+\t\t\tif random(100) <= 100 - jagged then\n+\t\t\t\tbuild_chamber(xn, yn, locs_set, size - 1, jagged)\n+\t\t\tend\n+\t\tend\n \tend\n-\tif val == params.terrain_clear then\n+\n+\tlocal function clear_tile(x, y)\n+\t\tif not map:on_board(x,y) then\n+\t\t\treturn\n+\t\tend\n+\t\tif map:get_tile(x,y) == params.terrain_castle or map:get_tile(x,y) == params.terrain_keep then\n+\t\t\treturn\n+\t\tend\n \t\tlocal r = random(1000)\n \t\tif r <= params.village_density then\n-\t\t\tmap[index] = params.terrain_village\n-\t\t\telse\n-\t\t\tmap[index] = params.terrain_clear\n-\t\tend\n+\t\t\tmap:set_tile(x, y, params.terrain_village)\n \t\telse\n-\t\tmap[index] = val\n-\tend\n-end\n-\n-local function set_tile(x, y, val)\n-\tset_tile_index(loc_to_index(x, y), val)\n-end\n-\n-local function get_tile(x, y, val)\n-\treturn map[loc_to_index(x,y)]\n-end\n-\n-local function on_board(x, y)\n-\treturn x >= 0 and y >= 0 and x < params.map_width and y < params.map_height\n-end\n-\n-local function on_inner_board(x, y)\n-\treturn x >= 1 and y >= 1 and x < params.map_width - 1 and y < params.map_height -  1\n-end\n-\n-local adjacent_offset = {\n-\t{ {0,-1}, {1,-1}, {1,0}, {0,1}, {-1,0}, {-1,-1} },\n-\t{ {0,-1}, {1,0}, {1,1}, {0,1}, {-1,1}, {-1,0} }\n-}\n-local function adjacent_tiles(x, y)\n-\tlocal offset = adjacent_offset[2 - (x % 2)]\n-\tlocal i = 0\n-\treturn function()\n-\t\ti = i + 1\n-\t\tif i <= 6 then\n-\t\t\treturn offset[i][1] + x, offset[i][2] + y\n-\t\t\telse\n-\t\t\treturn nil\n+\t\t\tmap:set_tile(x, y, params.terrain_clear)\n \t\tend\n \tend\n-end\n \n-local function build_chamber(x, y, locs_set, size, jagged)\n-\tlocal index = loc_to_index(x, y)\n-\tif locs_set[index] or not on_board(x, y) or size == 0 then\n-\t\treturn\n-\tend\n-\tlocs_set[index] = {x, y}\n-\tfor xn, yn in adjacent_tiles(x, y) do\n-\t\tif random(100) <= 100 - jagged then\n-\t\t\tbuild_chamber(xn, yn, locs_set, size - 1, jagged)\n+\tlocal chambers = {}\n+\tlocal chambers_by_id = {}\n+\tlocal passages = {}\n+\n+\tfor chamber in helper.child_range(params, \"chamber\") do\n+\t\tlocal chance = tonumber(chamber.chance) or 100\n+\t\tlocal x = chamber.x\n+\t\tlocal y = chamber.y\n+\t\tlocal id = chamber.id\n+\t\tif chance == 0 or random(100) > chance then","path":"data/lua/cave_map_generator.lua","position":116,"original_position":116,"commit_id":"f50ed4b747f6a8fc1e3143951b8fe88ffc48acda","original_commit_id":"7c9f1a2968fcabe201acc25403675cc3ec69055d","user":{"login":"gfgtdf","id":4893136,"avatar_url":"https://avatars.githubusercontent.com/u/4893136?v=3","gravatar_id":"","url":"https://api.github.com/users/gfgtdf","html_url":"https://github.com/gfgtdf","followers_url":"https://api.github.com/users/gfgtdf/followers","following_url":"https://api.github.com/users/gfgtdf/following{/other_user}","gists_url":"https://api.github.com/users/gfgtdf/gists{/gist_id}","starred_url":"https://api.github.com/users/gfgtdf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfgtdf/subscriptions","organizations_url":"https://api.github.com/users/gfgtdf/orgs","repos_url":"https://api.github.com/users/gfgtdf/repos","events_url":"https://api.github.com/users/gfgtdf/events{/privacy}","received_events_url":"https://api.github.com/users/gfgtdf/received_events","type":"User","site_admin":false},"body":"hmm but you didn't add such a check for the much more common chance=100 case.","created_at":"2016-10-26T21:59:41Z","updated_at":"2016-10-26T21:59:41Z","html_url":"https://github.com/wesnoth/wesnoth/pull/845#discussion_r85229776","pull_request_url":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845","_links":{"self":{"href":"https://api.github.com/repos/wesnoth/wesnoth/pulls/comments/85229776"},"html":{"href":"https://github.com/wesnoth/wesnoth/pull/845#discussion_r85229776"},"pull_request":{"href":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845"}}},"pull_request":{"url":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845","id":91062996,"html_url":"https://github.com/wesnoth/wesnoth/pull/845","diff_url":"https://github.com/wesnoth/wesnoth/pull/845.diff","patch_url":"https://github.com/wesnoth/wesnoth/pull/845.patch","issue_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/845","number":845,"state":"open","locked":false,"title":"Improvements to the Lua cave map generator","user":{"login":"CelticMinstrel","id":578731,"avatar_url":"https://avatars.githubusercontent.com/u/578731?v=3","gravatar_id":"","url":"https://api.github.com/users/CelticMinstrel","html_url":"https://github.com/CelticMinstrel","followers_url":"https://api.github.com/users/CelticMinstrel/followers","following_url":"https://api.github.com/users/CelticMinstrel/following{/other_user}","gists_url":"https://api.github.com/users/CelticMinstrel/gists{/gist_id}","starred_url":"https://api.github.com/users/CelticMinstrel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CelticMinstrel/subscriptions","organizations_url":"https://api.github.com/users/CelticMinstrel/orgs","repos_url":"https://api.github.com/users/CelticMinstrel/repos","events_url":"https://api.github.com/users/CelticMinstrel/events{/privacy}","received_events_url":"https://api.github.com/users/CelticMinstrel/received_events","type":"User","site_admin":false},"body":"This branch contains some improvements to the Lua cave generator. I still have several things I want to add, but I'd like to get at least the first two commits into 1.13.6, which is why I've opened this PR now.","created_at":"2016-10-26T18:40:52Z","updated_at":"2016-10-26T21:59:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"858da1a9dbfc3478eb85e6a430b4309b9565085d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845/commits","review_comments_url":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845/comments","review_comment_url":"https://api.github.com/repos/wesnoth/wesnoth/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/845/comments","statuses_url":"https://api.github.com/repos/wesnoth/wesnoth/statuses/f50ed4b747f6a8fc1e3143951b8fe88ffc48acda","head":{"label":"wesnoth:lua_mapgen_stuff","ref":"lua_mapgen_stuff","sha":"f50ed4b747f6a8fc1e3143951b8fe88ffc48acda","user":{"login":"wesnoth","id":4024232,"avatar_url":"https://avatars.githubusercontent.com/u/4024232?v=3","gravatar_id":"","url":"https://api.github.com/users/wesnoth","html_url":"https://github.com/wesnoth","followers_url":"https://api.github.com/users/wesnoth/followers","following_url":"https://api.github.com/users/wesnoth/following{/other_user}","gists_url":"https://api.github.com/users/wesnoth/gists{/gist_id}","starred_url":"https://api.github.com/users/wesnoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wesnoth/subscriptions","organizations_url":"https://api.github.com/users/wesnoth/orgs","repos_url":"https://api.github.com/users/wesnoth/repos","events_url":"https://api.github.com/users/wesnoth/events{/privacy}","received_events_url":"https://api.github.com/users/wesnoth/received_events","type":"Organization","site_admin":false},"repo":{"id":9432220,"name":"wesnoth","full_name":"wesnoth/wesnoth","owner":{"login":"wesnoth","id":4024232,"avatar_url":"https://avatars.githubusercontent.com/u/4024232?v=3","gravatar_id":"","url":"https://api.github.com/users/wesnoth","html_url":"https://github.com/wesnoth","followers_url":"https://api.github.com/users/wesnoth/followers","following_url":"https://api.github.com/users/wesnoth/following{/other_user}","gists_url":"https://api.github.com/users/wesnoth/gists{/gist_id}","starred_url":"https://api.github.com/users/wesnoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wesnoth/subscriptions","organizations_url":"https://api.github.com/users/wesnoth/orgs","repos_url":"https://api.github.com/users/wesnoth/repos","events_url":"https://api.github.com/users/wesnoth/events{/privacy}","received_events_url":"https://api.github.com/users/wesnoth/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wesnoth/wesnoth","description":"Free, turn-based strategy game with a high fantasy theme, featuring both singleplayer and online/hotseat multiplayer combat.","fork":false,"url":"https://api.github.com/repos/wesnoth/wesnoth","forks_url":"https://api.github.com/repos/wesnoth/wesnoth/forks","keys_url":"https://api.github.com/repos/wesnoth/wesnoth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wesnoth/wesnoth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wesnoth/wesnoth/teams","hooks_url":"https://api.github.com/repos/wesnoth/wesnoth/hooks","issue_events_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/events{/number}","events_url":"https://api.github.com/repos/wesnoth/wesnoth/events","assignees_url":"https://api.github.com/repos/wesnoth/wesnoth/assignees{/user}","branches_url":"https://api.github.com/repos/wesnoth/wesnoth/branches{/branch}","tags_url":"https://api.github.com/repos/wesnoth/wesnoth/tags","blobs_url":"https://api.github.com/repos/wesnoth/wesnoth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wesnoth/wesnoth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wesnoth/wesnoth/git/refs{/sha}","trees_url":"https://api.github.com/repos/wesnoth/wesnoth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wesnoth/wesnoth/statuses/{sha}","languages_url":"https://api.github.com/repos/wesnoth/wesnoth/languages","stargazers_url":"https://api.github.com/repos/wesnoth/wesnoth/stargazers","contributors_url":"https://api.github.com/repos/wesnoth/wesnoth/contributors","subscribers_url":"https://api.github.com/repos/wesnoth/wesnoth/subscribers","subscription_url":"https://api.github.com/repos/wesnoth/wesnoth/subscription","commits_url":"https://api.github.com/repos/wesnoth/wesnoth/commits{/sha}","git_commits_url":"https://api.github.com/repos/wesnoth/wesnoth/git/commits{/sha}","comments_url":"https://api.github.com/repos/wesnoth/wesnoth/comments{/number}","issue_comment_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/comments{/number}","contents_url":"https://api.github.com/repos/wesnoth/wesnoth/contents/{+path}","compare_url":"https://api.github.com/repos/wesnoth/wesnoth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wesnoth/wesnoth/merges","archive_url":"https://api.github.com/repos/wesnoth/wesnoth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wesnoth/wesnoth/downloads","issues_url":"https://api.github.com/repos/wesnoth/wesnoth/issues{/number}","pulls_url":"https://api.github.com/repos/wesnoth/wesnoth/pulls{/number}","milestones_url":"https://api.github.com/repos/wesnoth/wesnoth/milestones{/number}","notifications_url":"https://api.github.com/repos/wesnoth/wesnoth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wesnoth/wesnoth/labels{/name}","releases_url":"https://api.github.com/repos/wesnoth/wesnoth/releases{/id}","deployments_url":"https://api.github.com/repos/wesnoth/wesnoth/deployments","created_at":"2013-04-14T17:13:06Z","updated_at":"2016-10-25T12:21:41Z","pushed_at":"2016-10-26T21:28:25Z","git_url":"git://github.com/wesnoth/wesnoth.git","ssh_url":"git@github.com:wesnoth/wesnoth.git","clone_url":"https://github.com/wesnoth/wesnoth.git","svn_url":"https://github.com/wesnoth/wesnoth","homepage":"http://www.wesnoth.org/","size":2558992,"stargazers_count":947,"watchers_count":947,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":317,"mirror_url":null,"open_issues_count":20,"forks":317,"open_issues":20,"watchers":947,"default_branch":"master"}},"base":{"label":"wesnoth:master","ref":"master","sha":"7950cdadd5867de5b9b8e9e671326fc37300bde0","user":{"login":"wesnoth","id":4024232,"avatar_url":"https://avatars.githubusercontent.com/u/4024232?v=3","gravatar_id":"","url":"https://api.github.com/users/wesnoth","html_url":"https://github.com/wesnoth","followers_url":"https://api.github.com/users/wesnoth/followers","following_url":"https://api.github.com/users/wesnoth/following{/other_user}","gists_url":"https://api.github.com/users/wesnoth/gists{/gist_id}","starred_url":"https://api.github.com/users/wesnoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wesnoth/subscriptions","organizations_url":"https://api.github.com/users/wesnoth/orgs","repos_url":"https://api.github.com/users/wesnoth/repos","events_url":"https://api.github.com/users/wesnoth/events{/privacy}","received_events_url":"https://api.github.com/users/wesnoth/received_events","type":"Organization","site_admin":false},"repo":{"id":9432220,"name":"wesnoth","full_name":"wesnoth/wesnoth","owner":{"login":"wesnoth","id":4024232,"avatar_url":"https://avatars.githubusercontent.com/u/4024232?v=3","gravatar_id":"","url":"https://api.github.com/users/wesnoth","html_url":"https://github.com/wesnoth","followers_url":"https://api.github.com/users/wesnoth/followers","following_url":"https://api.github.com/users/wesnoth/following{/other_user}","gists_url":"https://api.github.com/users/wesnoth/gists{/gist_id}","starred_url":"https://api.github.com/users/wesnoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wesnoth/subscriptions","organizations_url":"https://api.github.com/users/wesnoth/orgs","repos_url":"https://api.github.com/users/wesnoth/repos","events_url":"https://api.github.com/users/wesnoth/events{/privacy}","received_events_url":"https://api.github.com/users/wesnoth/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wesnoth/wesnoth","description":"Free, turn-based strategy game with a high fantasy theme, featuring both singleplayer and online/hotseat multiplayer combat.","fork":false,"url":"https://api.github.com/repos/wesnoth/wesnoth","forks_url":"https://api.github.com/repos/wesnoth/wesnoth/forks","keys_url":"https://api.github.com/repos/wesnoth/wesnoth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wesnoth/wesnoth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wesnoth/wesnoth/teams","hooks_url":"https://api.github.com/repos/wesnoth/wesnoth/hooks","issue_events_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/events{/number}","events_url":"https://api.github.com/repos/wesnoth/wesnoth/events","assignees_url":"https://api.github.com/repos/wesnoth/wesnoth/assignees{/user}","branches_url":"https://api.github.com/repos/wesnoth/wesnoth/branches{/branch}","tags_url":"https://api.github.com/repos/wesnoth/wesnoth/tags","blobs_url":"https://api.github.com/repos/wesnoth/wesnoth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wesnoth/wesnoth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wesnoth/wesnoth/git/refs{/sha}","trees_url":"https://api.github.com/repos/wesnoth/wesnoth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wesnoth/wesnoth/statuses/{sha}","languages_url":"https://api.github.com/repos/wesnoth/wesnoth/languages","stargazers_url":"https://api.github.com/repos/wesnoth/wesnoth/stargazers","contributors_url":"https://api.github.com/repos/wesnoth/wesnoth/contributors","subscribers_url":"https://api.github.com/repos/wesnoth/wesnoth/subscribers","subscription_url":"https://api.github.com/repos/wesnoth/wesnoth/subscription","commits_url":"https://api.github.com/repos/wesnoth/wesnoth/commits{/sha}","git_commits_url":"https://api.github.com/repos/wesnoth/wesnoth/git/commits{/sha}","comments_url":"https://api.github.com/repos/wesnoth/wesnoth/comments{/number}","issue_comment_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/comments{/number}","contents_url":"https://api.github.com/repos/wesnoth/wesnoth/contents/{+path}","compare_url":"https://api.github.com/repos/wesnoth/wesnoth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wesnoth/wesnoth/merges","archive_url":"https://api.github.com/repos/wesnoth/wesnoth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wesnoth/wesnoth/downloads","issues_url":"https://api.github.com/repos/wesnoth/wesnoth/issues{/number}","pulls_url":"https://api.github.com/repos/wesnoth/wesnoth/pulls{/number}","milestones_url":"https://api.github.com/repos/wesnoth/wesnoth/milestones{/number}","notifications_url":"https://api.github.com/repos/wesnoth/wesnoth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wesnoth/wesnoth/labels{/name}","releases_url":"https://api.github.com/repos/wesnoth/wesnoth/releases{/id}","deployments_url":"https://api.github.com/repos/wesnoth/wesnoth/deployments","created_at":"2013-04-14T17:13:06Z","updated_at":"2016-10-25T12:21:41Z","pushed_at":"2016-10-26T21:28:25Z","git_url":"git://github.com/wesnoth/wesnoth.git","ssh_url":"git@github.com:wesnoth/wesnoth.git","clone_url":"https://github.com/wesnoth/wesnoth.git","svn_url":"https://github.com/wesnoth/wesnoth","homepage":"http://www.wesnoth.org/","size":2558992,"stargazers_count":947,"watchers_count":947,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":317,"mirror_url":null,"open_issues_count":20,"forks":317,"open_issues":20,"watchers":947,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845"},"html":{"href":"https://github.com/wesnoth/wesnoth/pull/845"},"issue":{"href":"https://api.github.com/repos/wesnoth/wesnoth/issues/845"},"comments":{"href":"https://api.github.com/repos/wesnoth/wesnoth/issues/845/comments"},"review_comments":{"href":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845/comments"},"review_comment":{"href":"https://api.github.com/repos/wesnoth/wesnoth/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wesnoth/wesnoth/pulls/845/commits"},"statuses":{"href":"https://api.github.com/repos/wesnoth/wesnoth/statuses/f50ed4b747f6a8fc1e3143951b8fe88ffc48acda"}}}}
{"actor":{"display_login":"gfgtdf"}}