src/economy_new.cpp
author celestar
Sun, 01 Apr 2007 09:38:43 +0000
branchgamebalance
changeset 9905 91eca6fdee8d
parent 9903 dc85aaa556ae
permissions -rw-r--r--
(svn r9539) [gamebalance] -Add: Don't take real estate costs into account on the lowest difficulty level
9881
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     1
/* $Id$ */
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     2
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     3
/** @file */
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     4
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     5
#include "economy_new.h"
9888
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
     6
#include "town.h"
9881
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     7
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     8
/** The global economy */
fbb3eab0e186 (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.
celestar
parents:
diff changeset
     9
CEconomy *_eco;
fbb3eab0e186 (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.
celestar
parents:
diff changeset
    10
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    11
/** Base prices used at game startup, reference year 1800 */
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    12
static const int32 price_base[CEconomy::MAX_PRICE] = {
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    13
	    100, ///< station_value
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    14
	    100, ///< build_rail
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    15
	     95, ///< build_road
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    16
	     65, ///< build_signals
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    17
	    275, ///< build_bridge
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    18
	    600, ///< build_train_depot
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    19
	    500, ///< build_road_depot
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    20
	    700, ///< build_ship_depot
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    21
	    450, ///< build_tunnel
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    22
	    200, ///< train_station_track
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    23
	    180, ///< train_station_length
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    24
	    600, ///< build_airport
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    25
	    200, ///< build_bus_station
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    26
	    200, ///< build_truck_station
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    27
	    350, ///< build_dock
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    28
	 400000, ///< build_railvehicle
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    29
	   2000, ///< build_railwagon
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    30
	 700000, ///< aircraft_base
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    31
	  14000, ///< roadveh_base
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    32
	  65000, ///< ship_base
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    33
	     20, ///< build_trees
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    34
	    250, ///< terraform
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    35
	     20, ///< clear_1
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    36
	     40, ///< purchase_land
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    37
	    200, ///< clear_2
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    38
	    500, ///< clear_3
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    39
	     20, ///< remove_trees
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    40
	    -70, ///< remove_rail
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    41
	     10, ///< remove_signals
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    42
	     50, ///< clear_bridge
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    43
	     80, ///< remove_train_depot
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    44
	     80, ///< remove_road_depot
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    45
	     90, ///< remove_ship_depot
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    46
	     30, ///< clear_tunnel
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    47
	  10000, ///< clear_water
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    48
	     50, ///< remove_rail_station
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    49
	     30, ///< remove_airport
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    50
	     50, ///< remove_bus_station
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    51
	     50, ///< remove_truck_station
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    52
	     55, ///< remove_dock
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    53
	   1600, ///< remove_house
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    54
	     40, ///< remove_road
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    55
	   5600, ///< running_rail[0] railroad
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    56
	   5200, ///< running_rail[1] monorail
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    57
	   4800, ///< running_rail[2] maglev
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    58
	   9600, ///< aircraft_running
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    59
	   1600, ///< roadveh_running
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    60
	   5600, ///< ship_running
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    61
	1000000, ///< build_industry
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    62
};
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    63
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    64
/**
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    65
 * Starts the economy. This sets the basic growth by the difficulty level and adjust the current
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    66
 * EAL by the year of the game. We also set the economic cycles and initialize the prices here
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    67
 * @warning This should be run once per game only
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    68
 */
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    69
CEconomy::CEconomy()
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    70
{
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    71
	/* Set basic growth */
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    72
	FixedT<int32, 16> growth(_opt.diff.economic_growth, 2);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    73
	m_basic_growth = (growth + 1) / 100 + 1;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    74
	DEBUG(eco, 3, "Starting a new economy with a basic growth factor of %.3f in the year %d", (double)m_basic_growth, _cur_year);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    75
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    76
	/* Set up the economic cycles */
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    77
	m_long_term_cycle   = RandomRange(15) + 45;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    78
	m_short_term_cycle  = RandomRange( 4) +  6;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    79
	m_long_term_ampl    = RandomRange( 5) + 10;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    80
	m_short_term_ampl   = RandomRange(10) + 15;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    81
	m_long_term_ampl   /= 1000;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    82
	m_short_term_ampl  /= 1000;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    83
	DEBUG(eco, 4, "Adjusting economic cycles to %d and %d years", m_long_term_cycle, m_short_term_cycle);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    84
	DEBUG(eco, 4, "Adjusting economic cycles to %f and %f (amplitude)", (double)m_long_term_ampl, (double)m_short_term_ampl);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    85
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    86
	m_activity_level = 1;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    87
	m_activity_level = pow(m_basic_growth, _cur_year - 1820);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    88
	DEBUG(eco, 4, "Adjusting basic EAL for current year (offset %d) to %.3f", _cur_year - 1820, (double)m_activity_level);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    89
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    90
	/* Initalize prices */
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    91
	for (int i = 0; i < MAX_PRICE; i++) m_prices[i] = price_base[i];
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
    92
}
9881
fbb3eab0e186 (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.
celestar
parents:
diff changeset
    93
/**
9888
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
    94
 * Adjust the global activity level by the cumulative activity level of all towns.
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
    95
 * This is to iron out the difference between the sum of all economic activites of
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
    96
 * all towns and the the product of the economic activity per capita times the
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
    97
 * population of the map.
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
    98
 */
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
    99
void CEconomy::AdjustActivityByTowns()
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   100
{
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   101
	Town *t;
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   102
	FixedT<int64, 16> total_activity = 0;
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   103
	FixedT<int64, 16> old_activity = m_activity_level;
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   104
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   105
	FOR_ALL_TOWNS(t) {
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   106
		total_activity += (t->GetActivity() * t->population * m_activity_level);
9889
cfd2278f9099 (svn r9165) [gamebalance] -Add: Towns now have different levels of wealth. Alas, it doesn't have any influence either up to now
celestar
parents: 9888
diff changeset
   107
		DEBUG(eco, 6, "Obtained EAL of %f", (double)t->GetActivity());
9888
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   108
	}
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   109
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   110
	DEBUG(eco, 5, "Global EAL is             %f", (double)m_activity_level * GetWorldPopulation());
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   111
	DEBUG(eco, 5, "Total EAL of all towns is %f", (double)total_activity);
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   112
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   113
	m_activity_level = total_activity / GetWorldPopulation();
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   114
	DEBUG(eco, 4, "Adjusting global EAL to %f (ratio %f)", (double)m_activity_level, (double)(m_activity_level/old_activity));
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   115
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   116
	FOR_ALL_TOWNS(t) t->SetActivity(t->GetActivity() * old_activity / m_activity_level);
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   117
}
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   118
7cf72895ca8c (svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
celestar
parents: 9881
diff changeset
   119
/**
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   120
 * Obtains the costs that a certain user operation at a tile would generate.
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   121
 * This function takes into account that cost that arise from obtaining ownership
9905
91eca6fdee8d (svn r9539) [gamebalance] -Add: Don't take real estate costs into account on the lowest difficulty level
celestar
parents: 9903
diff changeset
   122
 * of the tile in question. Note that these costs are not accounted for in the
91eca6fdee8d (svn r9539) [gamebalance] -Add: Don't take real estate costs into account on the lowest difficulty level
celestar
parents: 9903
diff changeset
   123
 * very simple difficulty levels.
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   124
 * @warning         This function needs to be called BEFORE the tile actions
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   125
 *                  are performed. Otherwise you'll get an assertion on the command
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   126
 *                  because the computed prices for the test and the exec run are
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   127
 *                  different
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   128
 * @todo            Implement inflation
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   129
 * @todo            Make this work with "overbuilding" owned land
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   130
 * @todo            Implement multipliers (for newgrf)
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   131
 * @param operation The operation that is to be performed on the tile
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   132
 * @param tile      The tile on which we want to operate, if omitted
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   133
 *                  no change of ownership is assumed.
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   134
 * @param release   Set to true when the owner releases ownership of tile
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   135
 * @return          The cost (positive) or income (negative) for the operation
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   136
 */
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   137
int32 CEconomy::GetPrice(Price operation, TileIndex tile, bool release) const
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   138
{
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   139
	int32 cost = m_prices[operation];
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   140
9905
91eca6fdee8d (svn r9539) [gamebalance] -Add: Don't take real estate costs into account on the lowest difficulty level
celestar
parents: 9903
diff changeset
   141
	if (tile == INVALID_TILE || _opt.diff.economic_model == 0) return cost;
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   142
	if (release) cost -= Town::GetTilePrice(tile);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   143
	else if (_current_player < MAX_PLAYERS && _current_player != GetTileOwner(tile)) cost += Town::GetTilePrice(tile);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   144
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   145
	return cost;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   146
}
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   147
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   148
/**
9901
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   149
 * Descriptor for the new economy within the savegame
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   150
 */
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   151
/* static */
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   152
const SaveLoad CEconomy::eco_desc[] = {
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   153
	SLE_VAR(CEconomy, m_activity_level,   SLE_INT64),
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   154
	SLE_VAR(CEconomy, m_basic_growth,     SLE_INT32),
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   155
	SLE_VAR(CEconomy, m_long_term_cycle,  SLE_INT8),
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   156
	SLE_VAR(CEconomy, m_short_term_cycle, SLE_INT8),
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   157
	SLE_VAR(CEconomy, m_long_term_ampl,   SLE_INT32),
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   158
	SLE_VAR(CEconomy, m_short_term_ampl,  SLE_INT32),
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9901
diff changeset
   159
	SLE_ARR(CEconomy, m_prices,           SLE_INT32, MAX_PRICE),
9901
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   160
	SLE_END()
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   161
};
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   162
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   163
/**
9881
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   164
 * Starts a new economy. As there can always be only one economy in place,
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   165
 * deletes the one that is currently active
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   166
 */
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   167
void InitializeEconomy()
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   168
{
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   169
	delete _eco;
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   170
	_eco = new CEconomy;
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   171
	assert(_eco != NULL);
fbb3eab0e186 (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.
celestar
parents:
diff changeset
   172
}
9901
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9889
diff changeset
   173