public void fillPlanetPropabilities() { string jsonString = File.ReadAllText("./SystemGenerator/Workers/Version2/Data/SystemTwoGasGiant.json"); dynamic files = JsonConvert.DeserializeObject(jsonString); List <PlanetChance> chances = new List <PlanetChance>(); foreach (var f in files.planets) { PlanetChance chance = new PlanetChance { type = f.planet.planetType, circle = f.planet.circle, probability = f.planet.probability }; if (chances.Any(e => e.circle == chance.circle)) { chance.probStart = chances.Last(e => e.circle == chance.circle).probEnd; } chance.probEnd = chance.probStart + chance.probability; chances.Add(chance); if (!circlePlanetChances.ContainsKey(chance.circle)) { circlePlanetChances.Add(chance.circle, new List <PlanetChance>()); } circlePlanetChances[chance.circle].Add(chance); } }
//guarantee that exactly one earthlike is present // and also: one volcanic, two desert //keep this order: // Medium Light Light // volcanic, desert, desert, earthlike, barren, Asteroids, Gas, Asteroids, Gas, Ice, Asteroids // 2 4 5 6 7 8 9 10 11 12 13 /* * public void showPropabilities(System.Windows.Forms.TextBox textbox1) * { * if (textbox1 == null) return; * * for (int i = 0; i < planetPropability.Count; i += 10) * { * int overAllInCircle = 0; * textbox1.Text += "Circle " + i + " : "; * for (int j = 0; j < planetPropability[i].Count; j++) overAllInCircle++; * textbox1.Text += overAllInCircle + Environment.NewLine; * } * } */ public int getPlanetType(int _circle) { int random = RandomHelper.GetRandomInt(0, 100); if (!circlePlanetChances.ContainsKey(_circle)) { return(0); } if (!circlePlanetChances[_circle].Any(e => e.probStart <= random && e.probEnd > random)) { return(0); } PlanetChance planet = circlePlanetChances[_circle].First(e => e.probStart <= random && e.probEnd > random); return(planetObjectId(planet.type)); }