1
DF Modding / AutoFort
« on: June 26, 2020, 02:35:50 pm »
Moving this here from General Discussion
Automatic Fort Generation
I am maximally lazy; as I perform a repetitive task I think of ways to automate it, and this has been the case when making fortresses. I don't want to do this for my own fortresses, because I am the program that bests makes new exciting forts, but it feels like there is a general enough structure to what I do, regardless of the goal of my fort, that I could abstract it into a program, and that program could then generate groovy NPC fortresses that evolve with the world.
First off, I'm virtually certain someone else must have posted about this, but being new here and not knowing the exact lingo, my search-fu is lacking. If someone can point me towards a thread, I'd be greatful. Other than that, I intend to just put some thoughts down here; I like thinking about creative problems, and I'm sure having more opinions on it would only make the end result better.
Automatic Fort Generation: A Problem Statement
So, in essence, what do we want from an automatically generated fort?
When the fortress generation starts there will be initial conditions guiding its evolution based the motivations of the settlers (nomads, expanding the borders of a nearby settlement, an advance outpost for an invasion, a remote new settlement far from the homeland, a mining colony, etc).
The race influences the fortress structure (eg. dwarves are more likely to make underground fortresses, humans are more likely to channel out pits for stone and build buildings, but if the area doesn't allow it, anything is possible to survive). In the long run the fortress should evolve to suit the races preference*.
Relics of the fortresses evolution in this case refers to things like gradually replacing materials that become available over time, or having the goal of the settlement evolve, like an advance outpost that becomes a keep surrounded by farms after a war, or a small villiage that gradually grows to a city over a long period of time. Each of those scenarios would leave footprints depending of the nature of the changes at each step (like having wooden inner walls that used to be outer walls).
The goal here is then to find a framework to encapsulate all of this so a small working version can be written that, although intiially limited, could grow to accomodate all of these variables. To satisfy the requirement of "looking designed" will require some way to creatively mutate the base structure. Ideally if I could encapsulate this in a configureable way, so that I only leave a minimum of fingerprints on the fortress generator, then some kind of community sourcing action could generate parameter sets to finetune certain aspects of the final forts.
While I have a lot of pretty cool ideas for for this could generalise to other races and terrains, as a very bare minimum, the least this thing would have to do is create a fortress, for dwarves, underground.
A Simple Model For Fortress Evolution
For this to work properly, I can't just generate a fortress, I have to show my work. A good starting point is the same as Dwarf Fortress itself, the embark. I would need to know how many dwarves are coming, why they are coming and what they are bringing. A site may be built by royal decree, in which case the king could send a hundred laborours with several caravans of prepared materials and it would just pop into existence; or seven rugged, wild spirited dwarves could march into the mountain with two axes, two picks and a bag of seeds.
The motivation of the group and the materials they have will affect what happens when they reach the area to build their fortress, but this area will also affect what they can do**.
Ceremaic and clay industries can only exist if there is clay and sand.
Terrain that has large wobbles all over is not suitable for big surface structures (or rather, would be preferentially selected against in that environment, unless there was a motivation otherwise).
Realistically the first phase should involve shelter. Dwarves can either gather materials to build a building, or dig down/into the side of a mountain for shelter, leaving the food and wagon outside for too long isn't a good option. This is not necessarily housing yet, just somewhere to exist that isn't ouside and exposed - a meeting place, indoors. The cave is underground, safe, and eminently useful to your stone industry; but a lot of my forts have had some kind of keep-like structure, and it normally evolves from a little hut I built to protect my caravan.
Once there is somewhere to exist that isn't outside, the next priority is food. There are limited options on what to do here depending on the environment and the items you embarked with, but ignoring the complexity of what you brought along, in general you can get food by hunting, foraging, farming, owning animals and fishing. Owning animals yields continuous food in the form of milk and eggs, and discrete amounts of food in the form of meat, that if properly managed, doesn't reduce your flock size. Bees are counted as animals in that list, but cannot be eaten (yet?).
The food industries chosen by the group will related to what's most readily available in the area; but will also be affected by the motivation for creating the fort. You can't have 20 herbalists and fishermen roaming the country side when you're an advance outpost for an invasion; in such a case you either need a secure food supply behind your walls, or a reliable trade route to get supplies to sustain your war effort***. The size of this industry would be also affected by the groups motivation (plans for a big city needs plans for a lot of food, initial farm area might be small, but space is left for expansion because the city is planned to be large, a city that was planned small but grew large would bare the scars of inadequate spacing, and might necessitate creating a "second fortress" somewhere else that can accommodate the increased numbers comfortably).
Alcohol is a vital offshoot of the food industry, and all dwarven fortresses need a supply. All dwarven fortresses should employ a progressive strategy for acquiring alcohol.
Depending on the chosen food industry, dwarves may have the means to create alcohol.
From this point on though, things become less clearly defined, and depend more and more on the motivations of the group. City builders may want to focus on getting their stone-industry up and running, which may have gotten a kickstart from the initial digging of a cave. A dedicated mining operation might treat the initial fort as a starting point for going down to the magma, require shafts to dump ore down and a minecart system to transport it up. A military fort close to enemy lines might want to prioritise defences.
In summary, up to this point most fortresses would follow a similar path, but at this point they diverge. The problem involves capturing the trajectory of that transformation in a way that allows you to not only quickly and easily encode scenarios like the ones I've been dreaming up into the fortress builders "plan", but does so in a general enough way to be able to grow with the game. It may be possible that the embark is a single wizard, and he casts 50-level slade tower in the middle of the map, or that in the future you could embark with vampires only, and not need food, shelter or beds.
So, at the moment the model we are working with for the fort generator is looking something like this:
The first version of this model was and could only be made from my experiences designing a fortress, but at this stage is still sufficiently vague to not constrain the end result much. Essentially, a fortress has a reason for being built, there are stages to its construction, and events affect how it grows. Mention was made of above and below ground structures, but nothing has been said about the sizes of areas, the spacing, the choices of materials, the relative layout of rooms, or other important factors, such as how the fortress survives economically¶ and whether they have requirements on who can migrate there (no children on the front lines...). These are important questions, and while it's very important to consider them so they are able to fit into the final generator, they are outside the scope of an initial implementation.
Some additional random thoughts on this topic: The population of a city affects the speed at which it is constructed. Food sources have a "rate" attached to them, and once the rate of consumption approaches the rate of generation, a need to expand the food industry is created. For simplicty this is checked on a yearly basis to accomodate the average # of animals roaming the country side, the average plant growth in the area, average fish available, etc. Food industries expand horizontally at first, if motivations allow it, and then vertically to increase capacity.
So, now that a basic model is in place, and we have a feel for the lay of the land, it's time to consider...
The Minimum Viable Fortress Generator
If someone came up to me and said, "Hey dude, I have an automatic fortress generator for Dwarf Fortress", what is the absolute least I would expect, given the title was technically accurate? I would imagine it would be something that spits out QuickFort blueprints; that doesn't care about what the map looks like, but tells you how to build. I would expect it to be either configurable or randomisable, else it's just a single blueprint, and I would expect it to generate structures compatible with a finished fortress of some size... bonus points if I can specify a number of dwarves. Double bonus points if I can specify casts and have the housing be dynamically created in zones near their industries with dining areas for individual groups (on top of a central meeting hall).
If I were dreaming a bit bigger I'd like it to have knowledge of different kinds of abstractions, and give me high level controls for determining how they are generated, eg. for a farming area I'd like to control the generation by specifying a capacity for how much food it should generate, a control for the varity of food sources (varity and capacity interact like civs in world gen with world size), perhaps some kind of seed, and a "wealth" control to determine the value of the chosen materials.. then some geometry of farm area should be generated with floors and plots and assigned to whatever vegetables were available for selection.
If it had knowledge of these abstractions, and a way to control how they interact, then we are in business. There are degrees of abstractions, and they can be deepened over time, given you plan their structure and interactions correctly. I think you can catagorise the motivations in the early game loosely as, in approximate order of priority:
I would expect a fortress generator to lay out structures to fulfill these needs, in a logically connected fashion. The kitchen and still must be close to the area the plants are stored, but also to the place where the prepared meals and alcohol is stored. Space must be left for future expansion, but supply lines need to be short. Structures exist within a fort; a meeting hall, an entrance, a sleeping area - and these structures contain substructures; seating areas, decorations and bedrooms. A properly designed hierarchy of rooms and rules for their connectivity will give rise to various configurations of fortressses. Making these rules dynamic in response to a set of key parameters relating to their connectivity and parameters should then give the control needed to generate fortresses of a varity of scales and shapes. If this can then be adapted to suit an external terrain, with a random geometry and geology, the road from the minimum generator to implementing the above model becomes clearer.
The lynchpin in this whole thing is going to be figuring out how to effectively translate motivations into structures. Ideally I'd want to use things similar to what's already in Dwarf Fortress; I don't know if groups as a whole can have a motivation yet, but perhaps it could be adapted from the structure of the personal motivations, or reflect the desired of the king through the competancies of his underlines. Facinating as sourcing the real motivations from the game can doubtless prove to be, I'd have to pick a few general abstraction to work around, so this thing can comfortably slide into an external system, that way it can continue to grow outwards.
PAUSE
There's a bit more to develop here, there's still something to be thought about the minimum fortress generators minimum rooms; and the question of what method would be used to connect things hasn't been answered. I'm inclined to think what it wants to be connected to is a property of a room, and it satisfies it by the shortest route possible... but that is tomorrow me's problem. This has been a fascinating two and a half hours, but it's 4.30am and any additional planning will have to wait for a fresher me. I find it easiest to develop ideas by talking to myself, but I also find it useful to have an audience
* a splinter group of dwarves that fear the underground, a goblin-elf love cult that worship magma and enslave dwarves to get to it... 'preference' can be a broad term here.
**I'm not quite prepared to consider the complexities of multilevel heavy aquifers at this point, but I imagine you'd end up with a lot of unhappy dwarves in wooden structures on the surface, or shacked up in the dirt.
*** In a truly integrated fortress generator this would require the fortress sending the food in increase their food stores, either by building more food industries, or increasing imports, which, depending on the length of time it goes on for, may affect the industries in their neighboring cities. When the war ends, the price of food could fall and a city collapses economically.
↕ "Seek Cavern" should involve digging vertical shafts to a certain depth, increasing in number until some critical stage when all shafts are made deeper. This is repeated until a cave is found. Shaft density should increase with depth. This might be hard to write, depending how caves are generated. There should be some math that helps dig exploratory tunnels.
↕↕ At this point blood wine would have made an interesting addition.
↕↕↕ eg. an unsuccessful invation that does some damage could be interpreted as "need for security" increased by "violent encounter", which could lead to "wall", "trap" or "moat" for a military fort, but possibly "abandon area" for a small family that came to build a hut in the mountains.
¶ Not strictly a problem, but I think the best way to approach this is from a worldbuilding / roleplaying perspective.
Automatic Fort Generation
I am maximally lazy; as I perform a repetitive task I think of ways to automate it, and this has been the case when making fortresses. I don't want to do this for my own fortresses, because I am the program that bests makes new exciting forts, but it feels like there is a general enough structure to what I do, regardless of the goal of my fort, that I could abstract it into a program, and that program could then generate groovy NPC fortresses that evolve with the world.
First off, I'm virtually certain someone else must have posted about this, but being new here and not knowing the exact lingo, my search-fu is lacking. If someone can point me towards a thread, I'd be greatful. Other than that, I intend to just put some thoughts down here; I like thinking about creative problems, and I'm sure having more opinions on it would only make the end result better.
Automatic Fort Generation: A Problem Statement
So, in essence, what do we want from an automatically generated fort?
- There must be enough variance that to all but the most non-casual observer it would look designed
- There must be relics of its evolution
- It must be appropriate to the culture
- It must be appropraite to the history of the civilisation and site.
When the fortress generation starts there will be initial conditions guiding its evolution based the motivations of the settlers (nomads, expanding the borders of a nearby settlement, an advance outpost for an invasion, a remote new settlement far from the homeland, a mining colony, etc).
The race influences the fortress structure (eg. dwarves are more likely to make underground fortresses, humans are more likely to channel out pits for stone and build buildings, but if the area doesn't allow it, anything is possible to survive). In the long run the fortress should evolve to suit the races preference*.
Relics of the fortresses evolution in this case refers to things like gradually replacing materials that become available over time, or having the goal of the settlement evolve, like an advance outpost that becomes a keep surrounded by farms after a war, or a small villiage that gradually grows to a city over a long period of time. Each of those scenarios would leave footprints depending of the nature of the changes at each step (like having wooden inner walls that used to be outer walls).
The goal here is then to find a framework to encapsulate all of this so a small working version can be written that, although intiially limited, could grow to accomodate all of these variables. To satisfy the requirement of "looking designed" will require some way to creatively mutate the base structure. Ideally if I could encapsulate this in a configureable way, so that I only leave a minimum of fingerprints on the fortress generator, then some kind of community sourcing action could generate parameter sets to finetune certain aspects of the final forts.
While I have a lot of pretty cool ideas for for this could generalise to other races and terrains, as a very bare minimum, the least this thing would have to do is create a fortress, for dwarves, underground.
A Simple Model For Fortress Evolution
For this to work properly, I can't just generate a fortress, I have to show my work. A good starting point is the same as Dwarf Fortress itself, the embark. I would need to know how many dwarves are coming, why they are coming and what they are bringing. A site may be built by royal decree, in which case the king could send a hundred laborours with several caravans of prepared materials and it would just pop into existence; or seven rugged, wild spirited dwarves could march into the mountain with two axes, two picks and a bag of seeds.
The motivation of the group and the materials they have will affect what happens when they reach the area to build their fortress, but this area will also affect what they can do**.
Ceremaic and clay industries can only exist if there is clay and sand.
Terrain that has large wobbles all over is not suitable for big surface structures (or rather, would be preferentially selected against in that environment, unless there was a motivation otherwise).
Realistically the first phase should involve shelter. Dwarves can either gather materials to build a building, or dig down/into the side of a mountain for shelter, leaving the food and wagon outside for too long isn't a good option. This is not necessarily housing yet, just somewhere to exist that isn't ouside and exposed - a meeting place, indoors. The cave is underground, safe, and eminently useful to your stone industry; but a lot of my forts have had some kind of keep-like structure, and it normally evolves from a little hut I built to protect my caravan.
Once there is somewhere to exist that isn't outside, the next priority is food. There are limited options on what to do here depending on the environment and the items you embarked with, but ignoring the complexity of what you brought along, in general you can get food by hunting, foraging, farming, owning animals and fishing. Owning animals yields continuous food in the form of milk and eggs, and discrete amounts of food in the form of meat, that if properly managed, doesn't reduce your flock size. Bees are counted as animals in that list, but cannot be eaten (yet?).
The food industries chosen by the group will related to what's most readily available in the area; but will also be affected by the motivation for creating the fort. You can't have 20 herbalists and fishermen roaming the country side when you're an advance outpost for an invasion; in such a case you either need a secure food supply behind your walls, or a reliable trade route to get supplies to sustain your war effort***. The size of this industry would be also affected by the groups motivation (plans for a big city needs plans for a lot of food, initial farm area might be small, but space is left for expansion because the city is planned to be large, a city that was planned small but grew large would bare the scars of inadequate spacing, and might necessitate creating a "second fortress" somewhere else that can accommodate the increased numbers comfortably).
Alcohol is a vital offshoot of the food industry, and all dwarven fortresses need a supply. All dwarven fortresses should employ a progressive strategy for acquiring alcohol.
Depending on the chosen food industry, dwarves may have the means to create alcohol.
- If they are unable to create it, they must try import it.
- If they are unable to import alcohol, they must seek seeds.
- If no soil is available, seek water to create mud.
- If no water is available, seek cavern↕ and bees.
- If no seeds are available, seek cavern↕ and bees
- If there are no caverns or bees, suffer↕↕.
From this point on though, things become less clearly defined, and depend more and more on the motivations of the group. City builders may want to focus on getting their stone-industry up and running, which may have gotten a kickstart from the initial digging of a cave. A dedicated mining operation might treat the initial fort as a starting point for going down to the magma, require shafts to dump ore down and a minecart system to transport it up. A military fort close to enemy lines might want to prioritise defences.
In summary, up to this point most fortresses would follow a similar path, but at this point they diverge. The problem involves capturing the trajectory of that transformation in a way that allows you to not only quickly and easily encode scenarios like the ones I've been dreaming up into the fortress builders "plan", but does so in a general enough way to be able to grow with the game. It may be possible that the embark is a single wizard, and he casts 50-level slade tower in the middle of the map, or that in the future you could embark with vampires only, and not need food, shelter or beds.
So, at the moment the model we are working with for the fort generator is looking something like this:
- A fortress is an settlement that may have aboveground structures and or belowground structures.
- Dwarves typically live in the belowground structures.
- Fortress construction happens in phases over time.
- As a first effort, the primary conern of any dwarves is to find shelter and food
- Subsequent actions taken to develop the fortress should be a product of the motivations of the inhabitants and the events that take place there↕↕↕
The first version of this model was and could only be made from my experiences designing a fortress, but at this stage is still sufficiently vague to not constrain the end result much. Essentially, a fortress has a reason for being built, there are stages to its construction, and events affect how it grows. Mention was made of above and below ground structures, but nothing has been said about the sizes of areas, the spacing, the choices of materials, the relative layout of rooms, or other important factors, such as how the fortress survives economically¶ and whether they have requirements on who can migrate there (no children on the front lines...). These are important questions, and while it's very important to consider them so they are able to fit into the final generator, they are outside the scope of an initial implementation.
Some additional random thoughts on this topic: The population of a city affects the speed at which it is constructed. Food sources have a "rate" attached to them, and once the rate of consumption approaches the rate of generation, a need to expand the food industry is created. For simplicty this is checked on a yearly basis to accomodate the average # of animals roaming the country side, the average plant growth in the area, average fish available, etc. Food industries expand horizontally at first, if motivations allow it, and then vertically to increase capacity.
So, now that a basic model is in place, and we have a feel for the lay of the land, it's time to consider...
The Minimum Viable Fortress Generator
If someone came up to me and said, "Hey dude, I have an automatic fortress generator for Dwarf Fortress", what is the absolute least I would expect, given the title was technically accurate? I would imagine it would be something that spits out QuickFort blueprints; that doesn't care about what the map looks like, but tells you how to build. I would expect it to be either configurable or randomisable, else it's just a single blueprint, and I would expect it to generate structures compatible with a finished fortress of some size... bonus points if I can specify a number of dwarves. Double bonus points if I can specify casts and have the housing be dynamically created in zones near their industries with dining areas for individual groups (on top of a central meeting hall).
If I were dreaming a bit bigger I'd like it to have knowledge of different kinds of abstractions, and give me high level controls for determining how they are generated, eg. for a farming area I'd like to control the generation by specifying a capacity for how much food it should generate, a control for the varity of food sources (varity and capacity interact like civs in world gen with world size), perhaps some kind of seed, and a "wealth" control to determine the value of the chosen materials.. then some geometry of farm area should be generated with floors and plots and assigned to whatever vegetables were available for selection.
If it had knowledge of these abstractions, and a way to control how they interact, then we are in business. There are degrees of abstractions, and they can be deepened over time, given you plan their structure and interactions correctly. I think you can catagorise the motivations in the early game loosely as, in approximate order of priority:
- Shelter: Cave or Keep (initially)
- Security: Doors, Gates, Traps,
- Food: Forage, Hunt, Farm, Animals, Fish
- Building Materials: Wood, Stone, Ice, Ceramics, Glass
- Sleeping Areas: Dormitories, bedrooms
- Industry: Crafts, something plentiful in the area
- Medical Facilities: Hospital, Water, Supplies
- Self-Actualisation: Temples, Libraries, Taverns, Guild Halls
- Beautification: Engraving, Smoothing, Gold Floors, Mist Generators (necessitating plumbing), fort "scale' grows over time
I would expect a fortress generator to lay out structures to fulfill these needs, in a logically connected fashion. The kitchen and still must be close to the area the plants are stored, but also to the place where the prepared meals and alcohol is stored. Space must be left for future expansion, but supply lines need to be short. Structures exist within a fort; a meeting hall, an entrance, a sleeping area - and these structures contain substructures; seating areas, decorations and bedrooms. A properly designed hierarchy of rooms and rules for their connectivity will give rise to various configurations of fortressses. Making these rules dynamic in response to a set of key parameters relating to their connectivity and parameters should then give the control needed to generate fortresses of a varity of scales and shapes. If this can then be adapted to suit an external terrain, with a random geometry and geology, the road from the minimum generator to implementing the above model becomes clearer.
The lynchpin in this whole thing is going to be figuring out how to effectively translate motivations into structures. Ideally I'd want to use things similar to what's already in Dwarf Fortress; I don't know if groups as a whole can have a motivation yet, but perhaps it could be adapted from the structure of the personal motivations, or reflect the desired of the king through the competancies of his underlines. Facinating as sourcing the real motivations from the game can doubtless prove to be, I'd have to pick a few general abstraction to work around, so this thing can comfortably slide into an external system, that way it can continue to grow outwards.
PAUSE
There's a bit more to develop here, there's still something to be thought about the minimum fortress generators minimum rooms; and the question of what method would be used to connect things hasn't been answered. I'm inclined to think what it wants to be connected to is a property of a room, and it satisfies it by the shortest route possible... but that is tomorrow me's problem. This has been a fascinating two and a half hours, but it's 4.30am and any additional planning will have to wait for a fresher me. I find it easiest to develop ideas by talking to myself, but I also find it useful to have an audience

* a splinter group of dwarves that fear the underground, a goblin-elf love cult that worship magma and enslave dwarves to get to it... 'preference' can be a broad term here.
**I'm not quite prepared to consider the complexities of multilevel heavy aquifers at this point, but I imagine you'd end up with a lot of unhappy dwarves in wooden structures on the surface, or shacked up in the dirt.
*** In a truly integrated fortress generator this would require the fortress sending the food in increase their food stores, either by building more food industries, or increasing imports, which, depending on the length of time it goes on for, may affect the industries in their neighboring cities. When the war ends, the price of food could fall and a city collapses economically.
↕ "Seek Cavern" should involve digging vertical shafts to a certain depth, increasing in number until some critical stage when all shafts are made deeper. This is repeated until a cave is found. Shaft density should increase with depth. This might be hard to write, depending how caves are generated. There should be some math that helps dig exploratory tunnels.
↕↕ At this point blood wine would have made an interesting addition.
↕↕↕ eg. an unsuccessful invation that does some damage could be interpreted as "need for security" increased by "violent encounter", which could lead to "wall", "trap" or "moat" for a military fort, but possibly "abandon area" for a small family that came to build a hut in the mountains.
¶ Not strictly a problem, but I think the best way to approach this is from a worldbuilding / roleplaying perspective.