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 |
@@ -114,7 +114,7 | |||
|
114 | 114 | |
|
115 | 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 | 120 | private System.Collections.Generic.IEnumerable<Cell> iterate_neighbors(int x, int y) |
@@ -175,19 +175,19 | |||
|
175 | 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 | 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 | 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 | 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 | 192 | SendMessage(new MoveCameraMessage {Movement = new Vector2(4, 0)}); |
|
193 | 193 | } |
@@ -107,7 +107,7 | |||
|
107 | 107 | //calculate the probability in order to get the expected number of removed trees |
|
108 | 108 | var expected = to_remove; |
|
109 | 109 | var trials = tree_squares.Count(); |
|
110 | double probability = ((double)expected / (double)trials); | |
|
110 | double probability = ((double)expected / (double)trials) / 12; | |
|
111 | 111 | |
|
112 | 112 | foreach (var square in tree_squares) |
|
113 | 113 | { |
@@ -120,7 +120,7 | |||
|
120 | 120 | } |
|
121 | 121 | if (removed >= to_remove) |
|
122 | 122 | { |
|
123 | break; | |
|
123 | // break; | |
|
124 | 124 | } |
|
125 | 125 | } |
|
126 | 126 | } |
@@ -57,8 +57,8 | |||
|
57 | 57 | if (random_generator.NextDouble() < 0.5 |
|
58 | 58 | && !squares.Contains(new_square) |
|
59 | 59 | && !occupied_squares.Contains(new_square) |
|
60 |
&& MathUtils.Between |
|
|
61 |
&& MathUtils.Between |
|
|
60 | && MathUtils.Between(new_square.X, 0, this.MapWidth) | |
|
61 | && MathUtils.Between(new_square.Y, 0, this.MapHeight) | |
|
62 | 62 | ) |
|
63 | 63 | { |
|
64 | 64 | squares_to_add.Add(new_square); |
@@ -485,8 +485,8 | |||
|
485 | 485 | Vector2 original = Vector2.Transform(new Vector2(screenX, screenY), camera.get_transformation(GraphicsDevice)); |
|
486 | 486 | |
|
487 | 487 | return (!FNAGame.enableCulling || |
|
488 | (MathUtils.Between(original.X, -Tile.TileSpriteWidth, FNAGame.width) | |
|
489 | && MathUtils.Between(original.Y, -Tile.TileSpriteHeight, FNAGame.height))); | |
|
488 | (MathUtils.BetweenExclusive(original.X, -Tile.TileSpriteWidth, FNAGame.width) | |
|
489 | && MathUtils.BetweenExclusive(original.Y, -Tile.TileSpriteHeight, FNAGame.height))); | |
|
490 | 490 | } |
|
491 | 491 | |
|
492 | 492 | //Convenience method I'm not super sure about anymore. |
@@ -782,14 +782,14 | |||
|
782 | 782 | null); |
|
783 | 783 | |
|
784 | 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 | 787 | has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].hasTree; |
|
788 | 788 | } |
|
789 | 789 | //*/ |
|
790 | 790 | |
|
791 | 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 | 794 | status_left = String.Format("{0:},{1:} {2} ({3})", this.mouseGrid.X, this.mouseGrid.Y, |
|
795 | 795 | this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].status, |
@@ -43,7 +43,7 | |||
|
43 | 43 | |
|
44 | 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 | 47 | return stop; |
|
48 | 48 | } |
|
49 | 49 |
@@ -37,16 +37,16 | |||
|
37 | 37 | this.previous_budget = previous_budget; |
|
38 | 38 | |
|
39 | 39 | if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
40 | && MathUtils.Between(mouseCur.X, width+x-20, width+x) | |
|
41 | && MathUtils.Between(mouseCur.Y, y+bar_height, y+bar_height+20) | |
|
40 | && MathUtils.BetweenExclusive(mouseCur.X, width+x-20, width+x) | |
|
41 | && MathUtils.BetweenExclusive(mouseCur.Y, y+bar_height, y+bar_height+20) | |
|
42 | 42 | ) { |
|
43 | 43 | |
|
44 | 44 | return false; |
|
45 | 45 | |
|
46 | 46 | } |
|
47 | 47 | else if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
48 | && MathUtils.Between(mouseCur.X, x, width+x) | |
|
49 | && MathUtils.Between(mouseCur.Y, y, 500 + y)) | |
|
48 | && MathUtils.BetweenExclusive(mouseCur.X, x, width+x) | |
|
49 | && MathUtils.BetweenExclusive(mouseCur.Y, y, 500 + y)) | |
|
50 | 50 | { |
|
51 | 51 | if (mousePrev.LeftButton == ButtonState.Released) |
|
52 | 52 | { |
@@ -7,17 +7,29 | |||
|
7 | 7 | { |
|
8 | 8 | } |
|
9 | 9 | |
|
10 | ||
|
10 | 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 | 24 | return ((x < val && val < y) || (y < val && val < x)); |
|
13 | 25 | |
|
14 | 26 | } |
|
15 | 27 | |
|
16 |
|
|
|
17 | { | |
|
18 |
|
|
|
28 | public static bool BetweenExclusive(int val, int x, int y) | |
|
29 | { | |
|
30 | return ((x < val && val < y) || (y < val && val < x)); | |
|
19 | 31 | |
|
20 | } | |
|
32 | } | |
|
21 | 33 | |
|
22 | 34 | public static bool BetweenInclusive(float val, float x, float y) |
|
23 | 35 | { |
@@ -25,88 +37,91 | |||
|
25 | 37 | |
|
26 | 38 | } |
|
27 | 39 | |
|
28 |
|
|
|
29 | { | |
|
30 |
|
|
|
40 | public static bool BetweenInclusive(int val, int x, int y) | |
|
41 | { | |
|
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 |
|
|
|
51 | { | |
|
52 |
|
|
|
62 | protected float Decrement(float value, float delta) | |
|
63 | { | |
|
64 | float magnitude = Math.Abs(value); | |
|
53 | 65 | |
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 | { | |
|
58 | return 0.0f; | |
|
59 | } | |
|
60 |
|
|
|
61 | { | |
|
62 |
|
|
|
63 | } | |
|
64 |
|
|
|
65 | { | |
|
66 |
|
|
|
67 | } | |
|
68 | else | |
|
69 | { | |
|
70 | return 0.0f; | |
|
71 | } | |
|
72 | } | |
|
66 | //If distance from zero is less than our delta, | |
|
67 | //go to zero to prevent overshooting: | |
|
68 | if (magnitude < delta) | |
|
69 | { | |
|
70 | return 0.0f; | |
|
71 | } | |
|
72 | else if (value > 0) | |
|
73 | { | |
|
74 | return value - delta; | |
|
75 | } | |
|
76 | else if (value < 0) | |
|
77 | { | |
|
78 | return value + delta; | |
|
79 | } | |
|
80 | else | |
|
81 | { | |
|
82 | return 0.0f; | |
|
83 | } | |
|
84 | } | |
|
73 | 85 | |
|
74 | 86 | |
|
75 | 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 | 92 | double u1 = random.NextDouble(); |
|
80 | 93 | double u2 = random.NextDouble(); |
|
81 | 94 | |
|
82 | 95 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); |
|
83 | 96 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); |
|
84 | 97 | |
|
85 |
|
|
|
86 |
|
|
|
87 | } | |
|
98 | yield return (variation * z1) + mean; | |
|
99 | yield return (variation * z2) + mean; | |
|
100 | } | |
|
88 | 101 | } |
|
89 | 102 | |
|
90 | 103 | public static Double NextNormal(Random random, float mean, float variation) |
|
91 | 104 | { |
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
105 | //Uses Box-Muller to scale the default uniform distribution | |
|
106 | double u1 = random.NextDouble(); | |
|
107 | double u2 = random.NextDouble(); | |
|
95 | 108 | |
|
96 |
|
|
|
97 |
|
|
|
109 | double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); | |
|
110 | double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); | |
|
98 | 111 | |
|
99 |
|
|
|
100 | return (variation * z1) + mean; | |
|
101 | } | |
|
102 | else { | |
|
103 | return (variation * z2) + mean; | |
|
104 | } | |
|
112 | if (random.NextDouble() > 0.5d) | |
|
113 | { | |
|
114 | return (variation * z1) + mean; | |
|
115 | } | |
|
116 | else | |
|
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