I've added a new tool for making content definitions: Statistics. This sounds complicated, and it probably is, but it's not too difficult to understand. The basic idea is that instead of referencing some property of the source or target object, a content creator can instead reference a value that is calculated about the game Universe as a whole. Example statistics include:

* the number of objects in the universe that match a condition, such as how many systems, or how many planets owned by an empire within some distance

* the total population on planets controlled by an empire

* the average trade output on planets in systems with Blue stars

* the largest industry rating on planets within 5 starlane jumps

There are a few other options as well, but in general, the statistics mechanism needs three things:

* A sampling condition: This determines which objects are considered when calculating the statistic.

* A property name: This is calculated for each object that matches the sampling condition. These properties are the same as could could be reference on the source or target objects before, like Population, TargetFarming, StarType, including container references like Planet.PlanetSize.

* A statistic type: This is an operation to perform on the property name values. The options include:

** Number: How many objects match the sampling condition. Note that this can be specified without a property, as no property needs to be evalulated, and if a property is specified, it is ignored.

** Sum: The sum of property values of objects matching the sampling condition.

** Mean: The mean (average = sum / number) property value.

** RMS: The square root of the sum of the property values squared.

** Mode: The most common property value. This is most useful for enumerated types like PlanetSize or StarType. This is the only statistic that can be calculated for those enumerated types, as there is no valid or useful "mean" of the planet types (for example), or "number" that has a planet type value. If no objects match the sampling condition, 0 is returned for int or double values, an empty string is returned, or an INVALID_WHATEVER enumerated type is returned.

** Max: The largest property value.

** Min: The smallest property value.

** Spread: The difference between the largest and smallest property values.

** STDEV: The standard deviation of property values. Returns 0 if there is only one matching object.

** Product: The result of multiplying all the property values together. Returns 1 if there is no matching object.

Unless otherwise specified, if no objects match the sampling condition, 0 is returned.

Other statistic types could be added if needed.

A simple (if implausible) example use of this functionality is an effect that adds to the Trade meter an amount equal to the total population in the universe:

**Code:**

SetTargetTrade Sum Population Planet

"Sum" specifes the statistic to compute on the property values. "Population" is a property name that specifies what property to calculate on each object. "Planet" is a condition specifies what objects to calculate property values on.

Like most content description synatx, there are optional names to these parts, so this could be rewritten:

**Code:**

SetTargetTrade Sum property = Population condition = Planet

with the same result.

Also, for the Number statistic, no property is needed:

**Code:**

SetTargetTrade Number System

which sets target trade equal to the number of systems in the universe.