public void FlightmasterTest() { var builder = new TileBuilder("Azeroth", 36, 49); builder.PrepareData(new ConsoleLog()); builder.Build(); }
public void Given_ARightRotatedTile_When_GettingRightEdge_Then_ReturnsBottomEdge() { // Arrange var field = new Field(ImmutableHashSet.Create( Segment.RightTop, Segment.Right, Segment.RightBottom )); var tile = new TileBuilder() .CreateTile(new IFeature[] { field, }) .ValueOrFailure(); var placement = new TilePlacement(tile, Rotation.Quarter); // Act var actualEdge = placement.GetFeaturesAt(Edge.Bottom); // Assert IFeature[] expectedEdge = { field, field, field }; Assert.Equal(expectedEdge, actualEdge); }
public void Given_AnUnrotatedTile_When_GettingTopEdge_Then_ReturnsTopEdge() { // Arrange var field = new Field(ImmutableHashSet.Create( Segment.TopLeft, Segment.Top, Segment.TopRight )); var tile = new TileBuilder() .CreateTile(new IFeature[] { field, }) .ValueOrFailure(); var placement = new TilePlacement(tile, Rotation.None); // Act var actualEdge = placement.GetFeaturesAt(Edge.Top); // Assert IFeature[] expectedEdge = { field, field, field }; Assert.Equal(expectedEdge, actualEdge); }
public void TestNotAllStraightWinningSet() { GameLogic gl = new GameLogic(); var tiles = TileBuilder.BuildNotAllStraightTiles(); var wt = gl.BuildWinningTiles(tiles, null); Assert.IsNull(wt); }
public TileToken(TileBuilder builder) { Id = builder.Id; Sprite = builder.Sprite; Name = builder.Name; x = 0; y = 0; }
protected override void OnInvoke(ScheduledTask task) { //update data var tBuilder = new TileBuilder(); // oops, you use code from proj A. // So, you have it // as a reference, And MS thinks that // your bgAgent uses forbidden API }
public void FlightmasterTest() { MpqManager.Initialize("S:\\WoW"); var builder = new TileBuilder("Azeroth", 36, 49); builder.Build(new ConsoleLog()); }
public void TestAllPongWinningSet() { GameLogic gl = new GameLogic(); var tiles = TileBuilder.BuildAllPongTiles(); var wt = gl.BuildWinningTiles(tiles, null); Assert.IsNotNull(wt); }
public MainForm() { InitializeComponent(); Game.State = new GameState(); Game.CarsController = new CarsController(); CityBuilder.Create(); TileBuilder.Build(); }
public void TestWinWith4Flowers() { GameLogic gl = new GameLogic(); var tiles = TileBuilder.BuildWinWith4FLowers(); var ws = gl.BuildWinningTiles(tiles, null); var wt = pc.GetWinningType(game, ws, player); Assert.IsTrue(wt.Contains(WinningType.AllFourFlowerSameType)); }
public static void CreateWallMount() { ObjectTile tile = TileBuilder.CreateTile <ObjectTile>(LayerType.Objects); tile.Rotatable = true; tile.Offset = true; TileBuilder.CreateAsset(tile, "WallMountTile"); }
static void CreateNavmesh() { var sw = Stopwatch.StartNew(); var build = new TileBuilder("Azeroth", 28, 28).Build(); Console.WriteLine("Generated navmesh in {0}", sw.Elapsed); TestNavmesh(build); }
public void TestPureHand() { GameLogic gl = new GameLogic(); var tiles = TileBuilder.BuildPureHand(); var ws = gl.BuildWinningTiles(tiles, null); var wt = pc.GetWinningType(game, ws, player); Assert.IsTrue(wt.Contains(WinningType.PureHand)); }
public static void CreateWallConnected() { var tile = TileBuilder.CreateTile <ConnectedTile>(LayerType.Structures); tile.texturePath = "Walls"; tile.connectCategory = ConnectCategory.Walls; tile.connectType = ConnectType.ToSameCategory; TileBuilder.CreateAsset(tile, "WallTile"); }
public override void OnInspectorGUI() { TileBuilder myyTileBuilder = (TileBuilder)target; DrawDefaultInspector(); if (GUILayout.Button("Build Tiles")) { myyTileBuilder.BuildTiles(); } }
public static void CreateTable() { ConnectedTile tile = TileBuilder.CreateTile <ConnectedTile>(LayerType.Objects); tile.texturePath = "Tables"; tile.connectCategory = ConnectCategory.Tables; tile.connectType = ConnectType.ToSameCategory; TileBuilder.CreateAsset(tile, "TableTile"); }
public static void CreateWindow() { ConnectedTile tile = TileBuilder.CreateTile <ConnectedTile>(LayerType.Windows); tile.texturePath = "Windows"; tile.connectCategory = ConnectCategory.Windows; tile.connectType = ConnectType.ToSameCategory; TileBuilder.CreateAsset(tile, "WindowTile"); }
public void TestFlower() { var tiles = TileBuilder.BuildAllStraightTilesWithOneFlower(); game.CurrentWind = WindDirection.East; player.Wind = WindDirection.East; player.ConnectionId = "p1"; int points = pc.CalculateFlower(game, tiles, player); Assert.AreEqual(1, points); }
public TileSetModel Read(Stream stream) { Builder.SetTileSize(_tileSize); Builder.SetPixelFormat(TilePixelFormat.Indexed8bpp); BinaryReader binReader = new BinaryReader(stream); binReader.BaseStream.Position = 0; int bytesPerTile = _tileSize * _tileSize / 8; int tilesNo = (int)binReader.BaseStream.Length / (bytesPerTile * _bitPlanesNo); if (tilesNo == 0) { return(null); } for (int tileIndex = 0; tileIndex < tilesNo; tileIndex++) { byte[] tileData = new byte[_tileSize * _tileSize]; for (int i = 0; i < _bitPlanesNo; i++) { byte[] rawData = binReader.ReadBytes(bytesPerTile); rawData = rawData.Reverse().ToArray(); if (rawData.Length == 0) { return(null); } var bitArray = new BitArray(rawData); for (int k = 0; k < _tileSize * _tileSize; k++) { tileData[k] += (byte)((bitArray[k] ? 1 : 0) << i); } } tileData = tileData.Reverse().ToArray(); //Start building new tile var tileBuilder = TileBuilder.NewTile(); tileBuilder.SetIndex(tileIndex); tileBuilder.SetData(tileData); //Add new tile to tileset being build Builder.AddTile(tileBuilder.Build()); } return(Builder.Build()); }
/// <summary> /// Turn EncodedGridStruct to GridStruct /// </summary> /// <param name="grid"></param> /// <returns></returns> public static GridStruct DecodeGrid(this EncodedGridStruct grid) { GridStruct DecodedGrid = new GridStruct(grid.width, grid.height); for (int x = 0; x < grid.width; x++) { for (int y = 0; y < grid.height; y++) { DecodedGrid.grid[x, y] = TileBuilder.Create(Type.GetType(grid.grid[x, y].floor), Type.GetType(grid.grid[x, y].environmentObject), Type.GetType(grid.grid[x, y].gameObject)); } } return(DecodedGrid); }
public void Given_TwoNeighbours_When_FeaturesMatch_Then_True() { var topTile = new TileBuilder() .CreateTile(new IFeature[] { new Field(ImmutableHashSet.Create( Segment.BottomRight, Segment.Bottom, Segment.BottomLeft )), }) .ValueOrFailure(); var centreTile = new TileBuilder() .CreateTile(new[] { new Field(ImmutableHashSet.Create( Segment.BottomLeft, Segment.Bottom, Segment.BottomRight, Segment.TopLeft, Segment.Top, Segment.TopRight )), }) .ValueOrFailure(); var bottomTile = new TileBuilder() .CreateTile(new[] { new Field(ImmutableHashSet.Create( Segment.TopLeft, Segment.Top, Segment.TopRight )), }) .ValueOrFailure(); var topAction = MakePlaceTile(0, 1, topTile); var centreAction = MakePlaceTile(0, 0, centreTile); var bottomAction = MakePlaceTile(0, -1, bottomTile); var board = MakeBoard(topAction, bottomAction); var engine = MockEngine(board); AssertTrue <AdjacentFeaturesMatchRule>(engine, centreAction); }
/// <summary> /// Sets the floor index of a rectangle of tiles to build a floor /// </summary> /// <param name="x">Horizontal start position</param> /// <param name="y">Vertical start position</param> /// <param name="width">Width of the floor</param> /// <param name="depth">Depth of the floor</param> /// <param name="height">Height of the floor from the ground</param> /// <param name="textureFunc">Function deciding which texture to apply to a floor tile. /// Params are: int horzpos, int vertpos</param> /// <param name="tiles">Tile array to build the floor in</param> public static void BuildFloor(TileBuilder[,] tiles, int x, int y, int width, int depth, int height, Func<int, int, ResourceLocator> textureFunc) { int tw = tiles.GetLength(0); int th = tiles.GetLength(1); for (int i = 0; i < width; ++i) { int tx = x + i; if (tx >= 0 && tx < tw) { for (int j = 0; j < depth; ++j) { int ty = y + j; if (ty >= 0 && ty < th) tiles[tx, ty].SetFloor(height, textureFunc(i, j)); } } } }
/// <summary> /// Sets the roof index of a rectangle of tiles to build a roof /// </summary> /// <param name="x">Horizontal start position</param> /// <param name="y">Vertical start position</param> /// <param name="width">Width of the roof</param> /// <param name="depth">Depth of the roof</param> /// <param name="height">Height of the roof from the ground</param> /// <param name="texture">Tile texture name</param> /// <param name="slant">Direction of slant</param> /// <param name="tiles">Tile array to build the roof in</param> public static void BuildRoof(TileBuilder[,] tiles, int x, int y, int width, int depth, int height, ResourceLocator texture, Face slant = Face.None) { int tw = tiles.GetLength(0); int th = tiles.GetLength(1); for (int i = 0; i < width; ++i) { int tx = x + i; if (tx >= 0 && tx < tw) { for (int j = 0; j < depth; ++j) { int ty = y + j; if (ty >= 0 && ty < th) tiles[tx, ty].SetRoof(height, slant, texture); } } } }
public TileSetModel Read(Stream stream) { Builder.SetTileSize(TILE_SIZE); Builder.SetPixelFormat(TilePixelFormat.Indexed8bpp); BinaryReader binReader = new BinaryReader(stream); binReader.BaseStream.Position = 0; int tilesNo = (int)(binReader.BaseStream.Length / 256); if (tilesNo == 0) { return(null); } for (int tileIndex = 0; tileIndex < tilesNo; tileIndex++) { byte[] rawData = binReader.ReadBytes(TILE_SIZE * TILE_SIZE); if (rawData.Length == 0) { return(null); } byte[] tileData = new byte[TILE_SIZE * TILE_SIZE]; for (int k = 0; k < TILE_SIZE * TILE_SIZE; k++) { tileData[k] = rawData[(k * 64) % (TILE_SIZE * TILE_SIZE) + k / 4]; } //Start building new tile var tileBuilder = TileBuilder.NewTile(); tileBuilder.SetIndex(tileIndex); tileBuilder.SetData(tileData); //Add new tile to tileset being build Builder.AddTile(tileBuilder.Build()); } return(Builder.Build()); }
/// <summary> /// This is a coroutine to place tiles into Unity in between frames. This coroutine will /// run until it hits yield and then return control to the main thread. It is essential /// in preventing Unity from freezing up while loading chunks. The only latency left is /// in the call to the database. Note that we planned to solve this with an on disk cache. /// </summary> IEnumerator tileMonitor() { // Check current position Vector3 currpos = Globals.position; int x = Convert.ToInt32(Math.Round(currpos[0] / 32)); int z = Convert.ToInt32(Math.Round(currpos[2] / 32)); //Check for tiles within needed range //We want all tiles in a 6x6 range for (int i = x - 3; i < x + 3; i++) { for (int j = z - 3; j < z + 3; j++) { //Check if current tile exists Tuple <int, int> tempTuple = new Tuple <int, int>(i, j); if (!active.Contains(tempTuple)) { //order a prefab to be created with the new coordinates GameObject Obj = worldTiles[counter + 1]; Obj.name = "Tilex" + Convert.ToString(i) + "y" + Convert.ToString(j); Obj.transform.position = new Vector3((i * 31), 0, (j) * 31); Obj.transform.rotation = Quaternion.identity; Obj.transform.localScale = new Vector3(256 / 10 + 1, 256 / 10 + 1, 256 / 10 + 1); //Get elevations and imagery from the database to build the tile Tuple <Mesh, Material, bool> TileTuple = TileBuilder.BuildTile(i * 256, -j * 256); //If the database returned a found true in the bool, apply the information to the tile if (TileTuple.Item3) { Obj.GetComponent <MeshRenderer>().material = TileTuple.Item2; Obj.GetComponent <MeshFilter>().mesh = TileTuple.Item1; Obj.transform.localScale = Vector3.one; active.Add(tempTuple); counter = (counter + 1) % worldSize; } yield return(null); } } } }
public void FindFeatureTiles_Given_ALoopWithinThreeTiles_FourFeaturesAndThreeTilesAreReturned() { var pathFinder = new PathFinder(); var leftTile = new TileBuilder() .CreateTile(new City(RightBottom, RightTop)) .ValueOrFailure(); var middleTile = new TileBuilder() .CreateTile(new City(LeftBottom, RightBottom), new City(LeftTop, RightTop)) .ValueOrFailure(); var rightTile = new TileBuilder() .CreateTile(new City(LeftBottom, LeftTop)) .ValueOrFailure(); // When var placeLeftTileGameAction = MakePlaceTile(-1, 0, leftTile); var placeMiddleTileGameAction = MakePlaceTile(0, 0, middleTile); var placeRightTileGameAction = MakePlaceTile(1, 0, rightTile); var board = MakeBoard( placeLeftTileGameAction, placeMiddleTileGameAction, placeRightTileGameAction); var featureTiles = pathFinder.FindFeatureTiles( placeLeftTileGameAction.Point, board, leftTile.Features.FirstOrDefault()) .ValueOrFailure(); // Then var expectedFeatureTiles = new Dictionary <IFeature, Tile> { { leftTile.Features.First(), leftTile }, { middleTile.Features.First(), middleTile }, { middleTile.Features.Last(), middleTile }, { rightTile.Features.First(), rightTile }, }; Assert.Equal(expectedFeatureTiles, featureTiles); }
/// <summary> /// Generate quantized mesh tile from the supplied grid /// </summary> /// <returns></returns> public bool BuildQuantizedMeshTile() { try { ComputeHeaderInfo(); // Turn grid into a quantized mesh var vertices = MeshBuilder.MakeQuantizedMesh(ref TileData); var tileHeader = new TerrainTileHeader() { MaximumHeight = TileData.MaximumHeight, MinimumHeight = TileData.MinimumHeight, CenterX = TileData.CenterX, CenterY = TileData.CenterY, CenterZ = TileData.CenterZ, BoundingSphereCenterX = TileData.BoundingSphereCenterX, BoundingSphereCenterY = TileData.BoundingSphereCenterY, BoundingSphereCenterZ = TileData.BoundingSphereCenterZ, BoundingSphereRadius = TileData.BoundingSphereRadius, HorizonOcclusionPointX = TileData.HorizonOcclusionPointX, HorizonOcclusionPointY = TileData.HorizonOcclusionPointY, HorizonOcclusionPointZ = TileData.HorizonOcclusionPointZ }; // This class constructs a tile from the computed mesh var tileBuilder = new TileBuilder(); var tile = tileBuilder.MakeTile(vertices, ref TileData.VertexNormals, tileHeader, MapUtils.GridSizeToTriangleCount(TileData.GridSize), TileData.GridSize, TileData.HasLighting); QuantizedMeshTile = CompressTile ? MapUtils.Compress(tile) : tile; BuildTileFaultCode = RequestErrorStatus.OK; } catch (Exception E) { Log.LogError(E, "BuildQuantizedMeshTile: Exception:"); return(false); } return(true); }
public void CrossingTest() { //MpqManager.Initialize("I:\\WoW"); byte[] dataA, dataB; // Build tile A { var builder = new TileBuilder("Azeroth", 31, 49); builder.PrepareData(new ConsoleLog()); dataA = builder.Build(); Assert.IsNotNull(dataA); } // Build tile B { var builder = new TileBuilder("Azeroth", 32, 49); builder.PrepareData(new ConsoleLog()); dataB = builder.Build(); Assert.IsNotNull(dataB); } // Load into mesh var pather = new Pather("X:\\Meshes\\Azeroth"); Assert.IsTrue(pather.LoadTile(dataA)); Assert.IsTrue(pather.LoadTile(dataB)); // and try pathing, coords from AzerothMeshTest -> TileCrossing which is a non-building version of this var start = new Vector3(-9467.8f, 64.2f, 55.9f); var end = new Vector3(-9248.9f, -93.35f, 70.3f); var path = pather.FindPath(start, end); // check result Assert.IsNotNull(path); Assert.Greater(path.Count, 0); Assert.Less((end - path[path.Count - 1].Location).Length(), 3f); }
private static void LoadTiles(string path) { Object[] assets = AssetDatabase.LoadAllAssetsAtPath(path); foreach (KeyValuePair <string, DmiIcon> entry in DmiIconData.Data) { if (entry.Key.Contains("floors.dmi")) // TODO only supports floors right now { string folderPath = Path.Combine(tilesPath, assets[0].name); foreach (DmiState state in entry.Value.states) { int dmiIndex = int.Parse(state.unityName.Replace("floors_", "")); int tileCount = state.frames * state.dirs; for (int e = 0; e < state.frames * state.dirs; e++) { string tileName = state.state + (tileCount > 1 ? "_" + e : ""); SimpleTile tile = TileBuilder.CreateTile <SimpleTile>(LayerType.Floors); tile.sprite = assets[dmiIndex + e + 1] as Sprite; tile.LayerType = LayerType.Floors; if (tileName.Length == 0) { tileName = "FloorTile"; } TileBuilder.CreateAsset(tile, tileName, folderPath); } } break; } } }
public static void GenerateTiles(string subject) { //Moving old tiles string basePath = Application.dataPath + "/Resources/Prefabs/"; string basePath2 = basePath + subject + "/"; // Debug.Log (basePath2); int counter = 0; int created = 0; string[] scan = Directory.GetFiles(basePath2, "*.prefab", SearchOption.AllDirectories); foreach (string file in scan) { counter++; int t = scan.Length; EditorUtility.DisplayProgressBar(counter + "/" + scan.Length + " Generating Tiles for " + subject, "Tile: " + counter, counter / (float)scan.Length); // Debug.Log ("Longpath data: " + file); //Get the filename without extention and path string name = Path.GetFileNameWithoutExtension(file); // Debug.Log ("Creating tile for prefab: " + name); //Generating the path needed to hook onto for selecting the game object string smallPath = file.Substring(file.IndexOf("Assets") + 0); // Debug.Log ("smallpath data: " + smallPath); //Generating the path needed to chose the right tile output sub-folder string subPath = smallPath.Substring(smallPath.IndexOf(subject) + 7); // Debug.Log ("subPath data: " + subPath); string barePath = subPath.Substring(0, subPath.LastIndexOf(Path.DirectorySeparatorChar)); // Debug.Log ("barePath data: " + barePath); //Check if tile already exists if (File.Exists(Application.dataPath + "/Tilemaps/Tiles/" + subject + "/" + barePath + "/" + name + ".asset")) { // Debug.Log ("A tile for " + name + " already exists... Skipping..."); } else { //setup building the tile// ObjectTile tile = TileBuilder.CreateTile <ObjectTile>(LayerType.Objects); //Cast the gameobject GameObject cast = AssetDatabase.LoadAssetAtPath(smallPath, typeof(GameObject)) as GameObject; if (barePath == "/WallMounts") { tile.Rotatable = true; tile.Offset = true; } else { tile.Rotatable = false; tile.Offset = false; } tile.Object = cast; //Create the tile TileBuilder.CreateAsset(tile, name, "Assets/Tilemaps/Tiles/" + subject + "/" + barePath); PreviewSpriteBuilder.Create(cast); created++; } } EditorUtility.ClearProgressBar(); Debug.Log(created + " / " + counter + " Tiles created for prefabs"); }
protected abstract void Generate(District district, TileBuilder[,] tiles, int borderLeft, int borderTop, int borderRight, int borderBottom, Random rand);
public static void CreateSimpleObject() { TileBuilder.CreateTile <SimpleTile>(LayerType.None, "SimpleTile"); }
/// <summary> /// Sets the wall indices of a row of adjacent tiles to build a wall /// </summary> /// <param name="x">Horizontal position of the wall</param> /// <param name="y">Vertical position of the wall</param> /// <param name="face">Direction the exterior of the wall is facing</param> /// <param name="width">Width of the wall</param> /// <param name="height">Height of the wall</param> /// <param name="inTexture">Interior tile texture name</param> /// <param name="exTexture">Exterior tile texture name</param> /// <param name="tiles">Tile array to build the wall in</param> public static void BuildWall(TileBuilder[,] tiles, int x, int y, Face face, int width, int height, ResourceLocator inTexture, ResourceLocator exTexture) { BuildWall(tiles, x, y, face, width, 0, height, inTexture, exTexture); }
/// <summary> /// Sets the wall indices of a row of adjacent tiles to build a wall /// </summary> /// <param name="x">Horizontal position of the wall</param> /// <param name="y">Vertical position of the wall</param> /// <param name="face">Direction the exterior of the wall is facing</param> /// <param name="width">Width of the wall</param> /// <param name="offset">Distance from the ground</param> /// <param name="height">Height of the wall</param> /// <param name="inTexture">Interior tile texture name</param> /// <param name="exTexture">Exterior tile texture name</param> /// <param name="tiles">Tile array to build the wall in</param> public static void BuildWall(TileBuilder[,] tiles, int x, int y, Face face, int width, int offset, int height, ResourceLocator inTexture, ResourceLocator exTexture) { int tw = tiles.GetLength(0); int th = tiles.GetLength(1); for (int j = 0; j < width; ++j) { int tx = x + (face == Face.North || face == Face.South ? j : 0); int ty = y + (face == Face.East || face == Face.West ? j : 0); if (tx >= 0 && tx < tw && ty >= 0 && ty < th) for (int i = 0; i < height; ++i) tiles[tx, ty].SetWall(face, i + offset, inTexture); tx += face.GetNormalX(); ty += face.GetNormalY(); if (tx >= 0 && tx < tw && ty >= 0 && ty < th) for (int i = 0; i < height; ++i) tiles[tx, ty].SetWall(face.GetOpposite(), i + offset, exTexture); } }
public static void CreateObject() { TileBuilder.CreateTile <ObjectTile>(LayerType.Objects, "ObjectTile"); }
/// <summary> /// Sets the wall indices of a row of adjacent tiles to build a wall /// </summary> /// <param name="x">Horizontal position of the wall</param> /// <param name="y">Vertical position of the wall</param> /// <param name="face">Direction the exterior of the wall is facing</param> /// <param name="width">Width of the wall</param> /// <param name="height">Height of the wall</param> /// <param name="textureFunc">Function deciding which texture to apply to a wall tile. /// Params are: int horzpos, int level, Face face, bool isInterior</param> /// <param name="tiles">Tile array to build the wall in</param> public static void BuildWall(TileBuilder[,] tiles, int x, int y, Face face, int width, int height, Func<int, int, Face, bool, ResourceLocator> textureFunc) { BuildWall(tiles, x, y, face, width, 0, height, textureFunc); }
/// <summary> /// Sets the wall indices of a row of adjacent tiles to build a wall /// </summary> /// <param name="x">Horizontal position of the wall</param> /// <param name="y">Vertical position of the wall</param> /// <param name="face">Direction the exterior of the wall is facing</param> /// <param name="width">Width of the wall</param> /// <param name="offset">Distance from the ground</param> /// <param name="height">Height of the wall</param> /// <param name="textureFunc">Function deciding which texture to apply to a wall tile. /// Params are: int horzpos, int level, Face face, bool isInterior</param> /// <param name="tiles">Tile array to build the wall in</param> public static void BuildWall(TileBuilder[,] tiles, int x, int y, Face face, int width, int offset, int height, Func<int, int, Face, bool, ResourceLocator> textureFunc) { Face opp = face.GetOpposite(); int tw = tiles.GetLength(0); int th = tiles.GetLength(1); for (int j = 0; j < width; ++j) { int tx = x + (face == Face.North || face == Face.South ? j : 0); int ty = y + (face == Face.East || face == Face.West ? j : 0); if (tx >= 0 && tx < tw && ty >= 0 && ty < th) { for (int i = 0; i < height; ++i) { ResourceLocator tex = textureFunc(j, i + offset, face, true); if (tex != null) tiles[tx, ty].SetWall(face, i + offset, tex); } } tx += face.GetNormalX(); ty += face.GetNormalY(); if (tx >= 0 && tx < tw && ty >= 0 && ty < th) { for (int i = 0; i < height; ++i) { ResourceLocator tex = textureFunc(j, i + offset, face, false); if (tex != null) tiles[tx, ty].SetWall(opp, i + offset, tex); } } } }
/// <summary> /// Builds a solid (non hollow) box /// </summary> /// <param name="x">Horizontal position of the box</param> /// <param name="y">Vertical position of the box</param> /// <param name="width">Width of the box</param> /// <param name="depth">Depth of the box</param> /// <param name="height">Height of the box</param> /// <param name="wallTexture">Top tile texture for the box</param> /// <param name="topTexture">Wall tile texture for the box</param> /// <param name="tiles">Tile array to build the box in</param> public static void BuildSolid(TileBuilder[,] tiles, int x, int y, int width, int depth, int height, ResourceLocator wallTexture, ResourceLocator topTexture) { BuildFloor(tiles, x, y, width, depth, height, topTexture); BuildWall(tiles, x - 1, y, Face.East, depth, height, wallTexture); BuildWall(tiles, x, y - 1, Face.South, width, height, wallTexture); BuildWall(tiles, x + width, y, Face.West, depth, height, wallTexture); BuildWall(tiles, x, y + depth, Face.North, width, height, wallTexture); }
public abstract void Generate(District district, TileBuilder[,] tiles, Random rand);
public Block Generate(District district, int borderLeft, int borderTop, int borderRight, int borderBottom, Random rand) { int width = district.Width; int height = district.Height; TileBuilder[,] tiles = new TileBuilder[width, height]; for (int tx = 0; tx < width; ++tx) for (int ty = 0; ty < height; ++ty) tiles[tx, ty] = new TileBuilder(); int innerLeft = borderLeft; int innerTop = borderTop; int innerRight = width - borderRight; int innerBottom = height - borderBottom; int innerWidth = width - borderLeft - borderRight; int innerHeight = height - borderTop - borderBottom; Func<int, int, ResourceLocator> roadFunc = delegate(int tx, int ty) { return rand.NextTexture("floor/road/", 0, 4); }; GenHelper.BuildFloor(tiles, 0, 0, width, height, 0, roadFunc); GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, innerWidth + 2, innerHeight + 2, 0, (x, y) => { if (Tools.Random.NextDouble() < 0.75) { return "floor/concrete/0"; } else { return Tools.Random.NextTexture("floor/concrete", 1, 4); } }); int texOffset = 0; bool horz = false; Func<int, int, ResourceLocator> pavementFunc = delegate(int tx, int ty) { if ((horz && tx % 8 == 4) || (!horz && ty % 8 == 4)) return "floor/pavement/" + (texOffset + 2).ToString("X").ToLower(); return rand.NextTexture("floor/pavement/", texOffset, texOffset + 2); }; if (borderBottom > 1) { texOffset = 0; horz = true; GenHelper.BuildFloor(tiles, innerLeft - 1, innerBottom, innerWidth + 2, 1, 0, pavementFunc); } if (borderRight > 1) { texOffset = 4; horz = false; GenHelper.BuildFloor(tiles, innerRight, innerTop - 1, 1, innerHeight + 2, 0, pavementFunc); } if (borderTop > 1) { texOffset = 8; horz = true; GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, innerWidth + 2, 1, 0, pavementFunc); } if (borderLeft > 1) { texOffset = 12; horz = false; GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, 1, innerHeight + 2, 0, pavementFunc); } if (borderBottom > 1 && borderRight > 1) GenHelper.BuildFloor(tiles, innerRight, innerBottom, 1, 1, 0, "floor/pavement/3"); if (borderTop > 1 && borderRight > 1) GenHelper.BuildFloor(tiles, innerRight, innerTop - 1, 1, 1, 0, "floor/pavement/7"); if (borderTop > 1 && borderLeft > 1) GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, 1, 1, 0, "floor/pavement/b"); if (borderBottom > 1 && borderLeft > 1) GenHelper.BuildFloor(tiles, innerLeft - 1, innerBottom, 1, 1, 0, "floor/pavement/f"); Generate(district, tiles, borderLeft, borderTop, borderRight, borderBottom, rand); Block block = new Block(district); block.BuildTiles(tiles); return block; }