(svn r9152) [gamebalance] -Add: Towns now have an economic activity level so that poorer and richer towns can occur on the map
--- a/src/economy_new.cpp Tue Mar 13 21:49:33 2007 +0000
+++ b/src/economy_new.cpp Tue Mar 13 22:03:23 2007 +0000
@@ -3,11 +3,38 @@
/** @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, total %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);
+}
+
+/**
* Starts a new economy. As there can always be only one economy in place,
* deletes the one that is currently active
*/
--- a/src/economy_new.h Tue Mar 13 21:49:33 2007 +0000
+++ b/src/economy_new.h Tue Mar 13 22:03:23 2007 +0000
@@ -1,6 +1,9 @@
/* $Id$ */
-/** @file */
+/**
+ * @file economy_new.h
+ * Definition file for the economy of the game.
+ */
#ifndef ECONOMY_NEW_H
#define ECONOMY_NEW_H
@@ -17,6 +20,25 @@
class EconomicObject {
protected:
FixedT<int64, 16> m_activity_level; ///< Economic Activity Level, an indicator for the GDP per capita of the map
+
+public:
+ /**
+ * Destructors for EconomicObjects. It is virtual because at least one of the methods
+ * (or member functions) is virtual; thus a non-virtual destructor will cause a
+ * compiler warning
+ */
+ virtual ~EconomicObject() {}
+
+ /**
+ * Used to set the activity level from outside
+ */
+ virtual void SetActivity() {}
+
+ /**
+ * Obtains the activity level of the object
+ * @return the economic activity
+ */
+ FixedT<int64, 16> GetActivity() const { return m_activity_level; }
};
/**
@@ -87,6 +109,7 @@
*/
void MonthlyLoop()
{
+ AdjustActivityByTowns();
/* Modifications of the global economic activity one-tenth of a percent */
static const int RandomEvents[] = {-1, 1, -2, 2, -5, 5, -10, 10, -12, 12, -15, 15, -20, 20, -25, 25, 32, -32, 50, -50, -100};
/* I didn't use the 19, because it hardly ever is the return of RandomRange for whatever reason */
@@ -97,8 +120,11 @@
m_activity_level *= mod;
DEBUG(eco, 5, "Added a random event with a value of %f, adjusted EAL to %f", (double)mod, (double)m_activity_level);
+
}
+ void AdjustActivityByTowns();
+
private:
/**
* Computes the modification of economic growth by cyclic events
--- a/src/town.h Tue Mar 13 21:49:33 2007 +0000
+++ b/src/town.h Tue Mar 13 22:03:23 2007 +0000
@@ -5,12 +5,13 @@
#include "oldpool.h"
#include "player.h"
+#include "economy_new.h"
enum {
INVALID_TOWN = 0xFFFF,
};
-struct Town {
+struct Town : EconomicObject {
TileIndex xy;
// Current population of people and amount of houses.
@@ -78,6 +79,18 @@
// NOSAVE: UpdateTownRadius updates this given the house count.
uint16 radius[5];
+
+ /**
+ * Sets the economic activity level of a town
+ * @param level The activity level
+ */
+ /* virtual */
+ template <typename T>
+ void SetActivity(T level)
+ {
+ DEBUG(eco, 7, "Setting EAL of town %d [0x%x], to %f", index, xy, (double)level);
+ m_activity_level = level;
+ }
};
uint32 GetWorldPopulation(void);
--- a/src/town_cmd.cpp Tue Mar 13 21:49:33 2007 +0000
+++ b/src/town_cmd.cpp Tue Mar 13 22:03:23 2007 +0000
@@ -962,6 +962,9 @@
t->exclusive_counter = 0;
t->statues = 0;
+ FixedT<int32, 16> activity = 1;
+
+ t->SetActivity(activity);
t->townnametype = SPECSTR_TOWNNAME_START + _opt.town_name;
t->townnameparts = townnameparts;
@@ -1113,6 +1116,7 @@
}
}
+ _eco->AdjustActivityByTowns();
return true;
}