First:
Basic price algorithm:1) Each entity has sets of RAWs that dictate things they need, such as
[NEEDED_GOOD:BUILDING_MAT]
[NAME:Building materials]
[AMOUNT_PER_YEAR_PER_CAPITA:5] (units are abstract, bear with me)
[OPTION:BUILD_LOGS:2] (the "build_logs" is a special tag. It corresponds to [PRODUCTION_CLASS:BUILD_LOGS] tags included in any material definition tokens that you want to qualify for this type of good (in this case, you'd put it in all the tree structural material definitions, for all species that seem reasonable to build with). After that is a number meaning it's relative desirability for this purpose. Different options can be swapped, and will be swapped based on relative desirability.)
[OPTION:BUILD_STONE:5] (stone in this case is more desirable for building for example. They will prefer stone as long as its cost is less than 2.5x as expensive as wood in this example.)
etc.
[NEEDED_GOOD:FOOD]
and so on
2) Each entity also has RAWs for production of resources. Level of production takes into consideration these raws, and also of course the amount of that resource in the given settlement, and current world prices
[CAN_PRODUCE:BUILD_LOGS] (matches up with name fields above)
[MAXIMUM_PER_YEAR_PER_CAPITA:7] (total amount woodcutters can actually work IF there is a surplus of trees. This doesn't dictate amount of wood, just maximum production
[AVERAGE_STARTING_VOLUME:7000] (an average AI-sized settlement is defined as starting out with this much wood. This is matched up to an estimate of the actual average prevalence of things with [PRODUCTION_CLASS:BUILD_LOGS] in an average embark during worldgen, in order to algorithmically come up with an abstract unit <--> actual item conversion rate. So a site with an average number of trees in worldgen has 7,000 "units" of trees to begin with. A site with half the average number of trees has 3,500 units, etc., automatically)
[RENEWABLE:100] if tag is present, units will replenish themselves each year at a rate equal to the number written here per year, up to the original starting volume maximum. A site with double the average number of trees will replenish 200 a year, etc. If not present, there's just a finite amount available, period (metals)
[CHANGING_COST:1.2] How much it costs extra to mine more of the resource for every power of 1/2 the amount of the world average you start with. If you have 1/4 the world average, it costs 1.2*1.2 = 144% to mine each unit for that settlement compared to somebody with world average amounts. If you have 4x as much as average, it costs 1/1.2/1.2 = 69% as much to mine as somebody with world average amounts.
[COST_PER_UNIT_TO_PRODUCE:2] (number of dwarfbucks it costs to gather one unit of logs in terms of time/effort/equipment/skills, etc.
It doesn't matter that you don't literally pay woodcutters. (re: Goblincookie's inevitable complaint) This is an economics
abstraction equal to the value of that effort, i.e. basically what you would hypothetically pay an imaginary third party to come in and do it on site if they expected no profit.) By having this in entity raws, different races can gather stuff more efficiently, I.e. elves get wood easier, dwarves get stone easier, etc.
[CAN_PRODUCE:BUILD_STONE]
(and associated tags)
[CAN_PRODUCE:ABOVE_PLANTS]
[CAN_PRODUCE:BELOW_PLANTS]
etc. etc.
[PERISHABLE] is also a tag to add to materials now. If they have them, the goods only last a year for global trade, and go poof if unsold. See below.
3) Every year, Use the above information + a site's available resources + its population to figure out the baseline production levels and consumption levels for each settlement.
4) Make adjustments to baseline values of production or consumption based on whether there's a war on, or a climatological situation causing crops to do poorly, or whatever (see list below)
5) Automatically "trade" any matching needs and productions within the same settlement, for free.
6) Determine prices of goods based on supply/demand of each individual pair of settlements and thus what each party would profit (ignoring caravans)
7) Make any adjustments for "strategic value" of the relationship between those settlements, which can add additional subsidies or whatever. Also can add on compulsory taxes and so forth. Also any adjustments for irrationality with dice rolls. Whatever. Various special types of adjustments discussed throughout this thread.
Subtract the cost of a hypothetical caravan between each pair. Subtract this value temporarily from each individual profit margin. See if any of them still remain positive. Take the highest positive result and actually now simulate that settlement sending out a caravan and trading with the relevant neighbor.
9 ) Adjust the production and consumption values to reflect the trades that were just made and subtract some sort of set of resources for the caravan costs (could always be some same set of stuff overhead + another set of stuff * distance, ideally defined in raws. Like a bit of wood, a couple animals, and some food and booze, lowering of production that year to represent loss of labor while they're trading and population requirements and such). Have some chance of the caravan being killed on the way and the sending settlement simply losing all their stuff and dwarves with no trades occurring. Can depend on if at war, etc.
10) Now go back and repeat #6-9 repeatedly, until #8 yields no more positive values. When it doesn't, stop. Trades are now complete for the season.
11) Anybody who didn't trade has their still-unsatisfied needs and unsold goods carried over to the next year. [PERISHABLE] goods go poof, and those settlements re-adjust their production investments of perishables for next year to be more conservative if they wasted some this year.
12) If certain needs pile up too high without being satisfied, settlements can collapse. Like if food needs get too high per capita, population starts getting reduced (fun bonus: you can have a cannibalism ethic that if acceptable, population decrease also lowers the outstanding food need...). If other needs go unsatisfied, the settlement might not collapse outright but may suffer other challenges (lack of building materials = can't expand, for instance. Lack of weapons = more likely to far poorly in battles, etc.). This might just require a whole mess of special tags in raws, not sure how else to do it better.
13) Player trading is treated just like every other kind of trading, except during the cycle of steps #6-9 repeating, if the player is involved, the cycle stops and waits for the player to actually experience that caravan in-game before calculating the remainder.
My edits in orange. Lots of them are just being careful about terminology. "Demand" means a very specific thing - i.e. the demand curve. Not the same as consumption (actual number of things sunk) or relative desirability of different materials -- both of which drive demand. Demand (and supply) are law-based, shouldn't be adjusted directly.
I'm also not clear on why you had two separate headings for that post.
Things affecting prices
- Famine raises demand for lowers production of food
- Good harvest year crashes demand for raises production of food
- War raises demand for consumption of weapons and armor and ammo and probably other things like war animals, anvils, siege engine parts, trap components, splints, crutches, cloth, etc.
- Prosperity and urbanization raise demand for consumption of art
- Metal demand affected by war also accounted for already by consumption of end goods, don't double count.
- Building material consumption affected by age of settlement and whether it just recently expanded in size category on world map
- Luxury good consumption affected by wealth of settlement.
- Most things ALSO (in addition to other notes above) affected by population, of course.
- Fashions to influence prices relative desirability of different materials for various goods (initial/default in the RAWs per entity, adjusted a little bit to either side for fashion over worldgen) and relative consumption of different luxuries (same)
- Cultural associations (ie. purple symbolizes nobility, gold symbolizes royalty, etc) to influence prices of different materials in long run
- Recipes go in and out of popularity in the short and long term, influencing prices of types of food
I'm not addressing implementation obviously, because we already disagree there.