From 51b988f18c2c0959504e992c77fb5cfeab914281 Mon Sep 17 00:00:00 2001 From: Vegapnk Date: Thu, 30 May 2024 09:40:57 +0200 Subject: [PATCH] Rescued Cocoonweaver, FerventOvipositor and InsectIncubator into Breeding Genes --- CHANGELOG.md | 1 + .../Defs/AbilityDefs/Ability_CocoonWeaver.xml | 34 ++++++++ Common/Defs/Effects/cocoonweave.xml | 37 +++++++++ Common/Defs/GeneDefs/GeneDefs_Breeding.xml | 67 ++++++++++----- Common/Defs/GeneDefs/GeneDefs_SexSpecial.xml | 17 ++++ .../Genes/Breeding/Gene_FerventOvipositor.cs | 42 ++++++++++ Source/Genes/Breeding/Gene_InsectIncubator.cs | 67 +++++++++++++++ .../CompAbilityEffect_CocoonWeaver.cs | 81 +++++++++++++++++++ .../CompProperties_AbilityCocoonWeaver.cs | 18 +++++ Source/Rjw-Genes.csproj | 4 + 10 files changed, 348 insertions(+), 20 deletions(-) create mode 100644 Common/Defs/AbilityDefs/Ability_CocoonWeaver.xml create mode 100644 Common/Defs/Effects/cocoonweave.xml create mode 100644 Source/Genes/Breeding/Gene_FerventOvipositor.cs create mode 100644 Source/Genes/Breeding/Gene_InsectIncubator.cs create mode 100644 Source/Genes/Special/Abilities/CompAbilityEffect_CocoonWeaver.cs create mode 100644 Source/Genes/Special/Abilities/CompProperties_AbilityCocoonWeaver.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index da18d06..fe75024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Slider for Evergrowth Tick-Speed, thanks to @jaaldabaoth - Resizing Age for resizing Genes can be set in Settings @jaaldabaoth - **Licentia related genes are only placeholders**, as Licentia is not 1.5 yet +- InsectIncubator only does self-fertilization now, but does not increase storage capacities for eggs anymore **Fixes:** diff --git a/Common/Defs/AbilityDefs/Ability_CocoonWeaver.xml b/Common/Defs/AbilityDefs/Ability_CocoonWeaver.xml new file mode 100644 index 0000000..2a1577a --- /dev/null +++ b/Common/Defs/AbilityDefs/Ability_CocoonWeaver.xml @@ -0,0 +1,34 @@ + + + + rjw_genes_ability_cocoonweaver + + Weaves the victim into a (self-sustaining) cocoon. The victim cannot move, but can be bred. + Genes/Icons/Cocoon + true + true + false + Mote_CocoonStencil + CocoonWeave + CastAbilityOnThingMelee + 404 + + 30000 + + Verb_CastAbilityTouch + false + -1 + 15 + + true + false + false + false + true + + + +
  • + + + \ No newline at end of file diff --git a/Common/Defs/Effects/cocoonweave.xml b/Common/Defs/Effects/cocoonweave.xml new file mode 100644 index 0000000..573ccd2 --- /dev/null +++ b/Common/Defs/Effects/cocoonweave.xml @@ -0,0 +1,37 @@ + + + + + CocoonWeave + +
  • + SubEffecter_SprayerChance + BloodSplash + 0.15 + 2~3 + 0.75~1.5 + (244, 244, 244) + RandomDrawPosOnTarget + true +
  • + + + + + Mote_CocoonStencil + MoteAttached + Terrain + + 0.1 + 0.4 + 999999 + True + + + Graphic_PawnBodySilhouette + PawnSilhouetteStencil + Things/Mote/Transparent + + + +
    \ No newline at end of file diff --git a/Common/Defs/GeneDefs/GeneDefs_Breeding.xml b/Common/Defs/GeneDefs/GeneDefs_Breeding.xml index 1495b43..6d16ee6 100644 --- a/Common/Defs/GeneDefs/GeneDefs_Breeding.xml +++ b/Common/Defs/GeneDefs/GeneDefs_Breeding.xml @@ -2,28 +2,31 @@ - + + rjw_genes_breeding + + +
  • + Genes/Icons/RJW_Genes_Endogene_Background + Genes/Icons/RJW_Genes_Xenogene_Background +
  • +
    +
    + + + rjw_genes_mechbreeder Pawns with this gene are able to birth mechanoids unharmed. World/WorldObjects/Expanding/Mechanoids 51 - rjw_genes_breeding 1 -1 - - -
  • - Genes/Icons/RJW_Genes_Endogene_Background - Genes/Icons/RJW_Genes_Xenogene_Background -
  • -
    - + rjw_genes_zoophile - rjw_genes_breeding Xenotypes with this Gene are Zoophile. Genes/Icons/Zoophile 54 @@ -32,22 +35,46 @@ Zoophile - - -
  • - Genes/Icons/RJW_Genes_Endogene_Background - Genes/Icons/RJW_Genes_Xenogene_Background -
  • -
    - + rjw_genes_fertile_anus - rjw_genes_breeding Xenotypes with this gene have a functional uterus connected to the anal cavity even for males Genes/Icons/Fertile_anus 54 + + rjw_genes_insectincubator + + RJW_Genes.Gene_InsectIncubator + Pawns with this gene fertilize insect eggs that are placed inside them. + Genes/Icons/Egg + 52 + 1 + -1 + + + + rjw_genes_insectbreeder + + Pawns with this gene are able to fertilize eggs with any fertile penis. + Genes/Icons/Insect_Breeder + 53 + 1 + -1 + + + + rjw_genes_fervent_ovipositor + + RJW_Genes.Gene_FerventOvipositor + Pawns that have a female (egg producing) ovipositor produce eggs at drastically increased speed. + Genes/Icons/Fervent_Ovipositor + 55 + 1 + -1 + +
    \ No newline at end of file diff --git a/Common/Defs/GeneDefs/GeneDefs_SexSpecial.xml b/Common/Defs/GeneDefs/GeneDefs_SexSpecial.xml index c3c042f..6cd34be 100644 --- a/Common/Defs/GeneDefs/GeneDefs_SexSpecial.xml +++ b/Common/Defs/GeneDefs/GeneDefs_SexSpecial.xml @@ -109,4 +109,21 @@ + + rjw_genes_cocoonweaver + + cocooner + Carriers of this gene can produce a cocoon to prepare helpless (or willing) victims for breeding. + Genes/Icons/Cocoon + 11 + +
  • rjw_genes_ability_cocoonweaver
  • +
    + + rjw_genes_ability_cocoonweaver + + 1 + -1 +
    + \ No newline at end of file diff --git a/Source/Genes/Breeding/Gene_FerventOvipositor.cs b/Source/Genes/Breeding/Gene_FerventOvipositor.cs new file mode 100644 index 0000000..3d8f612 --- /dev/null +++ b/Source/Genes/Breeding/Gene_FerventOvipositor.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Verse; +using rjw; + +namespace RJW_Genes +{ + + /// + /// Manages the rjw_genes_fervent_ovipositor to grow eggs much faster. + /// + /// TODO: Move the Multiplier into XML + /// TODO: This gene only works after the first egg, the first egg for two new pawns spawns at the same time (strange). + /// + public class Gene_FerventOvipositor : Gene + { + + const int MULTIPLIER = 3; // Tick 3 times as much, making a pawn with this Gene Produce Eggs 4 times as fast as the normal. + + public override void Tick() + { + base.Tick(); + + if (pawn == null) return; + + Hediff_PartBaseNatural OvipositorF = (Hediff_PartBaseNatural)pawn.health.hediffSet.GetFirstHediffOfDef(rjw.Genital_Helper.ovipositorF); + + if (OvipositorF == null) return; + + OvipositorF.nextEggTick = Math.Max(OvipositorF.nextEggTick - MULTIPLIER, -1); + + // DevNote: I first had a for-loop calling OviPositorF.tick(), but I fear that would be a performance sink. + // Also, it would double other aspects as well, such as bleeding out through your insect-PP or dropping out the eggs. + } + + + } +} \ No newline at end of file diff --git a/Source/Genes/Breeding/Gene_InsectIncubator.cs b/Source/Genes/Breeding/Gene_InsectIncubator.cs new file mode 100644 index 0000000..ce53827 --- /dev/null +++ b/Source/Genes/Breeding/Gene_InsectIncubator.cs @@ -0,0 +1,67 @@ +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 + /// + /// To save performance, this gene fires (default) every 0.5h, which also means a slight delay until fertilization happens. + /// + 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); + // This part works as intended and shows Non-Human Eggs too + //if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"Gene_InsectIncubator: Found {eggs.Count} Hediff_InsectEgg in {pawn}"); + + + 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); + // DevNote Issue 38: Sometimes Eggs are not fertilized here, because the normal Fertilize Function is called which has an upper Limit on Gestation. + // I will not do anything about it here, maybe upstream, but I print here. + if (RJW_Genes_Settings.rjw_genes_detailed_debug) + { + if (egg.fertilized) + ModLog.Message($"Gene_InsectIncubator: fertilized egg {egg} in {pawn}"); + else if (egg.GestationProgress > 0.5) + ModLog.Message($"Gene_InsectIncubator: Failed to fertilize {egg} in {pawn} due to high gestation progress"); + else + ModLog.Message($"Gene_InsectIncubator: failed to fertiliz egg {egg} in {pawn}"); + } + } + // DevNote: There is an issue with Eggs reaching too much gestation progress (>100%), which causes DownStream bugs. To avoid this, there are some extra checks in place. + else if (egg.fertilized && egg.GestationProgress <= .93) + { + egg.lastTick += TICK_INTERVAL; + } + } + } + } + } +} diff --git a/Source/Genes/Special/Abilities/CompAbilityEffect_CocoonWeaver.cs b/Source/Genes/Special/Abilities/CompAbilityEffect_CocoonWeaver.cs new file mode 100644 index 0000000..a3af363 --- /dev/null +++ b/Source/Genes/Special/Abilities/CompAbilityEffect_CocoonWeaver.cs @@ -0,0 +1,81 @@ +using Verse; +using RimWorld; +using rjw; + +namespace RJW_Genes +{ + /// + /// The CocoonWeaver Ability applies the RJW-Cocoon to a pawn. + /// Friendly Pawns can always be cocooned, neutral and hostile pawns must be downed. + /// + public class CompAbilityEffect_CocoonWeaver : CompAbilityEffect + { + private new CompProperties_AbilityCocoonWeaver Props + { + get + { + return (CompProperties_AbilityCocoonWeaver)this.props; + } + } + + + public override void Apply(LocalTargetInfo target, LocalTargetInfo dest) + { + base.Apply(target, dest); + + Pawn CocooningPawn = this.parent.pawn; + Pawn PawnToCocoon = target.Pawn; + + // Error Case - Null Pawn + if (PawnToCocoon == null) + { + return; + } + + PawnToCocoon.health.AddHediff(HediffDef.Named("RJW_Cocoon")); + + } + + /// + /// For validity, there are a few checks: + /// 0. Target is not already cocooned + /// 1. Target is either Colonist / Prisoner + /// 2. If the Target is an enemy or neutral, it must be downed. + /// + public override bool Valid(LocalTargetInfo target, bool throwMessages = false) + { + Pawn cocoonTarget = target.Pawn; + if (cocoonTarget != null) + { + bool CocoonTargetIsColonistOrPrisoner = cocoonTarget.Faction == this.parent.pawn.Faction || cocoonTarget.IsPrisonerOfColony; + bool CocoonTargetIsHostile = cocoonTarget.HostileTo(this.parent.pawn); + bool CocoonTargetIsDowned = cocoonTarget.Downed; + + if (cocoonTarget.health.hediffSet.hediffs.Any(t => t.def.defName == "RJW_Cocoon")) + { + if (throwMessages) + Messages.Message(cocoonTarget.Name + " is already cocooned.", cocoonTarget, MessageTypeDefOf.RejectInput, false); + return false; + } + + if (!CocoonTargetIsColonistOrPrisoner && !(CocoonTargetIsHostile && CocoonTargetIsDowned)) + { + if (throwMessages) + { + if (CocoonTargetIsHostile && !CocoonTargetIsDowned) + { + Messages.Message(cocoonTarget.Name + " is hostile, but not downed.", cocoonTarget, MessageTypeDefOf.RejectInput, false); + } + else if (!CocoonTargetIsColonistOrPrisoner) + { + Messages.Message(cocoonTarget.Name + " is not a part of the colony or hostile.", cocoonTarget, MessageTypeDefOf.RejectInput, false); + } + } + return false; + } + } + return base.Valid(target, throwMessages); + } + + } +} \ No newline at end of file diff --git a/Source/Genes/Special/Abilities/CompProperties_AbilityCocoonWeaver.cs b/Source/Genes/Special/Abilities/CompProperties_AbilityCocoonWeaver.cs new file mode 100644 index 0000000..caa63b6 --- /dev/null +++ b/Source/Genes/Special/Abilities/CompProperties_AbilityCocoonWeaver.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; +using RimWorld; + +namespace RJW_Genes +{ + public class CompProperties_AbilityCocoonWeaver : CompProperties_AbilityEffect + { + public CompProperties_AbilityCocoonWeaver() + { + this.compClass = typeof(CompAbilityEffect_CocoonWeaver); + } + } +} \ No newline at end of file diff --git a/Source/Rjw-Genes.csproj b/Source/Rjw-Genes.csproj index c257868..d8b0fcb 100644 --- a/Source/Rjw-Genes.csproj +++ b/Source/Rjw-Genes.csproj @@ -64,6 +64,8 @@ + + @@ -154,6 +156,8 @@ + +