Faction Def Extension - AndroidQuazar/VanillaExpandedFramework GitHub Wiki

The FactionDefExtension of Vanilla Expanded Framework provides additional configurable features to faction definitions.

public class FactionDefExtension : DefModExtension
{
  public bool hasCities = true;
  public string settlementGenerationSymbol;
  public string packAnimalTexNameSuffix;
  public PawnKindDef strangerInBlackReplacement;
  private string siegeParameterSet;
  public SiegeParameterSetDef siegeParameterSetDef;
  public List<StartingGoodwillByFaction> startingGoodwillByFactionDefs = new List<StartingGoodwillByFaction>();

  public List<BiomeDef> allowedBiomes = new List<BiomeDef>();
  public List<BiomeDef> disallowedBiomes = new List<BiomeDef>();

  public List<RaidStrategyDef> allowedStrategies = new List<RaidStrategyDef>();
}

How do I use this code?

Add the VFECore.FactionDefExtension Def Extension to the FactionDef you want to customize, and specify optional parameters as desired:

<modExtensions>
	<li Class="VFECore.FactionDefExtension">			
		<!-- Specify optional parameters here -->				
	</li>
</modExtensions>

Setting initial relations between factions

This allows you to set initial goodwill values and relations between your faction and any number of FactionDefs.

Possible use cases include:

  • Faction_Kingdom and Faction_Rebels are mutual enemies, so even if both factions are friendly with the player, they should attack each other if their caravans happen to meet on the player colony map
  • Multiple factions of the same Faction_Republic type are mutual rivals
  • Different starting goodwill for different starting player factions/scenarios; for instance, Faction_CatEmpire is initially friendly with PlayerColony, PlayerTribe and Faction_CatPlayerColony, but extremely hostile towards Faction_MousePlayerColony from another mod

To specify custom initial goodwill by faction type, add a startingGoodwillByFactionDefs node, containing a list of FactionDefs with their corresponding allowed starting goodwill ranges:

<FactionDef>
	<defName>FactionA</defName>
	<!-- Remaining XML nodes and tags omitted for clarity -->
	<modExtensions>
		<li Class="VFECore.FactionDefExtension">			
			<startingGoodwillByFactionDefs>
				<FactionB>-100~-80</FactionB> <!-- Faction A's starting goodwill with Faction B will be between -100 and -80 -->
				<FactionC>-25~25</FactionC> <!-- Faction A's starting goodwill with Faction C will be between -25 and 25 -->
				<FactionD>42~-69</FactionD> <!-- Faction A's starting goodwill with Faction D will be between 42 and 69 -->
			</startingGoodwillByFactionDefs>			
		</li>
	</modExtensions>
</FactionDef>

Upon initial world generation or when a new faction is added to an existing savegame, the game will iterate through every possible pair of relations between FactionA and any other faction, and if the other faction's type matches FactionB, FactionC or FactionD, it will set their starting relations with FactionA to within the specified range allowed for each faction type.

Example 1

In the Mousekin Race mod, the following configuration makes Mousekin_FactionKingdom factions:

  • Neutral or mildly friendly to Mousekin settler and refugee starting players
  • Hostile or neutral to other Mousekin Kingdoms (representing possible alliances or rivalries with other Kingdoms)
  • Hostile to Independent/Rebel Mousekins
  • Friendly to Mousekin Nomads
<FactionDef>
	<defName>Mousekin_FactionKingdom</defName>
	<!-- Remaining XML nodes and tags omitted for clarity -->
	<modExtensions>
		<li Class="VFECore.FactionDefExtension">
			<startingGoodwillByFactionDefs>
				<Mousekin_PlayerFaction_Settlers>10~20</Mousekin_PlayerFaction_Settlers>
				<Mousekin_PlayerFaction_Refugees>10~20</Mousekin_PlayerFaction_Refugees>
				<Mousekin_FactionKingdom>-20~20</Mousekin_FactionKingdom>
				<Mousekin_FactionIndyTown>-100~-80</Mousekin_FactionIndyTown>
				<Mousekin_FactionNomad>30~40</Mousekin_FactionNomad>
			</startingGoodwillByFactionDefs>
		</li>
	</modExtensions>
</FactionDef>

Example 2

If, for some reason, two or more factions both have startingGoodwillByFactionDefs lists with entries that reference each other, the resulting mutual relation will be the worst possible of the specified ranges.

<FactionDef>
	<defName>Faction_Foobar</defName>
	<!-- Remaining XML nodes and tags omitted for clarity -->
	<modExtensions>
		<li Class="VFECore.FactionDefExtension">
			<startingGoodwillByFactionDefs>
				<Faction_Wahoo>-90~-20</Faction_Wahoo>
			</startingGoodwillByFactionDefs>
		</li>
	</modExtensions>
</FactionDef>

<FactionDef>
	<defName>Faction_Wahoo</defName>
	<!-- Remaining XML nodes and tags omitted for clarity -->
	<modExtensions>
		<li Class="VFECore.FactionDefExtension">
			<startingGoodwillByFactionDefs>
				<Faction_Foobar>-75~-65</Faction_Foobar>
			</startingGoodwillByFactionDefs>
		</li>
	</modExtensions>
</FactionDef>

In this case, the final mutual goodwill between the Foobar and the Wahoo factions will be a random value between -90 and -65

Restricting biomes that faction settlements can spawn in

If your faction prefers to spawn its settlements in only some biomes, add an allowedBiomes containing a list of BiomeDefs:

<FactionDef>
	<defName>FactionA</defName>
	<!-- Remaining XML nodes and tags omitted for clarity -->
	<modExtensions>
		<li Class="VFECore.FactionDefExtension">			
			<allowedBiomes>
				<!-- List of allowed BiomeDefs -->
			</allowedBiomes>			
		</li>
	</modExtensions>
</FactionDef>

Conversely, if your faction can spawn in most biomes except for a few that they'd rather avoid, add an disallowedBiomes containing a list of BiomeDefs:

<FactionDef>
	<defName>FactionA</defName>
	<!-- Remaining XML nodes and tags omitted for clarity -->
	<modExtensions>
		<li Class="VFECore.FactionDefExtension">			
			<disallowedBiomes>
				<!-- List of disallowed BiomeDefs -->
			</disallowedBiomes>	
		</li>
	</modExtensions>
</FactionDef>

Example

In the Vanilla Factions Expanded: Vikings mod, the following configuration makes Viking factions prefer Ice Sheets, Sea Ice, Boreal Forests, Cold Bogs and Tundras:

<FactionDef ParentName="HumanFactionBase" Name="VFEV_VikingBase" Abstract="True">
	<!-- Remaining XML nodes and tags omitted for clarity -->
	<modExtensions>
		<li Class="VFECore.FactionDefExtension">			
			<allowedBiomes>
				<li>IceSheet</li>
				<li>SeaIce</li>
				<li>BorealForest</li>
				<li>ColdBog</li>
				<li>Tundra</li>
			</allowedBiomes>	
		</li>
	</modExtensions>
</FactionDef>

Setting authorized raid strategy of factions

In the Vanilla Factions Expanded: Insectoid mod, the following configuration makes Insectoid only use the custom raid strategy (and skip the vanilla ImmediateAttack, ImmediateAttackSapper…):

<FactionDef ParentName="FactionBase">
  <!-- Remaining XML nodes and tags omitted for clarity -->
  <modExtensions>
    <li Class="VFECore.FactionDefExtension">
      <allowedStrategies>
        <li>VFEI_ImmediateAttackInsect</li>
      </allowedStrategies>
    </li>
  </modExtensions>
</FactionDef>

Making a faction not require a leader

In the Reinforced Mechanoids 2 mod, the following configuration makes the ancient remnant faction spawn human-like, but without a faction leader. This will also hide the faction from the call list at the Comms console, as a faction requires an active leader to be called. That is however optional!

	<FactionDef ParentName="FactionBase">
		<modExtensions>
			<li Class="VFECore.FactionDefExtension">
				<shouldHaveLeader>false</shouldHaveLeader>
				<excludeFromCommConsole>true</excludeFromCommConsole>
			</li>
		</modExtensions>
	</FactionDef>

Prevent faction bases from being connected to roads

In the Reinforced Mechanoids 2 mod, the following configuration makes it so the bases of the factions are never connected by a road on the world map:

	<FactionDef ParentName="FactionBase">
		<modExtensions>
			<li Class="VFECore.FactionDefExtension">
				<neverConnectToRoads>true</neverConnectToRoads>
				<minDistanceToOtherSettlements>30</minDistanceToOtherSettlements>
			</li>
		</modExtensions>
	</FactionDef>

<neverConnectToRoads>true</neverConnectToRoads> defines if faction bases should be connected to roads.

<minDistanceToOtherSettlements>30</minDistanceToOtherSettlements> defines the min distance a base of this faction can be spawned from another factions bases. Here it is 30 world tiles.

⚠️ **GitHub.com Fallback** ⚠️