Esempio n. 1
0
    // Rivers
    void TriangulateWithRiver(HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e)
    {
        Vector3 centerL, centerR;

        if (cell.HasRiverThroughEdge(direction.Opposite()))
        {
            // Left Vertex
            centerL = center + HexMetrics.GetFirstSolidCorner(direction.Previous()) * 0.25f;
            // Right Vertex
            centerR = center + HexMetrics.GetSecondSolidCorner(direction.Next()) * 0.25f;
        }
        else if (cell.HasRiverThroughEdge(direction.Next()))
        {
            centerL = center;
            centerR = Vector3.Lerp(center, e.v5, 2f / 3f);
        }
        else if (cell.HasRiverThroughEdge(direction.Previous()))
        {
            centerL = Vector3.Lerp(center, e.v1, 2f / 3f);
            centerR = center;
        }
        else if (cell.HasRiverThroughEdge(direction.Next2()))
        {
            centerL = center;
            centerR = center + HexMetrics.GetSolidEdgeMiddle(direction.Next()) * (0.5f * HexMetrics.innerToOuter);
        }
        else
        {
            centerL = center + HexMetrics.GetSolidEdgeMiddle(direction.Previous()) * (0.5f * HexMetrics.innerToOuter);
            centerR = center;
        }
        center = Vector3.Lerp(centerL, centerR, 0.5f);

        // Middle Line
        EdgeVertices m = new EdgeVertices(
            Vector3.Lerp(centerL, e.v1, 0.5f),
            Vector3.Lerp(centerR, e.v5, 0.5f),
            1f / 6f);

        // Channel bottoms
        m.v3.y = center.y = e.v3.y;

        TriangulateEdgeStrip(m, cell.Color, e, cell.Color);

        terrain.AddTriangle(centerL, m.v1, m.v2);
        terrain.AddTriangleColor(cell.Color);
        terrain.AddQuad(centerL, center, m.v2, m.v3);
        terrain.AddQuadColor(cell.Color);
        terrain.AddQuad(center, centerR, m.v3, m.v4);
        terrain.AddQuadColor(cell.Color);
        terrain.AddTriangle(centerR, m.v4, m.v5);
        terrain.AddTriangleColor(cell.Color);

        if (!cell.IsUnderwater)
        {
            bool reversed = cell.IncomingRiver == direction;
            TriangulateRiverQuad(centerL, centerR, m.v2, m.v4, cell.RiverSurfaceY, 0.4f, reversed);
            TriangulateRiverQuad(m.v2, m.v4, e.v2, e.v4, cell.RiverSurfaceY, 0.6f, reversed);
        }
    }
Esempio n. 2
0
    /// <summary>
    /// 设置流出河流
    /// </summary>
    /// <param name="direction"></param>
    public void SetOutgoingRiver(HexDirection direction)
    {
        if (hasOutgoingRiver && outgoingRiver == direction)
        {
            return;
        }
        //指定方向必须有邻居并且高度不高于当前单元
        HexCell neighbor = GetNeighbor(direction);

        if (!IsValidRiverDestination(neighbor))
        {
            return;
        }

        RemoveOutgoingRiver();
        if (hasIncomingRiver && incomingRiver == direction)
        {
            RemoveIncomingRiver();
        }

        hasOutgoingRiver = true;
        outgoingRiver    = direction;

        //添加河流时删除单元内的特殊地形
        specialIndex = 0;

        //设置相应方向邻居的流入河流
        neighbor.RemoveIncomingRiver();
        neighbor.hasIncomingRiver = true;
        neighbor.incomingRiver    = direction.Opposite();

        //设置河流时删除覆盖道路
        SetRoad((int)direction, false);
    }
Esempio n. 3
0
    public void SetOutgoingRiver(HexDirection direction)
    {
        if (hasOutgoingRiver && outgoingRiver == direction)
        {
            return;
        }

        HexCell neighbor = GetNeighbor(direction);

        if (!neighbor || elevation < neighbor.elevation)
        {
            return;
        }

        RemoveOutgoingRiver();

        if (hasIncomingRiver && incomingRiver == direction)
        {
            RemoveIncomingRiver();
        }

        hasOutgoingRiver = true;
        outgoingRiver    = direction;
        neighbor.RemoveIncomingRiver();
        neighbor.hasIncomingRiver = true;
        neighbor.incomingRiver    = direction.Opposite();
        SetRoad((int)direction, false);
    }
Esempio n. 4
0
    public void SetOutGoingRiver(HexDirection direction)
    {
        if (hasOutGoingRiver && outGoingRiver == direction)
        {
            return;
        }

        HexCell neighbor = GetNeighbor(direction);

        if (!neighbor || elevation < neighbor.elevation)
        {
            return;
        }

        RemoveOutGoingRiver();
        if (hasIncomingRiver && incomingRiver == direction)
        {
            RemoveInComingRiver();
        }

        hasOutGoingRiver = true;
        outGoingRiver    = direction;
        RefreshSelfOnly();

        neighbor.RemoveInComingRiver();
        neighbor.hasIncomingRiver = true;
        neighbor.incomingRiver    = direction.Opposite();
        neighbor.RefreshSelfOnly();
    }
    /// <summary>
    /// Sets the outgoing river in the given direction. The neighbor in that direction gets an incoming river.
    /// </summary>
    public void SetOutgoingRiver(HexDirection direction)
    {
        // If already has a outgoing river bail out
        if (hasOutgoingRiver && outgoingRiver == direction)
        {
            return;
        }

        HexCell neighbor = GetNeighbor(direction);

        if (!IsValidRiverDestination(neighbor))
        {
            return;
        }

        RemoveOutgoingRiver();         // Remove previous if any
        if (hasIncomingRiver && incomingRiver == direction)
        {
            RemoveIncomingRiver();             // Remove previous
        }

        hasOutgoingRiver = true;
        outgoingRiver    = direction;
        specialIndex     = 0;           // Remove special feature

        neighbor.RemoveIncomingRiver(); // Remove previous
        neighbor.hasIncomingRiver = true;
        neighbor.incomingRiver    = direction.Opposite();
        neighbor.specialIndex     = 0;     // Remove special feature

        SetRoad((int)direction, false);    // This already calls refresh
    }
Esempio n. 6
0
    public void SetOutgoingRiver(HexDirection direction)
    {
        if (hasOutgoingRiver && outgoingRiver == direction) //River already exists - do nothing
        {
            return;
        }

        HexCell neighbor = GetNeighbor(direction);

        if (!IsValidRiverDestination(neighbor)) //There must a neighbor and can't flow upwards
        {
            return;
        }

        RemoveOutgoingRiver();
        if (hasIncomingRiver && incomingRiver == direction)
        {
            RemoveIncomingRiver();
        }

        hasOutgoingRiver = true;
        outgoingRiver    = direction;
        specialIndex     = 0;

        neighbor.RemoveIncomingRiver();
        neighbor.hasIncomingRiver = true;
        neighbor.incomingRiver    = direction.Opposite();
        neighbor.specialIndex     = 0;

        SetRoad((int)direction, false);
    }
    public void SetOutgoingRiver(HexDirection direction)
    {
        if (hasOutgoingRiver && outgoingRiver == direction)
        {
            return;
        }

        HexCell neighbor = GetNeighbor(direction);

        if (!IsValidRiverDestination(neighbor))
        {
            return;
        }

        RemoveOutgoingRiver();
        if (hasIncomingRiver && incomingRiver == direction)
        {
            RemoveIncomingRiver();
        }
        hasOutgoingRiver = true;
        outgoingRiver    = direction;
        specialIndex     = 0;

        neighbor.RemoveIncomingRiver();
        neighbor.hasIncomingRiver = true;
        neighbor.incomingRiver    = direction.Opposite();
        neighbor.specialIndex     = 0;

        SetRoad((int)direction, false);
    }
Esempio n. 8
0
    void TriangulateWaterShore(
        HexDirection direction, HexCell cell, HexCell neighbor, Vector3 center
        )
    {
        EdgeVertices e1 = new EdgeVertices(
            center + HexMetrics.GetFirstWaterCorner(direction),
            center + HexMetrics.GetSecondWaterCorner(direction)
            );

        water.AddTriangle(center, e1.v1, e1.v2);
        water.AddTriangle(center, e1.v2, e1.v3);
        water.AddTriangle(center, e1.v3, e1.v4);
        water.AddTriangle(center, e1.v4, e1.v5);

        Vector3 center2 = neighbor.Position;

        center2.y = center.y;
        EdgeVertices e2 = new EdgeVertices(
            center2 + HexMetrics.GetSecondSolidCorner(direction.Opposite()),
            center2 + HexMetrics.GetFirstSolidCorner(direction.Opposite())
            );

        waterShore.AddQuad(e1.v1, e1.v2, e2.v1, e2.v2);
        waterShore.AddQuad(e1.v2, e1.v3, e2.v2, e2.v3);
        waterShore.AddQuad(e1.v3, e1.v4, e2.v3, e2.v4);
        waterShore.AddQuad(e1.v4, e1.v5, e2.v4, e2.v5);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        waterShore.AddQuadUV(0f, 0f, 0f, 1f);

        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (nextNeighbor != null)
        {
            Vector3 v3 = nextNeighbor.Position + (nextNeighbor.IsUnderwater ?
                                                  HexMetrics.GetFirstWaterCorner(direction.Previous()) :
                                                  HexMetrics.GetFirstSolidCorner(direction.Previous()));
            v3.y = center.y;
            waterShore.AddTriangle(e1.v5, e2.v5, v3);
            waterShore.AddTriangleUV(
                new Vector2(0f, 0f),
                new Vector2(0f, 1f),
                new Vector2(0f, nextNeighbor.IsUnderwater ? 0f : 1f)
                );
        }
    }
Esempio n. 9
0
        private void TriangulateWaterShore(HexDirection direction, HexCell cell, HexCell neighbor, Vector3 center)
        {
            var edge = new EdgeVertices(
                center + HexMetrics.GetFirstWaterCorner(direction),
                center + HexMetrics.GetSecondWaterCorner(direction),
                HexMetrics.edgeOuterStep);

            _water.AddTriangle(center, edge.v1, edge.v2);
            _water.AddTriangle(center, edge.v2, edge.v3);
            _water.AddTriangle(center, edge.v3, edge.v4);
            _water.AddTriangle(center, edge.v4, edge.v5);

            var center2 = neighbor.Position;

            center2.y = center.y;
            var edge2 = new EdgeVertices(
                center2 + HexMetrics.GetSecondSolidCorner(direction.Opposite()),
                center2 + HexMetrics.GetFirstSolidCorner(direction.Opposite()),
                HexMetrics.edgeOuterStep);

            if (cell.HasRiverThroughEdge(direction))
            {
                TriangulateEstuary(edge, edge2, cell.IncomingRiver == direction);
            }
            else
            {
                _waterShore.AddQuad(edge.v1, edge.v2, edge2.v1, edge2.v2);
                _waterShore.AddQuad(edge.v2, edge.v3, edge2.v2, edge2.v3);
                _waterShore.AddQuad(edge.v3, edge.v4, edge2.v3, edge2.v4);
                _waterShore.AddQuad(edge.v4, edge.v5, edge2.v4, edge2.v5);
                _waterShore.AddQuadUV(0, 0, 0, 1);
                _waterShore.AddQuadUV(0, 0, 0, 1);
                _waterShore.AddQuadUV(0, 0, 0, 1);
                _waterShore.AddQuadUV(0, 0, 0, 1);
            }
            var nextNeighbor = cell.GetNeighbor(direction.Next());

            if (nextNeighbor != null)
            {
                var v3 = nextNeighbor.Position + (nextNeighbor.IsUnderWater
                             ? HexMetrics.GetFirstWaterCorner(direction.Previous())
                             : HexMetrics.GetFirstSolidCorner(direction.Previous()));
                v3.y = center.y;
                _waterShore.AddTriangle(edge.v5, edge2.v5, v3);
                _waterShore.AddTriangleUV(Vector2.zero, Vector2.up, nextNeighbor.IsUnderWater ? Vector2.zero : Vector2.up);
            }
        }
Esempio n. 10
0
    private void TriangulateWithRiver(HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e)
    {
        Vector3 centerL, centerR;

        if (cell.HasRiverThroughEdge(direction.Opposite()))
        {
            centerL = center + HexMetrics.GetFirstSolidCorner(direction.Previous()) * 0.25f;
            centerR = center + HexMetrics.GetSecondSolidCorner(direction.Next()) * 0.25f;
        }
        else if (cell.HasRiverThroughEdge(direction.Next()))
        {
            centerL = center;
            centerR = Vector3.Lerp(center, e.v5, 2f / 3f);
        }
        else if (cell.HasRiverThroughEdge(direction.Previous()))
        {
            centerL = Vector3.Lerp(center, e.v1, 2f / 3f);
            centerR = center;
        }
        else if (cell.HasRiverThroughEdge(direction.Next2()))
        {
            centerL = center;
            centerR = center + HexMetrics.GetSolidEdgeMiddle(direction.Next()) * (0.5f * HexMetrics.innerToOuter);
        }
        else
        {
            centerL = center + HexMetrics.GetSolidEdgeMiddle(direction.Previous()) * (0.5f * HexMetrics.innerToOuter);
            centerR = center;
        }

        center = Vector3.Lerp(centerL, centerR, 0.5f);

        EdgeVertices m =
            new EdgeVertices(Vector3.Lerp(centerL, e.v1, 0.5f), Vector3.Lerp(centerR, e.v5, 0.5f), 1f / 6f);

        m.v3.y = center.y = e.v3.y;

        TriangulateEdgeStrip(m, weights1, cell.Index, e, weights1, cell.Index);

        terrain.AddTriangle(centerL, m.v1, m.v2);
        terrain.AddQuad(centerL, center, m.v2, m.v3);
        terrain.AddQuad(center, centerR, m.v3, m.v4);
        terrain.AddTriangle(centerR, m.v4, m.v5);

        Vector3 indices;

        indices.x = indices.y = indices.z = cell.Index;
        terrain.AddTriangleCellData(indices, weights1);
        terrain.AddQuadCellData(indices, weights1);
        terrain.AddQuadCellData(indices, weights1);
        terrain.AddTriangleCellData(indices, weights1);

        if (!cell.IsUnderwater)
        {
            bool reversed = cell.IncomingRiver == direction;
            TriangulateRiverQuad(centerL, centerR, m.v2, m.v4, cell.RiverSurfaceY, 0.4f, reversed, indices);
            TriangulateRiverQuad(m.v2, m.v4, e.v2, e.v4, cell.RiverSurfaceY, 0.6f, reversed, indices);
        }
    }
Esempio n. 11
0
    void TriangulateWaterShore(HexDirection direction, HexCell cell, HexCell neighbor, Vector3 center)
    {
        EdgeVertices e1 = new EdgeVertices(center + HexMetrics.GetFirstWaterCorner(direction),
                                           center + HexMetrics.GetSecondWaterCorner(direction));

        water.AddTriangle(center, e1.v1, e1.v2);
        water.AddTriangle(center, e1.v2, e1.v3);
        water.AddTriangle(center, e1.v3, e1.v4);
        water.AddTriangle(center, e1.v4, e1.v5);

        Vector3 center2 = neighbor.Position;

        center2.y = center.y;
        EdgeVertices e2 = new EdgeVertices(
            center2 + HexMetrics.GetSecondSolidCorner(direction.Opposite()),
            center2 + HexMetrics.GetFirstSolidCorner(direction.Opposite()));

        if (cell.HasRiverThroughEdge(direction))
        {
            TriangulateEstuary(e1, e2, cell.IncomingRiver == direction);
        }
        else
        {
            waterShore.AddQuad(e1.v1, e1.v2, e2.v1, e2.v2);
            waterShore.AddQuad(e1.v2, e1.v3, e2.v2, e2.v3);
            waterShore.AddQuad(e1.v3, e1.v4, e2.v3, e2.v4);
            waterShore.AddQuad(e1.v4, e1.v5, e2.v4, e2.v5);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
            waterShore.AddQuadUV(0f, 0f, 0f, 1f);
        }

        HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

        if (nextNeighbor != null)
        {
            Vector3 center3 = nextNeighbor.Position;
            center3.y = center.y;
            waterShore.AddTriangle(e1.v5, e2.v5,
                                   center3 + HexMetrics.GetFirstSolidCorner(direction.Previous()));
            waterShore.AddTriangleUV(new Vector2(0f, 0f),
                                     new Vector2(0f, 1f),
                                     new Vector2(0f, nextNeighbor.IsUnderwater?0f:1f));
        }
    }
Esempio n. 12
0
    /// <summary>
    /// 将相邻的cell实例赋值到neighbors中对应的位置
    /// 这里注意neighbors的索引下标,应与HexDirection方位的int值对应
    /// </summary>
    /// <param name="direction">相邻cell的方位</param>
    /// <param name="cell">相邻cell的实例</param>
    public void SetNeighbor(HexDirection direction, HexCell cell)
    {
        //通过枚举索引,将相邻的cell放入自身数组中的相对应位置上
        neighbors[(int)direction] = cell;

        //在赋值自身的neighbors实例的同时,也将自身实例赋值到相邻cell的neighbors数组中
        cell.neighbors[(int)direction.Opposite()] = this;
    }
Esempio n. 13
0
 public void SetNeighbor(HexDirection direction, HexCell cell)
 {
     if (cell)
     {
         neighbors[(int)direction] = cell;
         cell.neighbors[(int)direction.Opposite()] = this;
     }
 }
Esempio n. 14
0
 public void AddNeighbor(HexDirection dir, HexMesh n)
 {
     if (n != null)
     {
         this.neighbors[(int)dir]         = n;
         n.neighbors[(int)dir.Opposite()] = this;
     }
 }
Esempio n. 15
0
 bool CanAddBridge(HexCell cell, HexDirection dir)
 {
     if (cell.incomingRiver != dir.Next())
     {
         return(false);
     }
     return(cell.HasRoadThroughEdge(dir.Next2()) || cell.HasRoadThroughEdge(dir.Opposite()));
 }
Esempio n. 16
0
    public void SetNeighbour(HexDirection direction, Hex cell)
    {
        neighbours[(int)direction] = cell;
        cell.neighbours[(int)direction.Opposite()] = this;

        allNeighbours.Add(cell);
        cell.allNeighbours.Add(this);
    }
Esempio n. 17
0
    void TriangulateWithRiver(
        HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e
        )
    {
        Vector3 centerL, centerR;

        if (cell.HasRiverThroughEdge(direction.Opposite()))
        {
            centerL = center +
                      HexMetrics.GetFirstSolidCorner(direction.Previous()) * 0.25f;
            centerR = center +
                      HexMetrics.GetSecondSolidCorner(direction.Next()) * 0.25f;
        }
        else if (cell.HasRiverThroughEdge(direction.Next()))
        {
            centerL = center;
            centerR = Vector3.Lerp(center, e.v5, 2f / 3f);
        }
        else if (cell.HasRiverThroughEdge(direction.Previous()))
        {
            centerL = Vector3.Lerp(center, e.v1, 2f / 3f);
            centerR = center;
        }
        else if (cell.HasRiverThroughEdge(direction.Next2()))
        {
            centerL = center;
            centerR = center +
                      HexMetrics.GetSolidEdgeMiddle(direction.Next()) *
                      (0.5f * HexMetrics.innerToOuter);
        }
        else
        {
            centerL = center +
                      HexMetrics.GetSolidEdgeMiddle(direction.Previous()) *
                      (0.5f * HexMetrics.innerToOuter);
            centerR = center;
        }
        center = Vector3.Lerp(centerL, centerR, 0.5f);

        EdgeVertices m = new EdgeVertices(
            Vector3.Lerp(centerL, e.v1, 0.5f),
            Vector3.Lerp(centerR, e.v5, 0.5f),
            1f / 6f
            );

        m.v3.y = center.y = e.v3.y;

        TriangulateEdgeStrip(m, cell.Color, e, cell.Color);

        AddTriangle(centerL, m.v1, m.v2);
        AddTriangleColor(cell.Color);
        AddQuad(centerL, center, m.v2, m.v3);
        AddQuadColor(cell.Color);
        AddQuad(center, centerR, m.v3, m.v4);
        AddQuadColor(cell.Color);
        AddTriangle(centerR, m.v4, m.v5);
        AddTriangleColor(cell.Color);
    }
        private void TriangulateWithRiver(HexDirection direction, HexCell cell, Vector3 centre, EdgeVertices e)
        {
            Vector3 centreL, centreR;

            if (cell.HasRiverThroughEdge(direction.Opposite()))
            {
                centreL = centre + HexMetrics.GetFirstSolidCorner(direction.Previous()) * 0.25f;
                centreR = centre + HexMetrics.GetSecondSolidCorner(direction.Next()) * 0.25f;
            }
            else if (cell.HasRiverThroughEdge(direction.Next()))
            {
                centreL = centre;
                centreR = Vector3.Lerp(centre, e.v5, 2f / 3);
            }
            else if (cell.HasRiverThroughEdge(direction.Previous()))
            {
                centreL = Vector3.Lerp(centre, e.v1, 2f / 3);
                centreR = centre;
            }
            else if (cell.HasRiverThroughEdge(direction.Next2()))
            {
                centreL = centre;
                centreR = centre + HexMetrics.GetSolidEdgeMiddle(direction.Next()) * 0.5f * HexMetrics.InnerToOuter;
            }
            else
            {
                centreL = centre + HexMetrics.GetSolidEdgeMiddle(direction.Previous()) * 0.5f * HexMetrics.InnerToOuter;
                centreR = centre;
            }

            centre = Vector3.Lerp(centreL, centreR, 0.5f); // aligns edges

            var m = new EdgeVertices(
                Vector3.Lerp(centreL, e.v1, 0.5f),
                Vector3.Lerp(centreR, e.v5, 0.5f),
                1f / 6);

            m.v3.y = centre.y = e.v3.y;

            TriangulateEdgeStrip(m, weights1, cell.Index, e, weights1, cell.Index);

            Terrain.AddTriangle(centreL, m.v1, m.v2);
            Terrain.AddQuad(centreL, centre, m.v2, m.v3);
            Terrain.AddQuad(centre, centreR, m.v3, m.v4);
            Terrain.AddTriangle(centreR, m.v4, m.v5);

            var indices = new Vector3(cell.Index, cell.Index, cell.Index);

            Terrain.AddTriangleCellData(indices, weights1);
            Terrain.AddQuadCellData(indices, weights1);
            Terrain.AddQuadCellData(indices, weights1);
            Terrain.AddTriangleCellData(indices, weights1);

            var reversed = cell.IncomingRiver == direction;

            TriangulateRiverQuad(centreL, centreR, m.v2, m.v4, cell.RiverSurfaceY, 0.4f, reversed, indices);
            TriangulateRiverQuad(m.v2, m.v4, e.v2, e.v4, cell.RiverSurfaceY, 0.6f, reversed, indices);
        }
Esempio n. 19
0
 public void SetNeighbour(HexDirection direction, GridCell cell)
 {
     if (cell == null)
     {
         return;
     }
     cellNeighbours[(int)direction] = cell;
     cell.cellNeighbours[(int)direction.Opposite()] = this;//notice the opposite(). this is possible due to HexDirExtensions;
 }
Esempio n. 20
0
 void EditCell(HexCell cell)
 {
     if (cell)
     {
         if (activeTerrainTypeIndex >= 0)
         {
             cell.TerrainTypeIndex = activeTerrainTypeIndex;
         }
         if (applyElevation)
         {
             cell.Elevation = activeElevation;
         }
         if (applyWaterLevel)
         {
             cell.WaterLevel = activeWaterLevel;
         }
         if (applyUrbanLevel)
         {
             cell.UrbanLevel = activeUrbanLevel;
         }
         if (applyFarmLevel)
         {
             cell.FarmLevel = activeFarmLevel;
         }
         if (applyPlantLevel)
         {
             cell.PlantLevel = activePlantLevel;
         }
         if (riverMode == OptionalToggle.No)
         {
             cell.RemoveRiver();
         }
         if (roadMode == OptionalToggle.No)
         {
             cell.RemoveRoads();
         }
         if (walledMode != OptionalToggle.Ignore)
         {
             cell.Walled = walledMode == OptionalToggle.Yes;
         }
         if (isDrag)
         {
             HexCell otherCell = cell.GetNeighbor(dragDirection.Opposite());
             if (otherCell)
             {
                 if (riverMode == OptionalToggle.Yes)
                 {
                     otherCell.SetOutgoingRiver(dragDirection);
                 }
                 if (roadMode == OptionalToggle.Yes)
                 {
                     otherCell.AddRoad(dragDirection);
                 }
             }
         }
     }
 }
Esempio n. 21
0
        public void TriangulateContoursBetween(
            IHexCell center, IHexCell right, HexDirection direction, Color centerWeights, Color rightWeights, IHexMesh mesh
            )
        {
            var centerRightContour = CellContourCanon.GetContourForCellEdge(center, direction);
            var rightCenterContour = CellContourCanon.GetContourForCellEdge(right, direction.Opposite());

            int centerRightIndex = 1, rightCenterIndex = rightCenterContour.Count - 1;

            while (centerRightIndex < centerRightContour.Count && rightCenterIndex > 0)
            {
                mesh.AddQuad(
                    centerRightContour[centerRightIndex - 1].ToXYZ(), centerRightContour[centerRightIndex].ToXYZ(),
                    rightCenterContour[rightCenterIndex].ToXYZ(), rightCenterContour[rightCenterIndex - 1].ToXYZ()
                    );

                mesh.AddQuadColor(centerWeights, rightWeights);

                centerRightIndex++;
                rightCenterIndex--;
            }

            for (; centerRightIndex < centerRightContour.Count; centerRightIndex++)
            {
                mesh.AddTriangle(
                    centerRightContour[centerRightIndex - 1].ToXYZ(), rightCenterContour[0].ToXYZ(), centerRightContour[centerRightIndex].ToXYZ()
                    );

                mesh.AddTriangleColor(centerWeights, rightWeights, centerWeights);
            }

            for (; rightCenterIndex > 0; rightCenterIndex--)
            {
                mesh.AddTriangle(
                    centerRightContour.Last().ToXYZ(), rightCenterContour[rightCenterIndex].ToXYZ(), rightCenterContour[rightCenterIndex - 1].ToXYZ()
                    );

                mesh.AddTriangleColor(centerWeights, rightWeights, rightWeights);
            }

            if (RiverCanon.HasRiverAlongEdge(right, direction.Next2()))
            {
                var nextRight = Grid.GetNeighbor(center, direction.Next());

                var rightNextRightContour = CellContourCanon.GetContourForCellEdge(right, direction.Next2());
                var nextRightRightContour = CellContourCanon.GetContourForCellEdge(nextRight, direction.Previous());

                mesh.AddTriangle(
                    centerRightContour.Last().ToXYZ(),
                    rightNextRightContour.Last().ToXYZ(),
                    nextRightRightContour.First().ToXYZ()
                    );

                mesh.AddTriangleColor(centerWeights, rightWeights, rightWeights);
            }
        }
Esempio n. 22
0
 /// <summary>
 /// 编辑六边形晶胞参数
 /// </summary>
 /// <param name="cell"></param>
 void EditCell(HexCell cell)
 {
     if (cell)
     {
         if (applyColor)
         {
             cell.Color = activeColor;
         }
         if (applyElevation)
         {
             cell.Elevation = activeElevation;
         }
         if (applyWaterLevel)
         {
             cell.WaterLevel = activeWaterLevel;
         }
         if (applyUrbanLevel)
         {
             cell.UrbanLevel = activeUrbanLevel;
         }
         if (applyFarmLevel)
         {
             cell.FarmLevel = activeFarmLevel;
         }
         if (applyPlantLevel)
         {
             cell.PlantLevel = activePlantLevel;
         }
         if (riverMode == OptionalToggle.No)
         {
             cell.RemoveRiver();
         }
         if (roadMode == OptionalToggle.No)
         {
             cell.RemoveRoads();
         }
         if (isDrag)
         {
             // 支持笔刷绘制河流,主要利用获取的拖拽方向
             HexCell otherCell = cell.GetNeighbor(dragDirection.Opposite());
             if (otherCell)
             {
                 if (riverMode == OptionalToggle.Yes)
                 {
                     // 设置流出河流方向
                     otherCell.SetOutgoingRiver(dragDirection);
                 }
                 if (roadMode == OptionalToggle.Yes)
                 {
                     // 设置道路走向
                     otherCell.AddRoad(dragDirection);
                 }
             }
         }
     }
 }
Esempio n. 23
0
 //对六边形的某条边进行编辑
 void EditorEdge(HexCell cell, HexDirection clickDir)
 {
     if (IsEditorStep())
     {
         cell.isStepDirection[(int)clickDir] = true;
         if (cell.GetNeighbor(clickDir) != null)
         {
             cell.GetNeighbor(clickDir).isStepDirection[(int)clickDir.Opposite()] = true;
         }
     }
     else if (IsEditorSlope())
     {
         cell.isStepDirection[(int)clickDir] = false;
         if (cell.GetNeighbor(clickDir) != null)
         {
             cell.GetNeighbor(clickDir).isStepDirection[(int)clickDir.Opposite()] = false;
         }
     }
 }
 private HexDirection GetBestDirection(HexDirection startDirection, List <HexDirection> otherDirections, HexHash hash)
 {
     if (otherDirections.Contains(startDirection.Opposite()))
     {
         return(startDirection.Opposite());
     }
     else if (otherDirections.Contains(startDirection.Next2()))
     {
         return(startDirection.Next2());
     }
     else if (otherDirections.Contains(startDirection.Previous2()))
     {
         return(startDirection.Previous2());
     }
     else
     {
         return(otherDirections[Mathf.FloorToInt(hash.A * otherDirections.Count)]);
     }
 }
Esempio n. 25
0
 void OnTakeDamageEnd()
 {
     if (_enemy != null && CanCounter)
     {
         Attack(_enemy, _direction.Opposite(), 105);
     }
     else
     {
         EndTurn();
     }
 }
Esempio n. 26
0
    void EditCell(HexCell cell)
    {
        if (cell)
        {
            cell.Color = colors[1];

            if (applyElevation)
            {
                cell.Elevation = activeElevation;
            }
            if (applyWaterLevel)
            {
                cell.WaterLevel = activeWaterLevel;
            }
            if (applyUrbanLevel)
            {
                cell.UrbanLevel = activeUrbanLevel;
                cell.UpdateCell();
            }
            if (applyFarmLevel)
            {
                cell.FarmLevel = activeFarmLevel;
                cell.UpdateCell();
            }
            if (applyPlantLevel)
            {
                cell.PlantLevel = activePlantLevel;
                cell.UpdateCell();
            }
            if (riverMode == OptionalToggle.No)
            {
                cell.RemoveRiver();
            }
            if (roadMode == OptionalToggle.No)
            {
                cell.RemoveRoads();
            }
            if (isDrag)
            {
                HexCell otherCell = cell.GetNeighbor(dragDirection.Opposite());
                if (otherCell)
                {
                    if (riverMode == OptionalToggle.Yes)
                    {
                        otherCell.SetOutgoingRiver(dragDirection);
                    }
                    if (roadMode == OptionalToggle.Yes)
                    {
                        otherCell.AddRoad(dragDirection);
                    }
                }
            }
        }
    }
Esempio n. 27
0
    void EditCell(HexCell cell)
    {
        if (cell)
        {
            if (applyColor)
            {
                cell.Color = activeColor;
            }

            if (applyElevation)
            {
                cell.Elevation = activeElevation;
            }

            if (applyWaterLevel)
            {
                cell.WaterLevel = activeWaterLevel;
            }

            if (applyUrbanLevel)
            {
                cell.UrbanLevel = activeUrbanLevel;
            }

            if (riverMode == OptionalToggle.No)
            {
                cell.RemoveRiver();
            }

            if (roadMode == OptionalToggle.No)
            {
                cell.RemoveRoads();
            }

            if (isDrag)
            {
                HexCell otherCell = cell.GetNeighbor(dragDirection.Opposite());
                if (otherCell)
                {
                    if (riverMode == OptionalToggle.Yes)
                    {
                        otherCell.SetOutgoingRiver(dragDirection);
                    }

                    if (roadMode == OptionalToggle.Yes)
                    {
                        otherCell.AddRoad(dragDirection);
                    }
                }
            }
        }
        // hexGrid.Refresh();
    }
Esempio n. 28
0
    BlockWithDir GetNext(BlockWithDir prev)
    {
        HexDirection dir   = prev.Dir;
        BlockModel   block = prev.Block;
        int          x     = block.x;
        int          z     = block.z;

        if (dir == HexDirection.E)
        {
            x += 1;
        }
        if (dir == HexDirection.W)
        {
            x -= 1;
        }
        if (dir == HexDirection.NE)
        {
            x += (z % 2);
            z += 1;
        }
        if (dir == HexDirection.NW)
        {
            x += (z % 2) - 1;
            z += 1;
        }
        if (dir == HexDirection.SE)
        {
            x += (z % 2);
            z -= 1;
        }
        if (dir == HexDirection.SW)
        {
            x += (z % 2) - 1;
            z -= 1;
        }
        BlockModel next = grid.Get(x, z);

        if (next == null)
        {
            return(null);
        }
        HexDirection opp = dir.Opposite();

        if (next.dir1 == opp)
        {
            return(new BlockWithDir(next, next.dir2));
        }
        if (next.dir2 == opp)
        {
            return(new BlockWithDir(next, next.dir1));
        }
        return(null);
    }
        //private List<HexTile> GetZBucket(int z) {
        //	List<HexTile> result;
        //	if (!zDict.TryGetValue(z, out result)) {
        //		result = new List<HexTile>();
        //		zDict[z] = result;
        //	}
        //	return result;
        //}

        /// <summary>
        /// Since the axis 2 only holds 3 values in order to avoid redundancy, the hex at the given coordinates only
        /// contains half the information. If the given direction is not one of the first three, we have to go to
        /// one of the three neighboring hexagons in order to find the common value.
        /// </summary>
        /// <param name="column"></param>
        /// <param name="row"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public static Vector3Int Convert(int column, int row, HexDirection direction)
        {
            if ((int)direction >= 3)
            {
                Vector2Int move = HexUtils.MoveFrom(column, row, direction);
                return(new Vector3Int(move.x, move.y, (int)direction.Opposite()));
            }
            else
            {
                return(new Vector3Int(column, row, (int)direction));
            }
        }
Esempio n. 30
0
    void PlaceArrow(HexDirection direction, HexCell cell)
    {
        HexCell neighbor = cell.GetNeighbor(direction);

        if (neighbor == null || neighbor.IsUnderwater)
        {
            return;
        }
        EdgeVertices e = new EdgeVertices(
            neighbor.Position + HexMetrics.GetFirstArrowCorner(direction.Opposite()),
            neighbor.Position + HexMetrics.GetSecondArrowCorner(direction.Opposite()));

        Vector3 center = new Vector3(e.v3.x, e.v3.z, -e.v3.y - 0.1f);

        Toggle instance = Instantiate(arrowPrefab);

        instance.onValueChanged.AddListener(delegate { migrationMenu.Open(neighbor, cell); });

        instance.transform.localPosition = HexMetrics.PerturbPerspective(center);
        instance.transform.localRotation = Quaternion.Euler(0f, 0f, 60f - 60f * (float)direction);
        instance.transform.SetParent(arrowContainer, false);
    }