Old revision #pn1c10m0z | New revision #pwwa4fqnb | ||
---|---|---|---|
1 | diff --git a/src/road.cpp b/src/road.cpp | 1 | diff --git a/src/road.cpp b/src/road.cpp |
2 | index 399971c.. | 2 | index 399971c..281cfd9 100644 |
3 | --- a/src/road.cpp | 3 | --- a/src/road.cpp |
4 | +++ b/src/road.cpp | 4 | +++ b/src/road.cpp |
5 | @@ -247,3 +247, | 5 | @@ -247,3 +247,44 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data) |
6 | assert(ret); | 6 | assert(ret); |
7 | return result; | 7 | return result; |
8 | } | 8 | } | … | … |
10 | +/** | 10 | +/** |
11 | + * Returns the available RoadSubTypes for the provided RoadType | 11 | + * Returns the available RoadSubTypes for the provided RoadType |
12 | + * @param rt the RoadType to filter | 12 | + * @param rt the RoadType to filter |
13 | + * @param c the company | 13 | + * @param c the company ID to check the roadtype against |
14 | + * @param | 14 | + * @param any_date whether to return only currently introduced roadtypes or also future ones |
15 | + * @returns the existing RoadSubTypes | 15 | + * @returns the existing RoadSubTypes |
16 | + */ | 16 | + */ |
17 | +RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool | 17 | +RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_date = true) |
18 | +{ | 18 | +{ |
19 | + if (c != INVALID_COMPANY) { | ||
20 | + const Company *company = Company::GetIfValid(c); | ||
21 | + | ||
22 | + return company->avail_roadtypes[rt]; | ||
23 | + } | ||
24 | + | ||
19 | + RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE; | 25 | + RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE; |
20 | |||
21 | + | 26 | + |
22 | + /* Road is always visible and available. */ | 27 | + /* Road is always visible and available. */ |
23 | + if (rt == ROADTYPE_ROAD) known_roadsubtypes |= ROADSUBTYPES_NORMAL; // TODO | 28 | + if (rt == ROADTYPE_ROAD) known_roadsubtypes |= ROADSUBTYPES_NORMAL; // TODO | … | … |
28 | + /* Check if the subtype can be used in the current climate */ | 33 | + /* Check if the subtype can be used in the current climate */ |
29 | + if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; | 34 | + if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; |
30 | + | 35 | + |
36 | + /* Check whether available for all potential companies */ | ||
37 | + if (e->company_avail != (CompanyMask)-1) continue; | ||
38 | + | ||
31 | + RoadTypeIdentifier rtid = e->GetRoadType(); | 39 | + RoadTypeIdentifier rtid = e->GetRoadType(); |
32 | + if (rtid.basetype != rt) continue; | 40 | + if (rtid.basetype != rt) continue; |
33 | + | 41 | + |
34 | + known_roadsubtypes |= GetRoadTypeInfo(rtid)->introduces_roadtypes; | 42 | + known_roadsubtypes |= GetRoadTypeInfo(rtid)->introduces_roadtypes; |
35 | + } | 43 | + } |
36 | + | 44 | + |
37 | + if (!only_existing) { | 37 | + /* Get the date introduced roadtypes as well. */ |
38 | + /* Get the date introduced roadtypes as well. */ | 38 | + known_roadsubtypes = AddDateIntroducedRoadTypes(rt, known_roadsubtypes, any_date ? MAX_DAY : _date); |
39 | + known_roadsubtypes = AddDateIntroducedRoadTypes(rt, known_roadsubtypes, MAX_DAY); | ||
40 | + } | ||
41 | + | 47 | + |
42 | + const Company *company = Company::GetIfValid(c); | 42 | + return known_roadsubtypes; |
43 | + | ||
44 | + /* If it's not used ever, don't show it to the user. */ | ||
45 | + RoadTypeIdentifier rtid; | ||
46 | + FOR_ALL_SORTED_ROADTYPES(rtid, rt) { | ||
47 | + if (!HasBit(known_roadsubtypes, rtid.subtype)) continue; | ||
48 | + | ||
49 | + if (company != NULL) { | ||
50 | + if (only_existing && !HasBit(company->avail_roadtypes[rtid.basetype], rtid.subtype)) { | ||
51 | + continue; | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + SetBit(available_roadsubtypes, rtid.subtype); | ||
56 | + } | ||
57 | + | ||
58 | + return available_roadsubtypes; | ||
59 | +} | 49 | +} |