Skip to content

Commit

Permalink
1.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
XeoNovaDan committed Oct 18, 2018
1 parent 1582f5f commit 2974f95
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 59 deletions.
6 changes: 3 additions & 3 deletions About/About.xml
Expand Up @@ -3,10 +3,10 @@
<name>[XND] Watermill Tweaks</name>
<author>XeoNovaDan</author>
<url>https://ludeon.com/forums/index.php?topic=29503.0</url>
<targetVersion>0.19.2009</targetVersion>
<description>Current Version: v1.1.3 (28th August 2018)\n\nChanges the watermill generator in several different ways:
<targetVersion>1.0.2059</targetVersion>
<description>Current Version: v1.2 (18th October 2018)\n\nChanges the watermill generator in several different ways:
* Increases its base power production from 1100W to 1400W
* Power production is directly influenced by the season
* Its power production decreases if temperatures are bad
* Its power production decreases if temperatures are too low or too high
* Adds a new incident which affects watermill generators, both good and bad</description>
</ModMetaData>
2 changes: 1 addition & 1 deletion About/Manifest.xml
@@ -1,6 +1,6 @@
<Manifest>
<identifier>WatermillTweaks</identifier>
<version>1.1.3</version>
<version>1.2</version>
<manifestUri>https://rawgit.com/XeoNovaDan/WatermillTweaks/master/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/XeoNovaDan/WatermillTweaks/releases</downloadUri>
</Manifest>
Binary file modified About/Preview.png
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/Preview.xcf
Binary file not shown.
Binary file modified Assemblies/WatermillTweaks.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Defs/Storyteller/Incidents_Map_Misc.xml
Expand Up @@ -10,7 +10,7 @@
</targetTags>
<workerClass>WatermillTweaks.IncidentWorker_TurbulentWaters</workerClass>
<gameCondition>TurbulentWaters</gameCondition>
<letterDef>NegativeEvent</letterDef>
<letterDef>NeutralEvent</letterDef>
<letterLabel>Turbulent waters</letterLabel>
<letterText>Due to some heavy rainfall upstream or some other disturbances, the river is flowing more quickly than normal. Watermill generators will produce more power but will also get damaged over time.</letterText>
<baseChance>0.5</baseChance>
Expand Down
Binary file not shown.
Binary file modified Source/WatermillTweaks/.vs/WatermillTweaks/v15/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
56 changes: 6 additions & 50 deletions Source/WatermillTweaks/HarmonyPatches.cs
Expand Up @@ -15,21 +15,9 @@ static class HarmonyPatches

private static readonly Type patchType = typeof(HarmonyPatches);

private const float PowerProductionFactorSpring = 1.3f;
private const float PowerProductionFactorSummer = 1f;
private const float PowerProductionFactorFall = 0.9f;
private const float PowerProductionFactorWinter = 0.8f;

private const float ZeroPowerProductionLowTemp = -40f;
private const float HalfPowerProductionLowTemp = -10f;
private const float FullPowerProductionLowTemp = 0f;
private const float FullPowerProductionHighTemp = 50f;
private const float HalfPowerProductionHighTemp = 60f;
private const float ZeroPowerProductionHighTemp = 90f;

static HarmonyPatches()
{
HarmonyInstance h = HarmonyInstance.Create("XeoNovaDan.BetterWatermillGenerators");
HarmonyInstance h = HarmonyInstance.Create("XeoNovaDan.WatermillTweaks");

h.Patch(AccessTools.Property(typeof(CompPowerPlantWater), "DesiredPowerOutput").GetGetMethod(true), null,
new HarmonyMethod(patchType, nameof(PostfixDesiredPowerOutput)));
Expand All @@ -41,10 +29,10 @@ static HarmonyPatches()
public static void PostfixDesiredPowerOutput(CompPowerPlantWater __instance, ref float __result)
{
// Season
__result *= SeasonalPowerOutputFactor(GetWatermillMapSeason(__instance.parent));
__result *= WatermillUtility.SeasonalPowerOutputFactorFor(__instance.parent.GetMapSeason());

// Outdoor Temperature
__result *= PowerOutputFactorFromTemperatureCurve.Evaluate(__instance.parent.MapHeld.mapTemperature.OutdoorTemp);
__result *= WatermillUtility.GetTemperatureToPowerOutputFactorCurveFor(__instance.parent).Evaluate(__instance.parent.MapHeld.mapTemperature.OutdoorTemp);

// Turbulent Waters
if (__instance.parent.MapHeld.GameConditionManager.ConditionIsActive(BWG_GameConditionDefOf.TurbulentWaters))
Expand All @@ -54,47 +42,15 @@ public static void PostfixDesiredPowerOutput(CompPowerPlantWater __instance, ref
public static void PostfixCompInspectStringExtra(CompPowerPlantWater __instance, ref string __result)
{
// Season
Season season = GetWatermillMapSeason(__instance.parent);
float seasonalPowerProductionFactor = SeasonalPowerOutputFactor(season);
Season season = __instance.parent.GetMapSeason();
float seasonalPowerProductionFactor = WatermillUtility.SeasonalPowerOutputFactorFor(season);
__result += "\n" + season.LabelCap() + ": x" + seasonalPowerProductionFactor.ToStringPercent();

// Outdoor Temperature
float tempPowerProductionFactor = PowerOutputFactorFromTemperatureCurve.Evaluate(__instance.parent.MapHeld.mapTemperature.OutdoorTemp);
float tempPowerProductionFactor = WatermillUtility.GetTemperatureToPowerOutputFactorCurveFor(__instance.parent).Evaluate(__instance.parent.MapHeld.mapTemperature.OutdoorTemp);
if (tempPowerProductionFactor != 1f)
__result += "\n" + "BadTemperature".Translate().CapitalizeFirst() + ": x" + tempPowerProductionFactor.ToStringPercent();
}

private static Season GetWatermillMapSeason(Thing powerPlant)
{
return GenDate.Season(Find.TickManager.TicksAbs, Find.WorldGrid.LongLatOf(powerPlant.MapHeld.Tile));
}

private static float SeasonalPowerOutputFactor(Season season)
{
switch (season)
{
case Season.PermanentWinter:
return PowerProductionFactorWinter;
case Season.Winter:
return PowerProductionFactorWinter;
case Season.Fall:
return PowerProductionFactorFall;
case Season.Spring:
return PowerProductionFactorSpring;
default:
return PowerProductionFactorSummer;
}
}

private static SimpleCurve PowerOutputFactorFromTemperatureCurve = new SimpleCurve
{
{ new CurvePoint(ZeroPowerProductionLowTemp, 0f), true },
{ new CurvePoint(HalfPowerProductionLowTemp, 0.5f), true },
{ new CurvePoint(FullPowerProductionLowTemp, 1f), true },
{ new CurvePoint(FullPowerProductionHighTemp, 1f), true },
{ new CurvePoint(HalfPowerProductionHighTemp, 0.5f), true },
{ new CurvePoint(ZeroPowerProductionHighTemp, 0f), true },
};

}
}
2 changes: 1 addition & 1 deletion Source/WatermillTweaks/IncidentWorker_TurbulentWaters.cs
Expand Up @@ -20,7 +20,7 @@ public override float AdjustedChance
{
if (map != null)
{
RiverDef river = map.TileInfo.Rivers[(map.TileInfo.Rivers.Count - 1)].river;
RiverDef river = map.GetRiver();
if (river == RiverDefOf.River)
finalCommonality = def.baseChance;
else if (river == RiverDefOf.LargeRiver)
Expand Down
5 changes: 3 additions & 2 deletions Source/WatermillTweaks/WatermillTweaks.csproj
Expand Up @@ -35,7 +35,7 @@
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -45,7 +45,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand All @@ -56,6 +56,7 @@
<Compile Include="IncidentWorker_TurbulentWaters.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RiverDefOf.cs" />
<Compile Include="WatermillUtility.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
72 changes: 72 additions & 0 deletions Source/WatermillTweaks/WatermillUtility.cs
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;

namespace WatermillTweaks
{
public static class WatermillUtility
{

private const float PowerProductionFactorSpring = 1.2f;
private const float PowerProductionFactorSummer = 1f;
private const float PowerProductionFactorFall = 1.1f;
private const float PowerProductionFactorWinter = 0.7f;

//private const float ZeroPowerProductionLowTemp = -40f;
//private const float HalfPowerProductionLowTemp = -10f;
private const float FullPowerProductionLowTemp = 0f;
private const float FullPowerProductionHighTemp = 50f;
private const float HalfPowerProductionHighTemp = 60f;
private const float ZeroPowerProductionHighTemp = 90f;

public static Season GetMapSeason(this Thing thing) =>
GenDate.Season(Find.TickManager.TicksAbs, Find.WorldGrid.LongLatOf(thing.MapHeld.Tile));

public static RiverDef GetRiver(this Map map) =>
map.TileInfo.Rivers.First().river;

public static float SeasonalPowerOutputFactorFor(Season season)
{
switch (season)
{
case (Season.PermanentWinter | Season.Winter):
return PowerProductionFactorWinter;
case Season.Fall:
return PowerProductionFactorFall;
case Season.Spring:
return PowerProductionFactorSpring;
default:
return PowerProductionFactorSummer;
}
}

public static SimpleCurve GetTemperatureToPowerOutputFactorCurveFor(Thing thing)
{
RiverDef river = thing.Map.GetRiver();
float halfPowerProductionLowTemp = LowPowerProductionDict[river];

return new SimpleCurve()
{
new CurvePoint(Mathf.RoundToInt(halfPowerProductionLowTemp * 1.5f), 0f),
new CurvePoint(halfPowerProductionLowTemp, 0.5f),
new CurvePoint(FullPowerProductionLowTemp, 1f),
new CurvePoint(FullPowerProductionHighTemp, 1f),
new CurvePoint(HalfPowerProductionHighTemp, 0.5f),
new CurvePoint(ZeroPowerProductionHighTemp, 0f)
};
}

private static readonly Dictionary<RiverDef, float> LowPowerProductionDict = new Dictionary<RiverDef, float>()
{
{ RiverDefOf.Creek, -5f },
{ RiverDefOf.River, -10f },
{ RiverDefOf.LargeRiver, -15f },
{ RiverDefOf.HugeRiver, -20f },
};

}
}
Binary file not shown.
@@ -1 +1 @@
f1f02df9e5eade6a376db0eff59e2e7a5162b966
d061d2c908a8112dc39d0b29286b427af139ea92
Expand Up @@ -6,3 +6,7 @@ E:\Documents\My RimWorld Mods\B19\WatermillTweaks\Assemblies\WatermillTweaks.dll
E:\Documents\My RimWorld Mods\B19\WatermillTweaks\Source\WatermillTweaks\obj\Debug\WatermillTweaks.csprojAssemblyReference.cache
E:\Documents\My RimWorld Mods\B19\WatermillTweaks\Source\WatermillTweaks\obj\Debug\WatermillTweaks.csproj.CoreCompileInputs.cache
E:\Documents\My RimWorld Mods\B19\WatermillTweaks\Source\WatermillTweaks\obj\Debug\WatermillTweaks.dll
E:\Documents\GitHub\WatermillTweaks\Assemblies\WatermillTweaks.dll
E:\Documents\GitHub\WatermillTweaks\Source\WatermillTweaks\obj\Debug\WatermillTweaks.csprojAssemblyReference.cache
E:\Documents\GitHub\WatermillTweaks\Source\WatermillTweaks\obj\Debug\WatermillTweaks.csproj.CoreCompileInputs.cache
E:\Documents\GitHub\WatermillTweaks\Source\WatermillTweaks\obj\Debug\WatermillTweaks.dll
Binary file not shown.
Binary file modified Source/WatermillTweaks/obj/Debug/WatermillTweaks.dll
Binary file not shown.

0 comments on commit 2974f95

Please sign in to comment.