Roguelike Adventure Generator (PART 2)

The previous post.

It’s time for more adventure crafting!

The first official resource I decided to add was food. I think it makes sense to start from the bottom and work my way up. These factions are just springing into existence, after all. They have to worry about the basic necessities! I don’t think you’ll find too many civilizations that decided to settle near a copper deposit instead of food and ended up being too successful.

The stock market might like copper but your tummy sure doesn’t. The production chain for food is also quite a bit simpler than metal. It’s easier to plant, grow, and eat a potato than it is to go through all the steps required to forge a set of armor.

I’m going to add just one type of food resource for each existing terrain type. That’s plains, forests, mountains, lakes, and ocean respectively. Eventually, though, there will be hundreds if not thousands of resources. The more resources there are the more unique the world will be due to factions having access to different materials. I’m also using real-world resources, such as corn or sheep, for the time being. I’ll introduce some make-believe resources later!

The first resource I’ll be adding is corn. I wanted to start with the most useful resources, but after some research, pretty much everyone disagrees on what is historically the most used old-world vegetable. It was a toss-up between grains and stuff like carrots, cabbages, and potatoes. I gave up and just choose what I personally think is the most recognizable veggie.

I set corn to spawn on generic land tiles (which I’m now referring to as plains) and the rest is history. The resource generator is seed friendly so the map will continue looking the same.

Here is what the world looks like after adding corn. It’s not very impressive, admittedly. The resources only occupy a single tile so there’s never going to be much to look at. It’s not like terrain generation where I’m causing huge sweeping changes across the entire map.

That’s actually it for resource generation! It feels odd to suddenly pivot away from resources, but I’d like to focus only on what needs doing rather than adding things for the sake of it.

The next thing I need to do is figure out how to fill the world with factions.

I eventually settled on using a BSP. That stands for binary space partition – which, like most programming related things, sounds way more complicated than it actually is. It’s just an efficient way to cram some arbitrary space with a bunch of rectangles. That’s all. It does this by taking a square and halving it. Then it takes those halves and halves them, too!

Here’s an example animation of the BSP process I painstakingly made by stitching a bunch of screenshots together. I start with a maximum rectangle size of 400 and reduce that by 10 every iteration. Eventually, a threshold is reached and it stops slicing those rectangles up.

How does this help me, though? If you saw the animation then you presumably noticed how quickly it can carve a large space into a bunch of smaller ones. I don’t have to do flood fills, distance calculations, collision detections, or any other time-consuming object placement routines. Instead, I can just take some of those rectangles and shove a faction in them

Each of these spaces is guaranteed to be separate from all the others due to how a BSP works so I can just choose one and spawn a faction at its center. Easy! It’s future-proofed, too. Even if the map size is dramatically increased it will still be just as quick.

I settled on a minimum size of 30. This means the BSP will keep trying to carve the map into pieces until its impossible to shrink any of the rectangles any further. This number results in a good number of spawn locations while also leaving enough room to see whats going on.

This is what the world looks like with the rectangles overlayed on them. Every single one of those rectangles is where a faction object will be placed. It’s not time to spawn any factions yet, though. I need to do some cleanup first to remove bad spawn positions.

I’m going to loop over each of these rectangles and compare it’s center coordinates to the terrain below it. If any of their center coordinates are ocean then I’m going to remove them.

This is what happens after I’ve discarded any rectangles whose center is ocean. I could get way more accurate by only erasing rectangles that are entirely ocean but decided not to. It would be a lot of work to implement that in a performance-friendly way. I’ll probably do that later, but since my current plan is to spawn factions at the center I don’t think it’s necessary.

Also, I’ve slightly shrunk all the rectangles. It’s easier on the eyes when they’re spaced out.

I got some spawn points up and running so now it’s time to start actually adding factions!

There we go. Each faction gets a random lightish color and is named after a random number in the 100-999 range. I wanted to give them randomly generated names but that ended up being too much work. I’ll do that later once I have some history generation to pull data from.

I made the random colors brighter, thickened the rectangle borders and gave them all a dark transparent background. It’s a bit easier to see things now! It’s not perfect but theres only so much I can do. This is just debugging info, anyway, so who cares? It’s for our eyes only.

It’s finally time to start actually simulating things – but what?

The earliest thing I can imagine any civilization doing is growing. That boils down to claiming territory and increasing their population size. I can’t think of a realistic way to simulate this, though, so we’re going to do it in a very programmey way. I’ll think of something better later!

Sure is a lot of ‘later’ going on…

I’m going to start by getting all the factions to look like proper countries. I’ll do this by using a floodfill. Lots of floodfills, actually! Each faction will simultaneously grow outwards and claim any territory they can get their greedy little hands on. They claim one pixel at a time and, at least for the time being, will be respecting one another’s borders by not taking claimed land.

Those wiggly fuzzy pixels are a rendering artifact.

That was pretty weird. It started out looking fine, but as time went on things really went off the rails! Especially in the upper right corner. This is happening because the floodfills are competing for space. The more limited the real estate becomes the more ridiculous things start to look. The factions in crowded areas ended up looking fine-ish due to relatively equal space but those near the ocean have plenty of room to thoughtlessly expand into.

Let’s move on.

I’m going to start off by making each faction’s initial expansion less perfectly square. This is happening because the floodfill is storing its expansion candidates in a list. Lists are ordered which means the order you populate them will also be the order you loop over them.

This is causing a square shape due to how the floodfill is expanding. I’m going to change to a set which isn’t ordered – which basically means the floodfill direction will be randomized.

Also, before any programmers yell at me, I know that using a set isn’t literally the same as randomization. It’s close enough to get the job done, though, and isn’t slow as snails.

That looks better. It’s starting to look like a territory map now! It’s still not perfect, though. I need to change how the floodfill detects neighboring tiles. It’s currently detecting neighbors in all eight directions. This causes the weird noisy looking mixture of territories you can see in some parts of the map. That’s happening because the floodfill is allowed to cut corners by moving diagonally. I’m going to restrict it to cardinal movement only.

Made in professional image editing program paint.
The top example (principle) is cutting corners while the below example (cardinal) is not.

Here is a crude example of diagonal versus cardinal floodfilling. That top example is exactly what’s happening to make things look so noisy. Turning off diagonal flooding will fix that.

That’s way better! The map is so much cleaner now.

The next thing I need to do is restrict the floodfill to land tiles only.

Perfecto! The map is now full of a bunch of colored blobs that look vaguely like countries.

Image from here.

This is the kind of map I’m going for, by the way, if you can’t read my mind.

Unfortunately, I’ve decided not to take this approach at all. That’s prototyping, baby! Instead of digging in and doubling down, I’m going to admit my mistake and adjust accordingly. I left in the above content because it was fun to write and was hopefully an interesting read, too.

Let me explain some of my problems with this approach before changing course.

  1. I couldn’t figure out how to fix the out of control flooding issue that you saw in the very first example. It might look fixed right now but it’s not. Limiting the floodfill to land tiles has merely reduced its chance of occurring. The possibility is still there. Lurking in the shadows.

2] The faction borders are way too wiggly. I can’t figure out how to fix this, either. I know that real-world borders can sometimes be pretty funky (wtf Ireland lol) but more often than not they’re relatively straight or otherwise make some kind of sense. Thus, I don’t mind some squiggliness – but every single border shouldn’t be so crazy. More importantly, they should look more unique. They’re not literally the same but if you’ve seen one you’ve seen them all.

3] I’ve decided to handle world generation differently. Most procedural games will simulate things before playing in a process that’s usually called history generation. The issue I have with this approach is that the end result is a stagnant world. Instead of being part of history and helping shape the world, you’re just playing in the afterglow. You get to hear about great events but not take part in them. I’m going to take a more interactive approach by letting the player get directly involved in altering the course of history. I think this is essential for an adventure generator. What kind of great adventure doesn’t end up changing the world in some way shape or form? Can you think of any that don’t? I certainly can’t.

Thus, some change is needed. This method of magically spawning a bunch of factions out of thin air isn’t interactive enough and the territory grabbing floodfill is too artificial. I’m going to switch over to a more organic simulation. I’m going to abandon the idea of pre-generation and instead go for a state where the world is in a constant state of generation.

This idea of constant generation will leave the world open for player manipulation. This idea was inspired by my goals in the Super Project, but it’ll be happening on a smaller scale.

Much like how things are always changing in our world, they will always be changing in this world, too! The first thing I need to do is change how factions are created. They need to be formed in a more natural manner. I’m going to fill the world with agents and have population centers form when enough of them share the same tile. This is to simulate how smart people claim civilization is formed – which is people coming together to make urban settlements.

This is what the world looks like when it’s covered in 10,000 agents. Each of them is placed at a random coordinate. The only placement rule is that they can’t spawn on lake or ocean.

I should simulate movement next, but I don’t think it’s needed yet. There are so many agents on the map that I bet theres a few clumps of them that I can turn into a faction!

I was right, but only marginally so. The map is so big that even with 10,000 agents scattered across its surface there’s barely any agents occupying the same tile. I had to lower the bare minimum number of agents needed per tile to 7 before any factions would pop up. This gave me a grand total of 3 factions. It’s not perfect but its a nice good start!

I’m going to go ahead and get them moving now. Every turn the agents wiggle to a random tile. The idea here is to cross my fingers and hope enough of them visit the same tile.

It’s alive! I disabled the terrain view and faction generator so they’re easier to see.

I enabled faction creation but messed up the faction coordinates. They’re only being made along the x-axis which results in that weird diagonal conga line. Things gradually slow down because hundreds of factions are being created in the same position every single turn. The factions aren’t moving, by the way. It just looks like they are because new factions that have different colors are constantly being spawned. It creates a neat moving line illusion.

Fixed it. Factions are now being created at the correct coordinates! It’s pretty neat watching all these factions pop into existence. I’m going to increase the minimum agent count to a bigger number now. This should thin the faction count down. Also, those long glitchy lines that appear are what happens when text is drawn slightly off-screen in pygame.

I raised the number first to 30 and then gradually all the way down to 10. No deal. I let the simulation run for a good while, too, but nothing happened. The luck required for that many agents to appear on the same tile for one turn must be astronomical. I’d rather not increase the number of agents but I also don’t want to lower the agent per tile threshold. What do?

I think I need to improve the agents’ movement behavior. The whole random movement thing was a good starting point but it’s too unreliable. I was going to try treating the agents like magnets and subtly attracting them to one each other’s coordinates – but that sounds like a nightmare to implement in a performance-friendly way. I’ve messed with this kind of particle physics simulation in pygame before and it’s sloooow. This simulation is going to be running every turn while the player is playing so I have to be cautious. It’s fine if typical map generation takes a few minutes but no one is going to tolerate every turn taking that long!

I’m going to take some inspiration from ants for the next step. They’re individually dumb but capable of seemingly intelligent behavior in groups. They accomplish this by reacting to a few basic senses that can result in sweeping changes. This makes it look like they’re being directed by some kind of leadership when in reality they’re just a bunch of little autonomous drones reacting to basic stimuli.

I’m going to make the agents indirectly smart by feeding them sensory input. This way I can make them do smart things without actually giving them any AI.

Or, in other words, I can process ten thousand agents every turn without lag!

I’m going to create a scent array out of noise and overlay it across the terrain. The agents, when moving, will analyze their neighboring tiles and move to whichever one has the highest scent value. This should cause them to naturally congregate towards the same areas!

Whoa! It worked surprisingly well. That blue overlay is the scent array. It looks like solid blobs of blue, but it’s actually a smooth variety of noise float values. I didn’t choose to make it blue, by the way. It’s the default color that pygame applies to surfarrays. That’s a built-in tool that can be used to rapidly draw entire arrays in one pass instead of having to slowly loop over every single pixel. Either way, it’s a colossal pain in the arse to manually recolor.

Here is a different view that I manually drew one pixel at a time using standard greyscale noise coloration. It lets you better view the gradient of noise values. I wanted some parts of the map to be more attractive than others so I applied an aggressive threshold. That’s why some parts of the noise look so sharp. This way the agents are driven towards certain areas.

This is what the non-thresholded version looks like.

Anyway, the scent approach is far from perfect. If you scroll up and watch the animation you’ll notice how the majority of agents stop moving. That’s because they reach a position where none of their neighboring tiles have a higher scent value than the one they’re on. They’ve basically found the smelliest tile and logically refuse to budge from it.

My first idea was to implement a scaling approach where agents, upon getting stuck, would begin searching further and further out for a higher value tile. However, then I realized they would need to do some form of pathfinding to reach said tile. I’d also have to use a floodfill to find it in the first place. I’m good at optimizing things, but I don’t think even I can squish 10,000 floodfills and pathfinding calculations into a single frame without causing lag…

I’m going to try some simple brute force methods before getting fancy. First, I’m going to turn movement randomization back on – but now they’ll only move if they’re stuck. I’m hoping this will shake them free and help them find a better scent trail to follow.

I expected some progress but I didn’t think it would be almost perfect! Many of the agents that were once stuck are now wiggling themselves free and hooking up with other agents. If you compare this to the previous animation you’ll see way more factions being made.

Theres still some duds, though! I think these guys are remaining stuck because theres no scent trails near them to follow. That’s why the bottom left island populates much slower – especially in the lower middle portion. They’re moving, sure, but they’re in such a wasteland that they never catch a scent to follow. It’s like wandering around in a desert for water.

I think theres also another problem happening. If you pay close attention you’ll notice some agents moving back and forth between the same two spots. They get stuck and randomly move. Then, next turn, they detect their previous position at the best option and move back to it. They’re getting stuck in a back and forth loop instead of stuck idling in one position.

Before applying any fixes, though, I’m going to change something that I think makes a lot of sense. I’m going to delete any agents that exist on the same tile when a faction is made. If a faction is made then it stands to reason that people have created a settlement – so they shouldn’t be moving around anymore!

Here is the result! If you compare it to the previous image it takes longer for factions to start appearing. There’s less faction overlapping, too. The factions were previously flashing like crazy because agents were constantly producing them at the exact same location. This was causing a graphical layering issue that resulted in all that flashing. It can’t happen anymore now, though, because once a faction is created the founding agents are killed.

Changed the color to red in adobe premiere so it’s easier to see.

Then I implemented a heatmap visualizer so I can see the longterm movement of all the agents and it verified my thoughts. It doesn’t take long before movement comes to a halt.

You can see the heatmap die as time goes on. It starts out super hot from all the movement but everything slowly putters out. I’m not sure why but something is gumming up the works.

I think that’s enough for now. It’s been a long time since I posted anything, so I’m going to go ahead and release this post early. See ya next time!

Roguelike Adventure Generator (PART 1)

I’ve been watching a lot of shows lately that involve high fantasy adventures – most of which involve some kind of power grab. They’re the kind of shows full of shady politics, tactical dealings, huge battles, and vast ambitions. I want to try and distill this into game format.

The most recent example of such a show is Game of Thrones. It has all sorts of characters going on all sorts of grand adventures. There’s dairy queen, for example, uniting a bunch of misfit armies, freeing the slaves, and taming dragons on her quest to claim the iron throne.

The best example of an epic adventure, though, is probably the Lord of the Rings. The sheer amount of stuff that Frodo gets up to on his quest to throw the one ring into Mount Doom is honestly quite ridiculous. I’d like to make a game that enables this kind of interesting quest.

Thus, long story short, I’m going to make an adventure generator!

Currently, my plan is to create a deeply simulated fantasy world. I want to fill the world with a bunch of different factions and let god sort them out.

The result should be a ton of chaos that I can exploit for procedural quest generation by using something similar to Stalkers A-Life or Bethesda’s radiant AI systems. I don’t know how these systems work, but it doesn’t matter. I’ll figure something out when needed.

I have to make the world super interactive in order to support maximum freedom of choice while also giving it enough depth that the player can get up to all sorts of zany antics.

Anyway, let’s get down to brass tacks. I’ve been pouring ungodly amounts of in-depth design analysis into my super project so for this series I’d rather focus on getting things done. I’ll go into excessive detail when it’s necessary instead of front-loading everything like I usually do.

The first thing I need to do is build the world. The game is going to focus on player-centric activities but without a world and its inhabitants, there’s no activities to be had! Thus, I need to create a basic simulation. I need to generate terrain, factions and who knows what else.

The first step is to generate noise. Lots of noise! It’s never actually that easy, though.

Let me show you what plain old noise looks like. It’s not very useful or pretty!

Here is some plain old simplex noise. The result would be largely the same even if I used perlin, wavelet or anything else. The problem is that noise is kind of worthless by itself. It needs to be treated like a worthless lump of clay and shaped into something more useful.

The brown tiles are what I’m currently using to represent land. The entire map defaults to being filled with land because I’m not applying a threshold. This means it doesn’t matter if a particular tile of noise is 0, 1, or something in-between. It considers everything land.

This is what happens if I apply a threshold of 0.2!

There are some blobs of water showing up now! This happens because increasing the threshold basically causes gaps to appear in the noise array. I’m only accepting values that are greater than the threshold – so anything below it doesn’t get carved to the map. I turn any tiles that aren’t land into water which is why more of it appears as the threshold rises.

As you can see, the higher I raise the threshold the less land there is.

You might also notice how each of the examples has a similar pattern. That’s because I’m using a seed number for the noise generator. I’m going to do that from now on for continuity purposes. This way, even a hundred posts from now, the map will still look familiar! I think it will be neat to compare an old version of the map to a fancier one a couple posts from now.

By the way, the map is actually far larger than I’ve led you to believe. The above images are only showing a small section of the world. This section is all I can fit in my 1280×720 game window! Even if I maxed out my game resolution to 1920×1080 or greater it still wouldn’t be enough to fit the whole world. The map is 200×200 which comes out to 40,000 tiles in total while each individual tile is 12×12. I’m only able to show 75 of these tiles at a time.

Let’s switch over to pixel scale. This means I basically draw every tile as an individual pixel instead of a 12×12 tile. If you take into consideration that every tile takes up 12 pixels then you can imagine the space-saving that occurs by compressing them to 1×1!

This is the result of switching over to pixel scale. I went ahead and included the rest of the map area just so you could really comprehend how much smaller things are. If you look closely you’ll notice the previous images pattern is now visible at the pixel scales center.

Anyway, since we can now see so much more it’s time to up the map size. Let’s go from 200×200 to 700×700. That brings us up to a grand total of 490,000 tiles from 40,000!

That’s better. I’m still using the same seed and threshold so due to how noise works, the previous image can be found in this images upper left corner.

Scroll up to look and then back down and you’ll see what I mean.

The next step is to make the world a little more interesting. I’m sure you’ve noticed how repetitive the noise looks. It was fine when we were zoomed in but now that we’re zoomed out a very obvious pattern has emerged. It doesn’t look like any kind of terrain I’ve ever seen! It comes off as some sort of bizarre planet covered in lakes.

This is another problem with noise. It’s very repetitive looking. This happens because the noise isn’t as random as you might think. If it was, then these images would look like static.

It’s beyond the scope of this blog to explain how and why the noise generates shapes instead of useless static, but this wiki entry about noise might help you a little bit.

Either way, static isn’t very useful in regards to terrain generation. The repetitive patterns, though, aren’t exactly ideal either. They look artificial and just plain weird.

The answer is more manipulation. I’ve found the best way to reduce this sameyness is to mix your noise with more noise. That’s what we’re going to do next. I’m going to generate some big and small noise and then evenly mix them together to see what happens.

Here is an animated version of the same images to try and better show the combination.

The end result is certainly more interesting visually but it’s still pretty samey. The only thing I really accomplished was replacing the old pattern with a new one. It’s rougher, sure, as if the world has been eroded over time, but the map still looks very repetitive from top to bottom.

It’s just less squiggly and more spikey.

To further improve this, I’m going to make both sets of noise bigger.

I’m pretty happy with this result! It also helps show off the whole noise combination thing a lot better since you can more clearly see how each set of noise influenced the final result.

This worked better because each set of noise had a bigger scale.

Previously, each set of noise was like static. Theirs shapes, sure, but they’re just a bunch of small patterns. The big noise, though, due to taking up so much space can’t repeat itself as much. This makes the end result more unique when it gets combined with other noise.

This is the map I’ll be using from now on so get used to it! The next thing I want to do is some noise maintenance. I’m going to nuke a few of those small islands from orbit.

Before and after small areas of land were turned into water.

Here is the end result. I turned any landmasses that were less than 30 tiles in total into water. The next step is basically the same thing but used on different terrain. I’m going to use my godly powers to erase any blobs of water that are too small now instead of land.

Before and after tiny bodies of water were turned into land.

I settled on a minimum water count of 50 after some trial and error. It gets rid of all the dumb puddles while retaining a few lakes and other interesting bodies of water.

What’s next? It’s time to give the world some actual terrain. Forests, mountains, deserts and other stuff like that! Believe it or not, I’m going to use more noise to accomplish this.

Here is our map with the addition of forests. It looks stupid because I need to add some new carving rules. I need to restrict the forests to only being carved over land tiles.

This is what it looks like after only letting the forests overwrite land. I also cleaned up any blobs of forest that were less than 20. I’m still using a seed for everything so if you compare this image and the previous one you’ll notice its the exact same noise distribution.

I think the forests might be too big, though, but I don’t care enough to mess with them further. I’ll probably come back to them later and fiddle with the noise values a bit more.

Let’s add some freshwater next. This doesn’t take any noise generation or anything! Instead, I’ll just be converting small bodies of landlocked water into freshwater.

This is what the map looks like with freshwater. I’m turning any water that is less than 10,000 tiles in size into it. That basically means everything but the ocean itself gets converted.

This isn’t a perfect solution. It’s possible for a landlocked blob of ocean tiles to exist that is greater than 10,000 tiles in size. This method wouldn’t detect and convert such a scenario into freshwater. That’s just how procedural generation is. There are infinite possibilities due to the nature of randomization which means theres too many edge cases to handle.

The mountains are next. These are a pain in the ass to make in a satisfying way. Originally, I wanted to create fault lines and simulate volcanic activity along them to create nice looking mountain ranges. This is the kind of appearance I was going for.

Satellite image of the Himalayan mountains. Credit: NASA.

I want nice long ridges like the above image and other curvy stringy mountain range shapes.

However, after several days of tinkering, I’ve decided to give up on that approach. I was making progress but it was slow and soon began to feel ridiculous. The terrain doesn’t really matter right now so every second spent perfecting it was largely a waste of time. I fell into that design trap of working on irrelevant things or optimizing when optimization isn’t needed.

I decided to take a less advanced approach. No geological modeling, unfortunately! Instead, I’m basically just generating a bunch of circles and then corrupting them with noise. There are too many steps involved to screenshot so I’m going to create a gif and then explain it.

Editing on wordpress is like stepping on legos.

I made the gif by just recording my screen. I built an in-game noise visualizer for debugging purposes. It’s a lot easier to figure out what you’re doing when you can see the results!

First, I create two arrays full of randomly positioned and sized circles. That’s Hills1 and Hills2 in the animation. Then, I feed these two circle arrays to a zany math function. It compares the two circle arrays and spits out a weird combination of the two. The combination seems to detect overlapping values and blends them into football-like shapes. The result is that Hills3 is now full of crescents and other vague mountain shapes instead of perfect circles. The first two hill arrays are purposely similar to one another to take advantage of this side effect.

Then I create two sets of small noise. That’s Small1 and Small 2. This noise is evenly mixed together to create Small3. The mixture is then eroded to rough it up even further. Finally, I mix Hills3 with Small3 and apply a gaussian filter to smooth things. The mountains are done!

Here is our familiar world with mountains.

Also, since this is the last dose of terrain generation for the time being, here are some other worlds. They’re made using the exact same noise settings. I just randomized the seed value.

The result isn’t perfect but it’s close enough. There’s some stringy mountain range shapes and other decently peaky looking things so I’m going to call it a wrap and move on.

Here is what the current world would look like if converted into an island if you’re curious.

This is accomplished by creating a map sized centered gradient circle and blending the landmass with it. It basically causes the land to taper off the further it gets from the center.

If you remember, I started adding terrain as a stepping stone towards supporting a basic simulation. I need a world to populate, of course, before I can do anything interesting. I’ve met that goal, so let’s move onto the next step! I’m going to start adding resources now.

I generated terrain first because resources are often tied to it. It’s possible to find ore in the middle of nowhere, for example, but it’s more likely to show up in the mountains. The same goes for wildlife resources like sheep. I guess they could be found in a swampy wasteland but they probably prefer grassy areas near fresh-water sources like natural springs or lakes.

There’s not enough biome variety to accurately simulate resource distribution yet but that’s alright. I’m not aiming for realism right now. I just wanted to build some kind of foundation to work off of instead of just throwing everything around randomly.

Why don’t I just throw it around randomly, though? I don’t literally need terrain. I could just as easily generate resources without it. The answer is that I want resources tied to terrain in preparation for faction generation. Towns, industries and entire civilizations have sprung up around useful resources. The best example I can think of is Egypt and the Nile river or the middle east and its oil. I want to say Rome and its bronze, too, but I’m not entirely sure.

Either way, I think an easy way to make factions more interesting is to give them unique access to certain resources. If one faction has access to lots of iron, for example, then they’ll be able to make some great equipment while everyone else is stuck with copper or stone. It then stands to reason that they’ll develop high-end blacksmithing as a result and potentially claim a good portion of the world due to their access to strong metals and talented smiths.

I could just randomly generate factions and give them access to random resources but then the world would have no weight to it. They would just be an intangible background element that can’t be interacted with. They’d be more like perks or upgrades than resources in this state. If iron is a real resource, though, then factions can trade, steal or even fight over it.

It has implications for the player, too, since resources are now a legitimate in-world thing.

The first iteration of this will be quite simple but should nevertheless help make the world a little more diverse at almost no cost to me complexity wise. I like the way the total war series of games handle resources. They’re just single tile objects on the map. I was originally going to generate fields of resources using noise, but have decided to go this way instead.

Medieval total war is the best total war.

I’m going to generate some resources, and then, if a faction is near said resources they’ll claim it. They’ll build a mine on diamonds, a farm on wheat or ranch on cows. This will be a real place the player can visit and people will staff. Traders will transport goods back and forth between them and whatever town the resource belongs to.

I think we’ll stop here, though. I’d like to put more thought into resources and factions before committing to anything. Come back next year when I add resources, factions and more!

Minimap goodness

I added a minimap to the game. It was originally just to help me with debugging but it’s actually pretty useful for normal game play. The minimap allows you to see the whole map at once. This lets you find errors with terrain generation, pathfinding anomalies and all sorts of general wonkiness that you might otherwise miss.

For example, here’s a minimap view of a few survivors pathfinding to random waypoints. There’s something wrong going on, though. Try to see if you can find it!

I’ve now got it specifically set to not clear each frame which causes a noticable trail affect. This allows us to see everywhere the survivors have moved instead of only where they’re currently at. Can you see the problem, now?

The little buggers are pathing through walls! That’s no good. I do plan to eventually add ghosts (to be discussed in a future monster post!) but now isn’t the time. I wasn’t aware of this issue previously, so without the minimap, who knows how long it would of taken to discover?

The source of this problem was the path map. I accidentally created it using (y, x) coordinates instead of (x, y). That means it was basically flipped or mirrored. Or, in other words, the path map did not align with the terrain map. Here is an example of what that looks like. The left example is the messed up path map.

The beings use this path map for path calculations. The terrain map is just so I know where to draw what. It otherwise has no bearing on gameplay. This is what was causing them to path through walls. They were actually doing exactly what they’re supposed to do. It was my fault for feeding them the wrong information.

Also, just for the heck of it, here’s a bunch survivors moving around while the bug is still active. This makes it far more obvious. It also makes it look like a busy subway map! The minimap is a incredibly useful tool and I strongly suggest other developers implement it for visual debugging.

Here’s the same trail affect using a corrected path map. Much better!

Let me show you some other fun stuff I shoved into the minimap! Here is a heat map. This first video is just the heat map on its own.

This is the heat map overlaid on the terrain map.

Every time a survivor moves they add a 20 to their location in the heat map. Every turn all the values in said array are reduced by 1. The more beings that visit the same tile the hotter it gets as that locations value doesn’t have enough time to fade away. This allows you to see the most active portions of your map.

The side walks near the middle of the map are obviously the most traveled areas followed by building corners. The least traveled areas are the map edges and building interiors. This remains true no matter how many times I randomize the map as shown in the video. The last example in the video was actually the worst. The buildings were so big that their weren’t many roads to use. This also caused a noticeably lag spike.

This heat map could actually help me with fine tuning the map generator. Everyone is sticking to the roads because they’re really the only path from point A to B. The buildings never connect to a neighboring building so they’re all dead ends. That’s just asking for disaster in a zombie apocalypse! Moving through buildings, across roofs and other less visible or otherwise alternate paths is a common trope in zombie media. I need to give buildings more doors, add alleyways between buildings, convert some buildings to empty plots and more to better support that. I’ll show you the results of these improvements in a later post!

The heat map could also be used for game play purposes. I could have cautious survivors avoid pathing through areas with a lot of zombie activity. I could also have zombies move towards areas with high survivor activity. Maybe animals want to avoid any activity all together! There’s a lot of potential uses.

The minimap works by drawing everything on a 1×1 pixel level instead of 12×12 ascii tiles. That allows me to see an entire level at a glance even if its pretty big. I can fit up to a 720×720 sized map on a 1280×720 screen using the minimap. That’s 518400 tiles! I can only fit a 60×60 area of the map on screen at the current 12×12 ascii font size so you can see why the minimap is handy. That’s 3600 compared to 518400 visible tiles.

If you were wondering, this is what a 720×720 minimap looks like.

It’s also stupidly fast since I’m using pygame surfarrays to just straight up blit the numpy terrain array. That means I don’t have to manually loop over every single tile and draw them. I can’t do any efficiency calculations, such as drawing only tiles that are within the camera viewport, as we’re purposely drawing the whole map. Even for the default map size, which is a moderate 200×200, that’s 40,000 tiles! I did a test to see how slow individually drawing all those would be and it knocked my frame rate down to unplayable single digit numbers.

Here is a standard minimap in its native habitat. That’s pretty hard to see, huh?

I realized that, too. I’m going to add some controls that will let the player scale the minimap by pressing the + and – keys. Later I’ll be adding a more traditional full screen style overview map that the player can zoom much closer to and also drag their view around. I’ll probably let them doodle on it, too. That way they can mark supply caches, zombies hordes or just draw dicks. Implementing this feature will make it easy to later add support for other beings having maps that the player can loot and analyze for information. Maybe you can find treasure maps, paths to hidden safehouses, directions to settlements and more. That’s all for another day, though. I need a writing break!

Foray into game development

I’ve decided to start talking about the various projects I’m both currently making or planning to eventually make. Today we’ll be talking about my zombie roguelike. I know, I know. The whole zombie thing is old hat these days. Everyone is sick of the undead. I need a simple project to get started with, though, and you can’t get much simpler than zombies!

I’m going to be giving my game a unique spin or two. This will help separate it from the competition and give it reason to live. The first attempt at doing so will be giving the player unfettered customization options. Everyone has their own opinion of what a zombie apocalypse entails so I’ll be giving players the proverbial keys to the city. This way they can setup a campaign to their exact preferences by having access to just about every variable that exists.

Want a day zero kind of situation? Then you can crank up the survivor numbers while limiting the zombies. The zombies will be highly infectious but relatively limited in number. Then spawn a good amount of military personnel to simulate them trying to maintain order. Turn up the event weights for military road blocks, patrols and special forces endeavors. Maybe throw in some scary men in hazmat suits performing field research. Increase survivor panic levels so they’re more prone to fighting one another or otherwise engaging in criminal activity like looting businesses. Then have utilities like water or power start going offline as infrastructure fails. Boom! Those tweaks alone should give a decent first contact vibe. The outbreak has just started and all hell is breaking loose. You can force the game to remain in this state or have it slowly transition to a different one over time by adjusting times. In media this initial chaos usually slides into a more typical zombie apocalypse setting after a few days to weeks.

Maybe you want a far off post apocalypse? Everyone has become used to zombies in such a setting. They’re more of a nuisance than a threat. Their numbers are much lower as many of them have simply decayed away into nothingness. Human numbers are low enough that new zombies are rarely made. The few that do exist, though, might be unusually tough or have mutated in some unique way. Gangs fight one another for territorial control of what little resources are left. Mother nature has made good progress reclaiming her land. The many abandoned cities dotting the world are now full of wildlife. It’s becoming hard to tell where the concrete jungle begins and the forest ends. The great highways of our time are lost beneath grass, vines and roots.

Their aren’t many vehicles left as they’ve all been scrapped for building material. The same goes for furniture and practically anything else that could be of use. If you want something then you need to trade for it or make it yourself. More natural predators such as wolves are a greater concern than zombies now. The power vacuum left by humanity teetering on the brink of extinction has allowed the animal populations to explode. The outbreak could of evolved, too, so perhaps now there’s undead animals roaming the wilds. Good luck with that undead black bear! There’s a few well known bastions of human life that provide some degree of stability. I imagine each of them belonging to a unique faction and having their own atmosphere. The adversity of survival would guarantee they’re all different.

I originally had paragraphs of faction examples here but I’ll save that for a future post. This one is already a miniature book. Nevertheless, I think its important to have a world full of grey zones rather than strict good or bad morals. I thus try to sprinkle it into everything I make. These settings would give your campaign a more Fallout, Metro or Stalker like vibe to it. The coolest part is that only a handful of settings would need to be changed in order to make it happen. Make zombies less common but more powerful or unique. Increase the number of factions. Enable the gang warfare system. Turn up the ruination level so buildings are damaged. Turn up the overgrowth factor so its bleeding into civilization and animals are more common. It’s really not that hard.

Or you could just shoot for a more average but perfectly acceptable range of settings. The good old survive for as long as you can in a ever worsening situation. Supplies are becoming ever rarer. Survivors are getting aggressive out of desperation. Zombies more numerable. That kind of thing. This will probably be the initial goal I’ll shoot for. Then once the basic foundation is laid I’ll begin adding customization options and expanding the scope of possibilities and supported play styles.

The biggest things I’ve learned over the years is starting simple. The things I’m talking about doing might sound hard to create but they’re really not. The difficulty comes from trying to do it all at once from the get go. Take baby steps and you’ll arrive at the desired end product naturally!

None of this is above my skill level. I’ve been making roguelikes as a hobbyist for at-least a decade now. I started right after quitting the waste of time that was college in order to independently learn how to code so I could work from home. Then I got wrapped up in caring for mentally ill family members so I’ve had nothing but time on my hands to learn. The last couple of years was almost literally nothing but making all sorts of roguelikes. I have several rather extensive roguelike libraries full of code built up because of this and have made probably around a hundred or so prototype stage games over the years. I’m probably under exaggerating on that number, too. I’m planning to go through a lot of those really old projects and write about them in the future. It will be a fun trip down embarrassingly bad code memory lane.

I just lacked the experience all those years ago to fully realize them. That’s the problem, though. I haven’t actually released anything. It’s one of the main reasons I’m starting this whole project. I need developer experience. I need to learn how to patch games, take bug reports, share the executable and all that hullabaloo. Hopefully you’ll help me get it!

I probably should of started doing this a long time ago but I was in that infinite loop of waiting until I was better. That moment of feeling ready never came, though. I don’t think any creator ever feels fully satisfied with their works. I kept noticeably improving in all sorts of ways but never felt like it was time to go public. That’s why I’ve decided to just go for it. It’s scary but I’m taking the leap!

Anyway, that’s enough for today. I’ve already spent too much time writing and not enough coding. I don’t want to be one of those budding developers that make promises and then never deliver. Come back later! I’ll either be talking about more personal behind the scenes game design stuff or sharing actual game progress.

Also, a teaser: