OpenTTDLib
[ class tree: OpenTTDLib ] [ index: OpenTTDLib ] [ all elements ]
Prev Next

Settings

and their defaults

Table of Contents

Settings

Since version 0.2 the way options are set has changed drastically. Please read the following sections, esp. when upgrading from v. 0.1.1 or earlier.

Options can be set in 3 different ways, as demonstrated in the following sections:

Note: when setting options, values are typcasted to be of the same type as the options default value.

Example: OpenTTDLib::OPTION_DEFAULT_CONVERT_MAPSET has the value false, so when setting OpenTTDLib::OPTION_CONVERT_MAPSET the value you assign will be typecast to 'boolean' using settype().

Calling OpenTTDLib::setOption()

When passing 2 parameters to the method, the first parameter may not be an array(), as otherwise the method will return right away. In this example, the first parameter is a string. Using 'CONVERT_NETLANG' or OpenTTDLib::OPTION_CONVERT_NETLANG makes no difference whatsoever, though I would advise to use the class constants.

<?php

$openttd = new OpenTTDLib();
$optnttd->setOption( OpenTTDLib::OPTION_CONVERT_NETLANG, true );

?>

When passing an array to OpenTTDLib::setOption() the key => value pairs, are as in the example obove.

<?php

$openttd = new OpenTTDLib();
$options = array(
	OpenTTDLib::OPTION_CONVERT_NETLANG	=> true,
	OpenTTDLib::OPTION_CONVERT_MAPSET	=> true,
);
$openttd->setOption( $options );

?>
When using this method of setting options, the second must be null.


Value of Currently Set Options (OpenTTDLib::getOption())

If you need to get the value of an option, use OpenTTDLib::getOption(), if the option has not been set to a custom value, the default value of the option in question is returned.
<?php

$openttd = new OpenTTDLib();
$openttd->getOption( OpenTTDLib::OPTION_CONVERT_NETLANG ); /* returns true */

?>
with this method you have access to any set options.

3rd parameter of OpenTTDLib::queryServer()

Since v. 0.2 OpenTTDLib::queryServer() only accepts 3 parameters, the thrid one being an optional array which is then passed on to OpenTTDLib::setOption().

The array has the same structure as in the previous example.

<?php

$openttd = new OpenTTDLib();

$host = 'localhost';
$port = 3979;
$options = array(
	OpenTTDLib::OPTION_CONVERT_NETLANG	=> true,
	OpenTTDLib::OPTION_CONVERT_MAPSET	=> true,

$openttd->queryServer( $host, $port, $options );

?>



Available Options

Following are all available options, their default values and effect.

OpenTTDLib::OPTION_CONVERT_MAPSET

Option type: boolean

Defaults to: false (OpenTTDLib::OPTION_DEFAULT_CONVERT_MAPSET)

When set to true, mapset integers are replaced by their corresponding names i.e. 0 = TEMPERATE, 1 = ARCTIC, 2 = DESERT, 3 = TOYLAND

Alternativly you can use OpenTTDLib::convertMapSet() to get hold of the string value.


OpenTTDLib::OPTION_CONVERT_NETLANG

Option type: boolean

Defaults to: false (OpenTTDLib::OPTION_DEFAULT_CONVERT_NETLANG)

when set to true, netlang integers are replaced by their corresponding names i.e. 0 = ANY, 1 = ENGLISH, 2 = GERMAN, 3 = FRENCH, etc.

Alternativly you can use OpenTTDLib::convertNetLang() to get hold of the string value.


OpenTTDLib::OPTION_CONVERT_VEHICLETYPE

Option type: boolean

Defaults to: false (OpenTTDLib::OPTION_DEFAULT_CONVERT_VEHICLETYPE)

When set to true, vehicle type integers are replaced by their corresponding names. i.e. 0 = TRAIN, 1 = TRUCK, 2 = BUS, 3 = AIRCRAFT, 4 = SHIP

Alternativly you can use OpenTTDLib::convertVehicleType() to get hold of the string value.


OpenTTDLib::OPTION_CONVERT_STATIONTYPE

Option type: boolean

Defaults to: false (OpenTTDLib::OPTION_DEFAULT_CONVERT_STATIONTYPE)

When set to true, station type integers are replaced by their corresponding names i.e. 0 = TRAIN, 1 = TRUCK_STOP, 2 = BUS_STOP, 3 = AIRPORT, 4 = DOCK

Alternativly you can use OpenTTDLib::convertStationType() to get hold of the string value.


OpenTTDLib::OPTION_NEWGRF_MAX_REQUEST

Option type: integer

defaults to: 10 (OpenTTDLib::OPTION_DEFAULT_NEWGRF_MAX_REQUEST)

Maximum number of newgrf id and md5sum pairs that will be sent in a single OpenTTDLibPacket::UDP_CLIENT_GET_NEWGRFS packet. This only limits the amount of data in a request packet, does not specify any details for the answer packet the server sends out. i.e. if the server only responds to 4 of those requested newgrs, another request packet is sent containing the missing newgrf details.


OpenTTDLib::OPTION_CACHE_NEWGRF

Option type: boolean

defaults to: true (OpenTTDLib::OPTION_DEFAULT_CACHE_NEWGRF)

Enables or disables the cache for newgrf data, if enabled (set to true) the cache is checked first for matching newgrf id and md5sum pairs. Queries to the server will only be sent for unresolved newgrf id and md5sum pairs.

Note: If you have a version of PHP5 that does not include support for SimpleXML, simply set this option to false and you do not need to include OpenTTDLibCache.php.


OpenTTDLib::OPTION_CACHE_GAME

Option type: boolean

defaults to: false (OpenTTDLib::OPTION_DEFAULT_CACHE_GAME)

Enable or disable the cache for game details, such as $info, $detail, $newgrf

NOTE: this is currently not implemented, therefore has no affect!


OpenTTDLib::OPTION_CACHE_FILE

Option type: string

defaults to: cache.xml (OpenTTDLib::OPTION_DEFAULT_CACHE_FILE)

Specify the path (relative or absolute) of the cache file. Make sure your webserver user has permission to read and write to that file.


OpenTTDLib::OPTION_CACHE_UPDATE

Option type: boolean

defaults to: true (OpenTTDLib::OPTION_DEFAULT_CACHE_UPDATE)

Whether or not to write updated cache data back to the cache file. If OpenTTDLibCache is unable to write to the file due to file permissions, it will throw an exception. If you know this is going to happen, you can disable writing to the cache file with this option.


OpenTTDLib::OPTION_RETURNTYPE

Option type: integer

defaults to: OpenTTDLib::RETURNTYPE_OBJECT (OpenTTDLib::OPTION_DEFAULT_RETURNTYPE)

This tells OpenTTDLib::getInfo(), OpenTTDLib::getDetail() and OpenTTDLib::getNewGrf() which data type to return, can be one of OpenTTDLib::RETURNTYPE_ARRAY or OpenTTDLib::RETURNTYPE_OBJECT

NOTE: the default as of v0.3 is to return objects, but if you are expecting an array, set this option to OpenTTDLib::RETURNTYPE_ARRAY


OpenTTDLib::OPTION_QUERYTYPE

Option type: integer

defaults to: OpenTTDLib::QUERYTYPE_ALL (OpenTTDLib::OPTION_DEFAULT_QUERYTYPE)

Defines which information to retrieve from the game server Available query types are: OpenTTDLib::QUERYTYPE_ALL, OpenTTDLib::QUERYTYPE_INFO, OpenTTDLib::QUERYTYPE_DETAIL, OpenTTDLib::QUERYTYPE_NEWGRF


OpenTTDLib::OPTION_TIMEOUT

Option type: integer

defaults to: 5 (OpenTTDLib::OPTION_DEFAULT_TIMEOUT)

Defines how long to wait for a response packet from the server (is in seconds).

NOTE: currently a request udp packet is only sent once. Due to the nature of UDP packets have a chance of not arriving their destination ever...!



Prev Up Next
Easy HowTo User Guide to OpenTTDLib Return Value Structures

Documentation generated on Wed, 29 Apr 2009 23:33:49 +0200 by phpDocumentor 1.4.2