Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions C7Engine/C7GameData/MapUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ private Intent ResolveIntent(Tile tile) {
return Intent.Disabled;

// Impassable terrain (e.g. some mods' deserts) cannot be entered
// by any unit, no matter what.
if (tile.IsImpassable())
// by any unit, but a barbarian camp tile stays enterable (like a
// city) so the camp's garrison can move out and back in.
if (tile.IsImpassable() && !tile.hasBarbarianCamp)
return Intent.Disabled;

var unitOwner = this.owner;
Expand Down
23 changes: 23 additions & 0 deletions EngineTests/AI/Pathing/AStarPathFindingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@ private void TestLandUnitCannotPathThroughImpassableTile() {
// The path cannot cross the impassable tile to reach the destination.
Assert.Empty(tilePath.path);
}

[Fact]
private void TestBarbarianCampTileIsEnterableEvenWhenImpassable() {
InitilizeStartTile(MakeHillTile(), new TileLocation(50, 50));
var impassableDesert = AddNeighborsAndUpdateMap(startTile, MakeImpassableDesertTile(), TileDirection.NORTH);
impassableDesert.hasBarbarianCamp = true;

MapUnit unit = MakeLandUnit();
unit.unitType.attack = 1;
unit.location = startTile;
startTile.unitsOnTile.Add(unit);

// A camp tile stays enterable even on impassable terrain, so a
// garrison can leave and return, both peacefully and forcefully.
Assert.True(unit.CanEnter(impassableDesert));
Assert.True(unit.CanEnterForcefully(impassableDesert));

AStarAlgorithm aStarAlgorithm = PathingAlgorithmChooser.GetAlgorithm(unit) as AStarAlgorithm;
TilePath tilePath = aStarAlgorithm.PathFrom(startTile, impassableDesert, unit);

Assert.NotEmpty(tilePath.path);
Assert.True(tilePath.path.Contains(impassableDesert));
}
}

public sealed class AStarPathFindingWaterUnitTest : MapBase {
Expand Down
Loading