Skip to content

Commit

Permalink
Updating to A18
Browse files Browse the repository at this point in the history
  • Loading branch information
KiameV committed Oct 28, 2017
1 parent 5dd4601 commit 476e27a
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 24 deletions.
2 changes: 1 addition & 1 deletion About/PublishedFileId.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
933019589
1182992587
4 changes: 2 additions & 2 deletions About/about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModMetaData>
<name>Change Research Speed</name>
<author>Kiame Vivacity</author>
<url>http://steamcommunity.com/sharedfiles/filedetails/?id=933019589</url>
<targetVersion>0.17.1557</targetVersion>
<url>https://ludeon.com/forums/index.php?topic=32854</url>
<targetVersion>0.18.0</targetVersion>
<description>Change the speed of research both globally and per-save whenever you want.</description>
</ModMetaData>
Binary file modified About/gamegoing.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified About/nogame.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Languages/English/Keyed/ModifyResearchTime.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<ModifyResearchTime>Modify Research Time</ModifyResearchTime>
<ModifyResearchTime>Change Research Time</ModifyResearchTime>
<ModifyResearchTime.Global>Global</ModifyResearchTime.Global>
<ModifyResearchTime.CurrentGame>Current Game</ModifyResearchTime.CurrentGame>
<ModifyResearchTime.Factor>Factor</ModifyResearchTime.Factor>
<ModifyResearchTime.Apply>Apply</ModifyResearchTime.Apply>
<ModifyResearchTime.ResearchTimesUpdated>Research Times Updated</ModifyResearchTime.ResearchTimesUpdated>
<ModifyResearchTime.AllowTechAdvance>Allow Tech Advance</ModifyResearchTime.AllowTechAdvance>
<ModifyResearchTime.AllowTechAdvanceToolTip>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.</ModifyResearchTime.AllowTechAdvanceToolTip>
</LanguageData>
7 changes: 4 additions & 3 deletions Source/FloatInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Verse;
using RimWorld;
using Verse;

namespace ModifyResearchTime
{
Expand Down Expand Up @@ -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;
Expand Down
70 changes: 69 additions & 1 deletion Source/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Harmony;
using RimWorld;
using System.Reflection;
using System.Text;
using Verse;

namespace ModifyResearchTime
Expand All @@ -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");
}
}

Expand All @@ -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<ResearchProjectDef>.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());
}
}
}
}
20 changes: 16 additions & 4 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using RimWorld;
using UnityEngine;
using Verse;

namespace ModifyResearchTime
Expand Down Expand Up @@ -28,7 +29,7 @@ public override void DoSettingsWindowContents(Rect rect)
if (Settings.GlobalFactor.ValidateInput())
{
base.GetSettings<Settings>().Write();
Messages.Message("ModifyResearchTime.Global".Translate() + " " + "ModifyResearchTime.ResearchTimesUpdated".Translate(), MessageSound.Benefit);
Messages.Message("ModifyResearchTime.Global".Translate() + " " + "ModifyResearchTime.ResearchTimesUpdated".Translate(), MessageTypeDefOf.PositiveEvent);
}
}

Expand All @@ -44,24 +45,35 @@ 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();
}
}

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<string>(ref (GlobalFactor.AsString), "ModifyResearchTime.Factor", "1.00", false);
Scribe_Values.Look<bool>(ref AllowTechAdvance, "ModifyResearchTime.AllowTechAdvance", false, false);
}
}
}
17 changes: 5 additions & 12 deletions Source/WorldComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Expand Down

0 comments on commit 476e27a

Please sign in to comment.