private void InitWorldAreaWithHexType(WorldMap.HexType hexType, float riddling, int areaSeed, Material currentMaterial, Camera currentCamera, bool isIncludeNoneType, ref bool isAdded) { currentMaterial.SetFloat("Vector1_Riddling", riddling); currentMaterial.SetFloat("Vector1_Seed", areaSeed); for (int chankX = 0; chankX < width / chankSize; ++chankX) { for (int chankY = 0; chankY < height / chankSize; ++chankY) { InitChankWithHexType(hexType, chankX, chankY, currentMaterial, currentCamera, isIncludeNoneType, ref isAdded); } } }
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 InitResources(int resourcesSeed) { int resourceSeed = resourcesSeed; foreach (LimitedMinedResourceInfo resourceInfo in limitedMinedResourceInfoList.resourceInfos) { bool isAdded = false; float riddling = resourceInfo.riddling; WorldMap.HexType hexType = WorldMap.GameResourceTypeToHexType(resourceInfo.gameResourceType); for (int i = 0; i < attemptsAmountToAddAnyResourcesPerType && !isAdded; ++i) { InitWorldAreaWithHexType(hexType, riddling, resourceSeed, resourceMaterial, resourceCamera, false, ref isAdded); riddling *= 2f; ++resourceSeed; } if (!isAdded) { Debug.LogError(string.Format("Cannot add {0} resource. Increase resource riddling may fix the problem", hexType.ToString())); } } }
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)); } } } }