(svn r5070) Merged the bridge branch

-Feature: Bridges can now be placed above:
	Any railway track combination (excluding depots and waypoints)
	Any road combination (excluding depots)
	Clear tiles (duh), including fields
	Tunnel entrances
	Bridge heads

Thanks to Tron for idea and implementation, KUDr for the yapf synchronization and many others for hours of testing

There are still a number of visual problems remaining, especially when electric railways are on or under the bridge.
DO NOT REPORT THOSE BUGS FOR THE TIME BEING please.
This commit is contained in:
celestar
2006-06-02 13:05:41 +00:00
parent d680fcec77
commit 25a63ec7af
33 changed files with 776 additions and 981 deletions

View File

@@ -25,6 +25,7 @@
#include "waypoint.h"
#include "vehicle_gui.h"
#include "train.h"
#include "bridge.h"
#include "newgrf_callbacks.h"
#include "newgrf_engine.h"
#include "newgrf_text.h"
@@ -91,10 +92,7 @@ void TrainPowerChanged(Vehicle* v)
/* Power is not added for articulated parts */
if (IsArticulatedPart(u)) continue;
if (IsBridgeTile(u->tile) && IsBridgeMiddle(u->tile) && DiagDirToAxis(DirToDiagDir(u->direction)) == GetBridgeAxis(u->tile)) {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeOnBridge(u->tile))) engine_has_power = false;
if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeOnBridge(u->tile))) wagon_has_power = false;
} else if (IsLevelCrossingTile(u->tile)) {
if (IsLevelCrossingTile(u->tile)) {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeCrossing(u->tile))) engine_has_power = false;
if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeCrossing(u->tile))) wagon_has_power = false;
} else {
@@ -1529,13 +1527,14 @@ static void ReverseTrainSwapVeh(Vehicle *v, int l, int r)
UpdateVarsAfterSwap(a);
UpdateVarsAfterSwap(b);
VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
VehicleEnterTile(b, b->tile, b->x_pos, b->y_pos);
/* call the proper EnterTile function unless we are in a wormhole */
if (!(a->u.rail.track & 0x40)) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
if (!(b->u.rail.track & 0x40)) VehicleEnterTile(b, b->tile, b->x_pos, b->y_pos);
} else {
if (!(a->u.rail.track & 0x80)) a->direction = ReverseDir(a->direction);
UpdateVarsAfterSwap(a);
VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
if (!(a->u.rail.track & 0x40)) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
}
/* Update train's power incase tiles were different rail type */
@@ -1848,8 +1847,6 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v, int max_distance)
return tfdd;
}
if (v->u.rail.track == 0x40) tile = GetVehicleOutOfTunnelTile(v);
if (_patches.yapf.rail_use_yapf) {
bool found = YapfFindNearestRailDepotTwoWay(v, max_distance, NPF_INFINITE_PENALTY, &tfdd.tile, &tfdd.reverse);
tfdd.best_length = found ? max_distance / 2 : -1; // some fake distance or NOT_FOUND
@@ -2567,9 +2564,7 @@ static byte AfterSetTrainPos(Vehicle *v, bool new_tile)
byte new_z, old_z;
// need this hint so it returns the right z coordinate on bridges.
_get_z_hint = v->z_pos;
new_z = GetSlopeZ(v->x_pos, v->y_pos);
_get_z_hint = 0;
old_z = v->z_pos;
v->z_pos = new_z;
@@ -2645,13 +2640,6 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
// normal tracks, jump to owner check
break;
case MP_TUNNELBRIDGE:
if (IsBridge(tile) && IsBridgeMiddle(tile)) {
// is train going over the bridge?
if (v->z_pos > GetTileMaxZ(tile)) return true;
}
break;
case MP_STREET:
// tracks over roads, do owner check of tracks
return
@@ -2992,15 +2980,16 @@ static void TrainController(Vehicle *v)
v->direction = chosen_dir;
}
} else {
/* in tunnel */
/* in tunnel on on a bridge */
GetNewVehiclePos(v, &gp);
// Check if to exit the tunnel...
if (!IsTunnelTile(gp.new_tile) ||
!(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&0x4) ) {
SetSpeedLimitOnBridge(v);
if (!(IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) || !(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 0x4)) {
v->x_pos = gp.x;
v->y_pos = gp.y;
VehiclePositionChanged(v);
if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v);
continue;
}
}
@@ -3097,7 +3086,7 @@ static void DeleteLastWagon(Vehicle *v)
* others are on it */
DisableTrainCrossing(v->tile);
if (v->u.rail.track == 0x40) { // inside a tunnel
if ( (v->u.rail.track == 0x40 && v->vehstatus & VS_HIDDEN) ) { // inside a tunnel
TileIndex endtile = CheckTunnelBusy(v->tile, NULL);
if (endtile == INVALID_TILE) return; // tunnel is busy (error returned)
@@ -3128,15 +3117,16 @@ static void ChangeTrainDirRandomly(Vehicle *v)
};
do {
//I need to buffer the train direction
if (!(v->u.rail.track & 0x40)) {
v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]);
}
/* We don't need to twist around vehicles if they're not visible */
if (!(v->vehstatus & VS_HIDDEN)) {
v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]);
BeginVehicleMove(v);
UpdateTrainDeltaXY(v, v->direction);
v->cur_image = GetTrainImage(v, v->direction);
AfterSetTrainPos(v, false);
/* Refrain from updating the z position of the vehicle when on
a bridge, because AfterSetTrainPos will put the vehicle under
the bridge in that case */
if (!(v->u.rail.track & 0x40)) AfterSetTrainPos(v, false);
}
} while ((v = v->next) != NULL);
}
@@ -3147,7 +3137,7 @@ static void HandleCrashedTrain(Vehicle *v)
uint32 r;
Vehicle *u;
if (state == 4 && v->u.rail.track != 0x40) {
if (state == 4 && !(v->u.rail.track & VS_HIDDEN)) {
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
}
@@ -3234,10 +3224,15 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
tile = v->tile;
// tunnel entrance?
if (IsTunnelTile(tile) &&
DiagDirToDir(GetTunnelDirection(tile)) == v->direction) {
return true;
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
DiagDirection dir;
if (IsTunnel(tile)) {
dir = GetTunnelDirection(tile);
} else {
dir = GetBridgeRampDirection(tile);
}
if (DiagDirToDir(dir) == v->direction) return true;
}
// depot?