mirror of
				https://gitgud.io/amevarashi/rjw-sexperience-ideology.git
				synced 2024-08-15 00:43:19 +00:00 
			
		
		
		
	Added isBloodRelated filter attribute
This commit is contained in:
		
							parent
							
								
									765e6c0778
								
							
						
					
					
						commit
						7d6f0d043c
					
				
					 8 changed files with 92 additions and 142 deletions
				
			
		| 
						 | 
				
			
			@ -44,24 +44,7 @@
 | 
			
		|||
          <li>
 | 
			
		||||
            <filter>
 | 
			
		||||
              <relations>
 | 
			
		||||
                <hasOneOfRelations>
 | 
			
		||||
                  <li>Parent</li>
 | 
			
		||||
                  <li>Child</li>
 | 
			
		||||
                  <li>Sibling</li>
 | 
			
		||||
                  <li>HalfSibling</li>
 | 
			
		||||
                  <li>Grandparent</li>
 | 
			
		||||
                  <li>Grandchild</li>
 | 
			
		||||
                  <li>NephewOrNiece</li>
 | 
			
		||||
                  <li>UncleOrAunt</li>
 | 
			
		||||
                  <li>GreatGrandparent</li>
 | 
			
		||||
                  <li>GreatGrandchild</li>
 | 
			
		||||
                  <li>GranduncleOrGrandaunt</li>
 | 
			
		||||
                  <li>GrandnephewOrGrandniece</li>
 | 
			
		||||
                  <li>CousinOnceRemoved</li>
 | 
			
		||||
                  <li>SecondCousin</li>
 | 
			
		||||
                  <li>Cousin</li>
 | 
			
		||||
                  <li>Kin</li>
 | 
			
		||||
                </hasOneOfRelations>
 | 
			
		||||
                <isBloodRelated>true</isBloodRelated>
 | 
			
		||||
              </relations>
 | 
			
		||||
            </filter>
 | 
			
		||||
            <historyEventDef>RSI_IncestuosMarriage</historyEventDef>
 | 
			
		||||
| 
						 | 
				
			
			@ -107,24 +90,7 @@
 | 
			
		|||
          <li>
 | 
			
		||||
            <filter>
 | 
			
		||||
              <relations>
 | 
			
		||||
                <hasOneOfRelations>
 | 
			
		||||
                  <li>Parent</li>
 | 
			
		||||
                  <li>Child</li>
 | 
			
		||||
                  <li>Sibling</li>
 | 
			
		||||
                  <li>HalfSibling</li>
 | 
			
		||||
                  <li>Grandparent</li>
 | 
			
		||||
                  <li>Grandchild</li>
 | 
			
		||||
                  <li>NephewOrNiece</li>
 | 
			
		||||
                  <li>UncleOrAunt</li>
 | 
			
		||||
                  <li>GreatGrandparent</li>
 | 
			
		||||
                  <li>GreatGrandchild</li>
 | 
			
		||||
                  <li>GranduncleOrGrandaunt</li>
 | 
			
		||||
                  <li>GrandnephewOrGrandniece</li>
 | 
			
		||||
                  <li>CousinOnceRemoved</li>
 | 
			
		||||
                  <li>SecondCousin</li>
 | 
			
		||||
                  <li>Cousin</li>
 | 
			
		||||
                  <li>Kin</li>
 | 
			
		||||
                </hasOneOfRelations>
 | 
			
		||||
                <isBloodRelated>true</isBloodRelated>
 | 
			
		||||
              </relations>
 | 
			
		||||
            </filter>
 | 
			
		||||
            <historyEventDef>RSI_IncestuosSex</historyEventDef>
 | 
			
		||||
| 
						 | 
				
			
			@ -223,24 +189,7 @@
 | 
			
		|||
          <li>
 | 
			
		||||
            <filter>
 | 
			
		||||
              <relations>
 | 
			
		||||
                <hasOneOfRelations>
 | 
			
		||||
                  <li>Parent</li>
 | 
			
		||||
                  <li>Child</li>
 | 
			
		||||
                  <li>Sibling</li>
 | 
			
		||||
                  <li>HalfSibling</li>
 | 
			
		||||
                  <li>Grandparent</li>
 | 
			
		||||
                  <li>Grandchild</li>
 | 
			
		||||
                  <li>NephewOrNiece</li>
 | 
			
		||||
                  <li>UncleOrAunt</li>
 | 
			
		||||
                  <li>GreatGrandparent</li>
 | 
			
		||||
                  <li>GreatGrandchild</li>
 | 
			
		||||
                  <li>GranduncleOrGrandaunt</li>
 | 
			
		||||
                  <li>GrandnephewOrGrandniece</li>
 | 
			
		||||
                  <li>CousinOnceRemoved</li>
 | 
			
		||||
                  <li>SecondCousin</li>
 | 
			
		||||
                  <li>Cousin</li>
 | 
			
		||||
                  <li>Kin</li>
 | 
			
		||||
                </hasOneOfRelations>
 | 
			
		||||
                <isBloodRelated>true</isBloodRelated>
 | 
			
		||||
                <hasNoneOfRelations>
 | 
			
		||||
                  <li>Spouse</li>
 | 
			
		||||
                </hasNoneOfRelations>
 | 
			
		||||
| 
						 | 
				
			
			@ -282,24 +231,7 @@
 | 
			
		|||
          <li>
 | 
			
		||||
            <filter>
 | 
			
		||||
              <relations>
 | 
			
		||||
                <hasOneOfRelations>
 | 
			
		||||
                  <li>Parent</li>
 | 
			
		||||
                  <li>Child</li>
 | 
			
		||||
                  <li>Sibling</li>
 | 
			
		||||
                  <li>HalfSibling</li>
 | 
			
		||||
                  <li>Grandparent</li>
 | 
			
		||||
                  <li>Grandchild</li>
 | 
			
		||||
                  <li>NephewOrNiece</li>
 | 
			
		||||
                  <li>UncleOrAunt</li>
 | 
			
		||||
                  <li>GreatGrandparent</li>
 | 
			
		||||
                  <li>GreatGrandchild</li>
 | 
			
		||||
                  <li>GranduncleOrGrandaunt</li>
 | 
			
		||||
                  <li>GrandnephewOrGrandniece</li>
 | 
			
		||||
                  <li>CousinOnceRemoved</li>
 | 
			
		||||
                  <li>SecondCousin</li>
 | 
			
		||||
                  <li>Cousin</li>
 | 
			
		||||
                  <li>Kin</li>
 | 
			
		||||
                </hasOneOfRelations>
 | 
			
		||||
                <isBloodRelated>true</isBloodRelated>
 | 
			
		||||
                <hasNoneOfRelations>
 | 
			
		||||
                  <li>Spouse</li>
 | 
			
		||||
                </hasNoneOfRelations>
 | 
			
		||||
| 
						 | 
				
			
			@ -336,24 +268,7 @@
 | 
			
		|||
          <li>
 | 
			
		||||
            <filter>
 | 
			
		||||
              <relations>
 | 
			
		||||
                <hasOneOfRelations>
 | 
			
		||||
                  <li>Parent</li>
 | 
			
		||||
                  <li>Child</li>
 | 
			
		||||
                  <li>Sibling</li>
 | 
			
		||||
                  <li>HalfSibling</li>
 | 
			
		||||
                  <li>Grandparent</li>
 | 
			
		||||
                  <li>Grandchild</li>
 | 
			
		||||
                  <li>NephewOrNiece</li>
 | 
			
		||||
                  <li>UncleOrAunt</li>
 | 
			
		||||
                  <li>GreatGrandparent</li>
 | 
			
		||||
                  <li>GreatGrandchild</li>
 | 
			
		||||
                  <li>GranduncleOrGrandaunt</li>
 | 
			
		||||
                  <li>GrandnephewOrGrandniece</li>
 | 
			
		||||
                  <li>CousinOnceRemoved</li>
 | 
			
		||||
                  <li>SecondCousin</li>
 | 
			
		||||
                  <li>Cousin</li>
 | 
			
		||||
                  <li>Kin</li>
 | 
			
		||||
                </hasOneOfRelations>
 | 
			
		||||
                <isBloodRelated>true</isBloodRelated>
 | 
			
		||||
              </relations>
 | 
			
		||||
            </filter>
 | 
			
		||||
            <multiplier>2.0</multiplier>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,27 +1,33 @@
 | 
			
		|||
using RimWorld;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience.Ideology
 | 
			
		||||
namespace RJWSexperience.Ideology.Filters
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Filter to describe how one pawn sees another
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Def loader")]
 | 
			
		||||
	public class RelationFilter
 | 
			
		||||
	{
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public bool? isVeneratedAnimal;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public bool? isAlien;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public bool? isBloodRelated;
 | 
			
		||||
		public List<PawnRelationDef> hasOneOfRelations;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public List<PawnRelationDef> hasNoneOfRelations;
 | 
			
		||||
 | 
			
		||||
		private bool initialized = false;
 | 
			
		||||
		private HashSet<PawnRelationDef> hasOneOfRelationsHashed;
 | 
			
		||||
		private HashSet<PawnRelationDef> hasNoneOfRelationsHashed;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// Check if the pair of pawns fits filter conditions
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		public bool Applies(Pawn pawn, Pawn partner)
 | 
			
		||||
		{
 | 
			
		||||
			// Fail if any single condition fails
 | 
			
		||||
			if (isVeneratedAnimal != null && isVeneratedAnimal != pawn.Ideo.IsVeneratedAnimal(partner))
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -39,11 +45,14 @@ namespace RJWSexperience.Ideology
 | 
			
		|||
			if (!initialized)
 | 
			
		||||
				Initialize();
 | 
			
		||||
 | 
			
		||||
			if (hasNoneOfRelationsHashed == null && hasOneOfRelationsHashed == null)
 | 
			
		||||
			if (hasNoneOfRelationsHashed == null && hasOneOfRelationsHashed == null && isBloodRelated == null)
 | 
			
		||||
				return true;
 | 
			
		||||
 | 
			
		||||
			IEnumerable<PawnRelationDef> relations = pawn.GetRelations(partner);
 | 
			
		||||
 | 
			
		||||
			if (isBloodRelated != null && isBloodRelated != relations.Any(def => def.familyByBloodRelation))
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (hasOneOfRelationsHashed != null)
 | 
			
		||||
			{
 | 
			
		||||
				if (relations.EnumerableNullOrEmpty())
 | 
			
		||||
| 
						 | 
				
			
			@ -2,19 +2,24 @@
 | 
			
		|||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience.Ideology
 | 
			
		||||
namespace RJWSexperience.Ideology.Filters
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Filter to describe one pawn
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Def loader")]
 | 
			
		||||
	public class SinglePawnFilter
 | 
			
		||||
	{
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public bool? isAnimal;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public bool? isSlave;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public bool? isPrisoner;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// Check if pawn fits filter conditions
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		public bool Applies(Pawn pawn)
 | 
			
		||||
		{
 | 
			
		||||
			// Fail if any single condition fails
 | 
			
		||||
			if (isAnimal != null && isAnimal != pawn.IsAnimal())
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										34
									
								
								Source/IdeologyAddon/Filters/TwoPawnFilter.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Source/IdeologyAddon/Filters/TwoPawnFilter.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience.Ideology.Filters
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Filter to describe two pawns and relations between them
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Def loader")]
 | 
			
		||||
	public class TwoPawnFilter
 | 
			
		||||
	{
 | 
			
		||||
		public SinglePawnFilter doer;
 | 
			
		||||
		public SinglePawnFilter partner;
 | 
			
		||||
		public RelationFilter relations;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// Check if the pair of pawns fits filter conditions
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		public bool Applies(Pawn pawn, Pawn partner)
 | 
			
		||||
		{
 | 
			
		||||
			// Fail if any single condition fails
 | 
			
		||||
			if (doer?.Applies(pawn) == false)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (this.partner?.Applies(partner) == false)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (relations?.Applies(pawn, partner) == false)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,16 +1,22 @@
 | 
			
		|||
using RimWorld;
 | 
			
		||||
using RJWSexperience.Ideology.Filters;
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience.Ideology.HistoryEvents
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Type to associate single HistoryEventDef with a TwoPawnFilter
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Def loader")]
 | 
			
		||||
	public class TwoPawnEventRule
 | 
			
		||||
	{
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public HistoryEventDef historyEventDef;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public TwoPawnFilter filter;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// Check if the pair of pawns fits filter conditions
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		public bool Applies(Pawn pawn, Pawn partner) => filter?.Applies(pawn, partner) == true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,13 +59,13 @@
 | 
			
		|||
    <Compile Include="PreceptWorkers\ThoughtWorker_Precept_NonPregnant_Social.cs" />
 | 
			
		||||
    <Compile Include="PreceptWorkers\ThoughtWorker_Precept_Pregnant.cs" />
 | 
			
		||||
    <Compile Include="PreceptWorkers\ThoughtWorker_Precept_Pregnant_Social.cs" />
 | 
			
		||||
    <Compile Include="RelationFilter.cs" />
 | 
			
		||||
    <Compile Include="Filters\RelationFilter.cs" />
 | 
			
		||||
    <Compile Include="RelationHelpers.cs" />
 | 
			
		||||
    <Compile Include="RomanceChanceFactorHelpers.cs" />
 | 
			
		||||
    <Compile Include="RsiHistoryEventDefOf.cs" />
 | 
			
		||||
    <Compile Include="RsiPreceptDefOf.cs" />
 | 
			
		||||
    <Compile Include="TwoPawnFilter.cs" />
 | 
			
		||||
    <Compile Include="SinglePawnFilter.cs" />
 | 
			
		||||
    <Compile Include="Filters\TwoPawnFilter.cs" />
 | 
			
		||||
    <Compile Include="Filters\SinglePawnFilter.cs" />
 | 
			
		||||
    <Compile Include="Precepts\Comp_SelfTookMemoryThought_Gendered.cs" />
 | 
			
		||||
    <Compile Include="Precepts\Comp_KnowsMemoryThought_Gendered.cs" />
 | 
			
		||||
    <Compile Include="HistoryEvents\HistoryEventDefExtensionMethods.cs" />
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,30 +1,41 @@
 | 
			
		|||
using System.Collections.Generic;
 | 
			
		||||
using RJWSexperience.Ideology.Filters;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience.Ideology.Precepts
 | 
			
		||||
{
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Def extension to enable changing SexAppraiser results based on filters
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Def loader")]
 | 
			
		||||
	public class DefExtension_ModifyPreference : DefModExtension
 | 
			
		||||
	{
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public List<Rule> rules;
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// Apply SexAppraiser modifiers from rules with a satisfied filter
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		public void Apply(Pawn pawn, Pawn partner, ref float preference)
 | 
			
		||||
		{
 | 
			
		||||
			foreach (Rule rule in rules)
 | 
			
		||||
			foreach (Rule rule in rules.Where(rule => rule.Applies(pawn, partner)))
 | 
			
		||||
			{
 | 
			
		||||
				if (rule.Applies(pawn, partner))
 | 
			
		||||
					preference *= rule.multiplier;
 | 
			
		||||
				preference *= rule.multiplier;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// Type to associate SexAppraiser result modifier with a TwoPawnFilter
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		public class Rule
 | 
			
		||||
		{
 | 
			
		||||
			[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
			public float multiplier = 1f;
 | 
			
		||||
			[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
			public TwoPawnFilter filter;
 | 
			
		||||
 | 
			
		||||
			/// <summary>
 | 
			
		||||
			/// Check if the pair of pawns fits filter conditions
 | 
			
		||||
			/// </summary>
 | 
			
		||||
			public bool Applies(Pawn pawn, Pawn partner)
 | 
			
		||||
			{
 | 
			
		||||
				if (filter == null)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,30 +0,0 @@
 | 
			
		|||
using rjw;
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJWSexperience.Ideology
 | 
			
		||||
{
 | 
			
		||||
	public class TwoPawnFilter
 | 
			
		||||
	{
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public SinglePawnFilter doer;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public SinglePawnFilter partner;
 | 
			
		||||
		[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
 | 
			
		||||
		public RelationFilter relations;
 | 
			
		||||
 | 
			
		||||
		public bool Applies(Pawn pawn, Pawn partner)
 | 
			
		||||
		{
 | 
			
		||||
			if (doer?.Applies(pawn) == false)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (this.partner?.Applies(partner) == false)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			if (relations?.Applies(pawn, partner) == false)
 | 
			
		||||
				return false;
 | 
			
		||||
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue