Skip to content

Commit

Permalink
Updated source code
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLoneTec committed Feb 12, 2025
1 parent b4a031f commit c58fc68
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Mods/Minerals/Source/Minerals/Minerals.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
<HintPath>..\..\..\Hardcore-SK-Source\R1.1\Assemblies\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>references\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\Assemblies\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Core_SK">
<HintPath>..\..\..\..\..\public\Hardcore-SK\Mods\Core_SK\Assemblies\Core_SK.dll</HintPath>
<HintPath>..\..\..\Assemblies\Core_SK.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine.CoreModule">
<HintPath>references\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\..\..\Assemblies\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down
28 changes: 0 additions & 28 deletions Mods/Minerals/Source/Minerals/Minerals.userprefs

This file was deleted.

4 changes: 3 additions & 1 deletion Mods/Minerals/Source/Minerals/StaticMineral.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -124,6 +124,7 @@ public virtual ThingDef_StaticMineral attributes

public virtual void incPctYeild(float amount, Pawn miner)
{
//Log.Message("incPctYeild Entered with Pawn: " + miner.def.defName + ". Amount: " + amount);
// Increase yeild for when it is destroyed
float minerYield = 1f;
if (miner.def.race.IsMechanoid)
Expand Down Expand Up @@ -172,6 +173,7 @@ public virtual void incPctYeild(float amount, Pawn miner)
{
minerSkill = miner.skills.GetSkill(SkillDefOf.Mining).Level;
}
//Log.Message("minerSkill is: " + minerSkill);
float proportionDamaged = (float) Mathf.Min(amount, HitPoints) / (float) MaxHitPoints;
float proportionMined = proportionDamaged * minerYield;
yieldPct += proportionMined;
Expand Down
99 changes: 92 additions & 7 deletions Mods/Minerals/Source/Minerals/harmonyPatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
using RimWorld; // RimWorld specific functions
using Verse; // RimWorld universal objects
using RimWorld.Planet;
using System.Runtime.CompilerServices;
using PatchOperationWhatHappened;
using SK.Enlighten;
using System.IO;
using Verse.Noise;
using Log = Verse.Log;
using SK;

namespace Minerals
{
Expand Down Expand Up @@ -41,12 +48,29 @@ public static void MakeRocksAccordingToBiome(int tile, ref World __instance, ref
// Pick a set of random rocks
Rand.PushState();
Rand.Seed = tile;
List<ThingDef> list = (from d in DefDatabase<ThingDef>.AllDefs
where d.category == ThingCategory.Building && d.building.isNaturalRock && !d.building.isResourceRock &&
!d.IsSmoothed && d.defName != "GU_RoseQuartz" && d.defName != "AB_SlimeStone" &&
d.defName != "GU_AncientMetals" && d.defName != "AB_Cragstone" && d.defName != "AB_Obsidianstone" &&
d.defName != "BiomesIslands_CoralRock" && d.defName != "LavaRock" && d.defName != "AB_Mudstone"
select d).ToList<ThingDef>();

// Disabled since found great impact on tps. Skyarkhangel. 01.04.2024.
// Made list of stones hardcoded, until not found solution.

//List<ThingDef> list = (from d in DefDatabase<ThingDef>.AllDefs
// where d.category == ThingCategory.Building && d.building.isNaturalRock && !d.building.isResourceRock &&
// !d.IsSmoothed && d.defName != "GU_RoseQuartz" && d.defName != "AB_SlimeStone" &&
// d.defName != "GU_AncientMetals" && d.defName != "AB_Cragstone" && d.defName != "AB_Obsidianstone" &&
// d.defName != "BiomesIslands_CoralRock" && d.defName != "LavaRock" && d.defName != "AB_Mudstone"
// select d).ToList<ThingDef>();

List<ThingDef> list = new List<ThingDef>
{
ThingDefOf.Sandstone,
ThingDefOf.Granite,
ThingDef.Named("Slate"),
ThingDef.Named("Limestone"),
ThingDef.Named("Marble"),
ThingDef.Named("ZF_BasaltBase"),
ThingDef.Named("ZF_ClaystoneBase"),
ThingDef.Named("ZF_MudstoneBase")
};

int num = Rand.RangeInclusive(MineralsMain.Settings.terrainCountRangeSetting.min, MineralsMain.Settings.terrainCountRangeSetting.max);
if (num > list.Count)
{
Expand Down Expand Up @@ -135,7 +159,68 @@ public static void Prefix(ref IEnumerable<Thing> things)
}
things = replacementList;
}
}
}

[HarmonyPatch(typeof(GenStep_PreciousLump))]
[HarmonyPatch("Generate")]
[HarmonyPatch(new Type[] { typeof(Map), typeof(GenStepParams)})]
static class GenStep_PreciousLump_Patch
{
[HarmonyPrefix]
public static bool Prefix(GenStep_PreciousLump __instance, Map map, GenStepParams parms)
{
if (parms.sitePart != null && parms.sitePart.parms.preciousLumpResources != null)
__instance.forcedDefToScatter = parms.sitePart.parms.preciousLumpResources;
else
__instance.forcedDefToScatter = __instance.mineables.RandomElement<ThingDef>();

if (__instance.forcedDefToScatter is ThingDef_StaticMineral)
{
ThingDef_StaticMineral mineral = __instance.forcedDefToScatter as ThingDef_StaticMineral;
float averageDropAmount = 0;
float averageMarketValue = 0;
foreach (var item in mineral.randomlyDropResources)
{
averageDropAmount += item.DropProbability * item.CountPerDrop;
averageMarketValue += (item.DropProbability * item.CountPerDrop) * DefDatabase<ThingDef>.GetNamed(item.ResourceDefName).BaseMarketValue;
}
int count = mineral.randomlyDropResources.Count;
__instance.count = 1;
float randomRangeAmount = __instance.totalValueRange.RandomInRange;
int minimumLumps = Mathf.Max(Mathf.RoundToInt((averageMarketValue / __instance.totalValueRange.min) * 6),2);
__instance.forcedLumpSize = Mathf.Max(Mathf.RoundToInt(randomRangeAmount /
((averageDropAmount / count) * (averageMarketValue / count))), 1) + Rand.Range(minimumLumps, minimumLumps * 2);

float preRoundedValue = randomRangeAmount / (averageDropAmount / count) * (averageMarketValue / count);

//Log.Message("Calculation: " + randomRangeAmount + " / (" + averageDropAmount + " / " + count +") * (" + averageMarketValue + " / " + count + ") = " + preRoundedValue);
//Log.Message("Spawning Precious Lumps for: " + __instance.forcedDefToScatter.defName + ". Forced Lump size is: " + __instance.forcedLumpSize);

GenStep_ScatterLumpsMineable gen = new GenStep_ScatterLumpsMineable
{
forcedDefToScatter = __instance.forcedDefToScatter,
count = __instance.count,
forcedLumpSize = __instance.forcedLumpSize
};

gen.Generate(map,parms);

return false;
}

return true;
}
}

[HarmonyPatch(typeof(CompLongRangeMineralScanner))]
[HarmonyPatch("SetDefaultTargetMineral")]
static class SetDefaultTargetMineral_Patch
{
[HarmonyPostfix]
public static void Postfix(CompLongRangeMineralScanner __instance)
{
Traverse.Create(__instance).Field("targetMineable").SetValue(DefDatabase<ThingDef>.GetNamed("SolidOreGold"));
}
}
}
}

0 comments on commit c58fc68

Please sign in to comment.