示例#1
0
 protected override void EditCell(IHexCell cell)
 {
     if (IsPaintingTerrain && CellModificationLogic.CanChangeTerrainOfCell(cell, ActiveTerrain))
     {
         CellModificationLogic.ChangeTerrainOfCell(cell, ActiveTerrain);
     }
 }
示例#2
0
        public void PaintTerrain(MapRegion region, IRegionBiomeTemplate template)
        {
            var unassignedLandCells = new HashSet <IHexCell>(region.LandCells);

            PaintArcticTerrain(region, template, unassignedLandCells);
            PaintOtherTerrains(region, template, unassignedLandCells);
            AssignLandOrphans(region, template, unassignedLandCells);

            foreach (var cell in region.WaterCells)
            {
                ModLogic.ChangeTerrainOfCell(cell, CellTerrain.ShallowWater);
            }
        }
示例#3
0
        public void GenerateTopologyAndEcology(OceanData oceanData)
        {
            foreach (var region in oceanData.EmptyOceanRegions)
            {
                foreach (var cell in region.Cells)
                {
                    ModLogic.ChangeTerrainOfCell(cell, CellTerrain.DeepWater);
                }
            }

            foreach (var region in oceanData.ArchipelagoRegions)
            {
                RegionData regionData = oceanData.GetRegionData(region);

                RegionGenerator.GenerateTopology(region, regionData.Topology);
                RegionGenerator.PaintTerrain(region, regionData.Biome);
                RegionGenerator.AssignFloodPlains(region.LandCells);
            }
        }
示例#4
0
        private void CreateCell(int x, int z, int i)
        {
            var position = new Vector3(
                (x + z * 0.5f - z / 2) * RenderConfig.InnerRadius * 2f,
                0f,
                z * RenderConfig.OuterRadius * 1.5f
                );

            var newCell = new HexCell(position, this, CellSignals);

            newCell.WorkerSlot = WorkerSlotFactory.BuildSlot(newCell);

            newCell.Index       = i;
            newCell.Coordinates = HexCoordinates.FromOffsetCoordinates(x, z);

            CellModificationLogic.ChangeTerrainOfCell(newCell, CellTerrain.Grassland);
            CellModificationLogic.ChangeShapeOfCell(newCell, CellShape.Flatlands);
            CellModificationLogic.ChangeVegetationOfCell(newCell, CellVegetation.None);

            cells.Add(newCell);
        }
示例#5
0
        public bool TryIncreaseYield(
            MapRegion region, RegionData regionData, YieldType type, out YieldSummary yieldAdded
            )
        {
            if (type != YieldType.Food)
            {
                yieldAdded = YieldSummary.Empty;
                return(false);
            }

            var candidates = region.Cells.Where(GetLakeCandidateFilter(region));

            if (candidates.Any())
            {
                var newLake = candidates.Random();

                var oldYields = new Dictionary <IHexCell, YieldSummary>();

                foreach (var cell in Grid.GetCellsInRadius(newLake, 1))
                {
                    oldYields[cell] = YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs);
                }

                ModLogic.ChangeTerrainOfCell(newLake, CellTerrain.FreshWater);

                yieldAdded = YieldSummary.Empty;
                foreach (var cell in oldYields.Keys)
                {
                    yieldAdded += YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs) - oldYields[cell];
                }

                return(true);
            }
            else
            {
                yieldAdded = YieldSummary.Empty;
                return(false);
            }
        }
        public bool TryDecreaseScore(MapRegion region, RegionData regionData, out float scoreRemoved)
        {
            var allCandidates = region.LandCells.Where(CandidateFilter).ToList();

            allCandidates.Sort(CandidateComparer);

            var bestCandidate = allCandidates.FirstOrDefault();

            if (bestCandidate != null)
            {
                var oldScore = CellScorer.GetScoreOfCell(bestCandidate);

                ModLogic.ChangeTerrainOfCell(bestCandidate, CellTerrain.ShallowWater);

                scoreRemoved = oldScore - CellScorer.GetScoreOfCell(bestCandidate);

                return(true);
            }
            else
            {
                scoreRemoved = 0f;
                return(false);
            }
        }
        public void DecomposeCells(SerializableMapData mapData)
        {
            Grid.Build(mapData.CellCountX, mapData.CellCountZ);

            foreach (var cellData in mapData.HexCells)
            {
                var cellToModify = Grid.GetCellAtCoordinates(cellData.Coordinates);

                CellModificationLogic.ChangeTerrainOfCell(cellToModify, cellData.Terrain);
                CellModificationLogic.ChangeShapeOfCell(cellToModify, cellData.Shape);
                CellModificationLogic.ChangeVegetationOfCell(cellToModify, cellData.Vegetation);
                CellModificationLogic.ChangeFeatureOfCell(cellToModify, cellData.Feature);
                CellModificationLogic.ChangeHasRoadsOfCell(cellToModify, cellData.HasRoads);

                cellToModify.SuppressSlot = cellData.SuppressSlot;

                //Converging rivers (where two rivers combine and flow into a third) have
                //order-sensitive creation, since attempting to place both of the inflow
                //rivers before the outflow river has been created is invalid. To account for
                //this, we delay the creation of any invalid rivers (since those represent
                //an inflow being attached to another inflow) until after all other rivers
                //have been placed.
                var delayedRivers = new List <System.Tuple <IHexCell, HexDirection, RiverFlow> >();

                for (int i = 0; i < 6; i++)
                {
                    var edge = (HexDirection)i;

                    if (cellData.HasRiverAtEdge[i] && !RiverCanon.HasRiverAlongEdge(cellToModify, edge))
                    {
                        if (RiverCanon.CanAddRiverToCell(cellToModify, edge, cellData.DirectionOfRiverAtEdge[i]))
                        {
                            RiverCanon.AddRiverToCell(cellToModify, edge, cellData.DirectionOfRiverAtEdge[i]);
                        }
                        else
                        {
                            delayedRivers.Add(new System.Tuple <IHexCell, HexDirection, RiverFlow>(
                                                  cellToModify, edge, cellData.DirectionOfRiverAtEdge[i]
                                                  ));
                        }
                    }
                }

                foreach (var river in delayedRivers)
                {
                    if (RiverCanon.CanAddRiverToCell(river.Item1, river.Item2, river.Item3))
                    {
                        RiverCanon.AddRiverToCell(river.Item1, river.Item2, river.Item3);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "Failed to decompose river ({0}, {1}, {2})",
                                                                river.Item1, river.Item2, river.Item3
                                                                ));
                    }
                }

                cellToModify.WorkerSlot.IsOccupied = cellData.IsSlotOccupied;
                cellToModify.WorkerSlot.IsLocked   = cellData.IsSlotLocked;
            }

            foreach (var chunk in Grid.Chunks)
            {
                chunk.Refresh(MapRendering.TerrainRefreshType.All);
            }
        }