summaryrefslogtreecommitdiff
path: root/src/industry_cmd.cpp
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2008-09-15 17:18:22 +0000
committerbelugas <belugas@openttd.org>2008-09-15 17:18:22 +0000
commit0682dc3a0d97ecee26d807476071d5f552f86212 (patch)
treebbcf66eb7b0fe5be0cf11258b7cfa2654517ac4b /src/industry_cmd.cpp
parent606f4defdca281a3f918c9525dbd4d525ad11131 (diff)
downloadopenttd-0682dc3a0d97ecee26d807476071d5f552f86212.tar.xz
(svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
This will allow to perform more changes per month on big maps and less on smaller maps, while not overtaxing the IndustryMonthlyLoop process. Thanks to frosch, for nice code ideas and rewrites
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r--src/industry_cmd.cpp49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 41be3a9f2..7c78762a1 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2235,6 +2235,47 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
}
}
+/** Daily handler for the industry changes
+ * Taking the original map size of 256*256, the number of random changes was always of just one unit.
+ * But it cannot be the same on smaller or bigger maps. That number has to be scaled up or down.
+ * For small maps, it implies that less than one change per month is required, while on bigger maps,
+ * it would be way more. The daily loop handles those changes. */
+void IndustryDailyLoop()
+{
+ _economy.industry_daily_change_counter += _economy.industry_daily_increment;
+
+ /* Bits 16-31 of industry_construction_counter contain the number of industries to change/create today,
+ * the lower 16 bit are a fractional part that might accumulate over several days until it
+ * is sufficient for an industry. */
+ uint16 change_loop = _economy.industry_daily_change_counter >> 16;
+
+ /* Reset the active part of the counter, just keeping the "factional part" */
+ _economy.industry_daily_change_counter &= 0xFFFF;
+
+ if (change_loop == 0) {
+ return; // Nothing to do? get out
+ }
+
+ PlayerID old_player = _current_player;
+ _current_player = OWNER_NONE;
+
+ /* perform the required industry changes for the day */
+ for (uint16 j = 0; j < change_loop; j++) {
+ /* 3% chance that we start a new industry */
+ if (Chance16(3, 100)) {
+ MaybeNewIndustry();
+ } else {
+ Industry *i = GetRandomIndustry();
+ if (i != NULL) ChangeIndustryProduction(i, false);
+ }
+ }
+
+ _current_player = old_player;
+
+ /* production-change */
+ InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
+}
+
void IndustryMonthlyLoop()
{
Industry *i;
@@ -2250,14 +2291,6 @@ void IndustryMonthlyLoop()
}
}
- /* 3% chance that we start a new industry */
- if (Chance16(3, 100)) {
- MaybeNewIndustry();
- } else {
- i = GetRandomIndustry();
- if (i != NULL) ChangeIndustryProduction(i, false);
- }
-
_current_player = old_player;
/* production-change */