| 637 | } |
| 638 | |
| 639 | bool 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 | |
| 689 | bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta) |
| 690 | { |
no test coverage detected