From 03536a32a189918713ec808bf270d4ad853a7a38 Mon Sep 17 00:00:00 2001 From: tron Date: Wed, 8 Mar 2006 08:16:31 +0000 Subject: (svn r3786) More work for DirDiff --- aircraft_cmd.c | 9 +++++---- disaster_cmd.c | 2 +- roadveh_cmd.c | 8 ++++++-- train_cmd.c | 9 ++++++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/aircraft_cmd.c b/aircraft_cmd.c index ba1c9ee2b..da812a4bf 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -947,9 +947,6 @@ static bool AircraftController(Vehicle *v) return false; } -static const int8 _crashed_aircraft_moddir[4] = { - -1,0,0,1 -}; static void HandleCrashedAircraft(Vehicle *v) { @@ -973,7 +970,11 @@ static void HandleCrashedAircraft(Vehicle *v) if (v->u.air.crashed_counter < 650) { if (CHANCE16R(1,32,r)) { - v->direction = (v->direction + _crashed_aircraft_moddir[GB(r, 16, 2)]) & 7; + static const DirDiff delta[] = { + DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT + }; + + v->direction = ChangeDir(v->direction, delta[GB(r, 16, 2)]); SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos); r = Random(); CreateEffectVehicleRel(v, diff --git a/disaster_cmd.c b/disaster_cmd.c index 61590c47a..d053ff199 100644 --- a/disaster_cmd.c +++ b/disaster_cmd.c @@ -665,7 +665,7 @@ static void DisasterTick_5_and_6(Vehicle *v) return; } - v->direction = (v->direction + (GB(Random(), 0, 1) ? 2 : -2)) & 7; + v->direction = ChangeDir(v->direction, GB(Random(), 0, 1) ? DIRDIFF_90RIGHT : DIRDIFF_90LEFT); } diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 7a97722ce..6c3d27d69 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -494,9 +494,13 @@ static byte SetRoadVehPosition(Vehicle *v, int x, int y) static void RoadVehSetRandomDirection(Vehicle *v) { - static const int8 _turn_prob[4] = { -1, 0, 0, 1 }; + static const DirDiff delta[] = { + DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT + }; + uint32 r = Random(); - v->direction = (v->direction + _turn_prob[r & 3]) & 7; + + v->direction = ChangeDir(v->direction, delta[r & 3]); BeginVehicleMove(v); UpdateRoadVehDeltaXY(v); v->cur_image = GetRoadVehImage(v, v->direction); diff --git a/train_cmd.c b/train_cmd.c index 960af695a..88e8881d2 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -3015,12 +3015,15 @@ static void DeleteLastWagon(Vehicle *v) static void ChangeTrainDirRandomly(Vehicle *v) { - static const int8 _random_dir_change[4] = { -1, 0, 0, 1 }; + static const DirDiff delta[] = { + DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT + }; do { //I need to buffer the train direction - if (!(v->u.rail.track & 0x40)) - v->direction = (v->direction + _random_dir_change[GB(Random(), 0, 2)]) & 7; + if (!(v->u.rail.track & 0x40)) { + v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]); + } if (!(v->vehstatus & VS_HIDDEN)) { BeginVehicleMove(v); UpdateTrainDeltaXY(v, v->direction); -- cgit v1.2.3-70-g09d2