Skip to content

Instantly share code, notes, and snippets.

@glx22
Created December 6, 2021 18:20
Show Gist options
  • Save glx22/264c5293e723b7a97ab6ab98ef1e6538 to your computer and use it in GitHub Desktop.
Save glx22/264c5293e723b7a97ab6ab98ef1e6538 to your computer and use it in GitHub Desktop.
// 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 \d17
1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
"B" "MINV" \w4 \dx00000000
"B" "NPAR" \w1 00
"B" "PALS" \w1 "A"
"B" "BLTR" \w1 "8"
00
00
2 * 292 08 08 "NML\01" "NML Example NewGRF: Object" 00 "\8ENML Example NewGRF: Object\0D\98This NewGRF is intended to provide a coding example for the high-level NewGRF-coding language NML.\0DOriginal graphics by \89planetmaker, \98coding by \89planetmaker.\0D\98This NewGRF defines a tile which can act as company-land replacement." 00
3 * 34 04 0F FF 02 \wxD000 "Infrastructure" 00 "Company land" 00
4 * 19 04 00 FF 01 \wxD002 "Company land" 00
// param[126] = param[161]
5 * 5 0D 7E \D= A1 00
// param[127] = (param[126] - 302012611)
6 * 9 0D 7F \D- 7E FF \dx120058C3
// param[127] = (param[127] << -31)
7 * 9 0D 7F \Du<< 7F FF \dxFFFFFFE1
8 * 9 09 7F 04 \7= \dx00000000 01
9 * 19 0B 03 7F 06 "1.2.0 (r22723)" 00
// Name: company_land_layout - feature 0F
10 * 20 02 0F FF \b64 \dx00000000 \wx0002 81
\dx00000000 \b0 \b0 \b0 \b0 \b0
// Name: company_land_layout@registers - feature 0F
11 * 54 02 0F FF 89
7D 01 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000080
\2r 7D 00 20 \dxFFFFFFFF
\2+ 7D 80 20 \dxFFFFFFFF
\2sto 1A 00 \dx00000081
\b1
\wx00FF \dx00000000 \dx00000000
\wx00FF //
// Name: company_land_terrain_switch
12 * 470 02 0F FE 89
41 28 \dx0000001F
\2cmp 1A 20 \dx0000001E
\2& 1A 20 \dx00000001
\2* 1A 20 \dx00000012
\2sto 1A 20 \dx00000080
\2r 41 28 \dx0000001F
\2cmp 1A 20 \dx0000001D
\2& 1A 20 \dx00000001
\2* 1A 20 \dx0000000F
\2sto 1A 20 \dx00000081
\2r 41 28 \dx0000001F
\2cmp 1A 20 \dx0000001B
\2& 1A 20 \dx00000001
\2* 1A 20 \dx00000011
\2sto 1A 20 \dx00000082
\2r 41 28 \dx0000001F
\2cmp 1A 20 \dx00000017
\2& 1A 20 \dx00000001
\2* 1A 20 \dx00000010
\2sto 1A 20 \dx00000083
\2r 41 28 \dx0000001F
\2cmp 1A 20 \dx00000000
\2< 1A 20 \dx00000001
\2sto 1A 20 \dx00000084
\2r 41 28 \dx0000001F
\2cmp 1A 20 \dx0000000E
\2^ 1A 20 \dx00000002
\2< 1A 20 \dx00000001
\2& 7D 84 20 \dxFFFFFFFF
\2* 41 28 \dx0000001F
\2+ 7D 83 20 \dxFFFFFFFF
\2+ 7D 82 20 \dxFFFFFFFF
\2+ 7D 81 20 \dxFFFFFFFF
\2+ 7D 80 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000000
\2r 1A 20 \dx00000F8D
\2sto 1A 20 \dx00000001
\2r 41 20 \dx00000007
\2cmp 1A 20 \dx00000001
\2& 1A 20 \dx00000001
\2sto 1A 20 \dx00000085 // guard
\2^ 1A 20 \dx00000001
\2sto 1A 20 \dx00000086 // !guard
\2r 7D 01 20 \dxFFFFFFFF
\2* 7D 86 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000087
\2r 7D 85 20 \dxFFFFFFFF
\2* 1A 20 \dx000011C6
\2+ 7D 87 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000001
\2r 41 20 \dx00000007
\2cmp 1A 20 \dx00000004
\2& 1A 20 \dx00000001
\2sto 1A 20 \dx00000088 // guard
\2^ 1A 20 \dx00000001
\2sto 1A 20 \dx00000089 // !guard
\2r 7D 01 20 \dxFFFFFFFF
\2* 7D 89 20 \dxFFFFFFFF
\2sto 1A 20 \dx0000008A
\2r 7D 88 20 \dxFFFFFFFF
\2* 1A 20 \dx000011C6
\2+ 7D 8A 20 \dxFFFFFFFF
\2sto 1A 00 \dx00000001
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx00FF // default: company_land_layout;
// Name: company_land_purchase_switch
13 * 51 02 0F FF 89
1A 20 \dx00000000
\2sto 1A 20 \dx00000000
\2r 1A 20 \dx00000F8D
\2sto 1A 20 \dx00000001
\2r 1A 00 \dx00000001
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx00FF // default: company_land_layout;
14 * 43 00 0F \b12 01 FF \wx0000
08 "INFR"
09 \wxD000
0A \wxD001
0B 0F
0C 11
0D 01
14 01
0E \dx0000016E
0F \dx0037BB49
10 \wx0834
16 00
17 01
15 * 10 00 0F \b1 01 FF \wx0000
15 \wx0011
// Name: @action3_0
16 * 43 02 0F FF 89
0C 00 \dx0000FFFF
\b3
\wx00FF \dx00000000 \dx00000000 // company_land_purchase_switch;
\wx8400 \dx00000157 \dx00000157 // return 1024;
\wx8002 \dx0000015C \dx0000015C // return string(STR_NAME_COMPANY_LAND);
\wx00FE // company_land_terrain_switch;
17 * 10 03 0F 01 00 \b1
FF \wx00FF // @action3_0;
\wx00FE // company_land_terrain_switch;
/*
* 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;
// Allow placement on any land tile (the default prevents building on 'steep' slopes).
// The object cannot be placed on water despite this, because OBJ_FLAG_ON_WATER isn't set.
tile_check: return CB_RESULT_LOCATION_ALLOW;
additional_text: return string(STR_NAME_COMPANY_LAND);
company_land_terrain_switch;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment