Skip to content

Commit

Permalink
Merge pull request #41 from RimNauts/main
Browse files Browse the repository at this point in the history
Add option in the mod settings to toggle incident filter
  • Loading branch information
sindre0830 authored Mar 11, 2023
2 parents 635b506 + 5da8203 commit 5260518
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
Binary file modified Assemblies/RimNauts2.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Changelog
- Add option in the mod settings to toggle incident filter
1 change: 1 addition & 0 deletions Languages/English/Keyed/Other.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
<RimNauts.object_type>Object type</RimNauts.object_type>
<RimNauts.amount>Amount</RimNauts.amount>
<RimNauts.randomize_all_neo>Randomize all objects</RimNauts.randomize_all_neo>
<RimNauts.incident_patch>Filter incidents on NEOs</RimNauts.incident_patch>
</LanguageData>
3 changes: 3 additions & 0 deletions Source/RimNauts2/RimNauts2/Biome/Patch/IncidentWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace RimNauts2.Biome.Patch {
[HarmonyLib.HarmonyPatch(typeof(RimWorld.IncidentWorker), "CanFireNow")]
class IncidentWorker_CanFireNow {
public static void Postfix(ref RimWorld.IncidentWorker __instance, RimWorld.IncidentParms parms, ref bool __result) {
if (!Settings.Container.get_incident_patch) return;
if (parms.forced) return;
try {
if (!__result || !World.Cache.exists(parms.target.Tile)) return;
Expand All @@ -17,13 +18,15 @@ public static void Postfix(ref RimWorld.IncidentWorker __instance, RimWorld.Inci
[HarmonyLib.HarmonyPatch(typeof(RimWorld.PawnsArrivalModeWorker), "CanUseWith")]
class PawnsArrivalModeWorker_CanUseWith {
public static void Postfix(RimWorld.IncidentParms parms, ref RimWorld.PawnsArrivalModeWorker __instance, bool __result) {
if (!Settings.Container.get_incident_patch) return;
if (__result && World.Cache.exists(parms.target.Tile)) __instance.def.minTechLevel = RimWorld.TechLevel.Industrial;
}
}

[HarmonyLib.HarmonyPatch(typeof(RimWorld.IncidentWorker_Raid), "ResolveRaidArriveMode")]
class IncidentWorker_Raid_ResolveRaidArriveMode {
public static bool Prefix(RimWorld.IncidentParms parms) {
if (!Settings.Container.get_incident_patch) return true;
if (!World.Cache.exists(parms.target.Tile)) return true;
parms.raidArrivalMode = parms.raidArrivalMode = (Rand.Value < 0.6f) ? RimWorld.PawnsArrivalModeDefOf.EdgeDrop : RimWorld.PawnsArrivalModeDefOf.CenterDrop;
return false;
Expand Down
2 changes: 1 addition & 1 deletion Source/RimNauts2/RimNauts2/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace RimNauts2 {
public static class Info {
public static readonly string name = "RimNauts 2";
public static readonly string version = "4.7.0";
public static readonly string version = "4.8.0";
}

public static class Style {
Expand Down
11 changes: 11 additions & 0 deletions Source/RimNauts2/RimNauts2/Settings/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ public class Container : ModSettings {
public static int? max_asteroid_ores;
public static bool? asteroid_ore_verbose;
public static bool? multi_threaded_update;
public static bool? incident_patch;

public override void ExposeData() {
Scribe_Collections.Look(ref object_generation_steps, "object_generation_steps", LookMode.Value, LookMode.Value);
Scribe_Values.Look(ref asteroid_ore_toggle, "asteroid_ore_toggle");
Scribe_Values.Look(ref max_asteroid_ores, "max_asteroid_ores");
Scribe_Values.Look(ref asteroid_ore_verbose, "asteroid_ore_verbose");
Scribe_Values.Look(ref multi_threaded_update, "multi_threaded_update");
Scribe_Values.Look(ref incident_patch, "incident_patch");
}

public static void clear() {
Expand All @@ -25,6 +27,7 @@ public static void clear() {
max_asteroid_ores = null;
asteroid_ore_verbose = null;
multi_threaded_update = null;
incident_patch = null;
}

public static Dictionary<World.Type, int> get_object_generation_steps {
Expand Down Expand Up @@ -70,5 +73,13 @@ public static bool get_multi_threaded_update {
return (bool) multi_threaded_update;
}
}

public static bool get_incident_patch {
get {
if (incident_patch != null) return (bool) incident_patch;
incident_patch = true;
return (bool) incident_patch;
}
}
}
}
6 changes: 4 additions & 2 deletions Source/RimNauts2/RimNauts2/Settings/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ public override void DoSettingsWindowContents(Rect inRect) {
buttons_view.End();

buttons_view = new Listing_Standard();
buttons_rectangle = new Rect(buttons_rectangle.x, buttons_rectangle.y + (30f * 3), buttons_rectangle.width, 90f);
buttons_rectangle = new Rect(buttons_rectangle.x, buttons_rectangle.y + 30f * 3, buttons_rectangle.width, 30f * 4);
buttons_view.Begin(buttons_rectangle);
toggle_buffer = add_checkbox(buttons_view, key: "RimNauts.multi_thread_update_option", Container.get_multi_threaded_update);
Container.multi_threaded_update = toggle_buffer;
toggle_buffer = add_checkbox(buttons_view, key: "RimNauts.mineral_rich_asteroids", Container.get_asteroid_ore_toggle);
Container.asteroid_ore_toggle = toggle_buffer;
toggle_buffer = add_checkbox(buttons_view, key: "RimNauts.mineral_rich_asteroids_messages_option", Container.get_asteroid_ore_verbose);
Container.asteroid_ore_verbose = toggle_buffer;
toggle_buffer = add_checkbox(buttons_view, key: "RimNauts.incident_patch", Container.get_incident_patch);
Container.incident_patch = toggle_buffer;
buttons_view.End();
// table header
Rect table_header_rectangle = new Rect(buttons_rectangle.x, buttons_rectangle.y + (30f * 4) + 4.0f, buttons_rectangle.width, 30f);
Rect table_header_rectangle = new Rect(buttons_rectangle.x, buttons_rectangle.y + (30f * 5) + 4.0f, buttons_rectangle.width, 30f);
Listing_Standard table_header_view = new Listing_Standard();
Widgets.DrawHighlight(table_header_rectangle);
table_header_view.Begin(table_header_rectangle);
Expand Down

0 comments on commit 5260518

Please sign in to comment.