-
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.
- Loading branch information
1 parent
5a23a70
commit 7ee8c76
Showing
7 changed files
with
185 additions
and
2 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,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> |
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,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; | ||
} | ||
} | ||
} | ||
} |
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
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
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,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> |
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