Learning C With Game Concepts/Inventory System

Inventory System
There is nothing quite so satisfying as equipping one's character. Most of the time, you start out at level 1, wearing rags and shackles. After being released from the local dungeon for one reason or another, you meet a Haberdasher with a heart of gold. He gives you some odd jobs so you can earn enough copper to eat. After weeks of punching things, fetching things, running from things, and still without two copper pieces to scratch together, you at last come across the "Unremarkable Sword of Rusty Might". Huzzahǃ It nothing compared to what the City Guard is using, but now those sewer rats shall feel your wrath. So let's get to itǃ

An Inventory Shouldː
 * Contain a list of items.
 * We should be able to ADD and REMOVE items from the list, as well as FIND items.
 * Similar items should be aggregated. When a similar item is added, quantity is increased, not list size.
 * Players should have their own inventory, as should chests and other containers.

An Item Shouldː
 * Have a name and description.
 * Health and mana.
 * These are the restorative properties of potions. 20 Health heals 20 health points if consumed.
 * Similar items should be aggregated. When a similar item is added, quantity is increased, not list size.
 * Have the option of multiple uses.
 * Have an ID that uniquely identifies it.

Putting the above specification into practice, we start by defining the kinds of items available, via an enumeration. In the future, we may want to import a list of items from a file, rather than keeping all of them with our source code. However, it's best to keep things small for testing purposes.

Each item that we create will be embedded in an item node. A node is a single unit which can be linked to other nodes in order to form a data structures such as lists and trees. In this case, the data structure is a doubly linked list. As you can see, the itemNodeStructure points forwards, backwards, and to its own item. When defining the itemNodeStructure, it is necessary to use "struct itemNodeStructure" to declare the pointers because the itemNode typedef is not yet in effect and the compiler will not understand.

Going back to ye olde playerStructure datatype, we add a new value to it.

Because the functions required for a basic inventory setup are somewhat involved, it cannot be broken up into more digestible pieces. My code is very likely not the most elegant solution to the problem, so there is room for improving the clarity. For now, if you want to understand how the functions for the inventory work, you'll need to read through the comments until you can identify what each piece of code is doing.

inventory.c

-

inventoryFinished.c