- struct rock_struct **b = bucket(x, y, p);
- int bdx = ((int)x+shape->w)/grid_size - (int)x/grid_size;
- int bdy = ((int)y+shape->h)/grid_size - (int)y/grid_size;
- if(hit_in_bucket(*b, x, y, shape)) return 1;
- if(hit_in_bucket(*(b-1), x, y, shape)) return 1;
- if(hit_in_bucket(*(b-bw), x, y, shape)) return 1;
- if(hit_in_bucket(*(b-bw-1), x, y, shape)) return 1;
-
- if(bdx) {
- if(hit_in_bucket(*(b+1), x, y, shape)) return 1;
- if(hit_in_bucket(*(b+1-bw), x, y, shape)) return 1;
+ int ix, iy;
+ int l, r, t, b;
+ struct rock_struct **bucket;
+
+ ix = x + grid_size; iy = y + grid_size;
+ l = ix / grid_size; r = (ix+shape->w)/grid_size;
+ t = iy / grid_size; b = (iy+shape->h)/grid_size;
+ bucket = &rock_buckets[p][l + t*bw];
+
+ if(hit_in_bucket(*bucket, x, y, shape)) return true;
+ if(l && hit_in_bucket(*(bucket-1), x, y, shape)) return true;
+ if(r && hit_in_bucket(*(bucket-bw), x, y, shape)) return true;
+ if(l && r && hit_in_bucket(*(bucket-(1+bw)), x, y, shape)) return true;
+
+ if(r > l) {
+ if(hit_in_bucket(*(bucket+1), x, y, shape)) return true;
+ if(hit_in_bucket(*(bucket+1-bw), x, y, shape)) return true;