Adds a feature allowing modders to specify initial relations/goodwill between a faction and one or more other FactionDefs.
Rationale
Currently, relations between all NPC factions either default to neutral or hostile (if set as permanent enemy to everyone).
However, there may be gameplay/lore reasons to specify custom goodwill between two or more NPC factions - for instance, FactionA and FactionB could set as hostile to each other while both being neutral or friendly to the player faction, such that if caravans from both factions show up on the player colony map at the same time, they would immediately attack each other.
This could open up new gameplay possibilities, where player can either choose to side with one of the factions, keep them apart so the player maintains good relations with both rivals, or even taking advantage of their feud to steal dropped resources and downed pawns.
The proposed code works as follows:
Check to see if a faction's VFECore.FactionDefExtension ModExtension (if defined) has a new startingGoodwillByFactionDefs field specified, containing a list of FactionDefs with the corresponding desired initial goodwill range
If the list contains at least one valid FactionDef, it will iterate through all faction relationship pairings, and if there is a matching FactionDef in the list, it would set a random custom initial starting goodwill between the two NPC factions within the allowed range
If the list contains no valid FactionDefs, or if there is no match, the code skips to the next possible faction relationship pairing
Usage
Example 1
While the game is setting up FactionA, if it comes across any factions of the type FactionB, it will set their mutual relations to a random number between -100 and -80 (i.e. hostile).
<FactionDef>
<defName>FactionA</defName>
<!-- Other fields omitted for clarity -->
<modExtensions>
<li Class="VFECore.FactionDefExtension">
<startingGoodwillByFactionDefs>
<FactionB>-100~-80</FactionB>
</startingGoodwillByFactionDefs>
</li>
</modExtensions>
</FactionDef>
Example 2
Both FactionA and FactionB (for some reason) defined goodwill ranges for each other, so the code picks the lowest possible combination of the two different goodwill ranges (i.e. -100 and -70), and sets their mutual relations between the revised range.
<FactionDef>
<defName>FactionA</defName>
<!-- Other fields omitted for clarity -->
<modExtensions>
<li Class="VFECore.FactionDefExtension">
<startingGoodwillByFactionDefs>
<FactionB>-100~-60</FactionB>
</startingGoodwillByFactionDefs>
</li>
</modExtensions>
</FactionDef>
<FactionDef>
<defName>FactionB</defName>
<!-- Other fields omitted for clarity -->
<modExtensions>
<li Class="VFECore.FactionDefExtension">
<startingGoodwillByFactionDefs>
<FactionA>-90~-70</FactionA>
</startingGoodwillByFactionDefs>
</li>
</modExtensions>
</FactionDef>
Example 3
If there is more than one Mousekin Kingdom, it will randomly set relations between each possible pair of Mice Kingdoms to be either neutral or hostile
<FactionDef>
<defName>Mousekin_FactionKingdom</defName>
<!-- Other fields omitted for clarity -->
<modExtensions>
<li Class="VFECore.FactionDefExtension">
<startingGoodwillByFactionDefs>
<Mousekin_FactionKingdom>-20~-20</Mousekin_FactionKingdom>
</startingGoodwillByFactionDefs>
</li>
</modExtensions>
</FactionDef>
Testing
Tested with a local, offline development build of my upcoming Mousekin Race mod, configured such that
The Mousekin Kingdom are enemies with the Independent/Rebel Mousekin Towns
Mousekin Gypsies are friendly to both the Kingdom and the Rebel Town factions, but are slightly friendlier to the Kingdom by design
Mousekin Kingdom have low to neutral positive goodwill with the vanilla Civil Outlander faction (representing initial, non-hostile distrust, between them)
Other combinations with involving both player and third-party race faction mods are possible
Spawning pawns from both the Kingdom and the Rebel NPC factions on the same map will cause them to immediately fight each other
Basic allied/hostile relationship between NPC factions can be observed in the vanilla Faction list, while actual goodwill values can be viewed using Fluffy's Relations Tab mod:
No adverse effects on other factionDefs (or resulting pairings) not listed in startingGoodwillByFactionDefs
Over 15 instances of world generation at game start successfully completed without errors
Additions
FactionDefs
.Rationale
Currently, relations between all NPC factions either default to neutral or hostile (if set as permanent enemy to everyone).
However, there may be gameplay/lore reasons to specify custom goodwill between two or more NPC factions - for instance,
FactionA
andFactionB
could set as hostile to each other while both being neutral or friendly to the player faction, such that if caravans from both factions show up on the player colony map at the same time, they would immediately attack each other.This could open up new gameplay possibilities, where player can either choose to side with one of the factions, keep them apart so the player maintains good relations with both rivals, or even taking advantage of their feud to steal dropped resources and downed pawns.
The proposed code works as follows:
VFECore.FactionDefExtension
ModExtension (if defined) has a newstartingGoodwillByFactionDefs
field specified, containing a list ofFactionDefs
with the corresponding desired initial goodwill rangeFactionDef
, it will iterate through all faction relationship pairings, and if there is a matchingFactionDef
in the list, it would set a random custom initial starting goodwill between the two NPC factions within the allowed rangeFactionDefs
, or if there is no match, the code skips to the next possible faction relationship pairingUsage
Example 1 While the game is setting up
FactionA
, if it comes across any factions of the typeFactionB
, it will set their mutual relations to a random number between -100 and -80 (i.e. hostile).Example 2 Both
FactionA
andFactionB
(for some reason) defined goodwill ranges for each other, so the code picks the lowest possible combination of the two different goodwill ranges (i.e. -100 and -70), and sets their mutual relations between the revised range.Example 3 If there is more than one Mousekin Kingdom, it will randomly set relations between each possible pair of Mice Kingdoms to be either neutral or hostile
Testing
factionDefs
(or resulting pairings) not listed instartingGoodwillByFactionDefs