diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut index b379c9af45..78938b8b12 100644 --- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -1016,10 +1016,10 @@ function Regression::Road() print(" Station"); print(" IsRoadTile(): " + AIRoad.IsRoadTile(33411)); - print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(0, 1, false, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(33411, 33411, false, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(33411, 33414, false, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(33411, 33412, false, false, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(0, 1, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(33411, 33411, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(33411, 33414, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(): " + AIRoad.BuildRoadStation(33411, 33412, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); print(" IsStationTile(): " + AITile.IsStationTile(33411)); print(" IsStationTile(): " + AITile.IsStationTile(33412)); print(" HasRoadType(Road): " + AIRoad.HasRoadType(33411, AIRoad.ROADTYPE_ROAD)); @@ -1033,15 +1033,15 @@ function Regression::Road() print(" RemoveRoadStation(): " + AIRoad.RemoveRoadStation(33411)); print(" Station Types"); - print(" BuildRoadStation(bus): " + AIRoad.BuildRoadStation(33411, 33410, false, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(truck): " + AIRoad.BuildRoadStation(33421, 33422, true, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(truck): " + AIRoad.BuildRoadStation(33412, 33413, true, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(bus): " + AIRoad.BuildRoadStation(33411 + 256, 33411, false, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(truck): " + AIRoad.BuildRoadStation(33412 + 256, 33412 + 256 + 256, true, false, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(bus-drive): " + AIRoad.BuildRoadStation(33413, 33412, false, true, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(truck-drive): " + AIRoad.BuildRoadStation(33414, 33413, true, true, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(bus-drive): " + AIRoad.BuildRoadStation(33415, 33414, false, true, AIStation.STATION_JOIN_ADJACENT)); - print(" BuildRoadStation(truck-drive): " + AIRoad.BuildRoadStation(33416, 33415, true, true, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(bus): " + AIRoad.BuildRoadStation(33411, 33410, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(truck): " + AIRoad.BuildRoadStation(33421, 33422, AIRoad.ROADVEHTYPE_TRUCK, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(truck): " + AIRoad.BuildRoadStation(33412, 33413, AIRoad.ROADVEHTYPE_TRUCK, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(bus): " + AIRoad.BuildRoadStation(33411 + 256, 33411, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildRoadStation(truck): " + AIRoad.BuildRoadStation(33412 + 256, 33412 + 256 + 256, AIRoad.ROADVEHTYPE_TRUCK, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildDriveThroughRoadStation(bus-drive): " + AIRoad.BuildDriveThroughRoadStation(33413, 33412, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildDriveThroughRoadStation(truck-drive): " + AIRoad.BuildDriveThroughRoadStation(33414, 33413, AIRoad.ROADVEHTYPE_TRUCK, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildDriveThroughRoadStation(bus-drive): " + AIRoad.BuildDriveThroughRoadStation(33415, 33414, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_JOIN_ADJACENT)); + print(" BuildDriveThroughRoadStation(truck-drive): " + AIRoad.BuildDriveThroughRoadStation(33416, 33415, AIRoad.ROADVEHTYPE_TRUCK, AIStation.STATION_JOIN_ADJACENT)); print(" BuildRoadDepot(): " + AIRoad.BuildRoadDepot(33417, 33418)); print(" GetRoadStationFrontTile(): " + AIRoad.GetRoadStationFrontTile(33411 + 256)); print(" GetRoadStationFrontTile(): " + AIRoad.GetRoadStationFrontTile(33412 + 256)); diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index 33b99129e4..d2557aeb69 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -6403,10 +6403,10 @@ BuildRoadStation(truck): true BuildRoadStation(bus): true BuildRoadStation(truck): true - BuildRoadStation(bus-drive): true - BuildRoadStation(truck-drive): true - BuildRoadStation(bus-drive): true - BuildRoadStation(truck-drive): true + BuildDriveThroughRoadStation(bus-drive): true + BuildDriveThroughRoadStation(truck-drive): true + BuildDriveThroughRoadStation(bus-drive): true + BuildDriveThroughRoadStation(truck-drive): true BuildRoadDepot(): true GetRoadStationFrontTile(): 33411 GetRoadStationFrontTile(): 33924 diff --git a/src/ai/api/ai_road.cpp b/src/ai/api/ai_road.cpp index c9e0f48880..8285ee617f 100644 --- a/src/ai/api/ai_road.cpp +++ b/src/ai/api/ai_road.cpp @@ -491,13 +491,14 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia return AIObject::DoCommand(tile, entrance_dir | (AIObject::GetRoadType() << 2), 0, CMD_BUILD_ROAD_DEPOT); } -/* static */ bool AIRoad::BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through, StationID station_id) +/* static */ bool AIRoad::_BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id) { EnforcePrecondition(false, tile != front); EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsValidTile(front)); EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front)); EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); + EnforcePrecondition(false, road_veh_type == ROADVEHTYPE_BUS || road_veh_type == ROADVEHTYPE_TRUCK); uint entrance_dir; if (drive_through) { @@ -508,12 +509,22 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia uint p2 = station_id == AIStation::STATION_JOIN_ADJACENT ? 0 : 32; p2 |= drive_through ? 2 : 0; - p2 |= truck ? 1 : 0; + p2 |= road_veh_type == ROADVEHTYPE_TRUCK ? 1 : 0; p2 |= ::RoadTypeToRoadTypes(AIObject::GetRoadType()) << 2; p2 |= (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; return AIObject::DoCommand(tile, entrance_dir, p2, CMD_BUILD_ROAD_STOP); } +/* static */ bool AIRoad::BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id) +{ + return _BuildRoadStationInternal(tile, front, road_veh_type, false, station_id); +} + +/* static */ bool AIRoad::BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id) +{ + return _BuildRoadStationInternal(tile, front, road_veh_type, true, station_id); +} + /* static */ bool AIRoad::RemoveRoad(TileIndex start, TileIndex end) { EnforcePrecondition(false, ::IsValidTile(start)); diff --git a/src/ai/api/ai_road.hpp b/src/ai/api/ai_road.hpp index 4b828dde80..1e3c84bdef 100644 --- a/src/ai/api/ai_road.hpp +++ b/src/ai/api/ai_road.hpp @@ -48,6 +48,14 @@ public: ROADTYPE_INVALID = -1, //!< Invalid RoadType. }; + /** + * Type of road station + */ + enum RoadVehicleType { + ROADVEHTYPE_BUS, //!< Build objects useable for busses and passenger trams + ROADVEHTYPE_TRUCK, //!< Build objects useable for trucks and cargo trams + }; + /** * Checks whether the given tile is actually a tile with road that can be * used to traverse a tile. This excludes road depots and 'normal' road @@ -322,9 +330,30 @@ public: * Builds a road bus or truck station. * @param tile Place to build the station. * @param front The tile exactly in front of the station. - * For drive-through stations either entrance side can be used. - * @param truck Whether to build a truck (true) or bus (false) station. - * @param drive_through Whether to make the station drive through or not. + * @param road_veh_type Whether to build a truck or bus station. + * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. + * @pre AIMap::IsValidTile(tile). + * @pre AIMap::IsValidTile(front). + * @pre 'tile' is not equal to 'front', but in a straight line of it. + * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). + * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception AIError::ERR_AREA_NOT_CLEAR + * @exception AIError::ERR_FLAT_LAND_REQUIRED + * @exception AIRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION + * @exception AIRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD + * @exception AIError:ERR_VEHICLE_IN_THE_WAY + * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION + * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS + * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN + * @return Whether the station has been/can be build or not. + */ + static bool BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id); + + /** + * Builds a drive-through road bus or truck station. + * @param tile Place to build the depot. + * @param front A tile on the same axis with 'tile' as the station shall be oriented. + * @param road_veh_type Whether to build a truck or bus station. * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. * @pre AIMap::IsValidTile(tile). * @pre AIMap::IsValidTile(front). @@ -341,7 +370,7 @@ public: * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN * @return Whether the station has been/can be build or not. */ - static bool BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through, StationID station_id); + static bool BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id); /** * Removes a road from the center of tile start to the center of tile end. @@ -404,6 +433,11 @@ private: * Internal function used by Build(OneWay)Road(Full). */ static bool _BuildRoadInternal(TileIndex start, TileIndex end, bool one_way, bool full); + + /** + * Internal function used by Build(DriveThrough)RoadStation. + */ + static bool _BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id); }; #endif /* AI_ROAD_HPP */ diff --git a/src/ai/api/ai_road.hpp.sq b/src/ai/api/ai_road.hpp.sq index 101d0bcd69..4aaf12846c 100644 --- a/src/ai/api/ai_road.hpp.sq +++ b/src/ai/api/ai_road.hpp.sq @@ -9,6 +9,8 @@ namespace SQConvert { template <> int Return(HSQUIRRELVM vm, AIRoad::ErrorMessages res) { sq_pushinteger(vm, (int32)res); return 1; } template <> AIRoad::RoadType GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIRoad::RoadType)tmp; } template <> int Return(HSQUIRRELVM vm, AIRoad::RoadType res) { sq_pushinteger(vm, (int32)res); return 1; } + template <> AIRoad::RoadVehicleType GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIRoad::RoadVehicleType)tmp; } + template <> int Return(HSQUIRRELVM vm, AIRoad::RoadVehicleType res) { sq_pushinteger(vm, (int32)res); return 1; } /* Allow AIRoad to be used as Squirrel parameter */ template <> AIRoad *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIRoad *)instance; } @@ -31,6 +33,8 @@ void SQAIRoad_Register(Squirrel *engine) { SQAIRoad.DefSQConst(engine, AIRoad::ROADTYPE_ROAD, "ROADTYPE_ROAD"); SQAIRoad.DefSQConst(engine, AIRoad::ROADTYPE_TRAM, "ROADTYPE_TRAM"); SQAIRoad.DefSQConst(engine, AIRoad::ROADTYPE_INVALID, "ROADTYPE_INVALID"); + SQAIRoad.DefSQConst(engine, AIRoad::ROADVEHTYPE_BUS, "ROADVEHTYPE_BUS"); + SQAIRoad.DefSQConst(engine, AIRoad::ROADVEHTYPE_TRUCK, "ROADVEHTYPE_TRUCK"); AIError::RegisterErrorMap(STR_ROAD_WORKS_IN_PROGRESS, AIRoad::ERR_ROAD_WORKS_IN_PROGRESS); AIError::RegisterErrorMap(STR_DRIVE_THROUGH_ERROR_DIRECTION, AIRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION); @@ -62,7 +66,8 @@ void SQAIRoad_Register(Squirrel *engine) { SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoadFull, "BuildRoadFull", 3, "?ii"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildOneWayRoadFull, "BuildOneWayRoadFull", 3, "?ii"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoadDepot, "BuildRoadDepot", 3, "?ii"); - SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoadStation, "BuildRoadStation", 6, "?iibbi"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildRoadStation, "BuildRoadStation", 5, "?iiii"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::BuildDriveThroughRoadStation, "BuildDriveThroughRoadStation", 5, "?iiii"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::RemoveRoad, "RemoveRoad", 3, "?ii"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::RemoveRoadFull, "RemoveRoadFull", 3, "?ii"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::RemoveRoadDepot, "RemoveRoadDepot", 2, "?i");