From c8dfa8fc8973fff342c53347af87f0bf08e842db Mon Sep 17 00:00:00 2001 From: Vegapnk Date: Mon, 24 Apr 2023 16:42:00 +0200 Subject: [PATCH] Rework of InsectIncubator --- CHANGELOG.md | 3 +- Common/Defs/GeneDefs/GeneDefs_Hive.xml | 3 +- .../Genes/Hive/Genes/Gene_InsectIncubator.cs | 53 +++++++++++++++++++ Source/Rjw-Genes.csproj | 3 +- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Source/Genes/Hive/Genes/Gene_InsectIncubator.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index d43ea61..c533b3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ **Changes:** - Cocoon Weaver Gene -- Spawn Spelopede Gene (Can re changed to spawn Megascarabs or other insects) +- Spawn Spelopede Gene (Can be changed to spawn Megascarabs or other insects via xml) - Queens & Caste Logic (see below) +- Addition to InsectIncubator: Now fertilizes eggs once placed inside a host, and breeds out eggs twice as fast. **Internal:** diff --git a/Common/Defs/GeneDefs/GeneDefs_Hive.xml b/Common/Defs/GeneDefs/GeneDefs_Hive.xml index e908798..84b15ff 100644 --- a/Common/Defs/GeneDefs/GeneDefs_Hive.xml +++ b/Common/Defs/GeneDefs/GeneDefs_Hive.xml @@ -169,7 +169,8 @@ rjw_genes_insectincubator - + + RJW_Genes.Gene_InsectIncubator Pawns with this gene are able to host more insect eggs, hatch them faster and fertilize any inserted egg. Genes/Icons/More_Egg_Space 52 diff --git a/Source/Genes/Hive/Genes/Gene_InsectIncubator.cs b/Source/Genes/Hive/Genes/Gene_InsectIncubator.cs new file mode 100644 index 0000000..d102a8a --- /dev/null +++ b/Source/Genes/Hive/Genes/Gene_InsectIncubator.cs @@ -0,0 +1,53 @@ +using RimWorld; +using rjw; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace RJW_Genes +{ + + /// + /// This Gene checks for all parasitic Insect-Eggs in a Pawn: + /// 1. Is it fertilized ? => tick it down "extra". + /// 2. Is it not fertilized? => fertilize it with the Incubator as parent + /// + /// Important: The other half of the behavior for the gene (more egg-capacity) is in `Patch_InsectINcubator_PregnancyHelper`. + /// + public class Gene_InsectIncubator : Gene + { + + const int TICK_INTERVAL = 60000 / 48; // 60k = 1 day, we want 0.5h which is 1/48th of 1 day. + + public override void Tick() + { + base.Tick(); + + // Don't check too often, only in the HashTickInterval to safe some computing power + if (this.pawn.IsHashIntervalTick(TICK_INTERVAL) && this.pawn.Map != null) + { + List eggs = new List(); + pawn.health.hediffSet.GetHediffs(ref eggs); + + foreach (Hediff_InsectEgg egg in eggs) + { + // The implanter check checks if the egg is still in an ovipositor. + if (egg.implanter == null || egg.implanter == pawn) + continue; + + if (!egg.fertilized && egg.implanter != null) { + egg.Fertilize(pawn); + if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"Gene_InsectIncubator: fertilized egg {egg} in {pawn}"); + } + else if (egg.fertilized) + { + egg.lastTick += TICK_INTERVAL; + } + } + } + } + } +} diff --git a/Source/Rjw-Genes.csproj b/Source/Rjw-Genes.csproj index f584d19..757a1be 100644 --- a/Source/Rjw-Genes.csproj +++ b/Source/Rjw-Genes.csproj @@ -43,8 +43,9 @@ + - +