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

Method AfterRemoveTile

src/station.cpp:639–687  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637}
638
639bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
640{
641 int x = TileX(tile);
642 int y = TileY(tile);
643
644 /* look if removed tile was on the bounding rect edge
645 * and try to reduce the rect by this edge
646 * do it until we have empty rect or nothing to do */
647 for (;;) {
648 /* check if removed tile is on rect edge */
649 bool left_edge = (x == this->left);
650 bool right_edge = (x == this->right);
651 bool top_edge = (y == this->top);
652 bool bottom_edge = (y == this->bottom);
653
654 /* can we reduce the rect in either direction? */
655 bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, this->top, x, this->bottom));
656 bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, this->left, y, this->right, y));
657 if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce)
658
659 if (reduce_x) {
660 /* reduce horizontally */
661 if (left_edge) {
662 /* move left edge right */
663 this->left = x = x + 1;
664 } else {
665 /* move right edge left */
666 this->right = x = x - 1;
667 }
668 }
669 if (reduce_y) {
670 /* reduce vertically */
671 if (top_edge) {
672 /* move top edge down */
673 this->top = y = y + 1;
674 } else {
675 /* move bottom edge up */
676 this->bottom = y = y - 1;
677 }
678 }
679
680 if (left > right || top > bottom) {
681 /* can't continue, if the remaining rectangle is empty */
682 this->MakeEmpty();
683 return true; // empty remaining rect
684 }
685 }
686 return false; // non-empty remaining rect
687}
688
689bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta)
690{

Callers 6

AfterRemoveRectMethod · 0.95
RemoveBuoyFunction · 0.80
RemoveRoadStopFunction · 0.80
RemoveRoadWaypointStopFunction · 0.80
RemoveDockFunction · 0.80

Calls 3

MakeEmptyMethod · 0.95
TileXFunction · 0.85
TileYFunction · 0.85

Tested by

no test coverage detected