Cave generator
Moderator: Forum Moderators
Forum rules
Before reporting issues in this section, you must read the following topic:
Before reporting issues in this section, you must read the following topic:
Cave generator
Hi,
I'm trying to use transform=flip_* in the lua map generation and I'm having problems figuring out if it is doing anything.
I tried every variation transform=, both together in a single line and individually, and I'm not noticing any changes to the map.
Anyone know what's going on?
another minor observation, on line 70 of cave_map_generator.lua there is
I'm trying to use transform=flip_* in the lua map generation and I'm having problems figuring out if it is doing anything.
I tried every variation transform=, both together in a single line and individually, and I'm not noticing any changes to the map.
Code: Select all
transform=flip_x,flip_y,flip_xy
#transform=flip_x
#transform=flip_y
#transform=flip_xy
transform_chance=100
another minor observation, on line 70 of cave_map_generator.lua there is
side_num = chamber.side,
. Anyone knows what's that for?Re: Cave generator flip
The bug might be in mapgen_helper.lua
It seems when it is flipping, it doesn't stop after
Possible fix to mapgen_helper.lua is breaking after i becomes greater than j
Edit: There is another bug with the transform.
The
The castle will look funny after flip_x or flip_y. They look normal with flip_xy.
It seems when it is flipping, it doesn't stop after
i > j
So everything gets flipped again returning the map to its original layout.Possible fix to mapgen_helper.lua is breaking after i becomes greater than j
Code: Select all
if i > j then
break
end
Code: Select all
function map_mt.__index.flip_x(map)
for y = 0, map.h - 1 do
for x = 0, map.w - 1 do
local i = loc_to_index(map, x, y)
local j = loc_to_index(map, map.w - x - 1, y)
if i > j then
break
end
map[i], map[j] = map[j], map[i]
end
end
end
function map_mt.__index.flip_y(map)
for x = 0, map.w - 1 do
for y = 0, map.h - 1 do
local i = loc_to_index(map, x, y)
local j = loc_to_index(map, x, map.h - y - 1)
if i > j then
break
end
map[i], map[j] = map[j], map[i]
end
end
end
The
[item_location] id=
values don't get transformed with the flip.The castle will look funny after flip_x or flip_y. They look normal with flip_xy.
Re: Cave generator demo
I'm attaching a demo of transform flip.
Uncomment starting from line 35 to test.
The i > j fix was applied in the screenshots. Notice the location_id did not change, and the castles look funny.
No transform flip_x flip_y flip_xy
Uncomment starting from line 35 to test.
The i > j fix was applied in the screenshots. Notice the location_id did not change, and the castles look funny.
No transform flip_x flip_y flip_xy
- Attachments
-
- _main.cfg
- (2.93 KiB) Downloaded 167 times
Re: mapgen_helper.lua patch
This patch will transform flip the map and map.locations
I'm not happy with the way map.locations flipping is done, there might be more efficient ways. But it does work!
I'm not happy with the way map.locations flipping is done, there might be more efficient ways. But it does work!
Code: Select all
--- mapgen_helper.lua.bak 2020-12-17 04:33:38.702810660 +0000
+++ mapgen_helper.lua 2020-12-17 04:29:02.670806194 +0000
@@ -56,7 +56,24 @@
for x = 0, map.w - 1 do
local i = loc_to_index(map, x, y)
local j = loc_to_index(map, map.w - x - 1, y)
+ if i > j then
+ break
+ end
map[i], map[j] = map[j], map[i]
+ if map.locations then
+ local i = map.locations:get(x, y)
+ local j = map.locations:get(map.w - x - 1, y)
+ if i then
+ map.locations:remove(x, y)
+ end
+ if j then
+ map.locations:remove(map.w - x - 1, y)
+ map.locations:insert(x, y, j)
+ end
+ if i then
+ map.locations:insert(map.w - x - 1, y, i)
+ end
+ end
end
end
end
@@ -66,7 +83,24 @@
for y = 0, map.h - 1 do
local i = loc_to_index(map, x, y)
local j = loc_to_index(map, x, map.h - y - 1)
+ if i > j then
+ break
+ end
map[i], map[j] = map[j], map[i]
+ if map.locations then
+ local i = map.locations:get(x, y)
+ local j = map.locations:get(x, map.h - y - 1)
+ if i then
+ map.locations:remove(x, y)
+ end
+ if j then
+ map.locations:remove(x, map.h - y - 1)
+ map.locations:insert(x, y, j)
+ end
+ if i then
+ map.locations:insert(x, map.h - y - 1, i)
+ end
+ end
end
end
end