Inventory System

Inventory System
All relevant code is contained in Inventory/scripts/inv.ds

The Inventory is an array made up of index pointers which refer to the Item List, along with a minimal set of data relative to the item being held. The InventoryDef Struct struct InventoryDef { 	int INDEX; Index2DDef ORIGIN; int DURABILITY; int AMOUNT; int MODIFIER; int TIMER; bool MARKED; };
 * INDEX points to the ItemList index, which in turn defines the item.
 * ORIGIN.X/Y provides functions with the origin coordinates of the item on the grid (for large items)
 * DURABILITY may refer to the number of uses a consumable has, the damage a weapon can take, or the number of times an ingredient may be used in craft recipes.
 * AMOUNT is how many stackable items are in this inventory spot.
 * MODIFIER points to the ModifierList, which in turn defines any special properties this item may possess.
 * TIMER keeps track of how long an item has existed in this spot (mostly for food items)
 * MARKED is reserved for functions which require inventory spaces to be checked, to ignore counting indexes for large items.

Inventory Types
There are different types of inventories, most are two-dimensional grids. These iteratively display their contents via the GridButton function. Some inventories exist only as single instances, such as the Weapon or Equipment slot, and use SingleButton instead.

List of current inventory types: __global_array InventoryDef[INV_MAX_X][INV_MAX_Y] Inventory; __global_array InventoryDef[CRAFT_MAX_X][CRAFT_MAX_Y] Crafting; __global_array InventoryDef[CHEST_MAX_X][CHEST_MAX_Y] Chest; __global_array InventoryDef Weapon; __global_array InventoryDef Item; __global_array InventoryDef Equipment;
 * Player Inventory
 * Player Crafting Window
 * Player Equipment Slot
 * Player Weapon Slot
 * Player Item Quickuse Slot
 * Chest/Container Window

Inventory Scripts & Behaviour
Inventory behaviour is mostly contained within Inventory/script/INV_Scripts.dh.

There are several main scripts which contain the bulk of the inventory code.
 * DisplayInventory - Player Inventory.
 * DisplayCrafting - Player Crafting Window.
 * DisplayEquipment - Equipment, Weapon and Useable Windows.
 * DisplayStash - Chest/Container Window.
 * ToggleMainInventory - Script puked by the player to toggle the default windows.


 * ToggleInventory - Selectively force a chosen window on/off, or toggle from current state.

Inventory Item Origins
The ORIGIN fields of the InventoryDef struct are used to point to the root spot of the item. This is done to cut down on item data populating the inventory fields. All items have origins, empty spaces are their own origin. Any function directly calling the item instance's properties will pass its origin, not its tile position, and all graphical functions rely on the origin and item size to determine positioning.