diff options
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/api/ai_road.cpp | 15 | ||||
-rw-r--r-- | src/ai/api/ai_road.hpp | 42 | ||||
-rw-r--r-- | src/ai/api/ai_road.hpp.sq | 7 |
3 files changed, 57 insertions, 7 deletions
diff --git a/src/ai/api/ai_road.cpp b/src/ai/api/ai_road.cpp index c9e0f4888..8285ee617 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 4b828dde8..1e3c84bde 100644 --- a/src/ai/api/ai_road.hpp +++ b/src/ai/api/ai_road.hpp @@ -49,6 +49,14 @@ public: }; /** + * 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 * stations, but includes drive through stations. @@ -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 101d0bcd6..4aaf12846 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<AIRoad::ErrorMessages>(HSQUIRRELVM vm, AIRoad::ErrorMessages res) { sq_pushinteger(vm, (int32)res); return 1; } template <> AIRoad::RoadType GetParam(ForceType<AIRoad::RoadType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIRoad::RoadType)tmp; } template <> int Return<AIRoad::RoadType>(HSQUIRRELVM vm, AIRoad::RoadType res) { sq_pushinteger(vm, (int32)res); return 1; } + template <> AIRoad::RoadVehicleType GetParam(ForceType<AIRoad::RoadVehicleType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIRoad::RoadVehicleType)tmp; } + template <> int Return<AIRoad::RoadVehicleType>(HSQUIRRELVM vm, AIRoad::RoadVehicleType res) { sq_pushinteger(vm, (int32)res); return 1; } /* Allow AIRoad to be used as Squirrel parameter */ template <> AIRoad *GetParam(ForceType<AIRoad *>, 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"); |