src/rail_cmd.cpp
branchgamebalance
changeset 9908 0fa543611bbe
parent 9907 3b068c3a1c74
child 9909 dce9a6923bb7
--- a/src/rail_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
+++ b/src/rail_cmd.cpp	Tue Jun 12 11:56:35 2007 +0000
@@ -1,5 +1,7 @@
 /* $Id$ */
 
+/** @file rail_cmd.cpp */
+
 #include "stdafx.h"
 #include "openttd.h"
 #include "bridge_map.h"
@@ -77,8 +79,8 @@
 
 static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
 {
-	TrackBits current; /* The current track layout */
-	TrackBits future; /* The track layout we want to build */
+	TrackBits current; // The current track layout
+	TrackBits future;  // The track layout we want to build
 	_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
 
 	if (!IsPlainRailTile(tile)) return false;
@@ -109,7 +111,7 @@
 
 static const TrackBits _valid_tileh_slopes[][15] = {
 
-// set of normal ones
+/* set of normal ones */
 {
 	TRACK_BIT_ALL,
 	TRACK_BIT_RIGHT,
@@ -131,7 +133,7 @@
 	TRACK_BIT_RIGHT,
 },
 
-// allowed rail for an evenly raised platform
+/* allowed rail for an evenly raised platform */
 {
 	TRACK_BIT_NONE,
 	TRACK_BIT_LEFT,
@@ -190,20 +192,20 @@
 static uint32 CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
 {
 	if (IsSteepSlope(tileh)) {
-		if (existing == 0) {
+		if (_patches.build_on_slopes && existing == 0) {
 			TrackBits valid = TRACK_BIT_CROSS | (HASBIT(1 << SLOPE_STEEP_W | 1 << SLOPE_STEEP_E, tileh) ? TRACK_BIT_VERT : TRACK_BIT_HORZ);
 			if (valid & rail_bits) return _eco->GetPrice(CEconomy::TERRAFORM);
 		}
 	} else {
 		rail_bits |= existing;
 
-		// don't allow building on the lower side of a coast
+		/* don't allow building on the lower side of a coast */
 		if (IsTileType(tile, MP_WATER) &&
 				~_valid_tileh_slopes[1][tileh] & rail_bits) {
 			return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
 		}
 
-		// no special foundation
+		/* no special foundation */
 		if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0)
 			return 0;
 
@@ -252,12 +254,12 @@
 	switch (GetTileType(tile)) {
 		case MP_RAILWAY:
 			if (!CheckTrackCombination(tile, trackbit, flags) ||
-					!EnsureNoVehicle(tile)) {
+					!EnsureNoVehicleOnGround(tile)) {
 				return CMD_ERROR;
 			}
 			if (!IsTileOwner(tile, _current_player) ||
 					!IsCompatibleRail(GetRailType(tile), railtype)) {
-				// Get detailed error message
+				/* Get detailed error message */
 				return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 			}
 
@@ -288,7 +290,7 @@
 			}
 #undef M
 
-			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
+			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
 			if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
 				if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
@@ -352,7 +354,7 @@
 			if (!IsLevelCrossing(tile) ||
 					GetCrossingRailBits(tile) != trackbit ||
 					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
-					!EnsureNoVehicle(tile)) {
+					!EnsureNoVehicleOnGround(tile)) {
 				return CMD_ERROR;
 			}
 
@@ -368,7 +370,7 @@
 
 			if (!IsPlainRailTile(tile) ||
 					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
-					!EnsureNoVehicle(tile)) {
+					!EnsureNoVehicleOnGround(tile)) {
 				return CMD_ERROR;
 			}
 
@@ -436,11 +438,11 @@
 
 	if (!ValParamTrackOrientation(TrackdirToTrack(*trackdir))) return CMD_ERROR;
 
-	// calculate delta x,y from start to end tile
+	/* calculate delta x,y from start to end tile */
 	dx = ex - x;
 	dy = ey - y;
 
-	// calculate delta x,y for the first direction
+	/* calculate delta x,y for the first direction */
 	trdx = _trackdelta[*trackdir].x;
 	trdy = _trackdelta[*trackdir].y;
 
@@ -449,7 +451,7 @@
 		trdy += _trackdelta[*trackdir ^ 1].y;
 	}
 
-	// validate the direction
+	/* validate the direction */
 	while (
 		(trdx <= 0 && dx > 0) ||
 		(trdx >= 0 && dx < 0) ||
@@ -465,8 +467,8 @@
 		}
 	}
 
-	// (for diagonal tracks, this is already made sure of by above test), but:
-	// for non-diagonal tracks, check if the start and end tile are on 1 line
+	/* (for diagonal tracks, this is already made sure of by above test), but:
+	 * for non-diagonal tracks, check if the start and end tile are on 1 line */
 	if (!IsDiagonalTrackdir(*trackdir)) {
 		trdx = _trackdelta[*trackdir].x;
 		trdy = _trackdelta[*trackdir].y;
@@ -519,7 +521,7 @@
 
 		tile += ToTileIndexDiff(_trackdelta[trackdir]);
 
-		// toggle railbit for the non-diagonal tracks
+		/* toggle railbit for the non-diagonal tracks */
 		if (!IsDiagonalTrackdir(trackdir)) ToggleBitT(trackdir, 0);
 	}
 
@@ -627,7 +629,7 @@
 	SignalVariant sigvar = (pre_signal ^ HASBIT(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC;
 	int32 cost;
 
-	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
+	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicleOnGround(tile))
 		return CMD_ERROR;
 
 	/* Protect against invalid signal copying */
@@ -653,35 +655,35 @@
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
 	if (!HasSignalOnTrack(tile, track)) {
-		// build new signals
+		/* build new signals */
 		cost = _eco->GetPrice(CEconomy::BUILD_SIGNALS);
 	} else {
 		if (p2 != 0 && sigvar != GetSignalVariant(tile)) {
-			// convert signals <-> semaphores
+			/* convert signals <-> semaphores */
 			cost = _eco->GetPrice(CEconomy::BUILD_SIGNALS) + _eco->GetPrice(CEconomy::REMOVE_SIGNALS);
 		} else {
-			// it is free to change orientation/pre-exit-combo signals
+			/* it is free to change orientation/pre-exit-combo signals */
 			cost = 0;
 		}
 	}
 
 	if (flags & DC_EXEC) {
 		if (!HasSignals(tile)) {
-			// there are no signals at all on this tile yet
+			/* there are no signals at all on this tile yet */
 			SetHasSignals(tile, true);
 			_m[tile].m2 |= 0xF0;              // all signals are on
-			_m[tile].m3 &= ~0xF0;          // no signals built by default
+			_m[tile].m3 &= ~0xF0;             // no signals built by default
 			SetSignalType(tile, SIGTYPE_NORMAL);
 			SetSignalVariant(tile, sigvar);
 		}
 
 		if (p2 == 0) {
 			if (!HasSignalOnTrack(tile, track)) {
-				// build new signals
+				/* build new signals */
 				_m[tile].m3 |= SignalOnTrack(track);
 			} else {
 				if (pre_signal) {
-					// cycle between normal -> pre -> exit -> combo -> ...
+					/* cycle between normal -> pre -> exit -> combo -> ... */
 					SignalType type = GetSignalType(tile);
 
 					SetSignalType(tile, type == SIGTYPE_COMBO ? SIGTYPE_NORMAL : (SignalType)(type + 1));
@@ -745,12 +747,12 @@
 
 	track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */
 
-	// copy the signal-style of the first rail-piece if existing
+	/* copy the signal-style of the first rail-piece if existing */
 	if (HasSignals(tile)) {
 		signals = _m[tile].m3 & SignalOnTrack(track);
 		if (signals == 0) signals = SignalOnTrack(track); /* Can this actually occur? */
 
-		// copy signal/semaphores style (independent of CTRL)
+		/* copy signal/semaphores style (independent of CTRL) */
 		semaphores = GetSignalVariant(tile) != SIG_ELECTRIC;
 	} else { // no signals exist, drag a two-way signal stretch
 		signals = SignalOnTrack(track);
@@ -766,7 +768,7 @@
 	 * remove     - 1 remove signals, 0 build signals */
 	signal_ctr = total_cost = 0;
 	for (;;) {
-		// only build/remove signals with the specified density
+		/* only build/remove signals with the specified density */
 		if (signal_ctr % signal_density == 0) {
 			uint32 p1 = GB(TrackdirToTrack(trackdir), 0, 3);
 			SB(p1, 3, 1, mode);
@@ -785,7 +787,7 @@
 		tile += ToTileIndexDiff(_trackdelta[trackdir]);
 		signal_ctr++;
 
-		// toggle railbit for the non-diagonal tracks (|, -- tracks)
+		/* toggle railbit for the non-diagonal tracks (|, -- tracks) */
 		if (!IsDiagonalTrackdir(trackdir)) ToggleBitT(trackdir, 0);
 	}
 
@@ -814,7 +816,7 @@
 
 	if (!ValParamTrackOrientation(track) ||
 			!IsTileType(tile, MP_RAILWAY) ||
-			!EnsureNoVehicle(tile) ||
+			!EnsureNoVehicleOnGround(tile) ||
 			!HasSignalOnTrack(tile, track)) {
 		return CMD_ERROR;
 	}
@@ -871,17 +873,17 @@
 
 	if (GetRailType(tile) == totype) return CMD_ERROR;
 
-	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
+	if (!EnsureNoVehicleOnGround(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
 
-	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
+	/* 'hidden' elrails can't be downgraded to normal rail when elrails are disabled */
 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
 
-	// change type.
+	/* change type. */
 	if (exec) {
 		SetRailType(tile, totype);
 		MarkTileDirtyByTile(tile);
 
-		// notify YAPF about the track layout change
+		/* notify YAPF about the track layout change */
 		TrackBits tracks = GetTrackBits(tile);
 		while (tracks != TRACK_BIT_NONE) {
 			YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
@@ -927,7 +929,7 @@
 	if (!ValParamRailtype(p2)) return CMD_ERROR;
 	if (p1 >= MapSize()) return CMD_ERROR;
 
-	// make sure sx,sy are smaller than ex,ey
+	/* make sure sx,sy are smaller than ex,ey */
 	ex = TileX(tile);
 	ey = TileY(tile);
 	sx = TileX(p1);
@@ -975,7 +977,7 @@
 	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
 		return CMD_ERROR;
 
-	if (!EnsureNoVehicle(tile))
+	if (!EnsureNoVehicleOnGround(tile))
 		return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
@@ -1192,7 +1194,7 @@
 	SpriteID pal = PAL_NONE;
 	bool junction = false;
 
-	// Select the sprite to use.
+	/* Select the sprite to use. */
 	(image = rti->base_sprites.track_y, track == TRACK_BIT_Y) ||
 	(image++,                           track == TRACK_BIT_X) ||
 	(image++,                           track == TRACK_BIT_UPPER) ||
@@ -1216,8 +1218,8 @@
 
 		if (foundation != 0) DrawFoundation(ti, foundation);
 
-		// DrawFoundation() modifies ti.
-		// Default sloped sprites..
+		/* DrawFoundation() modifies it.
+		 * Default sloped sprites.. */
 		if (ti->tileh != SLOPE_FLAT)
 			image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
 	}
@@ -1230,7 +1232,7 @@
 
 	DrawGroundSprite(image, pal);
 
-	// Draw track pieces individually for junction tiles
+	/* Draw track pieces individually for junction tiles */
 	if (junction) {
 		if (track & TRACK_BIT_X)     DrawGroundSprite(rti->base_sprites.single_y, PAL_NONE);
 		if (track & TRACK_BIT_Y)     DrawGroundSprite(rti->base_sprites.single_x, PAL_NONE);
@@ -1292,7 +1294,7 @@
 
 		if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
 	} else {
-		// draw depot/waypoint
+		/* draw depot/waypoint */
 		const DrawTileSprites* dts;
 		const DrawTileSeqStruct* dtss;
 		uint32 relocation;
@@ -1307,8 +1309,8 @@
 			image = dts->ground_sprite;
 			if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset;
 
-			// adjust ground tile for desert
-			// don't adjust for snow, because snow in depots looks weird
+			/* adjust ground tile for desert
+			 * don't adjust for snow, because snow in depots looks weird */
 			if (IsSnowRailGround(ti->tile) && _opt.landscape == LT_TROPIC) {
 				if (image != SPR_FLAT_GRASS_TILE) {
 					image += rti->snow_offset; // tile with tracks
@@ -1317,12 +1319,12 @@
 				}
 			}
 		} else {
-			// look for customization
+			/* look for customization */
 			byte stat_id = GetWaypointByTile(ti->tile)->stat_id;
 			const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, stat_id);
 
 			if (statspec != NULL) {
-				// emulate station tile - open with building
+				/* emulate station tile - open with building */
 				const Station* st = ComposeWaypointStation(ti->tile);
 				uint gfx = 2;
 
@@ -1352,7 +1354,7 @@
 				}
 			} else {
 default_waypoint:
-				// There is no custom layout, fall back to the default graphics
+				/* There is no custom layout, fall back to the default graphics */
 				dts = &_waypoint_gfx_table[GetWaypointAxis(ti->tile)];
 				relocation = 0;
 				image = dts->ground_sprite + rti->total_offset;
@@ -1377,7 +1379,7 @@
 				image += relocation;
 			}
 
-			if (_display_opt & DO_TRANS_BUILDINGS) {
+			if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
 				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
 				pal = PALETTE_TO_TRANSPARENT;
 			} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
@@ -1439,15 +1441,15 @@
 	bool stop;
 	bool has_presignal;
 
-	// presignal info
+	/* presignal info */
 	int presignal_exits;
 	int presignal_exits_free;
 
-	// these are used to keep track of the signals that change.
+	/* these are used to keep track of the signals that change. */
 	TrackdirByte bit[NUM_SSD_ENTRY];
 	TileIndex tile[NUM_SSD_ENTRY];
 
-	// these are used to keep track of the stack that modifies presignals recursively
+	/* these are used to keep track of the stack that modifies presignals recursively */
 	TileIndex next_tile[NUM_SSD_STACK];
 	DiagDirectionByte next_dir[NUM_SSD_STACK];
 
@@ -1459,22 +1461,22 @@
 
 	if (!IsTileType(tile, MP_RAILWAY)) return false;
 
-	// the tile has signals?
+	/* the tile has signals? */
 	if (HasSignalOnTrack(tile, TrackdirToTrack(trackdir))) {
 		if (HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
-			// yes, add the signal to the list of signals
+			/* yes, add the signal to the list of signals */
 			if (ssd->cur != NUM_SSD_ENTRY) {
 				ssd->tile[ssd->cur] = tile; // remember the tile index
 				ssd->bit[ssd->cur] = trackdir; // and the controlling bit number
 				ssd->cur++;
 			}
 
-			// remember if this block has a presignal.
+			/* remember if this block has a presignal. */
 			ssd->has_presignal |= IsPresignalEntry(tile);
 		}
 
 		if (HasSignalOnTrackdir(tile, trackdir) && IsPresignalExit(tile)) {
-			// this is an exit signal that points out from the segment
+			/* this is an exit signal that points out from the segment */
 			ssd->presignal_exits++;
 			if (GetSignalStateByTrackdir(tile, trackdir) != SIGNAL_STATE_RED)
 				ssd->presignal_exits_free++;
@@ -1532,21 +1534,21 @@
 
 		dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible)
 
-		// check for a vehicle with that trackdir on the start tile of the tunnel
+		/* check for a vehicle with that trackdir on the start tile of the tunnel */
 		if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) return true;
 
-		// check for a vehicle with that trackdir on the end tile of the tunnel
+		/* check for a vehicle with that trackdir on the end tile of the tunnel */
 		if (VehicleFromPos(end, &dest, SignalVehicleCheckProc) != NULL) return true;
 
-		// now check all tiles from start to end for a warping vehicle
-		// NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile?
+		/* now check all tiles from start to end for a warping vehicle
+		 * NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile? */
 		dest.track = 0x40;   //Vehicle inside a tunnel or on a bridge
 		for (; tile != end; tile += TileOffsByDiagDir(direction)) {
 			if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL)
 				return true;
 		}
 
-		// no vehicle found
+		/* no vehicle found */
 		return false;
 	}
 
@@ -1601,39 +1603,39 @@
 {
 	int i;
 
-	// thinking about presignals...
-	// the presignal is green if,
-	//   if no train is in the segment AND
-	//   there is at least one green exit signal OR
-	//   there are no exit signals in the segment
+	/* thinking about presignals...
+	 * the presignal is green if,
+	 *   if no train is in the segment AND
+	 *   there is at least one green exit signal OR
+	 *   there are no exit signals in the segment */
 
-	// then mark the signals in the segment accordingly
+	/* then mark the signals in the segment accordingly */
 	for (i = 0; i != ssd->cur; i++) {
 		TileIndex tile = ssd->tile[i];
 		byte bit = SignalAgainstTrackdir(ssd->bit[i]);
 		uint16 m2 = _m[tile].m2;
 
-		// presignals don't turn green if there is at least one presignal exit and none are free
+		/* presignals don't turn green if there is at least one presignal exit and none are free */
 		if (IsPresignalEntry(tile)) {
 			int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
 
-			// subtract for dual combo signals so they don't count themselves
+			/* subtract for dual combo signals so they don't count themselves */
 			if (IsPresignalExit(tile) && HasSignalOnTrackdir(tile, ssd->bit[i])) {
 				ex--;
 				if (GetSignalStateByTrackdir(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--;
 			}
 
-			// if we have exits and none are free, make red.
+			/* if we have exits and none are free, make red. */
 			if (ex && !exfree) goto make_red;
 		}
 
-		// check if the signal is unaffected.
+		/* check if the signal is unaffected. */
 		if (ssd->stop) {
 make_red:
-			// turn red
+			/* turn red */
 			if ((bit & m2) == 0) continue;
 		} else {
-			// turn green
+			/* turn green */
 			if ((bit & m2) != 0) continue;
 		}
 
@@ -1648,7 +1650,7 @@
 			}
 		}
 
-		// it changed, so toggle it
+		/* it changed, so toggle it */
 		_m[tile].m2 = m2 ^ bit;
 		MarkTileDirtyByTile(tile);
 	}
@@ -1663,23 +1665,23 @@
 	ssd.cur_stack = 0;
 
 	for (;;) {
-		// go through one segment and update all signals pointing into that segment.
+		/* go through one segment and update all signals pointing into that segment. */
 		ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
 		ssd.has_presignal = false;
 
 		FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, SetSignalsEnumProc, SetSignalsAfterProc, &ssd);
 		ChangeSignalStates(&ssd);
 
-		// remember the result only for the first iteration.
+		/* remember the result only for the first iteration. */
 		if (result < 0) {
-			// stay in depot while segment is occupied or while all presignal exits are blocked
+			/* stay in depot while segment is occupied or while all presignal exits are blocked */
 			result = ssd.stop || (ssd.presignal_exits > 0 && ssd.presignal_exits_free == 0);
 		}
 
-		// if any exit signals were changed, we need to keep going to modify the stuff behind those.
+		/* if any exit signals were changed, we need to keep going to modify the stuff behind those. */
 		if (ssd.cur_stack == 0) break;
 
-		// one or more exit signals were changed, so we need to update another segment too.
+		/* one or more exit signals were changed, so we need to update another segment too. */
 		tile = ssd.next_tile[--ssd.cur_stack];
 		direction = ssd.next_dir[ssd.cur_stack];
 	}
@@ -1772,7 +1774,7 @@
 
 	new_ground = RAIL_GROUND_GRASS;
 
-	if (old_ground != RAIL_GROUND_BARREN) { /* wait until bottom is green */
+	if (old_ground != RAIL_GROUND_BARREN) { // wait until bottom is green
 		/* determine direction of fence */
 		TrackBits rail = GetTrackBits(tile);
 
@@ -1966,7 +1968,7 @@
 	DiagDirection dir;
 	int length;
 
-	// this routine applies only to trains in depot tiles
+	/* this routine applies only to trains in depot tiles */
 	if (v->type != VEH_TRAIN || !IsTileDepotType(tile, TRANSPORT_RAIL)) return VETSB_CONTINUE;
 
 	/* depot direction */