In my little
Prohibition industry NewGRF there is an "industry" called "Coast Guard station" that can only be built on flat land directly next to water, not on the water itself and not on the "slope tiles".
This is the code used for that behaviour:
Code: Select all
switch(FEAT_INDUSTRYTILES, SELF, Coast_Guard_Station_tile_1_lc_0,
(nearby_tile_class( 1, 1) == TILE_CLASS_WATER) |
(nearby_tile_class( 1, 0) == TILE_CLASS_WATER) |
(nearby_tile_class( 1, -1) == TILE_CLASS_WATER) |
(nearby_tile_class( 0, -1) == TILE_CLASS_WATER) |
(nearby_tile_class(-1, -1) == TILE_CLASS_WATER) |
(nearby_tile_class(-1, 0) == TILE_CLASS_WATER) |
(nearby_tile_class(-1, 1) == TILE_CLASS_WATER) |
(nearby_tile_class( 0, 1) == TILE_CLASS_WATER)) {
0: return string(STR_ERROR_ONLY_NEXT_TO_WATER);
Coast_Guard_Station_tile_1_lc_1;
}
It checks all eight tiles around the central tile, which has coordinates (0, 0). Full NML source code in the attachment.
The only limit it has is that it can be built not only next to "ocean tiles" but also "river" and "channel" tiles - but as far as I know, there is no (or no simple) way to distinguish between these.