Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```C#
- GaiaConstants.FeatureType GetWeightedRandomFeatureType()
- {
- //Choose a random number
- float randomPick = UnityEngine.Random.Range(0f, 1f);
- //Work out the random number ranges
- float sumRanges = m_genChanceOfHills + m_genChanceOfIslands + m_genChanceOfLakes + m_genChanceOfMesas + m_genChanceOfMountains +
- m_genChanceOfPlains + m_genChanceOfRivers + m_genChanceOfValleys + m_genChanceOfVillages + m_genChanceOfWaterfalls;
- //Stop divide by zero
- if (sumRanges == 0f)
- {
- sumRanges = 1f;
- }
- //Set our way through it - crude but effective
- float currStep = 0f;
- float nextStep = 0f;
- nextStep = currStep + (m_genChanceOfHills / sumRanges);
- if (randomPick >= currStep && randomPick < nextStep)
- {
- return GaiaConstants.FeatureType.Hills;
- }
- currStep = nextStep;
- nextStep = currStep + (m_genChanceOfIslands / sumRanges);
- if (randomPick >= currStep && randomPick < nextStep)
- {
- return GaiaConstants.FeatureType.Islands;
- }
- currStep = nextStep;
- nextStep = currStep + (m_genChanceOfLakes / sumRanges);
- if (randomPick >= currStep && randomPick < nextStep)
- {
- return GaiaConstants.FeatureType.Lakes;
- }
- currStep = nextStep;
- nextStep = currStep + (m_genChanceOfMesas / sumRanges);
- if (randomPick >= currStep && randomPick < nextStep)
- {
- return GaiaConstants.FeatureType.Mesas;
- }
- currStep = nextStep;
- nextStep = currStep + (m_genChanceOfMountains / sumRanges);
- if (randomPick >= currStep && randomPick < nextStep)
- {
- return GaiaConstants.FeatureType.Mountains;
- }
- currStep = nextStep;
- nextStep = currStep + (m_genChanceOfPlains / sumRanges);
- if (randomPick >= currStep && randomPick < nextStep)
- {
- return GaiaConstants.FeatureType.Plains;
- }
- currStep = nextStep;
- nextStep = currStep + (m_genChanceOfRivers / sumRanges);
- if (randomPick >= currStep && randomPick < nextStep)
- {
- return GaiaConstants.FeatureType.Rivers;
- }```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement