Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Canal::_GetOtherDepotChainEnd(tile)
- {
- assert(AIMarine.IsWaterDepotTile(tile));
- local offsets = [AIMap.GetTileIndex(0, 1), AIMap.GetTileIndex(0, -1),
- AIMap.GetTileIndex(1, 0), AIMap.GetTileIndex(-1, 0)];
- local end_tile = tile;
- foreach (offset in offsets) {
- local next_tile = tile + offset;
- local cur_tile = tile;
- while (AIMarine.IsWaterDepotTile(next_tile) && AIMarine.AreWaterTilesConnected(cur_tile, next_tile)) {
- end_tile = next_tile;
- next_tile += offset;
- cur_tile += offset;
- }
- }
- return end_tile;
- }
- function Canal::_GetOtherDepotTile(tile)
- {
- assert(AIMarine.IsWaterDepotTile(tile));
- local end1 = this._GetOtherDepotChainEnd(tile);
- local end2 = this._GetOtherDepotChainEnd(end1);
- if (end1 > end2) {
- local swap = end1;
- end1 = end2;
- end2 = swap;
- }
- local length = AIMap.DistanceManhattan(end1, end2) + 1;
- local offset = AIMap.GetTileIndex(1, 0);
- if (AIMap.GetTileX(end1) == AIMap.GetTileX(end2)) {
- offset = AIMap.GetTileIndex(0, 1);
- }
- local next_tile = end1 + offset;
- do {
- if (AIMarine.IsWaterDepotTile(next_tile) && AIMarine.AreWaterTilesConnected(end1, next_tile)) {
- if (end1 == tile) {
- return next_tile;
- } else if (next_tile == tile) {
- return end1;
- }
- end1 += 2 * offset;
- next_tile += 2 * offset;
- length -=2;
- }
- } while (length != 0);
- }
Add Comment
Please, Sign In to add comment