Merge lp:~widelands-dev/widelands/terrain_affinity_as_int into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8933
Proposed branch: lp:~widelands-dev/widelands/terrain_affinity_as_int
Merge into: lp:widelands
Diff against target: 1945 lines (+397/-389)
43 files modified
data/tribes/immovables/berry_bushes/blueberry/init.lua (+3/-3)
data/tribes/immovables/berry_bushes/currant_black/init.lua (+3/-3)
data/tribes/immovables/berry_bushes/currant_red/init.lua (+3/-3)
data/tribes/immovables/berry_bushes/desert_hackberry/init.lua (+3/-3)
data/tribes/immovables/berry_bushes/juniper/init.lua (+3/-3)
data/tribes/immovables/berry_bushes/raspberry/init.lua (+3/-3)
data/tribes/immovables/berry_bushes/sea_buckthorn/init.lua (+3/-3)
data/tribes/immovables/berry_bushes/strawberry/init.lua (+3/-3)
data/world/immovables/bush1/init.lua (+8/-8)
data/world/immovables/trees/alder/init.lua (+8/-8)
data/world/immovables/trees/aspen/init.lua (+3/-3)
data/world/immovables/trees/beech/init.lua (+3/-3)
data/world/immovables/trees/birch/init.lua (+3/-3)
data/world/immovables/trees/cirrus/init.lua (+3/-3)
data/world/immovables/trees/larch/init.lua (+3/-3)
data/world/immovables/trees/liana/init.lua (+3/-3)
data/world/immovables/trees/maple/init.lua (+3/-3)
data/world/immovables/trees/mushroom_dark/init.lua (+3/-3)
data/world/immovables/trees/mushroom_green/init.lua (+3/-3)
data/world/immovables/trees/mushroom_red/init.lua (+3/-3)
data/world/immovables/trees/oak/init.lua (+3/-3)
data/world/immovables/trees/palm_borassus/init.lua (+3/-3)
data/world/immovables/trees/palm_coconut/init.lua (+3/-3)
data/world/immovables/trees/palm_date/init.lua (+3/-3)
data/world/immovables/trees/palm_oil/init.lua (+3/-3)
data/world/immovables/trees/palm_roystonea/init.lua (+3/-3)
data/world/immovables/trees/rowan/init.lua (+3/-3)
data/world/immovables/trees/spruce/init.lua (+3/-3)
data/world/immovables/trees/twine/init.lua (+3/-3)
data/world/immovables/trees/umbrella_green/init.lua (+3/-3)
data/world/immovables/trees/umbrella_red/init.lua (+3/-3)
data/world/terrains/init.lua (+145/-145)
src/logic/game.cc (+0/-4)
src/logic/game.h (+0/-3)
src/logic/map_objects/immovable.cc (+3/-3)
src/logic/map_objects/terrain_affinity.cc (+62/-53)
src/logic/map_objects/terrain_affinity.h (+26/-20)
src/logic/map_objects/tribes/worker.cc (+11/-11)
src/logic/map_objects/world/terrain_description.cc (+10/-10)
src/logic/map_objects/world/terrain_description.h (+10/-10)
src/scripting/lua_map.cc (+10/-10)
test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua (+9/-9)
test/maps/lua_testsuite.wmf/scripting/terrains_resources_descriptions.lua (+8/-8)
To merge this branch: bzr merge lp:~widelands-dev/widelands/terrain_affinity_as_int
Reviewer Review Type Date Requested Status
Arty Approve
Review via email: mp+358299@code.launchpad.net

Commit message

Fix desyncs caused by floating point arithmetic

- Floating point arithmetic can become inconsistent across platforms/compilers/hardware
- Upscale terrain affinity constants to turn them into ints
- Upscale the result of the affinity calculation and then use std::floor to cut it off at
  largely reduced precision for consistent rounding behavior. This should fix inconsistencies
  with double rounding and rounding direction.
- Catch a possible division by 0.

Description of the change

Fix cross-platform desyncs caused by floating point arithmetic. Further reading:

https://randomascii.wordpress.com/2012/03/21/intermediate-floating-point-precision/

https://arxiv.org/abs/cs/0701192

Test savegame:

https://bugs.launchpad.net/widelands/+bug/1800338/comments/3

With this savegame, I can cause a multiplayer desync on the same machine by compiling one copy of Widelands with GCC and another copy with Clang. The desync happens before the ship finishes building. With this branch, the desync is gone.

To post a comment you must log in.
8916. By GunChleoc

Formatting to make the diff more readable. Found another double. Fixed a comment.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4197. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/452676073.
Appveyor build 3993. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_terrain_affinity_as_int-3993.

8917. By GunChleoc

Merged trunk.

8918. By GunChleoc

Fix description tests

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4213. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/453859920.
Appveyor build 4009. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_terrain_affinity_as_int-4009.

8919. By GunChleoc

Merged trunk.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4238. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/455849882.
Appveyor build 4034. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_terrain_affinity_as_int-4034.

Revision history for this message
Arty (artydent) wrote :

I reviewed the code and also tested somewhat. Still has a few issues, most of them minor though. See diff comments.

The file data\world\immovables\bush1\init.lua still has a few comments (lines 86-94) referring to the floating point values, this should also be changed in this branch.

Overall it should be much less likely now to get different results based on platform/compiler dependent precision choices, but they might still happen. There are still things based on floating point calculations (like the main probability calculation in calculate_probability_to_grow) but they might be difficult to replace with pure integer based stuff.
That said, considering that the ratios of the final probabilities of the six best immovables already change significantly with this branch, we could possibly also change the basic probability calculation to somewhat that uses only integer operations but is not too far off from the current approach (which seems to have been based roughly on multivariate normal distributions).

Btw, where did those three weight constants in calculate_probability_to_grow originally come from? Their precision is too high to be from a simple "try and error until it feels right" approach. They still feel quite arbitrary though.

review: Needs Fixing
8920. By GunChleoc

Addressed code review

8921. By GunChleoc

Merged trunk.

8922. By GunChleoc

Fix documentation

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the excellent review :)

I have addressed most of your comments and left replies to the rest.

One of our math wizards spent a long time tweaking the system and the function, so I'm hesitant to change any semantics here. There is an e function involved, so there is no way to avoid floating point completely unless we radically change the system.

Revision history for this message
Arty (artydent) wrote :

Yes, the exponential function is the problem. Approximating it with highish precision using only integer calculations would require a lot of computation, which isn't really feasible. There are reasonable options though if we don't mind straying a little. The function we use here is basically a three-dimensional Gauß-curve, and I think we could find an alternative that roughly preserves the shape and can be done with a small number of integer operations.
It's probably not necessary though, but if we keep getting desyncs because of such platform/compiler-dependent computation differences, this would provide an option.

I also replied to your replies.

8923. By GunChleoc

Clean up the math

8924. By GunChleoc

Merged trunk.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for your math wizardry - I have now implemented both suggestions.

I think that greatly cutting the precision while forcing a uniform rounding strategy (round down) should be good enough for our purposes. Let's merge this and see if we're still getting desyncs. We can always decide to change the formula later if necessary.

@bunnybot merge

Revision history for this message
Arty (artydent) wrote :

Looks good now.

The comment with the assciativity is kinda obsolete now though.

And using int64_t wasn't really necessary now that you use the weights linearly.

review: Approve
8925. By GunChleoc

Final polish

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/tribes/immovables/berry_bushes/blueberry/init.lua'
2--- data/tribes/immovables/berry_bushes/blueberry/init.lua 2018-02-17 15:41:29 +0000
3+++ data/tribes/immovables/berry_bushes/blueberry/init.lua 2018-11-23 12:45:17 +0000
4@@ -2,9 +2,9 @@
5
6 terrain_affinity = {
7 preferred_temperature = 45, -- Temperature is in arbitrary units.
8- preferred_humidity = 0.75, -- In percent (1 being very wet).
9- preferred_fertility = 0.4, -- In percent (1 being very fertile).
10- pickiness = 0.15, -- Lower means it is less picky, i.e. it can deal better.
11+ preferred_humidity = 750, -- Values between 0 and 1000 (1000 being very wet).
12+ preferred_fertility = 400, -- Values between 0 and 1000 (1000 being very fertile).
13+ pickiness = 15, -- Lower means it is less picky, i.e. it can deal better.
14 }
15
16 tribes:new_immovable_type {
17
18=== modified file 'data/tribes/immovables/berry_bushes/currant_black/init.lua'
19--- data/tribes/immovables/berry_bushes/currant_black/init.lua 2018-02-17 15:41:29 +0000
20+++ data/tribes/immovables/berry_bushes/currant_black/init.lua 2018-11-23 12:45:17 +0000
21@@ -2,9 +2,9 @@
22
23 terrain_affinity = {
24 preferred_temperature = 120,
25- preferred_humidity = 0.1,
26- preferred_fertility = 0.2,
27- pickiness = 0.5,
28+ preferred_humidity = 100,
29+ preferred_fertility = 200,
30+ pickiness = 50,
31 }
32
33 tribes:new_immovable_type {
34
35=== modified file 'data/tribes/immovables/berry_bushes/currant_red/init.lua'
36--- data/tribes/immovables/berry_bushes/currant_red/init.lua 2018-02-17 15:41:29 +0000
37+++ data/tribes/immovables/berry_bushes/currant_red/init.lua 2018-11-23 12:45:17 +0000
38@@ -2,9 +2,9 @@
39
40 terrain_affinity = {
41 preferred_temperature = 95,
42- preferred_humidity = 0.55,
43- preferred_fertility = 0.45,
44- pickiness = 0.4,
45+ preferred_humidity = 550,
46+ preferred_fertility = 450,
47+ pickiness = 40,
48 }
49
50 tribes:new_immovable_type {
51
52=== modified file 'data/tribes/immovables/berry_bushes/desert_hackberry/init.lua'
53--- data/tribes/immovables/berry_bushes/desert_hackberry/init.lua 2018-02-17 15:41:29 +0000
54+++ data/tribes/immovables/berry_bushes/desert_hackberry/init.lua 2018-11-23 12:45:17 +0000
55@@ -2,9 +2,9 @@
56
57 terrain_affinity = {
58 preferred_temperature = 170, -- Temperature is in arbitrary units.
59- preferred_humidity = 0.05, -- In percent (1 being very wet).
60- preferred_fertility = 0.05, -- In percent (1 being very fertile).
61- pickiness = 0.3, -- Lower means it is less picky, i.e. it can deal better.
62+ preferred_humidity = 50, -- Values between 0 and 1000 (1000 being very wet).
63+ preferred_fertility = 50, -- Values between 0 and 1000 (1000 being very fertile).
64+ pickiness = 30, -- Lower means it is less picky, i.e. it can deal better.
65 }
66
67 tribes:new_immovable_type {
68
69=== modified file 'data/tribes/immovables/berry_bushes/juniper/init.lua'
70--- data/tribes/immovables/berry_bushes/juniper/init.lua 2018-04-21 15:27:00 +0000
71+++ data/tribes/immovables/berry_bushes/juniper/init.lua 2018-11-23 12:45:17 +0000
72@@ -2,9 +2,9 @@
73
74 terrain_affinity = {
75 preferred_temperature = 115,
76- preferred_humidity = 0.6,
77- preferred_fertility = 0.2,
78- pickiness = 0.15,
79+ preferred_humidity = 600,
80+ preferred_fertility = 200,
81+ pickiness = 15,
82 }
83
84 tribes:new_immovable_type {
85
86=== modified file 'data/tribes/immovables/berry_bushes/raspberry/init.lua'
87--- data/tribes/immovables/berry_bushes/raspberry/init.lua 2018-02-17 15:41:29 +0000
88+++ data/tribes/immovables/berry_bushes/raspberry/init.lua 2018-11-23 12:45:17 +0000
89@@ -2,9 +2,9 @@
90
91 terrain_affinity = {
92 preferred_temperature = 50,
93- preferred_humidity = 0.3,
94- preferred_fertility = 0.05,
95- pickiness = 0.1,
96+ preferred_humidity = 300,
97+ preferred_fertility = 50,
98+ pickiness = 10,
99 }
100
101 tribes:new_immovable_type {
102
103=== modified file 'data/tribes/immovables/berry_bushes/sea_buckthorn/init.lua'
104--- data/tribes/immovables/berry_bushes/sea_buckthorn/init.lua 2018-02-17 15:41:29 +0000
105+++ data/tribes/immovables/berry_bushes/sea_buckthorn/init.lua 2018-11-23 12:45:17 +0000
106@@ -2,9 +2,9 @@
107
108 terrain_affinity = {
109 preferred_temperature = 100, -- Temperature is in arbitrary units.
110- preferred_humidity = 0.95, -- In percent (1 being very wet).
111- preferred_fertility = 0.05, -- In percent (1 being very fertile).
112- pickiness = 0.15, -- Lower means it is less picky, i.e. it can deal better.
113+ preferred_humidity = 950, -- Values between 0 and 1000 (1000 being very wet).
114+ preferred_fertility = 50, -- Values between 0 and 1000 (1000 being very fertile).
115+ pickiness = 15, -- Lower means it is less picky, i.e. it can deal better.
116 }
117
118 tribes:new_immovable_type {
119
120=== modified file 'data/tribes/immovables/berry_bushes/strawberry/init.lua'
121--- data/tribes/immovables/berry_bushes/strawberry/init.lua 2018-05-02 08:13:07 +0000
122+++ data/tribes/immovables/berry_bushes/strawberry/init.lua 2018-11-23 12:45:17 +0000
123@@ -2,9 +2,9 @@
124
125 terrain_affinity = {
126 preferred_temperature = 110, -- Temperature is in arbitrary units.
127- preferred_humidity = 0.6, -- In percent (1 being very wet).
128- preferred_fertility = 0.8, -- In percent (1 being very fertile).
129- pickiness = 0.2, -- Lower means it is less picky, i.e. it can deal better.
130+ preferred_humidity = 600, -- Values between 0 and 1000 (1000 being very wet).
131+ preferred_fertility = 800, -- Values between 0 and 1000 (1000 being very fertile).
132+ pickiness = 20, -- Lower means it is less picky, i.e. it can deal better.
133 }
134
135 tribes:new_immovable_type {
136
137=== modified file 'data/world/immovables/bush1/init.lua'
138--- data/world/immovables/bush1/init.lua 2017-09-02 16:12:50 +0000
139+++ data/world/immovables/bush1/init.lua 2018-11-23 12:45:17 +0000
140@@ -83,15 +83,15 @@
141 -- -- Temperature is in arbitrary units.
142 -- preferred_temperature = 125,
143 --
144--- -- In percent (1 being very wet).
145--- preferred_humidity = 0.65,
146---
147--- -- In percent (1 being very fertile).
148--- preferred_fertility = 0.6,
149---
150--- -- A value in [0, 1] that defines how well this immovable can deal with non-ideal terrain.
151+-- -- The preferred humibity. This is a value between 0 and 1000, with 1000 being very wet.
152+-- preferred_humidity = 650,
153+--
154+-- -- The preferred fertility. This is a value between 0 and 1000, with 1000 being very fertile.
155+-- preferred_fertility = 600,
156+--
157+-- -- A value in [0, 99] that defines how well this immovable can deal with non-ideal terrain.
158 -- -- A lower value means that it is less picky, i.e. it can deal better with it.
159--- pickiness = 0.6,
160+-- pickiness = 60,
161 -- }
162 --
163 -- **animations**
164
165=== modified file 'data/world/immovables/trees/alder/init.lua'
166--- data/world/immovables/trees/alder/init.lua 2016-02-10 19:50:13 +0000
167+++ data/world/immovables/trees/alder/init.lua 2018-11-23 12:45:17 +0000
168@@ -4,15 +4,15 @@
169 -- Temperature is in arbitrary units.
170 preferred_temperature = 125,
171
172- -- In percent (1 being very wet).
173- preferred_humidity = 0.65,
174-
175- -- In percent (1 being very fertile).
176- preferred_fertility = 0.6,
177-
178- -- A value in [0, 1] that defines how well this can deal with non-ideal
179+ -- Value between 0 and 1000 (1000 being very wet).
180+ preferred_humidity = 650,
181+
182+ -- Values between 0 and 1000 (1000 being very fertile).
183+ preferred_fertility = 600,
184+
185+ -- A value in [0, 100] that defines how well this can deal with non-ideal
186 -- situations. Lower means it is less picky, i.e. it can deal better.
187- pickiness = 0.6,
188+ pickiness = 60,
189 }
190
191 world:new_immovable_type{
192
193=== modified file 'data/world/immovables/trees/aspen/init.lua'
194--- data/world/immovables/trees/aspen/init.lua 2016-02-10 19:50:13 +0000
195+++ data/world/immovables/trees/aspen/init.lua 2018-11-23 12:45:17 +0000
196@@ -2,9 +2,9 @@
197
198 terrain_affinity = {
199 preferred_temperature = 100,
200- preferred_humidity = 0.6,
201- preferred_fertility = 0.7,
202- pickiness = 0.8,
203+ preferred_humidity = 600,
204+ preferred_fertility = 700,
205+ pickiness = 80,
206 }
207
208 world:new_immovable_type{
209
210=== modified file 'data/world/immovables/trees/beech/init.lua'
211--- data/world/immovables/trees/beech/init.lua 2016-02-10 19:50:13 +0000
212+++ data/world/immovables/trees/beech/init.lua 2018-11-23 12:45:17 +0000
213@@ -2,9 +2,9 @@
214
215 terrain_affinity = {
216 preferred_temperature = 110,
217- preferred_humidity = 0.4,
218- preferred_fertility = 0.6,
219- pickiness = 0.6,
220+ preferred_humidity = 400,
221+ preferred_fertility = 600,
222+ pickiness = 60,
223 }
224
225 world:new_immovable_type{
226
227=== modified file 'data/world/immovables/trees/birch/init.lua'
228--- data/world/immovables/trees/birch/init.lua 2016-02-10 19:50:13 +0000
229+++ data/world/immovables/trees/birch/init.lua 2018-11-23 12:45:17 +0000
230@@ -2,9 +2,9 @@
231
232 terrain_affinity = {
233 preferred_temperature = 80,
234- preferred_humidity = 0.65,
235- preferred_fertility = 0.6,
236- pickiness = 0.6,
237+ preferred_humidity = 650,
238+ preferred_fertility = 600,
239+ pickiness = 60,
240 }
241
242 world:new_immovable_type{
243
244=== modified file 'data/world/immovables/trees/cirrus/init.lua'
245--- data/world/immovables/trees/cirrus/init.lua 2016-02-10 19:50:13 +0000
246+++ data/world/immovables/trees/cirrus/init.lua 2018-11-23 12:45:17 +0000
247@@ -2,9 +2,9 @@
248
249 terrain_affinity = {
250 preferred_temperature = 110,
251- preferred_humidity = 0.15,
252- preferred_fertility = 0.95,
253- pickiness = 0.8,
254+ preferred_humidity = 150,
255+ preferred_fertility = 950,
256+ pickiness = 80,
257 }
258
259 world:new_immovable_type{
260
261=== modified file 'data/world/immovables/trees/larch/init.lua'
262--- data/world/immovables/trees/larch/init.lua 2016-02-10 19:50:13 +0000
263+++ data/world/immovables/trees/larch/init.lua 2018-11-23 12:45:17 +0000
264@@ -2,9 +2,9 @@
265
266 terrain_affinity = {
267 preferred_temperature = 50,
268- preferred_humidity = 0.8,
269- preferred_fertility = 0.45,
270- pickiness = 0.8,
271+ preferred_humidity = 800,
272+ preferred_fertility = 450,
273+ pickiness = 80,
274 }
275
276 world:new_immovable_type{
277
278=== modified file 'data/world/immovables/trees/liana/init.lua'
279--- data/world/immovables/trees/liana/init.lua 2016-02-10 19:50:13 +0000
280+++ data/world/immovables/trees/liana/init.lua 2018-11-23 12:45:17 +0000
281@@ -2,9 +2,9 @@
282
283 terrain_affinity = {
284 preferred_temperature = 120,
285- preferred_humidity = 0.2,
286- preferred_fertility = 0.7,
287- pickiness = 0.6,
288+ preferred_humidity = 200,
289+ preferred_fertility = 700,
290+ pickiness = 60,
291 }
292
293 world:new_immovable_type{
294
295=== modified file 'data/world/immovables/trees/maple/init.lua'
296--- data/world/immovables/trees/maple/init.lua 2016-02-28 08:33:59 +0000
297+++ data/world/immovables/trees/maple/init.lua 2018-11-23 12:45:17 +0000
298@@ -2,9 +2,9 @@
299
300 terrain_affinity = {
301 preferred_temperature = 110,
302- preferred_humidity = 0.55,
303- preferred_fertility = 0.8,
304- pickiness = 0.8,
305+ preferred_humidity = 550,
306+ preferred_fertility = 800,
307+ pickiness = 80,
308 }
309
310 world:new_immovable_type{
311
312=== modified file 'data/world/immovables/trees/mushroom_dark/init.lua'
313--- data/world/immovables/trees/mushroom_dark/init.lua 2016-02-10 19:50:13 +0000
314+++ data/world/immovables/trees/mushroom_dark/init.lua 2018-11-23 12:45:17 +0000
315@@ -2,9 +2,9 @@
316
317 terrain_affinity = {
318 preferred_temperature = 100,
319- preferred_humidity = 0.2,
320- preferred_fertility = 0.8,
321- pickiness = 0.8,
322+ preferred_humidity = 200,
323+ preferred_fertility = 800,
324+ pickiness = 80,
325 }
326
327 world:new_immovable_type{
328
329=== modified file 'data/world/immovables/trees/mushroom_green/init.lua'
330--- data/world/immovables/trees/mushroom_green/init.lua 2016-02-10 19:50:13 +0000
331+++ data/world/immovables/trees/mushroom_green/init.lua 2018-11-23 12:45:17 +0000
332@@ -2,9 +2,9 @@
333
334 terrain_affinity = {
335 preferred_temperature = 105,
336- preferred_humidity = 0.2,
337- preferred_fertility = 0.9,
338- pickiness = 0.8,
339+ preferred_humidity = 200,
340+ preferred_fertility = 900,
341+ pickiness = 80,
342 }
343
344 world:new_immovable_type{
345
346=== modified file 'data/world/immovables/trees/mushroom_red/init.lua'
347--- data/world/immovables/trees/mushroom_red/init.lua 2016-02-10 19:50:13 +0000
348+++ data/world/immovables/trees/mushroom_red/init.lua 2018-11-23 12:45:17 +0000
349@@ -2,9 +2,9 @@
350
351 terrain_affinity = {
352 preferred_temperature = 80,
353- preferred_humidity = 0.35,
354- preferred_fertility = 0.85,
355- pickiness = 0.6,
356+ preferred_humidity = 350,
357+ preferred_fertility = 850,
358+ pickiness = 60,
359 }
360
361 world:new_immovable_type{
362
363=== modified file 'data/world/immovables/trees/oak/init.lua'
364--- data/world/immovables/trees/oak/init.lua 2016-02-10 19:50:13 +0000
365+++ data/world/immovables/trees/oak/init.lua 2018-11-23 12:45:17 +0000
366@@ -2,9 +2,9 @@
367
368 terrain_affinity = {
369 preferred_temperature = 90,
370- preferred_humidity = 0.7,
371- preferred_fertility = 0.5,
372- pickiness = 0.6,
373+ preferred_humidity = 700,
374+ preferred_fertility = 500,
375+ pickiness = 60,
376 }
377
378 world:new_immovable_type{
379
380=== modified file 'data/world/immovables/trees/palm_borassus/init.lua'
381--- data/world/immovables/trees/palm_borassus/init.lua 2016-02-10 19:50:13 +0000
382+++ data/world/immovables/trees/palm_borassus/init.lua 2018-11-23 12:45:17 +0000
383@@ -2,9 +2,9 @@
384
385 terrain_affinity = {
386 preferred_temperature = 180,
387- preferred_humidity = 0.4,
388- preferred_fertility = 0.4,
389- pickiness = 0.6,
390+ preferred_humidity = 400,
391+ preferred_fertility = 400,
392+ pickiness = 60,
393 }
394
395 world:new_immovable_type{
396
397=== modified file 'data/world/immovables/trees/palm_coconut/init.lua'
398--- data/world/immovables/trees/palm_coconut/init.lua 2016-02-10 19:50:13 +0000
399+++ data/world/immovables/trees/palm_coconut/init.lua 2018-11-23 12:45:17 +0000
400@@ -2,9 +2,9 @@
401
402 terrain_affinity = {
403 preferred_temperature = 130,
404- preferred_humidity = 0.5,
405- preferred_fertility = 0.6,
406- pickiness = 0.6,
407+ preferred_humidity = 500,
408+ preferred_fertility = 600,
409+ pickiness = 60,
410 }
411
412 world:new_immovable_type{
413
414=== modified file 'data/world/immovables/trees/palm_date/init.lua'
415--- data/world/immovables/trees/palm_date/init.lua 2016-02-10 19:50:13 +0000
416+++ data/world/immovables/trees/palm_date/init.lua 2018-11-23 12:45:17 +0000
417@@ -2,9 +2,9 @@
418
419 terrain_affinity = {
420 preferred_temperature = 160,
421- preferred_humidity = 0.5,
422- preferred_fertility = 0.5,
423- pickiness = 0.8,
424+ preferred_humidity = 500,
425+ preferred_fertility = 500,
426+ pickiness = 80,
427 }
428
429 world:new_immovable_type{
430
431=== modified file 'data/world/immovables/trees/palm_oil/init.lua'
432--- data/world/immovables/trees/palm_oil/init.lua 2016-02-10 19:50:13 +0000
433+++ data/world/immovables/trees/palm_oil/init.lua 2018-11-23 12:45:17 +0000
434@@ -2,9 +2,9 @@
435
436 terrain_affinity = {
437 preferred_temperature = 150,
438- preferred_humidity = 0.55,
439- preferred_fertility = 0.5,
440- pickiness = 0.8,
441+ preferred_humidity = 550,
442+ preferred_fertility = 500,
443+ pickiness = 80,
444 }
445
446 world:new_immovable_type{
447
448=== modified file 'data/world/immovables/trees/palm_roystonea/init.lua'
449--- data/world/immovables/trees/palm_roystonea/init.lua 2016-02-10 19:50:13 +0000
450+++ data/world/immovables/trees/palm_roystonea/init.lua 2018-11-23 12:45:17 +0000
451@@ -2,9 +2,9 @@
452
453 terrain_affinity = {
454 preferred_temperature = 160,
455- preferred_humidity = 0.6,
456- preferred_fertility = 0.6,
457- pickiness = 0.9,
458+ preferred_humidity = 600,
459+ preferred_fertility = 600,
460+ pickiness = 90,
461 }
462
463 world:new_immovable_type{
464
465=== modified file 'data/world/immovables/trees/rowan/init.lua'
466--- data/world/immovables/trees/rowan/init.lua 2016-02-10 19:50:13 +0000
467+++ data/world/immovables/trees/rowan/init.lua 2018-11-23 12:45:17 +0000
468@@ -2,9 +2,9 @@
469
470 terrain_affinity = {
471 preferred_temperature = 105,
472- preferred_humidity = 0.65,
473- preferred_fertility = 0.75,
474- pickiness = 0.8,
475+ preferred_humidity = 650,
476+ preferred_fertility = 750,
477+ pickiness = 80,
478 }
479
480 world:new_immovable_type{
481
482=== modified file 'data/world/immovables/trees/spruce/init.lua'
483--- data/world/immovables/trees/spruce/init.lua 2016-02-10 19:50:13 +0000
484+++ data/world/immovables/trees/spruce/init.lua 2018-11-23 12:45:17 +0000
485@@ -2,9 +2,9 @@
486
487 terrain_affinity = {
488 preferred_temperature = 60,
489- preferred_humidity = 0.7,
490- preferred_fertility = 0.5,
491- pickiness = 0.6,
492+ preferred_humidity = 700,
493+ preferred_fertility = 500,
494+ pickiness = 60,
495 }
496
497 world:new_immovable_type{
498
499=== modified file 'data/world/immovables/trees/twine/init.lua'
500--- data/world/immovables/trees/twine/init.lua 2016-02-10 19:50:13 +0000
501+++ data/world/immovables/trees/twine/init.lua 2018-11-23 12:45:17 +0000
502@@ -2,9 +2,9 @@
503
504 terrain_affinity = {
505 preferred_temperature = 95,
506- preferred_humidity = 0.2,
507- preferred_fertility = 0.4,
508- pickiness = 0.8,
509+ preferred_humidity = 200,
510+ preferred_fertility = 400,
511+ pickiness = 80,
512 }
513
514 world:new_immovable_type{
515
516=== modified file 'data/world/immovables/trees/umbrella_green/init.lua'
517--- data/world/immovables/trees/umbrella_green/init.lua 2016-02-10 19:50:13 +0000
518+++ data/world/immovables/trees/umbrella_green/init.lua 2018-11-23 12:45:17 +0000
519@@ -2,9 +2,9 @@
520
521 terrain_affinity = {
522 preferred_temperature = 110,
523- preferred_humidity = 0.2,
524- preferred_fertility = 0.85,
525- pickiness = 0.8,
526+ preferred_humidity = 200,
527+ preferred_fertility = 850,
528+ pickiness = 80,
529 }
530
531 world:new_immovable_type{
532
533=== modified file 'data/world/immovables/trees/umbrella_red/init.lua'
534--- data/world/immovables/trees/umbrella_red/init.lua 2016-02-29 17:10:00 +0000
535+++ data/world/immovables/trees/umbrella_red/init.lua 2018-11-23 12:45:17 +0000
536@@ -2,9 +2,9 @@
537
538 terrain_affinity = {
539 preferred_temperature = 90,
540- preferred_humidity = 0.15,
541- preferred_fertility = 0.825,
542- pickiness = 0.8,
543+ preferred_humidity = 150,
544+ preferred_fertility = 825,
545+ pickiness = 80,
546 }
547
548 world:new_immovable_type{
549
550=== modified file 'data/world/terrains/init.lua'
551--- data/world/terrains/init.lua 2017-09-02 16:12:50 +0000
552+++ data/world/terrains/init.lua 2018-11-23 12:45:17 +0000
553@@ -131,17 +131,17 @@
554 --
555 -- **humidity**
556 -- *Mandatory*. A terrain affinity constant. These are used to model how well
557--- trees will grow on this terrain. Humidity is in percent (1 being very wet).
558+-- trees will grow on this terrain. Values range from 1 - 1000 (1000 being very wet).
559 -- Example::
560 --
561--- humidity = 0.6,
562+-- humidity = 600,
563 --
564 -- **fertility**
565 -- *Mandatory*. A terrain affinity constant. These are used to model how well
566--- trees will grow on this terrain. Fertility is in percent (1 being very
567+-- trees will grow on this terrain. Values range from 1 - 1000 (1000 being very
568 -- fertile). Example::
569 --
570--- fertility = 0.7,
571+-- fertility = 700,
572 --
573
574 ------------------------
575@@ -167,8 +167,8 @@
576 dither_layer = 340,
577
578 temperature = 100,
579- humidity = 0.6,
580- fertility = 0.7,
581+ humidity = 600,
582+ fertility = 700,
583 }
584
585
586@@ -187,8 +187,8 @@
587 textures = { pics_dir .. "summer/meadow2_00.png" },
588 dither_layer = 350,
589 temperature = 100,
590- humidity = 0.6,
591- fertility = 0.65,
592+ humidity = 600,
593+ fertility = 650,
594
595 }
596
597@@ -208,8 +208,8 @@
598 textures = { pics_dir .. "summer/meadow3_00.png" },
599 dither_layer = 350,
600 temperature = 105,
601- humidity = 0.55,
602- fertility = 0.8,
603+ humidity = 550,
604+ fertility = 800,
605 }
606
607
608@@ -228,8 +228,8 @@
609 textures = { pics_dir .. "summer/meadow4_00.png" },
610 dither_layer = 350,
611 temperature = 110,
612- humidity = 0.65,
613- fertility = 0.75,
614+ humidity = 650,
615+ fertility = 750,
616 }
617
618
619@@ -244,8 +244,8 @@
620 textures = { pics_dir .. "summer/steppe_00.png" },
621 dither_layer = 330,
622 temperature = 100,
623- humidity = 0.4,
624- fertility = 0.4,
625+ humidity = 400,
626+ fertility = 400,
627 }
628
629
630@@ -260,8 +260,8 @@
631 textures = { pics_dir .. "summer/steppe_barren_00.png" },
632 dither_layer = 320,
633 temperature = 100,
634- humidity = 0.15,
635- fertility = 0.15,
636+ humidity = 150,
637+ fertility = 150,
638 }
639
640
641@@ -276,8 +276,8 @@
642 textures = { pics_dir .. "summer/mountain_meadow_00.png" },
643 dither_layer = 160,
644 temperature = 75,
645- humidity = 0.8,
646- fertility = 0.45,
647+ humidity = 800,
648+ fertility = 450,
649 }
650
651 world:new_terrain_type{
652@@ -296,8 +296,8 @@
653 textures = { pics_dir .. "summer/forested_mountain1_00.png" },
654 dither_layer = 71,
655 temperature = 50,
656- humidity = 0.75,
657- fertility = 0.5,
658+ humidity = 750,
659+ fertility = 500,
660 }
661
662 world:new_terrain_type{
663@@ -316,8 +316,8 @@
664 textures = { pics_dir .. "summer/forested_mountain2_00.png" },
665 dither_layer = 71,
666 temperature = 50,
667- humidity = 0.75,
668- fertility = 0.5,
669+ humidity = 750,
670+ fertility = 500,
671 }
672
673 world:new_terrain_type{
674@@ -331,8 +331,8 @@
675 textures = { pics_dir .. "summer/mountain1_00.png" },
676 dither_layer = 70,
677 temperature = 80,
678- humidity = 0.1,
679- fertility = 0.1,
680+ humidity = 100,
681+ fertility = 100,
682 }
683
684
685@@ -347,8 +347,8 @@
686 textures = { pics_dir .. "summer/mountain2_00.png" },
687 dither_layer = 70,
688 temperature = 80,
689- humidity = 0.1,
690- fertility = 0.1,
691+ humidity = 100,
692+ fertility = 100,
693 }
694
695
696@@ -363,8 +363,8 @@
697 textures = { pics_dir .. "summer/mountain3_00.png" },
698 dither_layer = 70,
699 temperature = 80,
700- humidity = 0.1,
701- fertility = 0.1,
702+ humidity = 100,
703+ fertility = 100,
704 }
705
706
707@@ -379,8 +379,8 @@
708 textures = { pics_dir .. "summer/mountain4_00.png" },
709 dither_layer = 70,
710 temperature = 80,
711- humidity = 0.1,
712- fertility = 0.1,
713+ humidity = 100,
714+ fertility = 100,
715 }
716
717 world:new_terrain_type{
718@@ -394,8 +394,8 @@
719 textures = { pics_dir .. "summer/beach_00.png" },
720 dither_layer = 60,
721 temperature = 120,
722- humidity = 0.6,
723- fertility = 0.2,
724+ humidity = 600,
725+ fertility = 200,
726 }
727
728 world:new_terrain_type{
729@@ -410,8 +410,8 @@
730 dither_layer = 370,
731 fps = 14,
732 temperature = 105,
733- humidity = 0.999,
734- fertility = 0.1,
735+ humidity = 999,
736+ fertility = 100,
737 }
738 world:new_terrain_type{
739 name = "summer_snow",
740@@ -424,8 +424,8 @@
741 textures = { pics_dir .. "summer/snow_00.png" },
742 dither_layer = 220,
743 temperature = 50,
744- humidity = 0.999,
745- fertility = 0.001,
746+ humidity = 999,
747+ fertility = 1,
748 }
749
750
751@@ -440,9 +440,9 @@
752 textures = path.list_files(pics_dir .. "summer/lava/lava_??.png"),
753 dither_layer = 30,
754 fps = 4,
755- temperature = 1273.0,
756- humidity = 0.001,
757- fertility = 0.001,
758+ temperature = 1273,
759+ humidity = 1,
760+ fertility = 1,
761 }
762
763
764@@ -458,8 +458,8 @@
765 dither_layer = 180,
766 fps = 14,
767 temperature = 100,
768- humidity = 0.999,
769- fertility = 0.001,
770+ humidity = 999,
771+ fertility = 1,
772 }
773
774 ------------------------
775@@ -482,8 +482,8 @@
776 textures = { pics_dir .. "wasteland/ashes_00.png" },
777 dither_layer = 400,
778 temperature = 120,
779- humidity = 0.15,
780- fertility = 0.9,
781+ humidity = 150,
782+ fertility = 900,
783 }
784
785
786@@ -502,8 +502,8 @@
787 textures = { pics_dir .. "wasteland/ashes2_00.png" },
788 dither_layer = 410,
789 temperature = 118,
790- humidity = 0.13,
791- fertility = 0.999,
792+ humidity = 130,
793+ fertility = 999,
794 }
795
796
797@@ -522,8 +522,8 @@
798 textures = { pics_dir .. "wasteland/hardground1_00.png" },
799 dither_layer = 420,
800 temperature = 100,
801- humidity = 0.25,
802- fertility = 0.8,
803+ humidity = 250,
804+ fertility = 800,
805 }
806
807
808@@ -542,8 +542,8 @@
809 textures = { pics_dir .. "wasteland/hardground2_00.png" },
810 dither_layer = 370,
811 temperature = 95,
812- humidity = 0.15,
813- fertility = 0.85,
814+ humidity = 150,
815+ fertility = 850,
816 }
817
818
819@@ -562,8 +562,8 @@
820 textures = { pics_dir .. "wasteland/hardground3_00.png" },
821 dither_layer = 380,
822 temperature = 105,
823- humidity = 0.2,
824- fertility = 0.9,
825+ humidity = 200,
826+ fertility = 900,
827 }
828
829
830@@ -582,8 +582,8 @@
831 textures = { pics_dir .. "wasteland/hardground4_00.png" },
832 dither_layer = 390,
833 temperature = 90,
834- humidity = 0.2,
835- fertility = 0.8,
836+ humidity = 200,
837+ fertility = 800,
838 }
839
840
841@@ -598,8 +598,8 @@
842 textures = { pics_dir .. "wasteland/hardlava_00.png" },
843 dither_layer = 360,
844 temperature = 120,
845- humidity = 0.1,
846- fertility = 0.2,
847+ humidity = 100,
848+ fertility = 200,
849 }
850
851
852@@ -618,8 +618,8 @@
853 textures = { pics_dir .. "wasteland/forested_mountain1_00.png" },
854 dither_layer = 81,
855 temperature = 110,
856- humidity = 0.15,
857- fertility = 0.95,
858+ humidity = 150,
859+ fertility = 950,
860 }
861
862 world:new_terrain_type{
863@@ -637,8 +637,8 @@
864 textures = { pics_dir .. "wasteland/forested_mountain2_00.png" },
865 dither_layer = 81,
866 temperature = 95,
867- humidity = 0.2,
868- fertility = 0.4,
869+ humidity = 200,
870+ fertility = 400,
871 }
872
873 world:new_terrain_type{
874@@ -652,8 +652,8 @@
875 textures = { pics_dir .. "wasteland/mountain1_00.png" },
876 dither_layer = 90,
877 temperature = 80,
878- humidity = 0.05,
879- fertility = 0.2,
880+ humidity = 50,
881+ fertility = 200,
882 }
883
884
885@@ -668,8 +668,8 @@
886 textures = { pics_dir .. "wasteland/mountain2_00.png" },
887 dither_layer = 90,
888 temperature = 80,
889- humidity = 0.05,
890- fertility = 0.2,
891+ humidity = 50,
892+ fertility = 200,
893 }
894
895
896@@ -684,8 +684,8 @@
897 textures = { pics_dir .. "wasteland/mountain3_00.png" },
898 dither_layer = 90,
899 temperature = 80,
900- humidity = 0.05,
901- fertility = 0.2,
902+ humidity = 50,
903+ fertility = 200,
904 }
905
906
907@@ -700,8 +700,8 @@
908 textures = { pics_dir .. "wasteland/mountain4_00.png" },
909 dither_layer = 80,
910 temperature = 80,
911- humidity = 0.05,
912- fertility = 0.2,
913+ humidity = 50,
914+ fertility = 200,
915 }
916
917
918@@ -716,8 +716,8 @@
919 textures = { pics_dir .. "wasteland/beach_00.png" },
920 dither_layer = 50,
921 temperature = 60,
922- humidity = 0.4,
923- fertility = 0.2,
924+ humidity = 400,
925+ fertility = 200,
926 }
927
928
929@@ -732,9 +732,9 @@
930 textures = path.list_files(pics_dir .. "wasteland/lava_stone1/lava-stone1_??.png"),
931 dither_layer = 20,
932 fps = 7,
933- temperature = 1273.0,
934- humidity = 0.001,
935- fertility = 0.001,
936+ temperature = 1273,
937+ humidity = 1,
938+ fertility = 1,
939 }
940
941
942@@ -749,9 +749,9 @@
943 textures = path.list_files(pics_dir .. "wasteland/lava_stone2/lava-stone2_??.png"),
944 dither_layer = 10,
945 fps = 7,
946- temperature = 1273.0,
947- humidity = 0.001,
948- fertility = 0.001,
949+ temperature = 1273,
950+ humidity = 1,
951+ fertility = 1,
952 }
953
954
955@@ -767,8 +767,8 @@
956 dither_layer = 170,
957 fps = 14,
958 temperature = 100,
959- humidity = 0.999,
960- fertility = 0.001,
961+ humidity = 999,
962+ fertility = 1,
963 }
964
965
966@@ -792,8 +792,8 @@
967 textures = { pics_dir .. "winter/tundra_00.png" },
968 dither_layer = 230,
969 temperature = 50,
970- humidity = 0.85,
971- fertility = 0.45,
972+ humidity = 850,
973+ fertility = 450,
974 }
975
976
977@@ -812,8 +812,8 @@
978 textures = { pics_dir .. "winter/tundra2_00.png" },
979 dither_layer = 240,
980 temperature = 55,
981- humidity = 0.75,
982- fertility = 0.45,
983+ humidity = 750,
984+ fertility = 450,
985 }
986
987
988@@ -832,8 +832,8 @@
989 textures = { pics_dir .. "winter/tundra3_00.png" },
990 dither_layer = 240,
991 temperature = 50,
992- humidity = 0.8,
993- fertility = 0.4,
994+ humidity = 800,
995+ fertility = 400,
996 }
997
998
999@@ -848,8 +848,8 @@
1000 textures = { pics_dir .. "winter/tundra_taiga_00.png" },
1001 dither_layer = 230,
1002 temperature = 40,
1003- humidity = 0.75,
1004- fertility = 0.4,
1005+ humidity = 750,
1006+ fertility = 400,
1007 }
1008
1009
1010@@ -864,8 +864,8 @@
1011 textures = { pics_dir .. "winter/taiga_00.png" },
1012 dither_layer = 250,
1013 temperature = 35,
1014- humidity = 0.75,
1015- fertility = 0.3,
1016+ humidity = 750,
1017+ fertility = 300,
1018 }
1019
1020
1021@@ -880,8 +880,8 @@
1022 textures = { pics_dir .. "winter/snow_00.png" },
1023 dither_layer = 250,
1024 temperature = 25,
1025- humidity = 0.8,
1026- fertility = 0.1,
1027+ humidity = 800,
1028+ fertility = 100,
1029 }
1030
1031
1032@@ -900,8 +900,8 @@
1033 textures = { pics_dir .. "winter/forested_mountain1_00.png" },
1034 dither_layer = 101,
1035 temperature = 35,
1036- humidity = 0.7,
1037- fertility = 0.4,
1038+ humidity = 700,
1039+ fertility = 400,
1040 }
1041
1042 world:new_terrain_type{
1043@@ -919,8 +919,8 @@
1044 textures = { pics_dir .. "winter/forested_mountain2_00.png" },
1045 dither_layer = 101,
1046 temperature = 35,
1047- humidity = 0.7,
1048- fertility = 0.4,
1049+ humidity = 700,
1050+ fertility = 400,
1051 }
1052
1053 world:new_terrain_type{
1054@@ -934,8 +934,8 @@
1055 textures = { pics_dir .. "winter/mountain1_00.png" },
1056 dither_layer = 110,
1057 temperature = 20,
1058- humidity = 0.3,
1059- fertility = 0.05,
1060+ humidity = 300,
1061+ fertility = 50,
1062 }
1063
1064
1065@@ -950,8 +950,8 @@
1066 textures = { pics_dir .. "winter/mountain2_00.png" },
1067 dither_layer = 110,
1068 temperature = 20,
1069- humidity = 0.3,
1070- fertility = 0.05,
1071+ humidity = 300,
1072+ fertility = 50,
1073 }
1074
1075
1076@@ -966,8 +966,8 @@
1077 textures = { pics_dir .. "winter/mountain3_00.png" },
1078 dither_layer = 100,
1079 temperature = 20,
1080- humidity = 0.3,
1081- fertility = 0.05,
1082+ humidity = 300,
1083+ fertility = 50,
1084 }
1085
1086
1087@@ -982,8 +982,8 @@
1088 textures = { pics_dir .. "winter/mountain4_00.png" },
1089 dither_layer = 100,
1090 temperature = 20,
1091- humidity = 0.3,
1092- fertility = 0.05,
1093+ humidity = 300,
1094+ fertility = 50,
1095 }
1096 world:new_terrain_type{
1097 name = "ice",
1098@@ -996,8 +996,8 @@
1099 textures = { pics_dir .. "winter/ice_00.png" },
1100 dither_layer = 260,
1101 temperature = 25,
1102- humidity = 0.5,
1103- fertility = 0.1,
1104+ humidity = 500,
1105+ fertility = 100,
1106 }
1107
1108
1109@@ -1012,8 +1012,8 @@
1110 textures = { pics_dir .. "winter/beach_00.png" },
1111 dither_layer = 40,
1112 temperature = 60,
1113- humidity = 0.5,
1114- fertility = 0.1,
1115+ humidity = 500,
1116+ fertility = 100,
1117 }
1118
1119
1120@@ -1029,8 +1029,8 @@
1121 dither_layer = 210,
1122 fps = 5,
1123 temperature = 50,
1124- humidity = 0.999,
1125- fertility = 0.001,
1126+ humidity = 999,
1127+ fertility = 1,
1128 }
1129
1130
1131@@ -1046,8 +1046,8 @@
1132 dither_layer = 210,
1133 fps = 5,
1134 temperature = 50,
1135- humidity = 0.999,
1136- fertility = 0.001,
1137+ humidity = 999,
1138+ fertility = 1,
1139 }
1140
1141
1142@@ -1063,8 +1063,8 @@
1143 dither_layer = 190,
1144 fps = 8,
1145 temperature = 50,
1146- humidity = 0.999,
1147- fertility = 0.001,
1148+ humidity = 999,
1149+ fertility = 1,
1150 }
1151
1152
1153@@ -1083,8 +1083,8 @@
1154 textures = { pics_dir .. "desert/desert4_00.png" },
1155 dither_layer = 270,
1156 temperature = 168,
1157- humidity = 0.001,
1158- fertility = 0.1,
1159+ humidity = 1,
1160+ fertility = 100,
1161 }
1162
1163 world:new_terrain_type{
1164@@ -1098,8 +1098,8 @@
1165 textures = { pics_dir .. "desert/drysoil_00.png" },
1166 dither_layer = 300,
1167 temperature = 172,
1168- humidity = 0.2,
1169- fertility = 0.2,
1170+ humidity = 200,
1171+ fertility = 200,
1172 }
1173 world:new_terrain_type{
1174 name = "desert_steppe",
1175@@ -1116,8 +1116,8 @@
1176 textures = { pics_dir .. "desert/steppe_00.png" },
1177 dither_layer = 360,
1178 temperature = 155,
1179- humidity = 0.5,
1180- fertility = 0.5,
1181+ humidity = 500,
1182+ fertility = 500,
1183 }
1184
1185
1186@@ -1136,8 +1136,8 @@
1187 textures = { pics_dir .. "desert/meadow_00.png" },
1188 dither_layer = 310,
1189 temperature = 160,
1190- humidity = 0.6,
1191- fertility = 0.6,
1192+ humidity = 600,
1193+ fertility = 600,
1194 }
1195
1196
1197@@ -1156,8 +1156,8 @@
1198 textures = { pics_dir .. "desert/mountainmeadow_00.png" },
1199 dither_layer = 150,
1200 temperature = 145,
1201- humidity = 0.5,
1202- fertility = 0.5,
1203+ humidity = 500,
1204+ fertility = 500,
1205 }
1206
1207
1208@@ -1176,8 +1176,8 @@
1209 textures = { pics_dir .. "desert/highmountainmeadow_00.png" },
1210 dither_layer = 150,
1211 temperature = 140,
1212- humidity = 0.4,
1213- fertility = 0.4,
1214+ humidity = 400,
1215+ fertility = 400,
1216 }
1217
1218
1219@@ -1196,8 +1196,8 @@
1220 textures = { pics_dir .. "desert/forested_mountain1_00.png" },
1221 dither_layer = 71,
1222 temperature = 141,
1223- humidity = 0.5,
1224- fertility = 0.5,
1225+ humidity = 500,
1226+ fertility = 500,
1227 }
1228
1229 world:new_terrain_type{
1230@@ -1215,8 +1215,8 @@
1231 textures = { pics_dir .. "desert/forested_mountain2_00.png" },
1232 dither_layer = 141,
1233 temperature = 120,
1234- humidity = 0.5,
1235- fertility = 0.5,
1236+ humidity = 500,
1237+ fertility = 500,
1238 }
1239
1240
1241@@ -1231,8 +1231,8 @@
1242 textures = { pics_dir .. "desert/mountain1_00.png" },
1243 dither_layer = 120,
1244 temperature = 130,
1245- humidity = 0.05,
1246- fertility = 0.05,
1247+ humidity = 50,
1248+ fertility = 50,
1249 }
1250
1251
1252@@ -1247,8 +1247,8 @@
1253 textures = { pics_dir .. "desert/mountain2_00.png" },
1254 dither_layer = 120,
1255 temperature = 130,
1256- humidity = 0.05,
1257- fertility = 0.05,
1258+ humidity = 50,
1259+ fertility = 50,
1260 }
1261
1262
1263@@ -1263,8 +1263,8 @@
1264 textures = { pics_dir .. "desert/mountain3_00.png" },
1265 dither_layer = 130,
1266 temperature = 130,
1267- humidity = 0.05,
1268- fertility = 0.05,
1269+ humidity = 50,
1270+ fertility = 50,
1271 }
1272
1273
1274@@ -1279,8 +1279,8 @@
1275 textures = { pics_dir .. "desert/mountain4_00.png" },
1276 dither_layer = 140,
1277 temperature = 130,
1278- humidity = 0.05,
1279- fertility = 0.05,
1280+ humidity = 50,
1281+ fertility = 50,
1282 }
1283 world:new_terrain_type{
1284 name = "desert1",
1285@@ -1293,8 +1293,8 @@
1286 textures = { pics_dir .. "desert/desert1_00.png" },
1287 dither_layer = 290,
1288 temperature = 167,
1289- humidity = 0.001,
1290- fertility = 0.001,
1291+ humidity = 1,
1292+ fertility = 1,
1293 }
1294
1295
1296@@ -1309,8 +1309,8 @@
1297 textures = { pics_dir .. "desert/desert2_00.png" },
1298 dither_layer = 280,
1299 temperature = 168,
1300- humidity = 0.001,
1301- fertility = 0.001,
1302+ humidity = 1,
1303+ fertility = 1,
1304 }
1305
1306
1307@@ -1325,8 +1325,8 @@
1308 textures = { pics_dir .. "desert/desert3_00.png" },
1309 dither_layer = 280,
1310 temperature = 178,
1311- humidity = 0.001,
1312- fertility = 0.001,
1313+ humidity = 1,
1314+ fertility = 1,
1315 }
1316
1317
1318@@ -1341,8 +1341,8 @@
1319 textures = { pics_dir .. "desert/beach_00.png" },
1320 dither_layer = 60,
1321 temperature = 179,
1322- humidity = 0.5,
1323- fertility = 0.1,
1324+ humidity = 500,
1325+ fertility = 100,
1326 }
1327
1328
1329@@ -1358,6 +1358,6 @@
1330 dither_layer = 200,
1331 fps = 5,
1332 temperature = 150,
1333- humidity = 0.999,
1334- fertility = 0.001,
1335+ humidity = 999,
1336+ fertility = 1,
1337 }
1338
1339=== modified file 'src/logic/game.cc'
1340--- src/logic/game.cc 2018-11-23 08:20:36 +0000
1341+++ src/logic/game.cc 2018-11-23 12:45:17 +0000
1342@@ -1076,8 +1076,4 @@
1343 fw.unsigned_32(general_stats_[p - 1].custom_statistic[j]);
1344 }
1345 }
1346-
1347-double logic_rand_as_double(Game* game) {
1348- return static_cast<double>(game->logic_rand()) / std::numeric_limits<uint32_t>::max();
1349-}
1350 }
1351
1352=== modified file 'src/logic/game.h'
1353--- src/logic/game.h 2018-10-21 09:42:03 +0000
1354+++ src/logic/game.h 2018-11-23 12:45:17 +0000
1355@@ -347,9 +347,6 @@
1356 location.y += logic_rand() % s - radius;
1357 return location;
1358 }
1359-
1360-// Returns a value between [0., 1].
1361-double logic_rand_as_double(Game* game);
1362 }
1363
1364 #endif // end of include guard: WL_LOGIC_GAME_H
1365
1366=== modified file 'src/logic/map_objects/immovable.cc'
1367--- src/logic/map_objects/immovable.cc 2018-09-25 06:32:35 +0000
1368+++ src/logic/map_objects/immovable.cc 2018-11-23 12:45:17 +0000
1369@@ -943,7 +943,7 @@
1370 FCoords const f = map.get_fcoords(immovable.get_position());
1371 const ImmovableDescr& descr = immovable.descr();
1372
1373- if (logic_rand_as_double(&game) <
1374+ if ((game.logic_rand() % TerrainAffinity::kPrecisionFactor) <
1375 probability_to_grow(descr.terrain_affinity(), f, map, game.world().terrains())) {
1376 MapObjectDescr::OwnerType owner_type = descr.owner_type();
1377 Player* owner = immovable.get_owner();
1378@@ -1030,7 +1030,7 @@
1379 FCoords const f = map.get_fcoords(immovable.get_position());
1380 const ImmovableDescr& descr = immovable.descr();
1381
1382- if (logic_rand_as_double(&game) <
1383+ if ((game.logic_rand() % TerrainAffinity::kPrecisionFactor) <
1384 probability_to_grow(descr.terrain_affinity(), f, map, game.world().terrains())) {
1385 // Seed a new tree.
1386 MapFringeRegion<> mr(map, Area<>(f, 0));
1387@@ -1047,7 +1047,7 @@
1388 const FCoords new_location = map.get_fcoords(mr.location());
1389 if (!new_location.field->get_immovable() &&
1390 (new_location.field->nodecaps() & MOVECAPS_WALK) &&
1391- logic_rand_as_double(&game) < probability_to_grow(descr.terrain_affinity(), new_location,
1392+ (game.logic_rand() % TerrainAffinity::kPrecisionFactor) < probability_to_grow(descr.terrain_affinity(), new_location,
1393 map, game.world().terrains())) {
1394 game.create_immovable_with_name(mr.location(), type_name, descr.owner_type(),
1395 nullptr /* owner */, nullptr /* former_building_descr */);
1396
1397=== modified file 'src/logic/map_objects/terrain_affinity.cc'
1398--- src/logic/map_objects/terrain_affinity.cc 2018-04-07 16:59:00 +0000
1399+++ src/logic/map_objects/terrain_affinity.cc 2018-11-23 12:45:17 +0000
1400@@ -33,113 +33,122 @@
1401
1402 namespace {
1403
1404-constexpr double pow2(const double& a) {
1405+// Literature on cross-platform floating point precision-problems:
1406+// https://arxiv.org/abs/cs/0701192
1407+// Monniaux, David (2008): "The pitfalls of verifying floating-point computations",
1408+// in: ACM Transactions on Programming Languages and Systems 30, 3 (2008) 12.
1409+//
1410+// Recommends using heximal float constants, but we'd need to switch to C++17 for that.
1411+//
1412+// https://randomascii.wordpress.com/2012/03/21/intermediate-floating-point-precision/
1413+
1414+constexpr double square(const double& a) {
1415 return a * a;
1416 }
1417
1418 // Helper function for probability_to_grow
1419 // Calculates the probability to grow for the given affinity and terrain values
1420-double calculate_probability_to_grow(const TerrainAffinity& affinity,
1421- double terrain_humidity,
1422- double terrain_fertility,
1423- double terrain_temperature) {
1424-
1425- constexpr double kHumidityWeight = 0.500086642549548;
1426- constexpr double kFertilityWeight = 0.5292268046607387;
1427- constexpr double kTemperatureWeight = 61.31300863608306;
1428-
1429- const double sigma_humidity = (1. - affinity.pickiness());
1430- const double sigma_temperature = (1. - affinity.pickiness());
1431- const double sigma_fertility = (1. - affinity.pickiness());
1432-
1433- return exp((-pow2((affinity.preferred_fertility() - terrain_fertility) /
1434- (kFertilityWeight * sigma_fertility)) -
1435- pow2((affinity.preferred_humidity() - terrain_humidity) /
1436- (kHumidityWeight * sigma_humidity)) -
1437- pow2((affinity.preferred_temperature() - terrain_temperature) /
1438- (kTemperatureWeight * sigma_temperature))) /
1439- 2);
1440+inline unsigned int calculate_probability_to_grow(const TerrainAffinity& affinity,
1441+ int terrain_humidity,
1442+ int terrain_fertility,
1443+ int terrain_temperature) {
1444+ constexpr double kHumidityWeight = 5.00086642549548;
1445+ constexpr double kFertilityWeight = 5.292268046607387;
1446+ constexpr double kTemperatureWeight = 0.6131300863608306;
1447+
1448+ // Avoid division by 0
1449+ assert(affinity.pickiness() < 100);
1450+ const double sigma = std::floor(100.0 - affinity.pickiness());
1451+
1452+ // Unlike real numbers, floating point multiplication/division is neither associative nor commutative. Fortunately, execution order is well-defined by the C++ standard.
1453+ const double result = exp(-
1454+ (square((affinity.preferred_fertility() - terrain_fertility) / (kFertilityWeight * sigma)) +
1455+ square((affinity.preferred_humidity() - terrain_humidity) / (kHumidityWeight * sigma)) +
1456+ square((affinity.preferred_temperature() - terrain_temperature) / (kTemperatureWeight * sigma))) / 2.0);
1457+
1458+ return static_cast<unsigned int>(std::max(0.0, std::floor(result * static_cast<double>(TerrainAffinity::kPrecisionFactor))));
1459 }
1460
1461 } // namespace
1462
1463 TerrainAffinity::TerrainAffinity(const LuaTable& table, const std::string& immovable_name)
1464- : preferred_fertility_(table.get_double("preferred_fertility")),
1465- preferred_humidity_(table.get_double("preferred_humidity")),
1466- preferred_temperature_(table.get_double("preferred_temperature")),
1467- pickiness_(table.get_double("pickiness")) {
1468- if (!(0 <= preferred_fertility_ && preferred_fertility_ <= 1.)) {
1469- throw GameDataError("%s: preferred_fertility is not in [0, 1].", immovable_name.c_str());
1470- }
1471- if (!(0 <= preferred_humidity_ && preferred_humidity_ <= 1.)) {
1472- throw GameDataError("%s: preferred_humidity is not in [0, 1].", immovable_name.c_str());
1473- }
1474- if (!(0 <= pickiness_ && pickiness_ <= 1.)) {
1475- throw GameDataError("%s: pickiness is not in [0, 1].", immovable_name.c_str());
1476+ : preferred_fertility_(table.get_int("preferred_fertility")),
1477+ preferred_humidity_(table.get_int("preferred_humidity")),
1478+ preferred_temperature_(table.get_int("preferred_temperature")),
1479+ pickiness_(table.get_int("pickiness")) {
1480+ if (!(0 <= preferred_fertility_ && preferred_fertility_ <= 1000)) {
1481+ throw GameDataError("%s: preferred_fertility is not in [0, 1000].", immovable_name.c_str());
1482+ }
1483+ if (!(0 <= preferred_humidity_ && preferred_humidity_ <= 1000)) {
1484+ throw GameDataError("%s: preferred_humidity is not in [0, 1000].", immovable_name.c_str());
1485+ }
1486+ if (!(0 <= pickiness_ && pickiness_ < 100)) {
1487+ throw GameDataError("%s: pickiness is not in [0, 99].", immovable_name.c_str());
1488 }
1489 if (preferred_temperature_ < 0) {
1490 throw GameDataError("%s: preferred_temperature is not possible.", immovable_name.c_str());
1491 }
1492 }
1493
1494-double TerrainAffinity::preferred_temperature() const {
1495+int TerrainAffinity::preferred_temperature() const {
1496 return preferred_temperature_;
1497 }
1498
1499-double TerrainAffinity::preferred_fertility() const {
1500+int TerrainAffinity::preferred_fertility() const {
1501 return preferred_fertility_;
1502 }
1503
1504-double TerrainAffinity::preferred_humidity() const {
1505+int TerrainAffinity::preferred_humidity() const {
1506 return preferred_humidity_;
1507 }
1508
1509-double TerrainAffinity::pickiness() const {
1510+int TerrainAffinity::pickiness() const {
1511 return pickiness_;
1512 }
1513
1514-double probability_to_grow(const TerrainAffinity& affinity,
1515+unsigned int probability_to_grow(const TerrainAffinity& affinity,
1516 const FCoords& fcoords,
1517 const Map& map,
1518 const DescriptionMaintainer<TerrainDescription>& terrains) {
1519- double terrain_humidity = 0;
1520- double terrain_fertility = 0;
1521- double terrain_temperature = 0;
1522+ // Initialize with 3 to get proper rounding with the integer division in the return statement
1523+ int terrain_humidity = 3;
1524+ int terrain_fertility = 3;
1525+ int terrain_temperature = 3;
1526
1527- const auto average = [&terrain_humidity, &terrain_fertility, &terrain_temperature,
1528+ const auto sum_up_values = [&terrain_humidity, &terrain_fertility, &terrain_temperature,
1529 &terrains](const int terrain_index) {
1530 const TerrainDescription& t = terrains.get(terrain_index);
1531- terrain_humidity += t.humidity() / 6.;
1532- terrain_temperature += t.temperature() / 6.;
1533- terrain_fertility += t.fertility() / 6.;
1534+ terrain_humidity += t.humidity();
1535+ terrain_temperature += t.temperature();
1536+ terrain_fertility += t.fertility();
1537 };
1538
1539- average(fcoords.field->terrain_d());
1540- average(fcoords.field->terrain_r());
1541+ sum_up_values(fcoords.field->terrain_d());
1542+ sum_up_values(fcoords.field->terrain_r());
1543 {
1544 FCoords tln;
1545 map.get_tln(fcoords, &tln);
1546- average(tln.field->terrain_d());
1547- average(tln.field->terrain_r());
1548+ sum_up_values(tln.field->terrain_d());
1549+ sum_up_values(tln.field->terrain_r());
1550 }
1551
1552 {
1553 FCoords trn;
1554 map.get_trn(fcoords, &trn);
1555- average(trn.field->terrain_d());
1556+ sum_up_values(trn.field->terrain_d());
1557 }
1558
1559 {
1560 FCoords ln;
1561 map.get_ln(fcoords, &ln);
1562- average(ln.field->terrain_r());
1563+ sum_up_values(ln.field->terrain_r());
1564 }
1565
1566 return calculate_probability_to_grow(
1567- affinity, terrain_humidity, terrain_fertility, terrain_temperature);
1568+ affinity, terrain_humidity / 6, terrain_fertility / 6, terrain_temperature / 6);
1569 }
1570
1571-double probability_to_grow(const TerrainAffinity& affinity, const TerrainDescription& terrain) {
1572+unsigned int probability_to_grow(const TerrainAffinity& affinity, const TerrainDescription& terrain) {
1573
1574 return calculate_probability_to_grow(
1575 affinity, terrain.humidity(), terrain.fertility(), terrain.temperature());
1576
1577=== modified file 'src/logic/map_objects/terrain_affinity.h'
1578--- src/logic/map_objects/terrain_affinity.h 2018-04-07 16:59:00 +0000
1579+++ src/logic/map_objects/terrain_affinity.h 2018-11-23 12:45:17 +0000
1580@@ -31,7 +31,6 @@
1581
1582 class Map;
1583 class TerrainDescription;
1584-class World;
1585 struct FCoords;
1586
1587 // Describes the parameters and the pickiness of Immovables towards terrain
1588@@ -39,39 +38,46 @@
1589 // define this.
1590 class TerrainAffinity {
1591 public:
1592+ static constexpr int kPrecisionFactor = 1 << 26;
1593+
1594 explicit TerrainAffinity(const LuaTable& table, const std::string& immovable_name);
1595
1596 // Preferred temperature is in arbitrary units.
1597- double preferred_temperature() const;
1598-
1599- // Preferred fertility in percent [0, 1].
1600- double preferred_fertility() const;
1601-
1602- // Preferred humidity in percent [0, 1].
1603- double preferred_humidity() const;
1604-
1605- // A value in [0, 1] that defines how well this can deal with non-ideal
1606+ int preferred_temperature() const;
1607+
1608+ // Preferred fertility, ranging from 0 to 1000.
1609+ int preferred_fertility() const;
1610+
1611+ // Preferred humidity, ranging from 0 to 1000.
1612+ int preferred_humidity() const;
1613+
1614+ // A value in [0, 99] that defines how well this can deal with non-ideal
1615 // situations. Lower means it is less picky, i.e. it can deal better.
1616- double pickiness() const;
1617+ int pickiness() const;
1618
1619 private:
1620- double preferred_fertility_;
1621- double preferred_humidity_;
1622- double preferred_temperature_;
1623- double pickiness_;
1624+ const int preferred_fertility_;
1625+ const int preferred_humidity_;
1626+ const int preferred_temperature_;
1627+ const int pickiness_;
1628
1629 DISALLOW_COPY_AND_ASSIGN(TerrainAffinity);
1630 };
1631
1632-// Returns a value in [0., 1.] that describes the suitability for the
1633-// 'immovable_affinity' for 'field'. Higher is better suited.
1634-double probability_to_grow(const TerrainAffinity& immovable_affinity,
1635+/**
1636+ * Returns a value in [0, TerrainAffinity::kPrecisionFactor] that describes the suitability for the 'immovable_affinity' for all 6 terrains around 'field'.
1637+ * Higher is better suited, with TerrainAffinity::kPrecisionFactor representing a probability of 1.
1638+ * */
1639+unsigned int probability_to_grow(const TerrainAffinity& immovable_affinity,
1640 const FCoords& fcoords,
1641 const Map& map,
1642 const DescriptionMaintainer<TerrainDescription>& terrains);
1643
1644-// Probability to grow for a single terrain
1645-double probability_to_grow(const TerrainAffinity& immovable_affinity,
1646+/**
1647+ * Returns a value in [0, TerrainAffinity::kPrecisionFactor] that describes the suitability for the 'immovable_affinity' for a single 'terrain'.
1648+ * Higher is better suited, with TerrainAffinity::kPrecisionFactor representing a probability of 1.
1649+ * */
1650+unsigned int probability_to_grow(const TerrainAffinity& immovable_affinity,
1651 const TerrainDescription& terrain);
1652
1653 } // namespace Widelands
1654
1655=== modified file 'src/logic/map_objects/tribes/worker.cc'
1656--- src/logic/map_objects/tribes/worker.cc 2018-11-07 10:19:29 +0000
1657+++ src/logic/map_objects/tribes/worker.cc 2018-11-23 12:45:17 +0000
1658@@ -452,11 +452,11 @@
1659 const uint32_t attribute_id = ImmovableDescr::get_attribute_id("tree_sapling");
1660
1661 const DescriptionMaintainer<TerrainDescription>& terrains = game.world().terrains();
1662- double best = 0.0;
1663+ int best = 0;
1664 for (DescriptionIndex i = 0; i < immovables.size(); ++i) {
1665 const ImmovableDescr& immovable_descr = immovables.get(i);
1666 if (immovable_descr.has_attribute(attribute_id) && immovable_descr.has_terrain_affinity()) {
1667- double probability =
1668+ int probability =
1669 probability_to_grow(immovable_descr.terrain_affinity(), fpos, map, terrains);
1670 if (probability > best) {
1671 best = probability;
1672@@ -464,7 +464,7 @@
1673 }
1674 }
1675 // normalize value to int16 range
1676- const int16_t correct_val = (std::numeric_limits<int16_t>::max() - 1) * best;
1677+ const int16_t correct_val = (std::numeric_limits<int16_t>::max() - 1) * (static_cast<double>(best) / TerrainAffinity::kPrecisionFactor);
1678
1679 if (x_check && (correct_val != cache_entry)) {
1680 forester_cache.clear();
1681@@ -798,7 +798,7 @@
1682 // affinity). We will pick one of them at random later. The container is
1683 // picked to be a stable sorting one, so that no deyncs happen in
1684 // multiplayer.
1685- std::set<std::tuple<double, DescriptionIndex, MapObjectDescr::OwnerType>>
1686+ std::set<std::tuple<int, DescriptionIndex, MapObjectDescr::OwnerType>>
1687 best_suited_immovables_index;
1688
1689 // Checks if the 'immovable_description' has a terrain_affinity, if so use it. Otherwise assume
1690@@ -809,7 +809,7 @@
1691 if (!immovable_description.has_attribute(attribute_id)) {
1692 return;
1693 }
1694- double p = 1.;
1695+ int p = TerrainAffinity::kPrecisionFactor;
1696 if (immovable_description.has_terrain_affinity()) {
1697 p = probability_to_grow(
1698 immovable_description.terrain_affinity(), fpos, map, game.world().terrains());
1699@@ -856,18 +856,18 @@
1700 // Randomly pick one of the immovables to be planted.
1701
1702 // Each candidate is weighted by its probability to grow.
1703- double total_weight = 0.0;
1704+ int total_weight = 0;
1705 for (const auto& bsii : best_suited_immovables_index) {
1706- double weight = std::get<0>(bsii);
1707- total_weight += weight * weight;
1708+ const int weight = std::get<0>(bsii);
1709+ total_weight += weight;
1710 }
1711
1712- double choice = logic_rand_as_double(&game) * total_weight;
1713+ int choice = game.logic_rand() % total_weight;
1714 for (const auto& bsii : best_suited_immovables_index) {
1715- double weight = std::get<0>(bsii);
1716+ const int weight = std::get<0>(bsii);
1717 state.ivar2 = std::get<1>(bsii);
1718 state.ivar3 = static_cast<int>(std::get<2>(bsii));
1719- choice -= weight * weight;
1720+ choice -= weight;
1721 if (0 > choice) {
1722 break;
1723 }
1724
1725=== modified file 'src/logic/map_objects/world/terrain_description.cc'
1726--- src/logic/map_objects/world/terrain_description.cc 2018-04-07 16:59:00 +0000
1727+++ src/logic/map_objects/world/terrain_description.cc 2018-11-23 12:45:17 +0000
1728@@ -105,19 +105,19 @@
1729 default_resource_index_(world.get_resource(table.get_string("default_resource").c_str())),
1730 default_resource_amount_(table.get_int("default_resource_amount")),
1731 dither_layer_(table.get_int("dither_layer")),
1732- temperature_(table.get_double("temperature")),
1733- fertility_(table.get_double("fertility")),
1734- humidity_(table.get_double("humidity")) {
1735+ temperature_(table.get_int("temperature")),
1736+ fertility_(table.get_int("fertility")),
1737+ humidity_(table.get_int("humidity")) {
1738
1739 if (table.has_key("tooltips")) {
1740 custom_tooltips_ = table.get_table("tooltips")->array_entries<std::string>();
1741 }
1742
1743- if (!(0 < fertility_ && fertility_ < 1.)) {
1744- throw GameDataError("%s: fertility is not in (0, 1).", name_.c_str());
1745+ if (!(0 < fertility_ && fertility_ < 1000)) {
1746+ throw GameDataError("%s: fertility is not in (0, 1000).", name_.c_str());
1747 }
1748- if (!(0 < humidity_ && humidity_ < 1.)) {
1749- throw GameDataError("%s: humidity is not in (0, 1).", name_.c_str());
1750+ if (!(0 < humidity_ && humidity_ < 1000)) {
1751+ throw GameDataError("%s: humidity is not in (0, 1000).", name_.c_str());
1752 }
1753 if (temperature_ < 0) {
1754 throw GameDataError("%s: temperature is not possible.", name_.c_str());
1755@@ -244,15 +244,15 @@
1756 return dither_layer_;
1757 }
1758
1759-double TerrainDescription::temperature() const {
1760+int TerrainDescription::temperature() const {
1761 return temperature_;
1762 }
1763
1764-double TerrainDescription::humidity() const {
1765+int TerrainDescription::humidity() const {
1766 return humidity_;
1767 }
1768
1769-double TerrainDescription::fertility() const {
1770+int TerrainDescription::fertility() const {
1771 return fertility_;
1772 }
1773
1774
1775=== modified file 'src/logic/map_objects/world/terrain_description.h'
1776--- src/logic/map_objects/world/terrain_description.h 2018-04-27 06:11:05 +0000
1777+++ src/logic/map_objects/world/terrain_description.h 2018-11-23 12:45:17 +0000
1778@@ -115,13 +115,13 @@
1779
1780 /// Parameters for terrain affinity of immovables.
1781 /// Temperature is in arbitrary units.
1782- double temperature() const;
1783-
1784- /// Humidity in percent [0, 1].
1785- double humidity() const;
1786-
1787- /// Fertility in percent [0, 1].
1788- double fertility() const;
1789+ int temperature() const;
1790+
1791+ /// Humidity, ranging from 0 to 1000.
1792+ int humidity() const;
1793+
1794+ /// Fertility, ranging from 0 to 1000.
1795+ int fertility() const;
1796
1797 /// Additional tooptip entries for the editor
1798 const std::vector<std::string>& custom_tooltips() const {
1799@@ -139,9 +139,9 @@
1800 int default_resource_amount_;
1801 int dither_layer_;
1802 int frame_length_;
1803- double temperature_;
1804- double fertility_;
1805- double humidity_;
1806+ int temperature_;
1807+ int fertility_;
1808+ int humidity_;
1809 std::vector<std::string> texture_paths_;
1810 std::vector<const Image*> textures_;
1811 RGBColor minimap_colors_[256];
1812
1813=== modified file 'src/scripting/lua_map.cc'
1814--- src/scripting/lua_map.cc 2018-11-09 01:26:21 +0000
1815+++ src/scripting/lua_map.cc 2018-11-23 12:45:17 +0000
1816@@ -1927,8 +1927,8 @@
1817
1818 returns the terrain affinity values for this immovable
1819
1820- (RO) a table containing numbers labeled as pickiness (double), preferred_fertility (double),
1821- preferred_humidity (double), and preferred_temperature (uint),
1822+ (RO) a table containing numbers labeled as pickiness (uint), preferred_fertility (uint),
1823+ preferred_humidity (uint), and preferred_temperature (uint),
1824 or nil if the immovable has no terrain affinity.
1825 */
1826 int LuaImmovableDescription::get_terrain_affinity(lua_State* L) {
1827@@ -1936,13 +1936,13 @@
1828 const TerrainAffinity& affinity = get()->terrain_affinity();
1829 lua_newtable(L);
1830 lua_pushstring(L, "pickiness");
1831- lua_pushdouble(L, affinity.pickiness());
1832+ lua_pushuint32(L, affinity.pickiness());
1833 lua_settable(L, -3);
1834 lua_pushstring(L, "preferred_fertility");
1835- lua_pushdouble(L, affinity.preferred_fertility());
1836+ lua_pushuint32(L, affinity.preferred_fertility());
1837 lua_settable(L, -3);
1838 lua_pushstring(L, "preferred_humidity");
1839- lua_pushdouble(L, affinity.preferred_humidity());
1840+ lua_pushuint32(L, affinity.preferred_humidity());
1841 lua_settable(L, -3);
1842 lua_pushstring(L, "preferred_temperature");
1843 lua_pushuint32(L, affinity.preferred_temperature());
1844@@ -2034,7 +2034,7 @@
1845 if (get()->has_terrain_affinity()) {
1846 const TerrainDescription* terrain =
1847 (*get_user_class<LuaMaps::LuaTerrainDescription>(L, 2))->get();
1848- lua_pushdouble(L, Widelands::probability_to_grow(get()->terrain_affinity(), *terrain));
1849+ lua_pushdouble(L, Widelands::probability_to_grow(get()->terrain_affinity(), *terrain) / static_cast<double>(Widelands::TerrainAffinity::kPrecisionFactor));
1850 } else {
1851 lua_pushnil(L);
1852 }
1853@@ -3513,22 +3513,22 @@
1854 /* RST
1855 .. attribute:: fertility
1856
1857- (RO) the :class:`double` fertility value for this terrain
1858+ (RO) the :class:`uint` fertility value for this terrain
1859 */
1860
1861 int LuaTerrainDescription::get_fertility(lua_State* L) {
1862- lua_pushdouble(L, get()->fertility());
1863+ lua_pushuint32(L, get()->fertility());
1864 return 1;
1865 }
1866
1867 /* RST
1868 .. attribute:: humidity
1869
1870- (RO) the :class:`double` humidity value for this terrain
1871+ (RO) the :class:`uint` humidity value for this terrain
1872 */
1873
1874 int LuaTerrainDescription::get_humidity(lua_State* L) {
1875- lua_pushdouble(L, get()->humidity());
1876+ lua_pushuint32(L, get()->humidity());
1877 return 1;
1878 }
1879
1880
1881=== modified file 'test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua'
1882--- test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua 2018-09-29 05:10:39 +0000
1883+++ test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua 2018-11-23 12:45:17 +0000
1884@@ -75,22 +75,22 @@
1885 local aff_umbrella_green_mature = egbase:get_immovable_description("umbrella_green_wasteland_mature").terrain_affinity
1886
1887 -- Pickiness
1888- assert_near(0.6, aff_alder_sapling["pickiness"], 0.01)
1889+ assert_equal(60, aff_alder_sapling["pickiness"])
1890 assert_equal(aff_alder_sapling["pickiness"], aff_alder_old["pickiness"])
1891- assert_near(0.6, aff_mushroom_red_pole["pickiness"], 0.01)
1892- assert_near(0.8, aff_umbrella_green_mature["pickiness"], 0.01)
1893+ assert_equal(60, aff_mushroom_red_pole["pickiness"])
1894+ assert_equal(80, aff_umbrella_green_mature["pickiness"])
1895
1896 -- preferred_fertility
1897- assert_near(0.6, aff_alder_sapling["preferred_fertility"], 0.01)
1898+ assert_equal(600, aff_alder_sapling["preferred_fertility"])
1899 assert_equal(aff_alder_sapling["preferred_fertility"], aff_alder_old["preferred_fertility"])
1900- assert_near(0.85, aff_mushroom_red_pole["preferred_fertility"], 0.01)
1901- assert_near(0.85, aff_umbrella_green_mature["preferred_fertility"], 0.01)
1902+ assert_equal(850, aff_mushroom_red_pole["preferred_fertility"])
1903+ assert_equal(850, aff_umbrella_green_mature["preferred_fertility"])
1904
1905 -- preferred_humidity
1906- assert_near(0.65, aff_alder_sapling["preferred_humidity"], 0.01)
1907+ assert_equal(650, aff_alder_sapling["preferred_humidity"])
1908 assert_equal(aff_alder_sapling["preferred_humidity"], aff_alder_old["preferred_humidity"])
1909- assert_near(0.35, aff_mushroom_red_pole["preferred_humidity"], 0.01)
1910- assert_near(0.2, aff_umbrella_green_mature["preferred_humidity"], 0.01)
1911+ assert_equal(350, aff_mushroom_red_pole["preferred_humidity"])
1912+ assert_equal(200, aff_umbrella_green_mature["preferred_humidity"])
1913
1914 -- preferred_temperature
1915 assert_equal(125, aff_alder_sapling["preferred_temperature"])
1916
1917=== modified file 'test/maps/lua_testsuite.wmf/scripting/terrains_resources_descriptions.lua'
1918--- test/maps/lua_testsuite.wmf/scripting/terrains_resources_descriptions.lua 2016-07-10 19:03:33 +0000
1919+++ test/maps/lua_testsuite.wmf/scripting/terrains_resources_descriptions.lua 2018-11-23 12:45:17 +0000
1920@@ -141,17 +141,17 @@
1921 end
1922
1923 function test_terrains_resource_descr:test_terrain_fertility()
1924- assert_near(0.7, egbase:get_terrain_description("summer_meadow1").fertility, 0.01)
1925- assert_near(0.2, egbase:get_terrain_description("wasteland_beach").fertility, 0.01)
1926- assert_near(0.5, egbase:get_terrain_description("desert_forested_mountain2").fertility, 0.01)
1927- assert_near(0.001, egbase:get_terrain_description("winter_water").fertility, 0.0001)
1928+ assert_equal(700, egbase:get_terrain_description("summer_meadow1").fertility)
1929+ assert_equal(200, egbase:get_terrain_description("wasteland_beach").fertility)
1930+ assert_equal(500, egbase:get_terrain_description("desert_forested_mountain2").fertility)
1931+ assert_equal(1, egbase:get_terrain_description("winter_water").fertility)
1932 end
1933
1934 function test_terrains_resource_descr:test_terrain_humidity()
1935- assert_near(0.6, egbase:get_terrain_description("summer_meadow1").humidity, 0.01)
1936- assert_near(0.4, egbase:get_terrain_description("wasteland_beach").humidity, 0.01)
1937- assert_near(0.5, egbase:get_terrain_description("desert_forested_mountain2").humidity, 0.01)
1938- assert_near(0.999, egbase:get_terrain_description("winter_water").humidity, 0.0001)
1939+ assert_equal(600, egbase:get_terrain_description("summer_meadow1").humidity)
1940+ assert_equal(400, egbase:get_terrain_description("wasteland_beach").humidity)
1941+ assert_equal(500, egbase:get_terrain_description("desert_forested_mountain2").humidity)
1942+ assert_equal(999, egbase:get_terrain_description("winter_water").humidity)
1943 end
1944
1945 function test_terrains_resource_descr:test_terrain_temperature()

Subscribers

People subscribed via source and target branches

to status/vote changes: