summaryrefslogtreecommitdiff
path: root/src/newgrf_engine.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2021-01-10 14:37:40 +0100
committerfrosch <github@elsenhans.name>2021-01-10 21:24:38 +0100
commit868d84bbfc8d2c1471ef713854dd05ebc872615a (patch)
treeeaad084698335fd20cd31e01729fa6e0eec9fa47 /src/newgrf_engine.cpp
parent5b089605606ecbf6d7e9996b49f6cb0605deaa68 (diff)
downloadopenttd-868d84bbfc8d2c1471ef713854dd05ebc872615a.tar.xz
Add: [NewGRF] vehicle variable 63 to test the tracktype of the current tile against a given tracktype.
Diffstat (limited to 'src/newgrf_engine.cpp')
-rw-r--r--src/newgrf_engine.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 8066ea432..e3dc059ff 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -702,6 +702,36 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
return ret;
}
+ case 0x63:
+ /* Tile compatibility wrt. arbitrary track-type
+ * Format:
+ * bit 0: Type 'parameter' is known.
+ * bit 1: Engines with type 'parameter' are compatible with this tile.
+ * bit 2: Engines with type 'parameter' are powered on this tile.
+ * bit 3: This tile has type 'parameter' or it is considered equivalent (alternate labels).
+ */
+ switch (v->type) {
+ case VEH_TRAIN: {
+ RailType param_type = GetRailTypeTranslation(parameter, object->ro.grffile);
+ if (param_type == INVALID_RAILTYPE) return 0x00;
+ RailType tile_type = GetTileRailType(v->tile);
+ if (tile_type == param_type) return 0x0F;
+ return (HasPowerOnRail(param_type, tile_type) ? 0x04 : 0x00) |
+ (IsCompatibleRail(param_type, tile_type) ? 0x02 : 0x00) |
+ 0x01;
+ }
+ case VEH_ROAD: {
+ RoadTramType rtt = GetRoadTramType(RoadVehicle::From(v)->roadtype);
+ RoadType param_type = GetRoadTypeTranslation(rtt, parameter, object->ro.grffile);
+ if (param_type == INVALID_ROADTYPE) return 0x00;
+ RoadType tile_type = GetRoadType(v->tile, rtt);
+ if (tile_type == param_type) return 0x0F;
+ return (HasPowerOnRoad(param_type, tile_type) ? 0x06 : 0x00) |
+ 0x01;
+ }
+ default: return 0x00;
+ }
+
case 0xFE:
case 0xFF: {
uint16 modflags = 0;