Main menu

Post navigation

Castle Generation

At long last, castles are generating, and you will be able to visit them in this release!

So get some food and drink, relax, put your feet up, and sit back for a detailed exploration of how castles are going to generate, what you’re going to find inside them, what the player will be able to do there, how you’ll gain access, who you’ll find living there, and so on.

Firstly – castles are one of the only two districts which are barred to player entry in the current version of the game (the other being dockyard districts). I tried a few early models of castle generation in the present release but just couldn’t find something which worked relatively quickly, generated them in the detail I wanted, and ensured that they were aesthetically consistent with the rest of the nation – not to mention that I was redoing how all the ideologies work and I wasn’t quite sure how these were going to tie in (more on this below). So I decided to leave them until this release, and now that NPCs are almost “done” and the majority of the bugs created over the last few months have dealt with, I realized the time had come to implement castles.

What goes into a castle? Castles are located in cities and take up a full district in that city. As I’ve talked about before, policies/ideologies have been completely reworked to provide physical and structural changes to each nation, rather than more abstract things. Therefore, the “Zealotry” ideology has religious buildings spawn in all city districts; the “Conscription” ideology places a barracks in every town; the “Isolationist” ideology creates city walls; “Theocracy” always ensures a crypt beneath a cathedral; and so on. I’ve now extended this system to castles, meaning that the rooms you find inside each castle (aside from the standard halls, guard quarters, etc) are entirely dependent on the ideologies of that nation, and forms a kind of microcosm which reflects the city around it (and all the people in that nation, and its towns and settlements, and its citizens, and so forth).

So, a Monastic nation will have some monks resident in the castle, a Vassalage nation will have a hallway depicting the banners and armour of all its important houses and families, an Imperialist nation will have a room filled with trophies from past conquests, a nation which cares about Aesthetics will have an art gallery within the castle, one which believes in a Penitentiary justice system will have a dungeon, and so on. This therefore means that each castle can have a range of special rooms, from the smallest possible number of two (I think!) for a nation where almost none of its polices necessitate special rooms, to a grand total of sixteen rooms for a nation which happens to have chosen ideologies which necessitate something special (and everything in-between). As ever I wanted castles to reflect the aesthetic/geometric preferences of each nation (square, octagon, circle, diamond, cross) and also, of course, to actually look like a castle on the outside with walls, moats, and so forth. This leaves us with a “two part” castle system – generating the outside of the castle which is the “district” of the city, so to speak, and then generating the inside of the castle.

Here we have an example of a “castle district”. In the design of this generator I wanted to accomplish several things. Firstly it should look defended, aside from the city walls which interpenetrate each city and delimit one district from another. This means walls and/or moats depending on the particular policies of that nation. Secondly, it should fit with the rest of the nation: this obviously means the usual consistency in brick colour, but also in shape, so we see here the castle for a octagon nation (and there will be others shown elsewhere in this entry), and the moat and the walls both clearly reflect this aesthetic preference. Thirdly, of course, it needs to fill up the district – splitting cities into square districts is an acquiescence to various gameplay and technical requirements or decisions, and trying to get a singe building to fill up an entire district just wouldn’t work (cathedrals in city centres, for example, are massive, but only take up around 1/4 of the district at most). Therefore, what else do castles often have? Well, castles (and stately homes/mansions/manors more generally) often have expansive gardens, so I decided to take a leaf from the mansion generation system and add some rather snazzy gardens into the mix as well, behind the walls (these will have more detail once I redo plants in some later release). Some more of the district is then “taken up” by adding small shape-appropriate towers into the external wall of the district as well as the internal; I think this makes quite a nice visual effect, and helps the districts with smaller castles (as castles can vary in size depending on how many ideology-dependent rooms spawn within them) feel a little less empty and devoid. Ultimately it is tricky making the entire district full via a single building, and there is more variation I want to add in the future, but I think it’s working well enough for the time being (as there will also have guards on patrol and so forth to add more detail). Here’s another example for a cross nation:

We then come to handling the inside of a castle. As above, there is a significant range of possible rooms, *and* each possible room has its own layout, and these need to somehow be shoved correctly into a castle of a particular shape and size. Suffice to say, this is no easy programming task, but the game can now select from a range of preset “starting points” for castles, and then split and subdivide rooms in a number of ways, and then add in the special rooms (and the ordinarily rooms) in sensible locations, and do this for any number of shapes, sizes and permutations of important rooms. Like most of the most complex generators in the game this is a mix of PCG, handmade regions, and large databases of areas that are somewhere between the handmade and the procedural. This system took the best part of a week’s coding to complete, but now it works (I think!) for any value (within the scope of possible values). Castles always contain a great hall and guard quarters (and/or soldier quarters depending on ideologies) which are positioned in the parapets/towers surrounding the castle. All castles then contain a range of studies, dining rooms, bedrooms on their upper floors, and so forth, and then a throne room situated somewhere on the ground floor, although the precise nature and position of this throne room varies for democratic/ theocratic/ stratocratic/ monarchic nations. Alongside these are all the ideology-determined rooms, of which there are dozens. Rooms that might otherwise be similar – like quarters for monks, servants, soldiers, etc (how many ways can you make a room with a bunch of bed distinct??) – always have some variations, so they might have different floors, or different extra furniture, and so forth, so every kind of room will be distinctive. Also – you see those rooms below with just tables in? Those will soon contain books, maps, trophies of battle, tributes from weaker nations, etc, but for now,they’re just tables! So, here are two examples of what the bottom-floor interior of a castle might look like, taken from an octagonal castle and a cross castle:

Naturally, not all castles have an “open” interior section that leads back outside, it just so happened that the two I generated for this entry did! More important rooms means a larger castle and a lower chance of an open inside. Similarly, there are various things that can appear in corridors – banners showing the coats of arms of vassal houses, holy books on pedastals, placards noting arena champions, and various other things – but I haven’t quite got around to adding those in yet at time of writing (but they won’t take more than a few hours at most). Similarly, see the odd empty room? Those will be money caches soon. Also, if you see some unknown symbols… well, you’ll have to explore some castles to find out what those are! Next we also have some top floors, containing the master bedroom for the ruler (and potential space for a harem, or consorts, or multiple partners, if the civilization in question goes in for that), then various bedrooms for the various offspring of the ruler, guests, and so forth, again with a nice lot of variation for different shapes and sizes of castle – these are of course rather similar to the ornate quarters in mansions in officer quarters in military districts, but there is only so much variation one can give to a bedroom. There are also the upper floors of each tower on each side, which lead out onto the roof! I’ll get pictures of these up at a later date as I’m still finishing them off, but you’ve no doubt seen the bedrooms in URR’s mansions, for instance, so you get the basic idea. There are also various rooms that spawn underground too, and various secret rooms as well…

What about the castle’s inhabitants? Well, naturally we’ll have the ruler; we’ll have any assistants, clerks, eunuchs, partners/consorts, and so forth; potentially priests and monks if the ideologies suit it; lots of guards and soldiers, though again their number and placement vary for various reasons; servants and/or slaves; and any guests, though I’m not quite sure what guests we’ll have visiting rulers. The rulers will of course sometimes leave the castle to preside over parliament, meet foreign dignitaries, and that kind of thing, but that’s in the future. What about access? I’m not going to implement the key/permission system in this release, since most of the things that will be later required to gain access to areas aren’t implemented yet anyway! You’ll remain free to wander around the world for the time being and meet the people there and talk to them, but it won’t be too long until you’ll need the appropriate keys and permissions to gain access to the most important areas; for now, therefore, guards will let you wander.

So there we have it. Castles are now, I would say, as detailed and interesting as cathedrals, which certainly makes a lot of sense – these should be the two most impressive structures in the world (although I have an idea for some special massive buildings in the future, like rare one-off huge prisons, or asylums, or arenas, and so forth). Here’s a comparison pic of a generated castle and a generated cathedral (the two largest structures you can find) to give you a good idea of the similarities and differences. I’m immensely pleased with how these now look and I hope you like them too!

Next week I’ll probably post about the final removal of (hopefully) all remaining bugs, at which point I would hope that the game will be stable, or at least as stable as a massive release of this sort can possibly be because major wide-ranging playtesting by a community rather than an individual. Then, hopefully, I can finish off AI/pathfinding and clothing stuff before the end of the year. It remains a hugely audacious goal – I need to get all nomadic clothing and tribal clothing generated, and get every single NPC scheduling and pathfinding correctly on the “human” rather than abstract scale – but I… think it can be done before the end of December. See you all in seven days!

Wow, the castle designs look really impressive! Your pace of programming is blistering. I can’t wait to explore/wander around/loot some of these structures, & it will be interesting to see how the culture of the nation that constructed the castle affects what’s found inside.

Thanks! In fairness, I have been really grinding this past fortnight – my academic workload has been a tad lighter, my partner is away, I set myself a deadline of being able to post this entry this weekend – but I appreciate the compliment anyway! I’m still trying to think of more ways to make all buildings vary, but the insides of castles are now really interesting and really different, and I’m really chuffed with how they turned out and how the rooms reflect the dominant culture.

Sure! The corridor placement is probably the most handmade part of it; there is a little procedurality, but most of the corridor layout system draws upon a large database. Then there are many many layers which offer various rooms, various walls, various items/structures/features, various layouts, and these are interposed and combined and spawned and ignored based on both the generator per se, and the inputs (the national culture) put into the generator. I’ve spoken before about things on URR being on a scale from “lots of handmade versions with small PCG elements” (e.g. mansions or hunter-gatherer encampments) to “almost total PCG with minor handmade aspects” (e.g. cathedrals or city districts); if the former is 0, and the latter 10, castles are somewhere around…. 7 or 8? So very PCG heavy but also with some combining of huge databases of elements I made myself.

great stuff as always!
(I could literally copy paste that line to every entry on this blog, so rather be assured, that as long as I don’t file a written complaint about not being in awe, I’m in awe).
Right now I just need a reason to not continue with preparing with my presentation for tomorrow, which is partly about Hidden-Markov-Model(HMM) Speechsynthesis. So while procrastinating the hell out of my time, I was suddenly struck by the question whether you use this model to procedurally generate stuff in you world?
In (HMM)- speech synthesis a machine is taught how to properly talk by guessing (for example) which the most likely length of a particular phonem (smallest sample of distinguishable sound) is in a particular context.
Thinking about now, this mostly should lead to one correct solution, whereas procedural generation has many outcomes as correct, right? Still probably the algorithm is somehow tweak-able to fit your procedural needs better?
Well just wondering about stuff right.
Looking forward to next weekend and your reply

“char-rnn is a multi-layer Recurrent Neural Network (RNN, LSTM, and GRU) for training/sampling from character-level language models. In other words the model takes one text file as input and trains a Recurrent Neural Network that learns to predict the next character in a sequence. The RNN can then be used to generate text character by character that will look like the original training data.”

The code was released to the public earlier this year and is written in Python. I have used it for my NLP class and was amazed at how well it worked.

The model itself took quite a while to train, but once learned, it spit out dialogue in seconds.

As above – this also looks really interesting, but I don’t think I’m going to utilize it for my dialogue. I want to handmake it so that it ends up precisely how I want, and so that I know exactly how all the speech-related code base actually works (which seems really important for something that will become *such* a core component of the game). However, the system you mentioned has reminded that I want to slightly redo how language specific words (like “Quaanom”, “Qonoma”, “Nomaaqoa”, etc) are generated, since I’m not happy with how some of them generate and what you describe sounds like it might be better. Lastly – you teach NLP? How interesting! It’s definitely an area I need to look at in the next month as I move towards speech generation, though I’m not sure how much I’ll wind up taking from it. And me too! It’s going to be absurdly big…

Thanks Frido! Ha, understood – very pleased you like the recent developments! Hmm, interesting stuff, but no, the models that generate absolutely everything in the world are entirely handmade. That sounds like a fascinating system though, and I do add similar constraints and levels of acceptability and the like into URR, but those are only in systems and methods I’ve developed myself. I always prefer to code stuff myself just per se (since I know it’ll be perfectly tailored, I’ll know the ins-and-outs of how it works, etc) – I don’t rule out using other libraries/systems/etc in the future… but I don’t think it’s likely!

I’ve been silently following your blog for a while and I’ve just peeked after some months to find out that 0.8 is coming soon! I’m so excited! I wanted to ask for more information about the servants of the castle. I’m a medieval junkie and something that I think would be great is to learn how the court of the castle will work.

Hey – thanks for the message! Right now, servants just go around and clean things (i.e. stand next to things), but in the future, maybe they’ll follow people of high rank to help them out, etc? And you’re welcome! Do let me know what you think of 0.8 once it finally comes out : )