## August 31, 2018

### Winds II: Better Winds

Inverse distance weighting is working well. So I decided to apply it to the sea winds as well. It gives nice smooth interpolation, even if there are some places that are a bit odd. But that's ok. Nothing is perfect...yet.

Once both season (hot and cold) have been calculated, I can use the areas near the coast to define the boundary conditions for the existing land wind model. For the coastal currents only, I've categorized them as cold, hot, or mild. These aren't absolute values, just relative ones. This feeds into the precipitation model, which will be used to give better results for erosion. I'm waiting to put the finishing touches on the erosion model until I can staple these parts to it.

## August 29, 2018

### Currents III: Better Currents

How did I not used Inverse Distance Weighting before now? It's easy to implement, and looks much more natural. Before, the currents looked a lot like Voroni diagrams in some places...sometimes they looked good, but mostly they just were offsets from the coast. It does take a while to run for now, because I haven't optimized the function like I think I can.

All in all, it looks pretty smooth. I guess I could use some kind of finite element modelling to get a really good simulation, but that's too much work for the benefit. I'd have to know a lot more about the ocean floor topography, which is something I haven't even touched.

## August 27, 2018

### Elevation VIII: The Void

I'm back working on the erosion code - I think I have a better implementation, but there is an interesting problem that crops up.

I have talked before about the basin-erosion, and how it finds a way out of any place where the water might be "stuck." However, I think this mechanism is causing total collapse of the system.

Watch this gif:

It's amazing. After some cycles of building beautiful terrain, something happens. It's the Void from the Neverending Story (or Jerry's Map). Everything falls victim to the Void, swallowed by its constant advance. I haven't quite figured out why this is happening, but I have a feeling it's related to the basin-erosion code. There are a couple of places where you can see it work as intended: in one frame there will be a black gorge carved out of the mountains, and the next frame will show nice fractal patterns forming around it. However, you can also see the blackness of the Void forming around it. And once it forms...

## August 24, 2018

### Resources X: A Man's Gotta Eat

As far as agriculture goes, there is no better resource I've found for implementing crop distribution than the Ramankutty Lab. This is an absolutely fantastic repository for the distribution of 175 different crops.

However, that's a lot of work for me to do, even though the heavy lifting has already been done. I have to figure out how to translate those stats into something my program can read. I have climate data, of course. Just have to decide which wires to plug in where.

Ramankutty provides some models for predicting crop cultivation based on the length of the growing season. This is a good start, although they use some data I don't have, like the actual evapotranspiration and the soil moisture index.

For my purposes, at first, I might just go through the data and figure out what Koppen climate the crops roughly align with. That's easy enough to do by layering the kml files which are easily available. I'll only post an example here: please go over to the repo linked above to get the data for yourself. It's very informative. This is probably the easiest way to do it: I can't find any crop lists compared to Koppen unfortunately; there are some broad generalizations but that's all.
 Source: Earthstat

Then again, it'll take a long time to go through 175 crop types. So I think I'll prioritize and work through them here and there. I'm also having a lot of fun making the symbols for them. I've either used alchemy symbols straight from the Quivira font or combined glyph shapes in Inkscape to maintain a consistent style. I also like the Symbola and Esoterik fonts, but I haven't had occasion to use them yet. I don't always use the alchemy symbol, most for metals, but I do try and tie it in somehow if I can. If a bunch of mystic medievalists did all the work for me, why reinvent the wheel? For example, barley and rye (both used in alcohol production) use various forms of alcohol symbols.

In terms of translating the yield numbers to actual reference numbers, we can calculate the number of acres it takes to produce one reference, and we also need to know the amount of arable land that's available for agriculture. This varies from climate to climate, and I need to do a more detailed study of the percentages there. For instance, India's Aw climate gives them a mind-boggling 52% of arable land, but only 4% is used for crops. Then, how many people does it take to work a single acre? Estimates are all over the place (since it may vary per crop), but the basic grains seem to be around 20 acres a person. I'd rather use 10 in the absence of better data for now. I've worked 10 acres before (vineyard), and it was rough but doable.

So the code will need to decide if the settlement will run out of available hands or available land first. Not so hard.

I'm looking over these yield numbers and some seem a little high for a pre-modern society, even assuming some magical assistance from the local druid. So I may revisit them.

Wheat: Cfb. Primarily, at least. One thing I'm doing is ignoring some of the smaller yield areas to account for differences in technology. Wheat is pretty hardy and can be grown in many different climates, but the highest yields are predominately Cfb. Yields 1,000 lbs/acre.

Barley: Cfb, Cfa, BSh, Dfb, Dfa. Another versatile crop, without which your stereotypical dwarfs will be ale-less. Of course, if you want beer, you need hops as well. Yields 100 lb/acre.

Oats: Cfa, Cfb. Yields 480 lb/acre.

Maize: Cfa, Dfa, Csa, Csb, Cfb. Yields 500 lb/acre.

Cassava: Af, Am, As, Aw, Csa, Cfa, Cwb, Cwa, Cwc, BSk, Dwa, Dwb. Very wide distribution. Yields 1,300 lb/acre.

Rice: Aw, Am, Cfa, Cfb, BSh, Dfb, Cfa, Cwa, Csa. This stuff will grow basically anywhere you have water. Yields 1,125 lb/acre.

## August 22, 2018

### Expanding Demoland

So far I've only considered the people who live in the actual settlements as part of the industrial system. However, I neglected to consider the rural population in this equation. It's a lot more work to manually input everything, but I already mentioned that doing it by hand the first time helps me design a better program in the long run.

The biggest effect is that there will be more market towns. In fact, so much so that I might raise the support value for some of the industries. The system is much like a musical instrument - it must be tuned to produce optimal results.

I still had a few rules. I only expanded into hexes which bordered existing settled hexes. Otherwise, I'd have to make up a whole new set of rules for how far a hegemony extended, and that's a problem for another time.

I really like the way the map style is progressing. I need to think about how I'm going to make these automatically, but for now, the manual approach is nice. Hopefully this uploads with enough resolution to see the interesting features. Maybe I should have done like Chicago Wiz and stuck with 3 hexes at a time.

Cadewin and Ffrith are now market towns, but things are pretty expensive. Still, it's a long way down through the forest to Derl from Cadewin, so you should just suck it up and bear it. Cadewin, at least, is lucky to have a road down to Derl. Betryn isn't so lucky - they can take their chances through the forest (remember, no roads, so what trails are there will take a twice as long to traverse with a cart) or raft down the river.

## August 20, 2018

### Resources IX: Demoland's Iron Industry

Industry is kind of a strong word for what they've got. Remember, barely anyone lives here. They have a good bit of iron, and not that much money to buy it with. There are only three places where they even can buy it: Andox, Gerlin, and Malis. They also have no connection to any outside economy, so as far as they know, iron is just cheap as dirt.

It's possible that an economy this poor (or at least, lacking in the Big Three fantasy coinages of copper, silver, and gold) would be on the barter system. However, the trade system is still of use here because it provides a comparative measure of value. If a goat is worth 1gp, and a chicken is worth 5cp, then a goat is worth 20 chickens. Easy.

I'll be going through this a bit slowly, since I'm uncovering bugs as I go back through all my code.

Also, these numbers are constantly changing. Eventually, of course, this will all be generated, but I'm a strong believer in doing it by hand at least at a very small scale so that I can catch some of the bigger problems as they come up. So some of the reference numbers might be too small or too large. I already caught a problem like this for the wood reference. In large economies, this can get lost in the weeds, but in small economies like Demoland, it can have huge social ramifications.

With the same caveat of constant development, I haven't fully researched some of the ores that appear here, specifically copper and silver, at least in terms of putting them into the system. So they appear fully formed, for now. Clay also appears (since you need it to create the furnaces to refine iron).

Not all cities are markets. Market towns are displayed in small caps. I try to keep the resource symbols up to date here.

• Andox is the market for Kenor, Norys, Derl, and Cadewin
• Gerlin is the market for Llen and Betryn
• Malis is the market for Ffrith
The reference amounts are as follows:
I'll put up another post soon talking about the recipe system I use to integrate my version of the Tao's trade network. But already I can see that this place is a total backwater. It helps to remember that about 80% of people live around, not in, the villages. Andox, for example, has over 5000 people scattered around it. So even though the town itself might be very small, it directly administers hegemony over a much larger population (including the surrounding hexes, so almost 8000 all told), many of whom will have to do business in Andox itself, since it's the best place to get iron tools (among other things).

## August 17, 2018

### Resources VIII: Timbercutting

I need wood references for Demoland.

But how much is a reference? How much can a man cut in a day? At first I tried to base something on how much yield a timber stand can give; this site gives 2000 board feet (24,000 cubic feet) per acre as a rule of thumb. But is that feasible in a pre-modern age? Perhaps with magic, one could harvest a great deal. But that's something we won't consider for now, and certainly won't be available in Demoland.

So that's a lot of wood. If we consider that much of Demoland is forested, and if the available forest depends on the infrastructure, then there are about 12 million acres ripe for the sawing. Even if the yield is only 200 board feet per acre per year, that barely changes the effect.

At that point, it becomes more an issue of the available manpower. The largest timber-producing town in Demoland is Malis, with a population of 604 (also remember that the reference system only accounts for what is collected to be sold, and doesn't necessarily stop a peasant from collecting wood for personal use, although that may be relevant for legal/political/story reasons). Since Malis produces only wood, if we assume that half the men (so ~150 people) are involved in timber felling, then they could potentially average 1280 cubic feet per day each, and therefore 192,000 cubic feet a day as a whole. Assuming the weather is good enough for 75% of the year, that's around 53 million cubic feet of wood. I've defined wood (for now) as 31250 cubic feet a reference - but in light of my new calculations, that seems a little silly. How about a million board feet (83,333 cubic feet) per reference? That gives Malis a total of 635 wood references, a more manageable number. I'll probably use that as the maximum of a randomly chosen amount.

This is the process I expect to go through for every reference. Given the available tools, how much can a place reasonably be expected to produce?

Perfectly consistent, as all things should be.

## August 15, 2018

### Resources VII: Gold Mining

Gold is super rare.

We don't tend to think of it as such because humanity has always sought it out.

Gold has a crust abundance of 3.9(10)$^{-9}$. That's nothing. Also, it means I can't use this number straight up like I did for iron. So I'll try a different approach. By some modern day estimates, there are about 580 gold deposits on earth, about a third of which are being exploited. Let's compare that to the amount of land area on earth and the area of a hex:
${580\textrm{ deposits}\over 57,000,000\textrm{ mi}^2}\cdot 347\textrm{ mi}^2 = 0.351\%$
Not a lot, but a workable number. That comes out to about 300 total mines on earth. I can play with the 580 number also.

Gold will often be found alongside of chalcopyrite (so in volcanic areas), but also occasionally in alluvial deposits (a major source for early civilizations) and then just randomly.

I think what I will do is give it a fairly high chance to be found where chalcopyrite is already being mined, as well as the random chance of 0.351% (or whatever it ends up being) everywhere else.

## August 13, 2018

### Resources VI: Industry

I realized that I had discussed iron working without really talking about how, from an economic perspective, the raw materials get pushed down the chain. Of course, this is accomplished by industries.

This leads to the question of how many industrial references are present in a place? The first consideration is the tech level of the region (not necessarily the individual settlement). Remember that Demoland is T-8.

One of the really common things to do these days is look up the Support Value (SV) of the industry in question and use that as a cut-off for whether or not it's available. I don't really like this for a few reasons. For one, it's all based on medieval France. Secondly, just because you hit the correct cutoff doesn't automatically grant you that industry.

Instead, I'll use the concept of SV as a jumping-off point. Once the population reaches SV, the industry is possible but not necessarily present. A higher population grants a higher chance to acquire it.

We can codify this using the following equation, where $P_i$ is the percent chance that an industry exists, $p$ is the population of the settlement, and $\sigma_i$ is the industry SV:
$P_i(p, \sigma_i) = {p - \sigma_i \over p - {\sigma_i \over 2}}\cdot(p\geq\sigma_i)$
This returns zero if $p < \sigma$. I've also structured it so that if $p = 2 \sigma_i$, then $P = 0.5$.

Assigning the support values themselves is pretty arbitrary, but should be roughly matched to the tech level it's in. Using the example of iron working:

A charcoal burner is necessary to turn wood into the charcoal used in a forge (if coal is available, that will probably be used instead, but I digress). This is a pretty low-tech industry, and it's existed for thousands of years. I'll call it T-6. This level is available from around 170-360 population/sqmi, so I'll choose 250 as the SV.

Ironworking (to refine the raw ore) and blacksmithery (to turn it into something useful) are both a bit higher up the chain, but not too much. T-7 is 360-750, so these two can have an SV of 600. This will make it uncommon, if not super rare. They're specialized skills, after all. In higher populations, though, they'll become more and more common.

Right now, the function given above just returns a chance. If we compare this to a random number, that will tell us if a reference for that industry appears. If we repeat the process for the number of times the SV will fit into the local population (so repeat $n = \lfloor{p\over\sigma_i}\rfloor$ times), this will increase the number of references.

Using that logic: Andox has a population of 1208. Therefore, $P(1208, 250) = 88.5\%$ for a charcoal burner. Since $n = 4$, we can have up to 4 references of charcoal burner here. As it turns out, there are only 2!

Running the numbers for the rest of the cities and industries: Andox has 2 charcoal burner references, 2 ironworker references, and 1 blacksmith reference. Malis and Derl each have 1 charcoal burner reference.

A few things to keep in mind: this system does not capture what people make themselves, only what is available for purchase in the local market. Secondly, this doesn't necessarily mean that there are but 5 people employed in the metallurgy business in Andox - it's merely a number to aid the system. They even might be all the same person!

Even from this, it's obvious that Andox's higher population make it the place to go if you want an item to be crafted with any level of skill. Scarcity creates conflict! Idiosyncrasies also lead to good story opportunities. The illustration here is limited because of the low population size, but Gerlin has no charcoal burners, despite being technically larger. Why is that? Why does Derl, a smaller village, get one? Food for thought.

I wish I had more to offer here. The system is starting to take shape, but I had to throw out all the commodities I'd built up, because the system wasn't nearly cohesive as the one I'm designing now. I had 73 total raw commodities, 165 products, and 42 industries. Not bad. Before diving too deeply into Demoland, I need to add a few things to the system (like currency or food) in order to let it stand on its own two feet.

On the other hand...if I wait for the system to be complete before using it, I could be here a few decades.

## August 10, 2018

### Currents II: Getting Tide of This

I'm so, so, sorry about the pun.

That being said, the current-code is coming along. Eventually, as usual, I found a way to cheat. The only time a current should cross the ocean (at least in the initial pass) is when it's being blown by a very powerful wind, which happens around the Equator and 45$^\circ$. Outside of that, the only valid locations I'm interested in right now are those right next to the coast.

So: check to see which neighboring hexes the water can flow into. If it's valid, go there. If you hit a coast, split.

There are, of course still some issues. For one, the cellular automaton can't seem to figure out what's going on at the folds. This is a pretty common problem for me, but it's the constraint I decided to live with.

 Ah, much better

Once all the coastal currents have been figured out, I'll just interpolate between everything to find out what happens in open water. A gross oversimplification, of course.

Then I'll need to figure out how that affects the on-shore winds and the moisture they carry, as well as where the hot and cold currents are (right now all the colors are red but that's just for contrast).

## August 8, 2018

### Currents I: Current Events

While I'm on a vector kick, I figured I'd tackle currents again. To really, truly model precipitation, I want a better model of where the hot or cold water is. I didn't actually spend that much work on it to begin with.

Most current modeling guides start off the same way. Head west along the equator, split north and south when you get to a coastline. When the current reaches about 45$^\circ$ latitude, it heads back west. If it originates from a pole, it's cold; if from the equator, it's hot. Warm and cold water meeting creates mild currents.

Theoretically that shouldn't be too hard to model. Unlike the wind model, I don't care about current strength, only direction. So I can start off with a set of vectors and propagate them out until the basics are modeled.

Keeping track of each vector is not the hard part; I just have a dictionary to store the angles. So each hex pushes water along its angle to the new target, which does the same on the next loop. The question is, what happens when I hit a coast? As mentioned before, it should split.

But, of course, this is not as simple as it seems at first. This is one of those problems where it's easy to visualize, but harder to implement in code (for me, at least). The code needs to be able to "see" the local coastline (or at least the coastal hexes) so that it can split the current in the correct directions.

For now, I've got the water moving a bit, but it won't split, and it can get trapped in a bay. The algorithm needs a way to "back out" and find an optimal path up the coast. I'm looking through a few options for classical algorithms to solve this problem (like Marching Squares or a walking algorithm).

 Good

 Not good
This stuff will also be useful once I extend the route finding code to the sea. It will be cheaper/easier to follow a current than to fight against it.

## August 6, 2018

### Wind I: Spirit of the Wind

I love what Here Dragons Abound did with wind. I want to do that, perhaps adding it to my pressure model.

Mainly, this will help with my move away from hand-drawing the rain. If I know where the wind is blowing, I can model the rain, yielding better results.

Once again, the primary source of my frustration is the sector rotation. It's hard to think in polar coordinates sometimes.

I applied a constant wind at an angle of 135$^\circ$, just for testing. The velocity is 25 knots, which is pretty high. I found a source showing a sea breeze strength of a max of 5 knots. No matter.

There are a few more rules for spreading the wind across land:
• Every time a wind is propagated, it loses 10% of its strength
• If it goes downhill, it gains some of that back depending on the slope
• If it goes uphill, it's deflected up to 90 degrees. I use a logistic function to make a nice smooth transition, using $K=90$, $P_0 = 1$, and $r={\ln(89)\over 2400}$. The rate is one of the settings I'm playing with to get a good result. The 2400 is the change in altitude where the deflection angle is 45$^\circ$. So if I want winds to make it higher up a slope, I make this number bigger.
• I talked about vector projection/rejection here, and I found that the best model for the wind is to use this to project the wind along the direction of the target hex. This "splits" the wind between the three hexes it's pointed toward the most.
• Everything gets added up using vector notation. At first I thought this propagated stuff forward too much but it seems ok after a few bugs were worked out. And I'm not using real data so that can affect things.

The wind barb notation shows the direction and strength of the local wind:

It's off to a good start. I'm going to think a bit more about the pressure systems so that maybe I can figure out how to integrate those into the model. There's also much tweaking to be done to get results I'm happy with.

Once that's done, I can move on to pushing moisture around.

## August 3, 2018

### Neon

The new tectonic map is pretty, if nothing else. However, pretty is about all it's good for, unless we keep in mind that each RGB color is a 3D map of the influences of convergent (red), transform (green), and divergent (blue) fault lines.

So I can take this and make a new uplift map. Convergent boundaries are strongest, transform boundaries will still form some mountains, and divergent should lower the terrain.

This map is infinitely more useful, as it shows what areas are likely to become mountains. I can play with the decay, of course, but I'm having so much trouble with the erosion model that I think this will do for now. No sense in changing too much at once.

Additionally, I see that the edge of the middle continent doesn't quite line up with the rift valley. This happens, of course, but I need to account for it by dropping some of that coast below sea level. Africa is a good example of this: there are several large lakes above the faults, where the earth is ripping apart and water is pouring in and seeping up.

## August 1, 2018

### Resources V: Iron Working

So now we've got raw iron ores. What do we do with them?

The first thing to do is extract the actual ore itself. Usually, the rock is crushed and the not-iron is removed. I've illustrated this product as "iron ore," which could be a combination of any of the four ores.

Next, we need a heat source. Most often throughout history, charcoal has been used, but coal is also an acceptable source (I've not included coal on the chart). It's used at every step of the process.

The simplest refined iron is sponge iron, which is created in bloomeries - charcoal furnaces that cause the iron to "bloom." If you have a bit better technology, you can make pig iron instead.

Pig iron can be turned into cast iron. Manganese and nickel are usually added to improve strength.

Both pig and sponge iron are used to create wrought iron. This is what we want for weapons, at the very least.

Wrought iron is finally turned into steel, with the addition of some extra charcoal, manganese, and nickel.

The chart is organized according to tech level (or development) and "stage." To correctly loop through every available resource, I've separated the products into these stages. Raw materials are always Stage 0. Higher stages usually mean higher complexity, but not necessarily higher tech level. For example, steel needs to know how much wrought iron is available, so all the wrought iron references need to be calculated before steel can be determined.

Whenever there are multiple paths for a recipe to take (e.g., charcoal/coal, goethite/hematite), I either take the cheapest one or the average.

One thing I'd like to add to the chart is the unit of each source required to move to the next step. I haven't talked much about my recipe system, but each complex commodity has instructions that determine how much material and labor cost is necessary. For example, limonite is about 55% iron, so you need ${1\over0.55}\approx1.8$ pounds of limonite to get 1 pound of ore.