Skip to content

Effective level, affinities vs real level, affinities

dmcbride edited this page Dec 21, 2014 · 1 revision

New APIs for buildings (effective_level and effective_efficiency) and Empire (effective_*_affinity) provide a simpler way to determine the total level or total affinity that creates all effects.

So, the question is: when to use the effective value, and when to use the actual value?

  • When using a value to determine an effect, use the effective value.
  • When using a value to determine costs of changing level, use the real value.

As an example of the former, when determining the hold size of a ship, you should use the effective_level of the trade ministry and the effective_trade_affinity of the empire. The effective_level of the trade ministry will cap the level of the trade min at the empire's tech level + 1, and then add in any bonuses or penalties that we create later. Similarly, the effective_trade_affinity will start with the empire's current trade_affinity and add bonuses and penalties that may be created in the future.

As an example of the latter, when upgrading and downgrading buildings, its actual level should be used for determining costs. Having a bonus to the acting level of a building should not become a penalty in upgrading it, nor should having a lower university lower the amount of waste it produces during a downgrade.

When updating an affinity or building level such that the new value should be used immediately, there are also clear_* methods. The effective methods all cache their values to keep the db impact down, so it's important to clear their caches when the new value is required. Since most access is read-only, this should be pretty rare.