Defaults and magic constants are a bane of pretty much any program. There exist several methods of dealing with this problem, some are better, some are not so good. TE is no different in this aspect and tries to handle its defaults.

The problem itself comes from the fact, that computer programs work on numbers and pretty much any piece of code can be instrumented with numerical values. Traditionally these would be just hardcoded into the code. This however leads to erosion of meaning of these values. To solve this problem named constants are used.

However, still it is required to recompile the program to change the constants. To resolve this issue configuration files are used. This is the solution implemented in TE.

To create a constant open the "common/defaults.hpp", scroll down to the definition of the 'defaults' class and simply use the macro:

DEFAULTS_CREATE_INTEGER_PROPERTY( _name, _default, _minimum, _maximum );

This will create a static function with a _name, which by default will return _default value.

Now recompile your unit and shazzam! you can use the default value by calling:


The defined values are stored in a simple text file which is loaded on the game startup by the 'common::configuration_file” class. If the file does not exist it will be created with the value defined as _default by the DEFAULTS_CREATE_INTEGER_PROPERTY macro, otherwise the values from the file shall be checked and ensured to be between the _minimum and _maximum.


And that is pretty much it. Your default value will be visible across the whole code base, but can be only changed via the configuration file of the game. This nicely puts all those magic constants in one place, making them easy to spot / modify or analyze.