summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/engine.cpp4
-rw-r--r--src/newgrf.cpp10
-rw-r--r--src/rail.cpp6
-rw-r--r--src/rail.h5
-rw-r--r--src/rail_cmd.cpp3
-rw-r--r--src/table/railtypes.h12
-rw-r--r--src/toolbar_gui.cpp7
7 files changed, 34 insertions, 13 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index ecc175e4a..198434a88 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -614,7 +614,7 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company)
SetBit(e->company_avail, company);
if (e->type == VEH_TRAIN) {
assert(e->u.rail.railtype < RAILTYPE_END);
- SetBit(c->avail_railtypes, e->u.rail.railtype);
+ c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
} else if (e->type == VEH_ROAD) {
SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
}
@@ -760,7 +760,7 @@ static void NewVehicleAvailable(Engine *e)
/* maybe make another rail type available */
RailType railtype = e->u.rail.railtype;
assert(railtype < RAILTYPE_END);
- FOR_ALL_COMPANIES(c) SetBit(c->avail_railtypes, railtype);
+ FOR_ALL_COMPANIES(c) c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
} else if (e->type == VEH_ROAD) {
/* maybe make another road type available */
FOR_ALL_COMPANIES(c) SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 4a4f55213..4f3c23f2f 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -3209,6 +3209,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteR
case 0x0E: // Compatible railtype list
case 0x0F: // Powered railtype list
+ case 0x19: // Introduced railtype list
{
/* Rail type compatibility bits are added to the existing bits
* to allow multiple GRFs to modify compatibility with the
@@ -3218,10 +3219,10 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteR
RailTypeLabel label = buf->ReadDWord();
RailType rt = GetRailTypeByLabel(BSWAP32(label));
if (rt != INVALID_RAILTYPE) {
- if (prop == 0x0E) {
- SetBit(rti->compatible_railtypes, rt);
- } else {
- SetBit(rti->powered_railtypes, rt);
+ switch (prop) {
+ case 0x0E: SetBit(rti->compatible_railtypes, rt); break;
+ case 0x0F: SetBit(rti->powered_railtypes, rt); break;
+ case 0x19: SetBit(rti->introduces_railtypes, rt); break;
}
}
}
@@ -3303,6 +3304,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint id, int numinfo, int prop, Byte
case 0x0E: // Compatible railtype list
case 0x0F: // Powered railtype list
+ case 0x19: // Introduced railtype list
for (int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
break;
diff --git a/src/rail.cpp b/src/rail.cpp
index 21ae80661..a2285ef16 100644
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -194,7 +194,7 @@ RailType GetBestRailtype(const CompanyID company)
RailTypes GetCompanyRailtypes(CompanyID company)
{
- RailTypes rt = RAILTYPES_NONE;
+ RailTypes rts = RAILTYPES_NONE;
Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
@@ -206,12 +206,12 @@ RailTypes GetCompanyRailtypes(CompanyID company)
if (rvi->railveh_type != RAILVEH_WAGON) {
assert(rvi->railtype < RAILTYPE_END);
- SetBit(rt, rvi->railtype);
+ rts |= GetRailTypeInfo(rvi->railtype)->introduces_railtypes;
}
}
}
- return rt;
+ return rts;
}
RailType GetRailTypeByLabel(RailTypeLabel label)
diff --git a/src/rail.h b/src/rail.h
index 465a4aac3..81bac120c 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -217,6 +217,11 @@ struct RailtypeInfo {
byte map_colour;
/**
+ * Bitmask of which other railtypes are introduced when this railtype is introduced.
+ */
+ RailTypes introduces_railtypes;
+
+ /**
* Sprite groups for resolving sprites
*/
const SpriteGroup *group[RTSG_END];
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index bb77984d9..be056ed4b 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -97,6 +97,9 @@ RailType AllocateRailType(RailTypeLabel label)
/* Make us compatible with ourself. */
rti->powered_railtypes = (RailTypes)(1 << rt);
rti->compatible_railtypes = (RailTypes)(1 << rt);
+
+ /* We also introduce ourself. */
+ rti->introduces_railtypes = (RailTypes)(1 << rt);
return rt;
}
}
diff --git a/src/table/railtypes.h b/src/table/railtypes.h
index eda7e6ff0..7e59ab70b 100644
--- a/src/table/railtypes.h
+++ b/src/table/railtypes.h
@@ -95,6 +95,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
+ /* introduction rail types */
+ RAILTYPES_RAIL,
+
{ NULL },
},
@@ -178,6 +181,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
+ /* introduction rail types */
+ RAILTYPES_ELECTRIC,
+
{ NULL },
},
@@ -257,6 +263,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
+ /* introduction rail types */
+ RAILTYPES_MONO,
+
{ NULL },
},
@@ -336,6 +345,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
+ /* introduction rail types */
+ RAILTYPES_MAGLEV,
+
{ NULL },
},
};
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index f5537a19c..a93568969 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -693,22 +693,21 @@ static CallBackFunction ToolbarZoomOutClick(Window *w)
static CallBackFunction ToolbarBuildRailClick(Window *w)
{
- /* Use C++ spec to zero whole array. */
- bool used_railtype[RAILTYPE_END] = { false };
+ RailTypes used_railtypes = RAILTYPES_NONE;
/* 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;
- used_railtype[e->u.rail.railtype] = true;
+ used_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
}
const Company *c = Company::Get(_local_company);
DropDownList *list = new DropDownList();
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
/* If it's not used ever, don't show it to the user. */
- if (!used_railtype[rt]) continue;
+ if (!HasBit(used_railtypes, rt)) continue;
const RailtypeInfo *rti = GetRailTypeInfo(rt);
/* Skip rail type if it has no label */