summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2008-02-09 03:12:05 +0000
committerbelugas <belugas@openttd.org>2008-02-09 03:12:05 +0000
commitcebb86777ab56559938a51bfdb2a3188eb427d08 (patch)
treec25cef20252d4f79dcaeff2a6dcf6fd23f201927 /src
parenta782ab3903891f414408556e87e1e94ca2cfc5a3 (diff)
downloadopenttd-cebb86777ab56559938a51bfdb2a3188eb427d08.tar.xz
(svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
And use multiply/divide operations instead of shifting. It does the same, just adds a bit more readability
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 498fa9fd4..bf8dea242 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2137,7 +2137,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
/* Increase if needed */
while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
- i->prod_level <<= 1;
+ i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM);
i->production_rate[0] = min(i->production_rate[0] * 2, 0xFF);
i->production_rate[1] = min(i->production_rate[1] * 2, 0xFF);
if (str == STR_NULL) str = indspec->production_up_text;
@@ -2148,9 +2148,9 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
if (i->prod_level == PRODLEVEL_MINIMUM) {
closeit = true;
} else {
- i->prod_level >>= 1;
- i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
- i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
+ i->prod_level = max(i->prod_level / 2, (int)PRODLEVEL_MINIMUM); // typecast to int required to please MSVC
+ i->production_rate[0] = (i->production_rate[0] + 1) / 2;
+ i->production_rate[1] = (i->production_rate[1] + 1) / 2;
if (str == STR_NULL) str = indspec->production_down_text;
}
}