First look at City Districts

Although I planned to spend this week finishing off graveyards and beginning work on settlements, I found myself working on cities instead. For starters I’ve now got it generating city walls both on the exterior of the city, and between districts, and connecting these logically with roads and rivers outside the city (rivers inside the city may have bridges going over them). Exterior gates are now present which you can pass through to gain access to the district of the city they connect to. One this system was in place, I’ve started with generating the actual districts themselves, and decided to begin with the lower-class housing districts, partly because these were the most similar to slums so I could use some of what I’d learned there, and also because a smaller percentage of the buildings there are going to be special/unique, so it seemed the easiest start.

Below is a screenshot of the player wandering around a lower-class housing district, having just come through a gate from another district (the large white door below the player). You can see a number of connected buildings, each with a single locked door. I have to say, just walking around these city districts is incredibly exciting. Even though there are no NPCs wandering around yet and you can’t get into buildings, it feels very dense and very like you’re wandering around a game now, rather than a world where a game is being developed. As part of this I’m also carrying out a major overhaul of how saving and loading works – to prevent larger file sizes causing slower load times – and, in turn, of how doors and interiors work. The new system is almost so laughably simple I’m ashamed I didn’t create it a year or so ago, but there you go. This will allow interiors to be made and handled on the fly, so that these interiors don’t have to be made until you actually need them, and will create a far superior database structure for the future. It’s not exciting work, but this kind of optimizing I try to do each release goes a long way to preparing the game for the future. If I still had the data structure now I had two years ago the game would have slowed to a halt, and this big change is another step along that same path. Anyway, here’s the district as seen in-game…

TerrainTest

… and here is a debug screenshot of how the map looked after I’d explored roughly a quarter of this one district (click to view full, I think it is worth it):

145x90_Ex

I’m still working on the exact mechanics for moving between districts, but as mentioned in previous entries each district will be distinct. Some might spread over two or even three map grids, in which case you can move between them without going through a gate, but otherwise you need to find yourself a gate (on the edges in each grid) and pass through them. In later versions some may be guarded, or locked under certain conditions, and I hope to have the regions of the city you have access to partially determined by your relationship with different factions in that city.

The next picture shows a quick floodfill on all the tiles of the map that are not wall or buildings. As you can see we get some central alleys where the main roads are, and then a fairly complex web of pathways outside from them. Do note there is a difference here from the slums I showed a few weeks ago – the paths here are straighter and longer, and rather more regular, whilst the buildings are generally a little larger and there are generally two tiles of gap between buildings rather than just one. Also the map below does not show any special buildings that may spawn in lower-class housing districts – such as black markets, prisons, slave quarters (if the civilization is a slaving one), asylums, and other goodness. I’ve been composing quite a list of special buildings for each district that can integrate well into the dense world lore the game generates (and that serves as your basis for exploration and sidequests), and these are some examples of the special buildings that will appear in these districts.

RoadmapNext week… I have no idea. Probably more city districts, though it’s not impossible I’ll be doing some work on settlements or finishing off graveyards instead by then (the system for connecting graves to histories is working, but needs tweaking to ensure all histories are “caught” by the system). Equally, I might be doing a lot of under-the-hood work this week to implement that new saving/loading system, which is one of those coding tasks that should be relatively simple but will probably take a fair bit of time to complete. Or something else! I’m reaching the point in the release where the number of aspects I have ongoing are spiraling outwards, which will be the case for the next month or so before I start to bring all the strands back in. See you next week!

 

Graveyards

This week I’ve made a lot of headway on generating graveyards and have started to generate the graves as well. Graveyards generally have one main entrance (this can sometimes be two, with the other on a different side of the graveyard) then a selection of interconnected areas. As with everything in the game, this is a completely new form of generation that isn’t used again in any other kind of settlement or area – I wanted to give it a feeling that the graveyard had been built up over the time, and that different areas placed graves in different patterns in various eras (note the various patterns for grave placement), whilst farms/towns and everything else have their own algorithms behind them. In a way, I suppose I want to almost “hide” the fact the game is procedurally generated – I want each area to look sufficiently unique that one can be fooled into thinking a region was hand-made. I also have begun to fully implement the generation of architectural styles (brick styles, colours, etc) for each civilization, so the colour of bricks seen here will be unique to this civilization. The road does not yet connect properly with the graveyard, but that is being worked on, whilst the tiny closed-off section of grave in the top-left corner will be removed during generation once I’m finished. Anyway, graveyard:

TerrainTest

As for the graves, there are twelve different headstone styles, twenty different “base” styles, thirty different patterns (the little flourishes on the grave, like spirals or diamonds or whatever), and each headstone style may be undamaged, slightly damaged, or heavily damaged. A zoomed-out picture of all the headstone variations is shown before, but once you include the number of possible patterns and bases, there are over 20000 possible graves, more than enough to service any playthrough. I’ll soon be adding a little bit of moss and general overgrowth at the base for the older graves.

Graves

The graves note three things – the years the person lived to and from (the date of birth may not be known, and older graves are more likely to be damaged), their name, and – if appropriate – what they died of (so naturally with these three aspects, the permutations are almost infinite). Obviously things like “He died of a horrifying wasting illness” would never be mentioned, but things that most would think merit commemoration, like falling in battle, or a duel, or whatever, might be mentioned, along with graves relating to important historical events like disasters. Thus, importantly – and rather nicely I think - these now link up to the histories! If you see a civilization fought in a particular war, you can check out the graveyard by their capital (and likely the minor graveyards in towns) and, indeed, find people to died in that war within the years that war was fought. Ditto for diseases, civil wars, whatever. I’m still working on thinking about tombs, catacombs, ossuaries and the like for wealthier people, rulers, etc. There is a good chance that graveyards which have catacombs below (which may not be all of them) might connect to the subterranean regions of the game (in the future), but these are still early plans right now.

Equally, as with all the history stuff, this will later have gameplay repercussions – maybe you hear somewhere of something buried in a particular grave, or in a particular tomb or ossuary? Or possibly that a particular set of graves are in a particular pattern that has some deeper meaning? As with other things like this relating to the in-game histories, you’ll always be making a choice: do I have the time to explore this little side-aspect whilst you’re passing through a city, or do you need to continue? The overall global clock (which I know I haven’t said anything about yet in detail) will give you time for some side exploration as these explorations of the world will be key to building up your character, but it’ll be up to you to decide which you can/cannot risk.Graveyards as a whole will also serve other functions. Maybe particular cults, religions, smugglers or other individuals might meet there? Perhaps there is treasure to be grabbed from any remaining tombs?

So there you have it. Next week’s blog entry could be at pretty much any time since between the 8th and 12th I’m in Berlin for the International Roguelike Developers Conference! Thus, the next update will either be whilst I’m in Berlin, some time a bit before, some time a bit after, or SOMETHING ELSE. It will likely be on slums and the early graphical generation of keys, and possibly something about the system of keys/doors/civilians I’ve been thinking about for a little while now. See you all next week (at some point)!

City Districts

This week I’ve been working on two major things – religions and cities. I haven’t totally finished off religions yet so I’m going to leave those for next week’s update, and focus now instead on cities. For a couple of weeks cities have been generating names based on how their civilization likes to name cities (there’s a huge variety of possibilities in this regard – not all city names are just “X+Y” “Winterhome”, “Axehearth” style) but the cities have only appeared on the world map as outlines, produced by the city’s reasonably-organic growth after several centuries of simulated time.

Cities

Although generating the interiors of cities for the player to work around are going to happen in the release after the one I’m working on now (currently 0.5, city interiors will see the light of day in 0.6), I decided to work on generating the rough outline of those interiors so that I could begin to fill up the “Cities” section of the in-game encyclopedia with some meaningful information. Thus, cities are split into districts. I’ve done this for several reasons. Firstly it will aid the player in knowing approximately where in the city they want to go for a particular objective by splitting the city into distinct parts; secondly it is arguably more realistic when one considers the kinds of layout post-medieval cities had; thirdly it allows for various mechanics involving the player either being allowed into certain districts, or being able to sneak/fight your way in, rather than having the city as a single huge map; and, fourthly, it allows for some rather aesthetically pleasing city maps. There are currently a range of districts planned. Here’s an incomplete list of what will generate in each district:

Docks: Ships. (Blue ‘D’)
Market: All types of item shop. (Yellow ‘$’)
Recreational: Arenas, pubs, gambling. (Purple ‘R’)
Upper Class Housing: Noble houses. (White ’1′)
Middle Class Housing: Guilds? (Light Grey ’2′)
Lower Class Housing: Jails, keysmiths. (Grey ’3′)
Medical: Gardens, Apothecaries, Hospitals, Fountains, physicians. (Green ‘+’)
Military: Barracks, weapon/armour traders, smiths. (Red ‘[‘)
City Centre: Cathedrals (and equivalents), libraries, government, universities, courts, mints, etc. (Blue Diamond)
Castle: Dungeons, ruler (if Monarchy/Stratocracy), weapons/armour, treasury. (Grey ‘#’)
Religious: Many religious temples, smaller altars, etc. (Lilac ‘^’)

Once I’d settled on this, I needed to get the game generating the districts in sensible layouts. This took a bit of working out because there were a range of variables. Firstly there were some districts cities had to have – such as city centres, and castles, and so forth. Secondly I had to order additional districts, like military or medical districts, in an appropriate order and probability weighting to get them appearing at the kind of frequency I want; thirdly, and most trickily, I needed to make sure districts that could sometimes be viable – such as docks if near a cost, military districts if the civ isn’t pacifist, and religious districts if the civ allows freedom or religion – generated in the right cities, knew which districts they were “more important than”, and generally were integrated into the lists of the generic districts well. Once this was done, I then worked on getting the cities to show in a zoomed-in map the player will be able to view both in the encyclopedia, and when moving between districts. I’m very happy with how these have come out:

Districts

Castles and city centres are *generally* close to the middle of the city, but you can get significant variation if the city has grown in a strange shape, existed near a coast where it couldn’t necessarily spread out a lot, or simply if the 1/9 chance (I think) for a castle or city centre to not be at the geographical centre of the city comes to pass. I’m still deciding what other information the encyclopedia should display for cities, but this will be one key part. In later versions city districts will be unknown until the player either explores them for the first time or learns information about that district from some other source, but for now I’ve just got it showing all the districts. Next week I’ll be talking about religions, their icons/symbols, how they generate, what benefits/disadvantages they give you, and what agendas religions may want their followers to pursue.

Cities, Roads and Towns

I’ve been working on adding cities, roads and towns to the world map. They’re generated in that order – each feudal civilization is given a capital city, and then everything goes from there. Cities start off as a small 2×2 structure. As time goes by, cities can expand in any direction, up to a maximum of a 5×5 size. A city reaching that full size is very rare – most cities don’t end up being twenty-five tiles in size and generally end up between fifteen and twenty. I tried a lot of different character sets for depicting cities, but in general I ended up showing them in the way displayed below. In the future each tile will be a distinct district, such as “administrative”, “market”, “military”, “medical” and so forth, but those aspects are still in the planning stages. The bigger the city, therefore, the more districts and the more services. Some district types might be particularly rare compared to others.

Meanwhile, once the cities have been placed on the map the game then adds a series of roads. I expected this to be quite simple, but as it turned out making a network of roads which wasn’t too dense, wasn’t too sparse, looked organic and found their own way around the map in an intelligent way was surprisingly tricky. Firstly, I didn’t want diagonal roads. Roads had to move orthogonally – the logic behind this was simply that I couldn’t find any ANSI/extended character that could accurately depict the shift from horizontal or vertical roads to diagonal ones. So, that meant that the pathfinding algorithm had to work only by moving in orthogonal directions. However, this was not without problem. For those who know how A* works, if you disable any diagonal directions it will still basically split the path into “diagonal” bits – even if those are just done by going up-left-up-left-up-left, rather than diagonally – and then long stretches of horizontal or vertical bits. What this meant was that any time roads were trying to path to a distant point, all the roads would line up (as we see below) and funnel themselves towards their target. Needless to say, this looks like crap.

Situation1

My initial solution was to try having the path sometimes divert from the optimal route. Say, each four “steps” there is a possibility for the path to divert one tile in a direction perpendicular to the route of travel. However, having tried this, it rapidly produced its own set of problems. What if the road decides to divert at a crucial point, and then cannot actually rejoin the initial route? Say, if it diverts on the tile before a coastline, and then cannot path back to where it needs to be, what would happen to that road? The solution to this would be to have the game check every time it wants to divert and make sure it can safely get back onto the right route, but then you’d just have roads which basically bounced up and down on a straight line, which – having tested it – also looked like crap. In the end the solution was pretty obvious, but I think reasonably elegant and simple. Once the world map is created, the game goes through the map and picks a certain selection of tiles – very few, and in a regular (though hard to spot if you don’t know it) pattern – that prevents any horizontal or vertical line from continuing for more than nine tiles at the max. A trivial solution, and once it tried to pathfind on this new, hidden map – also excluding mountains and deserts, which will in the future have their own methods of travelling across – you get something like this. The routes are still fairly optimal, but look organic and realistic:

Sit4

Situation2

Situ3

Once the road system is added to the map, the game then starts to work on placing towns. Whilst roads are being placed the game makes a note of each road – once they’re done, it then goes through each road in turn and measures how long it is. The longer it is, the more towns will be placed. In general each road will only have a single town, but roads above 50 or 60 tiles have a good shot of generating with two towns. This is obviously subject to change – I have on idea yet whether this will be too many towns, too few, or roughly enough. I should add towns and roads will not generate on the human scale for the next release; they will only be shown on the world map for now. However, if you check the development plan, 0.6 will see some of these areas actually starting to generate for you to walk around. As for mountains and deserts, the current intention is for “mountain passes” to generate which require navigation in a special way (still working on the specifics) whilst deserts have no roads or obvious means of travel. I currently plan for the player to be able to either navigate across them on their own – whilst taking the risk of running into a travelling nomadic civilization – or to make contact with a nomadic caravan who may take you safely across the desert. Again, this is for now squarely in the “future mechanics” category, but those are my initial thoughts. I’m also currently working on having the game add in other appropriate settlements (e.g. towns which aren’t on main roads, mines atop resources, farms, etc) and connecting them intelligently to the main road system, and we’ll have some more 0.5 world maps in a few weeks. Next time I’ll talk about generating the names for cities for all types of civilizations (hunter-gatherer settlements, feudal cities and nomadic encampments have very different names) and for the various religions the game is generating.

Efficient Map Generation & RPS Postmortem

For those who didn’t notice my incessant spamming of this link on every media outlet possibly available to me, I was interviewed for Rock Paper Shotgun earlier this week, and the interview can be found here: http://www.rockpapershotgun.com/2013/10/18/interview-ultima-ratio-regum-a-generated-4x-roguelike/. The response has been insane, and has made me very glad that I chose a higher hosting package for this site than I initially expected to need. Several gigabytes of downloads have taken place in the last week and the game is still flying off the shelves (metaphorically speaking) as I type this. Thanks to all the new people who’ve found the site, downloaded the game, followed on Facebook, Twitter or Twitch - I hope you like what you’ve seen, and that the development plan and the future objectives for the game sound like something you’d like to be a part of. I make a point of replying to every single comment, email or tweet I get, so if you have any comments, observations, criticisms or whatever else, do please send them my way. I’m well over 50% of the way through developing version 0.4 (see the development plan for more info), and it will be released before the end of the year.

And on that note, this fortnight’s update is a relatively short one, though a lot of work has been done. I’ve now enabled the ability to export the map grid you’re currently on into a .png file (much like you can currently export the various world map overlays by pressing ‘X’). More importantly, I’ve been redoing all the terrain generation, and have reduced the loading and saving times on all map grids by between 50% and 90%, depending on what’s on the map grid. Grids with buildings and interiors naturally take slightly longer to generate than other areas, but the reduction is very significant. All of those who say the game takes too long to load some segments (you are undoubtedly correct) can hopefully, now, rest easy that they won’t be waiting through the same kinds of load times. I’m also changing how the game stores data so that the save files will be less colossal; this is an ongoing process, but the save files for 0.4 will certainly be smaller than their titanic 0.3 brethren. The remaking of the terrain generation algorithm is perhaps 90% completed now, and one thing I’ve been doing is also adding more detail to the ziggurat regions. I felt they were looking a little sparse, so it seemed appropriate to do something to improve them a tad:

ZigB

And a gif of these structures at dawn, day, dusk and night (note also the changing shading on the trees):

Ziggif

For the time being these extra structures are just decoration, but in the future they too will be fully explorable, and each ziggurat region on the world map will have a lot more content in it than it currently does. In line with some feedback I’ve got, I’ve decided that there are only going to be three ziggurat locations on the map – each one will contain a single large ziggurat that will contain a key fragment, and the other ziggurats will contain a number of other things in them. I’d like each map grid you end up exploring to be a significant thing, so each grid area (like the one above) is going to contain a far larger amount of content. I’m now switching back to finishing off throwing and projectiles once and for all – perhaps only a day’s work remains there – then I’ll be moving onto handling the health system. Next week we’ll have a summary of all the other developments over the last month and then follow that up with the start of health and injuries.