Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 1.5/Defs/JobDefs/Jobs_Learning.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>

<jobDef>
<defName>AdmiringSpace</defName>
<driverClass>SaveOurShip2.JobDriver_AdmireSpace</driverClass>
<reportString>admiring space.</reportString>
</jobDef>

</Defs>
11 changes: 11 additions & 0 deletions 1.5/Defs/LearningDesireDefs/LearningDesires.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<LearningDesireDef>
<defName>AdmiringSpace</defName>
<label>admiring space</label>
<description>Space is so beautiful. Many kids admire it and dream of future life among the stars. Requires some kind of telescope.</description>
<iconPath>UI/Icons/Learning/Radiotalking</iconPath>
<workerClass>SaveOurShip2.LearningGiver_AdmiringSpace</workerClass>
<jobDef>AdmiringSpace</jobDef>
</LearningDesireDef>
</Defs>
26 changes: 26 additions & 0 deletions Source/1.5/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4908,6 +4908,32 @@ 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<LearningDesireDef> learningOptions = DefDatabase<LearningDesireDef>.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();
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<LearningDesireDef>.AllDefsListForReading.First((LearningDesireDef ld) => ld.defName == "AdmiringSpace"));
}
}
LearningDesireDef newDesire = learningOptions.RandomElementByWeight((LearningDesireDef ld) => ld.selectionWeight);
if (__instance.active.Count >= 2)
{
__instance.active.RemoveAt(0);
}
__instance.active.Add(newDesire);
return false;
}
}

// Biotech - disable "Summon diabolus available" letters for comm consoles on enemy ships
[HarmonyPatch(typeof(CompUseEffect_CallBossgroup), "PostSpawnSetup")]
public static class DisableMechSpawnAvailableLetter
Expand Down
40 changes: 40 additions & 0 deletions Source/1.5/Jobs/JobDriver_AdmireSpace.cs
Original file line number Diff line number Diff line change
@@ -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<Toil> 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;
}
}
}
61 changes: 61 additions & 0 deletions Source/1.5/Jobs/LearningGiver_AdmiringSpace.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 2 additions & 0 deletions Source/1.5/RimworldMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<Compile Include="Graphic\Graphic_SingleOnOffEmpty.cs" />
<Compile Include="HarmonyPatches.cs" />
<Compile Include="HediffPawnIsHologram.cs" />
<Compile Include="Jobs\JobDriver_AdmireSpace.cs" />
<Compile Include="Jobs\JobDriver_BreachAirlock.cs" />
<Compile Include="Jobs\JobDriver_CarryToCryptonest.cs" />
<Compile Include="Jobs\JobDriver_DefendBreacher.cs" />
Expand Down Expand Up @@ -291,6 +292,7 @@
<Compile Include="Jobs\JobGiver_LoadTorpedoes.cs" />
<Compile Include="Jobs\JobGiver_ManShipBridge.cs" />
<Compile Include="Jobs\JobGiver_RepairShields.cs" />
<Compile Include="Jobs\LearningGiver_AdmiringSpace.cs" />
<Compile Include="Jobs\LordJob_AssaultShip.cs" />
<Compile Include="Jobs\LordJob_DefendShip.cs" />
<Compile Include="Jobs\LordToil_AssaultShip.cs" />
Expand Down