Defining item types with conditional features
ItemsItems are a major part of roguelike games. For TCOD, I followed Sean Middleditch idea on dungeon dweller: I use a single structure to store all items. Thus, there is no specific code for weapons, armors, lights, potions. Only generic code for generic items. The magic is in the item type definition... Item typesAn item type has some standard properties (name, cost, weight, ...) and a list of features. A feature is a characteristic of the item that enable some game mechanism on this item. Now two items of the same type have exactly the same characteristics in TCOD. They are exact clones. Thus, a sword and a +2 sword are two items of different types. Since we don't want to have to define hundreds of item types, they are organised in a tree where every type inherit the characterics of its father. Near the tree root, there are some general types (weapon, armor, container, ingredient, ...). Each type has subtypes that are more and more specific (weapon -> one handed -> sword -> short sword ...) Item featuresThe whole list of item types is in a plain text file (items.dat) loaded at game start. Features are the only part that is hardcoded. Each feature control some process that can occur in the game engine. Here are some examples of features :
Features propertiesAdding a feature to an item type has two consequences : - a list of variables specific to the feature is added to the item type. These are static or initial properties of the item type. - another list of variables is added to all items of this type. These are dynamic properties for this item. Example : for the light feature (item producing light), there are the static properties :
The dynamic properties are :
Features conditions We also can add a list of conditions to each feature we apply to an item type. Conditions are also hardcoded.They also have parameters. Examples :
Item features in applicationI will give some examples using the following format for the items.dat file (this is not exactly the actual items.dat format in TCOD) : ITEM_DEF := item_type "name" { FEATURE_DEF }
item_type "Fishing Pole" {
item_type "Torch" {
item_type "Sting" { (*) Sting is an elvish sword which produce blue light when there are orcs nearby. ScreenshotsHere are some screenshots illustrating the feature system previously described. a sunrod a lamp a candle | PAGESDeveloper articles Game designer articles LINKS |


