Description:
Some refactoring.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -124,7 +124,7 | |||
|
124 | 124 | { |
|
125 | 125 | if (this.random_generator.NextDouble() > 0.75) |
|
126 | 126 | { |
|
127 |
int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, |
|
|
127 | int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR); | |
|
128 | 128 | int random_month = random_generator.Next(1, 12); |
|
129 | 129 | DateTime random_date = new DateTime(random_year, random_month, 1); |
|
130 | 130 | |
@@ -145,9 +145,6 | |||
|
145 | 145 | |
|
146 | 146 | currentNode = DialogTrees.introTree; |
|
147 | 147 | |
|
148 | ||
|
149 | ||
|
150 | ||
|
151 | 148 | } |
|
152 | 149 | |
|
153 | 150 | protected override void Initialize() |
@@ -37,6 +37,11 | |||
|
37 | 37 | public const int START_MONTH = 1; |
|
38 | 38 | public const int START_DAY = 1; |
|
39 | 39 | |
|
40 | public DateTime START_DATETIME{ | |
|
41 | get { | |
|
42 | return new DateTime(START_YEAR, START_MONTH, START_DAY); | |
|
43 | }} | |
|
44 | ||
|
40 | 45 | |
|
41 | 46 | private const float SPONTANEOUS_NEW_TREE_CHANCE = 0.9995f; |
|
42 | 47 | private const float NEIGHBOR_NEW_TREE_CHANCE = 0.995f; |
@@ -45,6 +50,9 | |||
|
45 | 50 | public const int TREE_PLANT_COST = 750; |
|
46 | 51 | public const int TREE_CLEAR_COST = 500; |
|
47 | 52 | |
|
53 | public const int MAX_TREES_TO_PLANT = 25; | |
|
54 | public const int MAX_TREES_TO_CLEAR = 25; | |
|
55 | ||
|
48 | 56 | public int Tick |
|
49 | 57 | { |
|
50 | 58 | get; |
@@ -139,7 +147,7 | |||
|
139 | 147 | return _tree_planting; |
|
140 | 148 | } |
|
141 | 149 | set { |
|
142 |
_tree_planting = MathUtils.Clamp(value, 0, |
|
|
150 | _tree_planting = MathUtils.Clamp(value, 0, MAX_TREES_TO_PLANT); | |
|
143 | 151 | } |
|
144 | 152 | } |
|
145 | 153 | private int _tree_clearing = 0; |
@@ -149,7 +157,7 | |||
|
149 | 157 | return _tree_clearing; |
|
150 | 158 | } |
|
151 | 159 | set { |
|
152 |
_tree_clearing = MathUtils.Clamp(value, 0, |
|
|
160 | _tree_clearing = MathUtils.Clamp(value, 0, MAX_TREES_TO_CLEAR); | |
|
153 | 161 | } |
|
154 | 162 | } |
|
155 | 163 |
@@ -34,11 +34,11 | |||
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | int new_tree_planting = sim.tree_planting; |
|
37 |
ImGui.SliderInt("Tree Planting ", ref new_tree_planting, 0, |
|
|
37 | ImGui.SliderInt("Tree Planting ", ref new_tree_planting, 0, Simulation.MAX_TREES_TO_PLANT, string.Format("%d (${0})", new_tree_planting*Simulation.TREE_PLANT_COST)); | |
|
38 | 38 | sim.tree_planting = new_tree_planting; |
|
39 | 39 | |
|
40 | 40 | int new_tree_clearing = sim.tree_clearing; |
|
41 |
ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, |
|
|
41 | ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, Simulation.MAX_TREES_TO_CLEAR, string.Format("%d (${0})", new_tree_clearing*Simulation.TREE_CLEAR_COST)); | |
|
42 | 42 | sim.tree_clearing = new_tree_clearing; |
|
43 | 43 | |
|
44 | 44 | ImGui.Text(string.Format("Crowded Trees: {0}", sim.crowded_trees )); |
@@ -60,7 +60,7 | |||
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | |
|
63 | public static System.Collections.Generic.IEnumerable<Double> NextNormalEnumerator(Random random, float mean) | |
|
63 | public static System.Collections.Generic.IEnumerable<Double> NextNormalEnumerator(Random random, float mean, float variation) | |
|
64 | 64 | { |
|
65 | 65 | |
|
66 | 66 | while (true) { |
@@ -70,13 +70,14 | |||
|
70 | 70 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); |
|
71 | 71 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); |
|
72 | 72 | |
|
73 | yield return z1; | |
|
74 | yield return z2; | |
|
73 | yield return (variation * z1) + mean; | |
|
74 | yield return (variation * z2) + mean; | |
|
75 | 75 | } |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | public static Double NextNormal(Random random, float mean, float variation) |
|
79 | 79 | { |
|
80 | //Uses Box-Muller to scale the default uniform distribution | |
|
80 | 81 | double u1 = random.NextDouble(); |
|
81 | 82 | double u2 = random.NextDouble(); |
|
82 | 83 |
You need to be logged in to leave comments.
Login now