Loading

Revision differences

Old revision #p84xottjaNew revision #pn1c10m0z
1diff --git a/src/road.cpp b/src/road.cpp  1diff --git a/src/road.cpp b/src/road.cpp  
2index 399971c..7205bc1 100644  2index 399971c..3f0d436 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,33 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data)  5@@ -247,3 +247,54 @@ 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 to check the roadtype against  
13+ * @param only_existing whether to return only currently introduced vehicles or also future ones  14+ * @param only_existing whether to return only currently introduced vehicles or also future ones  
14+ * @returns the existing RoadSubTypes  15+ * @returns the existing RoadSubTypes  
15+ */  16+ */  
16+RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, bool only_existing = false)  16+RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool only_existing = false)
17+{  18+{  
18+    RoadSubTypes used_roadsubtypes = ROADSUBTYPES_NONE;  19+    RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE;
   20+    RoadSubTypes available_roadsubtypes = ROADSUBTYPES_NONE;
   21+
   22+    /* Road is always visible and available. */
   23+    if (rt == ROADTYPE_ROAD) known_roadsubtypes |= ROADSUBTYPES_NORMAL; // TODO
19+  24+  
20+    /* Find used roadtypes */  25+    /* Find used roadtypes */  
21+    Engine *e;  26+    Engine *e;  
  
26+        RoadTypeIdentifier rtid = e->GetRoadType();  31+        RoadTypeIdentifier rtid = e->GetRoadType();  
27+        if (rtid.basetype != rt) continue;  32+        if (rtid.basetype != rt) continue;  
28+  33+  
29+        used_roadsubtypes |= GetRoadTypeInfo(rtid)->introduces_roadtypes;  29+        known_roadsubtypes |= GetRoadTypeInfo(rtid)->introduces_roadtypes;
30+    }  35+    }  
31+  36+  
32+    if (!only_existing) {  37+    if (!only_existing) {  
33+        /* Get the date introduced roadtypes as well. */  38+        /* Get the date introduced roadtypes as well. */  
34+        used_roadsubtypes = AddDateIntroducedRoadTypes(rt, used_roadsubtypes, MAX_DAY);  34+        known_roadsubtypes = AddDateIntroducedRoadTypes(rt, known_roadsubtypes, MAX_DAY);
35+    }  40+    }  
36+  41+  
37+    return used_roadsubtypes;  42+    const Company *company = Company::GetIfValid(c);
   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;
38+} 59+}