From 6fe445e6c0fa3163aba48b1ec6d810b6594777bd Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sun, 14 Nov 2021 16:39:17 +0100 Subject: Codechange: Un-bitstuff station/depot/waypoint commands. --- src/script/api/script_airport.cpp | 4 +--- src/script/api/script_basestation.cpp | 4 ++-- src/script/api/script_marine.cpp | 8 +++----- src/script/api/script_rail.cpp | 29 +++++++++++++---------------- src/script/api/script_road.cpp | 24 +++++++----------------- src/script/api/script_station.cpp | 2 +- 6 files changed, 27 insertions(+), 44 deletions(-) (limited to 'src/script/api') 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::Do(tile, type, p2, {}); + return ScriptObject::Command::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::Do(0, station_id, 0, text); + return ScriptObject::Command::Do(station_id, text); } else { - return ScriptObject::Command::Do(0, station_id, 0, text); + return ScriptObject::Command::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::Do(tile, ::TileX(front) == ::TileX(tile), 0, {}); + return ScriptObject::Command::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::Do(tile, p1, p2, {}); + return ScriptObject::Command::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::Do(tile, 0, 0, {}); + return ScriptObject::Command::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::Do(tile, ScriptObject::GetRailType(), entrance_dir, {}); + return ScriptObject::Command::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::Do(tile, p1, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, {}); + bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT; + return ScriptObject::Command::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::Do(tile, p1, p2 | spec->cls_id | index << 8, {})) return true; + if (ScriptObject::Command::Do(tile, (::RailType)GetCurrentRailType(), axis, num_platforms, platform_length, spec->cls_id, index, to_join, adjacent)) return true; } } - return ScriptObject::Command::Do(tile, p1, p2, {}); + return ScriptObject::Command::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::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::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::Do(tile, tile2, keep_rail ? 1 : 0, {}); + return ScriptObject::Command::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::Do(tile, tile2, keep_rail ? 1 : 0, {}); + return ScriptObject::Command::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::Do(tile, entrance_dir | (ScriptObject::GetRoadType() << 2), 0, {}); + return ScriptObject::Command::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::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::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::Do(tile, 1 | 1 << 8, GetRoadStopType(tile), {}); + return ScriptObject::Command::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 EnforcePrecondition(false, IsValidStation(station_id)); EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT)); - return ScriptObject::Command::Do(0, station_id, 0, {}); + return ScriptObject::Command::Do(station_id); } -- cgit v1.2.3-70-g09d2