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 811488eb276e4..78f14a1cba29e 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 @@ -27,7 +27,7 @@ # [chamber] id=player - x=15-35 + x=15..35 y=65 size=8 jagged=50 @@ -42,8 +42,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} @@ -54,8 +54,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} @@ -71,8 +71,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} @@ -85,8 +85,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} @@ -94,8 +94,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} @@ -103,8 +103,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} @@ -115,8 +115,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} @@ -124,8 +124,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} @@ -148,8 +148,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} @@ -162,8 +162,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} @@ -177,8 +177,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} @@ -191,8 +191,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 f65c05e2b30b6..025ba22bd0a6b 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 32113bccadf68..11b6c8193b1c2 100644 --- a/data/lua/cave_map_generator.lua +++ b/data/lua/cave_map_generator.lua @@ -42,8 +42,7 @@ function callbacks.generate_map(params) for chamber in helper.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 bb1ee0d597df5..e179046265647 100644 --- a/data/lua/mapgen_helper.lua +++ b/data/lua/mapgen_helper.lua @@ -1,4 +1,5 @@ local LS = wesnoth.require "lua/location_set.lua" +local helper = wesnoth.require "lua/helper.lua" 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, diff --git a/src/generators/lua_map_generator.cpp b/src/generators/lua_map_generator.cpp index 0ad423dfa8b77..25d6155fbade9 100644 --- a/src/generators/lua_map_generator.cpp +++ b/src/generators/lua_map_generator.cpp @@ -66,8 +66,8 @@ std::string lua_map_generator::create_map(boost::optional seed) config lua_map_generator::create_scenario(boost::optional seed) { - if (!create_scenario_.size()) { - return map_generator::create_scenario(); + if(create_scenario_.empty()) { + return map_generator::create_scenario(seed); } try {