private void dijkstraTest(int x, int y, int debt, OriginDirection d, bool firstmove) { int movement = unit.getMovement(); UnitSpec.UnitMove movementType = unit.getMovementType(); if (x >= 0 && x < this.sizex && y >= 0 && y < this.sizey && // within boundaries cost[x, y] >= 0 && // permission to map (x != originx || y != originy) // Not unit origin ) { TileSelect tile = PlayMap.Grid.getTileSpec(x, y); if (tile.HighLightColorType != TileSelect.HighlightType.EnemyRTargetable && //Ignore if there is a ranged marker ((UnitControl)PlayMap.GridController).HasSeenEnemyUnit(x, y, unit.playerFactionSpec)) { if (UnitControlBattle.canTarget(unit, ((UnitControl)PlayMap.GridController).getUnitData(x, y), 1)) { tile.HighLightColorType = TileSelect.HighlightType.EnemyTargetable; } else { tile.HighLightColorType = TileSelect.HighlightType.Enemy; } highlightedTiles.Add(tile); } else { int newcost = getMovementCost(movementType, tile.FloorType, unit.UnitBodySpec.isAmphibious()); if (newcost != 0) { newcost += debt; if ((newcost < cost[x, y] || cost[x, y] <= 0) && (firstmove || newcost <= movement)) { cost[x, y] = newcost; direction[x, y] = d; //tile.HighLightColorType = TileSelect.HighlightType.Movement; highlightedTiles.Add(tile); dijkstraTest(x, y + 1, newcost, OriginDirection.S, false); dijkstraTest(x, y - 1, newcost, OriginDirection.N, false); dijkstraTest(x + 1, y, newcost, OriginDirection.W, false); dijkstraTest(x - 1, y, newcost, OriginDirection.E, false); } } } } }
private void dijkstraTest(int x, int y, int movement, int debt, OriginDirection d, UnitSpec.UnitMove movementType, bool force) { if (x >= 0 && x < this.sizex && y >= 0 && y < this.sizey && cost[x, y] != -2) { TileSelect tile = TilesSpec.getTileSpec(x, y); int newcost = getMovementCost(movementType, tile.FloorType); if (newcost != 0) { newcost += debt; if ((newcost < cost[x, y] || cost[x, y] <= 0) && (force || newcost <= movement)) { cost[x, y] = newcost; direction[x, y] = d; highlightedTiles.Add(tile); dijkstraTest(x, y + 1, movement, newcost, OriginDirection.S, movementType, false); dijkstraTest(x, y - 1, movement, newcost, OriginDirection.N, movementType, false); dijkstraTest(x + 1, y, movement, newcost, OriginDirection.W, movementType, false); dijkstraTest(x - 1, y, movement, newcost, OriginDirection.E, movementType, false); } } } }