Cataclysm-dda: Question: comestible json values per whole or per charge?

Created on 6 Aug 2020  路  13Comments  路  Source: CleverRaven/Cataclysm-DDA

I am confused about how charges impact the properties of a comestible.

If something has a weight 2 g and 2 charges and vitA: 5 - does that mean each charge conveys vitA 5 and weighs 2 g or that the whole thing does and thus an individual charge will weigh 1 gram?

Or here is an example:

  {
    "type": "COMESTIBLE",
    "id": "spinach",
    "name": { "str_sp": "spinach" },
    "weight": "139 g",
    "color": "green",
    "spoils_in": "8 days",
    "comestible_type": "FOOD",
    "symbol": "%",
    "quench": 2,
    "healthy": 1,
    "calories": 30,
    "description": "A bunch of spinach leaves.",
    "price": 100,
    "price_postapoc": 50,
    "material": [ "veggy" ],
    "volume": "2250 ml",
    "charges": 5,
    "fun": -2,
    "flags": [ "RAW" ],
    "vitamins": [ [ "vitA", 53 ], [ "vitC", 13 ], [ "calcium", 3 ], [ "iron", 4 ] ]
  },

If I eat one charge of spinach do I get 30 calories or only 6 (30/5)? (Answer: ~6)

I've tested haphazardly and it seems the answer is "per charge" not "per full item" but I would love confirmation because...

The json does not seem to handle this consistently; some comestibles seem to assume per charge and other per whole. Which I'd love to fix if I could get someone to verify the answer for me. I'll owe you a beer.

<Question> stale

Most helpful comment

Maybe we should move all these values to per charge. Volume per stack in particular was causing rounding errors that cause containers to be filled one charge less than its maximum volume (and still is if you partially fill a container and then completely fill it). Of course for a smooth transition we may want to add a new json value rather than modifying the previous value.

All 13 comments

someone on discord wrote:

"I believe mass and volume are for the whole item including all charges, and calories are per charge, but I would have to check"

I'm going to go do another check now.

Whichever turns out to be true, really REALLY should be noted in JSON_INFO.md. Contributors were confused by this previously and there were even bugs due to this.

via KorGgenT:

volume is for the whole stack, mass and vitamins are for a single item
volume applies to the whole stack

stack_size is the relevant divider, which is the same as charges when charges is defined and stack_size is not

"charges" : 4,              // Number of uses when spawned
"stack_size" : 8,           // (Optional) How many uses are in the above-defined volume. If omitted, is the same as 'charges'
"weight": "350 g",                           // Weight, weight in grams, mg and kg can be used - "50 mg", "5 g" or "5 kg". For stackable items (ammo, comestibles) this is the weight per charge.
"volume": "250 ml",                          // Volume, volume in ml and L can be used - "50 ml" or "2 L". For stackable items (ammo, comestibles) this is the volume of stack_size charges.
"price": 100,                                // Used when bartering with NPCs. For stackable items (ammo, comestibles) this is the price for stack_size charges. Can use string "cent" "USD" or "kUSD".


  • volume: per stack
  • mass: per use
  • vitamins: per use
  • calories: per use?
  • quench: per use?
  • health: per use?

Whichever turns out to be true, really REALLY should be noted in JSON_INFO.md. Contributors were confused by this previously and there were even bugs due to this.

I'll update it - it actually is there - but it needs to be made more prominent

So this is an example:

  {
    "type": "COMESTIBLE",
    "id": "wild_herbs",
    "name": { "str_sp": "wild herbs" },
    "weight": "7 g",
    "color": "green",
    "comestible_type": "FOOD",
    "symbol": "%",
    "quench": -1,
    "calories": 9,
    "description": "A tasty collection of wild herbs including violet, sassafras, mint, clover, purslane, and fireweed.",
    "price": 190,
    "price_postapoc": 50,
    "material": [ "veggy" ],
    "volume": "250 ml",
    "charges": 20,
    "flags": [ "EDIBLE_FROZEN", "RAW" ],
    "stack_size": 100,
    "fun": -1
  },

It should spawn with vol 50 ml ( ( volume 250 / stack 100 ) * charges 20 ) and 140 g ( weight 7 * charges 20 )

And if you eat one of those 20 charges you should get ~9 calories

Sound right?

Maybe we should move all these values to per charge. Volume per stack in particular was causing rounding errors that cause containers to be filled one charge less than its maximum volume (and still is if you partially fill a container and then completely fill it). Of course for a smooth transition we may want to add a new json value rather than modifying the previous value.

Verified this in game

20 wild_herbs (which is 1/5 of a stack but a full set of charges as spawns in game) has

vol       50 ml ((250/100)*20)
weight 140 (7*20)
price    38 ((190/100)*20)
barter   10 ((50/100)*20)

However, it only showed 6 calories, not 9, not 180, nor ((9/100)*20). I'm not sure what to attribute that to...

Note that stack size does not seem to limit how many portions appear on one line in character inventory screens. (I assumed it would; the word "stack" has an inventory management connotation in my mind.)

stack_size indicates how many "charges" (portions, uses) are in a given volume.

charges indicates the "stack size" of the entity when spawned in game

See what I did there?

I'm trying to wrap my head around the utility of this, why divorce the volume of a good from the volume it manifests itself in? Charges divided by stack_size is a multiplier of JSON volume to determine the actual volume that spawns in-game.

Given the way calories/activity levels work now, I dont see much point in any food below ~50 calories even being in the game if im being honest. You would need to spend the entire day eating them (for the time it takes to process the eat action) to get the amount of calories to survive that day...

Low calorie food might be useful for overweight starts though.

I'd like to change the volume divisor to be listed as part of the volume definition for those few items where we need a volume that isn't a multiple of 1ml, do something similar for any other uses of stack_size, and then remove stack_size as a feature entirely.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not \'bump\' or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.

This issue has been automatically closed due to lack of activity. This does not mean that we do not value the issue. Feel free to request that it be re-opened if you are going to actively work on it

Was this page helpful?
0 / 5 - 0 ratings