
# Note on overwriting: the economic plans (unlike most other database objects) are additive in their overwriting, a bit like on_actions.
# This means that if you have multiple instances of e.g. "basic_economy_plan", the game will mash both entries into one.
# In practice, this means that:
# - you can add another "basic_economy_plan" with just a subplan entry, and it will add that subplan entry to the object
# - if you add a subplan entry that has the same name as an existing one, it will overwrite the existing one instead
# - if you add information that is not a subplan entry (e.g. simply "income = { }", it will usually overwrite it, depending on what exactly it is.
# To do a full overwrite of an economic plan, you should overwrite the file rather than the entry.

# How the AI picks a plan, once a month:
# - it discards every plan whose potential trigger fails
# - of the rest it discards every plan it has already fulfilled
# - of the rest it takes the one with the highest ai_weight
# - if it has fulfilled all of them it keeps the one with the lowest ai_weight, so an empire that has
#   outgrown the whole list still has income targets to build towards
# So ai_weight orders the tiers: the highest weight is the plan an empire starts on and the lowest
# weight is the plan it ends on.

# A plan is fulfilled when last month's income covers every resource in its income goal. Income is
# the only thing that decides a tier: pops, focus and naval_cap steer construction but never hold a
# plan open, because an empire can be stuck below any of them for reasons no amount of building
# fixes. Scaling subplans are left out of the goal too, because they grow without bound and no
# empire could ever finish a plan that counted them.
# To gate a tier on something other than income, put the condition in the next plan's potential.

# The two subplan flags are independent:
#
#                        | blocks the plan from being fulfilled | switches off scaling while unmet
#   ---------------------+--------------------------------------+---------------------------------
#   (no flag)            | yes                                  | yes
#   optional = yes       | yes                                  | no
#   scaling = yes        | no                                   | it is the thing being scaled
#   optional + scaling   | no                                   | no
#
# Use no flag for a target the AI must reach before it moves on, and that should hold scaling back
# until it is reached. Use optional for a gate that must be reached but should not stop the rest of
# the plan from scaling in the meantime, for example a strategic resource the empire may not have
# access to yet. Use optional together with scaling for a pure stretch goal that never holds the
# plan open.

# One catch on optional together with scaling: an income goal on it is added once for each pass of
# the scaling loop that the plain scaling subplans drive, not once for its own growth. So while the
# forecast does not yet cover the rest of the plan, which is most of the time an empire holds that
# plan, the loop makes no pass and the goal is zero. Once the forecast does cover it, the goal is
# added once per pass, which comes to a single time when the plain scaling subplans add nothing,
# either because the plan holds none or because each of them is already capped out.
# For a goal that must apply whatever the empire is behind on, use focus instead. A focus applies
# from every subplan whose potential passes, whatever its flags, and it never holds a plan open.

# Example AI Economic Plan

#example_plan = {
#	ai_weight = { # ai weighting of plan, scope is country. Highest weight wins.
#		weight = 1
#		# modifiers...
#	}
#
#	potential = { # country scope, plan is not considered at all while this fails
#		always = yes
#	}
#
#	income = { # how much surplus income of resources the AI aims for
#		energy = 50
#		minerals = 200
#		trade = 300
#		food = 100
#		consumer_goods = 10
#		alloys = 100
#
#		physics_research = 200
#		society_research = 200
#		engineering_research = 200
#	}
#
#	focus = { # increased prio until surplus income of rhs value is reached
#		alloys = 20        # never counts towards fulfilling the plan, so it is safe to focus a
#	}                      # resource whose income target is zero or negative
#
#	pops = 500 # number of total pops to aim for, does not count towards fulfilling the plan
#	naval_cap = 500 # empire naval cap to aim for, does not count towards fulfilling the plan
#
#	subplan = {
#		# an entire new plan with its own potential trigger and goals
#		# if the empire fulfills the potential trigger of the subplan
#		# then its goals will be added to the base plan.
#
#		# NOTE: there can be several subplans!
#
#		# NOTE: ai_weight is NOT added from subplans, and set_name is what identifies a subplan
#		# for overwriting, so give every subplan of a plan its own name.
#		set_name = "Example Subplan"
#
#		potential = {
#			always = yes
#		}
#
#		income = {
#			minerals = 50
#		}
#	}
#
#	subplan = {
#		# Once the forecast covers everything else in the plan, the scaling subplans are added
#		# again and again until it no longer does, which raises the target in step with the
#		# economy. Give it a potential to stop it once the resource is high enough.
#		set_name = "Example Scaling Subplan"
#		scaling = yes
#
#		potential = {
#			has_monthly_income = { resource = alloys value < 1500 }
#		}
#
#		income = {
#			alloys = 100
#		}
#	}
#
#	subplan = {
#		# A gate: the AI has to reach this before it moves on to the next plan, but it does not
#		# switch off the scaling subplans above while it is unmet.
#		set_name = "Example Optional Subplan"
#		optional = yes
#
#		income = {
#			exotic_gases = 1
#		}
#	}
#
#	subplan = {
#		# A pure stretch goal. The AI builds towards it but it never holds the plan open. The goal
#		# is added once per pass of the plain scaling loop above, thus it is zero while the empire
#		# is still behind the rest of the plan. Cap it with a potential, as the plain scaling
#		# subplans do, or it keeps growing once that loop runs.
#		set_name = "Example Optional Scaling Subplan"
#		optional = yes
#		scaling = yes
#
#		potential = {
#			has_monthly_income = { resource = unity value < 500 }
#		}
#
#		income = {
#			unity = 50
#		}
#	}
#}
