Tuesday, March 21, 2006

Items features 2

This is a upgrade of the item feature design previously described here.
In the first version, every item property was encoded in a list of features. I mentioned such features as 'mapcell' which contains the type of map cell on which the item works. The example for this feature was a fishing pole, which produce fishes when you are on a water cell.

But what if I want an item with several features, each one with different conditions ? Example :
a sword called Sting which has three features :
- can be weared on 'main hand' slot
- gives you 1d6 attack bonus when used as a weapon (only when weared)
- produce blue light (only when there are orcs nearby)

Using the previous system, this would lead to the following features :
- feature "wear" body_slot "main hand"
- feature "attack" damage "1d6"
- feature "light" range 5 color 200 200 255
- feature "near_creature" type "orc" range 15

Ok, everything is here but how can the engine use all this ?? Do we have to wear the sword to produce the light ? Do we need to be near an orc to wear it ? This is a total mess.

The issue is that "near_creature" is not a feature, but a feature condition.

Thus, using a new structure for item type definitions :
item type
=>feature1
=>=>condition1
=>=>condition2
=>feature2
=>=>condition3
=>=>condition4
allows more flexibility in the item design.

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 }

For Sting, we have :
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 }
}
}

Note that we now distinguish the wear feature (ability of an item to be wear on a specific body slot) and the wear condition (necessity to be weared to activate another feature). Of course, you can only use the condition "when_wear" on items that already have the feature "wear".

And for our 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" {} }
}