Okay sorry, I should be more explicit and clear. This is relevant to both/all our plans, and I've been dancing around it too long and procrastinating, so I'll just dive in.
Supply and Demand MechanicsOkay so first, terms:
"Demand" is a willingness to pay for something. However, this is not a constant amount for a good, but changes along a curve, seen below. Supply is the willingness to produce something at a given price point, and also changes along a curve. For our purposes, think of the demand curve as "price as a function of quantity" and think of supply as "quantity as a function of price."
So this is the basic vanilla situation. Demand is a curve, as shown, that depicts how much you're willing to pay for something at any/all possible quantities. Usually in real life, it's not a straight line like that, but would asymptote as it approaches the X axis (though it certainly CAN intersect), but don't worry about that too much just yet. Price is effectively how much producers will produce when tempted with different price points. More $$ encourages them to produce more to take advantage of the greater profits.
The price something will actually settle at in equilibrium is at the intersection point of the two. For purposes of our game, we can just literally use the intersection for the most part, and not worry too much about the process of it actually getting to equilibrium or all the nuances like how tariffs change things and all that BS.
How do we get these curves in DF? Well, there are a couple possible solutions to this.
Direct decision of the whole curve: You could just say "these are what the curves are" by having algorithms that entirely specify the whole curve directly. This MIGHT be simpler than other options -- if it looks like you'll get bogged down in defining the curve other ways OR it might be more complex -- if there is some simpler alternative for defining a curve with an equation or something, you probably want to go with that. You can think of this as directly defining dozens or hundreds of individual price points.
By using a few scalar values and making a curve from an equation: In this case, you might define some sort of nebulous "utility" value representing how generally useful a good is (based on anywhere to few to huge numbers of factors), and then also something like an "elasticity" value for each good, which is a value that measures basically "how much it makes sense to own multiples of this thing" or in other words "how much does demand change as price does" or in other words "the slope/curve of the line" Then using these two things plus a couple assumptions, you can fudge a passable curve dynamically generated for the trade system. Instead of defining "every" value for the line (first option), this is more like defining a line by only a point and slope, in your high school algebra class.
The more I think about it, the more I think that the DIRECT curve definition is actually the easier method for us... probably. So what would you need to do that method?
Broad Algorithm in General:1) Set out some specific general shapes that seem reasonable for different types of goods.
2) Define necessary "control points" boundaries, asymptotes, etc. that are easy to individually calculate in the program and roughly draft out the boundaries of the desired curve.
3) Then use something like Beziers
http://en.wikipedia.org/wiki/B%C3%A9zier_curve or whatever your favorite curve fitting method is, to make an actual curve based on your control values/boundaries
4) Interpolate the curve for every actual quantized unit that can be traded, and you have yourself a game-relevant demand/supply curve!
5) Figure out where they intersect for two specific trading partners.
6) Do something sort of like GoblinCookie's ordering of important goods to decide which things get traded (recalculating in between).
Starting out by discussing #1 and #2:
DEMAND:This is very subjective. Lots of things could increase the "utility" of a good. It's just how much the buyer is driven to own it. You could want something because it will help you to survive (grain), but you could also want something just because you have a fetish for it (maybe the noble's material preferences) and you just want to roll around in a big pile of it while drooling, or you might want it to satisfy some other desire, such as revenge. How many or few of these things we simulate is a matter of opinion and how complex you want it to be.
Each type of good should generally be assigned to one of these types of things, although again, you could always make it more or less complex.
Y axis here is in "cost" units -- if you want, imagine that 1 cost unit = one hour of dwarf labor. Here are some possible examples, though.
Each curve below is not the final curve. it's just that aspect's contribution/initial input to the final curve. Any of these could/would be further tweaked up or down or by slope based on stuff like "material preferences of dwarves in the site" or political mandates or other modifiers before being used to actually determine final prices1) Survival value -- Example FOOD. If a good is needed to sustain life, then buyers are going to be willing to pay pretty much everything they own for it up to the amount that they need to survive. Once you get past that, they will start to be willing to pay less, but the curve will have a long tail to it, representing the fact that it's
always nice to have backup stockpiles of survival essentials like grain, almost to infinite quantities. The survival contribution of a good might look something like this:
*Note: the curve is not entirely vertical in drop, because the morbid reality is that a few dwarves starving to death is not actually the end of a fort, necessarily... but still, they really want to avoid that.
You could model this curve by basically defining a few individual parameters, and then fitting a curve to them. You'd need "amount of wealth the fort has in non-survival goods" and "how much they need to survive right now" and a parameter for something like "how hoard-y/paranoid are they about having stocks on hand" and then finally, some sort of "how tasty is this type of food" parameter (quality of food doesn't matter for the left side of the curve, but does matter for the middle and right, where it will taper down much more slowly).
2) "Luxuries" I.e. generally nice things to own that aren't necessary for survival -- Example FURNITURE (also clothes, gems, etc.). "Luxury" is a very loose term here. "End user products that don't produce anything or keep you alive" if you want a more accurate term, which includes what you'd think of as actual luxuries, but also stuff like pants. Dwarves want these things, but they will never be
desperate for them. Also, the curves drop down to zero or near-zero more quickly than grain, because backup stockpiles of chairs are not quite as good to have around as backup stockpiles of grain:
As you can see, this one can be vastly simpler to model. You basically just need a Y-intercept, which is going to be based on the general quality of the furniture, and then a slope "how much or little extra pieces of this furniture are" and you can make curves like this dynamically.
3) Industrial tools -- things like picks, axes, anvils, buckets, barrels, pots, maybe mechanisms? and also just metals like iron. Iron here is being abstractly conceived of as things like "chisels" and stuff that the game implies are used in stuff like carpentry shops, even though they aren't explicitly in the game. Tools are things that aren't just "nice to have" but that actually help produce additional wealth for you, thus interacting in special ways with the economy.
What I suggest for these is that the game keep track of an abstract "amount of tools" a settlement has for each individual industry. No specification. It's not necessary to actually keep track of which tools are used for which industries, but you could do that and it would be better. The current amount of tools is used elsewhere in the supply side algorithms to act as a bottleneck for how much a settlement can ramp up production. So the major driver for
demand for tools = how much below the desired level of production the settlement is, based on the prices they are seeing for things they can produce in different industries. If they are already where they want to be, they will have (almost) zero demand (still a demand, because hey, if you can get them super cheap, why not save up for future contingencies). If they are currently tool-limited, they will have fairly high demand, although the demand can't go above the rates at which it would be unprofitable, because that defeat the whole purpose:
Necessary values needed to generate this curve all shown in the graph. You get the idea by now.
4) Building Materials -- These work exactly like industrial tools, and the curve looks sort of the same, except that these are needed to expand your population higher, so they're influenced by that instead. Instead of your desired production ramp-up driving it, it's whether or not you are currently limited by building mats for your population growth. If so, you'll pay actual reasonable values for them, or even slightly higher depending on how strapped/desperate you are (same left side slope concept as above). If you aren't limited, you'll only demand bargain basement prices from desperate sellers, otherwise you won't bother.
5) Medical? -- Kind of a special category because it's sort of like survival gear, but isn't strictly about survival. I'd draw the curve for this as something approximating the "luxuries" curve by default, except with the possibility of becoming more like the food curve temporarily IF you're in a time of war and just suffered a lot of casualties, or if your fort is ill or whatever.
6) Defense -- Just like tools and building materials, except instead of driven by desired production increase or desired population increase, it's driven by:
a) desired army/police/etc. size increase. Which is itself driven by obviously whether you're at war and whether that settlement is actually trying to build an army right now.
b) recent battles -- win or lose, a recent battle creates a directly applied need for war goods and thus if you don't have enough already, can create a shortfall that will make a little "shelf" like in the above curve under the tools section.
SUPPLY, RAW MATERIALSThis post is taking too long to write, but i'll keep my draft inside of a spoiler if you want:
Again, there are different broad categories, used to determine the algorithms for approximating a curve, and for how many/which parameters the code asks for. But then as with demand, the literal actual curves for each good are calculated on the fly every round of trading. The main numbers that matter for any good are:
- Labor availability
- Tools on hand (matters more or less, depending on the good category, see below)
- Current production level
- The market situation - is it profitable to scale up? Or down? Or stay where you are?
- How much of the actual stuff is on hand
Things that are farmable (plants, livestock goods) -- These things are not only renewable, but the settlement can intentionally increase or decrease the degree to which they renew (by setting aside more or less farmland or pastures or whatever). Ramping up production is not very tool-limited, and is instead primarily geometrically limited - i.e. based on how much of the stuff you have available in stockpiles. For example, the more grain you have on hand, the more you can plant next season. The more cows you have, the more you can increase the herd in a season. If you have very little grain or cows, then you are limited in how quickly you can expand your fields or herds -- even if it would be very profitable to double the herd, you may only be able to increase by maximum 30% a season or whatever.
Things that grow/renew but not (trivially) artificially farmable (trees, fish, non-domesticated animal goods, silk, etc.) -- These things will never run out, but it is difficult or impossible to ramp up production beyond a limited point, no matter how much profit could theoretically be made from doing so. Ramping up to a certain point is easy, and just requires a moderate amount of tools, but then the industry hits a brick wall. Also, the renewability of the resource will usually decrease (slower regeneration) the higher your exploitation of it is, unlike with farms.
Non-renewable resources (primarily minerals) -- These things are finite in quantity, and also have high tool requirements for ramping up production.
SUPPLY, MANUFACTURINGhaven't gotten to yet.
(needed subsection: how to decide how many raw materials to manufacture into stuff versus keeping them to sell or use them raw)
CURVES AND CURVE INTERPOLATIONSELF TRADE AND CARAVAN DETERMINATIONORDER OF TRADE