NMLTutorial/Object
The example used here is from the Dutch Road Furniture. The original graphics for this are by FooBar. The code is by FooBar, based on code for the object example from the NML source by planetmaker and Hirundu. Code and graphics are both licensed according to the GPL v2 or later. The code has been modified for the purpose of this tutorial.
Introduction
Objects, as well as stations, houses, industry tiles and airport tiles are coded slightly differently than vehicles. This difference mainly has to do with how sprites are defined. Item blocks and callbacks with switch blocks are still used as before, so our focus will be mainly on the graphics part. Stations are currently not yet possible in NML.
In this example we will make an object with four views to be used on flat ground tiles. After that we'll also make this object work on slopes, using some advanced features available in OpenTTD.
Folder structure
For this example we'll assume the following folder structure. There will be one language file in the lang folder, one graphics file in the gfx folder. These two folders sit together with the main NML file in one project folder:
object_example |- lang | |- english.lng |- gfx | |- dutch_fingerpost.png |- custom_tags.txt |- example_object.nml
Language files
Only English as default language with NewGRF name and description already defined. More things will be added to the language file as we go.
##grflangid 0x01 #Main grf title and description STR_GRF_NAME :{TITLE} STR_GRF_DESCRIPTION :Description: {SILVER}Dutch Road Furniture is an eyecandy object NewGRF that features road furniture that can be found alongside Dutch roads. {}(c)2011 FooBar. {}{BLACK}License: {SILVER}GPLv2 or higher.
custom_tags.txt this time contains the title of the NewGRF, see the introduction to language files for more details about the usage of custom_tags.txt.
NML file
Start the NML file by adding a grf block.
grf { grfid: "\FB\FB\05\01"; name: string(STR_GRF_NAME); desc: string(STR_GRF_DESCRIPTION); version: 0; min_compatible_version: 0; }
Nothing fancy there, just like we used to do and starting at version 0.
That should have you started nicely. Next we'll look into spritelayout blocks which are used for the graphics of objects.
NML Tutorial: Object