Loading

Revision differences

Old revision #p84xottjaNew revision #pwwa4fqnb
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..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,33 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data)  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 only_existing whether to return only currently introduced vehicles or also future ones  13+ * @param c the company ID to check the roadtype against
   14+ * @param any_date whether to return only currently introduced roadtypes 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 any_date = true)
17+{  18+{  
18+    RoadSubTypes used_roadsubtypes = ROADSUBTYPES_NONE;  19+    if (c != INVALID_COMPANY) {
   20+        const Company *company = Company::GetIfValid(c);
   21+
   22+        return company->avail_roadtypes[rt];
   23+    }
   24+
   25+    RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE;
   26+
   27+    /* Road is always visible and available. */
   28+    if (rt == ROADTYPE_ROAD) known_roadsubtypes |= ROADSUBTYPES_NORMAL; // TODO
19+  29+  
20+    /* Find used roadtypes */  30+    /* Find used roadtypes */  
21+    Engine *e;  31+    Engine *e;  
  
23+        /* Check if the subtype can be used in the current climate */  33+        /* Check if the subtype can be used in the current climate */  
24+        if (!HasBit(e->info.climates,  _settings_game.game_creation.landscape)) continue;  34+        if (!HasBit(e->info.climates,  _settings_game.game_creation.landscape)) continue;  
25+  35+  
  36+        /* Check whether available for all potential companies */  
  37+        if (e->company_avail != (CompanyMask)-1) continue;  
  38+  
26+        RoadTypeIdentifier rtid = e->GetRoadType();  39+        RoadTypeIdentifier rtid = e->GetRoadType();  
27+        if (rtid.basetype != rt) continue;  40+        if (rtid.basetype != rt) continue;  
28+  41+  
29+        used_roadsubtypes |= GetRoadTypeInfo(rtid)->introduces_roadtypes;  29+        known_roadsubtypes |= GetRoadTypeInfo(rtid)->introduces_roadtypes;
30+    }  43+    }  
31+  44+  
32+    if (!only_existing) {  32+    /* Get the date introduced roadtypes as well. */
33+        /* Get the date introduced roadtypes as well. */  33+    known_roadsubtypes = AddDateIntroducedRoadTypes(rt, known_roadsubtypes, any_date ? MAX_DAY : _date);
34+        used_roadsubtypes = AddDateIntroducedRoadTypes(rt, used_roadsubtypes, MAX_DAY);    
35+    }    
36+  47+  
37+    return used_roadsubtypes;  37+    return known_roadsubtypes;
38+} 49+}