public static CheckRegion Instance(TileRegion region) { CheckRegion ret; if (!instances.TryGetValue(region, out ret)) ret = instances[region] = new CheckRegion(region); return ret; }
private ItemType GetItemType(TileRegion region) { switch (region) { case TileRegion.Store_9: return(ItemType.Weapon); case TileRegion.Store_10: return(ItemType.Ability); case TileRegion.Store_11: return(ItemType.Armor); case TileRegion.Store_12: return(ItemType.Ring); case TileRegion.Store_13: return(ItemType.StatPot); case TileRegion.Store_14: return(ItemType.Other); default: return(ItemType.None); } }
/* The following method has some subtleties to it that need to be explained. The purpose of it is to trace out the * floor tiles in the room that are adjacent to a wall tile. The tricky part is ensuring that this is done * in an orderly fashion, i.e. that it traces out a more or less continuous path (some error is fine, but a random * ordering is not, as the ordering of the edge tiles is needed for an enormous optimization in the connectivity * algorithm used elsewhere). * * The basic idea is to start on an edge tile, and then perform a depth-first search along edge tiles. The difficulty * comes from two situations. First, consider this example: * * x x o * x x o * 1 2 o * o o o * * x represents wall, o represents floor, numbers represent the path travelled (and the order). If we only * look at horizontal neighbors, the search will terminate at 2, because no adjacent floor is adjacent to a wall. * So we need to look at diagonal neighbors. That leads to the following problem: * * x x x x * x x o x * x 3 x x * 1 2 x x * * The remaining o is not connected to the path so far, but it's diagonally adjacent to the 3. This is handled * by explicitly checking for this situation: in order to take a diagonal jump, one of the * two adjacent tiles must be a floor. i.e. one of these situations: * * x x x x x x x x x x x x * x x o x x o o x x o o x * x 3 o x x 3 x x x 3 o x * 1 2 x x 1 2 x x 1 2 x x * * The final complexity is the possibility of the path jumping, leading to irregularities in the edges. * Example: * * x x o o o 8 x * x x 4 5 6 7 x * 1 2 3 x x o x * o o o x x o x * * Ultimately this level of error is accepted as is. */ public TileRegion Extract(TileRegion region) { UnityEngine.Assertions.Assert.AreNotEqual(region.Count, 0, "Room is empty!"); List <Coord> edgeTiles = new List <Coord>(region.Count); Stack <Coord> stack = new Stack <Coord>(); Coord firstTile = GetStartingEdgeTile(map, region); stack.Push(firstTile); edgeTiles.Add(firstTile); visited[firstTile.x, firstTile.y] = true; while (stack.Count > 0) { Coord tile = stack.Pop(); foreach (Coord adj in GetAdjacentCoords(tile, adjacentTiles)) { if (!visited[adj.x, adj.y] && FoundEdgeTile(tile, adj, map)) { visited[adj.x, adj.y] = true; stack.Push(adj); edgeTiles.Add(adj); } } } return(new TileRegion(edgeTiles)); }
public static ConnectionInfo FindConnection(TileRegion regionA, TileRegion regionB, int roomIndexA, int roomIndexB) { Coord bestTileA = new Coord(); Coord bestTileB = new Coord(); float bestDistance = float.MaxValue; int indexA = 0; while (indexA < regionA.Count) { int indexB = 0; Coord tileA = regionA[indexA]; Coord bestTileBThisLoop = new Coord(); float bestDistanceThisLoop = float.MaxValue; while (indexB < regionB.Count) { Coord tileB = regionB[indexB]; float distance = tileA.Distance(tileB); if (distance < bestDistanceThisLoop) { bestDistanceThisLoop = distance; bestTileBThisLoop = tileB; } indexB += (int)distance; } if (bestDistanceThisLoop < bestDistance) { bestTileA = tileA; bestTileB = bestTileBThisLoop; bestDistance = bestDistanceThisLoop; } indexA += (int)bestDistanceThisLoop; } return(new ConnectionInfo(bestTileA, bestTileB, roomIndexA, roomIndexB, bestDistance)); }
/// <summary> /// Build the tile buffer at the specified region index with target coordinates' tiles /// </summary> /// <param name="region_index">Index in the local region array</param> /// <param name="region_i">X coordinate of the region in the grid</param> /// <param name="region_j">Y coordinate of the region in the grid</param> void BuildBuffer(int region_index, int region_i, int region_j) { int tile_count = RegionWidth * RegionHeight; var grid = ((Objects.TileMap)GameObject).Grid; // TODO: account for the resolution change if (regions[region_index] == null) { regions[region_index] = new TileRegion(tile_count); } var region = regions[region_index]; region.ResetBuffers(); for (int i = region_i * RegionWidth; i < (region_i + 1) * RegionWidth; i++) { for (int j = region_j * RegionHeight; j < (region_j + 1) * RegionHeight; j++) { var type = grid[i, j]; if (type == 0) { continue; } region.AddBackgroundTile(i, j, type); } } region.SetData(); }
private Layer GenerateEmptyLayer(TileRegion tileRegion, int layerNumber) { return(new Layer { Blocks = new int[tileRegion.Tiles.Count], LayerNumber = layerNumber }); }
public static CheckRegion Instance(TileRegion region) { CheckRegion ret; if (!instances.TryGetValue(region, out ret)) { ret = instances[region] = new CheckRegion(region); } return(ret); }
private Chunk GenerateEmptyChunk(TileRegion tileRegion, int chunkNumber) { return(new Chunk { Layers = Enumerable.Range(0, _settings.ChunkHeight) .Select(layerNumber => GenerateEmptyLayer(tileRegion, layerNumber)) .ToArray(), ChunkNumber = chunkNumber }); }
public IntPoint GetRandomTile(TileRegion region) { if (!Map.Regions.ContainsKey(region)) { return(new IntPoint(0, 0)); } var rand = new Random(); List <IntPoint> tiles = Map.Regions[region]; return(tiles[rand.Next(0, tiles.Count)]); }
static TileRegion[] ExtractEdges(Map map, List <TileRegion> regions) { EdgeExtractor extractor = new EdgeExtractor(map); TileRegion[] rooms = new TileRegion[regions.Count]; for (int i = 0; i < rooms.Length; i++) { rooms[i] = extractor.Extract(regions[i]); } return(rooms); }
private void AddRegion(TileRegion region, int x, int y) { if (Regions.ContainsKey(region)) { Regions[region].Add(new IntPoint(x, y)); } else { Regions.Add(region, new List <IntPoint> { new IntPoint(x, y) }); } }
private Region GenerateEmptyRegion(TileRegion tileRegion, int regionNumber) { var numChunks = (int)Mathf.Ceil((float)_settings.HeightLimit / _settings.ChunkHeight); return(new Region { Chunks = Enumerable.Range(0, numChunks) .Select(chunkNumber => GenerateEmptyChunk(tileRegion, chunkNumber)) .ToArray(), RegionNumber = regionNumber, Center = tileRegion.Center, }); }
public Reproduce(string children = null, double densityRadius = 10, int densityMax = 5, Cooldown coolDown = new Cooldown(), TileRegion region = TileRegion.None, double regionRange = 10) { _children = children == null ? null : (ushort?)GetObjType(children); _densityRadius = densityRadius; _densityMax = densityMax; _coolDown = coolDown.Normalize(60000); _region = region; _regionRange = regionRange; }
public Position?GetRegionPosition(TileRegion region) { if (Map.Regions.All(t => t.Value != region)) { return(null); } var reg = Map.Regions.Single(t => t.Value == region); return(new Position() { X = reg.Key.X, Y = reg.Key.Y }); }
void CreateArea() { arrRegion = new TileRegion[numberRegionVerAndHor, numberRegionVerAndHor]; for (int x = 0; x < numberRegionVerAndHor; x++) { for (int y = 0; y < numberRegionVerAndHor; y++) { Vector3 regionPosition = new Vector3(-numberRegionVerAndHor / 2 + x * regionSize, 0, -numberRegionVerAndHor / 2 + y * regionSize); TileRegion regionCreated = Instantiate(regionPref, regionPosition, regionPref.transform.rotation) as TileRegion; regionCreated.x = x; regionCreated.y = y; arrRegion[x, y] = regionCreated; regionCreated.transform.parent = this.transform; regionCreated.transform.localScale = new Vector3(regionSize, regionSize, 0f); regionCreated.renderer.material.color = Color.white; } } }
public ReproduceGroup( string group = null, double densityRadius = 10, int densityMax = 5, Cooldown coolDown = new Cooldown(), TileRegion region = TileRegion.None, double regionRange = 10) { _children = BehaviorDb.InitGameData.ObjectDescs.Values .Where(x => x.Group == group) .Select(x => x.ObjectType).ToArray(); _group = group; _densityRadius = densityRadius; _densityMax = densityMax; _coolDown = coolDown.Normalize(60000); _region = region; _regionRange = regionRange; }
private Region GenerateRegion(TileRegion tileRegion, int regionNumber) { var region = GenerateEmptyRegion(tileRegion, regionNumber); foreach (var(tile, tileIndex) in tileRegion.Tiles.WithIndex()) { var tileStack = GenerateTileStack(tile); foreach (var(chunk, chunkIndex) in region.Chunks.WithIndex()) { foreach (var(layer, layerIndex) in chunk.Layers.WithIndex()) { layer.Blocks[tileIndex] = tileStack[chunkIndex * _settings.ChunkHeight + layerIndex]; } } } return(region); }
public void Reset(Wmap map = null, int x = 0, int y = 0) { TileId = _originalDesc.TileId; TileDesc = _originalDesc.TileDesc; ObjType = _originalDesc.ObjType; ObjDesc = _originalDesc.ObjDesc; ObjCfg = _originalDesc.ObjCfg; Terrain = _originalDesc.Terrain; Region = _originalDesc.Region; Elevation = _originalDesc.Elevation; if (map != null) { InitConnection(map, x, y); } UpdateCount++; }
public TossObject(string child, double range = 5, double?angle = null, Cooldown coolDown = new Cooldown(), int coolDownOffset = 0, bool tossInvis = false, double probability = 1, string group = null, double?minAngle = null, double?maxAngle = null, double?minRange = null, double?maxRange = null, double?densityRange = null, int?maxDensity = null, TileRegion region = TileRegion.None, double regionRange = 10 ) { if (group == null) { _children = new ushort[] { GetObjType(child) } } ; else { _children = BehaviorDb.InitGameData.ObjectDescs.Values .Where(x => x.Group == group) .Select(x => x.ObjectType).ToArray(); } _range = range; _angle = angle * Math.PI / 180; _coolDown = coolDown.Normalize(); _coolDownOffset = coolDownOffset; _tossInvis = tossInvis; _probability = probability; _minRange = minRange; _maxRange = maxRange; _minAngle = minAngle * Math.PI / 180; _maxAngle = maxAngle * Math.PI / 180; _densityRange = densityRange; _maxDensity = maxDensity; _group = group; _region = region; _regionRange = regionRange; }
private void AddRegion(TileRegion region, int x, int y) { if (Regions.ContainsKey(region)) Regions[region].Add(new IntPoint(x, y)); else Regions.Add(region, new List<IntPoint> {new IntPoint(x, y)}); }
static Coord GetStartingEdgeTile(Map map, TileRegion region) { // Note that in practice, this should return the very first item in alltiles, but that may change in the future. return(region.First(tile => map.IsAdjacentToWallFast(tile.x, tile.y))); }
private CheckRegion(TileRegion region) { this.region = region; }
public IntPoint GetRandomTile(TileRegion region) { if (!Map.Regions.ContainsKey(region)) return new IntPoint(0, 0); var rand = new Random(); List<IntPoint> tiles = Map.Regions[region]; return tiles[rand.Next(0, tiles.Count)]; }