Пример #1
0
    public void EnableEdge(HexEdge edge)
    {
        switch (edge)
        {
        case HexEdge.UpperLeft:
            UpperLeftEdge.gameObject.SetActive(true);
            break;

        case HexEdge.UpperCenter:
            UpperCenterEdge.gameObject.SetActive(true);
            break;

        case HexEdge.UpperRight:
            UpperRightEdge.gameObject.SetActive(true);
            break;

        case HexEdge.LowerRight:
            LowerRightEdge.gameObject.SetActive(true);
            break;

        case HexEdge.LowerCenter:
            LowerCenterEdge.gameObject.SetActive(true);
            break;

        case HexEdge.LowerLeft:
            LowerLeftEdge.gameObject.SetActive(true);
            break;

        default:
            break;
        }
    }
Пример #2
0
 /// <summary>
 /// Build planar graph of car spawners and points of fuel triggers
 /// </summary>
 private void BuildGraph()
 {
     _graph.AddRange(Object.FindObjectsOfType <RefuelingMark>().Select(refueling => Scale(refueling.transform.position.ToHex())));
     for (var i = 0; i < _graph.Count; i++)
     {
         for (var j = i + 1; j < _graph.Count; j++)
         {
             var currentEdge = new HexEdge(_graph[i], _graph[j]);
             var isAdd       = true;
             var removeEdges = new List <HexEdge>();
             var magnitude   = Hex.Distance(currentEdge.A, currentEdge.B);
             foreach (var edge in Edges.Where(edge => Intersection(currentEdge, edge)))
             {
                 if (magnitude < Hex.Distance(edge.A, edge.B))
                 {
                     removeEdges.Add(edge);
                 }
                 else
                 {
                     isAdd = false;
                     break;
                 }
             }
             if (isAdd && !Edges.Contains(currentEdge))
             {
                 Edges.Add(currentEdge);
                 foreach (var edge in removeEdges)
                 {
                     Edges.Remove(edge);
                 }
             }
         }
     }
 }
Пример #3
0
    public void Triangulate(HexMesh mesh)
    {
        for (HexDirection direction = HexDirection.NE; direction <= HexDirection.NW; direction++)
        {
            Vector3      center = Position;
            EdgeVertices edge   = new EdgeVertices(
                Position + HexMetrics.GetFirstSolidCorner(direction),
                Position + HexMetrics.GetSecondSolidCorner(direction)
                );

            mesh.AddTriangle(Position, edge.v1, edge.v2);
            mesh.AddTriangleColor(Color, Color, Color);
            mesh.AddTriangle(Position, edge.v2, edge.v3);
            mesh.AddTriangleColor(Color, Color, Color);
            mesh.AddTriangle(Position, edge.v3, edge.v4);
            mesh.AddTriangleColor(Color, Color, Color);
            mesh.AddTriangle(Position, edge.v4, edge.v5);
            mesh.AddTriangleColor(Color, Color, Color);

            HexCell neighbor = GetNeighbor(direction);
            if (direction <= HexDirection.SE && neighbor != null)
            {
                edges[(int)direction] = HexEdge.Build(this, neighbor, direction);
                edges[(int)direction].Triangulate(mesh);

                HexCell nextNeighbor = GetNeighbor(direction.Next());
                if (direction <= HexDirection.E && nextNeighbor != null)
                {
                    corners[(int)direction] = Corner.Build(this, neighbor, nextNeighbor, direction);
                    corners[(int)direction].Triangulate(mesh);
                }
            }
        }
    }
Пример #4
0
    public Road InstantiateRoad(HexEdge edge, PlayerColor color)
    {
        Road road = Instantiate(roadPrefab, transform.TransformPoint(edge.ToLocalCoords()), edge.ToLocalRot(),
                                transform).GetComponent <Road>();

        road.Edge  = edge;
        road.Color = color;
        return(road);
    }
Пример #5
0
    public override void Triangulate(HexMesh mesh)
    {
        EdgeVertices e1 = this.edge1;
        Color        c1 = this.color1;

        for (int step = 1; step < HexMetrics.terraceSteps + 1; ++step)
        {
            EdgeVertices e2 = EdgeVertices.TerraceLerp(this.edge1, this.edge2, step);
            Color        c2 = HexMetrics.ColorLerp(this.color1, this.color2, step);
            HexEdge.TriangulateQuad(mesh, e1, e2, c1, c2);

            c1 = c2;
            e1 = e2;
        }
    }
Пример #6
0
 public bool IsValidRoad(PlayerColor color, HexEdge edge)
 {
     if (Roads.ContainsKey(edge))
     {
         return(false);
     }
     if (CornerGraph.IsOutOfRange(edge.Start) || CornerGraph.IsOutOfRange(edge.End))
     {
         return(false);
     }
     if (coordinator.GameState.State == GameStates.Setup)
     {
         //check if there's a settlement on one of the road's corners
         if (!((Units.ContainsKey(edge.Start) && Units[edge.Start].Color == color) ||
               (Units.ContainsKey(edge.End) && Units[edge.End].Color == color)))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #7
0
    public void PlacingRoad_Update()
    {
        Vector3?mousePos = RaycastMouse();

        if (mousePos.HasValue)
        {
            PlaceRoadAction action = new PlaceRoadAction(HexEdge.GetNearestEdge(mousePos.Value), Color);
            if (action.IsValid(Board))
            {
                Board.SetCurrentAction(action);
                if (Input.GetMouseButtonDown(0))
                {
                    Board.ApplyCurrentAction();
                    ChangeState(PlayerStates.Idle);
                    if (Coordinator.GameState.State == GameStates.Setup)
                    {
                        Coordinator.NextTurn();
                    }
                }
            }
        }
    }
Пример #8
0
 public override void Triangulate(HexMesh mesh)
 {
     HexEdge.TriangulateQuad(mesh, edge1, edge2, color1, color2);
 }
Пример #9
0
 public PlaceRoadAction(HexEdge edge, PlayerColor color)
 {
     Edge  = edge;
     Color = color;
 }
Пример #10
0
 /// <summary>
 /// Check for the crossing of two edge of the graph
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 public static bool Intersection(HexEdge a, HexEdge b)
 {
     return(AreCrossing(a.A, a.B, b.A, b.B));
 }
Пример #11
0
 public bool Equals(HexEdge other)
 {
     return(this == other);
 }
Пример #12
0
 public void AddRoad(HexEdge edge, Road road)
 {
     Roads.Add(edge, road);
 }
Пример #13
0
 private double GetPathfindingEdgeWeight(HexEdge edge)
 {
     return(0d);
 }