Previous posts have addressed the establishment of references to raw materials ("mats") and to various types of artisan, craftsman, and laborer ("services") in the game world; the manner by which importing is done from city to city so that each one ends up with at least a little bit of everything, both mats and services; and how an increased distance from a source for a mat or service X lowers its availability and thus increases its price directly (mat) or increases the price of all goods which are created by a given type of worker (service.)
What we are still missing, however, are the components of the economy system which take us from the finished import step (where the relative availability of mats and services is known for each city) to the price tables which I have posted here (for the most recent version, see this page.)
Those components are the recipes themselves and the algorithm by which a recipe's price is determined. This algorithm takes into accounts the mats and other recipes that go into the recipe, and the service that creates it.
Let's start by examining the structure of a recipe: that of a bar of hard soap.
The name of the recipe is self-explanatory: this is hard soap.
The first item after the parenthesis following Recipe is the type of service which produces this recipe. This is the chandler, who makes items from fats. (Come to think of it, I don't have candles in the system yet. One more thing to add.)
Next, we have a tuple consisting of the variable weightOneBarSoap and the unit, "lbs", by which its weight is measured. "weightOneBarSoap" is calculated by multiplying the desired volume of the bar of soap times the density of tallow. I use the density of tallow for that calculation because it's the principal ingredient in this soap recipe and thus it's OK if I use it as a proxy for finding the actual density of the soap mixture. This stuff doesn't have to be perfect.
Next we see two lists, denoted by square brackets. Each list is made up of 2-tuples, with the first element being a name, and the second being a quantity of the material named.
The first list is of the raw materials ("mats") which go into the recipe. In this case we only have salt. You can see that the amount of salt is calculated on the basis of how much tallow is used and how large the finished bar of soap is. If the bar were 1 pound exactly, we could eliminate the latter factor.
The second list is that of the other recipes which go into the soap recipe. Most manufactured products are not made solely from raw materials. Instead, they are composed of other, less-complex manufactured products. Therefore, recipes can be recursive: they contain other recipes inside themselves. (Eventually all things lead back to raw materials, or else there would be no end to the chain of recursive calculations.)
Finally, we have a description which gives additional details. Other recipes also include units in addition to their weight (for example, lengths of yarn give the number of feet per one-pound bundle.), and difficulty (something I'm still working on fine-tuning). The default difficulty is 1.
In the above image I've left out some of the calculations which go into the soap. Below I show all of them. You can imagine how lengthy a more involved recipe gets. Let me know if you'd like to see anything else from the trade page.
I'll stop here for now: if I kept writing today, I wouldn't end up posting at all. I'll discuss the algorithm which interprets a recipe in a followup, but the basic details are simple: find the price of all the raw materials and all the sub-recipes. Sum them together. Multiply by a factor which gets larger for recipes with a higher difficulty and if the service which produces the recipe is scarce in the town for which the price is being evaluated. Done!