introduction
this document explains the system i am creating to handle inventory items in my n64 game. throughout the game, the player will encounter and collect various items such as keys, potions, equipment, quest items, etc. i needed to come up with a way to keep track of which items the player currently has and how many, and a way to display information about the items and allow the player to use them on the inventory screen in the pause menu. i may expand the functionality of this system in the future, but for now it is doing what i need it to do. as always, if you notice anything that could be improved, feel free to contact me.
inventory system explanation
the INVENTORY map is part of the player object. it is always active in memory and can be updated any time the player collects, uses, buys, sells or discards an item. the ITEM_DICTIONARY map only gets built and loaded into memory when the player enters the pause menu. when the player leaves the pause menu it is deleted again.
i give each type of item an arbitrary id number. this id number is used as the key in the key/value pairs in each std::map object. for example, if the id number for the potion item type is 57, and the player currently has 4 potions, the key/value pair representing the potions in the player's inventory would be {57: 4}. each pair being just two numbers, this ensures the data keeping track of the player's inventory is fairly lightweight since it will need to be in memory at all times while the game is running.
this item id number is also used as the key in the key/value pairs in the ITEM_DICTIONARY std::map object. the values, however, are structs containing the following data:
when the player enters the pause menu, the game will build the ITEM_DICTIONARY with all of this information for each item in the game. on the inventory screen, the game will look at all of the items in the player's current INVENTORY, and display a list of them by pulling information from the corresponding items in the ITEM_DICTIONARY.
screenshots