Writing a json reader/ factory in python; have questions!


Prompted by my work for: https://github.com/CleverRaven/Cataclysm-DDA/issues/26183, I am working on expanding my script to read in and perform the inheritence for all json objects (starting w/ ter, furn and will go from there. Not planning to include buildings). I plan to subsequently load this information into a MySQL database and host it on one of the computers lying around my house. Mainly this is for practice working with databases and learning how to set up a server but hopefully it will be useful as well.


  1. What do optional members default to / is there an easier way to find out than looking through their factory code? json_info.md isn’t very helpful here. (Currently I assume numeric values to be zero)

    i. Some items use proportional and/or relative to inherit and modify values that haven’t been explicitly set. Currently in these cases I assume that the inherited value is zero.

    ii. Can someone explain this bit of the item category defaulting code:
    item_factory.cpp Lines 2537-2341

 bool weap = std::any_of( obj.melee.begin(), obj.melee.end(), []( int qty ) {
        return qty > MELEE_STAT;
    } );

    return weap ? "weapons" : "other";
  1. Some member values can be given using different units (e.g. volume -> 1/4L, L, ml). Presumably the game converts them into one standard unit; what is it / are they?

    i. What besides volume and the newly updated duration members allow multiple units?

  2. Are the json objects separated into different files purely for organization or is their location used in some way. (Not asking about load order hierarchies but within a dir level)

  3. Are there any values generated by the game other than armor and moves per attack?

  4. Are IDs globally unique or could one say give the same id to an item and a martial art?

1 Like
  1. Optional members default to the class default, whatever that is and yes you’ll neer to read the code to find out.
    1i. Yeah, that’s going to be wrong in some cases.
    1ii. Let me get back to you.
  2. Volume defaults to mL and mass to g.
  3. File location is arbitrary for human convenience. The game sorts stuff by type field value.
  4. Possibly.
  5. IDs are unique per type, but it’s perfectly legal to define a vehicle_part that has the same ID as it’s base item. Or a martial art for that matter.

Another question:

  1. Where does piercing damage come from? (not in json and item.cpp modifies/uses but no assignment also no mention of STAB flag in json_flags.md)

    i. Presumably dpt (weapon balance) is calculated w/ just bashing and cutting dmg then right?