Cave generator

Having trouble with the game? Report issues and get help here. Read this first!

Moderator: Forum Moderators

Forum rules
Before reporting issues in this section, you must read the following topic:
Post Reply
vghetto
Posts: 316
Joined: November 2nd, 2019, 5:12 pm

Cave generator

Post by vghetto »

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.

Code: Select all

transform=flip_x,flip_y,flip_xy
#transform=flip_x
#transform=flip_y
#transform=flip_xy
transform_chance=100
Anyone know what's going on?

another minor observation, on line 70 of cave_map_generator.lua there is side_num = chamber.side,. Anyone knows what's that for?
vghetto
Posts: 316
Joined: November 2nd, 2019, 5:12 pm

Re: Cave generator flip

Post by vghetto »

The bug might be in mapgen_helper.lua

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
Edit: There is another bug with the transform.
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.
vghetto
Posts: 316
Joined: November 2nd, 2019, 5:12 pm

Re: Cave generator demo

Post by vghetto »

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
no_flip.png
flip_x
flip_x.png
flip_y
flip_y.png
flip_xy
flip_xy.png
Attachments
_main.cfg
(2.93 KiB) Downloaded 24 times
vghetto
Posts: 316
Joined: November 2nd, 2019, 5:12 pm

Re: mapgen_helper.lua patch

Post by vghetto »

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!

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
Post Reply