Now, if you need to be able to dynamically add new types of inventory items without recompiling your code (like, by just editing a game data file), then you will need some kind of late-binding like a string would offer.
Yeah, that was part of the idea behind the decision. That I'd presumably store the various item types in external files eventually, like how I used XML for a project previously. So an enum seemed out of the question.
Ultimately, I expect there to be a lot of different item types, as I'm working towards a system of buying/selling not terribly unlike Elite etc. So that's one reason why being able to bunch together similar items and manipulate them en masse is important. You might be selling 200 of an item, and that item could have a base value of 500, but because they have a condition of 2/5, they might each be worth 200 or w/e. Or some people may not want to buy them at all. That sort of thing. Still working on the exact design as I go of course...
And yes, I'd occasionally want more than one item to share the same display name - I can think of at two unique situations where I'd want that, if the gameplay desired that feature.
Just the way I've been viewing it so far... is that if I ever had 2 types of item that theoretically could have the same display name... it seems like I'd be just as well to give them different names, even if it was something like "AK-47" vs "AK-47 (Gold)" or w/e.
Mind you, one other way I was sorta thinking of was along the lines of
- You might have an item called "AK-47" representing the standard version of that item.
- You might want certain special variants... one made of gold, like I mentioned, or one that shoots faster.
- Perhaps it would be simpler in terms of display wrt fitting names on screen and maybe cleaner in general to just have them all fall under the name of something like:
"AK-47(+)".
- You could then maybe give them unique descriptions if necessary etc.
- However I'm not completely sold on the idea, because while it does do a good job of marking that something is different to the norm, it doesn't actually say how in any way from the name alone...
...but on the other hand, in many cases it would likely take quite a few words at minimum to properly express its unique characteristics and so make that impractical to fit inside a name and would be better in some form of description attribute.
I guess my conclusion is that it would probably be better if I used an incrementing unique numerical ID, as long as it wasn't much hassle.
What would you have in mind? Just read all item data from a file, then have the program automatically generate numerical item type IDs in sequence?
EDIT: So where I'm at right now regarding my inventory architecture is:
- My Inventory class contains a vector, the vector contains objects of the class InvEntry.
- InvEntry represents an inventory entry describing the item contained.
- InvEntry contains an Item object, and a quantity integer representing how many of that Item are stored.
- The Item class describes the item.
Does that all sound good? No way of cleanly getting around the InvEntry class I think while still using a simple vector, and it accounts for Items being differentiated by any number of things in the future by simply updating the == operator overloading and comparing items for equality before shoving them into the same InvEntry.