(svn r9114) [gamebalance] -Add: Added the new economy, with the ability to adjust growth in the difficulty window. The economy doesn't do anything yet, it just exists. gamebalance
authorcelestar
Sun, 11 Mar 2007 14:02:43 +0000
branchgamebalance
changeset 9881 fbb3eab0e186
parent 9880 bd97cc28b569
child 9882 059933c94c5d
(svn r9114) [gamebalance] -Add: Added the new economy, with the ability to adjust growth in the difficulty window. The economy doesn't do anything yet, it just exists.
source.list
src/date.cpp
src/debug.cpp
src/debug.h
src/economy_new.cpp
src/economy_new.h
src/lang/english.txt
src/misc.cpp
src/openttd.h
src/settings_gui.cpp
--- a/source.list	Sun Mar 11 13:57:34 2007 +0000
+++ b/source.list	Sun Mar 11 14:02:43 2007 +0000
@@ -14,6 +14,7 @@
 depot.cpp
 driver.cpp
 economy.cpp
+economy_new.cpp
 elrail.cpp
 engine.cpp
 fileio.cpp
--- a/src/date.cpp	Sun Mar 11 13:57:34 2007 +0000
+++ b/src/date.cpp	Sun Mar 11 14:02:43 2007 +0000
@@ -13,6 +13,7 @@
 #include "network/network_server.h"
 #include "functions.h"
 #include "currency.h"
+#include "economy_new.h"
 
 Year      _cur_year;
 Month     _cur_month;
@@ -277,6 +278,7 @@
 	_cur_year = ymd.year;
 
 	/* yes, call various yearly loops */
+	_eco->YearlyLoop();
 	PlayersYearlyLoop();
 	TrainsYearlyLoop();
 	RoadVehiclesYearlyLoop();
--- a/src/debug.cpp	Sun Mar 11 13:57:34 2007 +0000
+++ b/src/debug.cpp	Sun Mar 11 14:02:43 2007 +0000
@@ -31,6 +31,7 @@
 int _debug_freetype_level;
 int _debug_sl_level;
 int _debug_station_level;
+int _debug_eco_level;
 
 
 typedef struct DebugLevel {
@@ -55,6 +56,7 @@
 	DEBUG_LEVEL(freetype),
 	DEBUG_LEVEL(sl),
 	DEBUG_LEVEL(station),
+	DEBUG_LEVEL(eco),
 	};
 #undef DEBUG_LEVEL
 
--- a/src/debug.h	Sun Mar 11 13:57:34 2007 +0000
+++ b/src/debug.h	Sun Mar 11 14:02:43 2007 +0000
@@ -5,6 +5,8 @@
 #ifndef DEBUG_H
 #define DEBUG_H
 
+#include "stdafx.h" // We need this for CDECL
+
 /* Debugging messages policy:
  * These should be the severities used for direct DEBUG() calls
  * maximum debugging level should be 10 if really deep, deep
@@ -42,6 +44,7 @@
 		freetype,
 		sl,
 		station,
+		eco,
 	};
 #endif /* NO_VARARG_MACRO */
 
@@ -77,6 +80,7 @@
 	extern int _debug_freetype_level;
 	extern int _debug_sl_level;
 	extern int _debug_station_level;
+	extern int _debug_eco_level;
 
 	#if !defined(NO_VARARG_MACRO)
 		void CDECL debug(const char *dbg, ...);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/economy_new.cpp	Sun Mar 11 14:02:43 2007 +0000
@@ -0,0 +1,19 @@
+/* $Id$ */
+
+/** @file */
+
+#include "economy_new.h"
+
+/** The global economy */
+CEconomy *_eco;
+
+/**
+ * Starts a new economy. As there can always be only one economy in place,
+ * deletes the one that is currently active
+ */
+void InitializeEconomy()
+{
+	delete _eco;
+	_eco = new CEconomy;
+	assert(_eco != NULL);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/economy_new.h	Sun Mar 11 14:02:43 2007 +0000
@@ -0,0 +1,60 @@
+/* $Id$ */
+
+/** @file */
+
+#ifndef ECONOMY_NEW_H
+#define ECONOMY_NEW_H
+
+#include "debug.h"          // debug outputs
+#include "fixedt.h"         // FixedT data types
+#include "date.h"           // current year / date
+#include "variables.h"      // difficulty
+
+/**
+ * Handles all the economic data and events
+ */
+class CEconomy {
+private:
+	FixedT<int32, 16> m_basic_growth;    ///< Basic growth number, depends solely on difficulty setting
+	FixedT<int64, 16> m_activity_level;  ///< Economic Activity Level, an indicator for the GDP per capita of the map
+
+public:
+	/**
+	 * Starts the economy. This sets the basic growth by the difficulty level and adjust the current
+	 * EAL by the year of the game. It also stores the world's population at the beginning of the
+	 * game.
+	 * @warning This should be run once per game only
+	 */
+	CEconomy() {
+		FixedT<int32, 16> growth(_opt.diff.economic_growth, 2);
+		growth += 1;
+		m_basic_growth = growth / 100 + 1;
+		DEBUG(eco, 3, "Starting a new economy with a basic growth factor of %.3f in the year %d", (double)m_basic_growth, _cur_year);
+		m_activity_level = 1;
+		m_activity_level = pow(m_basic_growth, _cur_year - 1820);
+		DEBUG(eco, 4, "Adjusting EAL for current year (offset %d) to %.3f", _cur_year - 1820, (double)m_activity_level);
+	}
+
+	/**
+	 * Removes an economy.
+	 */
+	~CEconomy() {
+		DEBUG(eco, 3, "Ending economy");
+	}
+
+	/**
+	 * Adjusts the economic settings on a yearly level.
+	 */
+	void YearlyLoop()
+	{
+		DEBUG(eco, 3, "Entering the yearly loop for economy");
+		m_activity_level *= m_basic_growth;
+		DEBUG(eco, 4, "Set global EAL to %.3f", (double)m_activity_level);
+	}
+
+};
+
+extern CEconomy *_eco;
+void InitializeEconomy();
+
+#endif /* ECONOMY_NEW_H */
--- a/src/lang/english.txt	Sun Mar 11 13:57:34 2007 +0000
+++ b/src/lang/english.txt	Sun Mar 11 14:02:43 2007 +0000
@@ -2017,6 +2017,7 @@
 STR_6814_TRAIN_REVERSING                                        :{LTBLUE}Train reversing: {ORANGE}{STRING}
 STR_6815_DISASTERS                                              :{LTBLUE}Disasters: {ORANGE}{STRING}
 STR_16816_CITY_APPROVAL                                         :{LTBLUE}City council's attitude towards area restructuring: {ORANGE}{STRING}
+STR_ECONOMIC_GROWTH                                             :{LTBLUE}Basic economic growth: {ORANGE}{STRING}
 ############ range for difficulty settings ends
 
 STR_26816_NONE                                                  :None
--- a/src/misc.cpp	Sun Mar 11 13:57:34 2007 +0000
+++ b/src/misc.cpp	Sun Mar 11 14:02:43 2007 +0000
@@ -4,6 +4,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "economy_new.h"
 #include "currency.h"
 #include "functions.h"
 #include "news.h"
@@ -128,6 +129,7 @@
 	InitializeAirportGui();
 	InitializeDockGui();
 	InitializeTowns();
+	InitializeEconomy();
 	InitializeTrees();
 	InitializeSigns();
 	InitializeStations();
--- a/src/openttd.h	Sun Mar 11 13:57:34 2007 +0000
+++ b/src/openttd.h	Sun Mar 11 14:02:43 2007 +0000
@@ -245,7 +245,7 @@
 	int32 build_industry;
 } Prices;
 
-#define GAME_DIFFICULTY_NUM 18
+#define GAME_DIFFICULTY_NUM 19
 
 typedef struct GameDifficulty {
 	int max_no_competitors;
@@ -266,6 +266,7 @@
 	int line_reverse_mode;
 	int disasters;
 	int town_council_tolerance; // minimum required town ratings to be allowed to demolish stuff
+	int economic_growth;
 } GameDifficulty;
 
 enum {
--- a/src/settings_gui.cpp	Sun Mar 11 13:57:34 2007 +0000
+++ b/src/settings_gui.cpp	Sun Mar 11 14:02:43 2007 +0000
@@ -321,6 +321,7 @@
 	{  0,   1,  1, STR_6834_AT_END_OF_LINE_AND_AT_STATIONS},
 	{  0,   1,  1, STR_6836_OFF},
 	{  0,   2,  1, STR_6839_PERMISSIVE},
+	{  0,   2,  1, STR_6820_LOW},
 };
 
 static inline bool GetBitAndShift(uint32 *b)
@@ -349,12 +350,13 @@
  * P: Train reversing (0 = end of line + stations, 1 = end of line)
  * Q: disasters
  * R: area restructuring (0 = permissive, 2 = hostile)
+ * S: Economic Growth
  */
 static const int16 _default_game_diff[3][GAME_DIFFICULTY_NUM] = { /*
-	 A, B, C, D,   E, F, G, H, I, J, K, L, M, N, O, P, Q, R*/
-	{2, 2, 1, 3, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0}, //easy
-	{4, 1, 1, 2, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1}, //medium
-	{7, 0, 2, 2, 100, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2}, //hard
+	 A, B, C, D,   E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S*/
+	{2, 2, 1, 3, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0, 2}, //easy
+	{4, 1, 1, 2, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1}, //medium
+	{7, 0, 2, 2, 100, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2, 0}, //hard
 };
 
 void SetDifficultyLevel(int mode, GameOptions *gm_opt)