src/economy_new.h
branchgamebalance
changeset 9883 ac3e1a8434b7
parent 9882 059933c94c5d
child 9884 c1169958d5ff
equal deleted inserted replaced
9882:059933c94c5d 9883:ac3e1a8434b7
     7 
     7 
     8 #include "debug.h"          // debug outputs
     8 #include "debug.h"          // debug outputs
     9 #include "fixedt.h"         // FixedT data types
     9 #include "fixedt.h"         // FixedT data types
    10 #include "date.h"           // current year / date
    10 #include "date.h"           // current year / date
    11 #include "variables.h"      // difficulty
    11 #include "variables.h"      // difficulty
    12 #include "functions.h"      // RandomRange
       
    13 
    12 
    14 /**
    13 /**
    15  * Handles all the economic data and events
    14  * Handles all the economic data and events
    16  */
    15  */
    17 class CEconomy {
    16 class CEconomy {
    18 private:
    17 private:
    19 	FixedT<int32, 16> m_basic_growth;     ///< Basic growth number, depends solely on difficulty setting
    18 	FixedT<int32, 16> m_basic_growth;    ///< Basic growth number, depends solely on difficulty setting
    20 	FixedT<int64, 16> m_activity_level;   ///< Economic Activity Level, an indicator for the GDP per capita of the map
    19 	FixedT<int64, 16> m_activity_level;  ///< Economic Activity Level, an indicator for the GDP per capita of the map
    21 	byte              m_long_term_cycle;  ///< The period of the long-term cycle suggested by Kondratiev
       
    22 	byte              m_short_term_cycle; ///< The period of the short-term cycle (see Juglar, others)
       
    23 	FixedT<int32, 16> m_long_term_ampl;   ///< Amplitude of the long-term cycle
       
    24 	FixedT<int32, 16> m_short_term_ampl;  ///< Amplitude of the short-term cycle
       
    25 
    20 
    26 public:
    21 public:
    27 	/**
    22 	/**
    28 	 * Starts the economy. This sets the basic growth by the difficulty level and adjust the current
    23 	 * Starts the economy. This sets the basic growth by the difficulty level and adjust the current
    29 	 * EAL by the year of the game. We also set the economic cycles here.
    24 	 * EAL by the year of the game. It also stores the world's population at the beginning of the
       
    25 	 * game.
    30 	 * @warning This should be run once per game only
    26 	 * @warning This should be run once per game only
    31 	 */
    27 	 */
    32 	CEconomy() {
    28 	CEconomy() {
    33 		/* Set basic growth */
       
    34 		FixedT<int32, 16> growth(_opt.diff.economic_growth, 2);
    29 		FixedT<int32, 16> growth(_opt.diff.economic_growth, 2);
    35 		m_basic_growth = (growth + 1) / 100 + 1;
    30 		growth += 1;
       
    31 		m_basic_growth = growth / 100 + 1;
    36 		DEBUG(eco, 3, "Starting a new economy with a basic growth factor of %.3f in the year %d", (double)m_basic_growth, _cur_year);
    32 		DEBUG(eco, 3, "Starting a new economy with a basic growth factor of %.3f in the year %d", (double)m_basic_growth, _cur_year);
    37 
       
    38 		/* Set up the economic cycles */
       
    39 		m_long_term_cycle  = 50; //RandomRange(15) + 45;
       
    40 		m_short_term_cycle = 10; //RandomRange(4) + 6;
       
    41 		m_long_term_ampl = RandomRange(5) + 10;
       
    42 		m_short_term_ampl = RandomRange(10) + 15;
       
    43 		m_long_term_ampl /= 1000;
       
    44 		m_short_term_ampl /= 1000;
       
    45 		DEBUG(eco, 4, "Adjusting economic cycles to %d and %d years", m_long_term_cycle, m_short_term_cycle);
       
    46 		DEBUG(eco, 4, "Adjusting economic cycles to %f and %f (amplitude)", (double)m_long_term_ampl, (double)m_short_term_ampl);
       
    47 
       
    48 		m_activity_level = 1;
    33 		m_activity_level = 1;
    49 		m_activity_level = pow(m_basic_growth, _cur_year - 1820);
    34 		m_activity_level = pow(m_basic_growth, _cur_year - 1820);
    50 		DEBUG(eco, 4, "Adjusting basic EAL for current year (offset %d) to %.3f", _cur_year - 1820, (double)m_activity_level);
    35 		DEBUG(eco, 4, "Adjusting EAL for current year (offset %d) to %.3f", _cur_year - 1820, (double)m_activity_level);
    51 
       
    52 	}
    36 	}
    53 
    37 
    54 	/**
    38 	/**
    55 	 * Removes an economy.
    39 	 * Removes an economy.
    56 	 */
    40 	 */
    61 	/**
    45 	/**
    62 	 * Adjusts the economic settings on a yearly level.
    46 	 * Adjusts the economic settings on a yearly level.
    63 	 */
    47 	 */
    64 	void YearlyLoop()
    48 	void YearlyLoop()
    65 	{
    49 	{
    66 		FixedT<int32, 16> growth = m_basic_growth;
       
    67 		growth += GetCyclicGrowth();
       
    68 		DEBUG(eco, 3, "Entering the yearly loop for economy");
    50 		DEBUG(eco, 3, "Entering the yearly loop for economy");
    69 		m_activity_level *= growth;
    51 		m_activity_level *= m_basic_growth;
    70 		DEBUG(eco, 4, "Set global EAL to %.3f", (double)m_activity_level);
    52 		DEBUG(eco, 4, "Set global EAL to %.3f", (double)m_activity_level);
    71 	}
    53 	}
    72 
    54 
    73 	/**
       
    74 	 * Computes the modification of economic growth by cyclic events
       
    75 	 * @return The growth modification
       
    76 	 */
       
    77 	FixedT<int32, 16> GetCyclicGrowth() const
       
    78 	{
       
    79 		FixedT<int32, 16> long_term (PI * 2 * (_cur_year - 1800), m_long_term_cycle);
       
    80 		FixedT<int32, 16> short_term(PI * 2 * (_cur_year - 1800), m_short_term_cycle);
       
    81 
       
    82 		//std::cout << long_term << /* ":" << short_term << */ std::endl;
       
    83 		//std::cout << cos(long_term) << /* ":" << cos(short_term) << */ std::endl;
       
    84 
       
    85 		//DEBUG(eco, 5, "Cyclic Growth is %.4f", (double)(m_long_term_ampl * cos(long_term) + m_short_term_ampl * cos(short_term)));
       
    86 		return (  m_long_term_ampl * cos(long_term) + m_short_term_ampl * cos(short_term) );
       
    87 	}
       
    88 };
    55 };
    89 
       
    90 
    56 
    91 extern CEconomy *_eco;
    57 extern CEconomy *_eco;
    92 void InitializeEconomy();
    58 void InitializeEconomy();
    93 
    59 
    94 #endif /* ECONOMY_NEW_H */
    60 #endif /* ECONOMY_NEW_H */