File: example_object.nml

package info (click to toggle)
nml 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,688 kB
  • sloc: python: 12,961; makefile: 37
file content (152 lines) | stat: -rw-r--r-- 5,609 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * This file is aimed to provide an example on how to code an Object in NML.
 * To keep the code readable, not every property or variable is documented in
 * detail, refer to the object-specific reference in the documentation.
 *
 * The NewGRF implements a replacement for the company land as NewObject which does
 * not show a sign but blends in with the terrain naturally. In transparent view
 * it shows a company-coloured border around the tiles.
 *
 * Apart from this file, you will also need the following
 * - Graphics, found in cc_grid.png (in the same folder)
 * - Language files, to be placed in the 'lang' folder.
 *      Currently english.lng is supplied.
 */

 /*
 * First, define a grf block. This defines some basic properties of the grf,
 * which are required for the grf to be valid and loadable.
 */
grf {
    /* This grf is part of NML, therefore "NML" is chosen as the first three
     * characters of the GRFID. It is the second real grf defined as part of
     * NML (the first is the train example), therefore the last character is
	 * set to 1. Successive grfs will have 2, 3, etc. there, to make sure each
	 * example grf has a unique GRFID.
     */
    grfid: "NML\01";
    /* GRF name and description strings are defined in the lang files */
    name: string(STR_GRF_NAME);
    desc: string(STR_GRF_DESCRIPTION);
    /* This is the first version, start numbering at 0. */
    version: 0;
    min_compatible_version: 0;
	/* This NewGRF has no parameters. See the train example NewGRF for parameter
	 * usage
	 */
}

/* Using parametrized sprite layouts are only valid in OpenTTD r22723 or later.
 * Earlier versions will choke on those and otherwise disable the NewGRF.
 */
if (version_openttd(1,2,0,22723) > openttd_version) {
	error(FATAL, REQUIRES_OPENTTD, string(STR_VERSION_22723));
}


// Template for 19 sprites: one for each possible tile slope
template tmpl_groundsprites(x, y) {
    [   0+x,   y, 64, 31, -31,  0 ]
    [  80+x,   y, 64, 31, -31,  0 ]
    [ 160+x,   y, 64, 23, -31,  0 ]
    [ 240+x,   y, 64, 23, -31,  0 ]

    [ 320+x,   y, 64, 31, -31,  0 ]
    [ 398+x,   y, 64, 31, -31,  0 ]
    [ 478+x,   y, 64, 23, -31,  0 ]
    [ 558+x,   y, 64, 23, -31,  0 ]

    [ 638+x,   y, 64, 39, -31, -8 ]
    [ 718+x,   y, 64, 39, -31, -8 ]
    [ 798+x,   y, 64, 31, -31, -8 ]
    [ 878+x,   y, 64, 31, -31, -8 ]

    [ 958+x,   y, 64, 39, -31, -8 ]
    [1038+x,   y, 64, 39, -31, -8 ]
    [1118+x,   y, 64, 31, -31, -8 ]
    [1196+x,   y, 64, 47, -31,-16 ]

    [1276+x,   y, 64, 15, -31,  0 ]
    [1356+x,   y, 64, 31, -31, -8 ]
    [1436+x,   y, 64, 31, -31, -8 ]
}

/* Spriteset of the 19 possible landslopes with company-coloured grid */
spriteset (cc_frame, "cc_grid.png") { tmpl_groundsprites(1, 1) }

spritelayout company_land_layout {
	ground {
		/* normal ground sprite - always draw */
		sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
	}
	childsprite {
		/* company-coloured border - always draw */
		sprite:        cc_frame(LOAD_TEMP(0));
		always_draw:   1;
		recolour_mode: RECOLOUR_REMAP;
		palette:       PALETTE_USE_DEFAULT;
	}
	childsprite {
		/* again the normal ground sprite. Thus in non-transparent view
		 * only the normal ground sprite is shown. In transparent view
		 * this acts as sprite which darkens the other two sprites via
		 * a translation to transparency.
		 */
		sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
	}
}

/* A pseudo-switch which sets the temporary parameters for the sprite layout */
switch (FEAT_OBJECTS, SELF, company_land_terrain_switch, [
			/* We store the offset into the spriteset due to the tile slope into the 1st temporary variable
			 * (= storage register 0)
			 */
			STORE_TEMP(slope_to_sprite_offset(tile_slope), 0),

			/* We store the offset to the flat groundsprite we use into the 2nd temporary variable
			 * (= storage register 1)
			 */
			STORE_TEMP(GROUNDSPRITE_NORMAL, 1),
			STORE_TEMP(terrain_type == TILETYPE_DESERT      ? GROUNDSPRITE_DESERT : LOAD_TEMP(1), 1),
			STORE_TEMP(terrain_type == TILETYPE_SNOW        ? GROUNDSPRITE_SNOW   : LOAD_TEMP(1), 1),
			]) {
	company_land_layout;
}

/* Pseudo switch for the purchase list branch: we want to display the flat ground tile */
switch (FEAT_OBJECTS, SELF, company_land_purchase_switch, [
			STORE_TEMP(0, 0),
			STORE_TEMP(GROUNDSPRITE_NORMAL, 1),

			1
			]) {
	company_land_layout;
}

/* Define the object itself */
item(FEAT_OBJECTS, company_land) {
	property {
		/* The class allows to sort objects into categories. This is 'infrastructure' */
		class:                  "INFR";
		/* If no other NewGRF provides this class before us, we have to name it */
		classname:              string(STR_NAME_OBJCLASS_INFRASTRUCTURE);
		/* Name of this particular object */
		name:                   string(STR_NAME_COMPANY_LAND);
		climates_available:     ALL_CLIMATES;
		size:                   [1, 1];
		build_cost_multiplier:  1;
		remove_cost_multiplier: 1;
		introduction_date:      date(1,1,1);        // available from day 1
		end_of_life_date:       date(10000,1,1);    // available till year 10000
		/* Anything can overbuild the object, removing returns the money, we don't want foundations and we want to allow bridges */
		object_flags:           bitmask(OBJ_FLAG_ANYTHING_REMOVE, OBJ_FLAG_REMOVE_IS_INCOME, OBJ_FLAG_NO_FOUNDATIONS, OBJ_FLAG_ALLOW_BRIDGE);
		height:                 0;                  // it's only a ground tile
		num_views:              1;
	}
	graphics {
		purchase:            company_land_purchase_switch;
		tile_check:          return 0;
		additional_text:     return string(STR_NAME_COMPANY_LAND);
		company_land_terrain_switch;
	}
}