Skip to content

Commit

Permalink
Fixes + Reformat + Small Refactor
Browse files Browse the repository at this point in the history
* Child will now be born with the same last name as mother
* Child will now be born with correct xenotype if parent uses a custom xenotype (Used to be that it would make them a baseliner)
* Added debug gizmo to hatch child instantly
* Made `TicksToBirth` and `TicksToCheckGraphic` a constant
* Saplingbirth child will have the BabyBirth letter
  • Loading branch information
NemuruYama committed Oct 15, 2024
1 parent 6b031d9 commit 6a1dac5
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 147 deletions.
Binary file modified 1.5/Assemblies/VanillaRacesExpanded-Phytokin.dll
Binary file not shown.
1 change: 1 addition & 0 deletions 1.5/Source/VanillaRacesExpanded-Phytokin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VanillaRacesExpanded-Phytokin/obj
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Verse;
using Verse.AI;
using RimWorld;

namespace VanillaRacesExpandedPhytokin
{
public class JobDriver_PlantSaplingchild : JobDriver
{




private IntVec3 TargetPosition
{
get
{
return this.job.GetTarget(TargetIndex.A).Cell;
}
}
private IntVec3 TargetPosition => job.GetTarget(TargetIndex.A).Cell;

public override bool TryMakePreToilReservations(bool errorOnFailed)
{
Expand All @@ -27,45 +15,41 @@ public override bool TryMakePreToilReservations(bool errorOnFailed)

protected override IEnumerable<Toil> MakeNewToils()
{


yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedOrNull(TargetIndex.A);
Toil toil = Toils_General.Wait(600, TargetIndex.None);
toil.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
toil.FailOnDespawnedOrNull(TargetIndex.A);
toil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
Toil toil = Toils_General
.Wait(600)
.WithProgressBarToilDelay(TargetIndex.A)
.FailOnDespawnedOrNull(TargetIndex.A)
.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
yield return toil;
Toil createSaplingChild = new Toil();
createSaplingChild.initAction = delegate ()

Toil createSaplingChild = new Toil
{
Thing thing = ThingMaker.MakeThing(InternalDefOf.VRE_SaplingchildTree, null);
thing.stackCount = 1;
Thing t;
GenPlace.TryPlaceThing(thing, TargetPosition, pawn.Map, ThingPlaceMode.Direct, out t, null, null, default(Rot4));
initAction = delegate
{
Thing thing = ThingMaker.MakeThing(InternalDefOf.VRE_SaplingchildTree);
thing.stackCount = 1;
GenPlace.TryPlaceThing(thing, TargetPosition, pawn.Map, ThingPlaceMode.Direct, out _);

Building_SaplingChild sapling = thing as Building_SaplingChild;
Building_SaplingChild sapling = thing as Building_SaplingChild;

Hediff pregnancy = pawn.health?.hediffSet?.GetFirstHediffOfDef(InternalDefOf.VRE_Saplingchild);
if (pregnancy != null)
{
HediffComp_Saplingchild comp = pregnancy.TryGetComp<HediffComp_Saplingchild>();
Hediff pregnancy = pawn.health?.hediffSet?.GetFirstHediffOfDef(InternalDefOf.VRE_Saplingchild);
HediffComp_Saplingchild comp = pregnancy?.TryGetComp<HediffComp_Saplingchild>();
if (comp != null)
{
comp.miscarriage = false;
sapling.motherGenes = comp.motherGenes;
sapling.motherXenotype = comp.motherXenotype;
sapling.mother = pawn;
comp.Miscarriage = false;
sapling.MotherGenes = comp.MotherGenes;
sapling.MotherXenotype = comp.MotherXenotype;
sapling.MotherXenotypeIcon = comp.MotherXenotypeIcon;
sapling.MotherXenotypeName = comp.MotherXenotypeName;
sapling.MotherUniqueXenotype = comp.MotherUniqueXenotype;
sapling.Mother = pawn;
sapling.SetFaction(pawn.Faction);
pawn.health.RemoveHediff(pregnancy);
}

}


};
yield return createSaplingChild;
yield break;
}

}
}
}
Original file line number Diff line number Diff line change
@@ -1,166 +1,199 @@
using Verse;
using System;
using RimWorld;
using System.Collections.Generic;
using UnityEngine;
using RimWorld.Planet;

namespace VanillaRacesExpandedPhytokin
{
public class Building_SaplingChild : Building
{
public List<GeneDef> MotherGenes = new List<GeneDef>();
public XenotypeDef MotherXenotype;
public XenotypeIconDef MotherXenotypeIcon;
public string MotherXenotypeName;
public bool MotherUniqueXenotype;
public Pawn Mother;

public List<GeneDef> motherGenes = new List<GeneDef>();
public XenotypeDef motherXenotype;
public int tickCounter = 0;
public int ticksToCheckGraphic = 6000;
public int ticksToBirth = 1800000; // 30 days
public bool successfulBirth = false;
public Pawn mother;
private const int TicksPerDay = 60000;
private const int TicksToCheckGraphic = 6000;
private const int TicksToBirth = TicksPerDay * 30; // 30 days

public int TickCounter;
public bool SuccessfulBirth;

public override void ExposeData()
{
base.ExposeData();

Scribe_Collections.Look(ref this.motherGenes, nameof(this.motherGenes), LookMode.Def);
Scribe_Defs.Look(ref this.motherXenotype, nameof(this.motherXenotype));
Scribe_Values.Look(ref this.tickCounter, nameof(this.tickCounter));
Scribe_Values.Look(ref this.successfulBirth, nameof(this.successfulBirth));
Scribe_References.Look(ref this.mother, nameof(this.mother));
Scribe_Collections.Look(ref MotherGenes, nameof(MotherGenes), LookMode.Def);
Scribe_Defs.Look(ref MotherXenotype, nameof(MotherXenotype));
Scribe_Values.Look(ref TickCounter, nameof(TickCounter));
Scribe_Values.Look(ref SuccessfulBirth, nameof(SuccessfulBirth));
Scribe_References.Look(ref Mother, nameof(Mother));
}

public override string GetInspectString()
{
string text = base.GetInspectString();
if (motherXenotype != null)

if (MotherXenotype != null)
{
if (text.Length != 0)
{
text += "\n";
}
text += "VRE_MotherXenotype".Translate(motherXenotype.LabelCap);

text += "VRE_MotherXenotype".Translate(MotherXenotypeName);
text += "\n";
text += "VRE_TimeToHatch".Translate((ticksToBirth-tickCounter).ToStringTicksToPeriod(true, false, true, true));
text += "VRE_TimeToHatch".Translate((TicksToBirth - TickCounter).ToStringTicksToPeriod());
}

return text;
}

public override void Tick()
{
base.Tick();
tickCounter++;
if ((tickCounter > ticksToBirth))
TickCounter++;
if (TickCounter > TicksToBirth)
{

Hatch();


}
if (tickCounter % ticksToCheckGraphic == 0)

if (TickCounter % TicksToCheckGraphic == 0)
{
base.Map.mapDrawer.MapMeshDirty(base.Position, MapMeshFlagDefOf.Things | MapMeshFlagDefOf.Buildings);
Map.mapDrawer.MapMeshDirty(Position, MapMeshFlagDefOf.Things | MapMeshFlagDefOf.Buildings);
}

}

public override Graphic Graphic
{
get
{
float sizePercentage = ((float)tickCounter / (float)ticksToBirth)+0.5f;
float sizePercentage = (float)TickCounter / (float)TicksToBirth + 0.5f;
Graphic modifiedGraphic;
if (tickCounter > ticksToBirth * 2 / 3)
if (TickCounter > TicksToBirth * 2 / 3)
{
modifiedGraphic = GraphicsCache.graphicMaturePlant;
modifiedGraphic.drawSize = this.def.graphicData.drawSize * sizePercentage *0.65f;

modifiedGraphic.drawSize = def.graphicData.drawSize * sizePercentage * 0.65f;
}
else
{
modifiedGraphic = base.Graphic;
modifiedGraphic.drawSize = this.def.graphicData.drawSize * sizePercentage;
modifiedGraphic.drawSize = def.graphicData.drawSize * sizePercentage;
}






return modifiedGraphic;
}

}

public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
{
base.Destroy(mode);
if (!successfulBirth)
if (!SuccessfulBirth)
{
mother?.needs?.mood?.thoughts?.memories?.TryGainMemory(ThoughtDefOf.Stillbirth);

Mother?.needs?.mood?.thoughts?.memories?.TryGainMemory(ThoughtDefOf.Stillbirth);
}

}



public void Hatch()
{
try
{
PawnGenerationRequest request = new PawnGenerationRequest(mother.kindDef, mother.Faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, allowDead: false, allowDowned: true, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowPregnant: false, allowFood: true, allowAddictions: true, inhabitant: false, certainlyBeenInCryptosleep: false, forceRedressWorldPawnIfFormerColonist: false, worldPawnFactionDoesntMatter: false, 0f, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, null, forceNoIdeo: false, forceNoBackstory: false, forbidAnyTitle: false, forceDead: false, null, null, null, null, null, 0f, DevelopmentalStage.Newborn);
string motherLastName = null;
if (Mother.Name is NameTriple nameTriple)
{
motherLastName = nameTriple.Last;
}

PawnGenerationRequest request = new PawnGenerationRequest(Mother.kindDef, Mother.Faction,
PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, allowDead: false,
allowDowned: true, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f,
forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowPregnant: false, allowFood: true,
allowAddictions: true, inhabitant: false, certainlyBeenInCryptosleep: false,
forceRedressWorldPawnIfFormerColonist: false, worldPawnFactionDoesntMatter: false, 0f, 0f, null, 1f,
null, null, null, null, null, null, null, null, fixedLastName: motherLastName, null, null, null,
forceNoIdeo: false, forceNoBackstory: false, forbidAnyTitle: false, forceDead: false, null, null,
null, null, null, 0f,
DevelopmentalStage.Newborn);

Pawn pawn = PawnGenerator.GeneratePawn(request);
if (PawnUtility.TrySpawnHatchedOrBornPawn(pawn, this))
{
if (pawn != null)
{
if (mother != null)
if (Mother != null)
{
if (pawn.playerSettings != null && mother.playerSettings != null)
if (pawn.playerSettings != null && Mother.playerSettings != null)
{
pawn.playerSettings.AreaRestrictionInPawnCurrentMap = mother.playerSettings.AreaRestrictionInPawnCurrentMap;
pawn.playerSettings.AreaRestrictionInPawnCurrentMap = Mother.playerSettings.AreaRestrictionInPawnCurrentMap;
}

if (pawn.RaceProps.IsFlesh)
{
pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, mother);
pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, Mother);
}
}

}
if (this.Spawned)

if (Spawned)
{
FilthMaker.TryMakeFilth(this.Position, this.Map, ThingDefOf.Filth_AmnioticFluid);
FilthMaker.TryMakeFilth(Position, Map, ThingDefOf.Filth_AmnioticFluid);
}

Find.LetterStack.ReceiveLetter("VRE_SaplingHatchedLabel".Translate(pawn.NameShortColored), "VRE_SaplingHatched".Translate(pawn.NameShortColored), LetterDefOf.PositiveEvent, (TargetInfo)pawn);
ChoiceLetter_BabyBirth choiceLetterBabyBirth = (ChoiceLetter_BabyBirth)LetterMaker.MakeLetter(
"VRE_SaplingHatchedLabel".Translate(pawn.NameShortColored),
"VRE_SaplingHatched".Translate(pawn.NameShortColored),
LetterDefOf.BabyBirth,
(TargetInfo)pawn
);
choiceLetterBabyBirth.Start();
Find.LetterStack.ReceiveLetter(choiceLetterBabyBirth);



foreach (GeneDef gene in motherGenes)
foreach (GeneDef gene in MotherGenes)
{
pawn.genes.AddGene(gene, false);
}
pawn.genes.SetXenotype(motherXenotype);




if (MotherUniqueXenotype)
{
pawn.genes.xenotypeName = MotherXenotypeName;
pawn.genes.iconDef = MotherXenotypeIcon;
}
else
{
pawn.genes.SetXenotype(MotherXenotype);
}
}
else
{
Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
}

}
finally
{
successfulBirth = true;
this.Destroy();
SuccessfulBirth = true;
Destroy();
}
}

public override IEnumerable<Gizmo> GetGizmos()
{
foreach (Gizmo gizmo in base.GetGizmos())
{
yield return gizmo;
}

if (!DebugSettings.ShowDevGizmos)
{
yield break;
}

yield return new Command_Action()
{
defaultLabel = "DEV: Hatch Now",
action = Hatch
};
}
}
}
}
Loading

0 comments on commit 6a1dac5

Please sign in to comment.