Skip to content

Commit

Permalink
Add: example for stations (conversion of CHIPS Cow pens)
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Aug 29, 2022
1 parent 350f078 commit 8a51324
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 0 deletions.
Binary file added examples/station/cows_cargo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions examples/station/example_station.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* This file is aimed to provide an example on how to code a Station in NML.
* To keep the code readable, not every property or variable is documented in
* detail, refer to the station-specific reference in the documentation.
*
* The NewGRF implements a conversion of CHIPS Cow pens.
*
* Apart from this file, you will also need the following
* - Graphics, found in cows_cargo.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 seventh real grf defined as part of
* NML (the first is the train example), therefore the last character is
* set to 6. Successive grfs will have 7, 8, etc. there, to make sure each
* example grf has a unique GRFID.
*/
grfid: "NML\06";
/* 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));
}

cargotable {
LVST
}

spriteset (cow_pen_empty, "cows_cargo.png") {
[ 10, 10, 64, 65, -31, -34 ]
[ 220, 10, 64, 65, -31, -34 ]
}

spriteset (cow_pen_half, "cows_cargo.png") {
[ 80, 10, 64, 65, -31, -34 ]
[ 290, 10, 64, 65, -31, -34 ]
}

spriteset (cow_pen_full, "cows_cargo.png") {
[ 150, 10, 64, 65, -31, -34 ]
[ 360, 10, 64, 65, -31, -34 ]
}

spritelayout cow_pen_X(a) {
ground {
sprite: 2022 + a; // prevent railtype offset
}
building {
sprite: SPRITESET(0); // first sprite in active spriteset
zextent: 36;
recolour_mode: RECOLOUR_REMAP;
palette: PALETTE_USE_DEFAULT;
}
}

spritelayout cow_pen_Y(a) {
ground {
sprite: 2022 + a; // prevent railtype offset
}
building {
sprite: SPRITESET(1); // second sprite in active spriteset
zextent: 36;
recolour_mode: RECOLOUR_REMAP;
palette: PALETTE_USE_DEFAULT;
}
}

spritegroup cow_pen_1 {
little: [cow_pen_empty, cow_pen_half];
lots: cow_pen_full;
}

spritegroup cow_pen_2 {
little: [cow_pen_empty, cow_pen_half, cow_pen_full];
lots: cow_pen_full;
}

random_switch(FEAT_STATIONS, TILE, random_cow_pen) {
1: cow_pen_1;
1: cow_pen_2;
}

/* Define the station itself */
item(FEAT_STATIONS, cow_pen) {
property {
/* The class allows to sort stations into categories. */
class: "NML_";
/* If no other NewGRF provides this class before us, we have to name it */
classname: string(STR_NAME_STATCLASS);
/* Name of this particular station */
name: string(STR_NAME_STATION);
cargo_threshold: 160;
draw_pylon_tiles: 0;
hide_wire_tiles: 0xFF;
non_traversable_tiles: 0xFF;
}
graphics {
sprite_layouts: [cow_pen_X(0), cow_pen_Y(0)];
purchase: cow_pen_half;
LVST: random_cow_pen;
cow_pen_empty;
}
}
9 changes: 9 additions & 0 deletions examples/station/lang/english.lng
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##grflangid 0x01
STR_GRF_NAME :NML Example NewGRF: Station
STR_GRF_DESCRIPTION :{ORANGE}NML Example NewGRF: Station{}{BLACK}This NewGRF is intended to provide a coding example for the high-level NewGRF-coding language NML.{}Conversion of CHIPS Cow pens.

STR_VERSION_22723 :1.2.0 (r22723)

STR_NAME_STATCLASS :NML Example

STR_NAME_STATION :CHIPS Cow pens
Binary file added regression/expected/example_station.grf
Binary file not shown.
138 changes: 138 additions & 0 deletions regression/expected/example_station.nfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Automatically generated by GRFCODEC. Do not modify!
// (Info version 32)
// Escapes: 2+ 2- 2< 2> 2u< 2u> 2/ 2% 2u/ 2u% 2* 2& 2| 2^ 2sto = 2s 2rst = 2r 2psto 2ror = 2rot 2cmp 2ucmp 2<< 2u>> 2>>
// Escapes: 71 70 7= 7! 7< 7> 7G 7g 7gG 7GG 7gg 7c 7C
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags

0 * 4 \d29

1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
"B" "MINV" \w4 \dx00000000
"B" "NPAR" \w1 00
"B" "PALS" \w1 "D"
"B" "BLTR" \w1 "8"
00
00
2 * 193 08 08 "NML\06" "NML Example NewGRF: Station" 00 "\8ENML Example NewGRF: Station\0D\98This NewGRF is intended to provide a coding example for the high-level NewGRF-coding language NML.\0DConversion of CHIPS Cow pens." 00
// param[126] = param[161]
3 * 5 0D 7E \D= A1 00

// param[127] = (param[126] - 302012611)
4 * 9 0D 7F \D- 7E FF \dx120058C3

// param[127] = (param[127] << -31)
5 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1

6 * 9 09 7F 04 \7= \dx00000000 01

7 * 19 0B 03 7F 06 "1.2.0 (r22723)" 00

8 * 12 00 08 \b1 01 FF \wx0000
09 "LVST"

9 * 6 01 04 \b3 FF \wx0002

10 cows_cargo.png 8bpp 10 10 64 65 -31 -34 normal
11 cows_cargo.png 8bpp 220 10 64 65 -31 -34 normal

12 cows_cargo.png 8bpp 80 10 64 65 -31 -34 normal
13 cows_cargo.png 8bpp 290 10 64 65 -31 -34 normal

14 cows_cargo.png 8bpp 150 10 64 65 -31 -34 normal
15 cows_cargo.png 8bpp 360 10 64 65 -31 -34 normal

// Name: cow_pen_1 - feature 04
16 * 11 02 04 FF \b2 \b1
\w0 \w1
\w2

// Name: cow_pen_2 - feature 04
17 * 13 02 04 FE \b3 \b1
\w0 \w1 \w2
\w2

// Name: random_cow_pen
18 * 11 02 04 FE 80 00 \b16 02
\wx00FF // (1/2) -> (1/2): cow_pen_1;
\wx00FE // (1/2) -> (1/2): cow_pen_2;

19 * 21 00 04 \b5 01 FF \wx0000
08 "NML_"
10 \wx00A0
11 00
14 FF
15 FF

20 * 18 04 04 FF 01 \wxC400 "NML Example" 00

21 * 21 04 04 FF 01 \wxC500 "CHIPS Cow pens" 00

// Name: cow_pen_half - feature 04
22 * 7 02 04 FF \b0 \b1

\w1

// Name: cow_pen_empty - feature 04
23 * 7 02 04 FD \b0 \b1

\w0

24 * 51 00 04 \b1 01 FF \wx0000
1A \b2
\b65 \dx00000000 \wx0002 82
\dx8000842D \wx0002 \b0 \b0 \b0 \b16 \b16 \b36 83
\b65 \dx00000000 \wx0002 84
\dx8000842D \wx0002 \b0 \b0 \b0 \b16 \b16 \b36 85

// Name: Station Layout@registers - Id 00
// a : register 80
// a : register 81
25 * 106 02 04 FC 89
1A 20 \dx00000000
\2sto 1A 20 \dx00000080
\2r 7D 80 20 \dxFFFFFFFF // a
\2+ 1A 20 \dx000007E6
\2sto 1A 20 \dx00000082
\2r 1A 20 \dx00000000
\2sto 1A 20 \dx00000083
\2r 1A 20 \dx00000000
\2sto 1A 20 \dx00000081
\2r 7D 81 20 \dxFFFFFFFF // a
\2+ 1A 20 \dx000007E6
\2sto 1A 20 \dx00000084
\2r 1A 20 \dx00000001
\2sto 1A 00 \dx00000085
\b0
\wx8000 // Return computed value

// Name: @action3_0
26 * 31 02 04 FD 89
7E FC 20 \dxFFFFFFFF // Station Layout@registers - Id 00
\2r 10 00 \dx000000FF
\b1
\wx00FD \dx00000000 \dx00000000 // cow_pen_empty;
\wx00FD // cow_pen_empty;

// Name: @action3_1
27 * 31 02 04 FE 89
7E FC 20 \dxFFFFFFFF // Station Layout@registers - Id 00
\2r 10 00 \dx000000FF
\b1
\wx00FE \dx00000000 \dx00000000 // random_cow_pen;
\wx00FE // random_cow_pen;

// Name: @action3_2
28 * 31 02 04 FF 89
7E FC 20 \dxFFFFFFFF // Station Layout@registers - Id 00
\2r 10 00 \dx000000FF
\b1
\wx00FF \dx00000000 \dx00000000 // cow_pen_half;
\wx00FF // cow_pen_half;

29 * 13 03 04 01 00 \b2
00 \wx00FE // @action3_1;
FF \wx00FF // @action3_2;
\wx00FD // @action3_0;

0 comments on commit 8a51324

Please sign in to comment.