diff --git a/docs/newgrf-town-nml.html b/docs/newgrf-town-nml.html
index acce091346..206d70c784 100644
--- a/docs/newgrf-town-nml.html
+++ b/docs/newgrf-town-nml.html
@@ -51,6 +51,8 @@
town_zone_2_radius_square_uncapped | 0..4294967295 | Town zone 2 radius squared (not clamped to 0xFFFF) | town_uncapped_variables, version 1 |
town_zone_3_radius_square_uncapped | 0..4294967295 | Town zone 3 radius squared (not clamped to 0xFFFF) | town_uncapped_variables, version 1 |
town_zone_4_radius_square_uncapped | 0..4294967295 | Town zone 4 radius squared (not clamped to 0xFFFF) | town_uncapped_variables, version 1 |
+ x_coordinate | 0..65535 | X coordinate of town tile | varaction2_towns_town_xy, version 1 |
+ y_coordinate | 0..65535 | Y coordinate of town tile | varaction2_towns_town_xy, version 1 |
Town Generic Callbacks
diff --git a/docs/newgrf-town.html b/docs/newgrf-town.html
index 10c5f948f7..f7088722d8 100644
--- a/docs/newgrf-town.html
+++ b/docs/newgrf-town.html
@@ -54,6 +54,7 @@
town_zone_2_radius_square | Town zone 2 radius squared |
town_zone_3_radius_square | Town zone 3 radius squared |
town_zone_4_radius_square | Town zone 4 radius squared |
+ town_xy | Town tile X and Y coordinates |
Number of town house (mappable variable: town_house_count)
@@ -68,6 +69,16 @@
This is the same as town variables 94, 96, 98, 9A, 9C, except 32 bits and not clamped to a maximum value of 0xFFFF.
This requires town_uncapped_variables, version 1.
+ Town tile X and Y coordinates (mappable variable: town_xy)
+
+ Bits | Meaning |
+ 0 - 15 | X coordinate of town tile |
+ 16 - 31 | Y coordinate of town tile |
+
+ This is similar to town variable 80, except the Y part is in the upper 16 bits and the X part is in the lower 16 bits.
+ This is the same format as house variable 47.
+ This requires varaction2_towns_town_xy, version 1.
+
Action 3 - Town
diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp
index 492a3a23d8..da364503bc 100644
--- a/src/newgrf_extension.cpp
+++ b/src/newgrf_extension.cpp
@@ -67,6 +67,7 @@ extern const GRFFeatureInfo _grf_feature_list[] = {
GRFFeatureInfo("town_feature", 1),
GRFFeatureInfo("town_uncapped_variables", 1),
GRFFeatureInfo("town_zone_callback", 1, GFTOF_TOWN_ZONE_CALLBACK),
+ GRFFeatureInfo("varaction2_towns_town_xy", 1),
GRFFeatureInfo("more_varaction2_types", 1, GFTOF_MORE_VARACTION2_TYPES),
GRFFeatureInfo("multi_part_ships", 1, GFTOF_MULTI_PART_SHIPS),
GRFFeatureInfo(),
@@ -182,6 +183,7 @@ extern const GRFVariableMapDefinition _grf_action2_remappable_variables[] = {
GRFVariableMapDefinition(GSF_FAKE_TOWNS, A2VRI_TOWNS_ZONE_2, "town_zone_2_radius_square"),
GRFVariableMapDefinition(GSF_FAKE_TOWNS, A2VRI_TOWNS_ZONE_3, "town_zone_3_radius_square"),
GRFVariableMapDefinition(GSF_FAKE_TOWNS, A2VRI_TOWNS_ZONE_4, "town_zone_4_radius_square"),
+ GRFVariableMapDefinition(GSF_FAKE_TOWNS, A2VRI_TOWNS_XY, "town_xy"),
GRFVariableMapDefinition(GSF_NEWLANDSCAPE, 0x40, "newlandscape_terrain_type"),
GRFVariableMapDefinition(GSF_NEWLANDSCAPE, 0x41, "newlandscape_tile_slope"),
GRFVariableMapDefinition(GSF_NEWLANDSCAPE, 0x42, "newlandscape_tile_height"),
diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h
index ee0afc5a38..9547f381ed 100644
--- a/src/newgrf_extension.h
+++ b/src/newgrf_extension.h
@@ -96,6 +96,7 @@ enum Action2VariableRemapIds {
A2VRI_TOWNS_ZONE_2,
A2VRI_TOWNS_ZONE_3,
A2VRI_TOWNS_ZONE_4,
+ A2VRI_TOWNS_XY,
};
enum GRFFeatureTestObservationFlag : uint8 {
diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp
index bea32ffd18..c5e69943cf 100644
--- a/src/newgrf_town.cpp
+++ b/src/newgrf_town.cpp
@@ -119,6 +119,9 @@
case A2VRI_TOWNS_ZONE_3:
case A2VRI_TOWNS_ZONE_4:
return this->t->cache.squared_town_zone_radius[variable - A2VRI_TOWNS_ZONE_0];
+
+ case A2VRI_TOWNS_XY:
+ return TileY(this->t->xy) << 16 | (TileX(this->t->xy) & 0xFFFF);
}
DEBUG(grf, 1, "Unhandled town variable 0x%X", variable);
@@ -180,6 +183,7 @@
case A2VRI_TOWNS_ZONE_2:
case A2VRI_TOWNS_ZONE_3:
case A2VRI_TOWNS_ZONE_4:
+ case A2VRI_TOWNS_XY:
return 0;
}
diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h
index 342de61ee1..fadc2edafd 100644
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -1639,6 +1639,7 @@ static const NIVariable _niv_towns[] = {
NIV(A2VRI_TOWNS_ZONE_2, "zone radius 2 (uncapped)"),
NIV(A2VRI_TOWNS_ZONE_3, "zone radius 3 (uncapped)"),
NIV(A2VRI_TOWNS_ZONE_4, "zone radius 4 (uncapped)"),
+ NIV(A2VRI_TOWNS_XY, "town tile xy"),
NIV_END()
};