public void StartGameAsClient(int mapSeed, int startGameSeed) { StartGameSeed = startGameSeed; MapGenerationSettings settings = new MapGenerationSettings(mapSeed, 10, 10, 0.08f, 1.5f, 5, 30, MapType.Island); PMG.GenerateMap(settings, callback: OnMapGenerationDone); }
// Start is called before the first frame update public void DisplayNoise(Noise noise, GameObject plane, MapGenerationSettings settings, float blackValue = 0f, float whiteValue = 1f) { int texRes = 32; plane.transform.localScale = new Vector3(settings.Width / 10, 1, settings.Height / 10); plane.transform.position = new Vector3(plane.transform.localScale.x * 10 / 2, -1f, plane.transform.localScale.z * 10 / 2); Texture2D tex = new Texture2D((int)plane.transform.localScale.x * texRes, (int)plane.transform.localScale.z * texRes); for (int y = 0; y < tex.height; y++) { for (int x = 0; x < tex.width; x++) { float noiseX = (((float)x / (float)tex.width) * (plane.transform.localScale.x * 10)); float noiseY = (((float)y / (float)tex.height) * (plane.transform.localScale.z * 10)); float value = (noise.GetValue(noiseX, noiseY, settings)); //Debug.Log("Value at " + noiseX + "/" + noiseY + "/" + 1f + ": " + rmfn.GetValue(noiseX, noiseY, 1f)); float colorValue = (value - blackValue) / (whiteValue - blackValue); tex.SetPixel(tex.width - x - 1, tex.height - y - 1, new Color(colorValue, colorValue, colorValue)); } } tex.Apply(); plane.GetComponent <MeshRenderer>().material.mainTexture = tex; }
public void generateWorld() { Debug.Log("generating world"); Physics.gravity = new Vector3(0, 0, 1f); this.mapGenerationSettings = MapGenerationSettings.loadSettings(applicationPersistentPath); this.mapData = MapData.loadData(applicationPersistentPath); UIController.getInstance().updateSettingsPanel(this.mapGenerationSettings, 0); Map map = MapGenerator.generateMap(0, mapGenerationSettings, mapData, applicationPersistentPath, this.randomGenerator); //UIController.getInstance().setCameraPosition(HexMathHelper.hexToWorldCoords(MapGenerator.mapCenter(this.mapGenerationSettings), MeshMapController.getInstance().getHexSize())); MeshMapController.getInstance().map = map; MeshMapController.getInstance().drawMap(); this.partyGenerationSettings = PartyGenerationSettings.loadSettings(applicationPersistentPath); Party party = PartyGenerator.getInstance().generateParty(applicationPersistentPath, this.partyGenerationSettings); PartyController.getInstance().party = party; PartyController.getInstance().setInitialPosition(MapGenerator.mapCenter(this.mapGenerationSettings)); UIController.getInstance().showPartyInfo(); UIController.getInstance().startingMenuPanel.SetActive(false); UIController.getInstance().inGamePanel.SetActive(true); this.currentTime = this.partyGenerationSettings.nightTime; }
/// <summary> /// Returns the wind direction for the given position in ° (0-359) /// </summary> public override float GetValue(float x, float y, MapGenerationSettings settings) { float noiseValue = Mathf.PerlinNoise(OffsetX + x * BaseScale, OffsetY + y * BaseScale); float value = mod((int)(noiseValue * 720f), 360); return(value); }
public static Map generateMap(int mapSeed, MapGenerationSettings mapGenerationSettings, MapData mapData, string applicationPersistentDataPath, System.Random randomGenerator) { Map map = new Map(); if (mapSeed == 0) { mapSeed = UnityEngine.Random.Range(0, 100); } Debug.Log(mapSeed); randomGenerator = new System.Random(mapSeed); for (int y = 0; y < mapGenerationSettings.mapHeight; y++) { for (int x = 0; x < mapGenerationSettings.mapWidth; x++) { int xOffset = y / 2; map.hexes.Add(generateHex(x + xOffset, y)); } } generateRegions(map, mapGenerationSettings, randomGenerator); generateTerrain(map, randomGenerator, mapGenerationSettings); generateClimate(map, randomGenerator, mapGenerationSettings); spawnWater(map, randomGenerator); setRiverPoints(map, randomGenerator); generateBiomes(map, mapData, randomGenerator); return(map); }
/// <summary> /// Returns average temperature for the given position in °C /// </summary> public override float GetValue(float x, float y, MapGenerationSettings settings) { float yEquator = settings.Height / 2; float baseTemp = PoleTemperature + ((1 - (Mathf.Abs(y - yEquator) / yEquator)) * (EquatorTemperature - PoleTemperature)); float tempModifier = Mathf.PerlinNoise(OffsetX + x * BaseScale, OffsetY + y * BaseScale) * TempModifyRange - TempModifyRange / 2; return(baseTemp + tempModifier); }
public static void saveSettings(string applicationPersistentPath, MapGenerationSettings mapGenerationSettings) { Debug.Log("saving..."); string settingsJson = JsonUtility.ToJson(mapGenerationSettings); File.WriteAllText(applicationPersistentPath + "/" + PARTY_GENERATION_SETTINGS_PERSIST_PATH + ".json", settingsJson); Debug.Log("saved"); }
/// <summary> /// Returns the annual precipitation for the given position in mm /// </summary> public override float GetValue(float x, float y, MapGenerationSettings settings) { float yEquator = settings.Height / 2; float basePrec = PolePrecipitation + ((1 - (Mathf.Abs(y - yEquator) / yEquator)) * (EquatorPrecipitation - PolePrecipitation)); float precMoidifer = Mathf.PerlinNoise(OffsetX + x * BaseScale, OffsetY + y * BaseScale); return(basePrec * precMoidifer); }
private void StartMapGeneration(int size) { MapGenerationSettings settings = new MapGenerationSettings(MapGenerationSettings.RandomSeed(), size, size, 0.08f, 1.5f, 5, 30, MapType.Island); PMG.GenerateMap(settings, OnMapGenerationDone); LoadingScreen.gameObject.SetActive(true); Hide(); }
static Vector2 findFirstRegionCorePosition(System.Random randomGenerator, MapGenerationSettings mapGenerationSettings) { List <Vector2> possiblePositions = new List <Vector2>(); //possiblePositions.Add(new Vector2(1 + 2, 2)); //possiblePositions.Add(new Vector2(mapWidth - 1 - 2 + 1, 2)); //possiblePositions.Add(new Vector2((mapHeight - 1 - 2) / 2 + 2, mapHeight - 1 - 2)); //possiblePositions.Add(new Vector2(mapWidth - 1 - 2 + (mapHeight - 1 - 2) / 2, mapHeight - 1 - 2)); possiblePositions.Add(mapCenter(mapGenerationSettings)); return(possiblePositions[randomGenerator.Next(possiblePositions.Count)]); }
public void InitGame(int numPlayers, int numStartingTerritories, int numStartingArmies) { State = GameState.Initializing; NumPlayers = numPlayers; NumStartingTerritories = numStartingTerritories; NumStartingArmies = numStartingArmies; Turn = 0; MapGenerationSettings settings = new MapGenerationSettings(MapGenerationSettings.RandomSeed(), 15, 10, 0.4f, 2f, 3, 12, MapType.BigOceans); PMG.GenerateMap(settings, OnMapGenerationDone); }
/// <summary> /// Returns the water topology type for the given position: /// 0 = Ocean /// 1 = Deep Ocean /// </summary> public override float GetValue(float x, float y, MapGenerationSettings settings) { float deepOceanValue = Mathf.PerlinNoise(DeepOceanOffsetX + x * BaseScale, DeepOceanOffsetY + y * BaseScale); if (deepOceanValue < 0.5f) { return(1); } else { return(0); } }
public void updatePanel(MapGenerationSettings mapGenerationSettings, int mapSeed) { Debug.Log(this.mapGenerationSettings.mapHeight); this.mapGenerationSettings = mapGenerationSettings; this.mapHeightInputField.text = this.mapGenerationSettings.mapHeight.ToString(); this.mapWidthInputField.text = this.mapGenerationSettings.mapWidth.ToString(); this.mapSeedInputField.text = mapSeed.ToString(); this.minRegionSizeInputField.text = this.mapGenerationSettings.minRegionSize.ToString(); this.maxRegionSizeInputField.text = this.mapGenerationSettings.maxRegionSize.ToString(); this.clustersPercentInputField.text = this.mapGenerationSettings.terrainClustersPercent.ToString(); this.adjacencyBonusInputField.text = this.mapGenerationSettings.terrainAdjucencyPercentBoost.ToString(); this.minMiddleClimatePercentInputField.text = this.mapGenerationSettings.middleClimateStripeMinHeightPercent.ToString(); this.maxMiddleClimatePercentInputField.text = this.mapGenerationSettings.middleClimateStripeMaxHeightPercent.ToString(); }
public static Vector2 getClosestToCenterFreeHex(Map map, MapGenerationSettings mapGenerationSettings, System.Random randomGenerator) { Vector2 mapCenter = MapGenerator.mapCenter(mapGenerationSettings); for (int radius = 1; radius < mapGenerationSettings.mapWidth / 2; radius++) { List <Vector2> circleHexes = HexMathHelper.getCircleAround(mapCenter, radius); shuffleList(circleHexes, randomGenerator); foreach (Vector2 hexPosition in circleHexes) { Hex hex = getHex((int)hexPosition.x, (int)hexPosition.y, map); if (hex != null && hex.regionId == 0) { return(hexPosition); } } } return(new Vector2(0, 0)); }
public static void generateRegions(Map map, MapGenerationSettings mapGenerationSettings, System.Random randomGenerator) { Vector2 firstRegionCorePosition = findFirstRegionCorePosition(randomGenerator, mapGenerationSettings); generateRegion(firstRegionCorePosition, 1, "First region", randomGenerator, map, mapGenerationSettings); int regionIndex = 2; while (canGenerateRegion(map, mapGenerationSettings) && map.regions.Count < mapGenerationSettings.mapHeight * mapGenerationSettings.mapWidth / mapGenerationSettings.minRegionSize) { generateRegion(getClosestToCenterFreeHex(map, mapGenerationSettings, randomGenerator), regionIndex, "First region", randomGenerator, map, mapGenerationSettings); regionIndex++; } removeSmallRegions(map); for (int i = 0; i < 2; i++) { fillHoles(map, randomGenerator); } removeEmptyTiles(map); }
private void GenerateButton_OnClick() { if (int.Parse(WidthText.text) < 3 || int.Parse(WidthText.text) > 25 || int.Parse(HeightText.text) < 3 || int.Parse(HeightText.text) > 25 || float.Parse(MinAreaText.text) > 0.5) { return; } Reset(); // Generate new map int seed = SeedText.text != "" ? int.Parse(SeedText.text) : MapGenerationSettings.RandomSeed(); int width = int.Parse(WidthText.text); int height = int.Parse(HeightText.text); float minRegionArea = float.Parse(MinAreaText.text); float maxRegionArea = float.Parse(MaxAreaText.text); int minContinentSize = int.Parse(MinContinentSizeText.text); int maxContinentSize = int.Parse(MaxContinentSizeText.text); float continentSizeFactor = ContinentSizeSlider.value; MapGenerationSettings settings = new MapGenerationSettings(seed, width, height, minRegionArea, maxRegionArea, minContinentSize, maxContinentSize, CurrentMapType, continentSizeFactor); PMG.GenerateMap(settings, callback: OnMapGenerationDone); }
/// <summary> /// Returns the topology type for the given position: /// 0 = Flat /// 1 = Hills /// 2 = Mountains /// 3 = Lake /// </summary> public override float GetValue(float x, float y, MapGenerationSettings settings) { float hillValue = Mathf.PerlinNoise(HillOffsetX + x * BaseScale, HillOffsetY + y * BaseScale); float mountainValue = Mathf.PerlinNoise(MountainOffsetX + x * BaseScale, MountainOffsetY + y * BaseScale); float lakeValue = Mathf.PerlinNoise(LakeOffsetX + x * BaseScale, LakeOffsetY + y * BaseScale); if (mountainValue < 0.2f) { return(2); } else if (hillValue < 0.35f) { return(1); } else if (lakeValue < 0.2f) { return(3); } else { return(0); } }
/// <summary> /// Creating a new singleplayer game or multiplayer game as host /// </summary> public void InitNewGame(GameSettings gameSettings, GameType type) { if (State != GameState.Inactive) { return; } InitGame(); GameSettings = gameSettings; ApplyGameSettings(); GameType = type; int mapSeed = GetRandomSeed(); StartGameSeed = GetRandomSeed(); MapGenerationSettings settings = new MapGenerationSettings(mapSeed, 10, 10, 0.08f, 1.5f, 5, 30, MapType.Island); if (GameType == GameType.MultiplayerHost) { NetworkPlayer.Server.GenerateMapServerRpc(mapSeed, StartGameSeed); } PMG.GenerateMap(settings, callback: OnMapGenerationDone); }
public abstract float GetValue(float x, float y, MapGenerationSettings settings);
public void updateSettingsPanel(MapGenerationSettings mapGenerationSettings, int mapSeed) { SettingsPanelController settingsPanelController = settingsPanel.GetComponent <SettingsPanelController>(); settingsPanelController.updatePanel(mapGenerationSettings, mapSeed); }
public static void generateClimate(Map map, System.Random randomGenerator, MapGenerationSettings mapGenerationSettings) { ClimateType middleClimateType = ClimateType.TEMPERATE; ClimateType upperClimateType = ClimateType.COOL; ClimateType bottomClimateType = ClimateType.WARM; int minY = 100000; int maxY = -100000; foreach (Hex hex in map.hexes) { if (hex.y > maxY) { maxY = hex.y; } if (hex.y < minY) { minY = hex.y; } } int actualMapHeight = maxY - minY; int middleClimateStripeHeight = actualMapHeight * randomGenerator.Next(mapGenerationSettings.middleClimateStripeMinHeightPercent, mapGenerationSettings.middleClimateStripeMaxHeightPercent) / 100; int minMiddleClimateY = minY + (actualMapHeight - middleClimateStripeHeight) / 2; int maxMiddleClimateY = minY + (actualMapHeight + middleClimateStripeHeight) / 2; foreach (Region region in map.regions) { int topHexCount = 0; int middleHexCount = 0; int bottomHexCount = 0; List <Hex> regionHexes = getRegionHexes(map, region.id); foreach (Hex hex in regionHexes) { if (hex.y < minMiddleClimateY) { bottomHexCount++; } else if (hex.y >= minMiddleClimateY && hex.y <= maxMiddleClimateY) { middleHexCount++; } else if (hex.y > maxMiddleClimateY) { topHexCount++; } } ClimateType regionClimateType = middleClimateType; if (topHexCount >= (topHexCount + middleHexCount + bottomHexCount) * mapGenerationSettings.marginalClimateThreshold / 100) { regionClimateType = upperClimateType; } else if (bottomHexCount >= (topHexCount + middleHexCount + bottomHexCount) * mapGenerationSettings.marginalClimateThreshold / 100) { regionClimateType = bottomClimateType; } region.climateType = regionClimateType; foreach (Hex hex in regionHexes) { hex.climateType = regionClimateType; hex.addTag(getClimateTag(regionClimateType)); } } }
public static void generateTerrain(Map map, System.Random randomGenerator, MapGenerationSettings mapGenerationSettings) { foreach (Region region in map.regions) { region.terrainProfile = TerrainProfile.TERRAIN_PROFILES[randomGenerator.Next(TerrainProfile.TERRAIN_PROFILES.Length)]; List <Hex> regionHexes = getRegionHexes(map, region.id); int lowTerrainClustersCount = regionHexes.Count * mapGenerationSettings.terrainClustersPercent / 100 * region.terrainProfile.lowPercent / 100; int normalTerrainClustersCount = regionHexes.Count * mapGenerationSettings.terrainClustersPercent / 100 * region.terrainProfile.normalPercent / 100; int elevatedTerrainClustersCount = regionHexes.Count * mapGenerationSettings.terrainClustersPercent / 100 * region.terrainProfile.elevatedPercent / 100; int highTerrainClustersCount = regionHexes.Count * mapGenerationSettings.terrainClustersPercent / 100 * region.terrainProfile.highPercent / 100; shuffleList(regionHexes, randomGenerator); for (int lowTerrain = 0; lowTerrain < lowTerrainClustersCount; lowTerrain++) { if (regionHexes.Count > 0) { regionHexes[0].terrainType = TerrainType.LOW; regionHexes[0].addTag("low"); regionHexes.RemoveAt(0); } } for (int normalTerrain = 0; normalTerrain < normalTerrainClustersCount; normalTerrain++) { if (regionHexes.Count > 0) { regionHexes[0].terrainType = TerrainType.NORMAL; regionHexes[0].addTag("normal"); regionHexes.RemoveAt(0); } } for (int elevatedTerrain = 0; elevatedTerrain < elevatedTerrainClustersCount; elevatedTerrain++) { if (regionHexes.Count > 0) { regionHexes[0].terrainType = TerrainType.ELEVATED; regionHexes[0].addTag("elevated"); regionHexes.RemoveAt(0); } } for (int highTerrain = 0; highTerrain < highTerrainClustersCount; highTerrain++) { if (regionHexes.Count > 0) { regionHexes[0].terrainType = TerrainType.HIGH; regionHexes[0].addTag("high"); regionHexes.RemoveAt(0); } } foreach (Hex hex in regionHexes) { List <Vector2> hexNeighbours = HexMathHelper.getHexNeighbours(new Vector2(hex.x, hex.y), 1); int lowAdjacentHexCount = 0; int normalAdjacentHexCount = 0; int elevatedAdjacentHexCount = 0; int highAdjacentHexCount = 0; foreach (Vector2 hexCoordinate in hexNeighbours) { Hex neighbourHex = getHex(hexCoordinate.x, hexCoordinate.y, map); if (neighbourHex != null) { if (neighbourHex.terrainType == TerrainType.LOW) { lowAdjacentHexCount++; } else if (neighbourHex.terrainType == TerrainType.NORMAL) { normalAdjacentHexCount++; } else if (neighbourHex.terrainType == TerrainType.ELEVATED) { elevatedAdjacentHexCount++; } else if (neighbourHex.terrainType == TerrainType.HIGH) { highAdjacentHexCount++; } } } while (lowAdjacentHexCount > 0 && normalAdjacentHexCount > 0 && elevatedAdjacentHexCount > 0 && highAdjacentHexCount > 0) { lowAdjacentHexCount--; normalAdjacentHexCount--; elevatedAdjacentHexCount--; highAdjacentHexCount--; } int lowPercentForThisHex = region.terrainProfile.lowPercent + lowAdjacentHexCount * mapGenerationSettings.terrainAdjucencyPercentBoost; int normalPercentForThisHex = region.terrainProfile.normalPercent + normalAdjacentHexCount * mapGenerationSettings.terrainAdjucencyPercentBoost; int elevatedPercentForThisHex = region.terrainProfile.elevatedPercent + elevatedAdjacentHexCount * mapGenerationSettings.terrainAdjucencyPercentBoost; int highPercentForThisHex = region.terrainProfile.highPercent + highAdjacentHexCount * mapGenerationSettings.terrainAdjucencyPercentBoost; int adjacentTerrainClusters = lowAdjacentHexCount + normalAdjacentHexCount + elevatedAdjacentHexCount + highAdjacentHexCount; if (adjacentTerrainClusters > 0) { int numberOfDifferentAdjacentTerrains = 0; if (lowAdjacentHexCount > 0) { numberOfDifferentAdjacentTerrains++; } if (normalAdjacentHexCount > 0) { numberOfDifferentAdjacentTerrains++; } if (elevatedAdjacentHexCount > 0) { numberOfDifferentAdjacentTerrains++; } if (highAdjacentHexCount > 0) { numberOfDifferentAdjacentTerrains++; } int overPercent = adjacentTerrainClusters * mapGenerationSettings.terrainAdjucencyPercentBoost; int percentSubstract = overPercent / (4 - numberOfDifferentAdjacentTerrains); if (lowAdjacentHexCount == 0) { lowPercentForThisHex -= percentSubstract; } if (normalAdjacentHexCount == 0) { normalPercentForThisHex -= percentSubstract; } if (elevatedAdjacentHexCount == 0) { elevatedPercentForThisHex -= percentSubstract; } if (highAdjacentHexCount == 0) { highPercentForThisHex -= percentSubstract; } int roll = randomGenerator.Next(lowPercentForThisHex + normalPercentForThisHex + elevatedPercentForThisHex + highPercentForThisHex); if (roll < lowPercentForThisHex) { hex.terrainType = TerrainType.LOW; hex.addTag("low"); } else if (roll < normalPercentForThisHex + lowPercentForThisHex) { hex.terrainType = TerrainType.NORMAL; hex.addTag("normal"); } else if (roll < elevatedPercentForThisHex + normalPercentForThisHex + lowPercentForThisHex) { hex.terrainType = TerrainType.ELEVATED; hex.addTag("elevated"); } else if (roll < highPercentForThisHex + elevatedPercentForThisHex + normalPercentForThisHex + lowPercentForThisHex) { hex.terrainType = TerrainType.HIGH; hex.addTag("high"); } } } } }
static bool canGenerateRegion(Map map, MapGenerationSettings mapGenerationSettings) { return(getOccupiedHexCount(map) < (mapGenerationSettings.mapWidth * mapGenerationSettings.mapHeight - mapGenerationSettings.maxRegionSize) && getFreeHexCount(map) > mapGenerationSettings.minRegionSize); }
public static Vector2 mapCenter(MapGenerationSettings mapGenerationSettings) { return(new Vector2(mapGenerationSettings.mapWidth / 2 + mapGenerationSettings.mapHeight / 4, mapGenerationSettings.mapHeight / 2)); }
public void saveSettings() { MapGenerationSettings.saveSettings(persistentPath, this.mapGenerationSettings); }
public static string GetMapHash(PolygonMapGenerator PMG) { StringBuilder hash = new StringBuilder(); // Line 0 (GenerationSettings.*): seed;width;height;minPolygonArea;maxPolygonArea;minContinentSize;maxContinentSize;mapType;continentSizeScale MapGenerationSettings mgs = PMG.GenerationSettings; hash.AppendLine(mgs.Seed + ";" + mgs.Width + ";" + mgs.Height + ";" + mgs.MinPolygonArea + ";" + mgs.MaxPolygonArea + ";" + mgs.MinContinentSize + ";" + mgs.MaxContinentSize + ";" + (int)mgs.MapType + ";" + mgs.ContinentSizeScaleFactor); // Line 1: n_nodes;n_ingraphconnections;n_egdeconnections;n_polygons;n_paths;n_landmasses;n_waterbodies;n_continents hash.AppendLine(PMG.Nodes.Count + ";" + PMG.InGraphConnections.Count + ";" + PMG.EdgeConnections.Count + ";" + PMG.Polygons.Count + ";" + PMG.RiverPaths.Count + ";" + PMG.Landmasses.Count + ";" + PMG.WaterBodies.Count + ";" + PMG.Continents.Count); // Node Lines: id;positionX;positionY;riverWidth;distanceFromNearestOcean foreach (GraphNode n in PMG.Nodes) { hash.AppendLine(n.Id + ";" + n.Vertex.x + ";" + n.Vertex.y + ";" + n.RiverWidth + ";" + n.DistanceFromNearestOcean); } // InGraphConnection Lines: id;fromNodeId;toNodeId;riverWidth foreach (GraphConnection c in PMG.InGraphConnections) { hash.AppendLine(c.Id + ";" + c.StartNode.Id + ";" + c.EndNode.Id + ";" + c.RiverWidth); } // EdgeConnection Lines: id;fromNodeId;toNodeId;riverWidth foreach (GraphConnection c in PMG.EdgeConnections) { hash.AppendLine(c.Id + ";" + c.StartNode.Id + ";" + c.EndNode.Id + ";" + c.RiverWidth); } // Polygon Lines: id;[nodeIds];[connectionIds] foreach (GraphPolygon p in PMG.Polygons) { hash.Append(p.Id + ";"); foreach (GraphNode n in p.Nodes) { hash.Append(n.Id + ","); } hash.Append(";"); foreach (GraphConnection c in p.Connections) { hash.Append(c.Id + ","); } hash.AppendLine(); } // River Path Lines: id;[nodeIds];[connectionIds];[polygonIds] foreach (GraphPath r in PMG.RiverPaths) { hash.Append(r.Id + ";"); foreach (GraphNode n in r.Nodes) { hash.Append(n.Id + ","); } hash.Append(";"); foreach (GraphConnection c in r.Connections) { hash.Append(c.Id + ","); } hash.Append(";"); foreach (GraphPolygon p in r.Polygons) { hash.Append(p.Id + ","); } hash.AppendLine(); } // Landmass Lines: [polygonIds] foreach (List <GraphPolygon> list in PMG.Landmasses) { foreach (GraphPolygon p in list) { hash.Append("p.Id" + ","); } hash.AppendLine(); } // Water Body Lines: [polygonIds] foreach (List <GraphPolygon> list in PMG.WaterBodies) { foreach (GraphPolygon p in list) { hash.Append("p.Id" + ","); } hash.AppendLine(); } // Continent Lines: [polygonIds] foreach (List <GraphPolygon> list in PMG.Continents) { foreach (GraphPolygon p in list) { hash.Append("p.Id" + ","); } hash.AppendLine(); } return(hash.ToString()); }
static void generateRegion(Vector2 corePosition, int id, string name, System.Random randomGenerator, Map map, MapGenerationSettings mapGenerationSettings) { Color32 regionColor = new Color32((byte)randomGenerator.Next(170), (byte)randomGenerator.Next(170), (byte)randomGenerator.Next(170), 255); Region region = new Region(id, name, regionColor); map.regions.Add(region); region.growthType = getRandomGrowthType(randomGenerator); generateConcentratedRegion(region, corePosition, map, randomGenerator, mapGenerationSettings); }
static void generateConcentratedRegion(Region region, Vector2 corePosition, Map map, System.Random randomGenerator, MapGenerationSettings mapGenerationSettings) { Hex coreHex = getHex((int)corePosition.x, (int)corePosition.y, map); if (coreHex == null) { coreHex = generateHex((int)corePosition.x, (int)corePosition.y); } coreHex.regionId = region.id; int regionSize = randomGenerator.Next(mapGenerationSettings.minRegionSize, mapGenerationSettings.maxRegionSize); Vector2 currentPosition = corePosition; int currentSize = 1; while (currentSize <= regionSize) { List <Vector2> possibleDirections = MapGenerator.possibleDirections(map, currentPosition); if (possibleDirections.Count == 0) { break; } int[] weightsArray = new int[possibleDirections.Count]; for (int i = 0; i < possibleDirections.Count; i++) { int weight = 1; int neighboursFromSameRegion = 0; Vector2 neighbour = possibleDirections[i]; List <Vector2> neighbourCoordinates = HexMathHelper.getHexNeighbours(new Vector2(neighbour.x, neighbour.y), 1); foreach (Vector2 neighbourCoordinate in neighbourCoordinates) { Hex hex = getHex((int)neighbourCoordinate.x, (int)neighbourCoordinate.y, map); if (hex != null && hex.regionId == region.id) { neighboursFromSameRegion++; } } //there's always one neighbour from the region weight = weight * (int)Mathf.Pow(10, (neighboursFromSameRegion - 1)); //discourage going out of bounds if (getHex((int)neighbour.x, (int)neighbour.y, map) == null) { weight = neighboursFromSameRegion; } weightsArray[i] = weight; } int weightSum = arraySum(weightsArray); int roll = randomGenerator.Next(weightSum); for (int weightIndex = 0; weightIndex < weightsArray.Length; weightIndex++) { int currentWeightSum = 0; for (int weightSumIndex = 0; weightSumIndex <= weightIndex; weightSumIndex++) { currentWeightSum += weightsArray[weightSumIndex]; } if (roll < currentWeightSum) { currentPosition = possibleDirections[weightIndex]; break; } } Hex nextHex = getHex((int)currentPosition.x, (int)currentPosition.y, map); if (nextHex == null) { nextHex = generateHex((int)currentPosition.x, (int)currentPosition.y); map.hexes.Add(nextHex); } nextHex.regionId = region.id; currentSize++; } }
public Map(MapGenerationSettings settings) { Attributes = settings; }
public void restoreDefaults() { updatePanel(MapGenerationSettings.loadSettings(persistentPath), 0); }