Adding trees and rivers to procedural map and voronoi to tiles

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Gunroar:Cannon()
Party member
Posts: 1139
Joined: Thu Dec 10, 2020 1:57 am

Adding trees and rivers to procedural map and voronoi to tiles

Post 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?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
applebappu
Prole
Posts: 37
Joined: Thu Jun 24, 2021 5:49 pm

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

Post 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.
User avatar
Gunroar:Cannon()
Party member
Posts: 1139
Joined: Thu Dec 10, 2020 1:57 am

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

Post 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?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
applebappu
Prole
Posts: 37
Joined: Thu Jun 24, 2021 5:49 pm

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

Post by applebappu »

Sure! I recently implemented a few different "tilesets" for forests, volcanos, and caves.

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

https://github.com/applebappu/wizard-tower
User avatar
Gunroar:Cannon()
Party member
Posts: 1139
Joined: Thu Dec 10, 2020 1:57 am

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

Post by Gunroar:Cannon() »

Wow, looks neat! I like ascii and roguelikes :P Do those have rivers? :huh:
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
applebappu
Prole
Posts: 37
Joined: Thu Jun 24, 2021 5:49 pm

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

Post 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.
User avatar
Gunroar:Cannon()
Party member
Posts: 1139
Joined: Thu Dec 10, 2020 1:57 am

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

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
applebappu
Prole
Posts: 37
Joined: Thu Jun 24, 2021 5:49 pm

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

Post by applebappu »

Gotcha lol. Yeah I do sometimes accidentally get rivers, but there's nothing in the code saying "make rivers" per se.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests