Description:
Change delta to be per-year
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -114,7 +114,7 | |||||
|
114 |
|
114 | ||
|
115 | public Boolean inBounds(int x, int y) |
|
115 | public Boolean inBounds(int x, int y) |
|
116 | { |
|
116 | { |
|
117 | return MathUtils.Between(x, 0, MapWidth - 1) && MathUtils.Between(y, 0, MapHeight - 1); |
|
117 | return MathUtils.BetweenExclusive(x, 0, MapWidth - 1) && MathUtils.BetweenExclusive(y, 0, MapHeight - 1); |
|
118 | } |
|
118 | } |
|
119 |
|
119 | ||
|
120 | private System.Collections.Generic.IEnumerable<Cell> iterate_neighbors(int x, int y) |
|
120 | private System.Collections.Generic.IEnumerable<Cell> iterate_neighbors(int x, int y) |
@@ -175,19 +175,19 | |||||
|
175 | #region mouse_movement |
|
175 | #region mouse_movement |
|
176 |
|
176 | ||
|
177 |
|
177 | ||
|
178 | if (MathUtils.Between(mouseCur.Y, menuBarHeight, 50 + menuBarHeight)) |
|
178 | if (MathUtils.BetweenExclusive(mouseCur.Y, menuBarHeight, 50 + menuBarHeight)) |
|
179 | { |
|
179 | { |
|
180 | SendMessage(new MoveCameraMessage {Movement = new Vector2(0, -4)}); |
|
180 | SendMessage(new MoveCameraMessage {Movement = new Vector2(0, -4)}); |
|
181 | } |
|
181 | } |
|
182 | else if (MathUtils.Between(mouseCur.Y, (this.viewHeight - 50 -menuBarHeight), this.viewHeight-menuBarHeight)) |
|
182 | else if (MathUtils.BetweenExclusive(mouseCur.Y, (this.viewHeight - 50 -menuBarHeight), this.viewHeight-menuBarHeight)) |
|
183 | { |
|
183 | { |
|
184 | SendMessage(new MoveCameraMessage {Movement = new Vector2(0, 4)}); |
|
184 | SendMessage(new MoveCameraMessage {Movement = new Vector2(0, 4)}); |
|
185 | } |
|
185 | } |
|
186 | if (MathUtils.Between(mouseCur.X, 0, 50)) |
|
186 | if (MathUtils.BetweenExclusive(mouseCur.X, 0, 50)) |
|
187 | { |
|
187 | { |
|
188 | SendMessage(new MoveCameraMessage {Movement = new Vector2(-4, 0)}); |
|
188 | SendMessage(new MoveCameraMessage {Movement = new Vector2(-4, 0)}); |
|
189 | } |
|
189 | } |
|
190 | else if (MathUtils.Between(mouseCur.X, (this.viewWidth - 50), this.viewWidth)) |
|
190 | else if (MathUtils.BetweenExclusive(mouseCur.X, (this.viewWidth - 50), this.viewWidth)) |
|
191 | { |
|
191 | { |
|
192 | SendMessage(new MoveCameraMessage {Movement = new Vector2(4, 0)}); |
|
192 | SendMessage(new MoveCameraMessage {Movement = new Vector2(4, 0)}); |
|
193 | } |
|
193 | } |
@@ -107,7 +107,7 | |||||
|
107 | //calculate the probability in order to get the expected number of removed trees |
|
107 | //calculate the probability in order to get the expected number of removed trees |
|
108 | var expected = to_remove; |
|
108 | var expected = to_remove; |
|
109 | var trials = tree_squares.Count(); |
|
109 | var trials = tree_squares.Count(); |
|
110 | double probability = ((double)expected / (double)trials); |
|
110 | double probability = ((double)expected / (double)trials) / 12; |
|
111 |
|
111 | ||
|
112 | foreach (var square in tree_squares) |
|
112 | foreach (var square in tree_squares) |
|
113 | { |
|
113 | { |
@@ -120,7 +120,7 | |||||
|
120 | } |
|
120 | } |
|
121 | if (removed >= to_remove) |
|
121 | if (removed >= to_remove) |
|
122 | { |
|
122 | { |
|
123 | break; |
|
123 | // break; |
|
124 | } |
|
124 | } |
|
125 | } |
|
125 | } |
|
126 | } |
|
126 | } |
@@ -57,8 +57,8 | |||||
|
57 | if (random_generator.NextDouble() < 0.5 |
|
57 | if (random_generator.NextDouble() < 0.5 |
|
58 | && !squares.Contains(new_square) |
|
58 | && !squares.Contains(new_square) |
|
59 | && !occupied_squares.Contains(new_square) |
|
59 | && !occupied_squares.Contains(new_square) |
|
60 |
&& MathUtils.Between |
|
60 | && MathUtils.Between(new_square.X, 0, this.MapWidth) |
|
61 |
&& MathUtils.Between |
|
61 | && MathUtils.Between(new_square.Y, 0, this.MapHeight) |
|
62 | ) |
|
62 | ) |
|
63 | { |
|
63 | { |
|
64 | squares_to_add.Add(new_square); |
|
64 | squares_to_add.Add(new_square); |
@@ -485,8 +485,8 | |||||
|
485 | Vector2 original = Vector2.Transform(new Vector2(screenX, screenY), camera.get_transformation(GraphicsDevice)); |
|
485 | Vector2 original = Vector2.Transform(new Vector2(screenX, screenY), camera.get_transformation(GraphicsDevice)); |
|
486 |
|
486 | ||
|
487 | return (!FNAGame.enableCulling || |
|
487 | return (!FNAGame.enableCulling || |
|
488 | (MathUtils.Between(original.X, -Tile.TileSpriteWidth, FNAGame.width) |
|
488 | (MathUtils.BetweenExclusive(original.X, -Tile.TileSpriteWidth, FNAGame.width) |
|
489 | && MathUtils.Between(original.Y, -Tile.TileSpriteHeight, FNAGame.height))); |
|
489 | && MathUtils.BetweenExclusive(original.Y, -Tile.TileSpriteHeight, FNAGame.height))); |
|
490 | } |
|
490 | } |
|
491 |
|
491 | ||
|
492 | //Convenience method I'm not super sure about anymore. |
|
492 | //Convenience method I'm not super sure about anymore. |
@@ -782,14 +782,14 | |||||
|
782 | null); |
|
782 | null); |
|
783 |
|
783 | ||
|
784 | bool has_tree = false; |
|
784 | bool has_tree = false; |
|
785 | if (MathUtils.Between(this.mouseGrid.X, 0, this.squaresAcross) && MathUtils.Between(this.mouseGrid.Y, 0, this.squaresAcross)) |
|
785 | if (MathUtils.BetweenExclusive(this.mouseGrid.X, 0, this.squaresAcross) && MathUtils.BetweenExclusive(this.mouseGrid.Y, 0, this.squaresAcross)) |
|
786 | { |
|
786 | { |
|
787 | has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].hasTree; |
|
787 | has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].hasTree; |
|
788 | } |
|
788 | } |
|
789 | //*/ |
|
789 | //*/ |
|
790 |
|
790 | ||
|
791 | String status_left = ""; |
|
791 | String status_left = ""; |
|
792 | if (MathUtils.Between(this.mouseGrid.X, -1, this.simulation.map.MapWidth) && MathUtils.Between(this.mouseGrid.Y, -1, this.simulation.map.MapHeight)) |
|
792 | if (MathUtils.BetweenExclusive(this.mouseGrid.X, -1, this.simulation.map.MapWidth) && MathUtils.BetweenExclusive(this.mouseGrid.Y, -1, this.simulation.map.MapHeight)) |
|
793 | { |
|
793 | { |
|
794 | status_left = String.Format("{0:},{1:} {2} ({3})", this.mouseGrid.X, this.mouseGrid.Y, |
|
794 | status_left = String.Format("{0:},{1:} {2} ({3})", this.mouseGrid.X, this.mouseGrid.Y, |
|
795 | this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].status, |
|
795 | this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].status, |
@@ -43,7 +43,7 | |||||
|
43 |
|
43 | ||
|
44 | public static Vector2 departurePoint(Vector2 start, Vector2 stop, float width, float height) |
|
44 | public static Vector2 departurePoint(Vector2 start, Vector2 stop, float width, float height) |
|
45 | { |
|
45 | { |
|
46 | if (MathUtils.Between(stop.X, 0, width ) && MathUtils.Between(stop.Y, 0, height)) { |
|
46 | if (MathUtils.BetweenExclusive(stop.X, 0, width ) && MathUtils.BetweenExclusive(stop.Y, 0, height)) { |
|
47 | return stop; |
|
47 | return stop; |
|
48 | } |
|
48 | } |
|
49 |
|
49 |
@@ -37,16 +37,16 | |||||
|
37 | this.previous_budget = previous_budget; |
|
37 | this.previous_budget = previous_budget; |
|
38 |
|
38 | ||
|
39 | if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
39 | if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
40 | && MathUtils.Between(mouseCur.X, width+x-20, width+x) |
|
40 | && MathUtils.BetweenExclusive(mouseCur.X, width+x-20, width+x) |
|
41 | && MathUtils.Between(mouseCur.Y, y+bar_height, y+bar_height+20) |
|
41 | && MathUtils.BetweenExclusive(mouseCur.Y, y+bar_height, y+bar_height+20) |
|
42 | ) { |
|
42 | ) { |
|
43 |
|
43 | ||
|
44 | return false; |
|
44 | return false; |
|
45 |
|
45 | ||
|
46 | } |
|
46 | } |
|
47 | else if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
47 | else if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
48 | && MathUtils.Between(mouseCur.X, x, width+x) |
|
48 | && MathUtils.BetweenExclusive(mouseCur.X, x, width+x) |
|
49 | && MathUtils.Between(mouseCur.Y, y, 500 + y)) |
|
49 | && MathUtils.BetweenExclusive(mouseCur.Y, y, 500 + y)) |
|
50 | { |
|
50 | { |
|
51 | if (mousePrev.LeftButton == ButtonState.Released) |
|
51 | if (mousePrev.LeftButton == ButtonState.Released) |
|
52 | { |
|
52 | { |
@@ -7,17 +7,29 | |||||
|
7 | { |
|
7 | { |
|
8 | } |
|
8 | } |
|
9 |
|
9 | ||
|
|
10 | |||
|
10 | public static bool Between(float val, float x, float y) |
|
11 | public static bool Between(float val, float x, float y) |
|
11 | { |
|
12 | { |
|
|
13 | return ((x <= val && val < y) || (y <= val && val < x)); | ||
|
|
14 | |||
|
|
15 | } | ||
|
|
16 | |||
|
|
17 | public static bool Between(int val, int x, int y) | ||
|
|
18 | { | ||
|
|
19 | return ((x <= val && val < y) || (y <= val && val < x)); | ||
|
|
20 | |||
|
|
21 | } | ||
|
|
22 | public static bool BetweenExclusive(float val, float x, float y) | ||
|
|
23 | { | ||
|
12 | return ((x < val && val < y) || (y < val && val < x)); |
|
24 | return ((x < val && val < y) || (y < val && val < x)); |
|
13 |
|
25 | ||
|
14 | } |
|
26 | } |
|
15 |
|
27 | ||
|
16 |
|
|
28 | public static bool BetweenExclusive(int val, int x, int y) |
|
17 | { |
|
29 | { |
|
18 |
|
|
30 | return ((x < val && val < y) || (y < val && val < x)); |
|
19 |
|
31 | ||
|
20 | } |
|
32 | } |
|
21 |
|
33 | ||
|
22 | public static bool BetweenInclusive(float val, float x, float y) |
|
34 | public static bool BetweenInclusive(float val, float x, float y) |
|
23 | { |
|
35 | { |
@@ -25,88 +37,91 | |||||
|
25 |
|
37 | ||
|
26 | } |
|
38 | } |
|
27 |
|
39 | ||
|
28 |
|
|
40 | public static bool BetweenInclusive(int val, int x, int y) |
|
29 | { |
|
41 | { |
|
30 |
|
|
42 | return ((x <= val && val <= y) || (y <= val && val <= x)); |
|
31 |
|
43 | ||
|
32 | } |
|
44 | } |
|
33 |
|
45 | ||
|
34 |
|
|
46 | public static int Clamp(int val, int min, int max) |
|
35 | { |
|
47 | { |
|
36 |
|
|
48 | if (val > max) |
|
37 | { |
|
49 | { |
|
38 | return max; |
|
50 | return max; |
|
39 | } |
|
51 | } |
|
40 |
|
|
52 | else if (val < min) |
|
41 | { |
|
53 | { |
|
42 | return min; |
|
54 | return min; |
|
43 | } |
|
55 | } |
|
44 | else |
|
56 | else |
|
45 | { |
|
57 | { |
|
46 | return val; |
|
58 | return val; |
|
47 | } |
|
59 | } |
|
48 | } |
|
60 | } |
|
49 |
|
61 | ||
|
50 |
|
|
62 | protected float Decrement(float value, float delta) |
|
51 | { |
|
63 | { |
|
52 |
|
|
64 | float magnitude = Math.Abs(value); |
|
53 |
|
65 | ||
|
54 |
|
|
66 | //If distance from zero is less than our delta, |
|
55 |
|
|
67 | //go to zero to prevent overshooting: |
|
56 |
|
|
68 | if (magnitude < delta) |
|
57 | { |
|
69 | { |
|
58 | return 0.0f; |
|
70 | return 0.0f; |
|
59 | } |
|
71 | } |
|
60 |
|
|
72 | else if (value > 0) |
|
61 | { |
|
73 | { |
|
62 |
|
|
74 | return value - delta; |
|
63 | } |
|
75 | } |
|
64 |
|
|
76 | else if (value < 0) |
|
65 | { |
|
77 | { |
|
66 |
|
|
78 | return value + delta; |
|
67 | } |
|
79 | } |
|
68 | else |
|
80 | else |
|
69 | { |
|
81 | { |
|
70 | return 0.0f; |
|
82 | return 0.0f; |
|
71 | } |
|
83 | } |
|
72 | } |
|
84 | } |
|
73 |
|
85 | ||
|
74 |
|
86 | ||
|
75 | public static System.Collections.Generic.IEnumerable<Double> NextNormalEnumerator(Random random, float mean, float variation) |
|
87 | public static System.Collections.Generic.IEnumerable<Double> NextNormalEnumerator(Random random, float mean, float variation) |
|
76 | { |
|
88 | { |
|
77 |
|
89 | ||
|
78 | while (true) { |
|
90 | while (true) |
|
|
91 | { | ||
|
79 | double u1 = random.NextDouble(); |
|
92 | double u1 = random.NextDouble(); |
|
80 | double u2 = random.NextDouble(); |
|
93 | double u2 = random.NextDouble(); |
|
81 |
|
94 | ||
|
82 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); |
|
95 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); |
|
83 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); |
|
96 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); |
|
84 |
|
97 | ||
|
85 |
|
|
98 | yield return (variation * z1) + mean; |
|
86 |
|
|
99 | yield return (variation * z2) + mean; |
|
87 | } |
|
100 | } |
|
88 | } |
|
101 | } |
|
89 |
|
102 | ||
|
90 | public static Double NextNormal(Random random, float mean, float variation) |
|
103 | public static Double NextNormal(Random random, float mean, float variation) |
|
91 | { |
|
104 | { |
|
92 |
|
|
105 | //Uses Box-Muller to scale the default uniform distribution |
|
93 |
|
|
106 | double u1 = random.NextDouble(); |
|
94 |
|
|
107 | double u2 = random.NextDouble(); |
|
95 |
|
108 | ||
|
96 |
|
|
109 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); |
|
97 |
|
|
110 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); |
|
98 |
|
111 | ||
|
99 |
|
|
112 | if (random.NextDouble() > 0.5d) |
|
100 | return (variation * z1) + mean; |
|
113 | { |
|
101 | } |
|
114 | return (variation * z1) + mean; |
|
102 | else { |
|
115 | } |
|
103 | return (variation * z2) + mean; |
|
116 | else |
|
104 | } |
|
117 | { |
|
|
118 | return (variation * z2) + mean; | ||
|
|
119 | } | ||
|
105 |
|
120 | ||
|
106 |
|
121 | ||
|
107 |
|
122 | ||
|
108 | } |
|
123 | } |
|
109 |
|
124 | ||
|
110 | } |
|
125 | } |
|
111 |
|
126 | ||
|
112 | } |
|
127 | } |
You need to be logged in to leave comments.
Login now