diff options
Diffstat (limited to 'src/ai/api')
-rw-r--r-- | src/ai/api/ai_road.cpp | 6 | ||||
-rw-r--r-- | src/ai/api/ai_road.hpp | 8 | ||||
-rw-r--r-- | src/ai/api/ai_road.hpp.sq | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/src/ai/api/ai_road.cpp b/src/ai/api/ai_road.cpp index 4cced8873..4cbce4a68 100644 --- a/src/ai/api/ai_road.cpp +++ b/src/ai/api/ai_road.cpp @@ -5,12 +5,18 @@ #include "ai_road.hpp" #include "ai_map.hpp" #include "ai_station.hpp" +#include "ai_cargo.hpp" #include "../../station_map.h" #include "../../command_type.h" #include "../../settings_type.h" #include "../../company_func.h" #include "../../script/squirrel_helper_type.hpp" +/* static */ AIRoad::RoadVehicleType AIRoad::GetRoadVehicleTypeForCargo(CargoID cargo_type) +{ + return AICargo::HasCargoClass(cargo_type, AICargo::CC_PASSENGERS) ? ROADVEHTYPE_BUS : ROADVEHTYPE_TRUCK; +} + /* static */ bool AIRoad::IsRoadTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; diff --git a/src/ai/api/ai_road.hpp b/src/ai/api/ai_road.hpp index e899af771..7bd26922d 100644 --- a/src/ai/api/ai_road.hpp +++ b/src/ai/api/ai_road.hpp @@ -57,6 +57,14 @@ public: }; /** + * Determines whether a busstop or a truckstop is needed to transport a certain cargo. + * @param cargo_type The cargo to test. + * @pre AICargo::IsValidCargo(cargo_type). + * @return The road vehicle type needed to transport the cargo. + */ + static RoadVehicleType GetRoadVehicleTypeForCargo(CargoID cargo_type); + + /** * 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. diff --git a/src/ai/api/ai_road.hpp.sq b/src/ai/api/ai_road.hpp.sq index b495dbba7..4c89d93a4 100644 --- a/src/ai/api/ai_road.hpp.sq +++ b/src/ai/api/ai_road.hpp.sq @@ -46,6 +46,7 @@ void SQAIRoad_Register(Squirrel *engine) { AIError::RegisterErrorMapString(AIRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD, "ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD"); AIError::RegisterErrorMapString(AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS, "ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS"); + SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetRoadVehicleTypeForCargo, "GetRoadVehicleTypeForCargo", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadTile, "IsRoadTile", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadDepotTile, "IsRoadDepotTile", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadStationTile, "IsRoadStationTile", 2, ".i"); |