public bool IsCloseEnoughToBase(World world, Player p, string buildingName, CPos topLeft) { if (p.PlayerActor.Trait <DeveloperMode>().BuildAnywhere) { return(true); } if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null) { return(false); } var buildingMaxBounds = Dimensions; var bibInfo = world.Map.Rules.Actors[buildingName].TraitInfoOrDefault <BibInfo>(); if (bibInfo != null && !bibInfo.HasMinibib) { buildingMaxBounds += new CVec(0, 1); } var scanStart = world.Map.Clamp(topLeft - new CVec(Adjacent, Adjacent)); var scanEnd = world.Map.Clamp(topLeft + buildingMaxBounds + new CVec(Adjacent, Adjacent)); var nearnessCandidates = new List <CPos>(); var bi = world.WorldActor.Trait <BuildingInfluence>(); var allyBuildEnabled = world.WorldActor.Trait <MapBuildRadius>().AllyBuildRadiusEnabled; for (var y = scanStart.Y; y < scanEnd.Y; y++) { for (var x = scanStart.X; x < scanEnd.X; x++) { var pos = new CPos(x, y); var buildingAtPos = bi.GetBuildingAt(pos); if (buildingAtPos == null) { var unitsAtPos = world.ActorMap.GetActorsAt(pos).Where(a => a.IsInWorld && (a.Owner == p || (allyBuildEnabled && a.Owner.Stances[p] == Stance.Ally)) && a.Info.HasTraitInfo <GivesBuildableAreaInfo>()); if (unitsAtPos.Any()) { nearnessCandidates.Add(pos); } } else if (buildingAtPos.IsInWorld && buildingAtPos.Info.HasTraitInfo <GivesBuildableAreaInfo>() && (buildingAtPos.Owner == p || (allyBuildEnabled && buildingAtPos.Owner.Stances[p] == Stance.Ally))) { nearnessCandidates.Add(pos); } } } var buildingTiles = FootprintUtils.Tiles(world.Map.Rules, buildingName, this, topLeft).ToList(); return(nearnessCandidates .Any(a => buildingTiles .Any(b => Math.Abs(a.X - b.X) <= Adjacent && Math.Abs(a.Y - b.Y) <= Adjacent))); }
public override void AddedToWorld(Actor self) { base.AddedToWorld(self); blockedPositions = FootprintUtils.Tiles(self); }