void ParseFile(List<string> file) { int y = file.Count; int x = 0; foreach (string s in file) { x = System.Math.Max(x, s.Length); } _map = new Cell[x, y]; for (int j = 0; j < y; j++) { for (int i = 0; i < x; i++) { char c; if (i < file[j].Length) { c = file[j][i]; } else { c = ' '; } TerrainType t = Terrain.CharToTerrain(c); SetTerrain(i, j, t); } } }
private void DetectLinks(Cell c, int x, int y) { if (c.Navigatable) { DetectConnectedInColumn(c, CellLink.Directions.North, x, y - 1); DetectConnectedInColumn(c, CellLink.Directions.East, x + 1, y); DetectConnectedInColumn(c, CellLink.Directions.South, x, y + 1); DetectConnectedInColumn(c, CellLink.Directions.West, x - 1, y); } }
public bool SetCell(Cell cell, int xPosition, List<ColourEnum> validColours) { // see if cell 'fits' and add if so. if(cell == null || cell.IsValid(validColours)) { _cells[xPosition] = cell; return true; } return false; }
// Update the province panel with the information of the last selected province public void UpdatePanel(Game.Cell selectedCell) { // Update name of the province transform.GetChild(0).GetComponent <Text>().text = selectedCell.ProvData.Name; // Update the type of terrain of the province transform.GetChild(1).GetComponent <Image>().sprite = selectedCell.ProvData.Terrain.TypeSprite; // Update combat and movement modifiers of the province transform.GetChild(2).GetChild(1).GetComponent <Text>().text = selectedCell.ProvData.Terrain.AtkMod.ToString(); transform.GetChild(3).GetChild(1).GetComponent <Text>().text = selectedCell.ProvData.Terrain.DefMod.ToString(); transform.GetChild(4).GetChild(1).GetComponent <Text>().text = selectedCell.ProvData.Terrain.MovMod.ToString(); }
public static List<String> FindUnfilledResourceRequirments(Cell Cell, Task Task) { var taskRequirements = Task.GetRequiredResources().ToList(); var cellResources = Cell.Resources; foreach (var item in cellResources) if (taskRequirements.Contains(item)) taskRequirements.Remove(item); return taskRequirements; }
public static List<String> FindExcessResources(Cell Cell, Task Task) { var taskRequirements = Task.GetRequiredResources(); var cellResources = new List<String>(Cell.Resources); foreach (var item in taskRequirements) if (cellResources.Contains(item)) cellResources.Remove(item); return cellResources; }
private object GetColour(Cell cell, int colourIndex) { if (cell == null) { return "-"; } if (cell.Colours[colourIndex] == ColourEnum.None) { return "-"; } return cell.Colours[colourIndex].ToString().Substring(0, 1); }
public MoveAction(Cell Start, CellLink.Directions Direction) { SplinePoints = new Vector3[3]; var startCell = Start; SplinePoints[0] = startCell.CenterPoint; var linkIndex = startCell.Links.FindIndex(l => l.Direction == Direction); if (linkIndex >= 0 && linkIndex < startCell.Links.Count) { var link = startCell.Links[linkIndex]; SplinePoints[1] = link.EdgePoint; if (link.Neighbor == null) Done = true; else SplinePoints[2] = link.Neighbor.CenterPoint; } else Done = true; }
private void DetectConnectedInColumn(Cell From, CellLink.Directions Direction, int CX, int CY) { if (CX < 0 || CX >= this.width || CY < 0 || CY >= this.height) return; var baseMesh = From.NavigationMesh; forRect(CX, CY, 0, 1, 1, this.depth, (neighbor, x, y, z) => { if (neighbor.Navigatable) { var coincidentEdge = Gem.Geo.Mesh.FindCoincidentEdge(neighbor.NavigationMesh, baseMesh); if (coincidentEdge.HasValue) From.Links.Add(new CellLink { Direction = Direction, Neighbor = neighbor, EdgePoint = (coincidentEdge.Value.P0 + coincidentEdge.Value.P1) / 2.0f, LinkZOffset = 0.0f }); } }); }
public bool SetCell(Cell cell, int xPosition, int yPosition) { if (_rows[yPosition] == null) { _rows[yPosition] = new Row(_size); } // border rows/cells var isBorder = xPosition == 0 || xPosition == _size - 1 || yPosition == 0 || yPosition == _size - 1; // get valid colours var validColours = isBorder ? null : GetValidColours(xPosition, yPosition); return _rows[yPosition].SetCell(cell, xPosition, validColours); }
void GenerateRandomMap(int x, int y, Random rnd) { _map = new Cell[x, y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { double r = rnd.NextDouble(); if (r < 0.85) { SetTerrain(i, j, TerrainType.Water); } else { SetTerrain(i, j, TerrainType.Sand); } } } bool changed; do { changed = false; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (getTerrain(i - 1, j) != TerrainType.Water && getTerrain(i, j) == TerrainType.Water && getTerrain(i + 1, j) != TerrainType.Water) { SetTerrain(i, j, getTerrain(i - 1, j)); changed = true; } if (getTerrain(i, j - 1) != TerrainType.Water && getTerrain(i, j) == TerrainType.Water && getTerrain(i, j + 1) != TerrainType.Water) { SetTerrain(i, j, getTerrain(i, j - 1)); changed = true; } if (getTerrain(i - 1, j - 1) != TerrainType.Water && getTerrain(i, j) == TerrainType.Water && getTerrain(i + 1, j + 1) != TerrainType.Water) { SetTerrain(i, j, getTerrain(i - 1, j - 1)); changed = true; } if (getTerrain(i - 1, j + 1) != TerrainType.Water && getTerrain(i, j) == TerrainType.Water && getTerrain(i + 1, j - 1) != TerrainType.Water) { SetTerrain(i, j, getTerrain(i - 1, j + 1)); changed = true; } } } } while (changed); do { changed = false; ClearImageCache(); for (int i = 0; i < x && !changed; i++) { for (int j = 0; j < y && !changed; j++) { if (GetImage(i, j) == null) { SetTerrain(i, j, TerrainType.Sand); changed = true; } } } } while (changed); ClearImageCache(); }
public static bool ResourceRequirmentsMet(Cell Cell, Task Task) { var taskRequirements = Task.GetRequiredResources(); var cellResources = Cell.Resources; if (taskRequirements.Count() != cellResources.Count) return false; var compared = taskRequirements.OrderBy(b => b).Zip(cellResources.OrderBy(b => b), (a, b) => a == b); if (compared.Count(b => b == false) != 0) return false; return true; }
public void generateField() { Vector2 pos = new Vector2(); pos.X = 450; pos.Y = 180; Block b = new Block(blocktext, pos, null, 0); b.SetParent(b); blocks.Add(b); for (int i = 1; i < this.cells.Count; i++) { bool setNewRoot = false; Vector2 newpos = new Vector2(); Cell C = new Cell(); int k = this.blocks.Count - 1; Block pre = this.blocks.ToArray()[k]; // Random generation of board blocks! // Variables: bool BuildBlock = false; int loc = rand.Next(1, 4); // Loop bool NotFound = true; while (NotFound) { if (setNewRoot) k = rand.Next(0, this.blocks.Count); pre = this.blocks.ToArray()[k]; loc = rand.Next(1, 5); // Check Direction to be Built switch (loc) { case 1: newpos.X = pre.Apos.X - 30; newpos.Y = pre.Apos.Y; break; case 2: newpos.X = pre.Apos.X; newpos.Y = pre.Apos.Y - 30; break; case 3: newpos.X = pre.Apos.X + 30; newpos.Y = pre.Apos.Y; break; case 4: newpos.X = pre.Apos.X; newpos.Y = pre.Apos.Y + 30; break; default: break; } if (newpos.X < mainFrame.Width && newpos.Y < mainFrame.Height && newpos.X >= 0 && newpos.Y >= 0) { foreach (Cell c in this.cells) { if (c.X == newpos.X && c.Y == newpos.Y) { C = c; C.visited = true; int freeNeighbors = 0; // check for neighbors if (!isBlockNeighbor((int)newpos.X + 30, (int)newpos.Y)) //if(!isVisitedNeighbor((int)newpos.X + 30, (int)newpos.Y)) freeNeighbors++; if (!isBlockNeighbor((int)newpos.X, (int)newpos.Y + 30)) //if(!isVisitedNeighbor((int)newpos.X, (int)newpos.Y + 30)) freeNeighbors++; if (!isBlockNeighbor((int)newpos.X - 30, (int)newpos.Y)) //if(!isVisitedNeighbor((int)newpos.X - 30, (int)newpos.Y)) freeNeighbors++; if (!isBlockNeighbor((int)newpos.X, (int)newpos.Y - 30)) //if (!isVisitedNeighbor((int)newpos.X, (int)newpos.Y - 30)) freeNeighbors++; if (freeNeighbors >= 3) { NotFound = false; BuildBlock = true; } if (freeNeighbors < 3) setNewRoot = true; } } } if (blocks.Count > 3000) return; } if (BuildBlock) { Block newBlock = new Block(blocktext, newpos, pre, loc); newBlock.cell = C; C.setBlock(newBlock); this.blocks.Add(newBlock); pre.SetChild(newBlock); //System.Console.WriteLine(C.id); } } }
public void generateMazePlan() { int ID = 0; for (int i = 0; i < mainFrame.Width / 30; i++) { for (int j = 0; j < mainFrame.Height / 30; j++) { Cell c = new Cell(i * 30,j * 30); c.id = ID + 1; ID++; this.cells.Add(c); } } }
private void UpdateNavigation(Cell c, int x, int y, int z) { c.Navigatable = false; c.Links.Clear(); c.NavigationMesh = null; c.CenterPoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); if (c.IsSolid) { c.NavigationMesh = Gem.Geo.Gen.Copy(Generate.GetNavigationMesh(c.Block.Shape)); if (c.Block.Orientable) Gem.Geo.Gen.Transform(c.NavigationMesh, Matrix.CreateRotationZ( (Gem.Math.Angle.PI / 2) * (int)c.BlockOrientation)); Gem.Geo.Gen.Transform(c.NavigationMesh, Matrix.CreateTranslation(x + 0.5f, y + 0.5f, z)); Gem.Geo.Gen.CalculateTangentsAndBiNormals(c.NavigationMesh); var centerPointRayOrigin = new Vector3(x + 0.5f, y + 0.5f, z + 2.0f); var hitCenter = c.NavigationMesh.RayIntersection(new Ray(centerPointRayOrigin, new Vector3(0, 0, -1))); if (hitCenter.Intersects) c.CenterPoint = centerPointRayOrigin + (new Vector3(0, 0, -1) * hitCenter.Distance); c.Navigatable = true; // Block must have two clear blocks above it to be navigatable. if (z != (this.depth - 1)) if (CellAt(x, y, z + 1).IsSolid) c.Navigatable = false; if (z != (this.depth - 2)) if (CellAt(x, y, z + 2).IsSolid) c.Navigatable = false; } }