changeset 17104:f081bf6f0633 draft

(svn r21841) -Feature: [NewGRF] Allow to define other railtypes that should be introduced if a particular rail type is introduced, e.g. to make sure slow rail is introduced when fast rail gets introduced
author rubidium <rubidium@openttd.org>
date Tue, 18 Jan 2011 21:28:07 +0000
parents 473b6165a404
children a804b91f3a3e
files src/engine.cpp src/newgrf.cpp src/rail.cpp src/rail.h src/rail_cmd.cpp src/table/railtypes.h src/toolbar_gui.cpp
diffstat 7 files changed, 34 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -614,7 +614,7 @@
 	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 @@
 		/* 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);
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -3209,6 +3209,7 @@
 
 			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 @@
 					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 @@
 
 			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;
 
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -194,7 +194,7 @@
 
 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 @@
 
 			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)
--- a/src/rail.h
+++ b/src/rail.h
@@ -217,6 +217,11 @@
 	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];
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -97,6 +97,9 @@
 			/* 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;
 		}
 	}
--- a/src/table/railtypes.h
+++ b/src/table/railtypes.h
@@ -95,6 +95,9 @@
 		/* map colour */
 		0x0A,
 
+		/* introduction rail types */
+		RAILTYPES_RAIL,
+
 		{ NULL },
 	},
 
@@ -178,6 +181,9 @@
 		/* map colour */
 		0x0A,
 
+		/* introduction rail types */
+		RAILTYPES_ELECTRIC,
+
 		{ NULL },
 	},
 
@@ -257,6 +263,9 @@
 		/* map colour */
 		0x0A,
 
+		/* introduction rail types */
+		RAILTYPES_MONO,
+
 		{ NULL },
 	},
 
@@ -336,6 +345,9 @@
 		/* map colour */
 		0x0A,
 
+		/* introduction rail types */
+		RAILTYPES_MAGLEV,
+
 		{ NULL },
 	},
 };
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -693,22 +693,21 @@
 
 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 */