public IReadOnlyList <Location> AdjacentLocations(Size2DI mapSize) { var results = new List <Location>(); var xVals = new List <int> { this.X - 1, this.X, this.X + 1 }; xVals.Remove(-1); xVals.Remove(mapSize.X); var yVals = new List <int> { this.Y - 1, this.Y, this.Y + 1 }; yVals.Remove(-1); yVals.Remove(mapSize.Y); foreach (var x in xVals) { foreach (var y in yVals) { if (x != this.X || y != this.Y) { results.Add(new Location { X = x, Y = y }); } } } return(results); }
public bool CanBuild(Size2DI size, Location location, bool requireCreep = false, bool hasAddOn = false, bool includeResourcePadding = false, bool includePadding = true) { var offsets = new List <LocationOffset>(); for (var x = 0; x < size.X; x++) { for (var y = 0; y < size.Y; y++) { offsets.Add(new LocationOffset { X = x, Y = y }); } } // This assumes (as is currently true) that all add-ons are 2x2 buildings // directly to the right of this one and with the same bottom Y-coordinate. if (hasAddOn) { offsets.Add(new LocationOffset { X = size.X, Y = 0 }); offsets.Add(new LocationOffset { X = size.X, Y = 1 }); offsets.Add(new LocationOffset { X = size.X + 1, Y = 0 }); offsets.Add(new LocationOffset { X = size.X + 1, Y = 1 }); } return(CanBuild(location, offsets, requireCreep, includeResourcePadding, includePadding)); }
// Note: includes natural structures, which is why the argument type is 'Unit'. // Also the 'structure' arg can be optional for unbuilt structures, so a separate type is required. private void StoreBuildingLocation(Location origin, Size2DI size, Unit structure, BuildingType type) { for (var x = origin.X; x < origin.X + size.X; x++) { for (var y = origin.Y; y < origin.Y + size.Y; y++) { structuresAndDeposits[x, y] = structure; SetAdjacentSpaces(structurePadding, x, y); if (structure != null && (structure.IsMineralDeposit || structure.IsVespeneGeyser || structure.IsVespeneBuilding)) { SetAdjacentSpaces(resourcePadding, x, y, 3); } // Reserve space for Tech Labs if (type == TerranBuildingType.Barracks || type == TerranBuildingType.Factory || type == TerranBuildingType.Starport) { // Note: I'm not sure if this will come up, but this could theoretically go off the edge of the map StoreBuildingLocation(new Location { X = origin.X + 3, Y = origin.Y }, new Size2DI { X = 2, Y = 2 }, null, TerranBuildingType.TechLab); } } } }
private static Bitmap GetImage(byte[] data, Size2DI mapSize) { return(new Bitmap( mapSize.X, mapSize.Y, mapSize.X, PixelFormat.Format8bppIndexed, Marshal.UnsafeAddrOfPinnedArrayElement(data, 0))); }
public void Setup() { // From AcropolisLE.SC2Map var mapSize = new Size2DI { X = 176, Y = 184 }; _gameInfo = new ResponseGameInfo { StartRaw = new StartRaw { MapSize = mapSize, PathingGrid = new ImageData { BitsPerPixel = 1, Size = mapSize, Data = ByteString.FromBase64(PathingGridBitmap) }, PlacementGrid = new ImageData { BitsPerPixel = 1, Size = mapSize, Data = ByteString.FromBase64(PlacementGridBitmap) }, PlayableArea = new RectangleI { P0 = new PointI { X = 18, Y = 18 }, P1 = new PointI { X = 156, Y = 153 } } } }; // Test grid setup GridConverter.GetDataValueBit(_gameInfo.StartRaw.PathingGrid, 22, 131).Should().Be(1); GridConverter.GetDataValueBit(_gameInfo.StartRaw.PlacementGrid, 22, 131).Should().Be(1); GridConverter.GetDataValueBit(_gameInfo.StartRaw.PathingGrid, 40, 124).Should().Be(1); GridConverter.GetDataValueBit(_gameInfo.StartRaw.PlacementGrid, 40, 123).Should().Be(0); }
public bool CanBuild(Size2DI size, int originX, int originY, bool includePadding) { for (var x = originX; x < originX + size.X; x++) { for (var y = originY; y < originY + size.Y; y++) { if (placementGrid[x, y] == 0 || structuresAndDeposits[x, y] != null) { return(false); } if (includePadding && (padding[x, y] || structurePadding[x, y])) { return(false); } } } return(true); }
public MapArray(MapArray <T> other) { this.size = new Size2DI(other.size); this.data = (T[])other.data.Clone(); }
public MapArray(Size2DI size) { this.size = size; this.data = new T[size.X * size.Y]; }
public MapArray(T[] data, Size2DI size) { this.size = size; this.data = data; }
public bool CanBuild(Size2DI size, Location location, bool includePadding) { return(CanBuild(size, location.X, location.Y, includePadding)); }
public bool CanBuild(Size2DI size, int originX, int originY) { return(CanBuild(size, originX, originY, true)); }
public bool CanBuild(Size2DI size, Location location) { return(CanBuild(size, location.X, location.Y, true)); }