Skip to content

Commit

Permalink
v3.3.0 updated for RimWorld 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jaschaephraim committed Nov 5, 2022
1 parent 5a23a70 commit 7ee8c76
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 2 deletions.
Binary file added 1.4/Assemblies/EndlessRimworld.dll
Binary file not shown.
18 changes: 18 additions & 0 deletions 1.4/Defs/Storyteller/Incidents_Map_Misc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>

<IncidentDef>
<defName>EndlessRimworld_WandererJoin</defName>
<label>wanderer join</label>
<category>Misc</category>
<targetTags>
<li>Map_PlayerHome</li>
</targetTags>
<workerClass>IncidentWorker_GiveQuest</workerClass>
<questScriptDef>WandererJoins</questScriptDef>
<baseChance>0</baseChance>
<pawnKind>Villager</pawnKind>
<populationEffect>IncreaseEasy</populationEffect>
</IncidentDef>

</Defs>
158 changes: 158 additions & 0 deletions 1.4/Source/EndlessRimworld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
using RimWorld;
using RimWorld.QuestGen;
using Verse;
using HarmonyLib;
using HugsLib;
using HugsLib.Settings;
using HugsLib.Utils;

namespace EndlessRimworld
{
internal enum Stage
{
Uninitiated,
Initiated,
Queued,
}

internal class State
{
internal static ModLogger logger;
internal static SettingHandle<int> delayTicks;
internal static Stage stage;
internal static Map incidentMap;

internal static void Reset()
{
State.logger.Trace("Resetting");
State.stage = Stage.Uninitiated;
State.incidentMap = null;
}
}

internal class EndlessRimworld : ModBase
{
public override string ModIdentifier => "EndlessRimworld";

private EndlessRimworld()
{
State.logger = Logger;
}

public override void DefsLoaded()
{
State.delayTicks = Settings.GetHandle(
"delayTicks",
"EndlessRimworldDelayTicks".Translate(),
"EndlessRimworldDelayTicksDescription".Translate(),
GenDate.TicksPerDay
);
State.delayTicks.ContextMenuEntries = new[]
{
new ContextMenuEntry("Immediately", () => State.delayTicks.Value = 0),
new ContextMenuEntry("One hour", () => State.delayTicks.Value = 2500),
new ContextMenuEntry("One day (default)", () => State.delayTicks.Value = 60000),
new ContextMenuEntry("One week", () => State.delayTicks.Value = 420000),
};
}
}

[HarmonyPatch(typeof(Root), "Start")]
internal static class Patch_Root_Start
{
private static void Prefix()
{
State.Reset();
}
}

[HarmonyPatch(typeof(IncidentWorker_GiveQuest), "CanFireNowSub")]
internal static class Patch_IncidentWorker_GiveQuest_CanFireNowSub
{
private static void Postfix(ref bool __result, IncidentWorker __instance)
{
if (__instance.def.defName == "EndlessRimworld_WandererJoin")
{
__result = true;
}
}
}

[HarmonyPatch(typeof(QuestGen_Get), "GetMap")]
internal static class Patch_QuestGen_Get_GetMap
{
private static void Postfix(ref Map __result)
{
if (State.stage == Stage.Queued)
{
__result = State.incidentMap;
}
}
}

[HarmonyPatch(typeof(GameEnder), "CheckOrUpdateGameOver")]
internal static class Patch_GameEnder_CheckOrUpdateGameOver
{
private static void Postfix()
{
if (Find.GameEnder.gameEnding)
{
if (State.stage != Stage.Uninitiated)
{
return;
}
State.logger.Trace("Initiating enqueue");
State.stage = Stage.Initiated;
}
else
{
State.Reset();
}
}
}

[HarmonyPatch(typeof(GameEnder), "GameEndTick")]
internal static class Patch_GameEnder_GameEndTick
{
private static void Prefix(ref bool ___gameEnding, ref int ___ticksToGameOver)
{
if (State.stage == Stage.Initiated && ___gameEnding && ___ticksToGameOver == 0)
{
int tick = Find.TickManager.TicksGame;
IncidentQueue incidentQueue = Find.Storyteller.incidentQueue;

IncidentDef wandererJoin = IncidentDefOf.WandererJoin;
IncidentDef erWandererJoin = IncidentDef.Named("EndlessRimworld_WandererJoin");

foreach (QueuedIncident current in incidentQueue)
{
if (current.FireTick - tick > GenDate.TicksPerDay)
{
break;
}
if (current.FiringIncident.def == wandererJoin)
{
State.logger.Trace("Incident already queued");
State.logger.Trace(current);
return;
}
}

State.incidentMap = Find.AnyPlayerHomeMap;
IncidentParms parms = StorytellerUtility.DefaultParmsNow(erWandererJoin.category, State.incidentMap);
parms.forced = true;

FiringIncident firingIncident = new FiringIncident(erWandererJoin, null, parms);
QueuedIncident queuedIncident = new QueuedIncident(firingIncident, tick + State.delayTicks, 0);

State.logger.Trace("Queueing incident");
State.logger.Trace(queuedIncident);
incidentQueue.Add(queuedIncident);

State.stage = Stage.Queued;
___gameEnding = false;
___ticksToGameOver = -1;
}
}
}
}
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<supportedVersions>
<li>1.2</li>
<li>1.3</li>
<li>1.4</li>
</supportedVersions>
<modDependencies>
<li>
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>jaschaephraim.endlessrimworld</identifier>
<version>3.2.0</version>
<version>3.3.0</version>
<dependencies>
<li>brrainz.harmony</li>
<li>UnlimitedHugs.HugsLib</li>
Expand Down
2 changes: 1 addition & 1 deletion About/Version.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<VersionData>
<overrideVersion>3.2.0</overrideVersion>
<overrideVersion>3.3.0</overrideVersion>
<gitHubRepository>jaschaephraim/endless-rimworld</gitHubRepository>
</VersionData>
6 changes: 6 additions & 0 deletions News/UpdateFeatures.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
<assemblyVersion>3.1.0</assemblyVersion>
<content>Multiversion support</content>
</HugsLib.UpdateFeatureDef>

<HugsLib.UpdateFeatureDef ParentName="UpdateFeatureBase">
<defName>EndlessRimworld_3_3_0</defName>
<assemblyVersion>3.3.0</assemblyVersion>
<content>Updated for RimWorld 1.4</content>
</HugsLib.UpdateFeatureDef>
</Defs>

0 comments on commit 7ee8c76

Please sign in to comment.