# HG changeset patch # User michi_cc # Date 2010-07-02 16:34:11 # Node ID 928b1cf244bbb3fcfb593d2f7e26f1060c3d5272 # Parent 81bd05aa8971a44d4c85b7d332a9ea3b27957fae (svn r20049) -Feature: [NewGRF] Add a railtype flag to disallow level crossings per railtype. diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp --- a/src/ai/api/ai_changelog.hpp +++ b/src/ai/api/ai_changelog.hpp @@ -22,6 +22,7 @@ * \li IsEnd for all lists. * \li AIIndustry::GetIndustryID * \li AIRail::GetMaxSpeed + * \li AIRail::ERR_RAILTYPE_DISALLOWS_CROSSING * * API removals: * \li HasNext for all lists. diff --git a/src/ai/api/ai_rail.hpp b/src/ai/api/ai_rail.hpp --- a/src/ai/api/ai_rail.hpp +++ b/src/ai/api/ai_rail.hpp @@ -38,6 +38,9 @@ public: /** Non-uniform stations is diabled */ ERR_NONUNIFORM_STATIONS_DISABLED, // [STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED] + + /** This railtype cannot have crossings */ + ERR_RAILTYPE_DISALLOWS_CROSSING, // [STR_ERROR_CROSSING_DISALLOWED] }; /** diff --git a/src/ai/api/ai_rail.hpp.sq b/src/ai/api/ai_rail.hpp.sq --- a/src/ai/api/ai_rail.hpp.sq +++ b/src/ai/api/ai_rail.hpp.sq @@ -42,6 +42,7 @@ void SQAIRail_Register(Squirrel *engine) SQAIRail.DefSQConst(engine, AIRail::ERR_CROSSING_ON_ONEWAY_ROAD, "ERR_CROSSING_ON_ONEWAY_ROAD"); SQAIRail.DefSQConst(engine, AIRail::ERR_UNSUITABLE_TRACK, "ERR_UNSUITABLE_TRACK"); SQAIRail.DefSQConst(engine, AIRail::ERR_NONUNIFORM_STATIONS_DISABLED, "ERR_NONUNIFORM_STATIONS_DISABLED"); + SQAIRail.DefSQConst(engine, AIRail::ERR_RAILTYPE_DISALLOWS_CROSSING, "ERR_RAILTYPE_DISALLOWS_CROSSING"); SQAIRail.DefSQConst(engine, AIRail::RAILTYPE_INVALID, "RAILTYPE_INVALID"); SQAIRail.DefSQConst(engine, AIRail::RAILTRACK_NE_SW, "RAILTRACK_NE_SW"); SQAIRail.DefSQConst(engine, AIRail::RAILTRACK_NW_SE, "RAILTRACK_NW_SE"); @@ -71,10 +72,12 @@ void SQAIRail_Register(Squirrel *engine) AIError::RegisterErrorMap(STR_ERROR_CROSSING_ON_ONEWAY_ROAD, AIRail::ERR_CROSSING_ON_ONEWAY_ROAD); AIError::RegisterErrorMap(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK, AIRail::ERR_UNSUITABLE_TRACK); AIError::RegisterErrorMap(STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED, AIRail::ERR_NONUNIFORM_STATIONS_DISABLED); + AIError::RegisterErrorMap(STR_ERROR_CROSSING_DISALLOWED, AIRail::ERR_RAILTYPE_DISALLOWS_CROSSING); AIError::RegisterErrorMapString(AIRail::ERR_CROSSING_ON_ONEWAY_ROAD, "ERR_CROSSING_ON_ONEWAY_ROAD"); AIError::RegisterErrorMapString(AIRail::ERR_UNSUITABLE_TRACK, "ERR_UNSUITABLE_TRACK"); AIError::RegisterErrorMapString(AIRail::ERR_NONUNIFORM_STATIONS_DISABLED, "ERR_NONUNIFORM_STATIONS_DISABLED"); + AIError::RegisterErrorMapString(AIRail::ERR_RAILTYPE_DISALLOWS_CROSSING, "ERR_RAILTYPE_DISALLOWS_CROSSING"); SQAIRail.DefSQStaticMethod(engine, &AIRail::IsRailTile, "IsRailTile", 2, ".i"); SQAIRail.DefSQStaticMethod(engine, &AIRail::IsLevelCrossingTile, "IsLevelCrossingTile", 2, ".i"); diff --git a/src/lang/english.txt b/src/lang/english.txt --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3543,6 +3543,7 @@ STR_ERROR_MUST_REMOVE_SIGNALS_FIRST STR_ERROR_NO_SUITABLE_RAILROAD_TRACK :{WHITE}No suitable railway track STR_ERROR_MUST_REMOVE_RAILROAD_TRACK :{WHITE}Must remove railway track first STR_ERROR_CROSSING_ON_ONEWAY_ROAD :{WHITE}Road is one way or blocked +STR_ERROR_CROSSING_DISALLOWED :{WHITE}Level crossings not allowed for this rail type STR_ERROR_CAN_T_BUILD_SIGNALS_HERE :{WHITE}Can't build signals here... STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK :{WHITE}Can't build railway track here... STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK :{WHITE}Can't remove railway track from here... diff --git a/src/rail.h b/src/rail.h --- a/src/rail.h +++ b/src/rail.h @@ -22,10 +22,12 @@ /** Railtype flags. */ enum RailTypeFlags { - RTF_CATENARY = 0, ///< Bit number for drawing a catenary. + RTF_CATENARY = 0, ///< Bit number for drawing a catenary. + RTF_NO_LEVEL_CROSSING = 1, ///< Bit number for disallowing level crossings. - RTFB_NONE = 0, ///< All flags cleared. - RTFB_CATENARY = 1 << RTF_CATENARY, ///< Value for drawing a catenary. + RTFB_NONE = 0, ///< All flags cleared. + RTFB_CATENARY = 1 << RTF_CATENARY, ///< Value for drawing a catenary. + RTFB_NO_LEVEL_CROSSING = 1 << RTF_NO_LEVEL_CROSSING, ///< Value for disallowing level crossings. }; DECLARE_ENUM_AS_BIT_SET(RailTypeFlags) @@ -259,6 +261,16 @@ static inline bool HasPowerOnRail(RailTy } /** + * Test if a RailType disallows build of level crossings. + * @param rt The RailType to check. + * @return Whether level crossings are not allowed. + */ +static inline bool RailNoLevelCrossings(RailType rt) +{ + return HasBit(GetRailTypeInfo(rt)->flags, RTF_NO_LEVEL_CROSSING); +} + +/** * Returns the cost of building the specified railtype. * @param railtype The railtype being built. * @return The cost multiplier. diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -423,6 +423,8 @@ CommandCost CmdBuildSingleRail(TileIndex if (GetDisallowedRoadDirections(tile) != DRD_NONE) return_cmd_error(STR_ERROR_CROSSING_ON_ONEWAY_ROAD); + if (RailNoLevelCrossings(railtype)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED); + RoadTypes roadtypes = GetRoadTypes(tile); RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD); RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM); diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -546,6 +546,10 @@ CommandCost CmdBuildRoad(TileIndex tile, if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear; + if (RailNoLevelCrossings(GetRailType(tile))) { + return_cmd_error(STR_ERROR_CROSSING_DISALLOWED); + } + Axis roaddir; switch (GetTrackBits(tile)) { case TRACK_BIT_X: