3012 if (diff == DIRDIFF_90RIGHT || (v->cur_speed <= 5 && diff <= DIRDIFF_REVERSE)) return v; |
3012 if (diff == DIRDIFF_90RIGHT || (v->cur_speed <= 5 && diff <= DIRDIFF_REVERSE)) return v; |
3013 } |
3013 } |
3014 return NULL; |
3014 return NULL; |
3015 } |
3015 } |
3016 |
3016 |
|
3017 /** Puts a train (logically) onto a bridge body. |
|
3018 * Sets the correct coordinates to traverse the bridge |
|
3019 * and aligns the vehicle with the bridge. The function |
|
3020 * assumes the train is on a bridge head about to enter |
|
3021 * the bridge. |
|
3022 */ |
|
3023 static void PutTrainOntoBridge(Vehicle *v) |
|
3024 { |
|
3025 DiagDirection dir; |
|
3026 uint8 dxy; |
|
3027 assert(IsBridgeTile(v->tile)); |
|
3028 dir = GetBridgeRampDirection(v->tile); |
|
3029 v->u.rail.track = 0x40; |
|
3030 v->direction = DiagDirToDir(dir); |
|
3031 CLRBIT(v->u.rail.flags, VRF_GOINGUP); |
|
3032 CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); |
|
3033 |
|
3034 switch (dir) { |
|
3035 default: NOT_REACHED(); |
|
3036 case DIAGDIR_NE: dxy = 0xF8; break; |
|
3037 case DIAGDIR_SE: dxy = 0x80; break; |
|
3038 case DIAGDIR_SW: dxy = 0x08; break; |
|
3039 case DIAGDIR_NW: dxy = 0x8F; break; |
|
3040 } |
|
3041 SB(v->x_pos, 0, 4, GB(dxy, 4, 4)); |
|
3042 SB(v->y_pos, 0, 4, GB(dxy, 0, 4)); |
|
3043 } |
|
3044 |
3017 static void TrainController(Vehicle *v, bool update_image) |
3045 static void TrainController(Vehicle *v, bool update_image) |
3018 { |
3046 { |
3019 Vehicle *prev; |
3047 Vehicle *prev; |
3020 GetNewVehiclePosResult gp; |
3048 GetNewVehiclePosResult gp; |
3021 uint32 r, tracks,ts; |
3049 uint32 r, tracks,ts; |
3075 |
3103 |
3076 /* We should not let the train that is leaving custom bridge head (entering bridge) |
3104 /* We should not let the train that is leaving custom bridge head (entering bridge) |
3077 * to enter the tile that is under bridge. Enter the bridge wormhole instead. */ |
3105 * to enter the tile that is under bridge. Enter the bridge wormhole instead. */ |
3078 if (IsBridgeTile(gp.old_tile) && GetBridgeRampDirection(gp.old_tile) == enterdir) { |
3106 if (IsBridgeTile(gp.old_tile) && GetBridgeRampDirection(gp.old_tile) == enterdir) { |
3079 /* train entering the bridge body */ |
3107 /* train entering the bridge body */ |
3080 extern uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y); |
3108 PutTrainOntoBridge(v); |
3081 VehicleEnter_Railway_Bridge(v, gp.new_tile, gp.x, gp.y); |
|
3082 UpdateTrainDeltaXY(v, v->direction); |
3109 UpdateTrainDeltaXY(v, v->direction); |
3083 if (update_image) v->cur_image = GetTrainImage(v, v->direction); |
3110 if (update_image) v->cur_image = GetTrainImage(v, v->direction); |
3084 continue; |
3111 continue; |
3085 } |
3112 } |
3086 |
3113 |