diff --git a/About/PublishedFileId.txt b/About/PublishedFileId.txt index 0fd5af1..7069845 100644 --- a/About/PublishedFileId.txt +++ b/About/PublishedFileId.txt @@ -1 +1 @@ -933019589 \ No newline at end of file +1182992587 \ No newline at end of file diff --git a/About/about.xml b/About/about.xml index 2207b3f..c67b0fa 100644 --- a/About/about.xml +++ b/About/about.xml @@ -2,7 +2,7 @@ Change Research Speed Kiame Vivacity - http://steamcommunity.com/sharedfiles/filedetails/?id=933019589 - 0.17.1557 + https://ludeon.com/forums/index.php?topic=32854 + 0.18.0 Change the speed of research both globally and per-save whenever you want. \ No newline at end of file diff --git a/About/gamegoing.jpg b/About/gamegoing.jpg index 5b0fd9f..1ff55cd 100644 Binary files a/About/gamegoing.jpg and b/About/gamegoing.jpg differ diff --git a/About/nogame.jpg b/About/nogame.jpg index a25d8ab..e68b1ae 100644 Binary files a/About/nogame.jpg and b/About/nogame.jpg differ diff --git a/Languages/English/Keyed/ModifyResearchTime.xml b/Languages/English/Keyed/ModifyResearchTime.xml index a9f35bb..d382b8e 100644 --- a/Languages/English/Keyed/ModifyResearchTime.xml +++ b/Languages/English/Keyed/ModifyResearchTime.xml @@ -1,9 +1,11 @@  - Modify Research Time + Change Research Time Global Current Game Factor Apply Research Times Updated + Allow Tech Advance + If the colony has either researched all current technology plus one technology from a future tech level OR the sum of all researched techs is greater than the number of techs to required to acquire the next tech level, the colony's tech level will go to the next level. \ No newline at end of file diff --git a/Source/FloatInput.cs b/Source/FloatInput.cs index af35243..2bfdd42 100644 --- a/Source/FloatInput.cs +++ b/Source/FloatInput.cs @@ -1,4 +1,5 @@ -using Verse; +using RimWorld; +using Verse; namespace ModifyResearchTime { @@ -36,13 +37,13 @@ public bool ValidateInput() { if (f <= 0) { - Messages.Message(name + " cannot be less than or equal to 0.", MessageSound.RejectInput); + Messages.Message(name + " cannot be less than or equal to 0.", MessageTypeDefOf.RejectInput); return false; } } else { - Messages.Message("Unable to parse " + name + " to a number.", MessageSound.RejectInput); + Messages.Message("Unable to parse " + name + " to a number.", MessageTypeDefOf.RejectInput); return false; } return true; diff --git a/Source/Main.cs b/Source/Main.cs index 187f6fb..becd537 100644 --- a/Source/Main.cs +++ b/Source/Main.cs @@ -1,5 +1,7 @@ using Harmony; +using RimWorld; using System.Reflection; +using System.Text; using Verse; namespace ModifyResearchTime @@ -12,7 +14,8 @@ static Main() var harmony = HarmonyInstance.Create("com.modifyresearchtime.rimworld.mod"); harmony.PatchAll(Assembly.GetExecutingAssembly()); - Log.Message("ModifyResearchTime: Adding Harmony Postfix to DefDatabase.ErrorCheckAllDefs"); + Log.Message("ModifyResearchTime: Adding Harmony Postfix to Game.InitNewGame"); + Log.Message("TechLevelAdvance: Adding Harmony Postfix to ResearchManager.ReapplyAllMods"); } } @@ -24,4 +27,69 @@ static void Postfix() WorldComp.InitializeNewGame(); } } + + [HarmonyPatch(typeof(ResearchManager), "ReapplyAllMods")] + static class Patch_ResearchManager_ReapplyAllMods + { + static void Postfix() + { + TechLevel techLevel = Faction.OfPlayer.def.techLevel; +#if DEBUG + Log.Warning("Tech Level: " + techLevel); +#endif + int countCurrentAndPreviousTechLevelFinished = 0; + int totalCurrentAndPreviousTechLevel = 0; + int countNextTechLevelFinished = 0; + + foreach (ResearchProjectDef def in DefDatabase.AllDefs) + { + if (def.techLevel <= techLevel) + { + ++totalCurrentAndPreviousTechLevel; + if (def.IsFinished) + { + ++countCurrentAndPreviousTechLevelFinished; + } +#if DEBUG + else + { + Log.Warning("Still need to reseach: " + def.defName); + } +#endif + } + else if (def.techLevel == techLevel + 1) + { + if (def.IsFinished) + { + ++countNextTechLevelFinished; + } + } + } +#if DEBUG + Log.Warning("Finished: " + countCurrentAndPreviousTechLevelFinished + " Next Tech Level Finished: " + countNextTechLevelFinished + " Total Techs: " + totalCurrentAndPreviousTechLevel); +#endif + if (countCurrentAndPreviousTechLevelFinished + countNextTechLevelFinished >= totalCurrentAndPreviousTechLevel && countNextTechLevelFinished > 0) + { + if (Scribe.mode == LoadSaveMode.Inactive) + { + // Only display this message is not loading + Messages.Message("Advancing Tech Level from [" + techLevel.ToString() + "] to [" + (techLevel + 1).ToString() + "].", MessageTypeDefOf.PositiveEvent); + } + techLevel += 1; + Faction.OfPlayer.def.techLevel = techLevel; + } + else + { + StringBuilder sb = new StringBuilder( + "Tech Advance: Need to research ["); + sb.Append(totalCurrentAndPreviousTechLevel - countCurrentAndPreviousTechLevelFinished - countNextTechLevelFinished); + sb.Append("] more technologies"); + if (countNextTechLevelFinished == 0) + { + sb.Append(" and at least one next-generation technology."); + } + Log.Message(sb.ToString()); + } + } + } } diff --git a/Source/Settings.cs b/Source/Settings.cs index d82642f..2242a66 100644 --- a/Source/Settings.cs +++ b/Source/Settings.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using RimWorld; +using UnityEngine; using Verse; namespace ModifyResearchTime @@ -28,7 +29,7 @@ public override void DoSettingsWindowContents(Rect rect) if (Settings.GlobalFactor.ValidateInput()) { base.GetSettings().Write(); - Messages.Message("ModifyResearchTime.Global".Translate() + " " + "ModifyResearchTime.ResearchTimesUpdated".Translate(), MessageSound.Benefit); + Messages.Message("ModifyResearchTime.Global".Translate() + " " + "ModifyResearchTime.ResearchTimesUpdated".Translate(), MessageTypeDefOf.PositiveEvent); } } @@ -44,12 +45,21 @@ public override void DoSettingsWindowContents(Rect rect) if (Settings.GameFactor.ValidateInput()) { WorldComp.UpdateFactor(Settings.GameFactor.AsFloat); - Messages.Message("ModifyResearchTime.CurrentGame".Translate() + " " + "ModifyResearchTime.ResearchTimesUpdated".Translate(), MessageSound.Benefit); + Messages.Message("ModifyResearchTime.CurrentGame".Translate() + " " + "ModifyResearchTime.ResearchTimesUpdated".Translate(), MessageTypeDefOf.PositiveEvent); } } - } + GUI.EndGroup(); + + Listing_Standard l = new Listing_Standard(GameFont.Small); + l.Begin(new Rect(0, 300, 400, 60)); + l.ColumnWidth = 300; + l.CheckboxLabeled( + "ModifyResearchTime.AllowTechAdvance".Translate(), + ref Settings.AllowTechAdvance, + "ModifyResearchTime.AllowTechAdvanceToolTip".Translate()); + l.End(); } } @@ -57,11 +67,13 @@ class Settings : ModSettings { public static readonly FloatInput GlobalFactor = new FloatInput("Global Research Time Factor"); public static readonly FloatInput GameFactor = new FloatInput("Game Research Time Factor"); + public static bool AllowTechAdvance = false; public override void ExposeData() { base.ExposeData(); Scribe_Values.Look(ref (GlobalFactor.AsString), "ModifyResearchTime.Factor", "1.00", false); + Scribe_Values.Look(ref AllowTechAdvance, "ModifyResearchTime.AllowTechAdvance", false, false); } } } \ No newline at end of file diff --git a/Source/WorldComp.cs b/Source/WorldComp.cs index c5eab17..5c98fe4 100644 --- a/Source/WorldComp.cs +++ b/Source/WorldComp.cs @@ -15,14 +15,12 @@ public WorldComp(World world) : base(world) public static void InitializeNewGame() { - if (Instance == null) - { - Log.Error("WorldComp.Instance is null."); - return; - } Settings.GameFactor.Copy(Settings.GlobalFactor); - Instance.currentFactor = Settings.GlobalFactor.AsFloat; + Instance.currentFactor = Settings.GameFactor.AsFloat; ResearchTimeUtil.ApplyFactor(1, Instance.currentFactor); +#if DEBUG + Log.Warning("InitializeNewGame: Global: " + Settings.GlobalFactor.AsString + " Game: " + Settings.GameFactor.AsString); +#endif } public override void ExposeData() @@ -32,17 +30,12 @@ public override void ExposeData() Settings.GameFactor.AsFloat = this.currentFactor; if (Scribe.mode == LoadSaveMode.PostLoadInit) { - ResearchTimeUtil.ApplyFactor(currentFactor, currentFactor); + ResearchTimeUtil.ApplyFactor(1, currentFactor); } } internal static void UpdateFactor(float newFactor) { - if (Instance == null) - { - Log.Error("WorldComp Instance is null."); - return; - } if (Instance.currentFactor != newFactor) { ResearchTimeUtil.ApplyFactor(Instance.currentFactor, newFactor);