void Update() { float zoomDelta = Input.GetAxis("Mouse ScrollWheel"); float zoomDelta_ = Input.GetAxis("Scroll PageUD"); if (zoomDelta != 0f) { AdjustZoom(zoomDelta); } if (zoomDelta_ != 0f) { AdjustZoom(zoomDelta_); } float rotationDelta = Input.GetAxis("Rotation"); if (rotationDelta != 0f) { AdjustRotation(rotationDelta); } float xDelta = Input.GetAxis("Horizontal"); float zDelta = Input.GetAxis("Vertical"); if (xDelta != 0f || zDelta != 0f) { AdjustPosition(xDelta, zDelta); } Vector3 t = transform.localPosition; t.y = grid.GetCell(TriCoordinates.FromPosition(t)).Elevation *TriMetrics.elevationStep; transform.localPosition = t; }
public static new Human Load(BinaryReader reader) { Human ret = Instantiate((Human)TriIsland.GetUnitPrefabs((int)UnitType.PERSON, 0)); TriCell tLoc = TriGrid.Instance.GetCell(TriCoordinates.Load(reader)); if (tLoc) { ret.Home = (Inn)tLoc.Statics; } else { (TriIsland.GetCamp() as Hall).Homeless.Add(ret); } tLoc = TriGrid.Instance.GetCell(TriCoordinates.Load(reader)); if (tLoc) { ret.Company = (Company)tLoc.Statics; } tLoc = TriGrid.Instance.GetCell(TriCoordinates.Load(reader)); if (tLoc) { ret.Work = tLoc.Statics; } return(ret); }
public IEnumerator <Coroutine> LoadUnit(string path) { ClearUnits(); using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "unit.dat")))) { int header = reader.ReadInt32(); if (header <= 0) { int counter = reader.ReadInt32(); for (int i = 0; i < counter; i++) { TriCoordinates coord = TriCoordinates.Load(reader); Unit loaded = Unit.Load(reader); if (loaded) { loaded.ID = i; loaded.Location = grid.GetCell(coord); if (grid.GetCell(coord).Statics) { loaded.GetIn((Building)grid.GetCell(coord).Statics); } loaded.transform.SetParent(UnitGroup); AddUnit(loaded); } // if (i % Strings.refreshLimit == 0) yield return null; } } else { Debug.LogWarning("Unknown unit format " + header); } } yield return(null); }
public IEnumerator <Coroutine> LoadNatural(string path) { ClearNaturals(); using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "natural.dat")))) { int header = reader.ReadInt32(); if (header <= 0) { int counter = reader.ReadInt32(); for (int i = 0; i < counter; i++) { TriCoordinates coord = TriCoordinates.Load(reader); Natural loaded = Natural.Load(reader); if (loaded) { loaded.ID = i; loaded.Location = grid.GetCell(coord); loaded.transform.SetParent(NaturalGroup); AddNatural(loaded); loaded.validateRotation(); } // if (i % Strings.refreshLimit == 0) yield return null; } } else { Debug.LogWarning("Unknown naturals format " + header); } } yield return(null); }
public TriCell GetCell(Vector3 position) { position = transform.InverseTransformPoint(position); TriCoordinates coordinates = TriCoordinates.FromPosition(position); int index = coordinates.X + coordinates.Z * cellCountX; return(cells[index]); }
private bool checkbounds(TriCoordinates coord) { if (coord.X > xMin && coord.X < xMax && coord.Z > zMin && coord.Z < zMax) { return(true); } return(false); }
public static new BuildCommand Load(BinaryReader reader) { TriGrid instance = TriGrid.Instance; TriCell tCell = instance.GetCell(TriCoordinates.Load(reader)); TriDirection tDir = (TriDirection)reader.ReadInt32(); Entity prefab = TriIsland.GetBuildingPrefabs(reader.ReadInt32(), reader.ReadInt32(), 0); return(new BuildCommand(tCell, tDir, prefab)); }
public IEnumerator <Coroutine> LoadBuilding(string path) { ClearBuildings(); using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "building.dat")))) { int header = reader.ReadInt32(); if (header <= 0) { int counter = reader.ReadInt32(); for (int i = 0; i < counter; i++) { TriCoordinates coord = TriCoordinates.Load(reader); Building loaded = Building.Load(reader); if (loaded.type == BuildingType.HALL) { camp = loaded as Hall; } if (loaded) { loaded.ID = i; loaded.Location = grid.GetCell(coord); loaded.EntranceDirection = loaded.EntranceDirection; switch (loaded.sizeType) { case SizeType.SINGLE: loaded.Location.Statics = loaded; break; case SizeType.HEX: TriCell k = loaded.Location; TriDirection tDir = loaded.EntranceDirection.Previous(); for (int j = 0; j < 6; j++) { if (!k) { break; } k.Statics = loaded; k = k.GetNeighbor(tDir); tDir = tDir.Next(); } break; } loaded.transform.SetParent(BuildingGroup); AddBuilding(loaded); } // if (i % Strings.refreshLimit == 0) yield return null; } } else { Debug.LogWarning("Unknown building format " + header); } } yield return(null); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { TriCoordinates coordinates = new TriCoordinates( property.FindPropertyRelative("x").intValue, property.FindPropertyRelative("z").intValue ); position = EditorGUI.PrefixLabel(position, label); GUI.Label(position, coordinates.ToString()); }
public override List <BuildState> GetBuildStatus(TriCoordinates coord, TriDirection dir) { List <BuildState> ret = new List <BuildState>(); TriCell cell = TriGrid.Instance.GetCell(coord); int elev = cell.Elevation; ret.Add(new BuildState(coord, cell.IsBuildable())); cell = cell.GetNeighbor(dir); ret.Add(new BuildState(cell.coordinates, cell.IsBuildable() && Mathf.Abs(elev - cell.Elevation) < 2)); return(ret); }
public virtual List <BuildState> GetBuildStatus(TriCoordinates coord, TriDirection dir) { List <BuildState> ret = new List <BuildState>(); TriGrid grid = TriGrid.Instance; TriCell cell = grid.GetCell(coord); int elev = cell.Elevation; ret.Add(new BuildState(cell.coordinates, cell.IsBuildable())); cell = grid.GetCell(coord).GetNeighbor(dir); ret.Add(new BuildState(cell.coordinates, cell.IsBuildable() && Mathf.Abs(cell.Elevation - elev) < 2)); return(ret); }
void CreateCell(int x, int z, int i) { Vector3 position; position.x = x * TriMetrics.innerRadius; position.y = 0f; position.z = z * TriMetrics.outerRadius * 1.5f - (0.5f * TriMetrics.outerRadius * ((x + z) % 2)); TriCell cell = cells[i] = Instantiate <TriCell>(cellPrefab); if ((x + z) % 2 == 0) { cell.inverted = true; } cell.coordinates = TriCoordinates.FromOffsetCoordinates(x, z); cell.Index = i; cell.transform.localPosition = position; if (x > 0) { if (cell.inverted) { cell.SetNeighbor(TriDirection.RIGHT, cells[i - 1]); } else { cell.SetNeighbor(TriDirection.LEFT, cells[i - 1]); } } if (z > 0 && !cell.inverted) { cell.SetNeighbor(TriDirection.VERT, cells[i - cellCountX]); } cell.Elevation = 0; labels.Add(Instantiate <Text>(cellLabelPrefab, cell.transform)); cell.uiRect = labels[i].rectTransform; labels[i].rectTransform.anchoredPosition = new Vector2(position.x, position.z); cell.gameObject.name = "TriCell " + x + ":" + z; AddCellToChunk(x, z, cell); }
public static new Person Load(BinaryReader reader) { Person ret = Instantiate((Person)TriIsleland.GetUnitPrefabs((int)UnitType.PERSON, 0)); TriCell tLoc = TriGrid.Instance.GetCell(TriCoordinates.Load(reader)); if (tLoc) { ret.Home = (Inn)tLoc.Statics; } tLoc = TriGrid.Instance.GetCell(TriCoordinates.Load(reader)); if (tLoc) { ret.Company = (Company)tLoc.Statics; } tLoc = TriGrid.Instance.GetCell(TriCoordinates.Load(reader)); if (tLoc) { ret.Work = tLoc.Statics; } return(ret); }
void CreateClimate() { climate.Clear(); ClimateData initialData = new ClimateData(); for (int i = 0; i < cellCount; i++) { climate.Add(initialData); } for (int cycle = 0; cycle < 40; cycle++) { for (int i = 0; i < cellCount; i++) { TriCoordinates t = grid.GetCell(i).coordinates; if (t == TriMetrics.TriToHex(t)) { EvolveClimate(i); } } } }
IEnumerator <WaitForEndOfFrame> CreateClimate() { climate.Clear(); ClimateData initialData = new ClimateData(); for (int i = 0; i < cellCount; i++) { climate.Add(initialData); } for (int cycle = 0; cycle < 40; cycle++) { for (int i = 0; i < cellCount; i++) { TriCoordinates t = grid.GetCell(i).coordinates; if (t == TriMetrics.TriToHex(t)) { EvolveClimate(i); } } } yield return(null); }
public static bool IsBuildable(TriDirection dir, TriCoordinates coord, SizeType sizeType) { switch (sizeType) { case SizeType.SINGLE: if (TriGrid.Instance.GetCell(coord).Statics) { return(false); } else { return(true); } case SizeType.HEX: TriCell cell = TriGrid.Instance.GetCell(coord); int elevation = cell.Elevation; TriCell k = cell; int elev = cell.Elevation; TriDirection tDir = dir.Previous(); for (int i = 0; i < 6; i++) { if (!k || !k.IsBuildable()) { return(false); } if (elev != k.Elevation) { return(false); } k = k.GetNeighbor(tDir); tDir = tDir.Next(); } return(true); default: return(false); } }
public override List <BuildState> GetBuildStatus(TriCoordinates coord, TriDirection dir) { List <BuildState> ret = new List <BuildState>(); TriCell k = TriGrid.Instance.GetCell(coord); int elev = k.Elevation; TriDirection tDir = dir.Previous(); for (int i = 0; i < 6; i++) { if (!k) { break; } ret.Add(new BuildState(k.coordinates, k.IsBuildable() && elev == k.Elevation)); k = k.GetNeighbor(tDir); tDir = tDir.Next(); } TriCell entrance = TriGrid.Instance.GetCell(coord).GetNeighbor(dir); ret.Add(new BuildState(entrance.coordinates, entrance.IsBuildable() && Mathf.Abs(entrance.GetNeighbor(dir).Elevation - elev) < 2)); return(ret); }
void CreateCell(int x, int z, int i) { Vector3 position; position.x = x * TriMetrics.innerRadius; position.y = 0f; position.z = z * TriMetrics.outerRadius * 1.5f - (0.5f * TriMetrics.outerRadius * ((x + z) % 2)); TriCell cell = cells[i] = new TriCell(); if ((x + z) % 2 == 0) { cell.inverted = true; } cell.coordinates = TriCoordinates.FromOffsetCoordinates(x, z); cell.Index = i; cell.position = position; if (x > 0) { if (cell.inverted) { cell.SetNeighbor(TriDirection.RIGHT, cells[i - 1]); } else { cell.SetNeighbor(TriDirection.LEFT, cells[i - 1]); } } if (z > 0 && !cell.inverted) { cell.SetNeighbor(TriDirection.VERT, cells[i - cellCountX]); } cell.Elevation = 0; AddCellToChunk(x, z, cell); }
public TriCell GetCell(TriCoordinates coord) { return(GetCell(coord.X, coord.Z)); }
TriCell GetRandomCell() { TriCoordinates t = TriMetrics.TriToHex(new TriCoordinates(Random.Range(xMin, xMax), Random.Range(zMin, zMax))); return(grid.GetCell(t.X, t.Z)); }
public void Load(string path) { ClearEntities(); using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "natural.dat")))) { int header = reader.ReadInt32(); if (header <= 0) { int counter = reader.ReadInt32(); for (int i = 0; i < counter; i++) { TriCoordinates coord = TriCoordinates.Load(reader); Natural loaded = Natural.Load(reader); if (loaded) { loaded.ID = i; loaded.Location = grid.GetCell(coord); loaded.transform.SetParent(NaturalGroup); AddNatural(loaded); loaded.validateRotation(); } } } else { Debug.LogWarning("Unknown naturals format " + header); } } using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "building.dat")))) { int header = reader.ReadInt32(); if (header <= 0) { int counter = reader.ReadInt32(); for (int i = 0; i < counter; i++) { TriCoordinates coord = TriCoordinates.Load(reader); Building loaded = Building.Load(reader); if (loaded) { loaded.ID = i; loaded.Location = grid.GetCell(coord); loaded.EntranceDirection = loaded.EntranceDirection; loaded.Location.Statics = loaded; loaded.transform.SetParent(BuildingGroup); AddBuilding(loaded); } } } else { Debug.LogWarning("Unknown building format " + header); } } using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "unit.dat")))) { int header = reader.ReadInt32(); if (header <= 0) { int counter = reader.ReadInt32(); for (int i = 0; i < counter; i++) { TriCoordinates coord = TriCoordinates.Load(reader); Unit loaded = Unit.Load(reader); if (loaded) { loaded.ID = i; loaded.Location = grid.GetCell(coord); if (grid.GetCell(coord).Statics) { loaded.GetIn((Building)grid.GetCell(coord).Statics); } loaded.transform.SetParent(UnitGroup); AddUnit(loaded); } } } else { Debug.LogWarning("Unknown unit format " + header); } } }
int RaiseTerrain(int chunkSize, int budget, bool initiated) { searchFrontierPhase += 1; TriCoordinates center = grid.GetCell(grid.cellCountX / 2, grid.cellCountZ / 2).coordinates; center = TriMetrics.TriToHex(center); TriCell firstCell = grid.GetCell(center.X, center.Z); if (initiated) { do { firstCell = GetRandomCell(); } while (firstCell.Elevation < 1); } searchFrontier.Enqueue(firstCell); center = firstCell.coordinates; checker.Add(center); int size = 0; while (size < chunkSize && searchFrontier.Count > 0) { TriCell current = searchFrontier.Dequeue(); if (current.Elevation < elevationMaximum) { TriDirection d = TriDirection.VERT; TriCell k = current; if (k.Elevation < elevationMaximum) { if (k.Elevation == 0) { budget -= 6; } for (int i = 0; i < 6; i++) { if (!k) { break; } k.Elevation += 1; k = k.GetNeighbor(d); if (current.inverted) { d = d.Next(); } else { d = d.Previous(); } } } } if (current.Elevation == 1 && budget == 0) { break; } size += 6; TriCoordinates coord = current.coordinates; for (int i = 0; i < 4; i++) { TriCell neighbor = grid.GetCell(coord.X + TriMetrics.hexDir[i, 0], coord.Z + TriMetrics.hexDir[i, 1]); if (neighbor && checkbounds(neighbor.coordinates) && !checker.Contains(neighbor.coordinates) && (i == 3 || Random.value < jitterProbability ? true : false)) { searchFrontier.Enqueue(neighbor); checker.Add(neighbor.coordinates); } } } searchFrontier.Clear(); checker.Clear(); return(budget); }
public static new DestroyCommand Load(BinaryReader reader) { return(new DestroyCommand(TriGrid.Instance.GetCell(TriCoordinates.Load(reader)).Statics)); }
public static new MoveCommand Load(BinaryReader reader) { return(new MoveCommand(TriGrid.Instance.GetCell(TriCoordinates.Load(reader)), reader.ReadBoolean(), reader.ReadBoolean())); }
public BuildState(TriCoordinates coord, bool value) { this.coord = coord; this.value = value; }
public static new GetInCommand Load(BinaryReader reader) { return(new GetInCommand((Building)TriGrid.Instance.GetCell(TriCoordinates.Load(reader)).Statics)); }
public static TriCoordinates TriToHex(TriCoordinates coord) { return(new TriCoordinates(coord.X - coord.X % 3, coord.Z - coord.Z % 2)); }
public int DistanceTo(TriCoordinates other) { return(2 * ((x < other.x)?(other.x - x):(x - other.x)) + ((z < other.z)?(other.z - z):(z - other.z))); }
public static new ChangeJobCommand Load(BinaryReader reader) { return(new ChangeJobCommand((Company)TriGrid.Instance.GetCell(TriCoordinates.Load(reader)).Statics)); }