c ++: let's say I have a list of one hundred unique weapons, how can I identify them all programmatically and simply?

I have a class Weapons frame, that has an int member, arms_frame_id, which I intend to use as a way to identify the weapon, and I use that comparison with other Weapons frame instances.

The problem is that I want to remove the weapon from the global list of WeaponFrames and equip it in a Actor. As a designer, I could know that arms_frame_id # 2 is the arc weapon that I want, but what is the best way to identify them through programming?

If I assign an identification to the Weapons frame When creating instances, I can not trust the value to be identical the next time the game is run, unless you assign the value to an enumeration or int. That could work though.

I'm using C ++ 11, could I create a namespace somewhere and list all types of weapons,

enum class WeaponFrameIDs {
Sword = 1,
Arc = 2, // repeated more than a hundred times

or I would make a ton of integers const in a header somewhere, even if it actually also lists like this:

namespace WeaponFrameIDs {
const int sword = 1;
const int Bow = 2;

I could also use strings assigned to an integer, but I am losing compile-time verification (and I can not use constexprs with VS2013), and I run the risk of duplicating entries. However, it supports dynamic allocation to the list:

std :: unordered_map WeaponFrameIDs {
{"Sword", 1},
{"Arc", 2},

Is there an alternative that I'm missing? What is the best way to write a system to identify weapons in a game?

If it is relevant, here is an example of a situation that I am trying to solve through the code. I'm not using a visual editor where I can drag a weapon to an actor.

void set_up_actor ()
Actor actor
WeaponFrame * weapon_frame = AllWeaponFrames.at (WeaponFrameIDs :: Bow);
actor.weapon_frame = weapon_frame;

Points I'm looking to avoid:

  • Fill in a complete heading with enumerations
  • I needed to recompile the whole project because I changed that header
  • Losing the ability to verify the id at the time of compilation
  • Eventually add ids generated by the user. This conflicts much With verification at compile time.

I am trying to solve the best way to extract the Weapon from a list, either by ID, index, specially assigned key or something else.

  • If I use a literal ID, actor-> armas_id = 1, I do not know what weapon is tied to the ID of 1.
  • If I use an enumeration, or a const. Int, to represent the one, I need to recompile the game for each of the new weapons I add.
  • If I change the type of identification to a chain, I lose the ability to programmatically validate the chain against the existing list of weapons.