summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-11-14 16:39:17 +0100
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commit6fe445e6c0fa3163aba48b1ec6d810b6594777bd (patch)
tree320cd8d2d76b38ee06f9fde07ea349adeb3f228a /src/script/api
parent21675ec7e22bfe53f20300cc27b4d50c84aeb4dc (diff)
downloadopenttd-6fe445e6c0fa3163aba48b1ec6d810b6594777bd.tar.xz
Codechange: Un-bitstuff station/depot/waypoint commands.
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_airport.cpp4
-rw-r--r--src/script/api/script_basestation.cpp4
-rw-r--r--src/script/api/script_marine.cpp8
-rw-r--r--src/script/api/script_rail.cpp29
-rw-r--r--src/script/api/script_road.cpp24
-rw-r--r--src/script/api/script_station.cpp2
6 files changed, 27 insertions, 44 deletions
diff --git a/src/script/api/script_airport.cpp b/src/script/api/script_airport.cpp
index 5927b1662..8ed4dbfca 100644
--- a/src/script/api/script_airport.cpp
+++ b/src/script/api/script_airport.cpp
@@ -77,9 +77,7 @@
EnforcePrecondition(false, IsValidAirportType(type));
EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
- uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1;
- p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
- return ScriptObject::Command<CMD_BUILD_AIRPORT>::Do(tile, type, p2, {});
+ return ScriptObject::Command<CMD_BUILD_AIRPORT>::Do(tile, type, 0, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION), station_id == ScriptStation::STATION_JOIN_ADJACENT);
}
/* static */ bool ScriptAirport::RemoveAirport(TileIndex tile)
diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp
index a24934410..788d54950 100644
--- a/src/script/api/script_basestation.cpp
+++ b/src/script/api/script_basestation.cpp
@@ -45,9 +45,9 @@
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
if (::Station::IsValidID(station_id)) {
- return ScriptObject::Command<CMD_RENAME_STATION>::Do(0, station_id, 0, text);
+ return ScriptObject::Command<CMD_RENAME_STATION>::Do(station_id, text);
} else {
- return ScriptObject::Command<CMD_RENAME_WAYPOINT>::Do(0, station_id, 0, text);
+ return ScriptObject::Command<CMD_RENAME_WAYPOINT>::Do(station_id, text);
}
}
diff --git a/src/script/api/script_marine.cpp b/src/script/api/script_marine.cpp
index f368ec918..809323394 100644
--- a/src/script/api/script_marine.cpp
+++ b/src/script/api/script_marine.cpp
@@ -83,7 +83,7 @@
EnforcePrecondition(false, ::IsValidTile(front));
EnforcePrecondition(false, (::TileX(front) == ::TileX(tile)) != (::TileY(front) == ::TileY(tile)));
- return ScriptObject::Command<CMD_BUILD_SHIP_DEPOT>::Do(tile, ::TileX(front) == ::TileX(tile), 0, {});
+ return ScriptObject::Command<CMD_BUILD_SHIP_DEPOT>::Do(tile, ::TileX(front) == ::TileX(tile) ? AXIS_Y : AXIS_X);
}
/* static */ bool ScriptMarine::BuildDock(TileIndex tile, StationID station_id)
@@ -92,9 +92,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
- uint p1 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1;
- uint p2 = (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
- return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, p1, p2, {});
+ return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, station_id != ScriptStation::STATION_JOIN_ADJACENT);
}
/* static */ bool ScriptMarine::BuildBuoy(TileIndex tile)
@@ -102,7 +100,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
- return ScriptObject::Command<CMD_BUILD_BUOY>::Do(tile, 0, 0, {});
+ return ScriptObject::Command<CMD_BUILD_BUOY>::Do(tile);
}
/* static */ bool ScriptMarine::BuildLock(TileIndex tile)
diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp
index ebba16343..30a1085d4 100644
--- a/src/script/api/script_rail.cpp
+++ b/src/script/api/script_rail.cpp
@@ -142,9 +142,9 @@
EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front));
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
- uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
+ DiagDirection entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? DIAGDIR_SE : DIAGDIR_NW) : (::TileX(tile) < ::TileX(front) ? DIAGDIR_SW : DIAGDIR_NE);
- return ScriptObject::Command<CMD_BUILD_TRAIN_DEPOT>::Do(tile, ScriptObject::GetRailType(), entrance_dir, {});
+ return ScriptObject::Command<CMD_BUILD_TRAIN_DEPOT>::Do(tile, (::RailType)ScriptObject::GetRailType(), entrance_dir);
}
/* static */ bool ScriptRail::BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id)
@@ -157,10 +157,8 @@
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
- uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8);
- if (direction == RAILTRACK_NW_SE) p1 |= (1 << 6);
- if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24);
- return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, {});
+ bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT;
+ return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X, num_platforms, platform_length, STAT_CLASS_DFLT, 0, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, adjacent);
}
/* static */ bool ScriptRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station)
@@ -176,10 +174,6 @@
EnforcePrecondition(false, source_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(source_industry));
EnforcePrecondition(false, goal_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(goal_industry));
- uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8);
- if (direction == RAILTRACK_NW_SE) p1 |= 1 << 6;
- if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24);
-
const GRFFile *file;
uint16 res = GetAiPurchaseCallbackResult(
GSF_STATIONS,
@@ -193,7 +187,10 @@
std::min(15u, num_platforms) << 4 | std::min(15u, platform_length),
&file
);
- uint32 p2 = (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
+
+ Axis axis = direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X;
+ bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT;
+ StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION;
if (res != CALLBACK_FAILED) {
int index = 0;
const StationSpec *spec = StationClass::GetByGrf(file->grfid, res, &index);
@@ -201,11 +198,11 @@
Debug(grf, 1, "{} returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename);
} else {
/* We might have gotten an usable station spec. Try to build it, but if it fails we'll fall back to the original station. */
- if (ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, p2 | spec->cls_id | index << 8, {})) return true;
+ if (ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), axis, num_platforms, platform_length, spec->cls_id, index, to_join, adjacent)) return true;
}
}
- return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, p2, {});
+ return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), axis, num_platforms, platform_length, STAT_CLASS_DFLT, 0, to_join, adjacent);
}
/* static */ bool ScriptRail::BuildRailWaypoint(TileIndex tile)
@@ -216,7 +213,7 @@
EnforcePrecondition(false, GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE);
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
- return ScriptObject::Command<CMD_BUILD_RAIL_WAYPOINT>::Do(tile, GetCurrentRailType() | (GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y) << 6 | 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, {});
+ return ScriptObject::Command<CMD_BUILD_RAIL_WAYPOINT>::Do(tile, GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y, 1, 1, STAT_CLASS_WAYP, 0, INVALID_STATION, false);
}
/* static */ bool ScriptRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)
@@ -225,7 +222,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, ::IsValidTile(tile2));
- return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(tile, tile2, keep_rail ? 1 : 0, {});
+ return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(tile, tile2, keep_rail);
}
/* static */ bool ScriptRail::RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)
@@ -234,7 +231,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, ::IsValidTile(tile2));
- return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(tile, tile2, keep_rail ? 1 : 0, {});
+ return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(tile, tile2, keep_rail);
}
/* static */ uint ScriptRail::GetRailTracks(TileIndex tile)
diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp
index 26cdb5190..c629396b7 100644
--- a/src/script/api/script_road.cpp
+++ b/src/script/api/script_road.cpp
@@ -529,9 +529,9 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front));
EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
- uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
+ DiagDirection entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? DIAGDIR_SE : DIAGDIR_NW) : (::TileX(tile) < ::TileX(front) ? DIAGDIR_SW : DIAGDIR_NE);
- return ScriptObject::Command<CMD_BUILD_ROAD_DEPOT>::Do(tile, entrance_dir | (ScriptObject::GetRoadType() << 2), 0, {});
+ return ScriptObject::Command<CMD_BUILD_ROAD_DEPOT>::Do(tile, ScriptObject::GetRoadType(), entrance_dir);
}
/* static */ bool ScriptRoad::_BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id)
@@ -545,20 +545,10 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, road_veh_type == ROADVEHTYPE_BUS || road_veh_type == ROADVEHTYPE_TRUCK);
EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
- uint entrance_dir;
- if (drive_through) {
- entrance_dir = ::TileY(tile) != ::TileY(front);
- } else {
- entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
- }
-
- uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 4;
- p2 |= drive_through ? 2 : 0;
- p2 |= road_veh_type == ROADVEHTYPE_TRUCK ? 1 : 0;
- p2 |= ScriptObject::GetRoadType() << 5;
- p2 |= entrance_dir << 3;
- p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
- return ScriptObject::Command<CMD_BUILD_ROAD_STOP>::Do(tile, 1 | 1 << 8, p2, {});
+ DiagDirection entrance_dir = DiagdirBetweenTiles(tile, front);
+ RoadStopType stop_type = road_veh_type == ROADVEHTYPE_TRUCK ? ROADSTOP_TRUCK : ROADSTOP_BUS;
+ StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION;
+ return ScriptObject::Command<CMD_BUILD_ROAD_STOP>::Do(tile, 1, 1, stop_type, drive_through, entrance_dir, ScriptObject::GetRoadType(), to_join, station_id != ScriptStation::STATION_JOIN_ADJACENT);
}
/* static */ bool ScriptRoad::BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id)
@@ -612,7 +602,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, IsTileType(tile, MP_STATION));
EnforcePrecondition(false, IsRoadStop(tile));
- return ScriptObject::Command<CMD_REMOVE_ROAD_STOP>::Do(tile, 1 | 1 << 8, GetRoadStopType(tile), {});
+ return ScriptObject::Command<CMD_REMOVE_ROAD_STOP>::Do(tile, 1, 1, GetRoadStopType(tile), false);
}
/* static */ Money ScriptRoad::GetBuildCost(RoadType roadtype, BuildType build_type)
diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp
index 34e7d8434..3b38844df 100644
--- a/src/script/api/script_station.cpp
+++ b/src/script/api/script_station.cpp
@@ -240,5 +240,5 @@ template<bool Tfrom, bool Tvia>
EnforcePrecondition(false, IsValidStation(station_id));
EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT));
- return ScriptObject::Command<CMD_OPEN_CLOSE_AIRPORT>::Do(0, station_id, 0, {});
+ return ScriptObject::Command<CMD_OPEN_CLOSE_AIRPORT>::Do(station_id);
}