Add road/tram type flag to disallow tunnels

pull/491/head
Jonathan G Rennison 1 year ago
parent 3497d0dcdb
commit 663a3969a0

@ -175,6 +175,8 @@
<dd>Scripts (AI/GS) may not build this roadtype</dd>
<dt>NO_TOWN_MODIFY</dt>
<dd>Towns may not modify tiles of this roadtype in any way whatsoever</dd>
<dt>NO_TUNNELS</dt>
<dd>Disallow tunnels for this roadtype</dd>
</dl>
</td>
</tr>
@ -202,6 +204,8 @@
<dd>Scripts (AI/GS) may not build this tramtype</dd>
<dt>NO_TOWN_MODIFY</dt>
<dd>Towns may not modify tiles of this tramtype in any way whatsoever</dd>
<dt>NO_TUNNELS</dt>
<dd>Disallow tunnels for this tramtype</dd>
</dl>
</td>
</tr>

@ -327,6 +327,8 @@
<tr><th>Bit</th><th>Value</th><th>Meaning</th></tr>
<tr><td>0</td><td>1</td><td>Scripts (AI/GS) may not build this road/tram type</td></tr>
<tr><td>1</td><td>2</td><td>Towns may not modify tiles of this road/tram type in any way whatsoever</td></tr>
<tr><td>2</td><td>4</td><td>Disallow tunnels for this road/tram type<br />
Support for this bit is indicated by the feature name: <font face="monospace">action0_roadtype_extra_flags</font>, version 2.</td></tr>
</table>
</p>
<p>This is indicated by the feature name: <font face="monospace">action0_roadtype_extra_flags</font>, version 1</p>

@ -2026,3 +2026,5 @@ STR_SHIFT_KEY_NAME :{BLACK}Shift
STR_CTRL_KEY_NAME :{BLACK}Ctrl
STR_MODIFIER_TOGGLE_SHIFT_TOOLTIP :{BLACK}Click to invert state of Shift key
STR_MODIFIER_TOGGLE_CTRL_TOOLTIP :{BLACK}Click to invert state of Ctrl key
STR_ERROR_TUNNEL_DISALLOWED_ROAD :{WHITE}Tunnels not allowed for this road type

@ -38,7 +38,7 @@ extern const GRFFeatureInfo _grf_feature_list[] = {
GRFFeatureInfo("action0_railtype_disable_realistic_braking", 1),
GRFFeatureInfo("action0_railtype_recolour", 1),
GRFFeatureInfo("action0_railtype_extra_aspects", 1),
GRFFeatureInfo("action0_roadtype_extra_flags", 1),
GRFFeatureInfo("action0_roadtype_extra_flags", 2),
GRFFeatureInfo("action0_roadtype_collision_mode", 1),
GRFFeatureInfo("varaction2_railtype_signal_context", 1),
GRFFeatureInfo("action0_global_extra_station_names", 2),

@ -55,10 +55,9 @@ DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags)
enum RoadTypeExtraFlags {
RXTF_NOT_AVAILABLE_AI_GS = 0, ///< Bit number for unavailable for AI/GS
RXTF_NO_TOWN_MODIFICATION, ///< Bit number for no town modification
RXTF_NO_TUNNELS, ///< Bit number for no tunnels
RXTFB_NONE = 0, ///< All flags cleared.
RXTFB_NOT_AVAILABLE_AI_GS = 1 << RXTF_NOT_AVAILABLE_AI_GS, ///< Value for unavailable for AI/GS
RXTFB_NO_TOWN_MODIFICATION = 1 << RXTF_NO_TOWN_MODIFICATION, ///< Value for no town modification
};
DECLARE_ENUM_AS_BIT_SET(RoadTypeExtraFlags)
@ -325,6 +324,17 @@ static inline bool RoadNoLevelCrossing(RoadType roadtype)
return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_NO_LEVEL_CROSSING);
}
/**
* Test if road disallows tunnels
* @param roadtype The roadtype we are testing
* @return True iff the roadtype disallows tunnels
*/
static inline bool RoadNoTunnels(RoadType roadtype)
{
assert(roadtype < ROADTYPE_END);
return HasBit(GetRoadTypeInfo(roadtype)->extra_flags, RXTF_NO_TUNNELS);
}
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
void ResetRoadTypes();

@ -1330,6 +1330,8 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Only allow building the outer roadbit, so building long roads stops at existing bridges */
if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) goto do_clear;
if (HasTileRoadType(tile, rtt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if (RoadNoTunnels(rt)) return_cmd_error(STR_ERROR_TUNNEL_DISALLOWED_ROAD);
/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
CommandCost ret = TunnelBridgeIsFree(tile, other_end);
if (ret.Failed()) return ret;
@ -3054,6 +3056,10 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
break;
case MP_TUNNELBRIDGE:
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) continue;
if (IsTunnel(tile) && RoadNoTunnels(to_type)) {
error.MakeError(STR_ERROR_TUNNEL_DISALLOWED_ROAD);
continue;
}
break;
default: continue;
}

@ -443,6 +443,7 @@ struct BuildRoadToolbarWindow : Window {
}
this->GetWidget<NWidgetCore>(WID_ROT_CONVERT_ROAD)->widget_data = rti->gui_sprites.convert_road;
this->GetWidget<NWidgetCore>(WID_ROT_BUILD_TUNNEL)->widget_data = rti->gui_sprites.build_tunnel;
if (HasBit(rti->extra_flags, RXTF_NO_TUNNELS)) this->DisableWidget(WID_ROT_BUILD_TUNNEL);
}
/**

@ -1791,9 +1791,10 @@ class NIHRoadType : public NIHelper {
HasBit(rti->flags, ROTF_HIDDEN) ? 'h' : '-',
HasBit(rti->flags, ROTF_TOWN_BUILD) ? 'T' : '-');
output.print(buffer);
seprintf(buffer, lastof(buffer), " Extra Flags: %c%c",
seprintf(buffer, lastof(buffer), " Extra Flags: %c%c%c",
HasBit(rti->extra_flags, RXTF_NOT_AVAILABLE_AI_GS) ? 's' : '-',
HasBit(rti->extra_flags, RXTF_NO_TOWN_MODIFICATION) ? 't' : '-');
HasBit(rti->extra_flags, RXTF_NO_TOWN_MODIFICATION) ? 't' : '-',
HasBit(rti->extra_flags, RXTF_NO_TUNNELS) ? 'T' : '-');
output.print(buffer);
seprintf(buffer, lastof(buffer), " Collision mode: %u", rti->collision_mode);
output.print(buffer);

@ -966,6 +966,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
case TRANSPORT_ROAD:
roadtype = Extract<RoadType, 0, 6>(p1);
if (!ValParamRoadType(roadtype)) return CMD_ERROR;
if (RoadNoTunnels(roadtype)) return_cmd_error(STR_ERROR_TUNNEL_DISALLOWED_ROAD);
break;
default: return CMD_ERROR;

Loading…
Cancel
Save