mirror of
				https://github.com/vegapnk/RJW-Genes.git
				synced 2024-08-15 00:23:31 +00:00 
			
		
		
		
	Fallback Logic for non-parent eggs, closes #37
This commit is contained in:
		
							parent
							
								
									7957f633c2
								
							
						
					
					
						commit
						8dc63c9308
					
				
					 2 changed files with 59 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -30,9 +30,10 @@ namespace RJW_Genes
 | 
			
		|||
        /// </summary>
 | 
			
		||||
        /// <param name="pawn">The pawn born, that maybe becomes a hive-xenotype.</param>
 | 
			
		||||
        /// <param name="hasDroneParent">whether there was a drone parent involved</param>
 | 
			
		||||
        public static void ManageHiveBirth(Pawn pawn, bool hasDroneParent = false)
 | 
			
		||||
        public static void ManageHiveBirth(Pawn pawn, bool hasDroneParent = false, XenotypeDef fallbackQueenDef = null, XenotypeDef fallbackDroneDef = null)
 | 
			
		||||
        {
 | 
			
		||||
            XenotypeDef queenDef = TryFindParentQueenXenotype(pawn);
 | 
			
		||||
            if (queenDef == null) queenDef = fallbackQueenDef;
 | 
			
		||||
            HiveOffspringChanceDef hiveOffspringChanceDef = HiveUtility.LookupHiveInheritanceChances(queenDef);
 | 
			
		||||
 | 
			
		||||
            // Case 1: Mother is Queen, Father is something else. Produce Worker.
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +57,7 @@ namespace RJW_Genes
 | 
			
		|||
                else if (roll < hiveOffspringChanceDef.droneChance + hiveOffspringChanceDef.queenChance)
 | 
			
		||||
                {
 | 
			
		||||
                    XenotypeDef droneDef = TryFindParentDroneXenotype(pawn);
 | 
			
		||||
                    if (droneDef == null) droneDef = fallbackDroneDef;
 | 
			
		||||
                    pawn.genes.SetXenotype(droneDef);
 | 
			
		||||
                    if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"{pawn} born as a new drone with xenotype {droneDef.defName} ({(hiveOffspringChanceDef.droneChance + hiveOffspringChanceDef.queenChance) * 100}% chance,rolled {roll}))");
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,9 +23,8 @@ namespace RJW_Genes
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
        [HarmonyPostfix]
 | 
			
		||||
        static void HandleHiveBasedInheritance(ref Thing __result)
 | 
			
		||||
        static void HandleHiveBasedInheritance(ref Thing __result, ref Hediff_InsectEgg __instance)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            // Check: Was the born thing a pawn? 
 | 
			
		||||
            if (__result == null || !(__result is Pawn))
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			@ -35,19 +34,70 @@ namespace RJW_Genes
 | 
			
		|||
 | 
			
		||||
            Pawn pawn = (Pawn)__result;
 | 
			
		||||
 | 
			
		||||
            // Important: Not all pawns have mother/father. Some Pawns are born in Growth-Vats or born from mod. 
 | 
			
		||||
            bool hasQueenParent = HiveBirthLogic.TryFindParentQueenXenotype(pawn) != null;
 | 
			
		||||
            bool hasDroneParent = HiveBirthLogic.TryFindParentDroneXenotype(pawn) != null;
 | 
			
		||||
            XenotypeDef queenDef = HiveBirthLogic.TryFindParentQueenXenotype(pawn) ?? TryFindParentQueenXenotypeFromEgg(__instance);
 | 
			
		||||
            XenotypeDef droneDef = HiveBirthLogic.TryFindParentDroneXenotype(pawn) ?? TryFindParentDroneXenotypeFromEgg(__instance);
 | 
			
		||||
 | 
			
		||||
            bool hasQueenParent = queenDef != null;
 | 
			
		||||
            bool hasDroneParent = droneDef != null;
 | 
			
		||||
 | 
			
		||||
            if (hasQueenParent)
 | 
			
		||||
            {
 | 
			
		||||
                if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"PostFix Hediff_InsectEgg::ProcessHumanLikeInsectEgg - Checking Hive Inheritance because {pawn} has a queen parent.");
 | 
			
		||||
                HiveBirthLogic.ManageHiveBirth(pawn, hasDroneParent);
 | 
			
		||||
                HiveBirthLogic.ManageHiveBirth(pawn, hasDroneParent, fallbackQueenDef: queenDef, fallbackDroneDef: droneDef);
 | 
			
		||||
            } else
 | 
			
		||||
            {
 | 
			
		||||
                if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"Ignoring Postfix Hediff_InsectEgg::ProcessHumanLikeInsectEgg - No Queen Parent - No Action.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Tries to retrieve a queen-xenotype-def from a given egg. 
 | 
			
		||||
        /// Checking priority goes: Implanter > Fertilizer > Null Otherwise. 
 | 
			
		||||
        /// 
 | 
			
		||||
        /// This is meant to be a fallback to the parent-relations which were not present in RJW 5.3.1. 
 | 
			
		||||
        /// Some comments and thoughts are captured in Issue #37. 
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="egg">An Egg for which queens are looked up for</param>
 | 
			
		||||
        /// <returns>The relevant xenotypedef of a queen, or null.</returns>
 | 
			
		||||
        public static XenotypeDef TryFindParentQueenXenotypeFromEgg(Hediff_InsectEgg egg)
 | 
			
		||||
        {
 | 
			
		||||
            XenotypeDef queenDef = null;
 | 
			
		||||
            if (egg == null)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            if (egg.implanter != null)
 | 
			
		||||
                queenDef = HiveUtility.TryGetQueenXenotype(egg.implanter);
 | 
			
		||||
 | 
			
		||||
            if (queenDef == null && egg.father != null)
 | 
			
		||||
                queenDef = HiveUtility.TryGetQueenXenotype(egg.implanter);
 | 
			
		||||
 | 
			
		||||
            return queenDef;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Tries to retrieve a drone-xenotype-def from a given egg. 
 | 
			
		||||
        /// Checking priority goes: Implanter > Fertilizer > Null Otherwise. 
 | 
			
		||||
        /// 
 | 
			
		||||
        /// This is meant to be a fallback to the parent-relations which were not present in RJW 5.3.1. 
 | 
			
		||||
        /// Some comments and thoughts are captured in Issue #37. 
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="egg">An Egg for which drones are looked up for</param>
 | 
			
		||||
        /// <returns>The relevant xenotypedef of a drone, or null.</returns>
 | 
			
		||||
        public static XenotypeDef TryFindParentDroneXenotypeFromEgg(Hediff_InsectEgg egg)
 | 
			
		||||
        {
 | 
			
		||||
            XenotypeDef droneDef = null;
 | 
			
		||||
            if (egg == null)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            if (egg.implanter != null)
 | 
			
		||||
                droneDef = HiveUtility.TryGetQueenXenotype(egg.implanter);
 | 
			
		||||
 | 
			
		||||
            if (droneDef == null && egg.father != null)
 | 
			
		||||
                droneDef = HiveUtility.TryGetQueenXenotype(egg.implanter);
 | 
			
		||||
 | 
			
		||||
            return droneDef;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue