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

Method Increment

src/tilearea.cpp:365–399  ·  view source on GitHub ↗

* Advance the internal state to the next potential tile. * The tile may be outside the map though. */

Source from the content-addressed store, hash-verified

363 * The tile may be outside the map though.
364 */
365void SpiralTileIterator::Increment()
366{
367 assert(!this->IsEnd());
368
369 /* Special value for first tile in areas with odd diameter */
370 if (this->dir == INVALID_DIAGDIR) {
371 const auto west = TileIndexDiffCByDir(DIR_W);
372 this->x += west.x;
373 this->y += west.y;
374 this->dir = DIAGDIR_BEGIN;
375 this->InitPosition();
376 return;
377 }
378
379 /* Step to the next 'neighbour' in the circular line */
380 const auto diff = TileIndexDiffCByDiagDir(this->dir);
381 this->x += diff.x;
382 this->y += diff.y;
383 --this->position;
384 if (this->position > 0) return;
385
386 /* Corner reached, switch direction */
387 ++this->dir;
388
389 if (this->dir == DIAGDIR_END) {
390 /* Jump to next circle */
391 const auto west = TileIndexDiffCByDir(DIR_W);
392 this->x += west.x;
393 this->y += west.y;
394 ++this->cur_radius;
395 this->dir = DIAGDIR_BEGIN;
396 }
397
398 this->InitPosition();
399}

Callers 2

SkipOutsideMapMethod · 0.95
SpiralTileIteratorClass · 0.95

Calls 4

IsEndMethod · 0.95
InitPositionMethod · 0.95
TileIndexDiffCByDirFunction · 0.85
TileIndexDiffCByDiagDirFunction · 0.85

Tested by

no test coverage detected