summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-03-08 08:16:31 +0000
committertron <tron@openttd.org>2006-03-08 08:16:31 +0000
commitfa6632ec3240c1407668f55169d316c1c4b6bd45 (patch)
treed22cc6ddd9856b7d1f71491480efca03c24ec3c9
parentf0d82204e072437212b5f5a0dd699443346913a5 (diff)
downloadopenttd-fa6632ec3240c1407668f55169d316c1c4b6bd45.tar.xz
(svn r3786) More work for DirDiff
-rw-r--r--aircraft_cmd.c9
-rw-r--r--disaster_cmd.c2
-rw-r--r--roadveh_cmd.c8
-rw-r--r--train_cmd.c9
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);