Wednesday, February 22, 2006

Generating Random Rivers

Rivers are now in my world generation.
At first I was trying to do all the fancy "rivers move around according to terrain" stuff - but my terrain height isn't generated in a standard "Earth" manner so it didn't work out well.

The current algorithm for generating a river is:

Get a continent for each river (if we want more rivers than there are continents then -> tough :D)
Get the highest point of each continent (randomly choose if there's more than one)
For each river assign a random high point as the source. (so yes there could be more than one river per continent.)
Choose a heading. (east, south, north, west - for example)
Advance towards that heading going forwards or up, or down, until the sea is reached.


Forwards

- -> --

Up
-
- -> -

Down

- -> -
-



It works quite well. Now I'm cleaning the generator class up, as it is this massive fat thing. I'm using the strategy pattern to cut the generator methods out. That way I can make a factory and load the planet up with various generators. The planet will then be made by running the generators it has. (A tiny bit more complicated than that - as some generators require other ones to have been run first and so on)

So the class still needs cleaning and then I have city placement to figure out. I'll try and give each warlord an equal a starting position. But I'm not sure how close I'll get. I have a rough city placing heurisitic worked out but only a few lines of code so far.

Also I need to update the reading list. I've polished off Code Complete and Twisty Little Passages. Next update I'll write a little about what I thought of them.

No comments: