980 return 0; |
980 return 0; |
981 } |
981 } |
982 return 0; |
982 return 0; |
983 } |
983 } |
984 |
984 |
|
985 /** |
|
986 * @retval 0 The vehicle can proceed |
|
987 * @retval 4 The vehicle changed onto of off the bridge (depending on the |
|
988 * status before, check with v->u.rail.track == 0x40) |
|
989 * @retval 8 The vehicle cannot enter the tile |
|
990 */ |
985 static uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y) |
991 static uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y) |
986 { |
992 { |
987 int z = GetSlopeZ(x, y) - v->z_pos; |
993 int z = GetSlopeZ(x, y) - v->z_pos; |
988 |
994 |
989 DiagDirection dir; |
995 DiagDirection dir; |
1002 uint16 spd = _bridge[GetBridgeType(tile)].speed; |
1008 uint16 spd = _bridge[GetBridgeType(tile)].speed; |
1003 if (v->cur_speed > spd) v->cur_speed = spd; |
1009 if (v->cur_speed > spd) v->cur_speed = spd; |
1004 } |
1010 } |
1005 |
1011 |
1006 dir = GetBridgeRampDirection(tile); |
1012 dir = GetBridgeRampDirection(tile); |
1007 if (DirToDiagDir(v->direction) == dir || |
1013 |
1008 (IsTileType(tile, MP_RAILWAY_BRIDGE) && DirToDiagDir(v->direction) != ReverseDiagDir(dir))) { |
1014 /* We are entering the bridge head from the bridge itself */ |
|
1015 if (v->direction == DiagDirToDir(ReverseDiagDir(dir))) { |
|
1016 v->tile = tile; |
|
1017 if (v->u.rail.track == 0x40) { |
|
1018 /* Get the vehicle out of the wormhole, the track will be chosen later |
|
1019 by the pathfinder */ |
|
1020 v->u.rail.track = 0; |
|
1021 return 4; |
|
1022 } |
|
1023 return 0; |
|
1024 |
|
1025 /* We are on the bridge head itself */ |
|
1026 } else { |
1009 switch (dir) { |
1027 switch (dir) { |
1010 default: NOT_REACHED(); |
1028 default: NOT_REACHED(); |
|
1029 /* Should any of these ifs be true, we're not near the edge which |
|
1030 faces the bridge body. In that case, do nothing */ |
1011 case DIAGDIR_NE: if ((x & 0xF) != 0) return 0; break; |
1031 case DIAGDIR_NE: if ((x & 0xF) != 0) return 0; break; |
1012 case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break; |
1032 case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break; |
1013 case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break; |
1033 case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break; |
1014 case DIAGDIR_NW: if ((y & 0xF) != 0) return 0; break; |
1034 case DIAGDIR_NW: if ((y & 0xF) != 0) return 0; break; |
1015 } |
1035 } |
|
1036 |
|
1037 /* We're about to enter the bridge body, clear all up/down flags just in case */ |
1016 v->u.rail.track = 0x40; |
1038 v->u.rail.track = 0x40; |
|
1039 v->direction = DiagDirToDir(dir); |
1017 CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
1040 CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
1018 CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
1041 CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
1019 return 4; |
1042 return 4; |
1020 } else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) { |
|
1021 v->tile = tile; |
|
1022 if (v->u.rail.track == 0x40) { |
|
1023 v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2); |
|
1024 return 4; |
|
1025 } |
|
1026 return 0; |
|
1027 } |
1043 } |
1028 return 0; |
1044 return 0; |
1029 } |
1045 } |
1030 |
1046 |
1031 static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y) |
1047 static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y) |