Given my design for exploration, the big technical problem here is how do I generate the world. I’ve decided on a multi-directional exploration system where the player can choose a direction, and eventually they will find things.
Simplifying the problem
The first step is to break the problem down into simpler parts. At the simplest level, the world generation is simply a list of things that need to be discovered. So, for example, we need each direction to be a list of
- Herb patch at 100m
- Clearing (for flowers) at 1km
- Swampy woods (for mushrooms) at 5km
- Plains at 15km
- Hills at 50km
Each of these values would have a random variance to it, so herb patch might be between 100 and 500m from the start.
This is relatively easy to think about; if I define my world generation in terms of a list of rules, I simply go down the list and generate each in turn. This also has the bonus that I don’t need to generate them all; I can generate up to 10km, then store that up to 10km is generated. If the player passes 10km I can generate more world, so that if the rules change (eg if the game has new features added) they don’t always have to move to an entirely new world to get a new area.
Now, my world generation isn’t quite so simple, since not every region always has every type of item
- Herb patch at 100-500m
- Clearing at 3-3.5km, 50% of the time
- Plains at 12-14km, 50% of the time
- Deep forest at 30-33km, 50% of the time if there is no Plains
- Hills at 40-45km, 50% of the time, if there are Plains
These are still pretty simple, but instead of adding the location at each point in the world, we check the condition first and only add if this is passed. With these, we now generate little worlds that are slightly different in feel, as in this example:
- Herbs, Clearing, Plains, Hills
- Herbs, Plains
- Herbs, Clearing, Deep forest
Given we have slightly different directions from the previous step, there is one obvious problem: For most of the location types, they have to be somewhere in the world. This means we need group conditions:
- Herbs at 100-500m, in all regions
- Clearing at 3-3.5km, 20% of the time, always in one region
- Swampy woods at 6-8km, 60% of the time, always in at least one region and not in all regions
- Plains at 30-33km in only one region
- Deep forest at 40-45km in only one region that doesn’t have plains
To use these, we need to always generate all of the region groups at the same time. So if we generate 10-20km north, we’d also generate east, west and south.
For each rule, now we have to apply the parts in the right order:
- Locate all the regions in the group
- Filter out all the region that can’t have the location (eg we can’t have plains and deep forest, or hills must have plains) and make a filtered list
- If necessary apply any random chances to everything on the filtered and make a new temporary list
- Check the group restrictions:
- If this is restricted to one region, choose a random region from the filtered list as the final list
- If this is restricted to at least one region, and our temporary list is empty, then use one of the random list as the final list
- If this is restricted to not all regions, and all regions are chosen, remove a random region from the temporary list and use that as the final list
- Add the new location to the regions that are in our final list
Now we have a set of regions that meet the conditions
- North: Herbs, Clearing, Swampy woods
- East: Herbs, Swampy woods, Deep forest
- South: Herbs, Clearing, Swampy woods, Deep forest
- West: Herbs, Clearing, Plains
Each location is at least on one direction, they all feel a bit different, and as the locations are added to the world generation will be far more interesting.
I’m very happy with where I am with this. I’ve got a world generation system that gives a simple linear progression, is generated as needed, is easy to understand and add to and achieves my goals of making a bit of interest to the exploration.
I still have some loose ends to tidy up here – for testing, I generate a new world and ignore the world in the saved game, but I need this feature until I have a way to reset the world (a soft reset with no benefit would be a useful option), and we don’t have one particularly important part of exploration yet, in that I can discover the locations, but they don’t unlock anything and there’s no message to say it happened, which sort of defeats the point of the story development.
It’s not too far off though, and then I’ll have a lot more of a sense of progression in the game!