From df0bcc3a21a0881348de4239c867d5aa08f4bb95 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 28 Oct 2016 17:11:32 -0400 Subject: [PATCH] Lua mapgen: Use helper.rand for chamber locations --- .../scenarios/17_Scepter_of_Fire.cfg | 50 +++++++++---------- .../scenarios/4_Gathering_Materials.cfg | 20 ++++---- data/lua/cave_map_generator.lua | 3 +- data/lua/mapgen_helper.lua | 16 ++++++ 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/data/campaigns/Heir_To_The_Throne/scenarios/17_Scepter_of_Fire.cfg b/data/campaigns/Heir_To_The_Throne/scenarios/17_Scepter_of_Fire.cfg index 125bbfea8061..a4950211b99c 100644 --- a/data/campaigns/Heir_To_The_Throne/scenarios/17_Scepter_of_Fire.cfg +++ b/data/campaigns/Heir_To_The_Throne/scenarios/17_Scepter_of_Fire.cfg @@ -26,7 +26,7 @@ # [chamber] id=player - x=15-35 + x=15..35 y=65 size=8 jagged=50 @@ -41,8 +41,8 @@ # [chamber] id=antechamber_1 - x=10-25 - y=50-60 + x=10..25 + y=50..60 size=7 jagged=5 {PASSAGE_NORMAL player 2 10 10} @@ -53,8 +53,8 @@ [/chamber] [chamber] id=antechamber_2 - x=25-40 - y=50-60 + x=25..40 + y=50..60 size=7 jagged=2 {PASSAGE_NORMAL player 2 3 1} @@ -70,8 +70,8 @@ # [chamber] id=center - x=25-26 - y=35-36 + x=25..26 + y=35..36 size=2 jagged=1 {PASSAGE_NORMAL antechamber_1 1 20 3} @@ -84,8 +84,8 @@ # [chamber] id=mini_1 - x=10-16 - y=36-40 + x=10..16 + y=36..40 size=5 jagged=2 {PASSAGE_NORMAL center 1 5 2} @@ -93,8 +93,8 @@ [/chamber] [chamber] id=mini_2 - x=8-20 - y=17-26 + x=8..20 + y=17..26 size=5 jagged=3 {PASSAGE_NORMAL center 1 5 2} @@ -102,8 +102,8 @@ [/chamber] [chamber] id=mini_3 - x=6-44 - y=14-30 + x=6..44 + y=14..30 size=3 jagged=4 {PASSAGE_NORMAL center 1 5 2} @@ -114,8 +114,8 @@ [/chamber] [chamber] id=mini_4 - x=30-42 - y=17-26 + x=30..42 + y=17..26 size=5 jagged=5 {PASSAGE_NORMAL center 1 5 2} @@ -123,8 +123,8 @@ [/chamber] [chamber] id=mini_5 - x=34-40 - y=36-40 + x=34..40 + y=36..40 size=5 jagged=5 {PASSAGE_NORMAL mini_4 2 5 2} @@ -147,8 +147,8 @@ # [chamber] id=enemy_1 - x=6-15 - y=45-55 + x=6..15 + y=45..55 size=5 jagged=3 {PASSAGE_NORMAL mini_1 2 5 2} @@ -161,8 +161,8 @@ [/chamber] [chamber] id=enemy_2 - x=6-15 - y=1-35 + x=6..15 + y=1..35 size=5 jagged=3 {PASSAGE_NORMAL mini_2 2 5 2} @@ -176,8 +176,8 @@ [/chamber] [chamber] id=enemy_3 - x=35-45 - y=1-35 + x=35..45 + y=1..35 size=5 jagged=3 {PASSAGE_NORMAL mini_4 2 5 2} @@ -190,8 +190,8 @@ [/chamber] [chamber] id=enemy_4 - x=35-45 - y=45-55 + x=35..45 + y=45..55 size=5 jagged=3 {PASSAGE_NORMAL mini_5 2 5 2} diff --git a/data/campaigns/Sceptre_of_Fire/scenarios/4_Gathering_Materials.cfg b/data/campaigns/Sceptre_of_Fire/scenarios/4_Gathering_Materials.cfg index ee59c84a71d8..607ca40ff1b2 100644 --- a/data/campaigns/Sceptre_of_Fire/scenarios/4_Gathering_Materials.cfg +++ b/data/campaigns/Sceptre_of_Fire/scenarios/4_Gathering_Materials.cfg @@ -34,8 +34,8 @@ #the chamber with the player. Near the south-west corner [chamber] id=player - x=10-15 - y=32-38 + x=10..15 + y=32..38 size=7 jagged=40 [item_location] @@ -47,8 +47,8 @@ #the chamber with the coal. Somewhere in the southeast. [chamber] id=coal1 - x=28-35 - y=28-35 + x=28..35 + y=28..35 size=8 [passage] chance=70 @@ -83,8 +83,8 @@ #the northern chamber with only bad guys. Somewhere in the north-east. [chamber] id=gold - x=28-35 - y=5-12 + x=28..35 + y=5..12 size=8 jagged=50 [passage] @@ -120,8 +120,8 @@ #chamber with the second coal mine. Somewhere in the north-west. [chamber] id=coal2 - x=8-12 - y=8-12 + x=8..12 + y=8..12 size=7 [passage] chance=70 @@ -156,8 +156,8 @@ #chamber with gold in it that connects to all the others [chamber] id=connector - x=15-20 - y=15-20 + x=15..20 + y=15..20 size=4 #passages to both the troll's chamber and the player’s chamber [passage] diff --git a/data/lua/cave_map_generator.lua b/data/lua/cave_map_generator.lua index dae218f7058c..19c6da806888 100644 --- a/data/lua/cave_map_generator.lua +++ b/data/lua/cave_map_generator.lua @@ -41,8 +41,7 @@ function callbacks.generate_map(params) for chamber in wml.child_range(params, "chamber") do local chance = tonumber(chamber.chance) or 100 - local x = helper.rand(chamber.x) - local y = helper.rand(chamber.y) + local x, y = MG.random_location(chamber.x, chamber.y) local id = chamber.id if chance == 0 or random(100) > chance then -- Set chance to 0 so that the scenario generator can tell which chambers were used diff --git a/data/lua/mapgen_helper.lua b/data/lua/mapgen_helper.lua index 6d914d179474..3c2686b5c1cc 100644 --- a/data/lua/mapgen_helper.lua +++ b/data/lua/mapgen_helper.lua @@ -1,4 +1,5 @@ local LS = wesnoth.require "location_set" +local helper = wesnoth.require "helper" local mapgen_helper, map_mt = {}, {__index = {}} @@ -10,6 +11,21 @@ function mapgen_helper.create_map(width,height,default_terrain) return map end +function mapgen_helper.random_location(x_list, y_list) + local x, y + if type(x_list) == "number" then + x = x_list + elseif type(x_list) == "string" then + x = tonumber(helper.rand(x_list)) + end + if type(y_list) == "number" then + y = y_list + elseif type(y_list) == "string" then + y = tonumber(helper.rand(y_list)) + end + return x or 0, y or 0 +end + local valid_transforms = { flip_x = true, flip_y = true,