First some background info: the game I'm working on is really just for my portfolio, but I am treating it as if I actually planned on releasing it for commercial. So even though I may not actually have a lot of item types or a lot of items for each type, I would still like to implement code that is efficient in handling such a scenario. Though I do plan to have at least 5 item types, with somewhere between 10-20 items per type. The amount of items that can be stored in an inventory is based on weight. Also, I plan on implementing some form of multiplayer with a small server size of say...4 people.
I have an Item class that has several sub classes (although technically just one at the moment). Information on all items will be aquired from lua scripts.
My first question is how to handle items and their data in general? Specifically, how should they be initially loaded into the game? Should I just create an instance of the item object, load its information in straight from the lua script, and then place the object in the inventory of the player that obtained it? OR, for each npc/player that has an inventory system, they will have their own list of all the items in the game? Or some other third way.
I've actually given the 2nd one some more thought but I don't know if it would be very efficient in terms of memory and data allocation. Basically the idea is that each inventory object (1 for each player and possibly for npcs) will have its own list of all the items in the game. It will also contain a data structure (assume empty in this case) that will store the items that the person has. So when the person acquires a new item, it will be located in the master list, the item count will be updated, and then a copy of that object will be put into the personal list. (Yeah, it doesn't sound pretty, but I've been awake for 36 hours straight now because of finals).
My second question is, regardless of how the master item list is handled, what would be the best data structure to use to store the items in a person's inventory, given that items will be removed, added and can be sorted. I've looked at vectors, linked lists, and maps but I'm having a hard time deciding which would be better.