Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: dwarf nutritional vectors v0.2  (Read 2254 times)

Bogus

  • Bay Watcher
    • View Profile
dwarf nutritional vectors v0.2
« on: March 30, 2016, 06:39:51 pm »

this is a second prototype, with a much more complex system and some other improvements. (the gist of what this about: making feeding your fort (much) harder and more interesting by giving food different properties and making units eat more.)

* not only item types but materials are now considered. item types have a base value, materials are composed of different types of nutrition (fat, protein, complex carbohydrates, sugar, fiber, water, alcohol).
* each of these types modfiy the base value and have different effects on the unit's hunger, thirst, stomach content/food and body fat values. for example, a PLANT_GROWTH of base value 8000 that is composed soleley of fiber will reduce hunger by about half that amount, but actually burn fat, and put a lot of useless material in the stomach. an egg with the same base value will decrease hunger by about 6000, while taking up less space in the stomach(but adding more nutrition to it). a sugary treat of the same size will cause the unit to put on some extra weight, and put enormous amounts of nutrition into the stomach, while taking up only little room.
* materials are ordered into groups tied to several plant/creature tokens, such that a group of species shares nutrition values for their materials. example:
Spoiler (click to show/hide)

using this system, no raw modfification at all is necessary, all the data is read from the table. in addition there is a set of default values for common material tokens (LEAF, FRUIT, MUSCLE, BRAIN, DRINK, ...) so this will work with pretty much any set of raws.

* no longer causes dwarves to eat more often, instead units will eat several items in a row until their hunger threshold is reached. to facilitate that, the hunger/thirst counters are stored and only written into memory after several jobs were completed.
* immoderation has a strong effect on the unit's subjective feeling of hunger. dwarves will eat up to 33% less or 88% more than their hunger would dictate. this, together with the above changes, will lead dwarves to go on massive binges, some more so than others. immoderate dwarves will grow fat and lardy (this requires further testing tho).
* this doesnt quite work so well yet with drinks, mostly because the alcohol syndrome isnt made for it (and the base value for drinks is fairly low, a beer gives about 1/5th of the normal value). dwarves will frequently drink until theyre unconscious, and then immediately drink again when they wake up.

stuff:
- drink water, give water, and serve drink are not yet implemented
- in future versions, there will be more counters that need to be stored and updated, like vitamins, etc. currently im using persist-storage to track jobs, but i am not sure it will be fast enough to update ~200 units and their counters every tick?
- is editing syndrome severity in memory feasible? do alcohol effects from multiple sources stack? i could base the alcohol effects on the alcohol content of the drink directly, if i edit the syndome after it is applied. this way there is no need for multiple alcohol templates, and it is more granual.
- stomach_content doesnt seem to do much, it just goes up to 300000 but doesnt seem to stop dwarves from eating. its conceivable that eating a lot of fibrous stuff without any nuttrition actually is dangerous.

code:
Spoiler (click to show/hide)
« Last Edit: April 05, 2016, 05:48:23 am by Bogus »
Logged

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: dwarf nutritional vectors v0.1
« Reply #1 on: March 30, 2016, 09:46:27 pm »

I'm not sure strict food value is a good way of measuring how nutritious something is.  It tends to be based upon creature rarity more than actual value as a meal, so an equivalent mass of alligator meat is three times as "nutritious" as common turkey or cow meat.

Also, right now, all you're doing is "calories"?

If you want a content suggestion, even though this might be leaping ahead a bit, I know I've read (and participated in) plenty of nutrition models in the suggestions forums.  Depending on the level of detail, there have been fairly detailed vitamin-based suggestions, down to having a few nutrition attributes that need balancing.

I would suggest looking at Elona's food system, where eating different foods would "exercise" different stats, such that eating fruit (or meals cooked with fruit) slightly trained Perception, Charisma, and Magic, while eating (non-fish) meat trained Strength, Constitution, and Charisma.  ("Masterwork" cooked foods giving about 4 times as much training, and "unquality" giving half.)  These were fairly small amounts, it takes thousands to level a stat, but you eat frequently.  Certain special creature meats gave additional bonuses, like horse meat training stamina or slime "meat" training charisma (supposedly being "good for the skin") by an additional 500 points.

You could do something similar, causing attribute training to strength when eating high-protein foods, or attribute training to Spatial Sense and Analytical Ability when eating omega-3 fatty acid foods like fatty fish (tuna, salmon, etc.). As a negative, you could start causing stress and bad moods or even some sort of syndrome to reflect critically imbalanced nutrition.

To "balance" additional attribute gain, you might want to make attribute rust faster, or have some sort of external attribute decay.

That said, it would be up to the dwarf's current decision-making what they eat unless you make additional changes to the plugin that would give a scripted control over what dwarves eat to try to guide their diets. (Possibly giving players a chance to set suggested diets for different classes of dwarves, and telling some dwarves they need to go carb-free...)  You might even want to include some method of guiding the ingredients that go into the roasts for more balanced meals.

... I'm sure that's way more than you wanted as an immediate response, so I'll restrain myself at this point. 
« Last Edit: March 30, 2016, 10:40:48 pm by NW_Kohaku »
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

expwnent

  • Bay Watcher
    • View Profile
Re: dwarf nutritional vectors v0.1
« Reply #2 on: March 30, 2016, 10:52:09 pm »

Interesting. Posting to watch.
Logged

Bogus

  • Bay Watcher
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #3 on: April 02, 2016, 09:35:23 am »

thx for the feedback. making more types of nutrition, including vitamins and minerals was definitly planned. also syndromes / stat changes for good or bad supply with these. the new version i made (in the initial post) now has different types of nutritients, but its still uses the basic levers that the game supplies, ie hunger, thirst, etc. i could expand a bit on that with exhaustion and sleepiness (say, eating&digesting a number of  elephant roasts would be a really, really laborous venture and as such make the dwarf in question sleepy). i think the game may already be doing that tho?

otherwise, for vitamins and such more counters are needed and these have to be stored somewhere between saves/loads, which makes it complicated. unsure if the persistent storage is fast enough to track 200 dwarves' counters every tick.

changes to physical attributes with diminishing returns would be a good way to bring weak dwarves to a ceratain floor of capability using a healthy diet, while not getting op on the upper end. so say after a year or two of eating really healthy a dwarf in very bad shape would be in okish shape.

regarding the food choices, this system is planned to go with a farming&cooking mod, so there is a bit of control over what meals are composed of. but a bit of ranomdness is ok i think, it should not be too easy to get all your dwarves to eat healthy.

« Last Edit: April 02, 2016, 09:42:19 am by Bogus »
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #4 on: April 02, 2016, 03:43:48 pm »

Persistent storage is getting an upgrade in the next version. It will be a non-issue at that point but you should still make your script run only every hundred ticks or so.
Logged

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #5 on: April 02, 2016, 04:10:37 pm »

Dwarf attributes are trained the same way as skills, with increasing cost per point, but much, much slower, already.  (Although this is probably simply a function of being a much larger integer to start with - you don't notice the difference between 1000 and 1001 as much as you notice the difference between 2 and 3, especially when 2 and 3 have different names, but 1000 and 1001 don't.

Also, attributes have hard caps at either double the "birth" attribute or 500 + birth attribute (higher of the two), or 5000 if "birth" attribute was 2500+.

As such, you don't need to worry too much about adding diminishing returns, because they're already somewhat baked into the game.

Also, starving dwarves will consume body fat upon reaching max hunger, and fat is increased with stamina, so that's something to consider.
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #6 on: April 02, 2016, 06:03:27 pm »

or 5000 if "birth" attribute was 2500+.

AFAIK there's no hard cap like that--saiyans in Sparking will get up to >10,000 in various attributes without issue.

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #7 on: April 02, 2016, 06:15:38 pm »

or 5000 if "birth" attribute was 2500+.

AFAIK there's no hard cap like that--saiyans in Sparking will get up to >10,000 in various attributes without issue.

Odd, then why is it treated as such in the raws? I remember that races with 5000 memory as min and max were treated as "perfect memory". Is this a new version thing?
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #8 on: April 02, 2016, 06:23:07 pm »

That's the maximum minimum, not the maximum maximum.

Bogus

  • Bay Watcher
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #9 on: April 03, 2016, 06:35:04 am »

implemented give food jobs. does anyone know what "GiveFood2" and "GiveWater2" jobs are, are these tavern jobs, animal feeding jobs, prisoner jobs?

and if they are not tavern jobs, which are these? do units receiving drinks from a barkeeper use the normal drink job, after they have received the item containing the drink?
« Last Edit: April 03, 2016, 06:39:58 am by Bogus »
Logged

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #10 on: April 03, 2016, 12:11:55 pm »

I can't help with that question, unfortunately, although it seems possible that "wait for a drink", "serve a drink", and "drink it" afterwards are all different jobs, as is hospital "give water".

Something I wanted to mention, though, was that in some of the older nutrition threads, character "calorie burn" was always the same, no matter what creature.  For dwarves of roughly the same size and activity level, this need not be so pressing, but if you have wildly different civilized creatures, or start feeding animals, you start to see problems.  I suggested hunger (for both FPS and systemic reasons) no longer be a hunger++ per tick system, but increase by a factor of size and metabolic/activity qualities. (I.E. cold-blooded creatures moving slowly stay full longer.)  This would mean creatures are on a scheduler where every, say, 100 ticks, they may gain 100, 150, 20, or whatever hunger based upon factors of how many calories it takes to keep them going, such that if the player has a sperm whaleman in the fortress, they eat more than a dwarf.

Toady, when he introduced grazers, actually did this backwards, which meant that grass "calories" were inversely proportional to size. (To the great detriment of elephants and other multi-ton creatures.)

Either way could work, although I suspect Toady's "backwards" method of a "size dilutes" food may be easier to implement.  You could still try to include some factors, like if a creature is fatigued, they burn calories faster, while a resting or sleeping creature might have a lower calorie burn (a check and retroactive changing to an assumed 'correct' calorie burn rate that only tests occasionally).
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

Bogus

  • Bay Watcher
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #11 on: April 03, 2016, 01:44:55 pm »

i do like the size version for its simplicity. activity level is already somewhat implemented in the core game, dwarves will put on less fat if theyre doing stuff, even when their stomachs are very full. this wont impact hunger levels tho.


Logged

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #12 on: April 03, 2016, 01:58:14 pm »

i do like the size version for its simplicity. activity level is already somewhat implemented in the core game, dwarves will put on less fat if theyre doing stuff, even when their stomachs are very full. this wont impact hunger levels tho.

The main reason I bring up metabolisms is that they are different between different species, however.  Cold blooded creatures are more efficient with their energy, since they warm their bodies through external sources. Meanwhile, among warm-blooded creatures, there is an "efficiency of scale" to warm-bloodedness with greater proportional volume to surface area meaning homeothermy is easily maintained with simple body mass.  Small birds burn much more energy relative to total mass than nearly any other creature with their tiny bodies losing heat while flapping furiously to fly.
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

Bogus

  • Bay Watcher
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #13 on: April 05, 2016, 05:50:50 am »

updated code in initial post, fixed a bug or two and did some tweaking. also removed all the debug stuff and cleaned up code.
Logged

Askot Bokbondeler

  • Bay Watcher
  • please line up orderly
    • View Profile
Re: dwarf nutritional vectors v0.2
« Reply #14 on: April 18, 2016, 10:31:24 am »

ptw