--- a/vehicle.c Fri Jun 22 20:06:59 2007 +0000
+++ b/vehicle.c Fri Jun 22 20:08:37 2007 +0000
@@ -36,7 +36,7 @@
#include "newgrf_engine.h"
#include "newgrf_sound.h"
-#define INVALID_COORD (-0x8000)
+#define INVALID_COORD (0x7fffffff)
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6))
/*
@@ -823,17 +823,29 @@
const int b = dpi->top + dpi->height;
// The hash area to scan
- const int xl = GB(l - 70, 7, 6);
- const int xu = GB(r, 7, 6);
- const int yl = GB(t - 70, 6, 6) << 6;
- const int yu = GB(b, 6, 6) << 6;
-
- int x;
- int y;
+ int xl, xu, yl, yu, x, y;
+
+ if (dpi->width + 70 < (1 << (7 + 6))) {
+ xl = GB(l - 70, 7, 6);
+ xu = GB(r, 7, 6);
+ } else {
+ /* scan whole hash row */
+ xl = 0;
+ xu = 0x3F;
+ }
+
+ if (dpi->height + 70 < (1 << (6 + 6))) {
+ yl = GB(t - 70, 6, 6) << 6;
+ yu = GB(b, 6, 6) << 6;
+ } else {
+ /* scan whole column */
+ yl = 0;
+ yu = 0x3F << 6;
+ }
for (y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) {
for (x = xl;; x = (x + 1) & 0x3F) {
- VehicleID veh = _vehicle_position_hash[(x + y) & 0xFFFF];
+ VehicleID veh = _vehicle_position_hash[x + y]; // already masked & 0xFFF
while (veh != INVALID_VEHICLE) {
const Vehicle* v = GetVehicle(veh);