public override void OnInspectorGUI() { HexTransform hex = target as HexTransform; VectorRGB value; /*SerializedProperty _quad = serializedObject.FindProperty ("_cachedLocalQuadPos"); * SerializedProperty _hex = serializedObject.FindProperty ("_cachedLocalHexPos"); * * if (_quad.vector2Value != (Vector2)hex.transform.position) { * _quad.vector2Value = (Vector2)hex.transform.position; * VectorRGBDrawer.ToProperty(_hex, (VectorRGB)hex.transform.position); * } * * EditorGUI.BeginChangeCheck (); * EditorGUILayout.PropertyField (_hex, new GUIContent ("Position"), true); * if (EditorGUI.EndChangeCheck()){ * var quadPos = (Vector2)VectorRGBDrawer.FromProperty (_hex); * _quad.vector2Value = quadPos; * hex.transform.position = new Vector3 ( * quadPos.x, * quadPos.y, * hex.transform.position.z * ); * }/**/ EditorGUI.BeginChangeCheck(); value = VectorRGBDrawer.VectorRGBFieldLayout(hex.localPositionCached.balanced, new GUIContent("Position")); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(hex, "Hex Position change"); hex.localPositionRaw = value; } /**/ }
// algorithm obtained from Red Blobs Games' Hexagons blog: http://www.redblobgames.com/grids/hexagons/ public List <HexTile> GetHexRing(HexTile Center, int Radius) { // reduce the radius to match our numerical system. Radius -= 1; List <HexTile> RetList = new List <HexTile>(); if (Radius == 0) { RetList.Add(Center); return(RetList); } HexTransform CurrentLoc = new HexTransform(Center.hexTransform.Position); CurrentLoc.Position += Radius * HexCubeDirections[4]; for (int i = 0; i < 6; ++i) { for (int j = 0; j < Radius; ++j) { if (CurrentLoc.validateOddQ()) { RetList.Add(MapGenerator.Map[(int)CurrentLoc.RowColumn.x, (int)CurrentLoc.RowColumn.y]); } CurrentLoc.Position += HexCubeDirections[i]; } } return(RetList); }
public KalamataTicket(Products product, BaseBuilding productOwner, float reservationID) { Product = product; ProductOwner = productOwner; ProductPosition = ProductOwner.hexTransform; ReservationID = reservationID; }
/// <summary> /// Configure the tile parameters using columna nd row data. /// </summary> /// <param name="q">The Column of the tile.</param> /// <param name="r">The Row of the tile.</param> public void ConfigureTile(int q, int r) { hexTransform = new HexTransform(q, r); SetTexture(TerrainTypes.Sea); TerrainType = TerrainTypes.Sea; ASI = new AStarInfo <HexTile>(this, 1); }
public bool validateOddQ(HexTransform testCon) { //X, Z + (X - (X & 1)) / 2 testCon.RowColumn.x = testCon.Position.x; testCon.RowColumn.y = testCon.Position.z + (testCon.Position.x - ((int)testCon.Position.x & 1)) / 2; if (testCon.RowColumn.x >= 0 && testCon.RowColumn.x < MapGenerator.Map.GetLength(0) && testCon.RowColumn.y >= 0 && testCon.RowColumn.y < MapGenerator.Map.GetLength(1)) { return(true); } return(false); }
public int GetConnections() { ASI.Connections.Clear(); HexTransform testCon = new HexTransform(0, 0); testCon = testCon.CubetoOddQ(hexTransform.Position.x + 1, hexTransform.Position.y, hexTransform.Position.z - 1); if (testCon.validateOddQ()) { ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI); } testCon = testCon.CubetoOddQ(hexTransform.Position.x + 1, hexTransform.Position.y, hexTransform.Position.z); if (testCon.validateOddQ()) { ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI); } testCon = testCon.CubetoOddQ(hexTransform.Position.x, hexTransform.Position.y, hexTransform.Position.z + 1); if (testCon.validateOddQ()) { ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI); } testCon = testCon.CubetoOddQ(hexTransform.Position.x - 1, hexTransform.Position.y, hexTransform.Position.z + 1); if (testCon.validateOddQ()) { ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI); } testCon = testCon.CubetoOddQ(hexTransform.Position.x - 1, hexTransform.Position.y, hexTransform.Position.z); if (testCon.validateOddQ()) { ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI); } testCon = testCon.CubetoOddQ(hexTransform.Position.x, hexTransform.Position.y, hexTransform.Position.z - 1); if (testCon.validateOddQ()) { ASI.Connections.Add(MapGenerator.Map[(int)testCon.RowColumn.x, (int)testCon.RowColumn.y].ASI); } return(ASI.Connections.Count); }
/// <summary> /// /// </summary> /// <param name="MyPos"></param> /// <param name="products"></param> /// <returns>A list of products and their locations, empty if no products were found.</returns> public List <KalamataTicket> ReserveProducts(HexTransform MyPos, params Products[] products) { List <KalamataTicket> productTickets = new List <KalamataTicket>(); List <Products> remainingProducts = new List <Products>(); remainingProducts.AddRange(products); // search buildings. foreach (BaseBuilding building in BuildingsList) { productTickets.AddRange(building.GetTicketForProducts(ref remainingProducts)); if (remainingProducts.Count == 0) { break; } } return(productTickets); }
public List <GOAPState> GetWorldState() { List <GOAPState> worldState = new List <GOAPState>() { new GOAPState("Has Target", new List <object> { (target != null) }), new GOAPState("Target in Range", new List <object> { (target.GetType() == typeof(GameEntity)) ? (HexTransform.CalcHexManhattanDist(MapGenerator.Map[(int)hexTransform.RowColumn.x, (int)hexTransform.RowColumn.y].ASI, MapGenerator.Map[(int)target.GetComponent <GameEntity>().hexTransform.RowColumn.x, (int)target.GetComponent <GameEntity>().hexTransform.RowColumn.y].ASI) <= attackRange) : false }), new GOAPState("Target is Enemy", new List <object> { (target.GetType() == typeof(GameEntity)) ? (target.GetComponent <GameEntity>().TeamID != TeamID) : false }), new GOAPState("Target is Tile", new List <object> { target.GetType() == typeof(HexTile) }), new GOAPState("Has Path", new List <object> { (path.Count > 0) }) }; return(worldState); }
/// <summary> /// Calculates the Hex Manhatton distance from this tile to the specified tile. /// </summary> /// <param name="TargetTile">The tile you want to find the distance to.</param> /// <returns></returns> public int CalcHexManhattanDist(HexTransform TargetTile) { return((int)((Mathf.Abs(TargetTile.Position.x - Position.x) + Mathf.Abs(TargetTile.Position.y - Position.y) + Mathf.Abs(TargetTile.Position.z - Position.z)) / 2f)); }
float DistanceToTarget() { return((float)HexTransform.CalcHexManhattanDist(MapGenerator.Map[(int)unit.hexTransform.RowColumn.x, (int)unit.hexTransform.RowColumn.y].ASI, MapGenerator.Map[(int)unit.DestinationBuilding.hexTransform.RowColumn.x, (int)unit.DestinationBuilding.hexTransform.RowColumn.y].ASI)); }
public void ConfigureBuilding(int Q, int R, int teamID) { hexTransform = new HexTransform(Q, R); Health = MaxHealth; TeamID = teamID; }