Skip to content

Commit

Permalink
WIP - Support [road_cost] in [passage]
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Apr 22, 2017
1 parent f37cf56 commit 829e700
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
56 changes: 51 additions & 5 deletions data/lua/cave_map_generator.lua
Expand Up @@ -21,7 +21,7 @@ function callbacks.generate_map(params)
end
end

local function clear_tile(x, y)
local function clear_tile(x, y, terrain_clear)
if not map:on_board(x,y) then
return
end
Expand All @@ -32,10 +32,43 @@ function callbacks.generate_map(params)
if r <= params.village_density then
map:set_tile(x, y, helper.rand(params.terrain_village))
else
map:set_tile(x, y, helper.rand(params.terrain_clear))
map:set_tile(x, y, helper.rand(terrain_clear or params.terrain_clear))
end
end

local function place_road(to_x, to_y, from_x, from_y, road_ops, terrain_clear)
if not map:on_board(to_x, to_y) then
return
end
local tile_op = road_ops[map:get_tile(to_x, to_y)]
-- These should use map:set_tile rather than clear_tile, but that doesn't work for some reason...
if tile_op then
if tile_op.convert_to_bridge and from_x and from_y then
local bridges = {}
for elem in tile_op.convert_to_bridge:gmatch("[^%s,][^,]*") do
table.insert(bridges, elem)
end
local dir = wesnoth.map_location.get_relative_dir(from_x, from_y, to_x, to_y)
if dir == 'n' or dir == 's' then
clear_tile(to_x, to_y, bridges[0])
elseif dir == 'sw' or dir == 'ne' then
clear_tile(to_x, to_y, bridges[1])
elseif dir == 'se' or dir == 'nw' then
clear_tile(to_x, to_y, bridges[2])
end
return
end
if tile_op.convert_to then
clear_tile(to_x, to_y, tile_op.convert_to)
return
end
end
if map:get_tile(to_x, to_y) == params.terrain_castle or map:get_tile(to_x, to_y) == params.terrain_keep then
return
end
clear_tile(to_x, to_y, terrain_clear)
end

local chambers = {}
local chambers_by_id = {}
local passages = {}
Expand Down Expand Up @@ -68,17 +101,25 @@ function callbacks.generate_map(params)
locs_set = locs_set,
id = id,
items = items,
data = chamber,
})
chambers_by_id[id] = chambers[#chambers]
for passage in helper.child_range(chamber, "passage") do
local dst = chambers_by_id[passage.destination]
if dst ~= nil then
local road_costs, road_ops = {}, {}
for road in helper.child_range(passage, "road_cost") do
road_costs[road.terrain] = road.cost
road_ops[road.terrain] = road
end
table.insert(passages, {
start_x = x,
start_y = y,
dest_x = dst.center_x,
dest_y = dst.center_y,
data = passage,
costs = road_costs,
roads = road_ops,
})
end
end
Expand All @@ -88,7 +129,7 @@ function callbacks.generate_map(params)
for i,v in ipairs(chambers) do
local locs_list = {}
for x, y in v.locs_set:stable_iter() do
clear_tile(x, y)
clear_tile(x, y, v.data.terrain_clear)
if map:on_inner_board(x, y) then
table.insert(locs_list, {x,y})
end
Expand Down Expand Up @@ -120,8 +161,11 @@ function callbacks.generate_map(params)
local jagged = v.data.jagged or 0
local calc = function(x, y, current_cost)
local res = 1.0
if map:get_tile(x, y) == params.terrain_wall then
local tile = map:get_tile(x, y)
if tile == params.terrain_wall then
res = laziness
else
res = v.costs[tile] or 1.0
end
if windiness > 1 then
res = res * random(windiness)
Expand All @@ -132,8 +176,10 @@ function callbacks.generate_map(params)
for i, loc in ipairs(path) do
local locs_set = LS.create()
build_chamber(loc[1], loc[2], locs_set, width, jagged)
local prev_x, prev_y
for x,y in locs_set:stable_iter() do
clear_tile(x, y)
place_road(x, y, prev_x, prev_y, v.roads, v.data.terrain_clear)
prev_x, prev_y = x, y
end
end
end
Expand Down
40 changes: 40 additions & 0 deletions data/multiplayer/scenarios/Random_Scenario_Cave.cfg
Expand Up @@ -2,6 +2,30 @@

#ifdef DEBUG

#define ROAD_COSTS
[road_cost]
terrain=Rb^Uf
cost=5
convert_to=Ur
[/road_cost]
[road_cost]
terrain=Rb^Ii
cost=1
convert_to=Ur^Ii
[/road_cost]
[road_cost]
terrain=Uue
cost=10
convert_to=Ur
[/road_cost]
[road_cost]
terrain=Wwg
cost=50
convert_to_bridge=Wwg^Bw|,Wwg^Bw/,Wwg^Bw\
convert_to=Ur
[/road_cost]
#enddef

#define PLAYER_CHAMBER NUMBER X Y
[chamber]
id=player_{NUMBER}
Expand All @@ -24,7 +48,15 @@
windiness=3
laziness=2
jagged=3
width=3
place_villages=yes
[/passage]
[passage]
destination=central_chamber
windiness=2
jagged=2
width=2
{ROAD_COSTS}
[/passage]
[/chamber]
#enddef
Expand Down Expand Up @@ -65,6 +97,14 @@
size=20
jagged=30
[/chamber]
[chamber]
id=lake
x=14..26
y=14..26
size=5
jagged=12
terrain_clear=Wwg
[/chamber]
{PLAYER_CHAMBER 1 3..10 3..10}
{PLAYER_CHAMBER 2 30..37 30..37}
{PLAYER_CHAMBER 3 3..10 30..37}
Expand Down

0 comments on commit 829e700

Please sign in to comment.