3013 } |
3013 } |
3014 } |
3014 } |
3015 |
3015 |
3016 static void ChangeTrainDirRandomly(Vehicle *v) |
3016 static void ChangeTrainDirRandomly(Vehicle *v) |
3017 { |
3017 { |
3018 static const int8 _random_dir_change[4] = { -1, 0, 0, 1 }; |
3018 static const DirDiff delta[] = { |
|
3019 DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
|
3020 }; |
3019 |
3021 |
3020 do { |
3022 do { |
3021 //I need to buffer the train direction |
3023 //I need to buffer the train direction |
3022 if (!(v->u.rail.track & 0x40)) |
3024 if (!(v->u.rail.track & 0x40)) { |
3023 v->direction = (v->direction + _random_dir_change[GB(Random(), 0, 2)]) & 7; |
3025 v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]); |
|
3026 } |
3024 if (!(v->vehstatus & VS_HIDDEN)) { |
3027 if (!(v->vehstatus & VS_HIDDEN)) { |
3025 BeginVehicleMove(v); |
3028 BeginVehicleMove(v); |
3026 UpdateTrainDeltaXY(v, v->direction); |
3029 UpdateTrainDeltaXY(v, v->direction); |
3027 v->cur_image = GetTrainImage(v, v->direction); |
3030 v->cur_image = GetTrainImage(v, v->direction); |
3028 AfterSetTrainPos(v, false); |
3031 AfterSetTrainPos(v, false); |