Man materials

From LSWiki

Jump to: navigation, search

Files

 /lib/materials.h
 /daemon/materials.c
 /def/material/*

Description

The list of materials that things can be composed of is extensive, and is not described here because the primary reference for it is the directory of material definitions, /def/material. This document is to give you a quick idea of how to work with materials, what they do, and how to get information on ones you might want to use.

/lib/materials.h contains the list of macros you should use to refer to materials. A quick example of how you would specify that an item is made of a material is:

#include <materials.h>

void create() { ::create(); set_names(({ "iron ball", "ball" })); add_material(Material_Iron); }

This marks your item as made of iron. This automatically causes it to have the properties associated with iron, such as Prop_Metal and Prop_Ferrous -- the full description of iron is /def/material/iron.c.

At times you may want, rather than to wade through the entire material list, to get a list of materials that have a given property, such as Prop_Stone or Prop_Metal. A quick way to do this is by querying the materials daemon as follows:

eval -i materials.h Material_Daemon->query_materials_by_property(Prop_Stone)

To easily and reliably retrieve the material definition object for a material so you can work with it, use the following mechanism:

#include <materials.h>

void find_iron_definition() { object def; def = Material(Material_Iron); }

Any time you store a reference to a material for use outside your current execution context (e.g. in a global variable, or in arguments to call_out()), you should use the material macro rather than storing the object definition. The reason for this is that the definition could be destructed and reloaded at any time, but if you store the code, you will always be able to retrieve the current definition. See the example below:

#include <materials.h>

internal int material;

void create() { ::create(); material = Material_Iron; }

void find_material_definition() { object def; def = Material(material); }

The information in materials regarding "hardness" and "strength" should not be used, as these are currently ill-defined measures and will probably be replaced by something better-conceptualized.

A flexible mechanism for randomly selecting materials from a defined pool is available. See man selection for details.

Personal tools