Tags:
create new tag
, view all tags

Freeciv Pollution Production Overview

See:

Contents

Overview

These are the results of my incomplete efforts to develop formulae for the Pollution Production ("tons" of pollution) in a Freeciv city.

If you don't know that Freeciv is a free and open almost clone of the Civ games by Sid Meiers you should go to the Freeciv website for more information.

I've chosen to use the term Pollution Production to mean the amount of pollution produced in a city. You might also be interested in the probability of pollution on a square within a city or the probability of a global warming event. I don't intend to address those subjects on these pages.

I am putting some of this information on both the Freeciv Wiki and on WikiLearn. The intention is that on the Freeciv Wiki I will provide only summary information but on the WikiLearn Wiki I will provide much more detail, including the data I collected and at least some examples of tests I have run for the more complicated formulae.

I've developed these formulae experimentally rather than by examining the code.

Pollution Calculation in the C Code

JTN pointed me (see http://freeciv.wikia.com/wiki/Talk:Cities#Pollution_Calculation to some of the code relevant to Pollution Production in common/city.c:city_pollution_types(), but it was only enough to tell me that, at least in simple cases, when Population is a factor in Pollution Production (before you build a Mass Transit in a given city), and before a clean power plant can be built, each unit of Population (i.e., each citizen in a city) counts for 1/4 as much as a unit of Production (i.e., Shields).

The Code

from city.c, rev. 2.1.6, iiuc:

/**************************************************************************
  Calculate the pollution from production and population in the city.
**************************************************************************/
int city_pollution_types(const struct city *pcity, int shield_total,
          int *pollu_prod, int *pollu_pop, int *pollu_mod)
{
  struct player *pplayer = city_owner(pcity);
  int prod, pop, mod;

  /* Add one one pollution per shield, multipled by the bonus. */
  prod = 100 + get_city_bonus(pcity, EFT_POLLU_PROD_PCT);
  prod = shield_total * MAX(prod, 0) / 100;

  /* Add one 1/4 pollution per citizen per tech, multiplied by the bonus. */
  pop = 100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT);
  pop = (pcity->size
    * num_known_tech_with_flag(pplayer, TF_POPULATION_POLLUTION_INC)
    * MAX(pop, 0)) / (4 * 100);

  /* Then there is base pollution (usually a negative number). */
  mod = game.info.base_pollution;

  if (pollu_prod) {
    *pollu_prod = prod;
  }
  if (pollu_pop) {
    *pollu_pop = pop;
  }
  if (pollu_mod) {
    *pollu_mod = mod;
  }
  return MAX(prod + pop + mod, 0);
}

A Simple Example

Here is the formula for Pollution Production in a city with no Factory, before the development of the Automobile or the technology to build a clean power plant (Hydroelectric or Nuclear power plant) or the Hoover Dam wonder:

int Pol = max(0, (Prod -20 + (Pop div 4)))

where: Prod and Pop are integers, and the expression (Prod + (Pop div 4) - 20) can be done in integer arithmetic. The final result (Pol) is an integer.

A More Complex Example

Here is the formula for Pollution Production in a city with a Factory, after the development of the Automobile, Mass Production (but without a Mass Transit in the city), before the development of Plastics, and with a clean power plant:

int Pol = max(0, (floor(0.75 * Prod -19.7525) + 3 * (Pop div 4) + max(0, ((Pop mod 4) -1)))))

where: Prod and Pop are integers, but the expression (0.75 * Prod -19.7525) must be done in real arithmetic accurate to at least 4 decimal places. The final result (Pol) is an integer.

Comment about the Complexity of the Formulae

<this needs a rewrite> I suspect that the developer(s) did not set out to develop such a complicated / convoluted formula, and I suspect that you won't find anything in the code in that form. Instead, I think they set out to develop computer algorithms that yielded a monotonically increasing quantity of Pollution Production with increases in city Shield production, city Population, city improvements, and available technology. When I tried to create a simple formula to duplicate those calculations, the formulae on this page were the result.

Difficulty in Collecting the Data

I've tested these and I believe they work. But it has been a pain, for a few reasons:

  • data collection has been tough--initially I collected data during a game and later found many discrepancies, either because of errors I made, or because, for example, I didn't initially realize pollution production changed based on certain events, and thus mixed data from before and after those events leading to data that was worthless

  • <darn> (my way of saying I forgot the point I was going to make here--it will come back to me)

If You Find an Error

If you think you've found an error in the formulae, please try to pinpoint whether the error is in the data I've collected and the preconditions (recorded in these pages) or in the conversion of that data to a formula. I have (well, I will, put the data I've collected on other pages).

So far, all of the data I've collected has been while playing under the Freeciv "default" ruleset, rather than under the Civ1 or Civ2 rulesets. I don't know if I'll ever bother to try to collect data and develop formulae for those rulesets. I have a sneaking suspicion though that it may not change--the formulae (and presumably, the computer calculations that achieve these results) are so complicated in some cases, it's hard to believe that anybody has gone to the trouble to create something different. But, what do I know.

Factors considered in the Pollution Calculation

Obviously, (Shield) Production affects pollution, and thus city improvements that affect production are relevant:

  • Factory
  • Mfg. Plant
  • power plant

City improvements that can reduce pollution are obviously relevant, like:

  • clean power plants (i.e., Hydroelectric, Nuclear, and the Hoover Dam wonder)
  • Mass Transit
  • Recycling Center

City population affects pollution.

Technologies affect pollution, both indirectly as they allow various city improvements (like Factory, Mass Transit, etc.), and more directly in the case of the Automobile, Mass Production, and Plastics which change some of the parameters of the pollution production.

Mass Production, unless I did something wrong, my data seems to show that the pollution rate changes when Mass Production is developed, just like it is changed by the Automobile and Plastics. I hadn't seen anything in the documentation about this, and thus am at least a little uncertain--maybe I collected some wrong data. In the one game I played to check this data (after several other games collecting bad data), Mass Production was developed in the turn after the Automobile was developed, and I found changes on both turns. I may have to play another game, or get confirmation from someone else to be sure of what I saw.

Organization of the Formulae and Data

The pollution calculation depends on so many factors, it's been hard for me to develop a scheme to name or classify the various scenarios. This is another attempt.

First of all, as I've mentioned somewhere, I've only collected data for the default ruleset, not the Civ1 or Civ2 rulesets--and think that maybe it won't change in those other rulesets. Nevertheless, I want to include a place in the naming convention to denote this data as being for the default rule set. Then maybe I can use a scheme based on typical progress through the game, even though there are some exceptions to this.

My typical course of development is as follows:

  • before Factory (Industrialization)
  • Factory
  • Factory with a "dirty" power plant
  • Factory with a clean power plant
  • after Automobile
  • after Mass Production
  • Mass Transit (in a city)
  • Recycling Center
  • Mfg. Plant (Robotics)
  • after Plastics

Obviously, there are other relevant categories--even after Plastics are developed, there will be (more recently founded) cities that don't have the full complement of relevant city improvements (i.e., Factory, power plant, Mfg. Plant, Mass Transit, and Recycling Center).

The Formulae, Preconditions, and Links to Pages with the Data

<later>

%SECTION{summary}%

Contributors

  • () RandyKramer - 2010-04-16
  • If you edit this page: add your name here; move this to the next line; and if you've used a comment marker (your initials in parenthesis), include it before your WikiName.

Revision Comment

%SECTION{last_revision}%
  • %DATE% —

Page Ratings

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2010-04-18 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look