(svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
authorcelestar
Sun, 10 Jul 2005 01:25:17 +0000
changeset 2032 64481deacfb1
parent 2031 6aa7f668a1b5
child 2033 1eb15b79b6f3
(svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
than one railtype (like Diesel engines on electrified rail).
-Codechange: Use IsCompatibleRail where it should be used
rail.h
train_cmd.c
train_gui.c
--- a/rail.h	Sat Jul 09 17:45:57 2005 +0000
+++ b/rail.h	Sun Jul 10 01:25:17 2005 +0000
@@ -505,7 +505,13 @@
  */
 static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
 {
-	return enginetype == tiletype;
+	static const bool EquivRailTypes[RAILTYPE_END][RAILTYPE_END] = {
+	{ true, false, false },
+	{ false, true, false },
+	{ false, false, true },
+	};
+
+	return EquivRailTypes[enginetype][tiletype];
 }
 
 #endif // RAIL_H
--- a/train_cmd.c	Sat Jul 09 17:45:57 2005 +0000
+++ b/train_cmd.c	Sun Jul 10 01:25:17 2005 +0000
@@ -2542,7 +2542,8 @@
 
 	return
 		IsTileOwner(tile, v->owner) &&
-		(v->subtype != TS_Front_Engine || (_map3_lo[tile] & 0xF) == v->u.rail.railtype);
+		(v->subtype != TS_Front_Engine ||
+		IsCompatibleRail(v->u.rail.railtype, GetRailType(tile)));
 }
 
 typedef struct {
--- a/train_gui.c	Sat Jul 09 17:45:57 2005 +0000
+++ b/train_gui.c	Sun Jul 10 01:25:17 2005 +0000
@@ -160,7 +160,7 @@
 		const Engine *e = GetEngine(i);
 		const RailVehicleInfo *rvi = RailVehInfo(i);
 
-		if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine ||
+		if (!IsCompatibleRail(railtype, e->railtype) || !(rvi->flags & RVI_WAGON) != is_engine ||
 				!HASBIT(e->player_avail, _local_player))
 			continue;
 
@@ -192,7 +192,7 @@
 
 			for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
 				const Engine *e = GetEngine(i);
-				if (e->railtype == railtype
+				if (IsCompatibleRail(railtype, e->railtype)
 				    && HASBIT(e->player_avail, _local_player))
 					count++;
 			}