Page 1 of 1

Adding trees and rivers to procedural map and voronoi to tiles

Posted: Sat Jul 31, 2021 4:34 pm
by Gunroar:Cannon()
1)In a simplex noise map like my editor,darkfrei's mid point displacement map or voronoi algorithm how do I add rivers and trees to the map?

2)How do I make a voronoi map tile based from the polygons?

Re: Adding trees and rivers to procedural map and voronoi to tiles

Posted: Tue Aug 03, 2021 12:06 am
by applebappu
I had to deal with something similar in my own game, actually. Your implementation may vary, but basically what I did was use the initial output of the noise map to then choose tiles from a table of potential selections, and then tweaked the table and the noise function until I was getting stuff I liked.

To make certain swaths of the map be rivers or trees, for instance, you might write it so that a particular number output from the noise map puts a tree or a river tile there.

Simplex noise outputs non-integer values, so you'll probably need to use math.floor to round it down to integers, or other permutations until you get it just right. Experimentation is key.

Here's my own map generation code, for your reference and adaptation:

Code: Select all

RandomMap = function(self)
		local noise_map = {}
		local up_stairs = {
			x = math.random(2,37),
			y = math.random(2,19)
		}
		local down_stairs = {
			x = math.random(2,37),
			y = math.random(2,19)
		}
		
		for i = 1, self.board_size.x do
			noise_map[i] = {}
			self.map_table[i] = {}
			for j = 1, self.board_size.y do
				noise_map[i][j] = math.floor(10 * ( love.math.noise( i + math.random(), j + math.random() ) ) ) + 1
				self.map_table[i][j] = map_pieces.tiles[noise_map[i][j]]

				if i == 1 or j == 1 then
					self.map_table[i][j] = "#"
				end

				if i == self.board_size.x or j == self.board_size.y then
					self.map_table[i][j] = "#"
				end

				if i == up_stairs.x and j == up_stairs.y then
					self.map_table[i][j] = "<"
				end

				if i == down_stairs.x and j == down_stairs.y then
					self.map_table[i][j] = ">"
				end
			end
		end
	end
My map is somewhat simpler than a diamond square generation, as you can see. Basically I'm just taking some simplex noise, making sure I get integer values out of it, then feeding that into my map_pieces table (not pictured here, but it's just a list of string "tiles" to choose from, for drawing to the screen). Then I shove in some fixed values I know I always want, like a border around the outside and some up and down stairs, and call it a day.

Hopefully you find this helpful; I've literally never worked with voronoi anything so I won't offer up any misinformation there lol.

Re: Adding trees and rivers to procedural map and voronoi to tiles

Posted: Tue Aug 03, 2021 9:36 am
by Gunroar:Cannon()
Thanks alot for this :awesome: . Yeah, I'm not to hot on voronoi really. Can you post any screenshot to show a map in action?

Re: Adding trees and rivers to procedural map and voronoi to tiles

Posted: Tue Aug 03, 2021 6:46 pm
by applebappu
Sure! I recently implemented a few different "tilesets" for forests, volcanos, and caves.

cave:
cave.png
cave.png (12.17 KiB) Viewed 4469 times
forest:
forest.png
forest.png (17.94 KiB) Viewed 4469 times
volcano:
volcano.png
volcano.png (18.96 KiB) Viewed 4469 times
Edit: Here, go ahead and poke through my source if you like.

https://github.com/applebappu/wizard-tower

Re: Adding trees and rivers to procedural map and voronoi to tiles

Posted: Wed Aug 04, 2021 7:06 pm
by Gunroar:Cannon()
Wow, looks neat! I like ascii and roguelikes :P Do those have rivers? :huh:

Re: Adding trees and rivers to procedural map and voronoi to tiles

Posted: Wed Aug 04, 2021 7:13 pm
by applebappu
Not as such right now. There's nothing forcing water tiles to spawn next to each other. Though I think that's simple enough to make happen, with some post processing.

Like after you generate the initial noise map, you could iterate back over it smoothing it out with some probabilities. Say, if noise_map[x][y] == "water tile" then uhhhh roll dice, with a weight towards putting more water next to it. Or something.

The way I've made "forests" and such is to just put more copies of that tile into the map_pieces table lol.

EDIT: oh, did you mean like, do roguelikes in general have rivers? yeah, absolutely. Nethack and ADOM both have water features for sure.

Re: Adding trees and rivers to procedural map and voronoi to tiles

Posted: Thu Aug 05, 2021 12:01 pm
by Gunroar:Cannon()
Thnx, and haha, no, I meant rivers in yours, but it's still good to know. Also if you count dwarf fotress adventure mode as a roguelike I guess it also has rivers :P

Re: Adding trees and rivers to procedural map and voronoi to tiles

Posted: Thu Aug 05, 2021 7:18 pm
by applebappu
Gotcha lol. Yeah I do sometimes accidentally get rivers, but there's nothing in the code saying "make rivers" per se.