Changeset - r3656:2ddda8cf72e7
[Not reviewed]
master
0 1 0
tron - 18 years ago 2006-04-25 07:29:02
tron@openttd.org
(svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
1 file changed with 20 insertions and 9 deletions:
openttd.c
20
9
0 comments (0 inline, 0 general)
openttd.c
Show inline comments
 
@@ -1082,6 +1082,13 @@ static void UpdateSignOwner(void)
 
extern void UpdateOldAircraft( void );
 
extern void UpdateOilRig( void );
 

	
 

	
 
static inline RailType UpdateRailType(RailType rt, RailType min)
 
{
 
	return rt >= min ? (RailType)(rt + 1): rt;
 
}
 

	
 

	
 
bool AfterLoadGame(void)
 
{
 
	Window *w;
 
@@ -1247,7 +1254,7 @@ bool AfterLoadGame(void)
 
		Vehicle* v;
 
		uint i;
 
		TileIndex t;
 
		bool make_elrail = false;
 
		RailType min_rail = RAILTYPE_ELECTRIC;
 

	
 
		for (i = 0; i < lengthof(_engines); i++) {
 
			Engine* e = GetEngine(i);
 
@@ -1262,7 +1269,7 @@ bool AfterLoadGame(void)
 
				RailType rt = GetEngine(v->engine_type)->railtype;
 

	
 
				v->u.rail.railtype = rt;
 
				if (rt == RAILTYPE_ELECTRIC) make_elrail = true;
 
				if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL;
 
			}
 
		}
 

	
 
@@ -1270,34 +1277,38 @@ bool AfterLoadGame(void)
 
		for (t = 0; t < MapSize(); t++) {
 
			switch (GetTileType(t)) {
 
				case MP_RAILWAY:
 
					if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1);
 
					SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
 
					break;
 

	
 
				case MP_STREET:
 
					if (IsLevelCrossing(t) && (GetRailTypeCrossing(t) > RAILTYPE_RAIL || make_elrail)) AB(_m[t].m4, 0, 4, 1);
 
					if (IsLevelCrossing(t)) {
 
						SetRailTypeCrossing(t, UpdateRailType(GetRailTypeCrossing(t), min_rail));
 
					}
 
					break;
 

	
 
				case MP_STATION:
 
					if (IsRailwayStation(t) && (GetRailType(t) > RAILTYPE_RAIL || make_elrail)) AB(_m[t].m3, 0, 4, 1);
 
					if (IsRailwayStation(t))  {
 
						SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
 
					}
 
					break;
 

	
 
				case MP_TUNNELBRIDGE:
 
					if (IsTunnel(t)) {
 
						if (GetTunnelTransportType(t) == TRANSPORT_RAIL) {
 
							if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1);
 
							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
 
						}
 
					} else {
 
						if (GetBridgeTransportType(t) == TRANSPORT_RAIL) {
 
							if (IsBridgeRamp(t)) {
 
								if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1);
 
								SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
 
							} else {
 
								if (GetRailTypeOnBridge(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 4, 4, 1);
 
								SetRailTypeOnBridge(t, UpdateRailType(GetRailTypeOnBridge(t), min_rail));
 
							}
 
						}
 
						if (IsBridgeMiddle(t) &&
 
								IsTransportUnderBridge(t) &&
 
								GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL) {
 
							if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1);
 
							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
 
						}
 
					}
 
					break;
0 comments (0 inline, 0 general)