예제 #1
0
        public void GenerateTopology(MapRegion region, IRegionTopologyTemplate template)
        {
            var landCells = region.LandCells;

            int desiredMountainCount = Mathf.RoundToInt(template.MountainsPercentage * landCells.Count() * 0.01f);
            int desiredHillsCount    = Mathf.RoundToInt(template.HillsPercentage * landCells.Count() * 0.01f);

            var elevatedCells = CellRandomSampler.SampleElementsFromSet(
                landCells, desiredHillsCount + desiredMountainCount,
                HillsStartingWeightFunction, HillsDynamicWeightFunction, cell => Grid.GetNeighbors(cell)
                );

            foreach (var cell in elevatedCells)
            {
                ModLogic.ChangeShapeOfCell(cell, CellShape.Hills);
            }

            var mountainousCells = CellRandomSampler.SampleElementsFromSet(
                elevatedCells, desiredMountainCount, MountainWeightFunction
                );

            foreach (var cell in mountainousCells)
            {
                ModLogic.ChangeShapeOfCell(cell, CellShape.Mountains);
            }
        }
 protected override void EditCell(IHexCell cell)
 {
     if (IsPainting && ModLogic.CanChangeShapeOfCell(cell, ActiveShape))
     {
         ModLogic.ChangeShapeOfCell(cell, ActiveShape);
     }
 }
예제 #3
0
        public bool TryIncreaseYield(
            MapRegion region, RegionData regionData, YieldType type, out YieldSummary yieldAdded
            )
        {
            if (type != YieldType.Production)
            {
                yieldAdded = YieldSummary.Empty;
                return(false);
            }

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

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

                var oldYield = YieldEstimator.GetYieldEstimateForCell(newHill, TechCanon.AvailableTechs);

                ModLogic.ChangeShapeOfCell(newHill, CellShape.Hills);

                var newYield = YieldEstimator.GetYieldEstimateForCell(newHill, TechCanon.AvailableTechs);

                yieldAdded = newYield - oldYield;
                return(true);
            }
            else
            {
                yieldAdded = YieldSummary.Empty;
                return(false);
            }
        }
예제 #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);
        }
        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.ChangeShapeOfCell(bestCandidate, CellShape.Mountains);

                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);
            }
        }