I’m making an RPG in C++ and the items (loot/gear) will have immutable base versions, but then the player can get instantiations of them which can change with use and modification. These mutable instantiations will be saved in the DB. But I’m wondering if the base versions should be defined in JSON, or a separate DB (with the same schema), or maybe the same DB (seems dangerous), or if I should just hardcode them in C++ in the ItemFactory.

How have you approached this problem in your games? How do game engines do it? I’m using SDL2 so I’m doing most of these systems from scratch.

  • Sentient LoomOP
    link
    fedilink
    English
    arrow-up
    2
    ·
    14 hours ago

    I’m actually leaning toward this. I might have a class that holds a large unordered_map with a string key, where the value is actually a function which calls a constructor loaded with the defining data (a function so that I can create the map in an object or function without creating ALL the objects every time).

    Still, creating a huge unordered_map every time I just need one (or ten) items seems bulky. But there will be five maps, each with their own native items, so maybe I can break it up that way.

    I’m also concerned about using magic strings to access values. I wonder if I should make another unordered_map just to hold string values (something like [“BASTARD_SWORD”] = “bastard_sword”) so that I never write the string, I just write… the string to access the string… maybe silly and bulky.