private void InitColonyMainBases(int coloniesSeed) { List <Vector2Int> colonyIndices = new List <Vector2Int>(); int offsettedColoniesSeed = coloniesSeed; int previousAmount = 0; while (colonyIndices.Count != colonyAmount) { AddColonyMainBases(colonyIndices, offsettedColoniesSeed); ++offsettedColoniesSeed; if (previousAmount == colonyIndices.Count) { Debug.LogError("Cannot add one more colony"); break; } previousAmount = colonyIndices.Count; } foreach (Vector2Int currentColony in colonyIndices) { WorldMap.HexCell hexCell = WorldMap.HexCell.Empty; hexCell.hexType = WorldMap.HexType.ColonyMainBase; worldMap.worldAreaInfo.area[currentColony.x, currentColony.y] = hexCell; } }
private void AddColonyMainBases(List <Vector2Int> colonyIndices, int offsettedColoniesSeed) { bool isAdded = false; InitWorldAreaWithHexType(WorldMap.HexType.ColonyMainBase, mainBaseRiddling, offsettedColoniesSeed, resourceMaterial, resourceCamera, false, ref isAdded); List <Vector2Int> allColonyIndices = new List <Vector2Int>(); for (int x = 0; x < cellColumns; ++x) { for (int y = 0; y < cellRows; ++y) { WorldMap.HexCell hexCell = worldMap.worldAreaInfo.area[x, y]; if (hexCell.hexType == WorldMap.HexType.ColonyMainBase) { allColonyIndices.Add(new Vector2Int(x, y)); hexCell.hexType = WorldMap.HexType.Land; worldMap.worldAreaInfo.area[x, y] = hexCell; } } } Utils.Shuffle(allColonyIndices, offsettedColoniesSeed); List <Vector2Int> unusedColonyIndices = new List <Vector2Int>(); int minDistanceBetweenColony = distanceBetweenColony; void AddCorrectIndices() { for (int i = 0; i < allColonyIndices.Count && colonyIndices.Count != colonyAmount; ++i) { Vector2Int currentIndices = allColonyIndices[i]; if (IsValidDistanceToOtherColony(colonyIndices, currentIndices, distanceBetweenColony)) { colonyIndices.Add(currentIndices); } else { unusedColonyIndices.Add(currentIndices); } } } AddCorrectIndices(); --minDistanceBetweenColony; while (colonyIndices.Count != colonyAmount && unusedColonyIndices.Count != 0 && minDistanceBetweenColony >= 1) { allColonyIndices = unusedColonyIndices; unusedColonyIndices = new List <Vector2Int>(); AddCorrectIndices(); --minDistanceBetweenColony; } }
private void InitLand() { for (int x = 0; x < cellColumns; ++x) { for (int y = 0; y < cellRows; ++y) { Vector2Int indices = new Vector2Int(x, y); Vector3 centerPosition = worldMap.GetHexPosition(indices); WorldMap.HexCell hexCell = WorldMap.HexCell.Empty; if (worldMap.IsHexInsideMap(centerPosition)) { hexCell.hexType = WorldMap.HexType.Land; } worldMap.worldAreaInfo.area[x, y] = hexCell; } } }
private void InitChankWithHexType(WorldMap.HexType hexType, int chankX, int chankY, Material currentMaterial, Camera currentCamera, bool isIncludeNoneType, ref bool isAdded) { int currentXOffset = chankX * chankSize; int currentYOffset = chankY * chankSize; Color32[] colors = TakeResourceSnapshot(chankX, chankY, currentMaterial, currentCamera); for (int pixelX = 0; pixelX < renderTexture.width; ++pixelX) { for (int pixelY = 0; pixelY < renderTexture.height; ++pixelY) { Color32 color = colors[pixelX + pixelY * renderTexture.width]; Vector3 position = new Vector3(pixelX + currentXOffset, 0f, pixelY + currentYOffset); Vector2Int indices = worldMap.GetHexIndices(position); if (worldMap.IsValidHexIndices(indices)) { WorldMap.HexCell hexCell = worldMap.worldAreaInfo.area[indices.x, indices.y]; if (color.r != 0) { if (hexCell.hexType == hexType) { hexCell.resourceAmount += color.r; worldMap.worldAreaInfo.area[indices.x, indices.y] = hexCell; } else if ((isIncludeNoneType && hexCell.hexType == WorldMap.HexType.None) || hexCell.hexType == WorldMap.HexType.Land) { isAdded |= true; hexCell.hexType = hexType; hexCell.resourceAmount += color.r; worldMap.worldAreaInfo.area[indices.x, indices.y] = hexCell; } } } } } }
private void SetResourcePrefabs(int aIForNPCSeed) { LimitedMinedResourceInfo[] hexTypeToLimitedMinedResourceInfo = new LimitedMinedResourceInfo[(int)WorldMap.HexType.AllResources]; foreach (LimitedMinedResourceInfo resourceInfo in limitedMinedResourceInfoList.resourceInfos) { WorldMap.HexType hexType = WorldMap.GameResourceTypeToHexType(resourceInfo.gameResourceType); hexTypeToLimitedMinedResourceInfo[(int)hexType] = resourceInfo; } int currentAIForNPCOffset = aIForNPCSeed; for (int x = 0; x < cellColumns; ++x) { for (int y = 0; y < cellRows; ++y) { WorldMap.HexCell hexCell = worldMap.worldAreaInfo.area[x, y]; if (WorldMap.IsResourceOnlyType(hexCell.hexType)) { GameResourceType gameResourceType = WorldMap.HexTypeToGameResourceType(hexCell.hexType); GameObject resourceDeposit = Instantiate(resourceDepositPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, resourcesTransform); ResourceSprite resourceSprite = resourceDeposit.GetComponent <ResourceSprite>(); resourceSprite.InitWithGameResourceType(gameResourceType); ResourceDeposit resourceDepositScript = resourceDeposit.GetComponent <ResourceDeposit>(); LimitedMinedResourceInfo limitedMinedResourceInfo = hexTypeToLimitedMinedResourceInfo[(int)hexCell.hexType]; float resourceAmount = limitedMinedResourceInfo.minAmount + Mathf.Pow(hexCell.resourceAmount / maxPossibleResourceValuePerCell, limitedMinedResourceInfo.power) * (limitedMinedResourceInfo.maxAmount - limitedMinedResourceInfo.minAmount); resourceDepositScript.SetResourceType(gameResourceType, resourceAmount); hexCell.indexInResourceArray = (short)worldMap.resourceDepositArray.Count; worldMap.worldAreaInfo.area[x, y] = hexCell; worldMap.resourceDepositArray.Add(resourceDepositScript); worldMap.resourceDepositIndicesArray.Add(new Vector2Int(x, y)); } else if (hexCell.hexType == WorldMap.HexType.Mountain) { GameObject mountain = Instantiate(mountainPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, mountainsTransform); EnvironmentHeightParameter environmentHeightParameter = mountain.GetComponent <EnvironmentHeightParameter>(); environmentHeightParameter.InitHeight(hexCell.resourceAmount / maxPossibleResourceValuePerCell); } else if (hexCell.hexType == WorldMap.HexType.Crater) { GameObject crater = Instantiate(craterPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, cratersTransform); EnvironmentHeightParameter environmentHeightParameter = crater.GetComponent <EnvironmentHeightParameter>(); environmentHeightParameter.InitHeight(hexCell.resourceAmount / maxPossibleResourceValuePerCell); } else if (hexCell.hexType == WorldMap.HexType.ColonyMainBase) { GameObject mainBaseLocation = Instantiate(mainBaseLocationPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, mainBaseLocationsTransform); ColonyTeritory colonyTeritory = mainBaseLocation.GetComponent <ColonyTeritory>(); Vector3[] positions = worldMap.GetHexRings(worldMap.GetHexPosition(new Vector2Int(x, y)), 1, colonyRaduis); bool isPlayer = worldMap.colonyMainBaseArray.Count == 0; colonyTeritory.InitAvailableHexes(new List <Vector3>(positions), isPlayer); if (!isPlayer) { AIForNPC aIForNPC = mainBaseLocation.GetComponent <AIForNPC>(); aIForNPC.worldMap = worldMap; aIForNPC.freezer = freezer; aIForNPC.colonyRaduis = colonyRaduis; aIForNPC.seed = currentAIForNPCOffset; aIForNPC.enabled = true; ++currentAIForNPCOffset; } hexCell.indexInColonyMainBaseArray = (short)worldMap.colonyMainBaseArray.Count; worldMap.worldAreaInfo.area[x, y] = hexCell; worldMap.colonyMainBaseArray.Add(mainBaseLocation); worldMap.colonyMainBaseIndicesArray.Add(new Vector2Int(x, y)); } } } }