summaryrefslogtreecommitdiff
path: root/src/rail.cpp
diff options
context:
space:
mode:
authorPeterN <peter@fuzzle.org>2019-03-31 02:05:23 +0100
committerGitHub <noreply@github.com>2019-03-31 02:05:23 +0100
commit6d1cc142c2390b3466a91de19d16e55bf1ee19f8 (patch)
tree48913eef7c9ccad20b4aa58c210f189f83f64d22 /src/rail.cpp
parente1069eee05b648a64ff5dac3dd5701b01cfa2034 (diff)
downloadopenttd-6d1cc142c2390b3466a91de19d16e55bf1ee19f8.tar.xz
Change: Shorten engine rail type drop down in autoreplace window. (#7448)
In the autoreplace window, the rail type drop down is for choosing engines of the given time. Many rail types do not have engines specifically designed for them, and are merely compatible with other rail types. This list is thus unwieldy and many options have no engines available. As this drop down is for choosing _engine_ rail type rather than compatible rail types, we can list just the rail types explicitly listed by engines.
Diffstat (limited to 'src/rail.cpp')
-rw-r--r--src/rail.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/rail.cpp b/src/rail.cpp
index c97dfb53c..f2870c1eb 100644
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -262,13 +262,14 @@ RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date)
/**
* Get the rail types the given company can build.
* @param company the company to get the rail types for.
+ * @param introduces If true, include rail types introduced by other rail types
* @return the rail types.
*/
-RailTypes GetCompanyRailtypes(CompanyID company)
+RailTypes GetCompanyRailtypes(CompanyID company, bool introduces)
{
RailTypes rts = RAILTYPES_NONE;
- Engine *e;
+ const Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
const EngineInfo *ei = &e->info;
@@ -278,12 +279,46 @@ RailTypes GetCompanyRailtypes(CompanyID company)
if (rvi->railveh_type != RAILVEH_WAGON) {
assert(rvi->railtype < RAILTYPE_END);
+ if (introduces) {
+ rts |= GetRailTypeInfo(rvi->railtype)->introduces_railtypes;
+ } else {
+ SetBit(rts, rvi->railtype);
+ }
+ }
+ }
+ }
+
+ if (introduces) return AddDateIntroducedRailTypes(rts, _date);
+ return rts;
+}
+
+/**
+ * Get list of rail types, regardless of company availability.
+ * @param introduces If true, include rail types introduced by other rail types
+ * @return the rail types.
+ */
+RailTypes GetRailTypes(bool introduces)
+{
+ RailTypes rts = RAILTYPES_NONE;
+
+ const Engine *e;
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
+ const EngineInfo *ei = &e->info;
+ if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue;
+
+ const RailVehicleInfo *rvi = &e->u.rail;
+ if (rvi->railveh_type != RAILVEH_WAGON) {
+ assert(rvi->railtype < RAILTYPE_END);
+ if (introduces) {
rts |= GetRailTypeInfo(rvi->railtype)->introduces_railtypes;
+ } else {
+ SetBit(rts, rvi->railtype);
}
}
}
- return AddDateIntroducedRailTypes(rts, _date);
+ if (introduces) return AddDateIntroducedRailTypes(rts, MAX_DAY);
+ return rts;
}
/**