Esempio n. 1
0
 void EditCell(HexCell cell)
 {
     if (cell)
     {
         if (applyColor)
         {
             cell.Color = activeColor;
         }
         if (roadMode == OptionalToggle.No)
         {
             cell.RemoveRoads();
         }
         if (isDrag)
         {
             HexCell otherCell = cell.GetNeighbor(dragDirection.Opposite());
             if (otherCell)
             {
                 if (roadMode == OptionalToggle.Yes)
                 {
                     otherCell.AddRoad(dragDirection);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 void EditCell(HexCell cell)
 {
     if (cell)
     {
         // Color
         if (applyColor)
         {
             cell.Color = activeColor;
         }
         // Elevation
         if (applyElevation)
         {
             cell.Elevation = activeElevation;
         }
         // Water
         if (applyWaterLevel)
         {
             cell.WaterLevel = activeWaterLevel;
         }
         // Urban/City
         if (applyUrbanLevel)
         {
             cell.UrbanLevel = activeUrbanLevel;
         }
         // Farm
         if (applyFarmLevel)
         {
             cell.FarmLevel = activeFarmLevel;
         }
         // Plant
         if (applyPlantLevel)
         {
             cell.PlantLevel = activePlantLevel;
         }
         // River
         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. 3
0
        public void updateChunkWithRiversAndRoads1Test()
        {
            GameObject obj  = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Prefabs/Hex Grid"));
            HexGrid    grid = obj.GetComponent <HexGrid>();

            HexGridChunk[] chunks = grid.getHexGridChunks();

            HexCell[]    cells     = chunks[0].getCells();
            HexDirection direction = HexDirection.NE;
            int          index     = 7;

            // ....................................................
            // SET DIRECT RIVER
            // ....................................................
            // Find cell with next steps: go to NE, go to NE
            HexCell cell = cells[index].GetNeighbor(direction)
                           .GetNeighbor(direction);

            // Set river to NW direction
            cell.SetOutgoingRiver(direction.Previous());
            // Get neigbor from SE direction cell
            HexCell neighbor = cell.GetNeighbor(direction.Next2());

            // Set river to NW direction
            neighbor.SetOutgoingRiver(direction.Previous());

            // Set road to previous 2 direction
            cell.AddRoad(direction.Next());

            // Set road to opposite direction
            cell.AddRoad(direction.Next().Opposite());
            // ....................................................

            // Update chunk
            foreach (HexGridChunk chunk in chunks)
            {
                chunk.Triangulate();
            }

            Assert.IsTrue(cell.HasIncomingRiver);
            Assert.IsTrue(cell.HasOutgoingRiver);
            Assert.IsTrue(cell.HasRoads);

            GameObject.Destroy(obj);
        }
Esempio n. 4
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. 5
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. 6
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. 7
0
    void EditCell(HexCell cell)
    {
        if (cell)
        {
            if (_activeTerrainTypeIndex >= 0)
            {
                cell.TerrainTypeIndex = _activeTerrainTypeIndex;
            }

            if (_applyElevation)
            {
                cell.Elevation = _activeElevation;
            }

            if (_riverMode == EditModes.Remove)
            {
                cell.RemoveRiver();
            }

            if (_roadMode == EditModes.Remove)
            {
                cell.RemoveRoads();
            }

            if (_applyWaterLevel)
            {
                cell.WaterLevel = _activeWaterLevel;
            }

            if (_isDrag)
            {
                var     oppositeDir = _dragDirection.Opposite();
                HexCell otherCell   = cell.GetNeighbor(oppositeDir);
                if (otherCell)
                {
                    if (_riverMode == EditModes.Add)
                    {
                        cell.SetIncomingRiver(oppositeDir, otherCell);
                    }
                    if (_roadMode == EditModes.Add)
                    {
                        otherCell.AddRoad(_dragDirection);
                    }
                }
            }
        }
    }
Esempio n. 8
0
    private void BuildRiverOrRoad(HexMapEditor mapEditor, int numIterations, int minLength, int maxLength, bool isRoad)
    {
        for (int i = 0; i < numIterations; ++i)
        {
            int startX = Random.Range(0, mapEditor.HexGrid.NumCellsX);
            int startZ = Random.Range(0, mapEditor.HexGrid.NumCellsZ);

            int     length      = Random.Range(minLength, maxLength);
            HexCell currentCell = mapEditor.HexGrid.GetCell(new HexCoordinates(startX, startZ));
            if (currentCell != null)
            {
                HexCell lastCell = null;

                for (int r = 2; r < length; ++r)
                {
                    HexDirection dir           = (HexDirection)0;
                    HexCell      neighbourCell = null;
                    for (int j = 0; j < 5; ++j)
                    {
                        dir = (HexDirection)Random.Range(0, 6);
                        //dir = HexDirection.E;
                        neighbourCell = currentCell.GetNeighbour(dir);
                        if (neighbourCell != null && neighbourCell != lastCell)
                        {
                            break;
                        }
                    }

                    if (neighbourCell != null)
                    {
                        if (isRoad)
                        {
                            currentCell.AddRoad(dir);
                        }
                        else
                        {
                            currentCell.SetOutgoingRiver(dir);
                        }

                        lastCell    = currentCell;
                        currentCell = neighbourCell;
                    }
                }
            }
        }
    }
Esempio n. 9
0
    private void EditCell(HexCell cell)
    {
        if (cell)
        {
            if (activeTerrainTypeIndex >= 0)
            {
                cell.TerrainTypeIndex = activeTerrainTypeIndex;
            }
            if (applyElevation)
            {
                cell.Elevation = activeElevation;
            }
            if (applyWaterLevel)
            {
                cell.WaterLevel = activeWaterLevel;
            }
            if (riverMode == OptionalToggle.No)
            {
                cell.RemoveRiver();
            }
            if (roadMode == OptionalToggle.No)
            {
                cell.RemoveRoads();
            }

            if (isDrag)
            {
                // Cell from which we come from.
                HexCell otherCell = cell.GetNeighbor(dragDirection.Opposite());
                if (otherCell)
                {
                    if (riverMode == OptionalToggle.Yes)
                    {
                        otherCell.SetOutgoingRiver(dragDirection);
                    }
                    if (roadMode == OptionalToggle.Yes)
                    {
                        otherCell.AddRoad(dragDirection);
                    }
                }
            }
        }
    }
Esempio n. 10
0
    public void EditCell(HexCell cell)
    {
        if (cell != null)
        {
            if (m_activeTerrainTypeIndex >= 0)
            {
                cell.TerrainTypeIndex = m_activeTerrainTypeIndex;
            }
            if (m_applyElevation)
            {
                cell.Elevation = m_activeElevation;
            }
            if (m_applyWaterLevel)
            {
                cell.WaterLevel = m_activeWaterLevel;
            }
            if (m_applyUrbanDensity)
            {
                cell.UrbanDensityLevel = m_activeUrbanDensityLevel;
            }

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

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



            if (m_wallMode != OptionalToggle.Ignore)
            {
                cell.Walled = m_wallMode == OptionalToggle.Yes;
            }

            if (m_applySpecialFeature)
            {
                cell.SpecialFeatureIndex = m_specialFeatureIndex;
            }


            if (m_isDrag)
            {
                HexCell otherCell = cell.GetNeighbour(m_dragDirection.Opposite());
                if (otherCell)
                {
                    if (m_riverMode == OptionalToggle.Yes)
                    {
                        otherCell.SetOutgoingRiver(m_dragDirection);
                    }
                    else if (m_roadMode == OptionalToggle.Yes)
                    {
                        otherCell.AddRoad(m_dragDirection);
                    }
                }
            }
        }
    }
Esempio n. 11
0
    void EditCell(HexCell cell)
    {
        if (!cell)
        {
            return;
        }

        if (this.activeTerrainTypeIndex >= 0)
        {
            cell.TerrainTypeIndex = this.activeTerrainTypeIndex;
        }

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

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

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

        if (this.applyFarmLevel)
        {
            cell.FarmLevel = this.activeFarmLevel;
        }

        if (this.applyPlantLevel)
        {
            cell.PlantLevel = this.activePlantLevel;
        }

        if (this.applySpecialIndex)
        {
            cell.SpecialIndex = this.activeSpecialIndex;
        }

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

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

        if (this.walledMode != OptionalToggle.Ignore)
        {
            cell.Walled = this.walledMode == OptionalToggle.Yes;
        }

        if (this.isDrag)
        {
            HexCell otherCell = cell.GetNeighbor(this.dragDirection.Opposite());

            if (!otherCell)
            {
                return;
            }

            if (this.riverMode == OptionalToggle.Yes)
            {
                otherCell.SetOutgoingRiver(this.dragDirection);
            }

            if (this.roadMode == OptionalToggle.Yes)
            {
                otherCell.AddRoad(this.dragDirection);
            }
        }
    }
Esempio n. 12
0
    void EditCell(HexCell cell)
    {
        if (cell)
        {
            // 设置地形类型引索
            if (activeTerrainTypeIndex >= 0)
            {
                cell.TerrainTypeIndex = activeTerrainTypeIndex;
            }

            // 单元高度
            if (applyElevation)
            {
                cell.Elevation = activeElevation;
            }

            // 单元水平面高度
            if (applyWaterLevel)
            {
                cell.WaterLevel = activeWaterLevel;
            }

            // 特殊特征物体下标
            if (applySpecialIndex)
            {
                cell.SpecialIndex = activeSpecialIndex;
            }

            // 单元城市密度
            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;
            }

            // 添加河流
            else 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. 13
0
    public void EditCell(HexCell cell)
    {
        if (cell == null)
        {
            return;
        }
        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 (applySpecialIndex)
        {
            cell.SpecialIndex = activeSpecialIndex;
        }

        if (riverMode == OptionalToggle.Remove)
        {
            cell.RemoveRiver();
        }
        if (roadMode == OptionalToggle.Remove)
        {
            cell.RemoveRoads();
        }
        if (walledMode != OptionalToggle.Ignore)
        {
            cell.Walled = walledMode == OptionalToggle.Add;
        }
        if (isDrag)
        {
            HexCell otherCell = cell.GetNeighbor(dragDirection.Opposite());
            if (otherCell != null)
            {
                if (riverMode == OptionalToggle.Add)
                {
                    previousCell.SetOutGoingRiver(dragDirection);
                }
                if (roadMode == OptionalToggle.Add)
                {
                    previousCell.AddRoad(dragDirection);
                }
            }
        }
    }
Esempio n. 14
0
    void EditCell(HexCell cell)
    {
        if (cell)
        {
            if (activeTerrainTypeIndex >= 0)
            {
                cell.TerrainTypeIndex = activeTerrainTypeIndex;
            }
            if (applyElevation)
            {
                cell.Elevation = activeElevation;
            }
            if (applyWaterLevel)
            {
                cell.WaterLevel = activeWaterLevel;
            }
            if (applySpecialIndex)
            {
                if (activeSpecialIndex == 2)
                {
                    hexGrid.CreateCity(cell);
                }
                else
                {
                    if (cell.City)
                    {
                        hexGrid.DestroyCity(cell.City);
                    }
                }
                if (activeSpecialIndex == 3)
                {
                    string playerName = players.options[players.value].text;
                    Player player;
                    if (playerName == "Human Player")
                    {
                        player = gameController.HumanPlayer;
                    }
                    else
                    {
                        int playerID = System.Convert.ToInt32(players.options[players.value].text);
                        player = gameController.GetPlayer(playerID);
                    }
                    hexGrid.CreateOperationCentre(cell, player);
                }
                else
                {
                    hexGrid.DestroyOperationCentre(cell);
                }

                cell.SpecialIndex = activeSpecialIndex;
            }
            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. 15
0
    private void EditCell(HexCell hexCell)
    {
        if (hexCell)
        {
            if (activeTerrainTypeIndex >= 0)
            {
                hexCell.TerrainTypeIndex = activeTerrainTypeIndex;
            }

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

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

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

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

            if (applySpecIndex)
            {
                hexCell.SpecIndex = activeSpecIndex;
            }

            if (applyTreeLevel)
            {
                hexCell.TreeLevel = activeTreeLevel;
            }

            if (applyStoneLevel)
            {
                hexCell.StoneLevel = activeStoneLevel;
            }

            if (wallMode == OptionalToggle.Yes)
            {
                for (HexDirection dir = HexDirection.TopRight; dir <= HexDirection.TopLeft; dir++)
                {
                    hexCell.AddWall(dir);
                }
            }

            /*
             * else if(wallMode == OptionalToggle.No)
             * {
             *  for (HexDirection dir = HexDirection.TopRight; dir <= HexDirection.TopLeft; dir++)
             *  {
             *      hexCell.RemoveWalls(dir);
             *  }
             * }
             */

            if (isDrag)
            {
                HexCell otherCell = hexCell.GetNeighbor(dragDirection.Opposite());

                if (otherCell)
                {
                    if (riverMode == OptionalToggle.Yes)
                    {
                        otherCell.SetOutgoingRiver(dragDirection);
                    }

                    if (roadMode == OptionalToggle.Yes)
                    {
                        otherCell.AddRoad(dragDirection);
                    }

                    if (wallMode == OptionalToggle.No)
                    {
                        otherCell.RemoveWalls(dragDirection);
                    }

                    /*
                     * if (wallMode == OptionalToggle.Yes)
                     * {
                     *  otherCell.AddWall(dragDirection);
                     * }
                     * else if (wallMode == OptionalToggle.No)
                     * {
                     *  otherCell.RemoveWalls(dragDirection);
                     * }
                     */
                }
            }
        }
    }