Thursday, October 26, 2017

Recipe - Faering Hull

The recipe presented in the last post is of a small size. Many recipes require much more calculation than soap does (though recall that the definitions for the other recipes that go into it also required their own calculations.)

In this post I'll included screenshots of all of the calculations for the "hull, faering" recipe. I believe this is the largest recipe so far, both in terms of calculation and in number of sub-components.

A faering is a type of rowboat. Since this recipe only calculates the hull, the boat is not complete: there are no seats, no oarlocks, and no oars. Still, there's quite a lot to see, and I'm restricting myself to only those items which are directly being used in the faering hull. I'll show rivets, for example, which are made of copper, but I won't then go and show the copper recipe.

OK. Here is the faering hull itself.

You can see that the faering is composed of many shaped wooden pieces, some of them steamed, and that it is held together with lots of caulk and rivets.

The quantities of these components are calculated in the lengthy sequence starting at the top of the screenshot. It should be pretty readable. I would go into it here but I've been chipping away at this post for a week or two and I just want to get it out there.

Having seen what pieces the hull is made of, and how many of each piece we need, we can look at how each of those pieces are defined. First come the recipes for rivets and caulk, which are used to join the wooden pieces together.

Second and last, we have the wooden pieces themselves. You can see how some of them are immediately used as components in "steamed" versions, which (as seen above) are the ones which actually show up in the hull recipe proper. These steamed variants represent the woodworking technique of clamping a piece in place and then steaming it so that it will hold the shape it currently holds. This is used to achieve the curved sides of the strakes which make up the bulk of the hull.

One minor note: "semiGoods" is the name of the list of trade goods which are not considered finished products. Thus, although their prices get evaluated, they are not ordinarily displayed for sale on the trade table.

Saturday, October 7, 2017

The Recipe System

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!