summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rail.cpp41
-rw-r--r--src/rail.h3
-rw-r--r--src/rail_gui.cpp24
3 files changed, 52 insertions, 16 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;
}
/**
diff --git a/src/rail.h b/src/rail.h
index b08f0650a..004593ce7 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -455,7 +455,8 @@ bool ValParamRailtype(const RailType rail);
RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date);
RailType GetBestRailtype(const CompanyID company);
-RailTypes GetCompanyRailtypes(const CompanyID c);
+RailTypes GetCompanyRailtypes(CompanyID company, bool introduces = true);
+RailTypes GetRailTypes(bool introduces);
RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels = true);
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 827f24456..176e8e6ef 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -1989,20 +1989,20 @@ void InitializeRailGUI()
*/
DropDownList *GetRailTypeDropDownList(bool for_replacement, bool all_option)
{
- RailTypes used_railtypes = RAILTYPES_NONE;
+ RailTypes used_railtypes;
+ RailTypes avail_railtypes;
- /* Find the used railtypes. */
- Engine *e;
- FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
- if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
+ const Company *c = Company::Get(_local_company);
- used_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
+ /* Find the used railtypes. */
+ if (for_replacement) {
+ avail_railtypes = GetCompanyRailtypes(c->index, false);
+ used_railtypes = GetRailTypes(false);
+ } else {
+ avail_railtypes = c->avail_railtypes;
+ used_railtypes = GetRailTypes(true);
}
- /* Get the date introduced railtypes as well. */
- used_railtypes = AddDateIntroducedRailTypes(used_railtypes, MAX_DAY);
-
- const Company *c = Company::Get(_local_company);
DropDownList *list = new DropDownList();
if (all_option) {
@@ -2030,9 +2030,9 @@ DropDownList *GetRailTypeDropDownList(bool for_replacement, bool all_option)
StringID str = for_replacement ? rti->strings.replace_text : (rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING);
DropDownListParamStringItem *item;
if (for_replacement) {
- item = new DropDownListParamStringItem(str, rt, !HasBit(c->avail_railtypes, rt));
+ item = new DropDownListParamStringItem(str, rt, !HasBit(avail_railtypes, rt));
} else {
- DropDownListIconItem *iconitem = new DropDownListIconItem(rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(c->avail_railtypes, rt));
+ DropDownListIconItem *iconitem = new DropDownListIconItem(rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt));
iconitem->SetDimension(d);
item = iconitem;
}