summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-01-13 23:53:33 +0000
committersmatz <smatz@openttd.org>2008-01-13 23:53:33 +0000
commitbfc4d80c8e548c5bb1f4b3b527498b3dfe840ff9 (patch)
tree6349e4140d7f2c5454c8e5306ae9774979db5690 /src
parent7d2d4314ec7c21cccff7c6a474b221d3d71e5ace (diff)
downloadopenttd-bfc4d80c8e548c5bb1f4b3b527498b3dfe840ff9.tar.xz
(svn r11845) -Codechange: simplify train collision detection a bit
Diffstat (limited to 'src')
-rw-r--r--src/train_cmd.cpp20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index ff14739d9..8d21a029b 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2805,7 +2805,6 @@ static uint CountPassengersInTrain(const Vehicle* v)
struct TrainCollideChecker {
Vehicle *v;
- const Vehicle *v_skip;
uint num;
};
@@ -2813,21 +2812,17 @@ static void *FindTrainCollideEnum(Vehicle *v, void *data)
{
TrainCollideChecker* tcc = (TrainCollideChecker*)data;
- if (v != tcc->v &&
- v != tcc->v_skip &&
- v->type == VEH_TRAIN &&
- v->u.rail.track != TRACK_BIT_DEPOT &&
+ if (v->type != VEH_TRAIN) return NULL;
+
+ /* get first vehicle now to make most usual checks faster */
+ Vehicle *coll = v->First();
+
+ /* can't collide with own wagons && can't crash in depot && not too far */
+ if (coll != tcc->v && v->u.rail.track != TRACK_BIT_DEPOT &&
abs(v->z_pos - tcc->v->z_pos) < 6 &&
abs(v->x_pos - tcc->v->x_pos) < 6 &&
abs(v->y_pos - tcc->v->y_pos) < 6 ) {
- Vehicle *coll = v->First();
-
- /* it can't collide with its own wagons */
- if (tcc->v == coll ||
- (tcc->v->u.rail.track == TRACK_BIT_WORMHOLE && (tcc->v->direction & 2) != (v->direction & 2)))
- return NULL;
-
/* two drivers + passengers killed in train tcc->v (if it was not crashed already) */
if (!(tcc->v->vehstatus & VS_CRASHED)) {
tcc->num += 2 + CountPassengersInTrain(tcc->v);
@@ -2859,7 +2854,6 @@ static void CheckTrainCollision(Vehicle *v)
TrainCollideChecker tcc;
tcc.v = v;
- tcc.v_skip = v->Next();
tcc.num = 0;
/* find colliding vehicles */