(svn r9141) [gamebalance] -Add: Random events that can occur monthly and affect the economy as a whole (i.e. are not local to a town or industry)
--- a/src/date.cpp Tue Mar 13 12:28:01 2007 +0000
+++ b/src/date.cpp Tue Mar 13 15:46:40 2007 +0000
@@ -265,6 +265,7 @@
RedrawAutosave();
}
+ _eco->MonthlyLoop();
PlayersMonthlyLoop();
EnginesMonthlyLoop();
TownsMonthlyLoop();
--- a/src/economy_new.h Tue Mar 13 12:28:01 2007 +0000
+++ b/src/economy_new.h Tue Mar 13 15:46:40 2007 +0000
@@ -71,6 +71,28 @@
}
/**
+ * Adds random events to the economic growth. This should call a random event every
+ * 20 months. Well at least it should if RandomRange would be distributed in a
+ * linear fashion. Note that there's one event in RandomEvents with a value of
+ * -100 that doesn't have a positive "partner". This one simulates a big crash
+ * or any other catastrohic event (war, disease, terrorism, whatever).
+ * @todo Add news events for higher modifications in the economy (=> 2%)
+ */
+ void MonthlyLoop()
+ {
+ /* Modifications of the global economic activity one-tenth of a percent */
+ static const int RandomEvents[] = {-1, 1, -2, 2, -5, 5, -10, 10, -12, 12, -15, 15, -20, 20, -25, 25, 32, -32, 50, -50, -100};
+ /* I didn't use the 19, because it hardly ever is the return of RandomRange for whatever reason */
+ if (RandomRange(20) != 18) return;
+
+ FixedT<int32, 16> mod( RandomEvents[RandomRange(lengthof(RandomEvents))], 1000);
+ mod += 1;
+
+ m_activity_level *= mod;
+ DEBUG(eco, 5, "Added a random event with a value of %f, adjusted EAL to %f", (double)mod, (double)m_activity_level);
+ }
+
+ /**
* Computes the modification of economic growth by cyclic events
* @return The growth modification
*/