Loading

Revision differences

Old revision #p13ckykxjNew revision #phdne9rqy
27  27  
28        /* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */  28        /* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */  
29        uint distance = DistanceSquare(vtile, st->airport.tile);  29        uint distance = DistanceSquare(vtile, st->airport.tile);  
30        if (v->acache.cached_max_range_sqr != 0) {  30        uint max_range = v->acache.cached_max_range_sqr;
   31        if (max_range != 0) {
31            /* Determine destinations */  32            /* Determine destinations */  
32            const Station *cur_dest = GetTargetAirportIfValid(v);  33            const Station *cur_dest = GetTargetAirportIfValid(v);  
33            const Station *next_dest;  34            const Station *next_dest;  
  
40            }  41            }  
41  42  
42            /* Check if our current and next (or previous) destinations can be reached from the depot airport. */  43            /* Check if our current and next (or previous) destinations can be reached from the depot airport. */  
43            if (next_dest != NULL && next_dest->airport.tile != INVALID_TILE && cur_dest != NULL) {  43            uint cur_dist = cur_dest != NULL ? DistanceSquare(st->airport.tile, cur_dest->airport.tile) : UINT_MAX;
44                if (DistanceSquare(st->airport.tile, next_dest->airport.tile) > v->acache.cached_max_range_sqr ||  44            uint next_dist = next_dest != NULL || next_dest->airport.tile != INVALID_TILE ? DistanceSquare(st->airport.tile, next_dest->airport.tile) : UINT_MAX;
45                    DistanceSquare(st->airport.tile, cur_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;  45            if (cur_dist != UINT_MAX && next_dist != UINT_MAX && (cur_dist > max_range || next_dist > max_range)) continue;
46            } else if (next_dest != NULL && next_dest->airport.tile != INVALID_TILE && cur_dest == NULL) {  46            if (cur_dist != UINT_MAX && next_dist == UINT_MAX && cur_dist > max_range) continue;
47                if (DistanceSquare(st->airport.tile, next_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;  47            if (cur_dist == UINT_MAX && next_dist != UINT_MAX && next_dist > max_range) continue;
48            } else if ((next_dest == NULL || next_dest->airport.tile == INVALID_TILE) && cur_dest != NULL) {    
49                if (DistanceSquare(st->airport.tile, cur_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;    
50            }    
51        }  49        }  
52        if (distance < best || index == INVALID_STATION) {  50        if (distance < best || index == INVALID_STATION) {  
53            best = distance;  51            best = distance;