I'm trying to organize the enums for a prototype of a cooking system in a game. Right now I'm not working on the recipe making system, but rather in the way I can, in the code, refer to each type of food and it's possible state, so that I can construct a struct containing those two fields, so that I can store it inside the hashmap for the inventory, and later change the texture and action to it, but now I'm trying to lay the foundation firmly by organizing the enums in a nice and logical way.
#Is this organization ok?
12 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
#pragma once
#include <cstdint>
namespace
{
enum _SharedStates : uint8_t
{
FRESH = 0,
DRIED,
FRIED,
BOILED,
ROTTEN,
ROASTED,
SMOKED,
PERFECT,
OK,
BAD,
};
}
// Essential items that although can be ingested, dont have any effect. Mostly used as ingredients
enum Essential : uint8_t
{
BOTTLED_WATER = 10,
SALT,
};
// Colectables, wether raw or prepared, that can be consumed as a unit, i.e. without necessarily being part of a full preparation/recipe.
namespace ingestible_unit
{
namespace ingredient
{
enum Kind : uint8_t
{
HERBS = 12,
WILD_BERRY,
WILD_LEAVES,
};
enum State : uint8_t
{
FRESH = _SharedStates::FRESH,
DRIED = _SharedStates::DRIED,
};
}
namespace food
{
namespace vegetarian
{
enum Kind : uint8_t
{
POTATO = 15,
EGG,
};
enum State : uint8_t
{
FRIED = _SharedStates::FRIED,
BOILED = _SharedStates::BOILED,
ROTTEN = _SharedStates::ROTTEN,
};
}
namespace meat
{
enum Kind : uint8_t
{
WILD_BOAR = 16,
CHICKEN,
RABBIT,
BEEF,
DEER,
FISH,
};
enum State : uint8_t
{
ROASTED = _SharedStates::ROASTED,
SMOKED = _SharedStates::SMOKED,
FRIED = _SharedStates::FRIED,
BOILED = _SharedStates::BOILED,
ROTTEN = _SharedStates::ROTTEN,
};
}
}
}
// Recipes that, either cooked or simply prepared, can be consumed
// They provide more and more lasting health than the ingestible units
namespace ingestible_whole
{
enum Kind : uint8_t
{
BOAR_ROAST = 22,
WILD_STEW,
FANCY_DEER,
WILD_SALAD,
OMELET_WITH_HERBS,
};
enum Freshness : uint8_t
{
PERFECT = _SharedStates::PERFECT,
OK = _SharedStates::OK,
BAD = _SharedStates::BAD,
ROTTEN = _SharedStates::ROTTEN,
};
}
this is what i came up with already, and although I like interligating the enums so that any item can be represented with a single distinct number, which I can't acheive with an enum class, I also feel weird having to change those numbers manually
what if i want to add 2 more Kinds in the Essential enum? I'll have to add 2 to the enumeration of the first item of every other enum of Kinds
as the number of enums grow, more iterations of that must happen so that it doesnt break, and by missing one number I can totaly shift those. This alone explains why it is bad code
If I only have a way to interligate those enums automatically rather than manually it would be aweasome
I want to keep it simple: any specification like ingestible_whole::Kind::FANCY_DEER is converted to an uint8_t that is distinct from every other one, which makes expansion simpler. On the other hand, if I choose to use enum classes, id have to create a type alias ItemId for std::variant with all the possible enums that hold those ids. This is manual like the approach I tackled, yet more complicated as it involves other data structures
And I want to keep it fast: a literal list of numbers that can refer to any item in the game is pretty interesting
Im happy that you are reading this. If you are willing to help me i'd be glad!
This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.