January 23, 2019

Cities II: Names

Generating cities without names is so impersonal.

So I applied my Markov generator to them.

But I don't want them too similar to real-world names. So I decided to "mix" the models together.

For each race, I used the following recipes, with words taken from Swadesh lists (it's hard to find longer lists of more obscure words, but I'm continuously looking). I tried to pick interesting combinations, but I think this will need a lot more experimentation.

  • Orcish = Arabic + Somali. These might be too similar linguistically to give a good effect, but we will see. Qolim, Ishan, Hailid, Faris, Afalah
  • Elfish = Korean + Egyptian. And these might be too dissimilar. I've already noticed that one meme or another tends to dominate the name. Dohyungminseung, Miunghyun, Daehyeon, Petat, Aprieb
  • Dwarfish = Hmong + Egyptian. Khapet, Ziamakiuwel, Sualmayakam, Tirdjedjedi, Menkhteshi
  • Humanish = Welsh + Polish. Rznardir, Garybatawart, Nosty, Kwieb, Zhciach
  • Halflingish = Bokmal + Russian. Smalt, Ideryy, Flyondel, Mamme, Smannyy
Well, they're pronounceable, at least.

The models can be mixed even further, abstracting it into a second-order chain. So if a city is founded in a kingdom of 50% humans and 50% dwarfs, then I can create a combined chain from all the existing city names of those races.

January 22, 2019

Cities I: History II: Fall and Decline

The basic city growth model is \[\Delta P = B + D + I + E\], where $\Delta P$ is population change, $B$ is births, $D$ is deaths, $I$ is immigration, and $E$ is emigration.

I handle $B$ and $D$ with the logistic equation \[B - D = r P \left(1 - {P \over K}\right)\], where $K$ is the carrying capacity of the city. I want some randomness here also, so I add a bit of random walk. I also add some random walk to $r$ (the maximum rate of increase) and $K$, to account for changing conditions in the city's management, infrastructure, and what-have-you.

This leaves $I$ and $E$, which is a bit trickier. I read a lot of papers on this, which mostly deal with models for modern cities, where people often live in totally different cities. Since permanent immigration is due to many varied non-deterministic reasons, these terms often refer to the flow of workers between cities (who aren't necessarily permanent residents). These phenomena are pretty well studied, but that's not helpful to me.

So I figured that a certain percentage of people from a city would want to move someplace better. The bigger the difference in desirability ($\delta_j - \delta_i$), the more people who would try to move there, as long as the host could bear them. The number of migrants is then defined as \[M = {\delta_j - \delta_i \over 10\cdot \textrm{max}\left(\delta_j, \delta_i\right)} P_i\], where $i$ is the source and $j$ is the destination. This captures reverse flow, so I don't have to worry about which one is nicer. Since $\delta$ is already partially a function of $P$, the dense tend to get denser, to a point.

To make things more interesting, there's also a ~5% chance of a "disaster" striking (or perhaps a series of such) which decrease the population even further.

Here's a city undergoing these processes:

All of this assumes near-perfect growth, not to mention a maximum $K$ that's probably optimistic (around 100k or so, but with magic, who knows?). But more importantly, there is no war here. And that, my friends, will not do.

January 17, 2019

Infrastructure II: History I

Time to begin placing cities.

There are a few considerations to make when growing populations/cities organically.
  • Initial populations of villages are set to $P_0 = 150$. The growth equation at time $t$ then becomes \[P(t) = {K \over {1 + {K - P_0 \over P_0} e^{-r t}}}\] In the future, I'll actually progressively modify the population number, but for now I just evaluate this equation using the age of the city.
  • The carrying capacity $K$ is a function of the desirability $D$ of the location. \[K_0 = 5000 \exp\left(10 \left({D \over \textrm{max}(D)} - {1 \over 2}\right)\right)\]
  • $K$ is then modified according to Central Place Theory (CPT). One of the tenets of CPT is that cities are spaced according to the product of their populations and inversely to the distance between them. My method for doing this is as follows: the city in question is assigned a level $\ell = \log_{10} K_0 - 1$. $K_0$ is then reduced by a factor of 10 if $2 ^ i > \delta_c$ for all $i < \ell$, where $\delta_c$ is the distance to the closest city of the same $\ell$. So a city of 9500 people cannot be closer than 4 hexes to another similarly sized city. If it is, then $K_0$ is reduced by a factor of 10. This will hopefully ensure an exponential distribution of city sizes, and prevent a concentration of very large settlements.
  • $r$ will be a random number with a max of $2\% \cdot D \over \textrm{max}(D)$. This sets the maximum growth rate at 2%, but allows for a lot of variation in between. Maybe the different races should have different growth rates?
  • Any given hex which meets all other requirements has only a 5% chance of generating a city. I'll give this a little boost for particularly desirable places.
  • I won't force them to obey Zipf's Law, but I'm wondering how the distribution will shake out. Zipf's Law has been demonstrated to hold most true for "small cities" over 100,000 - for a fantasy low-tech world, that might be a "huge city" instead!
  • Another thing I need is a mechanism to destroy or stagnate a town - many things can affect a city's growth or longevity. Not every city built in 1000 BC still exists. In fact, most don't. Plague, famine, war, resource depletion, etc can all wipe out even large settlements.
  • A dynamic $K$ value might be cool also. That way a settlement might have a bright future, but overcrowding could really hurt long-term. As groups compete for resources, which larger cities need more of, smaller settlements tend to be crowded out. I need to capture that, and that might help my goal of CPT-arranged cities.

Some observations:
  • Since dwarfs (blue cities) are not "constrained" to the coast, their cities are placed much faster. This isn't necessarily a problem, but I want to consider how heavily the coast is weighted vs the inland. As a result, non-dwarfen cities are isolated, and have more difficulty coalescing into an entity.

  • The desirability map takes a dozen seconds or so to populate. This adds up and makes the year-by-year simulation very slow.
  • Similarly, it's expensive to figure out where roads should be placed so that they make sense. I've added some timeout functions to the road placement algorithm to make sure that A* doesn't get stuck somewhere it can't get out, but the constraints need some work. As shown in these images, it's made slower by the fact that eventually, every city gets a full 6 roads coming in and out.
  • Some of the orc cities (purple) behave well with roads, but there are no special road considerations for different races.
  • River crossings are a problem. They would be easier to implement if I used edges instead of tiles, but that would be a big pain to implement with the drainage code.
After 550 years of simulation, the total city populations are as follows (not including rural population, which is expected to be about 5x urban):

elf13,552,065
dwarf5,570,650
halfling11,144,894
orc28,884,984
human14,688,643
Orc growth is much faster because their cities form at great distances from the other, allowing for rapid growth and large carrying capacities from CPT. The opposite is true of the dwarfs: they have many cities, but densely packed, which reduces the maximum carrying capacity.

I could do more analysis of the cities, but I'd like to tackle the road problem first, since it feeds back into the city placement algorithm, and is the current bottleneck for any kind of long-term simulation.

    January 11, 2019

    Desirability IV

    As discussed in previous posts, the presence of cities and infrastructure can make a location more desirable. Shown here for elves:

    without city modifier

    with city modifier
    As with many things, the rich will tend to get richer. Highly desirable locations will only become more so. Can penalties occur naturally? Something to consider.

    Currently, the cities are undifferentiated with respect to race - my end state will be to have more eclectic populations - but for placing initial cities, I may want to change that temporarily.

    The next steps are to put it all together in a coherent whole model.

    January 10, 2019

    Roads II

    With the rough infrastructure map in hand, I wanted to be able to place roads between them. Then both systems could be fed back into the desirability model.

    But as usual, there were some kinks to work out. There are a few constraints on the roads, such as climbing distance (too steep? penalty), altitude (particularly above 8000 ft, where the air is thin for those not acclimated), and of course overall length. Additionally, a hex must have a certain infrastructure threshold to even be considered for a road, and it's even higher for a bridge to cross a river.


    I don't mind the jaggedness of the line - the hexes are huge, after all. It's the overlapping roads I want to avoid. So I fixed it to seek only the closest city for a road. This is similar to a minimum spanning tree, but not exactly. I want a non-optimal layout - the spread of populations shouldn't always make sense.




    These maps also show how the infrastructure (red) is affected by local topography, which constrains it from spreading too far.

    Now, I can feed both of these systems into desirability and start building more organic layouts (the cities I used here are just randomly selected).

    January 4, 2019

    Infrastructure I

    In my discussion on desirability (for population centers), I realized that existing infrastructure is extremely important. Communities can exist in isolation but will inevitably spread themselves out, creating new communities and so on.

    Eventually, I'll split infrastructure out into separate races (at least for the desirability index). Infrastructure, of course, determines what sorts of services and industries could be available in a given hex, so I only need a single (non-racial) number eventually. But as far as settlement placement goes, it would make more sense that an elven village would prefer other elves rather than humans or dwarfs, given the chance. I can also define rough guidelines to racial relations - humans and elves might get along better than humans and dwarfs, and who likes the poor, stereotypically brutal orc?

    However, making this switch is pretty easy, so for now I'll work with a single value. This will make settlements more heterogeneous during these tests.

    To really get an accurate base number for infrastructure, I need a value for the total population in a region (or the whole world, as it may be). This part is tricky when starting from scratch and looking at the entire planet - I don't know how many people there are, and where they live. After all, that's the point of this system in the first place.

    The equation in question is as follows, where $I_{i,0}$ is the base infrastructure index of the $i$th city, $p_i$ is the population of the $i$th city, $p_t$ is the total population (urban and rural), and 346 is the number of square miles in a 20-hex:
    \[I_{i,0} = {p_i \over 346} {\sum_i p_i \over p_t}\]
    Essentially, I am ignoring the ${\sum_i p_i \over p_t}$ term, because I don't (yet) have access to $p_t$. Or I could make up a number. Ignoring it is the more palatable option, but adding a multiplicative factor will make the influence of a settlement "reach" farther.

    Placing a bunch of random cities and applying those rules:

    I'm excited to lay down some roads on this bad boy (and to feed it back into the desirability map).

    January 1, 2019

    Desirability III

    I am working on making the desirability index more parameterized. With this, I can create sets of parameters for each race, because humans, elves, etc will not desire the same climates, terrain, or biomes for their habitations.

    I'll probably be tweaking those recipes for a long time. I haven't looked into details on the races (5e is, of course, deeply unsatisfying). But I'm not worried about that for now.

    Most races avoid the rainforest - the soil is often poor for many types of crops. Dwarves like mountains and avoid the coast - but they're not total loners so they'll utilize rivers for travel. Stuff like that.

    This is a hard map to read - essentially I've layered five races on top of one another; humans: green, elves: red, dwarfs: blue, halflings: orange, and orcs: purple. Why those five? No idea. I wanted the three classics, plus a feature race for ice and desert climates that would be inhospitable for the others. The orcs end up with a lot of territory, but they are not as gregarious (modeled with an infrastructure penalty), so the size of their empires should theoretically be limited. The elves also have a wide distribution thanks to the large amount of rainforest (unless I penalize them for it also).


    All of this is, of course, very modular. It's easy to change the climate models and then propagate those changes to the desirability. This is a far cry from where I was earlier this year, where a map like this would require tons of manual rework.

    Creating this Step 0 desirability map is more or less straightforward (tweaking is, as always, necessary). However, existing infrastructure will also affect the terrain...but I haven't built any of that code, so that will need to be next.

    December 15, 2018

    Rivers VI: Lakes

    A few months ago, Alex Schroeder left a comment on one of my river basin head-wrackers. Unfortunately, the comment has now been deleted thanks to Google+'s wonderful management strategies, but the point still stands: when rivers are trapped, they usually can form lakes and flow out anyway, even if the hex is "higher."

    Something that I have to remember is that a hex altitude is the average. The hexes are not simple flat planes stacked like the Giant's Causeway.


    So, it's totally possible for a river to flow from a "lower" hex to a "higher" hex, simply following the shortest route to the sea. Perhaps it carves a canyon not visible on the main map.

    This algorithm needed a little elbow grease to implement, but it works. There are still some totally endorheic lakes. I can either continue to jitter the surface to make everything shake out, or just be ok with it. A shocking amount of the earth's groundwater never reaches the ocean (over land, anyway), so it's not a terrible thing.



    Right now, I'm just representing the lakes with circles (and non-navigable rivers with red). I agonized for a bit about making nice, generated lakes, but then I realized that...it was fine not to. This is not a beautiful overland map like Scott makes. This is, more or less, a representation for game purposes. So it's sufficient to say "here is a lake."

    The other thing to point out about this map is the size of the rivers. Again, this is purely representational, but I think I will continue to scale the numbers until the map is not quite so busy. I will have to determine the minimum river size necessary for trade, and that will be the low cutoff.

    This map is also not adjusted for precipitation. Since I've just now completed the elevation, I still have to run the wind and rain algorithms. But the actual drainage networks should remain unchanged.

    December 13, 2018

    Elevation XIV: Let It Be Done

    I've decided (for now) to be done with terrain generation. I've got something I like even if it's not perfect, and to facilitate the rest of my project I'll let it ride for a while at least. It won't matter too much if I do decide to come back and change it (as will no doubt happen) because everything is generated.


    I still might do some tinkering but this will do.

    December 7, 2018

    Gimme That Old Time Religion

    I'm not the first to address the issue of religion in D&D, and I'm certain I won't be the last. But I think it's worthwhile to begin thinking about how the divine works in my world, at least to form a coherent treatment of clerics, monks, and paladins (and sort of warlocks, though they are not connected with outside religion).

    For the paladin, his oath is what provides his power. The cleric, however, is granted strength by a Divine Being.

    Yet there are more orders of clerics than just one. How can this be in a world where proof of your god's existence is instantly accessible by any mook with a holy symbol? RPG clerics live in a world where they walk by sight, not by faith.

    There are some solutions to this, of course. One solution is to make all clerics worship the same deity. There cannot be more than one.

    This is a little unsatisfying. But consistent.

    If we wish to have more than one clerical order, following different gods, then it follows naturally that these deities cannot be all-powerful, and therefore not gods at all. If they were all-powerful, and also all true, then they could not all coexist logically. Zeus and Odin cannot be both god if both exist (as separate entities).

    Therefore, then, clerics could gain their power by belief in a localized (more or less) entity which existed on a plane above their own. This is a different level (higher or lower?) than that which a warlock patron might occupy.

    Clerics, of course, are gregarious, while monks are ascetics. I'm thinking that a leveled cleric would probably be a step up in whatever hierarchy exists from the local priest, but of course could certainly take up that mantle. A priest might be able to conjure some small healing magic or other stereotypically clerical things, but for the most part is responsible only for the spiritual journey of the local flock, whatever that might mean. Clerics are holy warriors with additional training from an established temple.

    I don't really like monks. So I'll ignore them for now. I think clerics fit the role much better, without the edgy Bruce Lee vibes.

    So what do they worship? I was browsing around and found the Book of Urantia, an absolutely insane mystical document of no religious value, but it's got some good inspiration for worldbuilding. Paper 85 identifies 6 progressive sources of worship:
    1. Stones
    2. Plants
    3. Animals
    4. Elements
    5. Heavenly bodies
    6. Man
    Of these, elemental forces are the most attractive to me in terms of a cosmology. However, I must recognize the extreme difficulty of putting myself in the shoes of an ancient man who worshiped, say, bears or fire. That said, I suspect the desire to anthropomorphize was still strong in those days. So the lightning that destroys trees and people becomes the Father of Storms and we'll give him a name, Ja-Pater.

    Ritual worship involves invoking the power's favor or appeasing it in some way. The question arises as to whether the cleric's powers are dependent on correctly approaching the power. Would schisms arise? If so, wouldn't it immediately be obvious that one side picked the wrong theological formula? Can a rogue cleric be stripped of his magic by his superiors as punishment for some crime against the deity? Food for thought.

    Ultimately, clerics must operate in some kind of organized (named) religion, whether it's a structured church or a looser collective like shamanism. I'm not sure yet how to determine a local religion procedurally, or if that's something to save for a rainy day. It's not going to matter that much for my planned model of empire growth.