forked from Vanilla-Expanded/VanillaRacesExpanded-Phytokin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
6b031d9
commit 6a1dac5
Showing
5 changed files
with
159 additions
and
147 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VanillaRacesExpanded-Phytokin/obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 96 additions & 63 deletions
159
...llaRacesExpanded-Phytokin/VanillaRacesExpanded-Phytokin/Building/Building_SaplingChild.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.