Skip to content

Commit fd13815

Browse files
committed
Removed redundant method to check if tile is in valid coordinates
1 parent 1a4c0d2 commit fd13815

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

C7Engine/C7GameData/Tile.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -639,46 +639,43 @@ public Tile GetTileAtNeighborIndex(int neighborIndex) {
639639
/// <param name="clockwise"></param>
640640
/// <returns></returns>
641641
public Tile FindInRing(int rank, Func<Tile, bool> predicate, bool clockwise = true) {
642-
Tile startingTile = map.tileAt(this.XCoordinate, this.YCoordinate - (2 * rank));
643-
int dx = startingTile.XCoordinate;
644-
int dy = startingTile.YCoordinate;
642+
int x = this.XCoordinate;
643+
int y = this.YCoordinate - (2 * rank);
645644

646-
if (startingTile != Tile.NONE && predicate(startingTile)) return startingTile;
645+
Tile currentTile = map.tileAt(x, y);
646+
if (currentTile != Tile.NONE && predicate(currentTile)) return currentTile;
647647

648648
// Going SW(counter-clockwise) or SE(clockwise)
649649
for (int _ = 1; _ < (2 * rank) + 1; _++) {
650-
if (clockwise) { dx++; dy++; } else { dx--; dy++; }
651-
if (!IsInValidCoordinates(dx, dy, out Tile currentTile) || !predicate(currentTile)) continue;
650+
if (clockwise) { x++; y++; } else { x--; y++; }
651+
currentTile = map.tileAt(x, y);
652+
if (currentTile == Tile.NONE || !predicate(currentTile)) continue;
652653
return currentTile;
653654
}
654655
// Going SE(counter-clockwise) or SW(clockwise)
655656
for (int _ = 1; _ < (2 * rank) + 1; _++) {
656-
if (clockwise) { dx--; dy++; } else { dx++; dy++; }
657-
if (!IsInValidCoordinates(dx, dy, out Tile currentTile) || !predicate(currentTile)) continue;
657+
if (clockwise) { x--; y++; } else { x++; y++; }
658+
currentTile = map.tileAt(x, y);
659+
if (currentTile == Tile.NONE || !predicate(currentTile)) continue;
658660
return currentTile;
659661
}
660662
// Going NE(counter-clockwise) or NW(clockwise)
661663
for (int _ = 1; _ < (2 * rank) + 1; _++) {
662-
if (clockwise) { dx--; dy--; } else { dx++; dy--; }
663-
if (!IsInValidCoordinates(dx, dy, out Tile currentTile) || !predicate(currentTile)) continue;
664+
if (clockwise) { x--; y--; } else { x++; y--; }
665+
currentTile = map.tileAt(x, y);
666+
if (currentTile == Tile.NONE || !predicate(currentTile)) continue;
664667
return currentTile;
665668
}
666669
// Going NW(counter-clockwise) or NE(clockwise)
667670
for (int _ = 1; _ < (2 * rank); _++) {
668-
if (clockwise) { dx++; dy--; } else { dx--; dy--; }
669-
if (!IsInValidCoordinates(dx, dy, out Tile currentTile) || !predicate(currentTile)) continue;
671+
if (clockwise) { x++; y--; } else { x--; y--; }
672+
currentTile = map.tileAt(x, y);
673+
if (currentTile == Tile.NONE || !predicate(currentTile)) continue;
670674
return currentTile;
671675
}
672676
return null;
673677
}
674678

675-
private bool IsInValidCoordinates(int dx, int dy, out Tile currentTile) {
676-
if (map.wrapHorizontally) dx %= map.numTilesWide;
677-
if (map.wrapVertically) dy %= map.numTilesTall;
678-
currentTile = map.tileAt(dx, dy);
679-
return currentTile != null && currentTile != Tile.NONE;
680-
}
681-
682679
// Returns the tiles in the spiral ordering defined by
683680
// GetTileAtNeighborIndex(i).
684681
public List<Tile> GetTilesWithinRankDistance(int rank) {

0 commit comments

Comments
 (0)