From 5964f7a1b38caea44d36cf674310eed75974fa6b Mon Sep 17 00:00:00 2001 From: user Date: Wed, 25 Sep 2024 21:53:14 +0300 Subject: [PATCH 1/3] Some kids learning needs don't work in space. So, disable them on space maps. This is the least that could be done to allow players raise kids on spaceships investing time in their learning and get a desired reward for that. Ideally, mihgt have new learning types in space. --- Source/1.5/HarmonyPatches.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/1.5/HarmonyPatches.cs b/Source/1.5/HarmonyPatches.cs index b5534fad..170974cc 100644 --- a/Source/1.5/HarmonyPatches.cs +++ b/Source/1.5/HarmonyPatches.cs @@ -4908,6 +4908,27 @@ public static void Postfix(Pawn pawn, ref bool __result) } } + // Biotech - when on space map, disomle kids learning options that don't work + [HarmonyPatch(typeof(Pawn_LearningTracker), "AddNewLearningDesire")] + public static class ProperLearningNeedsInSpace + { + public static bool Prefix(Pawn_LearningTracker __instance) + { + List learningOptions = DefDatabase.AllDefsListForReading.Where((LearningDesireDef ld) => !__instance.active.Contains(ld) && ld.Worker.CanGiveDesire).ToList(); + if (__instance.Pawn.Map != null && __instance.Pawn.Map.IsSpace()) + { + learningOptions = learningOptions.Where((LearningDesireDef ld) => ld.defName != "NatureRunning" && ld.defName != "Skydreaming").ToList(); + } + LearningDesireDef item = learningOptions.RandomElementByWeight((LearningDesireDef ld) => ld.selectionWeight); + if (__instance.active.Count >= 2) + { + __instance.active.RemoveAt(0); + } + __instance.active.Add(item); + return false; + } + } + // Biotech - disable "Summon diabolus available" letters for comm consoles on enemy ships [HarmonyPatch(typeof(CompUseEffect_CallBossgroup), "PostSpawnSetup")] public static class DisableMechSpawnAvailableLetter From 73380e368ae41f1ed4510fc19b789810c7200a6f Mon Sep 17 00:00:00 2001 From: user Date: Thu, 26 Sep 2024 07:18:37 +0300 Subject: [PATCH 2/3] Added AmireSpace learning desire for Biotech kids to make up for two vanilla desires not working, on space map and with telescope --- 1.5/Defs/JobDefs/Jobs_Learning.xml | 10 +++ .../LearningDesireDefs/LearningDesires.xml | 11 ++++ Source/1.5/HarmonyPatches.cs | 4 ++ Source/1.5/Jobs/JobDriver_AdmireSpace.cs | 40 ++++++++++++ .../1.5/Jobs/LearningGiver_AdmiringSpace.cs | 61 +++++++++++++++++++ Source/1.5/RimworldMod.csproj | 2 + 6 files changed, 128 insertions(+) create mode 100644 1.5/Defs/JobDefs/Jobs_Learning.xml create mode 100644 1.5/Defs/LearningDesireDefs/LearningDesires.xml create mode 100644 Source/1.5/Jobs/JobDriver_AdmireSpace.cs create mode 100644 Source/1.5/Jobs/LearningGiver_AdmiringSpace.cs diff --git a/1.5/Defs/JobDefs/Jobs_Learning.xml b/1.5/Defs/JobDefs/Jobs_Learning.xml new file mode 100644 index 00000000..16aabb5b --- /dev/null +++ b/1.5/Defs/JobDefs/Jobs_Learning.xml @@ -0,0 +1,10 @@ + + + + + AdmiringSpace + SaveOurShip2.JobDriver_AdmireSpace + admiring space. + + + \ No newline at end of file diff --git a/1.5/Defs/LearningDesireDefs/LearningDesires.xml b/1.5/Defs/LearningDesireDefs/LearningDesires.xml new file mode 100644 index 00000000..2ce800c2 --- /dev/null +++ b/1.5/Defs/LearningDesireDefs/LearningDesires.xml @@ -0,0 +1,11 @@ + + + + AmiringSpace + + Space is so beautiful. Many kids admire it and dream of future life among the stars. Requires some kind of telescope. + UI/Icons/Learning/Radiotalking + SaveOurShip2.LearningGiver_AdmiringSpace + AdmiringSpace + + \ No newline at end of file diff --git a/Source/1.5/HarmonyPatches.cs b/Source/1.5/HarmonyPatches.cs index 170974cc..4b5b93c2 100644 --- a/Source/1.5/HarmonyPatches.cs +++ b/Source/1.5/HarmonyPatches.cs @@ -4918,6 +4918,10 @@ public static bool Prefix(Pawn_LearningTracker __instance) if (__instance.Pawn.Map != null && __instance.Pawn.Map.IsSpace()) { learningOptions = learningOptions.Where((LearningDesireDef ld) => ld.defName != "NatureRunning" && ld.defName != "Skydreaming").ToList(); + if (__instance.Pawn.Map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.defName == "Telescope" || b.def.defName == "TelescopeSpace")) + { + learningOptions.Add(DefDatabase.AllDefsListForReading.First((LearningDesireDef ld) => ld.defName == "AmiringSpace")); + } } LearningDesireDef item = learningOptions.RandomElementByWeight((LearningDesireDef ld) => ld.selectionWeight); if (__instance.active.Count >= 2) diff --git a/Source/1.5/Jobs/JobDriver_AdmireSpace.cs b/Source/1.5/Jobs/JobDriver_AdmireSpace.cs new file mode 100644 index 00000000..7b9486a3 --- /dev/null +++ b/Source/1.5/Jobs/JobDriver_AdmireSpace.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Verse; +using Verse.AI; +using Verse.Sound; +using RimWorld; + +namespace SaveOurShip2 +{ + class JobDriver_AdmireSpace : JobDriver + { + public Building telescope => (Building)base.TargetThingA; + + public override bool TryMakePreToilReservations(bool errorOnFailed) + { + return pawn.Reserve(base.TargetA, job, 1, -1, null, errorOnFailed); + } + + protected override IEnumerable MakeNewToils() + { + this.FailOnDespawnedOrNull(TargetIndex.A); + this.FailOnSomeonePhysicallyInteracting(TargetIndex.A); + this.FailOnChildLearningConditions(); + this.FailOn(() => telescope.IsForbidden(pawn)); + yield return Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.InteractionCell).FailOn(() => telescope.IsForbidden(pawn)); + Toil toil = ToilMaker.MakeToil("MakeNewToils"); + toil.tickAction = delegate + { + pawn.rotationTracker.FaceTarget(base.TargetA); + LearningUtility.LearningTickCheckEnd(pawn); + }; + // toil.WithEffect(EffecterDefOf.Radiotalking, TargetIndex.A); + toil.handlingFacing = true; + toil.defaultCompleteMode = ToilCompleteMode.Never; + yield return toil; + } + } +} diff --git a/Source/1.5/Jobs/LearningGiver_AdmiringSpace.cs b/Source/1.5/Jobs/LearningGiver_AdmiringSpace.cs new file mode 100644 index 00000000..b8710463 --- /dev/null +++ b/Source/1.5/Jobs/LearningGiver_AdmiringSpace.cs @@ -0,0 +1,61 @@ +using RimWorld; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Verse; +using Verse.AI; + +namespace SaveOurShip2 +{ + public class LearningGiver_AdmiringSpace : LearningGiver + { + // Cannot work properly because context is not passed to this function. + // So will just return false, but this desire will be added manually in harmony patch? + public override bool CanGiveDesire + { + get + { + return false; + } + } + + private bool TryFindTelescope(Pawn pawn, out Thing telescopeResult) + { + Thing spaceTelecope = null; + Thing telecope = null; + if (pawn != null) + { + spaceTelecope = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(ThingDef.Named("TelescopeSpace")), PathEndMode.InteractionCell, TraverseParms.For(pawn), 9999f, (Thing t) => t is Building b && pawn.CanReserve(b) && !b.IsForbidden(pawn)); + telecope = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(ThingDef.Named("Telescope")), PathEndMode.InteractionCell, TraverseParms.For(pawn), 9999f, (Thing t) => t is Building b && pawn.CanReserve(b) && !b.IsForbidden(pawn)); + } + if (spaceTelecope != null) + { + telescopeResult = spaceTelecope; + } + else + { + telescopeResult = telecope; + } + return telescopeResult != null; + } + + public override bool CanDo(Pawn pawn) + { + if (!base.CanDo(pawn)) + { + return false; + } + return TryFindTelescope(pawn, out var telecope); + } + + public override Job TryGiveJob(Pawn pawn) + { + if (!TryFindTelescope(pawn, out var telesope)) + { + return null; + } + return JobMaker.MakeJob(def.jobDef, telesope); + } + } +} \ No newline at end of file diff --git a/Source/1.5/RimworldMod.csproj b/Source/1.5/RimworldMod.csproj index 463ce2d8..6ac3bffb 100644 --- a/Source/1.5/RimworldMod.csproj +++ b/Source/1.5/RimworldMod.csproj @@ -262,6 +262,7 @@ + @@ -291,6 +292,7 @@ + From ab03ab7a53f30f1a3ff23f2cfb5704a5880dfc67 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 30 Sep 2024 01:27:23 +0300 Subject: [PATCH 3/3] Fix def name and missing condition for duplicate learning desire. --- 1.5/Defs/LearningDesireDefs/LearningDesires.xml | 2 +- Source/1.5/HarmonyPatches.cs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/1.5/Defs/LearningDesireDefs/LearningDesires.xml b/1.5/Defs/LearningDesireDefs/LearningDesires.xml index 2ce800c2..ad3c6fd4 100644 --- a/1.5/Defs/LearningDesireDefs/LearningDesires.xml +++ b/1.5/Defs/LearningDesireDefs/LearningDesires.xml @@ -1,7 +1,7 @@ - AmiringSpace + AdmiringSpace Space is so beautiful. Many kids admire it and dream of future life among the stars. Requires some kind of telescope. UI/Icons/Learning/Radiotalking diff --git a/Source/1.5/HarmonyPatches.cs b/Source/1.5/HarmonyPatches.cs index 4b5b93c2..5cdd0c88 100644 --- a/Source/1.5/HarmonyPatches.cs +++ b/Source/1.5/HarmonyPatches.cs @@ -4918,17 +4918,18 @@ public static bool Prefix(Pawn_LearningTracker __instance) if (__instance.Pawn.Map != null && __instance.Pawn.Map.IsSpace()) { learningOptions = learningOptions.Where((LearningDesireDef ld) => ld.defName != "NatureRunning" && ld.defName != "Skydreaming").ToList(); - if (__instance.Pawn.Map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.defName == "Telescope" || b.def.defName == "TelescopeSpace")) + if ((__instance.Pawn.Map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.defName == "Telescope" || b.def.defName == "TelescopeSpace")) && + !__instance.active.Any((LearningDesireDef ld) => ld.defName == "AdmiringSpace")) { - learningOptions.Add(DefDatabase.AllDefsListForReading.First((LearningDesireDef ld) => ld.defName == "AmiringSpace")); + learningOptions.Add(DefDatabase.AllDefsListForReading.First((LearningDesireDef ld) => ld.defName == "AdmiringSpace")); } } - LearningDesireDef item = learningOptions.RandomElementByWeight((LearningDesireDef ld) => ld.selectionWeight); + LearningDesireDef newDesire = learningOptions.RandomElementByWeight((LearningDesireDef ld) => ld.selectionWeight); if (__instance.active.Count >= 2) { __instance.active.RemoveAt(0); } - __instance.active.Add(item); + __instance.active.Add(newDesire); return false; } }