diff options
author | smatz <smatz@openttd.org> | 2008-01-13 23:53:33 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2008-01-13 23:53:33 +0000 |
commit | a9f69f387d6a4b869d0f0985d92bb19cd0743849 (patch) | |
tree | 6349e4140d7f2c5454c8e5306ae9774979db5690 /src | |
parent | 88e16866bc8e5ee2e1e99dc89514f012ddf1972a (diff) | |
download | openttd-a9f69f387d6a4b869d0f0985d92bb19cd0743849.tar.xz |
(svn r11845) -Codechange: simplify train collision detection a bit
Diffstat (limited to 'src')
-rw-r--r-- | src/train_cmd.cpp | 20 |
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 */ |