MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / Iterator

Method Iterator

src/vehicle.cpp:432–457  ·  view source on GitHub ↗

* Iterator constructor. * Find first vehicle near (x, y). */

Source from the content-addressed store, hash-verified

430 * Find first vehicle near (x, y).
431 */
432VehiclesNearTileXY::Iterator::Iterator(int32_t x, int32_t y, uint max_dist)
433{
434 /* There are no negative tile coordinates */
435 this->pos_rect.left = std::max<int>(0, x - max_dist);
436 this->pos_rect.right = std::max<int>(0, x + max_dist);
437 this->pos_rect.top = std::max<int>(0, y - max_dist);
438 this->pos_rect.bottom = std::max<int>(0, y + max_dist);
439
440 if (2 * max_dist < TILE_HASH_MASK * TILE_SIZE) {
441 /* Hash area to scan */
442 this->hxmin = this->hx = GetTileHash1D(this->pos_rect.left / TILE_SIZE);
443 this->hxmax = GetTileHash1D(this->pos_rect.right / TILE_SIZE);
444 this->hymin = this->hy = GetTileHash1D(this->pos_rect.top / TILE_SIZE);
445 this->hymax = GetTileHash1D(this->pos_rect.bottom / TILE_SIZE);
446 } else {
447 /* Scan all */
448 this->hxmin = this->hx = 0;
449 this->hxmax = TILE_HASH_MASK;
450 this->hymin = this->hy = 0;
451 this->hymax = TILE_HASH_MASK;
452 }
453
454 this->current_veh = _vehicle_tile_hash[ComposeTileHash(this->hx, this->hy)];
455 this->SkipEmptyBuckets();
456 this->SkipFalseMatches();
457}
458
459/**
460 * Advance the internal state to the next potential vehicle.

Callers

nothing calls this directly

Calls 7

SkipEmptyBucketsMethod · 0.95
SkipFalseMatchesMethod · 0.95
GetTileHash1DFunction · 0.85
ComposeTileHashFunction · 0.85
GetTileHashFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85

Tested by

no test coverage detected