- Implemented inventory system.
- Implemented basic UI for the inventory system.
- Played some Castle of the Winds (http://lkbm.ecritter...w/download.html)
- Played some Dwarf Fortress (http://www.bay12games.com/dwarves/)
The inventory system doesn't just cover the player's inventory, but also inventories of monsters, the contents of containers like chests, the floor space of tiles and even (eventually) the player's worn equipment. I figure that all these are containers in which items can be placed into a specific (or any free) slot. By implementing a common system for all of these it means one item transfer system can be made that works for all of them and the UI can bind to any possible item container to display/interact with it. I made the following gameplay decisions with the inventory:
One item per slot, One slot per item
In some games bigger items take up more slots in the inventory. Stalker (or should that be S.T.A.L.K.E.R?) springs to mind where the rifles would take up huge amounts of slots in the backpack and the ammo would take up just one slot. I wanted to avoid that to keep it simple. I don't want any of the hassle of packing algorithms and I never find packing luggage that fun. So it's one item per slot. On the downside it does means a shield will take up as much space in the inventory as a spoon...
Inventories are space restricted, not weight restricted.
Another simplification. I did at least start off trying to implement weight restriction, but due to a catastrophic experiment involving nested containers, rings of strength and bags of holding I ditched the idea for making inventories limited to a certain number of slots instead. Tracking weight stats is kind of boring anyway - how much can I carry? How much am I carrying? how much does that shield weigh? Slot restrictions are much easier to visualize. I can tell how many slots I have left at a glance.
Items can be stacked
I didn't want this but I am forced down this route once I am slot restricted. The first items I made for testing were blue gemstones and red gemstones. They are small things the player can pick up and it was clear straight away that picking up 10 of them took up a ridiculous number of slots (10!). I want the entire inventory to fit on one screen really. To do that I need stacking for small items at least...
Currently there is a player Inventory screen which can be displayed and hidden pressing the 'I' key (wow!) and a floor space view (which is useful considering you can't see what's on the floor behind the player sometimes). Items can be dragged between the views and stacked, etc. I need keyboard support for the inventory eventually I guess but for now it is entirely mouse driven.
The following text is even more boring than the text above.
The basic class for inventory is ItemContainer. It's a container of items. Really it's a dictionary of items, mapping slot indexes to specific items. The player's inventory and the tile's floor space are both ItemContainers. Even the cursor has an ItemContainer, with one slot, so that it can "carry" items in drag/drop operations.
The most important method of the ItemContainer class is AddItem(Item). That does slightly more than it suggests. It not only adds an item to the container, it first tries to remove the item from it's existing container. I say try because the action can fail. Both containers and the item itself get a say as to whether the Add/Remove operation succeeds. I am thinking ahead to eg an item refusing to be removed from worn equipment if it's cursed. If AddItem fails a reason is returned, which eventually will be put out to the UI.
An InventoryWindow containing many InventorySlotWindows can be bound to an ItemContainer to display the ItemContainer's contents. When an InventorySlotWindow receives a MouseDown event it handles the dropping of an item into the underlying ItemContainer slot, or the picking up of an item from that slot. To pick up an item it simply calls the CursorContainer.AddItem(Item) and now the cursor has the item. When the cursor is drawn if it's ItemCollection contains anything the icon for that item is drawn beneath the cursor.
I now have an Item class that derives from Entity. Items are things that can be carried. The Item class has a StackCount property for how many items are in the stack and a StackLimit property. Items that cannot be stacked have a StackLimit of 1.
Things Left To Do:
The ever growing list. I am not even really working on the actual game yet, it's all foundational stuff so far. I spent so long on the UI system because I figure I can use it in other games too.
- Inventory system. Mostly done but a little work left.
- Inventory/Equipment/Floorspace UI. Need to implement equipment UI and improve inventory.
- Message/Log/Event Window Need a UI to display messages to the user. Errors, game events, etc
- What is the Point? can't really make a HUD or player stats display or a lot of other stuff without knowing how the game will work - eg what stats are there? what IS THE GAME?
- Action "Animations" adding visual feedback. At the moment turns are instant. You don't "see" what happened. Need to slow turns down so you can see arrows flying or fireballs exploding.
- Random Map Generation
- Saving/Loading - probably need a game first!