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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
|
/*
* This file is aimed to provide an example on how to code a railtype 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 graphical replacement for the normal and electric
* rails. Since almost all sprites (except caternary) are supplied, you can
* use this grf to see in detail what sprites are needed and in what order.
*
* Essentially this is a cut-down version of the Swedish Rails grf, drawn by
* Irwe and coded by planetmaker. Support for parameters, time-dependent
* graphics and snow support has been removed to keep this example within
* reasonable size. Due to the large quantity of sprites required for a
* railtype grf, the number of lines of code is still relatively high.
*
* All real sprites have been templated, even if the template is used only
* once. This allows adding e.g. snowed graphics fairly easily.
*
* Apart from this file, you will also need the following
* - Graphics, found in in the gfx folder
* - Language files, to be placed in the 'lang' folder.
* Currently english.lng is supplied.
*/
/**********************************************
* Header, containing some general stuff:
**********************************************/
/*
* 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 third real grf defined as part of
* NML, therefore the last character is set to 2. Successive grfs will
* have 3, 4, etc. there, to make sure each example grf has a unique GRFID.
*/
grfid : "NML\02";
name : string(STR_GRF_NAME);
desc : string(STR_GRF_DESCRIPTION);
version : 0; // must be numeric
min_compatible_version : 0;
}
/* Check for NuTracks and disable, if we're not active _after_ NuTracks */
if (!grf_order_behind("DJT\01")) {
error(FATAL, MUST_LOAD_AFTER, "NuTracks");
}
/* Default ground tile template (re-use as needed) */
template ground_tile(x, y) { [x, y, 64, 31, -31, 0] }
/**********************************************
* Track underlays (tracks + ballast):
**********************************************/
/* Underlays (single track bits with ballast)\
* Used for bridge surfaces also, therefore the template is split */
template tmpl_underlay_straight() {
ground_tile(75, 0)
ground_tile( 0, 0)
}
template tmpl_underlay_slope() {
[ 75, 40, 64,39, -31, -8]
[150, 40, 64,23, -31, 0]
[225, 40, 64,23, -31, 0]
[300, 40, 64,39, -30, -9]
}
template tmpl_underlay_diagonal() {
ground_tile(150, 0)
ground_tile(225, 0)
ground_tile( 0, 40)
ground_tile(300, 0)
}
template tmpl_underlay_railtypes() {
tmpl_underlay_straight()
tmpl_underlay_diagonal()
tmpl_underlay_slope()
/* X-crossing */
ground_tile(0, 120)
/* underlay for crossings w/o tracks */
ground_tile( 0, 80)
ground_tile(225, 80)
ground_tile(150, 80)
ground_tile( 75, 80)
ground_tile(300, 80)
}
/* Spriteset containing all underlays */
spriteset(track_underlays, "gfx/rails_overlays.png") {
tmpl_underlay_railtypes()
}
/**********************************************
* Track overlays (tracks without ballast):
**********************************************/
/* Template for overlays; 2x straight track, 4x diagonal track, 4x slope */
template tmpl_overlay_railtypes() {
[ 0,155, 40,21, -19, 5]
[ 50,155, 40,21, -19, 5]
[100,155, 40, 7, -19, 4]
[150,155, 40, 7, -21, 20]
[200,155, 12,19, 11, 6]
[250,155, 12,19, -21, 6]
[ 0,195, 64,39, -33, -8]
[ 75,195, 64,23, -31, 0]
[150,195, 64,23, -31, 0]
[225,195, 64,39, -32, -9]
}
/* Spriteset for overlays */
spriteset(track_overlays, "gfx/rails_overlays.png") {
tmpl_overlay_railtypes()
}
/**********************************************
* Level crossings:
**********************************************/
/* Level crossings require differing sprites depending
* on the open/closed state and on the driving side */
/* Template for the track overlays (x/y) */
template tmpl_rails_crossing(x,y) {
[x, y, 44, 23, -21, 4]
[x+50, y, 44, 23, -21, 4]
}
template tmpl_level_crossing_railtypes_open(y) {
tmpl_rails_crossing(5, 5)
[ 0, y, 5,12, -3, -8]
[ 50, y, 8,21, -5, -14]
[100, y, 6,23, -7, -20]
[150, y, 5,12, -5, -8]
[200, y, 7,21, 3, -15]
[250, y, 5,12, -1, -8]
[300, y, 5,12, -3, -10]
[350, y, 8,22, -3, -19]
}
template tmpl_level_crossing_railtypes_closed(y) {
tmpl_rails_crossing(5, 5)
[ 0, y, 5, 12, -3, -8]
[ 50, y, 19, 19, -4, -6]
[100, y, 23, 17, -24, -9]
[150, y, 5, 12, -5, -8]
[200, y, 25, 14, 3, -9]
[250, y, 5, 12, -1, -8]
[300, y, 5, 12, -3, -10]
[350, y, 19, 14, -15, -11]
}
template tmpl_level_crossing_railtypes_left_open(y) {
tmpl_rails_crossing(5, 5)
[ 0, y, 7, 21, 0, -14]
[ 50, y, 5, 12, -2, -6]
[100, y, 5, 12, -3, -9]
[150, y, 7, 21, -7, -15]
[200, y, 5, 12, 4, -7]
[250, y, 7, 22, 0, -17]
[300, y, 6, 21, -2, -19]
[350, y, 5, 12, -3, -9]
}
template tmpl_level_crossing_railtypes_left_closed(y) {
tmpl_rails_crossing(5, 5)
[ 0, y, 21, 19, -14, -6]
[ 50, y, 5, 12, -2, -6]
[100, y, 5, 12, -3, -9]
[150, y, 23, 15, -23, -9]
[200, y, 5, 12, 4, -7]
[250, y, 23, 17, 0, -7]
[300, y, 21, 13, -2, -11]
[350, y, 5, 12, -3, -9]
}
// right hand traffic:
spriteset(lc_right_closed, "gfx/lc_right.png") {
tmpl_level_crossing_railtypes_closed(100)
}
spriteset(lc_right_open, "gfx/lc_right.png") {
tmpl_level_crossing_railtypes_open(50)
}
// left hand traffic:
spriteset(lc_left_closed, "gfx/lc_left.png") {
tmpl_level_crossing_railtypes_left_closed(100)
}
spriteset(lc_left_open, "gfx/lc_left.png") {
tmpl_level_crossing_railtypes_left_open(50)
}
switch(FEAT_RAILTYPES, SELF, right_level_crossing_state_switch, level_crossing_status) {
LEVEL_CROSSING_CLOSED: lc_right_closed;
lc_right_open;
}
switch(FEAT_RAILTYPES, SELF, left_level_crossing_state_switch, level_crossing_status) {
LEVEL_CROSSING_CLOSED: lc_left_closed;
lc_left_open;
}
switch(FEAT_RAILTYPES, SELF, level_crossing_switch, traffic_side) {
TRAFFIC_SIDE_LEFT: left_level_crossing_state_switch;
right_level_crossing_state_switch;
}
/**********************************************
* Tracks in tunnels:
**********************************************/
/* Template for tunnel track overlays */
template tmpl_tunnel_tracks() {
ground_tile(75, 0)
ground_tile( 0, 0)
ground_tile(75, 50)
ground_tile( 0, 50)
}
spriteset(tunnel_overlays, "gfx/tunnel_track.png") {
tmpl_tunnel_tracks()
}
/**********************************************
* Depots:
**********************************************/
/* Template for depot sprites */
template tmpl_depot() {
[200, 10, 16, 8, 17, 7]
[118, 8, 64, 47, -9, -31]
[ 0, 10, 16, 8, -31, 7]
[ 37, 8, 64, 47, -53, -31]
[ 37, 63, 64, 47, -53, -31]
[118, 63, 64, 47, -9, -31]
}
/* Depots have differing sprites for normal and e-rail */
spriteset(depot_normal_rail, "gfx/depot_normal.png") {
tmpl_depot()
}
spriteset(depot_electric_rail, "gfx/depot_electric.png") {
tmpl_depot()
}
/**********************************************
* Bridge surfaces:
**********************************************/
/* Bridge surface, uses the same sprites as track underlays, but in a different order */
template tmpl_bridges_underlay() {
tmpl_underlay_straight()
tmpl_underlay_slope()
tmpl_underlay_diagonal()
}
/* Spriteset for bridge surfaces */
spriteset(bridge_underlay, "gfx/rails_overlays.png") {
tmpl_bridges_underlay()
}
/**********************************************
* Fences:
**********************************************/
/* Template for fences, parametrized to allow multiple sets of fences (unused) */
template tmpl_fences(y) {
[ 0, y, 32,20, -30, -4]
[ 48, y, 32,20, 0, -3]
[ 96, y, 2,30, 0,-17]
[112, y, 64, 5, -30, -4]
[192, y, 32,12, -30, -4]
[240, y, 32,12, 2, -3]
[288, y, 32,28, -31,-12]
[350, y, 32,28, 1,-10]
}
/* Spriteset for (company-coloured) fences */
spriteset(fencesCC, "gfx/fences.png") {
tmpl_fences(0)
}
/**********************************************
* GUI sprites:
**********************************************/
/* Template for a single icon sprite */
template tmpl_gui_icon(x, y) {
[x, y, 20, 20, 0, 0]
}
/* Template for a single cursor sprite */
template tmpl_gui_cursor(x, y) {
[x, y, 32, 32, 0, 0]
}
/* Template for all the GUI sprites (8 icons + 8 cursors) */
template tmpl_gui() {
tmpl_gui_icon( 0, 0)
tmpl_gui_icon( 25, 0)
tmpl_gui_icon( 50, 0)
tmpl_gui_icon( 75, 0)
tmpl_gui_icon(100, 0)
tmpl_gui_icon(125, 0)
tmpl_gui_icon(150, 0)
tmpl_gui_icon(175, 0)
tmpl_gui_cursor(200, 0)
tmpl_gui_cursor(250, 0)
tmpl_gui_cursor(300, 0)
tmpl_gui_cursor(350, 0)
tmpl_gui_cursor(400, 0)
tmpl_gui_cursor(450, 0)
tmpl_gui_cursor(500, 0)
tmpl_gui_cursor(550, 0)
}
/* Spritesets for the normal and electric GUI */
spriteset(gui_normal, "gfx/gui_rail.png") {
tmpl_gui()
}
spriteset(gui_electric, "gfx/gui_erail.png") {
tmpl_gui()
}
/**********************************************
* Railtype definitions:
**********************************************/
/* Define the normal rails */
item(FEAT_RAILTYPES, rail) {
/* Set only the most essential properties,
* Lots of compatible railtypes are defined to allow compatibility with
* various other sets out there */
property {
label: "RAIL"; // Let this railtype replace the default normal rails
compatible_railtype_list: ["RAIL", "ELRL", "_040", "_080", "RLOW", "RMED", "RHIG", "E040", "E080", "ELOW", "EMED", "EHIG", "HSTR", "DBNN", "DBNE", "DBHN", "DBHE"];
powered_railtype_list: ["RAIL", "ELRL", "_040", "_080", "RLOW", "RMED", "RHIG", "E040", "E080", "ELOW", "EMED", "EHIG", "HSTR", "DBNN", "DBNE", "DBHN", "DBHE"];
}
/* Associate graphics with this railtype */
graphics {
track_overlay: track_overlays;
underlay: track_underlays;
level_crossings: level_crossing_switch;
tunnels: tunnel_overlays;
depots: depot_normal_rail;
bridge_surfaces: bridge_underlay;
fences: fencesCC;
gui: gui_normal;
/* Caternary is not not implemented here, use the default */
}
}
/* Define the electric rails */
item(FEAT_RAILTYPES, elrail) {
/* Set only the most essential properties,
* Lots of compatible railtypes are defined to allow compatibility with
* various other sets out there */
property {
label: "ELRL"; // Let this railtype replace the default electric rails
compatible_railtype_list: ["RAIL", "ELRL", "_040", "_080", "RLOW", "RMED", "RHIG", "E040", "E080", "ELOW", "EMED", "EHIG", "HSTR", "DBNN", "DBNE", "DBHN", "DBHE"];
powered_railtype_list: ["ELRL", "E040", "E080", "ELOW", "EMED", "EHIG", "HSTR", "DBNE", "DBHE"];
}
/* Associate graphics with this railtype */
graphics {
track_overlay: track_overlays;
underlay: track_underlays;
level_crossings: level_crossing_switch;
tunnels: tunnel_overlays;
depots: depot_electric_rail;
bridge_surfaces: bridge_underlay;
fences: fencesCC;
gui: gui_electric;
/* Caternary is not not implemented here, use the default */
}
}
|