src/economy_new.h
branchgamebalance
changeset 9903 dc85aaa556ae
parent 9901 a922f277ebfd
equal deleted inserted replaced
9902:ed8f92929297 9903:dc85aaa556ae
    44 
    44 
    45 /**
    45 /**
    46  * Handles all the economic data and events
    46  * Handles all the economic data and events
    47  */
    47  */
    48 class CEconomy : public EconomicObject {
    48 class CEconomy : public EconomicObject {
       
    49 public:
       
    50 	/**
       
    51 	 * Enumerator for the different costs for operations a player can perform.
       
    52 	 * Should be used to access the array of prices.
       
    53 	 */
       
    54 	enum Price {
       
    55 		STATION_VALUE,
       
    56 		PRICE_RAIL_BUILD,      /**< Cost of placing a single piece of track (a vertical or horizontal one.
       
    57 								 *  @todo make sure the longer pieces of track cost a bit more
       
    58 								 */
       
    59 		BUILD_ROAD,
       
    60 		BUILD_SIGNALS,
       
    61 		BUILD_BRIDGE,
       
    62 		BUILD_TRAIN_DEPOT,
       
    63 		BUILD_ROAD_DEPOT,
       
    64 		BUILD_SHIP_DEPOT,
       
    65 		BUILD_TUNNEL,
       
    66 		TRAIN_STATION_TRACK,
       
    67 		TRAIN_STATION_LENGTH,
       
    68 		BUILD_AIRPORT,
       
    69 		BUILD_BUS_STATION,
       
    70 		BUILD_TRUCK_STATION,
       
    71 		BUILD_DOCK,
       
    72 		BUILD_RAILVEHICLE,
       
    73 		BUILD_RAILWAGON,
       
    74 		AIRCRAFT_BASE,
       
    75 		ROADVEH_BASE,
       
    76 		SHIP_BASE,
       
    77 		BUILD_TREES,
       
    78 		TERRAFORM,
       
    79 		CLEAR_1,
       
    80 		PURCHASE_LAND,
       
    81 		CLEAR_2,
       
    82 		CLEAR_3,
       
    83 		REMOVE_TREES,
       
    84 		PRICE_RAIL_REMOVE,     /**< cost for removing a piece of track. Less than for building because one
       
    85 								 *  might be able to reuse stuff
       
    86 						 		 */
       
    87 		REMOVE_SIGNALS,
       
    88 		CLEAR_BRIDGE,
       
    89 		REMOVE_TRAIN_DEPOT,
       
    90 		REMOVE_ROAD_DEPOT,
       
    91 		REMOVE_SHIP_DEPOT,
       
    92 		CLEAR_TUNNEL,
       
    93 		CLEAR_WATER,
       
    94 		REMOVE_RAIL_STATION,
       
    95 		REMOVE_AIRPORT,
       
    96 		REMOVE_BUS_STATION,
       
    97 		REMOVE_TRUCK_STATION,
       
    98 		REMOVE_DOCK,
       
    99 		REMOVE_HOUSE,
       
   100 		REMOVE_ROAD,
       
   101 		RUNNING_RAIL0,
       
   102 		RUNNING_RAIL1,
       
   103 		RUNNING_RAIL2,
       
   104 		AIRCRAFT_RUNNING,
       
   105 		ROADVEH_RUNNING,
       
   106 		SHIP_RUNNING,
       
   107 		BUILD_INDUSTRY,
       
   108 
       
   109 		MAX_PRICE              ///< end marker; use with for loops and arrays for example
       
   110 	};
       
   111 
       
   112 
    49 private:
   113 private:
    50 	FixedT<int32, 16> m_basic_growth;     ///< Basic growth number, depends solely on difficulty setting
   114 	FixedT<int32, 16> m_basic_growth;                 ///< Basic growth number, depends solely on difficulty setting
    51 	byte              m_long_term_cycle;  ///< The period of the long-term cycle suggested by Kondratiev
   115 	byte              m_long_term_cycle;              ///< The period of the long-term cycle suggested by Kondratiev
    52 	byte              m_short_term_cycle; ///< The period of the short-term cycle (see Juglar, others)
   116 	byte              m_short_term_cycle;             ///< The period of the short-term cycle (see Juglar, others)
    53 	FixedT<int32, 16> m_long_term_ampl;   ///< Amplitude of the long-term cycle
   117 	FixedT<int32, 16> m_long_term_ampl;               ///< Amplitude of the long-term cycle
    54 	FixedT<int32, 16> m_short_term_ampl;  ///< Amplitude of the short-term cycle
   118 	FixedT<int32, 16> m_short_term_ampl;              ///< Amplitude of the short-term cycle
       
   119 
       
   120 	FixedT<int32, 16> m_prices[MAX_PRICE];            ///< Cost of operations for the player. Positive for cost, negative for income
    55 
   121 
    56 public:
   122 public:
    57 	/**
   123 	CEconomy();
    58 	 * Starts the economy. This sets the basic growth by the difficulty level and adjust the current
       
    59 	 * EAL by the year of the game. We also set the economic cycles here.
       
    60 	 * @warning This should be run once per game only
       
    61 	 */
       
    62 	CEconomy() {
       
    63 		/* Set basic growth */
       
    64 		FixedT<int32, 16> growth(_opt.diff.economic_growth, 2);
       
    65 		m_basic_growth = (growth + 1) / 100 + 1;
       
    66 		DEBUG(eco, 3, "Starting a new economy with a basic growth factor of %.3f in the year %d", (double)m_basic_growth, _cur_year);
       
    67 
       
    68 		/* Set up the economic cycles */
       
    69 		m_long_term_cycle  = RandomRange(15) + 45;
       
    70 		m_short_term_cycle = RandomRange(4) + 6;
       
    71 		m_long_term_ampl = RandomRange(5) + 10;
       
    72 		m_short_term_ampl = RandomRange(10) + 15;
       
    73 		m_long_term_ampl /= 1000;
       
    74 		m_short_term_ampl /= 1000;
       
    75 		DEBUG(eco, 4, "Adjusting economic cycles to %d and %d years", m_long_term_cycle, m_short_term_cycle);
       
    76 		DEBUG(eco, 4, "Adjusting economic cycles to %f and %f (amplitude)", (double)m_long_term_ampl, (double)m_short_term_ampl);
       
    77 
       
    78 		m_activity_level = 1;
       
    79 		m_activity_level = pow(m_basic_growth, _cur_year - 1820);
       
    80 		DEBUG(eco, 4, "Adjusting basic EAL for current year (offset %d) to %.3f", _cur_year - 1820, (double)m_activity_level);
       
    81 
       
    82 	}
       
    83 
   124 
    84 	/**
   125 	/**
    85 	 * Removes an economy.
   126 	 * Removes an economy.
    86 	 */
   127 	 */
    87 	~CEconomy() {
   128 	~CEconomy() {
   126 
   167 
   127 	void AdjustActivityByTowns();
   168 	void AdjustActivityByTowns();
   128 
   169 
   129 	static const SaveLoad eco_desc[];
   170 	static const SaveLoad eco_desc[];
   130 
   171 
       
   172 	/**
       
   173 	 * Saves and Loads the prices from the savegame
       
   174 	 */
       
   175 	void SaveLoad_PRIC()
       
   176 	{
       
   177 		uint16 dummy[MAX_PRICE];
       
   178 		SlArray(m_prices, MAX_PRICE, SLE_INT32);
       
   179 		SlArray(dummy, MAX_PRICE, SLE_UINT16);
       
   180 	}
       
   181 
       
   182 	int32 GetPrice(Price operation, TileIndex tile = INVALID_TILE, bool release = false) const;
       
   183 
       
   184 	/**
       
   185 	 * Manually sets the price of an operation, used while loading games
       
   186 	 * @param operation The operation which to set the price for
       
   187 	 * @param value     The new price of the operation
       
   188 	 */
       
   189 	void SetPrice(int operation, int32 value)
       
   190 	{
       
   191 		assert(operation < MAX_PRICE);
       
   192 		DEBUG(eco, 4, "Setting price of operation %d to %f", (int)operation, (double) value);
       
   193 		m_prices[operation] = value;
       
   194 	}
       
   195 
   131 private:
   196 private:
   132 	/**
   197 	/**
   133 	 * Computes the modification of economic growth by cyclic events
   198 	 * Computes the modification of economic growth by cyclic events
   134 	 * @return The growth modification
   199 	 * @return The growth modification
   135 	 */
   200 	 */