public bool CanEnterCell(World world, UnitInfluence uim, int2 cell, Actor ignoreActor, bool checkTransientActors) { if (MovementCostForCell(world, cell) == int.MaxValue) return false; if (SharesCell && uim.HasFreeSubCell(cell)) return true; var blockingActors = uim.GetUnitsAt(cell).Where(x => x != ignoreActor).ToList(); if (checkTransientActors && blockingActors.Count > 0) { // Non-sharable unit can enter a cell with shareable units only if it can crush all of them if (Crushes == null) return false; if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() && a.TraitsImplementing<ICrushable>().Any(b => b.CrushClasses.Intersect(Crushes).Any())))) return false; } return true; }
public static bool CanEnterCell( MobileInfo mobileInfo, World world, UnitInfluence uim, BuildingInfluence bim, int2 cell, Actor ignoreActor, bool checkTransientActors ) { if (MovementCostForCell(mobileInfo, world, cell) == int.MaxValue) return false; // Check for buildings var building = bim.GetBuildingBlocking(cell); if (building != null && building != ignoreActor) { if (mobileInfo.Crushes == null) return false; var crushable = building.TraitsImplementing<ICrushable>(); if (crushable.Count() == 0) return false; if (!crushable.Any(b => b.CrushClasses.Intersect(mobileInfo.Crushes).Any())) return false; } // Check mobile actors var blockingActors = uim.GetUnitsAt( cell ).Where( x => x != ignoreActor ).ToList(); if (checkTransientActors && blockingActors.Count > 0) { // We can enter a cell with nonshareable units only if we can crush all of them if (mobileInfo.Crushes == null) return false; if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() && a.TraitsImplementing<ICrushable>().Any(b => b.CrushClasses.Intersect(mobileInfo.Crushes).Any())))) return false; } return true; }