1
0
Fork 0

Codechange: Always return the first vehicle when looking for close road vehicles.

pull/8480/head
J0anJosep 2021-11-13 19:02:29 +01:00
parent c270cebb59
commit d9b182df78
1 changed files with 9 additions and 4 deletions

View File

@ -714,6 +714,8 @@ static RoadVehicle *RoadVehFindCloseTo(RoadVehicle *v, int x, int y, Direction d
if (update_blocked_ctr && ++front->blocked_ctr > 1480) return nullptr; if (update_blocked_ctr && ++front->blocked_ctr > 1480) return nullptr;
rvf.best = rvf.best->First();
return RoadVehicle::From(rvf.best); return RoadVehicle::From(rvf.best);
} }
@ -1202,7 +1204,8 @@ bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
if (v->IsFrontEngine()) { if (v->IsFrontEngine()) {
const Vehicle *u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction); const Vehicle *u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction);
if (u != nullptr) { if (u != nullptr) {
v->cur_speed = u->First()->cur_speed; assert(u == u->First());
v->cur_speed = u->cur_speed;
return false; return false;
} }
} }
@ -1320,7 +1323,8 @@ again:
if (v->IsFrontEngine()) { if (v->IsFrontEngine()) {
const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
if (u != nullptr) { if (u != nullptr) {
v->cur_speed = u->First()->cur_speed; assert(u == u->First());
v->cur_speed = u->cur_speed;
/* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */ /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */
v->path.tile.push_front(tile); v->path.tile.push_front(tile);
v->path.td.push_front(dir); v->path.td.push_front(dir);
@ -1436,7 +1440,8 @@ again:
if (v->IsFrontEngine()) { if (v->IsFrontEngine()) {
const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
if (u != nullptr) { if (u != nullptr) {
v->cur_speed = u->First()->cur_speed; assert(u == u->First());
v->cur_speed = u->cur_speed;
/* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */ /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */
v->path.tile.push_front(v->tile); v->path.tile.push_front(v->tile);
v->path.td.push_front(dir); v->path.td.push_front(dir);
@ -1486,7 +1491,7 @@ again:
RoadVehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); RoadVehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
if (u != nullptr) { if (u != nullptr) {
u = u->First(); assert(u == u->First());
/* There is a vehicle in front overtake it if possible */ /* There is a vehicle in front overtake it if possible */
if (v->overtaking == 0) RoadVehCheckOvertake(v, u); if (v->overtaking == 0) RoadVehCheckOvertake(v, u);
if (v->overtaking == 0) v->cur_speed = u->cur_speed; if (v->overtaking == 0) v->cur_speed = u->cur_speed;