Open main menu

AI modding

Version

Outliner top.png
Please help with verifying or updating older sections of this article. At least some were last verified for version 2.5.

This article is for the PC version of Stellaris only.

Contents

SummaryEdit

Stellaris AI behaviour is determined by attitudes, behaviours and weights. Attitudes describe which actions an AI empire can pursue according to its current opinion level towards another empire, while behaviours describe the AI empire's behaviour in general. Weights are defined for most objects to help the AI determine what to do or build.

AI attitudesEdit

AI attitudes describe how an AI empire would react at certain opinion levels towards another empire, and what actions it may take. Attitude entries consist of a type and a list of allowed behaviours. The type of attitude is normally set to be the same as the name of the entry itself.

StructureEdit

Example:

   neutral = {
       type = neutral
       behaviour = {
           trade = yes
       }
   }

Any number of behaviours may be attached to the behaviour list on each attitude entry. If a behaviour is not listed inside the attitude's behaviour list, it will assume the value of 'no'. Available behaviours are listed in the table below.

Behaviour name Data type Default value ! Example Description
trade Boolean (yes/no) no trade = yes An attitude with trade set to yes will permit an empire to be traded with.
weaken Boolean (yes/no) no weaken = yes An attitude with weaken set to yes will cause an empire to try and weaken another. This does not mean that they will fight.
attack Boolean (yes/no) no attack = yes An attitude with attack set to yes will cause an empire to actively attack another, provided that war goals can be achieved.
vassalize Boolean (yes/no) no vassalize = yes An attitude with vassalize set to yes will cause an empire to attempt vassalization on another. This does not necessarily involve war.
coexist Boolean (yes/no) no coexist = yes An attitude with coexist set to yes will cause the empire to be more accepting of non-aggression pacts.
alliance Boolean (yes/no) no alliance = yes An attitude with alliance set to yes will cause the empire to try and seek an alliance, or accept an alliance offer if it comes their way.

WarningsEdit

Removing attitude entries from attitudes.txt can cause the game to crash to desktop. It is likely that these are accessed in a hard-coded manner by the game.

AI personalitiesEdit

Personalities describe how an AI empire will react to other empires around them. Each personality consists of a behaviour archetype which describes the empire's goal, a list of behaviours which describe the likely actions taken against other empires and pops, and several modifiers which alter other features which require numeric values as inputs.

Personality archetypesEdit

Personality archetypes describe the overall goal of the AI nation. If a personality archetype is not set, then the AI will pursue a balanced goal with no distinct focus.

Personality name Description
honorbound Cares about honor and martial prowess above all else.
capitalist Cares about trade and material profit above all else.
hegemon Cares about the superiority of their own empire above all else.
ideologue Cares about combating opposing ethics above all else.
isolationist Cares about maintaining their isolation from other empires above all else.
federation builder Cares about bringing different species together in a federation above all else.
propagator Cares about the propagation of its species above all else.
purifier Cares about purifying the galaxy of other species above all else.
explorer Cares about exploring the galaxy and making scientific or spiritual discoveries above all else.

BehavioursEdit

Behaviours determine the type of actions that an AI empire may take against other empires. These are set either to yes or no only; there is no current way to weight the AI's emphasis on certain aspects of their interactions. Currently, it is unknown what behaviour the AI will assume for each type of action if it remains unset. These behaviours are listed in the table below:

Behaviour name Description
conqueror Will they conquer planets from other empires?
subjugator Will they vassalise other empires?
liberator Will they liberate conquered empires?
opportunist Are they more likely to attack someone already embroiled in war?
uplifter Will they uplift and enlighten other species?
infiltrator Will they infiltrate primitives?
dominator Will they invade primitives?
slaver Will they enslave pops?
purger Will they purge alien pops?
robot_exploiter Will they use robots for menial labor?
robot_liberator Will they give rights to robots?
migrator Will they want to migrate to other empires?

Example:

   behaviour = {
       conqueror = no
       subjugator = no
       liberator = no
       opportunist = yes
       slaver = no
       uplifter = no
       purger = no
       dominator = no
       infiltrator = no
       robot_exploiter = yes
       robot_liberator = no
       migrator = no
   }

Modifiers:Edit

Modifiers affect specific aspects of interactions that an AI empire may take against other empires. Unlike behaviours, these are numeric and allow for fine-tuning of the AI personality. All modifier values are assumed to be floating-point numbers. These modifiers are listed in the table below:

Modifier name Description
aggressiveness Chance of declaring wars. Multiplier; set this to 1.0 for default AI behaviour. Values between 0 and 1 will result in a less aggressive AI. Values greater than 1 will result in a more aggressive AI. Must be greater than or equal to zero.
trade_willingness Willingness to pursue trade. At 0.0, trade will not be considered; at 1.0, trades will attempt to achieve a total value which is approximately equal for both sides. Greater values will weight the trade towards the other party. Must be greater than or equal to zero.
bravery Affects the chance that they will pick rivals and war targets of similar strength, instead of picking on the weak. Values between 0 and 1 will result in an AI which prefers to target weakened enemies. Values greater than 1 will result in an AI that may declare war against an equal or stronger enemy. Must be greater than or equal to zero.
military_spending Affects mineral and energy budget that goes to navies and armies. Values between 0 and 1 will result in an AI which spends less than normal on its military. Values greater than 1 will result in an AI that spends more than normal on its military. Must be greater than or equal to zero.
colony_spending Affects mineral and energy budget that goes to new colonies. Values between 0 and 1 will result in an AI which spends less than normal on colonising new worlds. Values greater than 1 will result in an AI that spends more than normal on colonising new worlds. Must be greater than or equal to zero.
alliance_acceptance Affects the likelihood of an AI accepting alliance offers from other nations. Value is additive to the base reluctance values.
federation_acceptance Affects the likelihood of an AI accepting federation offers from other nations. Value is additive to the base reluctance values.
threat_modifier Affects the severity of opinion modifiers generated by wars near an AI nation, or against the AI nation. Values between 0 and 1 will result in an AI that doesn't care too much about threat. Values higher than 1 will cause threat to be generated faster than normal.
friction_modifier Affects the severity of opinion modifiers generated by colonies or frontier outposts near an AI nation's borders. Values between 0 and 1 will result in an AI that cares less about contested borders and territorial pressure. Values higher than 1 will result in an AI that cares more about contested borders and territorial pressure.

Example:

   aggressiveness = 0.5
   trade_willingness = 0.5
   bravery = 0.75
   military_spending = 1.2
   colony_spending = 1.0
   alliance_acceptance = -50
   federation_acceptance = -50
   threat_modifier = 0.75
   friction_modifier = 2.0

Requirements and weightingEdit

Personality types for randomly-generated AI nations can be restricted by adding additional conditions. Standard conditions may be inserted to restrict personalities from being attached to certain empire types, or to weight personalities more heavily on others.

To allow a personality to be attached, every condition in the field 'allow' must evaluate to true.

Example:

   allow = {
        NOT { is_country_type = fallen_empire }         ## Does not permit this personality to be attached to a fallen empire.
        NOT { has_ethic = ethic_pacifist }              ## Does not permit this personality to be attached to a pacifist empire.
   }

Weighting is described in a similar manner. The field 'weight_modifier' must contain a numeric weight value greater than zero, and a list of weight modifiers containing a modifying factor and a list of conditions which must all evaluate to true for the modifying factor to apply.

Example:

   weight_modifier = {
       weight = 10	
       modifier = {
           factor = -2
           NOT = {
               has_ethic = "ethic_pacifist"
               has_ethic = "ethic_fanatic_pacifist"		
           }
       }
   }

ExamplesEdit

Below are examples of complete AI personalities taken from the base game files, with comments to illustrate the effects that each line has.

Honorbound warriorsEdit

    honorbound_warriors = {
	aggressiveness = 1.75
	trade_willingness = 0.7
	bravery = 1.5
	combat_bravery = 2.0	# rarely ever retreat in battle

	military_spending = 1.2
	colony_spending = 0.9

	federation_acceptance = -10
	nap_acceptance = -50
	defensive_pact_acceptance = 20
	migration_pact_acceptance = 0

	advanced_start_chance = 75

	weapon_preferences = weapon_type_strike_craft
	armor_ratio = 0.4
	shields_ratio = 0.4
	hull_ratio = 0.2

	threat_modifier = 0.75
	threat_others_modifier = 0.5
	friction_modifier = 1.0
	claims_modifier = 2.0

	behaviour = {
		conqueror = yes
		subjugator = yes
		liberator = no
		opportunist = no
		slaver = no
		caste_system = no
		uplifter = no
		purger = no
		displacer = no
		infiltrator = no
		dominator = yes
		robot_exploiter = no
		robot_liberator = no
		propagator = no
		multispecies = yes
		crisis_fighter = yes
	}

	allow = {
		is_country_type = default
		OR = {
			AND = {
				has_ethic = "ethic_fanatic_militarist"
				OR = {
					has_ethic = "ethic_spiritualist"
					has_ethic = "ethic_egalitarian"
					has_ethic = "ethic_xenophile"
				}			
			}
			AND = {
				has_ethic = "ethic_fanatic_xenophile"
				has_ethic = "ethic_militarist"
			}
		}

	}

	weight_modifier = {
		weight = 50
	}
 }

AI WeightsEdit

Most objects or actions scripted into the game support an ai_weight = { } section to help the AI determine the best course of action. Most AI improvement mods change these AI weights so the AI will make different choices than they do in vanilla. Many modders will neglect to write these sections into their mods, leaving the AI unable to use the new content effectively. In general, the AI will choose what to do based on attitudes and behaviors, but will decide the specific one from AI weights.

For example, the AI will choose to develop a planet. They must decide which district or building it is going to build. It will evaluate all the ai_weight sections in each available building and district, modify these weights based on their attitudes and behaviors, then build whichever has the highest weight, with some variability and randomization built-in to reduce determinism. The more thorough and effective the ai_weight sections are written, the better the AI performs and makes intelligent decisions in game.

For example, if you mod in new traits that will affect the performance of a particular job, it won't be used effectively unless the job's weight section is updated to include a modifier = { factor = x has_trait = my_new_trait } for the new trait. Without this, a pop with a new trait that increases mineral output, for example, may end up as a farmer, while a pop with no bonus to mineral production works as a miner. Your new building may never be built by the AI.

If you intentionally don't want something to be used by the AI, set the ai_weight to 0. ai_weight = { weight = 0 }. Or, if you don't want the AI to use something in certain circumstances, in the ai_weight section use a modifier section with factor = 0 line. For example, modifier = { factor = 0 has_trait = my_new_trait } in the weight section of the farmer job, would stop any pops with my_new_trait from working as a farmer.

The AI will only make good decisions if we give it the information to make good decisions.

ReferencesEdit