Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. ```C#
  2. GaiaConstants.FeatureType GetWeightedRandomFeatureType()
  3.         {
  4.             //Choose a random number
  5.             float randomPick = UnityEngine.Random.Range(0f, 1f);
  6.  
  7.             //Work out the random number ranges
  8.             float sumRanges = m_genChanceOfHills + m_genChanceOfIslands + m_genChanceOfLakes + m_genChanceOfMesas + m_genChanceOfMountains +
  9.                 m_genChanceOfPlains + m_genChanceOfRivers + m_genChanceOfValleys  + m_genChanceOfVillages + m_genChanceOfWaterfalls;
  10.  
  11.             //Stop divide by zero
  12.             if (sumRanges == 0f)
  13.             {
  14.                 sumRanges = 1f;
  15.             }
  16.  
  17.             //Set our way through it - crude but effective
  18.             float currStep = 0f;
  19.             float nextStep = 0f;
  20.  
  21.             nextStep = currStep + (m_genChanceOfHills / sumRanges);
  22.             if (randomPick >= currStep && randomPick < nextStep)
  23.             {
  24.                 return GaiaConstants.FeatureType.Hills;
  25.             }
  26.  
  27.             currStep = nextStep;
  28.             nextStep = currStep + (m_genChanceOfIslands / sumRanges);
  29.             if (randomPick >= currStep && randomPick < nextStep)
  30.             {
  31.                 return GaiaConstants.FeatureType.Islands;
  32.             }
  33.  
  34.             currStep = nextStep;
  35.             nextStep = currStep + (m_genChanceOfLakes / sumRanges);
  36.             if (randomPick >= currStep && randomPick < nextStep)
  37.             {
  38.                 return GaiaConstants.FeatureType.Lakes;
  39.             }
  40.  
  41.             currStep = nextStep;
  42.             nextStep = currStep + (m_genChanceOfMesas / sumRanges);
  43.             if (randomPick >= currStep && randomPick < nextStep)
  44.             {
  45.                 return GaiaConstants.FeatureType.Mesas;
  46.             }
  47.  
  48.             currStep = nextStep;
  49.             nextStep = currStep + (m_genChanceOfMountains / sumRanges);
  50.             if (randomPick >= currStep && randomPick < nextStep)
  51.             {
  52.                 return GaiaConstants.FeatureType.Mountains;
  53.             }
  54.  
  55.             currStep = nextStep;
  56.             nextStep = currStep + (m_genChanceOfPlains / sumRanges);
  57.             if (randomPick >= currStep && randomPick < nextStep)
  58.             {
  59.                 return GaiaConstants.FeatureType.Plains;
  60.             }
  61.  
  62.             currStep = nextStep;
  63.             nextStep = currStep + (m_genChanceOfRivers / sumRanges);
  64.             if (randomPick >= currStep && randomPick < nextStep)
  65.             {
  66.                 return GaiaConstants.FeatureType.Rivers;
  67.             }```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement