src/economy_new.cpp
author celestar
Thu, 22 Mar 2007 11:11:36 +0000
branchgamebalance
changeset 9901 a922f277ebfd
parent 9889 cfd2278f9099
child 9903 dc85aaa556ae
permissions -rw-r--r--
(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.
/* $Id$ */

/** @file */

#include "economy_new.h"
#include "town.h"

/** The global economy */
CEconomy *_eco;

/**
 * Adjust the global activity level by the cumulative activity level of all towns.
 * This is to iron out the difference between the sum of all economic activites of
 * all towns and the the product of the economic activity per capita times the
 * population of the map.
 */
void CEconomy::AdjustActivityByTowns()
{
	Town *t;
	FixedT<int64, 16> total_activity = 0;
	FixedT<int64, 16> old_activity = m_activity_level;

	FOR_ALL_TOWNS(t) {
		total_activity += (t->GetActivity() * t->population * m_activity_level);
		DEBUG(eco, 6, "Obtained EAL of %f", (double)t->GetActivity());
	}

	DEBUG(eco, 5, "Global EAL is             %f", (double)m_activity_level * GetWorldPopulation());
	DEBUG(eco, 5, "Total EAL of all towns is %f", (double)total_activity);

	m_activity_level = total_activity / GetWorldPopulation();
	DEBUG(eco, 4, "Adjusting global EAL to %f (ratio %f)", (double)m_activity_level, (double)(m_activity_level/old_activity));

	FOR_ALL_TOWNS(t) t->SetActivity(t->GetActivity() * old_activity / m_activity_level);
}

/**
 * Descriptor for the new economy within the savegame
 */
/* static */
const SaveLoad CEconomy::eco_desc[] = {
	SLE_VAR(CEconomy, m_activity_level,   SLE_INT64),
	SLE_VAR(CEconomy, m_basic_growth,     SLE_INT32),
	SLE_VAR(CEconomy, m_long_term_cycle,  SLE_INT8),
	SLE_VAR(CEconomy, m_short_term_cycle, SLE_INT8),
	SLE_VAR(CEconomy, m_long_term_ampl,   SLE_INT32),
	SLE_VAR(CEconomy, m_short_term_ampl,  SLE_INT32),
	SLE_END()
};

/**
 * 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);
}