/// <summary> /// Constructor of the Party class. /// </summary> /// <param name="grid">Reference to the HexGrid class.</param> public Party (HexGrid grid, PartyManager manager) { PartyId = parties++; _grid = grid; _partyManager = manager; _hexes = new List<AxialCoordinate>(); _partyColor = new Color(Random.Range(0.1f, 0.6f), Random.Range(0.1f, 0.6f), Random.Range(0.1f, 0.6f)); }
public ByteMapper(HexGrid destination_hex_grid) { byte_offset = 0; byte_address = 0; lowest_byte_address = 99999; highest_byte_address = 0; hex_grid = destination_hex_grid; }
/// <summary> /// Constructor of the party manager. /// </summary> /// <param name="grid">Reference to the HexGrid class.</param> /// <param name="amountOfParties">How many parties should we make.</param> public PartyManager(HexGrid grid, HexPathFinding path, UIManager ui, byte amountOfParties) { AmountOfParties = amountOfParties; _grid = grid; _path = path; _ui = ui; CreateParties(); _ui.SetTurnIndicator(parties[_currentParty].GetPartyColor()); }
public HexTile() { hexGrid = GameObject.Find ("Grid").GetComponent<HexGrid> (); isSelect = false; isNewHazard = false; isArmedHazard = false; isZone = false; hasXAllies = 0; xCoord = 0; yCoord = 0; }
public void Init() { var oldgrid = grid; switch (shape) { case GridShape.Hexagonal: grid = new HexGrid(HexGrid.HexagonalShape(size)); break; case GridShape.Triangle: grid = new HexGrid(HexGrid.TriangularShape(size)); break; case GridShape.Trapeze: grid = new HexGrid(HexGrid.TrapezoidalShape(0, size, 0, size, HexGrid.OddQToCube)); break; } if (oldgrid != null) { grid.orientation = oldgrid.orientation; grid.scale = oldgrid.scale; } }
public static void LoadFile(string file_to_open, HexGrid dest_hex_grid) { string line_string; int line_count = 0; ByteMapper hex_byte_map = new ByteMapper(dest_hex_grid); HexLine hxp = new HexLine(hex_byte_map); StreamReader sr = new StreamReader(file_to_open); dest_hex_grid.Clear(); /* read a line into the hex line parser */ while (!sr.EndOfStream) { line_string = sr.ReadLine(); hxp.ProcessLine(line_string); line_count++; } sr.Close(); dest_hex_grid.UpdateNumRows(); }
public void EndOfMap(HexGrid hex_grid) { /* int address_range, num_rows; int num_columns = 16; int i; ByteEntry be; address_range = (int)highest_byte_address - (int)lowest_byte_address + 1; num_rows = (address_range / num_columns); if ((address_range % num_columns) > 0) num_rows++; hex_grid.DataGridInit(num_rows, num_columns, (int)lowest_byte_address); for (i = 0; i < ItemList.Count; i++) { be = (ByteEntry)ItemList[i]; hex_grid.DataGridSetAddressValue((int)lowest_byte_address, (int)be.address, be.byte_val, num_columns); } */ }
public void Compare(HexGrid hex_grid_1, HexGrid hex_grid_2) { int start_address; int end_address; int i; int address_1; int address_2; bool all_equal = true; if (hex_grid_1.StartAddress() < hex_grid_2.StartAddress()) start_address = hex_grid_1.StartAddress(); else start_address = hex_grid_2.StartAddress(); if (hex_grid_1.EndAddress() > hex_grid_2.EndAddress()) end_address = hex_grid_1.EndAddress(); else end_address = hex_grid_2.EndAddress(); for (i = start_address; i <= end_address; i++) { address_1 = hex_grid_1.GetByteInt(i); address_2 = hex_grid_2.GetByteInt(i); if (address_1 != address_2) { hex_grid_1.AddCompareResult(i, false); hex_grid_2.AddCompareResult(i, false); all_equal = false; } } if (all_equal == true) { MessageBox.Show("Files are identical.", "Compare Results", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public override void CreateFromData(TowerData td, HexGrid grid) { GridPosition = td.GridPosition; Place(grid); }
public IEnumerator TestMovementOfSpaceShip() { SceneManager.LoadScene("MainMenuScene"); yield return(new WaitForSeconds(1)); if (!SceneManager.GetActiveScene().name.Equals("MainMenuScene")) { Assert.Fail(); } MainMenuSceneInit initializer = GameObject.Find("Initializer").GetComponent <MainMenuSceneInit>(); if (initializer == null) { Assert.Fail(); } initializer.ChangeScene("NewGameMapScene"); yield return(new WaitForSeconds(1)); if (!SceneManager.GetActiveScene().name.Equals("NewGameMapScene")) { Assert.Fail(); } GameApp gameApp = GameObject.Find("GameApp").GetComponent <GameApp>(); if (gameApp == null) { Assert.Fail(); } gameApp.PersistAllParameters(SceneManager.GetActiveScene().name); gameApp.Parameters.Remove("ServerAddress"); gameApp.Parameters.Remove("ServerPort"); gameApp.Parameters.Add("ServerAddress", "127.0.0.1"); gameApp.Parameters.Add("ServerPort", "9999"); LevelLoader levelLoader = GameObject.Find("LevelLoader").GetComponent <LevelLoader>(); if (levelLoader == null) { Assert.Fail(); } levelLoader.LoadLevel("NewGameScene"); yield return(new WaitForSeconds(1)); if (!SceneManager.GetActiveScene().name.Equals("NewGameScene")) { Assert.Fail(); } NewGameSceneInit newGameSceneInit = GameObject.Find("Initializer").GetComponent <NewGameSceneInit>(); if (newGameSceneInit == null) { Assert.Fail(); } newGameSceneInit.AddPlayer(); newGameSceneInit.AddPlayer(); List <GameApp.PlayerMenu> playerMenuList = new List <GameApp.PlayerMenu>(); GameApp.PlayerMenu player1 = new GameApp.PlayerMenu { name = "player1", password = "******", race = "human", playerType = "L" }; GameApp.PlayerMenu player2 = new GameApp.PlayerMenu { name = "player12", password = "******", race = "human", playerType = "L" }; playerMenuList.Add(player1); playerMenuList.Add(player2); gameApp.SavePlayersFromMenu(playerMenuList); ServerNetworkManager serverNetworkManager = GameObject.Find("ServerNetworkManager").GetComponent <ServerNetworkManager>(); serverNetworkManager.SetupNewGame(); yield return(new WaitForSeconds(1)); GameController gameController = GameObject.Find("GameController").GetComponent <GameController>(); if (gameController == null) { Assert.Fail(); } GameObject gameObjectspaceShip = GameObject.Find("Scout-1"); Spaceship spaceShip = gameObjectspaceShip.GetComponent <Spaceship>(); if (spaceShip == null || gameObjectspaceShip == null) { Assert.Fail(); } Debug.Log("1. I am here " + spaceShip.transform.localPosition); HexGrid grid = (GameObject.Find("HexGrid").GetComponent <HexGrid>()); if (grid == null) { Assert.Fail(); } Vector3 vector = new Vector3(310.0f, 0.0f, 270.0f); HexCoordinates destination = HexCoordinates.FromPosition(vector); spaceShip.Destination = destination; EventManager.selectionManager.SelectedObject = gameObjectspaceShip; yield return(new WaitForSeconds(3)); grid.TouchCell(vector); yield return(new WaitForSeconds(3)); yield return(null); }
public static void RenderHex(HexPoint pos, List <HexData> types, HexLayout layout, Color color, int frameCount, HexGrid <Hex> grid = null) { types = types.OrderBy(x => x.ID).ToList(); for (int i = 0; i < types.Count; i++) { int animation = 0; int connection = 0; if (types[i].RenderFlags.HasFlag(RenderFlags.Animated) && types[i].AnimationLength != 0 && types[i].AnimationSpeed != 0) { animation = ((frameCount + types[i].AnimationPhase) / types[i].AnimationSpeed) % types[i].AnimationLength; } if (grid != null && types[i].RenderFlags.HasFlag(RenderFlags.Connected)) { HexPoint[] directions = { new HexPoint(1, 0), // E 1 new HexPoint(1, -1), // NE 2 new HexPoint(0, -1), // NW 4 new HexPoint(-1, 0), // W 8 new HexPoint(-1, 1), // SW 16 new HexPoint(0, 1), // SE 32 }; for (int j = 0; j < 6; j++) { if (grid[pos + directions[j]].HasValue && grid[pos + directions[j]].Value.IDs.Contains(types[i].ID)) { connection += 1 << j; } } } TextureRenderer.DrawHex(Textures.Get($"Hex\\{types[i].Texture}"), pos, layout, Vector2.One * layout.size, color, new RectangleF(32 * connection, animation * 32, 32, 32)); } }
protected virtual List <HexTile> OtherTilesToExplodeAtPosition(HexGrid grid, float x, float y, float radius) { List <HexTile> toDestroy = new List <HexTile>(); return(toDestroy); }
public HexHintList(HexGrid grid) { Grid = grid; }
public abstract List <HexCell> GetCellsInRange(HexGrid grid);
/// <summary> /// Finds an HexObject component with the same cube coorinates /// </summary> /// <param name="q">Represents the X position</param> /// <param name="r">Represents the Y position</param> /// <param name="s">Represents the Z position</param> /// <returns>HexObject Component</returns> public static HexObject FindHexObject(this HexGrid Instance, double q, double r, double s) { return(Instance.FindHexObject(new CubeCoord(q, r, s)) ?? null); }
// Use this for initialization void Start() { //this will be adapted into level selecting logic _currentBoard = (HexGrid)ScriptableObject.CreateInstance("HexGrid"); }
/// <summary> /// Gets all the Hexes in a range around the position in cube coord /// </summary> /// <param name="q">X value in a cube coord</param> /// <param name="r">Y value in a cube coord</param> /// <param name="s">Z value in a cube coord</param> /// <param name="range">The amount of tiles away to be included</param> /// <returns></returns> public static List <Hex> HexesInRange(this HexGrid Instance, double q, double r, double s, int range) { return(HexesInRange(Instance, new Hex(q, r, s), range)); }
/// <summary> /// Finds an HexObject component with the same cube coordinates /// </summary> /// <param name="c">The location of the tile you want in cubecoords</param> /// <returns>HexObject Component</returns> public static HexObject FindHexObject(this HexGrid Instance, CubeCoord c) { //return Instance.Hexes.ToList().Find(h => h.Hex.cubeCoords == c); return(Instance.Hexes.Where(h => h.Hex.cubeCoords == c).FirstOrDefault()); }
public AtomFinder(HexGrid grid) { m_grid = grid; }
public AStar(HexGrid world, GameTile destination) { this.world = world; this.destination = destination; }
public void CalcTopo() { for (int i = 0; i < verts.Count; i++) { verts[i] = new Vector3(verts[i].x, heights[i] * HexGrid.tileHeight, verts[i].z); } //find lowest height int level = 1000; foreach (int i in heights) { if (i < level) { level = i; } } //move all heights down so the lowest is 0 for (int i = 0; i < heights.Count; i++) { heights[i] -= level; } //list of distances between opposing verts dis = new List <float> { (float)System.Math.Round(Vector3.Distance(verts[0], verts[3]), 3), (float)System.Math.Round(Vector3.Distance(verts[1], verts[4]), 3), (float)System.Math.Round(Vector3.Distance(verts[2], verts[5]), 3) }; //find highest height float highest = 0; foreach (float h in heights) { if (h > highest) { highest = h; } } //calc topo //flat if (highest == 0) { flat = true; tris = new List <int> { 0, 1, 2, 0, 2, 3, 0, 3, 5, 3, 4, 5 }; if (verts[0].y > 0.25f && Random.Range(0, 2) == 0) { Vector3 loc = HexGrid.GridToWorld(gridLoc); loc.y = verts[0].y; flat = true; } } if (flat) { BuildingController.Instance.flatLand.Add(gridLoc); } else if (Mathf.Approximately(dis[0], dis[1]) && Mathf.Approximately(dis[0], dis[2])) { for (int i = 0; i < 6; i++) { if (heights[i] == 0 && heights[HexGrid.MoveDirFix(i + 1)] == 0 && heights[HexGrid.MoveDirFix(i + 2)] == 0) { tris.AddRange(new List <int> { i, i + 1, i + 2, i, i + 2, i + 3, i, i + 3, i + 5, i + 3, i + 4, i + 5 }); } } } else if (dis[0] < dis[1] && dis[0] < dis[2]) { if (Vector3.Distance(verts[0], verts[2]) < Vector3.Distance(verts[1], verts[3])) { tris.AddRange(new List <int> { 0, 1, 2, 0, 2, 3 }); } else { tris.AddRange(new List <int> { 0, 1, 3, 1, 2, 3 }); } if (Vector3.Distance(verts[0], verts[4]) < Vector3.Distance(verts[3], verts[5])) { tris.AddRange(new List <int> { 0, 3, 4, 0, 4, 5 }); } else { tris.AddRange(new List <int> { 0, 3, 5, 3, 4, 5 }); } } else if (dis[1] < dis[0] && dis[1] < dis[2]) { if (Vector3.Distance(verts[1], verts[3]) < Vector3.Distance(verts[2], verts[4])) { tris.AddRange(new List <int> { 1, 2, 3, 1, 3, 4 }); } else { tris.AddRange(new List <int> { 1, 2, 4, 2, 3, 4 }); } if (Vector3.Distance(verts[1], verts[5]) < Vector3.Distance(verts[4], verts[0])) { tris.AddRange(new List <int> { 1, 4, 5, 1, 5, 0 }); } else { tris.AddRange(new List <int> { 1, 4, 0, 4, 5, 0 }); } } else if (dis[2] < dis[0] && dis[2] < dis[1]) { if (Vector3.Distance(verts[2], verts[4]) < Vector3.Distance(verts[3], verts[5])) { tris.AddRange(new List <int> { 2, 3, 4, 2, 4, 5 }); } else { tris.AddRange(new List <int> { 2, 3, 5, 3, 4, 5 }); } if (Vector3.Distance(verts[2], verts[0]) < Vector3.Distance(verts[5], verts[1])) { tris.AddRange(new List <int> { 2, 5, 0, 2, 0, 1 }); } else { tris.AddRange(new List <int> { 2, 5, 1, 5, 0, 1 }); } } else if (dis[0] == dis[1] && dis[2] > dis[0] && (heights[0] == heights[1] || heights[0] == heights[4])) { tris.AddRange(new List <int> { 1, 2, 3, 1, 3, 4, 1, 4, 0, 0, 4, 5 }); } else if (dis[1] == dis[2] && dis[0] > dis[1] && (heights[1] == heights[2] || heights[1] == heights[5])) { tris.AddRange(new List <int> { 0, 1, 5, 5, 1, 2, 5, 2, 4, 2, 3, 4 }); } else if (dis[2] == dis[0] && dis[1] > dis[2] && (heights[2] == heights[0] || heights[2] == heights[0])) { tris.AddRange(new List <int> { 0, 1, 2, 0, 2, 3, 0, 3, 5, 3, 4, 5 }); } else { tris.AddRange(new List <int> { 0, 1, 2, 0, 2, 3, 0, 3, 5, 3, 4, 5 }); } for (int j = 0; j < tris.Count; j++) { tris[j] = HexGrid.MoveDirFix(tris[j]); } uvs = new List <Vector2> { new Vector2(0.5f, 1), new Vector2(0.9375f, 0.75f), new Vector2(0.9375f, 0.25f), new Vector2(0.5f, 0), new Vector2(0.0625f, 0.25f), new Vector2(0.0625f, 0.75f) }; if (tris.Count != 12) { tris = new List <int> { 0, 1, 2, 0, 2, 3, 0, 3, 5, 3, 4, 5 } } ; foreach (Vector3 v in verts) { h += v.y; } h /= 6f; } }
void Start() { hexGrid = this; }
public static HexObject FindHexObject(this HexGrid Instance, Hex hex) { return(Instance.Hexes.Where(h => h.Hex == hex).FirstOrDefault()); }
void Awake() { hexGrid = FindObjectOfType <HexGrid>(); }
/// <summary> /// Gets all the Hexes in a range around the coord /// </summary> /// <param name="coord">The position in Cube Coord to check around</param> /// <param name="range">The amount of tiles away to be included</param> /// <returns>A List of the Hexes</returns> public static List <Hex> HexesInRange(this HexGrid Instance, CubeCoord coord, int range) { return(HexesInRange(Instance, new Hex(coord), range)); }
public static void Load(BinaryReader reader, GameController gameController, HexGrid grid, int header) { }
public void initAlly(int x, int y) { hexGrid = GameObject.Find ("Grid").GetComponent<HexGrid> (); xCoord = x; yCoord = y; isEdge (); getNextXY (); isSaved = false; hasMoved = false; }
public int toIndex(HexGrid grid) { return(X + Z * grid.CellCountX + Z / 2); }
public Hex(HexGrid grid, CubeCoordinates coordinates, Color color = Color.White) { this.grid = grid; this.coordinates = coordinates; Color = color; }
public GridRenderer(HexGrid <Hex> grid, HexLayout layout) { Grid = grid; Layout = layout; }
public override void _select_cb(HexGrid caller) { caller.set_build_state (); this.Status = State.WAIT_FOR_ORDERS; gm.display_build_or_move (this); }
public List <HexTile> OtherTilesToExplode(HexGrid grid) { List <HexTile> toDestroy = new List <HexTile>(); return(toDestroy); }
public UnitHighlightEngine(HexGrid mapManager) { _mapManager = mapManager; }
private IEnumerable <HexagonCell> GetCells(HexGrid grid) { return(grid.Select(p => p.Value)); }
void Start() { Instance = this; DoneGenerating = false; Ports = new List<Port>(); LandTiles = new List<LandHex>(); WaterTiles = new List<WaterHex>(); HexWidth = WaterHexPrefab.GetComponent<MeshRenderer>().bounds.size.x; SettingsManager settings = SettingsManager.Instance; GridWidth = settings.MapWidth; GridHeight = settings.MapHeight; Random.seed = settings.MapSeed; controlPoints = settings.MapControlPoints; GenerateGrid(GridWidth, GridHeight, controlPoints); }
// Start is called before the first frame update void Start() { rb = gameObject.GetComponent <Rigidbody>(); map = FindObjectOfType <HexGrid>(); currentLocation = map.getTile(0, 0); }
public void select(HexGrid caller) { if (state == State.DONE) { return; } _select_cb (caller); caller.select_ (this); }
public override void _select_cb(HexGrid caller) { this.state = State.DONE; grid.state_change (this); }
public virtual void _select_cb(HexGrid caller) { }
void SetGrid(HexGrid grid) { this.grid = grid; grid.SendMessage("AddUnit", this); }
// Use this for initialization void Start() { hexGrid = GameObject.Find("HexGrid").GetComponent <HexGrid>(); movementScript = GameObject.Find("HexGrid").GetComponent <MovementScript>(); lineRenderer = GetComponent <LineRenderer>(); }
public void SetGrid(HexGrid grid) { this.grid = grid; grid.SendMessage ("AddUnit", this); }
private void Awake() { locked = 0; grid = GameObject.FindWithTag("Grid").GetComponent <HexGrid>(); //于沛琦加,绑定地图探索text MapExplore = GameObject.FindWithTag("MapExplore").GetComponent <Text>(); ExplorePic = GameObject.FindWithTag("ExplorePic").GetComponent <Image>(); ExplorePic.fillAmount = 0.0f; //于沛琦加end //方政言加,为实现网格内容探测 gridcontent = GameObject.FindWithTag("Grid").GetComponent <GridContent>(); //方政言加end camera = GameObject.FindWithTag("MainCamera").GetComponent <CameraController>(); if (camera == null) { Debug.Log("camera not set"); } myInput = camera.GetComponent <MyInput>(); //设定初始格,并修改颜色 int index; //for (int i = 0; i < grid.height; i++) //{ // if (i == 0 || i == grid.height - 1) // { // for (int j = 0; j < grid.width; j++) // { // index = i * grid.height + j; // Cell = grid.cells[index]; // Cell.color = grid.CellColor[4]; // grid.hexMesh.Triangulate(grid.cells); // } // } // else // { // index = i * grid.height; // Cell = grid.cells[index]; // Cell.color = grid.CellColor[4]; // grid.hexMesh.Triangulate(grid.cells); // index = (i + 1) * grid.height - 1; // Cell = grid.cells[index]; // Cell.color = grid.CellColor[4]; // grid.hexMesh.Triangulate(grid.cells); // grid.hexMesh.Triangulate(grid.cells); // } //} index = 2 + 5 * grid.width + 5 / 2; CurrentCell = grid.cells[index]; CurrentCell.color = grid.CellColor[1]; grid.hexMesh.Triangulate(grid.cells); UpdateArround(CurrentCell, CurrentCellAround, CurrentTextAround); PrintArround(grid.CellColor[2], CurrentCellAround); playerPos = grid.cells[index].transform.position; //方政言加,为实现网格内容探测 CurrentText = index; gridcontent.start(CurrentText, CurrentTextAround); gridcontent.detectAround(CurrentTextAround); viewportalflag = false; viewsiflag = false; //方政言加end }
void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Input.GetMouseButtonDown(0)) { if (!mouseOverGUI && Physics.Raycast(ray, out hit, 50, unitMask)) { if (hit.transform.GetComponent <UnitAvatar>() != null) { selection = hit.transform; selection.GetComponent <SphereCollider>().enabled = false; oldGridLoc = HexGrid.RoundToGrid(hit.point); } } } if (Input.GetMouseButton(0)) { if (!mouseOverGUI && Physics.Raycast(ray, out hit, 50, groundMask) && selection != null) { selection.transform.position = hit.point; newGridLoc = HexGrid.RoundToGrid(hit.point); } } if (Input.GetMouseButtonUp(0)) { if (selection != null) { if (Physics.Raycast(ray, out hit, 50, groundMask)) { if (hit.point.z >= 0) { if (HexGrid.GridToWorld(oldGridLoc).z >= 0) { selection.transform.position = HexGrid.GridToWorld(oldGridLoc); } else { } } else { if (Physics.Raycast(ray, out hit, 50, tileMask)) { } else { Unit unit = selection.GetComponent <UnitAvatar>().unit; ArmyDisplay.Instance.army.AddSquad(unit); } } } if (selection != null) { selection.GetComponent <SphereCollider>().enabled = true; selection = null; } } } }
public override List <HexCell> GetCellsInArea(HexGrid grid, HexCell cell) { return(grid.SearchInRange(cell, horizontal, true)); }