Guide to creating game data

3. XML files describing game data
(level.xml, resource.xml and others)

In this documentation we show a sample of XML files useful to define data in our engine.

  1. Click on each attribute name to go to the documentation for related ObjectPascal property.

  2. In most cases, the values shown for attributes below are their default values (used if you don't specify any value). There are also some cases where attribute is required, these are marked clearly.

    • Note about attributes that specify URLs: the default value is always empty string (although sometimes URL is just required, e.g. "scene" inside level.xml). Relative URLs are always relative to the XML file. In simple cases, you just use filenames there, and place your data files along the XML files.

    • Note about attributes that specify sound names: the default value is usually an empty string, meaning "no sound assigned". Sound name is always optional. You should use there a sound name defined in sounds XML file.

  3. Note that the attributes shown are not exhaustive: you can derive new classes (descendants of TLevelLogic, TCreatureResource, and others) where you read other attributes. Also, for resource.xml, we show attributes of a TWalkAttackCreatureResource class (indicated by type="WalkAttack"), but there are also other resources: TMissileCreatureResource, TStillCreatureResource, TItemResource, TItemWeaponResource. They all share some properties (defined at base T3DResource, also all creatures have base TCreatureResource, also all items have base TItemResource), and also they all have some specific properties. See the engine API documentation for a complete list of properties of above classes, (almost) all of them can be set by a resource.xml file.

Notes specifically about level.xml and resource.xml files

  1. The data directory of the game is scanned for the special XML files named level.xml and resource.xml. This allows you to define new creatures or items (something that can be picked and carried by the player) or levels to the game simply by adding an additional subdirectory to the game data.

    What exactly is "data directory"? You give it as parameter to Levels.LoadFromFiles and Resources.LoadFromFiles calls, by default it's the result of ApplicationData function.

  2. Each level.xml / resource.xml file may contain relative URLs for 3D models and images related to this resource. The idea is that the XML file is kept together with the data of particular creature, item etc. So you can trivially add/remove available resources by simply adding/removing the appropriate subdirectory to the game data. No recompilation, and no modification of any central file, are necessary to add e.g. a new creature and a new level using that creature.

  3. In normal circumstances, these xml files are scanned and read only once when the game starts. For easy editing of game data (to not be forced to restart the game after every little tweak in configuration), you can also use add to your game some debug command to reload XML configuration of various things during the game. (Most, but not absolutely all, settings can be changed even while the game is running; exceptions are things that are "heavy" — e.g. changing animation URL may require restarting the level.)

Guide to creating game data