mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for RoadTypes.
parent
819e097d6e
commit
732109e444
|
@ -80,7 +80,7 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
|
|||
|
||||
case VEH_ROAD:
|
||||
/* make sure the roadtypes are compatible */
|
||||
if ((GetRoadTypeInfo(e_from->u.road.roadtype)->powered_roadtypes & GetRoadTypeInfo(e_to->u.road.roadtype)->powered_roadtypes) == ROADTYPES_NONE) return false;
|
||||
if (!GetRoadTypeInfo(e_from->u.road.roadtype)->powered_roadtypes.Any(GetRoadTypeInfo(e_to->u.road.roadtype)->powered_roadtypes)) return false;
|
||||
|
||||
/* make sure that we do not replace a tram with a normal road vehicles or vice versa */
|
||||
if (e_from->info.misc_flags.Test(EngineMiscFlag::RoadIsTram) != e_to->info.misc_flags.Test(EngineMiscFlag::RoadIsTram)) return false;
|
||||
|
|
|
@ -1781,7 +1781,7 @@ struct CompanyInfrastructureWindow : Window
|
|||
void UpdateRailRoadTypes()
|
||||
{
|
||||
this->railtypes = RAILTYPES_NONE;
|
||||
this->roadtypes = ROADTYPES_NONE;
|
||||
this->roadtypes = {};
|
||||
|
||||
/* Find the used railtypes. */
|
||||
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
|
||||
|
@ -1798,12 +1798,12 @@ struct CompanyInfrastructureWindow : Window
|
|||
for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
|
||||
if (!e->info.climates.Test(_settings_game.game_creation.landscape)) continue;
|
||||
|
||||
this->roadtypes |= GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes;
|
||||
this->roadtypes.Set(GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes);
|
||||
}
|
||||
|
||||
/* Get the date introduced roadtypes as well. */
|
||||
this->roadtypes = AddDateIntroducedRoadTypes(this->roadtypes, CalendarTime::MAX_DATE);
|
||||
this->roadtypes &= ~_roadtypes_hidden_mask;
|
||||
this->roadtypes.Reset(_roadtypes_hidden_mask);
|
||||
}
|
||||
|
||||
/** Get total infrastructure maintenance cost. */
|
||||
|
@ -1821,7 +1821,7 @@ struct CompanyInfrastructureWindow : Window
|
|||
uint32_t road_total = c->infrastructure.GetRoadTotal();
|
||||
uint32_t tram_total = c->infrastructure.GetTramTotal();
|
||||
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
|
||||
if (HasBit(this->roadtypes, rt)) total += RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total);
|
||||
if (this->roadtypes.Test(rt)) total += RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total);
|
||||
}
|
||||
|
||||
total += CanalMaintenanceCost(c->infrastructure.water);
|
||||
|
@ -1874,7 +1874,7 @@ struct CompanyInfrastructureWindow : Window
|
|||
size.width = std::max(size.width, GetStringBoundingBox(widget == WID_CI_ROAD_DESC ? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT : STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT).width + padding.width);
|
||||
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
|
||||
if (this->roadtypes.Test(rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
|
||||
lines++;
|
||||
size.width = std::max(size.width, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.name).width + padding.width + WidgetDimensions::scaled.hsep_indent);
|
||||
}
|
||||
|
@ -2013,7 +2013,7 @@ struct CompanyInfrastructureWindow : Window
|
|||
|
||||
/* Draw name of each valid roadtype. */
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
|
||||
if (this->roadtypes.Test(rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
|
||||
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), GetRoadTypeInfo(rt)->strings.name, TC_WHITE);
|
||||
}
|
||||
}
|
||||
|
@ -2025,7 +2025,7 @@ struct CompanyInfrastructureWindow : Window
|
|||
case WID_CI_TRAM_COUNT: {
|
||||
uint32_t road_tram_total = widget == WID_CI_ROAD_COUNT ? c->infrastructure.GetRoadTotal() : c->infrastructure.GetTramTotal();
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_COUNT)) {
|
||||
if (this->roadtypes.Test(rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_COUNT)) {
|
||||
this->DrawCountLine(r, y, c->infrastructure.road[rt], RoadMaintenanceCost(rt, c->infrastructure.road[rt], road_tram_total));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1281,7 +1281,7 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
|
|||
if (type == VEH_ROAD && company != OWNER_DEITY) {
|
||||
/* Check if the road type is available to this company */
|
||||
const Company *c = Company::Get(company);
|
||||
if ((GetRoadTypeInfo(e->u.road.roadtype)->powered_roadtypes & c->avail_roadtypes) == ROADTYPES_NONE) return false;
|
||||
if (!GetRoadTypeInfo(e->u.road.roadtype)->powered_roadtypes.Any(c->avail_roadtypes)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -83,13 +83,13 @@ static ChangeInfoResult RoadTypeChangeInfo(uint first, uint last, int prop, Byte
|
|||
switch (prop) {
|
||||
case 0x0F:
|
||||
if (GetRoadTramType(resolved_rt) == rtt) {
|
||||
SetBit(rti->powered_roadtypes, resolved_rt);
|
||||
rti->powered_roadtypes.Set(resolved_rt);
|
||||
} else {
|
||||
GrfMsg(1, "RoadTypeChangeInfo: Powered road type list: Road type {} road/tram type does not match road type {}, ignoring", resolved_rt, rt);
|
||||
}
|
||||
break;
|
||||
case 0x18: SetBit(rti->introduction_required_roadtypes, resolved_rt); break;
|
||||
case 0x19: SetBit(rti->introduces_roadtypes, resolved_rt); break;
|
||||
case 0x18: rti->introduction_required_roadtypes.Set(resolved_rt); break;
|
||||
case 0x19: rti->introduces_roadtypes.Set(resolved_rt); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ protected:
|
|||
if (IsRoadTT()) {
|
||||
const RoadVehicle *v = RoadVehicle::From(this->veh);
|
||||
RoadType roadtype = GetRoadType(this->new_tile, GetRoadTramType(v->roadtype));
|
||||
if (!HasBit(v->compatible_roadtypes, roadtype)) {
|
||||
if (!v->compatible_roadtypes.Test(roadtype)) {
|
||||
/* incompatible road type */
|
||||
this->err = EC_RAIL_ROAD_TYPE;
|
||||
return false;
|
||||
|
|
22
src/road.cpp
22
src/road.cpp
|
@ -126,7 +126,9 @@ bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype)
|
|||
} else {
|
||||
const Company *c = Company::GetIfValid(company);
|
||||
if (c == nullptr) return false;
|
||||
return HasBit(c->avail_roadtypes & ~_roadtypes_hidden_mask, roadtype);
|
||||
RoadTypes avail = c->avail_roadtypes;
|
||||
avail.Reset(_roadtypes_hidden_mask);
|
||||
return avail.Test(roadtype);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +139,9 @@ bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype)
|
|||
*/
|
||||
bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt)
|
||||
{
|
||||
return (Company::Get(company)->avail_roadtypes & ~_roadtypes_hidden_mask & GetMaskForRoadTramType(rtt)) != ROADTYPES_NONE;
|
||||
RoadTypes avail = Company::Get(company)->avail_roadtypes;
|
||||
avail.Reset(_roadtypes_hidden_mask);
|
||||
return avail.Any(GetMaskForRoadTramType(rtt));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +181,7 @@ RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date
|
|||
RoadTypes required = rti->introduction_required_roadtypes;
|
||||
if ((rts & required) != required) continue;
|
||||
|
||||
rts |= rti->introduces_roadtypes;
|
||||
rts.Set(rti->introduces_roadtypes);
|
||||
}
|
||||
|
||||
/* When we added roadtypes we need to run this method again; the added
|
||||
|
@ -193,7 +197,7 @@ RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date
|
|||
*/
|
||||
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
|
||||
{
|
||||
RoadTypes rts = ROADTYPES_NONE;
|
||||
RoadTypes rts{};
|
||||
|
||||
for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
|
||||
const EngineInfo *ei = &e->info;
|
||||
|
@ -203,9 +207,9 @@ RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
|
|||
const RoadVehicleInfo *rvi = &e->u.road;
|
||||
assert(rvi->roadtype < ROADTYPE_END);
|
||||
if (introduces) {
|
||||
rts |= GetRoadTypeInfo(rvi->roadtype)->introduces_roadtypes;
|
||||
rts.Set(GetRoadTypeInfo(rvi->roadtype)->introduces_roadtypes);
|
||||
} else {
|
||||
SetBit(rts, rvi->roadtype);
|
||||
rts.Set(rvi->roadtype);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +225,7 @@ RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
|
|||
*/
|
||||
RoadTypes GetRoadTypes(bool introduces)
|
||||
{
|
||||
RoadTypes rts = ROADTYPES_NONE;
|
||||
RoadTypes rts{};
|
||||
|
||||
for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
|
||||
const EngineInfo *ei = &e->info;
|
||||
|
@ -230,9 +234,9 @@ RoadTypes GetRoadTypes(bool introduces)
|
|||
const RoadVehicleInfo *rvi = &e->u.road;
|
||||
assert(rvi->roadtype < ROADTYPE_END);
|
||||
if (introduces) {
|
||||
rts |= GetRoadTypeInfo(rvi->roadtype)->introduces_roadtypes;
|
||||
rts.Set(GetRoadTypeInfo(rvi->roadtype)->introduces_roadtypes);
|
||||
} else {
|
||||
SetBit(rts, rvi->roadtype);
|
||||
rts.Set(rvi->roadtype);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -204,12 +204,12 @@ inline RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
|
|||
|
||||
inline bool RoadTypeIsRoad(RoadType roadtype)
|
||||
{
|
||||
return HasBit(GetMaskForRoadTramType(RTT_ROAD), roadtype);
|
||||
return GetMaskForRoadTramType(RTT_ROAD).Test(roadtype);
|
||||
}
|
||||
|
||||
inline bool RoadTypeIsTram(RoadType roadtype)
|
||||
{
|
||||
return HasBit(GetMaskForRoadTramType(RTT_TRAM), roadtype);
|
||||
return GetMaskForRoadTramType(RTT_TRAM).Test(roadtype);
|
||||
}
|
||||
|
||||
inline RoadTramType GetRoadTramType(RoadType roadtype)
|
||||
|
@ -244,7 +244,7 @@ inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
|
|||
*/
|
||||
inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
|
||||
{
|
||||
return HasBit(GetRoadTypeInfo(enginetype)->powered_roadtypes, tiletype);
|
||||
return GetRoadTypeInfo(enginetype)->powered_roadtypes.Test(tiletype);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,14 +62,14 @@ RoadTypes _roadtypes_tram; ///< Bitset of tram roadtypes.
|
|||
*/
|
||||
void ResetRoadTypes()
|
||||
{
|
||||
static_assert(lengthof(_original_roadtypes) <= lengthof(_roadtypes));
|
||||
static_assert(std::size(_original_roadtypes) <= std::size(_roadtypes));
|
||||
|
||||
auto insert = std::copy(std::begin(_original_roadtypes), std::end(_original_roadtypes), std::begin(_roadtypes));
|
||||
std::fill(insert, std::end(_roadtypes), RoadTypeInfo{});
|
||||
|
||||
_roadtypes_hidden_mask = ROADTYPES_NONE;
|
||||
_roadtypes_road = ROADTYPES_ROAD;
|
||||
_roadtypes_tram = ROADTYPES_TRAM;
|
||||
_roadtypes_hidden_mask = {};
|
||||
_roadtypes_road = {ROADTYPE_ROAD};
|
||||
_roadtypes_tram = {ROADTYPE_TRAM};
|
||||
}
|
||||
|
||||
void ResolveRoadTypeGUISprites(RoadTypeInfo *rti)
|
||||
|
@ -113,7 +113,7 @@ void InitRoadTypes()
|
|||
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
|
||||
RoadTypeInfo *rti = &_roadtypes[rt];
|
||||
ResolveRoadTypeGUISprites(rti);
|
||||
if (rti->flags.Test(RoadTypeFlag::Hidden)) SetBit(_roadtypes_hidden_mask, rt);
|
||||
if (rti->flags.Test(RoadTypeFlag::Hidden)) _roadtypes_hidden_mask.Set(rt);
|
||||
}
|
||||
|
||||
_sorted_roadtypes.clear();
|
||||
|
@ -141,10 +141,10 @@ RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
|
|||
rti->introduction_date = CalendarTime::INVALID_DATE;
|
||||
|
||||
/* Make us compatible with ourself. */
|
||||
rti->powered_roadtypes = (RoadTypes)(1ULL << rt);
|
||||
rti->powered_roadtypes = rt;
|
||||
|
||||
/* We also introduce ourself. */
|
||||
rti->introduces_roadtypes = (RoadTypes)(1ULL << rt);
|
||||
rti->introduces_roadtypes = rt;
|
||||
|
||||
/* Default sort order; order of allocation, but with some
|
||||
* offsets so it's easier for NewGRF to pick a spot without
|
||||
|
@ -156,9 +156,9 @@ RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
|
|||
|
||||
/* Set bitmap of road/tram types */
|
||||
if (rtt == RTT_TRAM) {
|
||||
SetBit(_roadtypes_tram, rt);
|
||||
_roadtypes_tram.Set(rt);
|
||||
} else {
|
||||
SetBit(_roadtypes_road, rt);
|
||||
_roadtypes_road.Set(rt);
|
||||
}
|
||||
|
||||
return rt;
|
||||
|
|
|
@ -843,7 +843,7 @@ struct BuildRoadToolbarWindow : Window {
|
|||
break;
|
||||
|
||||
case GM_EDITOR:
|
||||
if ((GetRoadTypes(true) & GetMaskForRoadTramType(rtt)) == ROADTYPES_NONE) return ES_NOT_HANDLED;
|
||||
if (!GetRoadTypes(true).Any(GetMaskForRoadTramType(rtt))) return ES_NOT_HANDLED;
|
||||
w = ShowBuildRoadScenToolbar(last_build);
|
||||
break;
|
||||
|
||||
|
@ -1767,8 +1767,8 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
|
|||
}
|
||||
|
||||
/* Filter listed road types */
|
||||
if (!HasBit(rtts, RTT_ROAD)) used_roadtypes &= ~GetMaskForRoadTramType(RTT_ROAD);
|
||||
if (!HasBit(rtts, RTT_TRAM)) used_roadtypes &= ~GetMaskForRoadTramType(RTT_TRAM);
|
||||
if (!HasBit(rtts, RTT_ROAD)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_ROAD));
|
||||
if (!HasBit(rtts, RTT_TRAM)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_TRAM));
|
||||
|
||||
DropDownList list;
|
||||
|
||||
|
@ -1779,9 +1779,9 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
|
|||
Dimension d = { 0, 0 };
|
||||
/* Get largest icon size, to ensure text is aligned on each menu item. */
|
||||
if (!for_replacement) {
|
||||
used_roadtypes &= ~_roadtypes_hidden_mask;
|
||||
used_roadtypes.Reset(_roadtypes_hidden_mask);
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
if (!HasBit(used_roadtypes, rt)) continue;
|
||||
if (!used_roadtypes.Test(rt)) continue;
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
|
||||
d = maxdim(d, GetSpriteSize(rti->gui_sprites.build_x_road));
|
||||
}
|
||||
|
@ -1792,17 +1792,17 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
|
|||
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
/* If it's not used ever, don't show it to the user. */
|
||||
if (!HasBit(used_roadtypes, rt)) continue;
|
||||
if (!used_roadtypes.Test(rt)) continue;
|
||||
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
|
||||
|
||||
if (for_replacement) {
|
||||
list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, GetString(rti->strings.replace_text), rt, !HasBit(avail_roadtypes, rt)));
|
||||
list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, GetString(rti->strings.replace_text), rt, !avail_roadtypes.Test(rt)));
|
||||
} else {
|
||||
std::string str = rti->max_speed > 0
|
||||
? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
|
||||
: GetString(rti->strings.menu_text);
|
||||
list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !HasBit(avail_roadtypes, rt)));
|
||||
list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1821,16 +1821,16 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
|
|||
RoadTypes used_roadtypes = GetRoadTypes(true);
|
||||
|
||||
/* Filter listed road types */
|
||||
used_roadtypes &= ~_roadtypes_hidden_mask;
|
||||
if (!HasBit(rtts, RTT_ROAD)) used_roadtypes &= ~GetMaskForRoadTramType(RTT_ROAD);
|
||||
if (!HasBit(rtts, RTT_TRAM)) used_roadtypes &= ~GetMaskForRoadTramType(RTT_TRAM);
|
||||
used_roadtypes.Reset(_roadtypes_hidden_mask);
|
||||
if (!HasBit(rtts, RTT_ROAD)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_ROAD));
|
||||
if (!HasBit(rtts, RTT_TRAM)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_TRAM));
|
||||
|
||||
DropDownList list;
|
||||
|
||||
/* If it's not used ever, don't show it to the user. */
|
||||
Dimension d = { 0, 0 };
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
if (!HasBit(used_roadtypes, rt)) continue;
|
||||
if (!used_roadtypes.Test(rt)) continue;
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
|
||||
d = maxdim(d, GetSpriteSize(rti->gui_sprites.build_x_road));
|
||||
}
|
||||
|
@ -1839,14 +1839,14 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
|
|||
auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_ROADTYPES);
|
||||
|
||||
for (const auto &rt : _sorted_roadtypes) {
|
||||
if (!HasBit(used_roadtypes, rt)) continue;
|
||||
if (!used_roadtypes.Test(rt)) continue;
|
||||
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
|
||||
|
||||
std::string str = rti->max_speed > 0
|
||||
? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
|
||||
: GetString(rti->strings.menu_text);
|
||||
list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !HasBit(avail_roadtypes, rt)));
|
||||
list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
|
||||
}
|
||||
|
||||
if (list.empty()) {
|
||||
|
|
|
@ -184,10 +184,10 @@ inline RoadType GetRoadType(Tile t, RoadTramType rtt)
|
|||
*/
|
||||
inline RoadTypes GetPresentRoadTypes(Tile t)
|
||||
{
|
||||
RoadTypes result = ROADTYPES_NONE;
|
||||
RoadTypes result{};
|
||||
if (MayHaveRoad(t)) {
|
||||
if (GetRoadTypeRoad(t) != INVALID_ROADTYPE) SetBit(result, GetRoadTypeRoad(t));
|
||||
if (GetRoadTypeTram(t) != INVALID_ROADTYPE) SetBit(result, GetRoadTypeTram(t));
|
||||
if (GetRoadTypeRoad(t) != INVALID_ROADTYPE) result.Set(GetRoadTypeRoad(t));
|
||||
if (GetRoadTypeTram(t) != INVALID_ROADTYPE) result.Set(GetRoadTypeTram(t));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ inline bool HasTileRoadType(Tile t, RoadTramType rtt)
|
|||
inline bool HasTileAnyRoadType(Tile t, RoadTypes rts)
|
||||
{
|
||||
if (!MayHaveRoad(t)) return false;
|
||||
return (GetPresentRoadTypes(t) & rts);
|
||||
return GetPresentRoadTypes(t).Any(rts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,8 +19,6 @@ static const RoadTypeLabel ROADTYPE_LABEL_TRAM = 'ELRL';
|
|||
|
||||
/**
|
||||
* The different roadtypes we support
|
||||
*
|
||||
* @note currently only ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
|
||||
*/
|
||||
enum RoadType : uint8_t {
|
||||
ROADTYPE_BEGIN = 0, ///< Used for iterations
|
||||
|
@ -31,17 +29,7 @@ enum RoadType : uint8_t {
|
|||
};
|
||||
DECLARE_INCREMENT_DECREMENT_OPERATORS(RoadType)
|
||||
|
||||
/**
|
||||
* The different roadtypes we support, but then a bitmask of them.
|
||||
* @note Must be treated as a uint64_t type, narrowing it causes bit membership tests to give wrong results.
|
||||
*/
|
||||
enum RoadTypes : uint64_t {
|
||||
ROADTYPES_NONE = 0, ///< No roadtypes
|
||||
ROADTYPES_ROAD = 1 << ROADTYPE_ROAD, ///< Road
|
||||
ROADTYPES_TRAM = 1 << ROADTYPE_TRAM, ///< Trams
|
||||
INVALID_ROADTYPES = UINT64_MAX, ///< Invalid roadtypes
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(RoadTypes)
|
||||
using RoadTypes = EnumBitSet<RoadType, uint64_t>;
|
||||
|
||||
/**
|
||||
* Enumeration for the road parts on a tile.
|
||||
|
|
|
@ -1119,7 +1119,7 @@ bool AfterLoadGame()
|
|||
for (auto t : Map::Iterate()) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_ROAD:
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, (RoadTypes)GB(t.m7(), 5, 3));
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, GB(t.m7(), 5, 3));
|
||||
SB(t.m7(), 5, 1, GB(t.m3(), 7, 1)); // snow/desert
|
||||
switch (GetRoadTileType(t)) {
|
||||
default: SlErrorCorrupt("Invalid road tile type");
|
||||
|
@ -1152,7 +1152,7 @@ bool AfterLoadGame()
|
|||
case MP_STATION:
|
||||
if (!IsStationRoadStop(t)) break;
|
||||
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, (RoadTypes)GB(t.m3(), 0, 3));
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, GB(t.m3(), 0, 3));
|
||||
SB(t.m7(), 0, 5, (HasBit(t.m6(), 2) ? OWNER_TOWN : GetTileOwner(t)).base());
|
||||
SB(t.m3(), 4, 4, t.m1());
|
||||
t.m4() = 0;
|
||||
|
@ -1161,7 +1161,7 @@ bool AfterLoadGame()
|
|||
case MP_TUNNELBRIDGE:
|
||||
if (old_bridge && IsBridge(t) && HasBit(t.m5(), 6)) break;
|
||||
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(t.m5(), 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, (RoadTypes)GB(t.m3(), 0, 3));
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, GB(t.m3(), 0, 3));
|
||||
|
||||
Owner o = GetTileOwner(t);
|
||||
SB(t.m7(), 0, 5, o.base()); // road owner
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false;
|
||||
|
||||
return ::IsTileType(tile, MP_ROAD) && ::GetRoadTileType(tile) == ROAD_TILE_DEPOT &&
|
||||
HasBit(::GetPresentRoadTypes(tile), (::RoadType)GetCurrentRoadType());
|
||||
::GetPresentRoadTypes(tile).Test(::RoadType(GetCurrentRoadType()));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptRoad::IsRoadStationTile(TileIndex tile)
|
||||
|
@ -55,7 +55,7 @@
|
|||
if (!::IsValidTile(tile)) return false;
|
||||
if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false;
|
||||
|
||||
return ::IsStationRoadStopTile(tile) && HasBit(::GetPresentRoadTypes(tile), (::RoadType)GetCurrentRoadType());
|
||||
return ::IsStationRoadStopTile(tile) && ::GetPresentRoadTypes(tile).Test(::RoadType(GetCurrentRoadType()));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptRoad::IsDriveThroughRoadStationTile(TileIndex tile)
|
||||
|
@ -63,7 +63,7 @@
|
|||
if (!::IsValidTile(tile)) return false;
|
||||
if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false;
|
||||
|
||||
return ::IsDriveThroughStopTile(tile) && HasBit(::GetPresentRoadTypes(tile), (::RoadType)GetCurrentRoadType());
|
||||
return ::IsDriveThroughStopTile(tile) && ::GetPresentRoadTypes(tile).Test(::RoadType(GetCurrentRoadType()));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptRoad::IsRoadTypeAvailable(RoadType road_type)
|
||||
|
@ -101,7 +101,7 @@
|
|||
{
|
||||
if (!ScriptMap::IsValidTile(tile)) return false;
|
||||
if (!IsRoadTypeAvailable(road_type)) return false;
|
||||
return ::MayHaveRoad(tile) && HasBit(::GetPresentRoadTypes(tile), (::RoadType)road_type);
|
||||
return ::MayHaveRoad(tile) && ::GetPresentRoadTypes(tile).Test(::RoadType(road_type));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2)
|
||||
|
@ -461,7 +461,7 @@ static std::optional<RoadPartOrientation> ToRoadPartOrientation(const TileIndex
|
|||
static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagDirection neighbour)
|
||||
{
|
||||
TileIndex neighbour_tile = ::TileAddByDiagDir(start_tile, neighbour);
|
||||
if (!HasBit(::GetPresentRoadTypes(neighbour_tile), rt)) return false;
|
||||
if (!::GetPresentRoadTypes(neighbour_tile).Test(rt)) return false;
|
||||
|
||||
switch (::GetTileType(neighbour_tile)) {
|
||||
case MP_ROAD:
|
||||
|
|
|
@ -218,10 +218,10 @@ template <bool Tfrom, bool Tvia>
|
|||
if (!ScriptRoad::IsRoadTypeAvailable(road_type)) return false;
|
||||
|
||||
for (const RoadStop *rs = ::Station::Get(station_id)->GetPrimaryRoadStop(RoadStopType::Bus); rs != nullptr; rs = rs->next) {
|
||||
if (HasBit(::GetPresentRoadTypes(rs->xy), (::RoadType)road_type)) return true;
|
||||
if (::GetPresentRoadTypes(rs->xy).Test(::RoadType(road_type))) return true;
|
||||
}
|
||||
for (const RoadStop *rs = ::Station::Get(station_id)->GetPrimaryRoadStop(RoadStopType::Truck); rs != nullptr; rs = rs->next) {
|
||||
if (HasBit(::GetPresentRoadTypes(rs->xy), (::RoadType)road_type)) return true;
|
||||
if (::GetPresentRoadTypes(rs->xy).Test(::RoadType(road_type))) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -58,7 +58,7 @@ static const RoadTypeInfo _original_roadtypes[] = {
|
|||
},
|
||||
|
||||
/* Powered roadtypes */
|
||||
ROADTYPES_ROAD,
|
||||
{ROADTYPE_ROAD},
|
||||
|
||||
/* flags */
|
||||
{RoadTypeFlag::TownBuild},
|
||||
|
@ -85,10 +85,10 @@ static const RoadTypeInfo _original_roadtypes[] = {
|
|||
CalendarTime::MIN_DATE,
|
||||
|
||||
/* roadtypes required for this to be introduced */
|
||||
ROADTYPES_NONE,
|
||||
{},
|
||||
|
||||
/* introduction road types */
|
||||
ROADTYPES_ROAD,
|
||||
{ROADTYPE_ROAD},
|
||||
|
||||
/* sort order */
|
||||
0x07,
|
||||
|
@ -139,7 +139,7 @@ static const RoadTypeInfo _original_roadtypes[] = {
|
|||
},
|
||||
|
||||
/* Powered roadtypes */
|
||||
ROADTYPES_TRAM,
|
||||
{ROADTYPE_TRAM},
|
||||
|
||||
/* flags */
|
||||
{RoadTypeFlag::Catenary, RoadTypeFlag::NoHouses},
|
||||
|
@ -166,10 +166,10 @@ static const RoadTypeInfo _original_roadtypes[] = {
|
|||
CalendarTime::INVALID_DATE,
|
||||
|
||||
/* roadtypes required for this to be introduced */
|
||||
ROADTYPES_NONE,
|
||||
{},
|
||||
|
||||
/* introduction road types */
|
||||
ROADTYPES_TRAM,
|
||||
{ROADTYPE_TRAM},
|
||||
|
||||
/* sort order */
|
||||
0x17,
|
||||
|
|
|
@ -2352,8 +2352,8 @@ struct ScenarioEditorToolbarWindow : Window {
|
|||
{
|
||||
this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= CalendarTime::MIN_YEAR);
|
||||
this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= CalendarTime::MAX_YEAR);
|
||||
this->SetWidgetDisabledState(WID_TE_ROADS, (GetRoadTypes(true) & GetMaskForRoadTramType(RTT_ROAD)) == ROADTYPES_NONE);
|
||||
this->SetWidgetDisabledState(WID_TE_TRAMS, (GetRoadTypes(true) & GetMaskForRoadTramType(RTT_TRAM)) == ROADTYPES_NONE);
|
||||
this->SetWidgetDisabledState(WID_TE_ROADS, !GetRoadTypes(true).Any(GetMaskForRoadTramType(RTT_ROAD)));
|
||||
this->SetWidgetDisabledState(WID_TE_TRAMS, !GetRoadTypes(true).Any(GetMaskForRoadTramType(RTT_TRAM)));
|
||||
|
||||
this->DrawWidgets();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue