Skip to content

Commit

Permalink
Lua mapgen: Use helper.rand for chamber locations
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Oct 31, 2016
1 parent 6f569cd commit 7e41841
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
50 changes: 25 additions & 25 deletions data/campaigns/Heir_To_The_Throne/scenarios/17_Scepter_of_Fire.cfg
Expand Up @@ -27,7 +27,7 @@
#
[chamber]
id=player
x=15-35
x=15..35
y=65
size=8
jagged=50
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -85,26 +85,26 @@
#
[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}
{PASSAGE_NORMAL antechamber_1 2 5 2}
[/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}
{PASSAGE_NORMAL mini_1 1 5 2}
[/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}
Expand All @@ -115,17 +115,17 @@
[/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}
{PASSAGE_NORMAL mini_3 2 5 2}
[/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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand Down
20 changes: 10 additions & 10 deletions data/campaigns/Sceptre_of_Fire/scenarios/4_Gathering_Materials.cfg
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions data/lua/cave_map_generator.lua
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions 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 = {}}

Expand All @@ -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,
Expand Down

0 comments on commit 7e41841

Please sign in to comment.