A GENERIC ITEMS SYSTEM

Defining item types with conditional features

 

Items

Items 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 types

An 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 features

The 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 :

  • attack : the item gives damage when used as a weapon
  • armor : the item increase armor bonus
  • light : the item produce light (mainly torchs and lantern but why not create luminescent sword blade).
  • wear : you can wear the item on a specific 'body slot' (clothes, weapons, rings, ...)
  • onoff : the item can be enabled/disabled (lantern)
  • ingredient : can be combined with another item to create a third item (destroying the 2 source items)
  • creator : can produce another type of items (pickaxe -> stones, fishing pole -> fishes, ...)
  • ...

Features properties

Adding 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 :

  • visiblity range (range at which a map cell is visible due to this item light)
  • duration (how much time the light lasts)
  • variation (how much the light intensity changes over time=> low for a lantern, high for a torch or a candle)
  • color

The dynamic properties are :

  • duration (initialized with the item type duration value and decreased over time)
  • variation (initialized with the item type variation, but increases when duration is near 0, simulating a torch flickering)
  • intensity coef (decreases when duration is near 0 so that a torch light smoothly disappears)

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 :

  • when_wear : the feature is only active if the item is attached to a body slot (this imply that the item also has the wear feature)
  • when_on : the feature is only active if the item has been turned on (this imply that the item also has the onoff feature)
  • when_oncell : the feature is only active when the player is on a specific map cell type (parameter : the cell type).
  • when_near_crea : the feature is only active when the player is near a specific creature type (parameter : the creature type, the range)

Item features in application

I 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 }
FEATURE_DEF := feature "name" { PARAM_LIST CONDITION_LIST }
PARAM_LIST := empty | PARAM_DEF PARAM LIST
PARAM_DEF := PARAM_NAME PARAM_VALUE
CONDITION_LIST := empty | CONDITION_DEF CONDITION_LIST
CONDITION_DEF := condition "name" { PARAM_LIST }

  • a fishing pole :

item_type "Fishing Pole" {
feature "produce" { ITEM_TYPE "fish" condition "when_oncell" { CELL_TYPE "water" } }
}

  • a torch :

item_type "Torch" {
feature "onoff" {}
feature "light" { RANGE 5 COLOR 255 200 0 condition "when_on" {} }
}

  • Sting(*) :

item_type "Sting" {
feature "wear" { BODY_PART "hand" }
feature "attack" { DAMAGE "1d6" condition "when_wear" {} }
feature "light" { RANGE 5 COLOR 200 200 255
condition "near_creature" { CREATURE_TYPE "orc" RANGE 10 }
}
}

(*) Sting is an elvish sword which produce blue light when there are orcs nearby.

Screenshots

Here are some screenshots illustrating the feature system previously described.
I created different types of lights (candle, torch, lamp, lantern, sunrod) with different ranges and colors. Than
ks to the parameters of the light feature, I can create any type of light without changing the engine code (only the items.dat file).

Also, note how non player characters and buildings project shadows. The screenshots show respectively a sunrod, a lamp and a candle.

a sunrod

a lamp

a candle

PAGES

Home

News

Forums 

The Doryen library

The Doryen Arena 

Developer articles

A generic items system

Building an island

Minimap interpolation

World storage

Basic dungeon generation

Dungeon morphing

Visibility Determination

Game designer articles

Inventory

The trading system

Stealth gameplay

Dialogs

Leveling system

Dynamic map


LINKS

Temple of the roguelike

Roguebasin

Dungeon dweller

Roguelike Dev newsgroup