Skip to content

Commit

Permalink
Updated Source code...again
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLoneTec committed Feb 12, 2025
1 parent c58fc68 commit b3c09dd
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 98 deletions.
Binary file modified Mods/Minerals/Assemblies/Minerals.dll
Binary file not shown.
Binary file removed Mods/Minerals/Assemblies/Minerals.dll.mdb
Binary file not shown.
12 changes: 12 additions & 0 deletions Mods/Minerals/Source/Minerals/DefOf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using RimWorld;
using Verse;
using Verse.AI;

namespace Minerals
{
[DefOf]
public static class ThingDefOfLocal
{
public static ThingDef SolidOreGold;
}
}
24 changes: 10 additions & 14 deletions Mods/Minerals/Source/Minerals/Minerals.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Krafs.Publicizer.2.3.0\build\Krafs.Publicizer.props" Condition="Exists('packages\Krafs.Publicizer.2.3.0\build\Krafs.Publicizer.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -9,6 +10,8 @@
<AssemblyName>Minerals</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
Expand All @@ -31,25 +34,13 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Hardcore-SK-Source\R1.1\Assemblies\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\Assemblies\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Core_SK">
<HintPath>..\..\..\Assemblies\Core_SK.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\Assemblies\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DefOf.cs" />
<Compile Include="events\NoticeMinerals.cs" />
<Compile Include="events\RichOreDeposit.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -66,7 +57,11 @@
<Compile Include="events\BlueSnow.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup />
<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.3.3" ExcludeAssets="runtime" />
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.3901" />
<PackageReference Include="Krafs.Publicizer" Version="2.2.1" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\Defs\ThingsDefs_Minerals\StaticMineralBase.xml">
<Link>xml\StaticMineralBase.xml</Link>
Expand All @@ -83,5 +78,6 @@
<None Include="..\..\Defs\ThingsDefs_Resources\Item_Resource_Gems.xml">
<Link>xml\Item_Resource_Gems.xml</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
</Project>
11 changes: 0 additions & 11 deletions Mods/Minerals/Source/Minerals/StaticMineral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,17 +1410,6 @@ Predicate<IntVec3> isValidSite(Map myMap, IntVec3 myPosition)
{
return c => c.DistanceTo(myPosition) <= spawnRadius && CanSpawnAt(myMap, c);
}

Predicate<IntVec3> isValidSiteDebug(Map myMap, IntVec3 myPosition)
{
return c =>
{
Log.Message("TryFindReproductionDestination: isValidSiteDebug: c: " + c);
Log.Message("TryFindReproductionDestination: isValidSiteDebug: c.DistanceTo(myPosition): " + c.DistanceTo(myPosition));
Log.Message("TryFindReproductionDestination: isValidSiteDebug: CanSpawnAt(myMap, c): " + CanSpawnAt(myMap, c));
return c.DistanceTo(myPosition) <= spawnRadius && CanSpawnAt(myMap, c);
};
}
}


Expand Down
100 changes: 27 additions & 73 deletions Mods/Minerals/Source/Minerals/harmonyPatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,100 +19,54 @@

namespace Minerals
{



/* Replace slate with basalt in the Alpha biomes Pyroclastic Conflagration biome*/
[HarmonyPatch(typeof(World))]
[HarmonyPatch("NaturalRockTypesIn")]
[HarmonyPatch(typeof(World), nameof(World.NaturalRockTypesIn))]
public static class Minerals_World_NaturalRockTypesIn_Patch
{
private static List<ThingDef> allRockDefs;

[HarmonyPostfix]
public static void MakeRocksAccordingToBiome(int tile, ref World __instance, ref IEnumerable<ThingDef> __result)
public static IEnumerable<ThingDef> MakeRocksAccordingToBiome(IEnumerable<ThingDef> results, int tile)
{
if (__instance.grid.tiles[tile].biome.defName == "AB_PyroclasticConflagration")
if (allRockDefs.NullOrEmpty())
{
List<ThingDef> replacedList = new List<ThingDef>();
ThingDef item = DefDatabase<ThingDef>.GetNamed("AB_Obsidianstone");
replacedList.Add(item);
replacedList.Add(DefDatabase<ThingDef>.GetNamed("ZF_BasaltBase"));

__result = replacedList;
allRockDefs = DefDatabase<ThingDef>.AllDefs.Where(x =>
(x.building?.buildingTags?.Contains("BaseRock") ?? false) && !x.IsSmoothed)
.ToList();
}
else if (__instance.grid.tiles[tile].biome.defName == "AB_OcularForest" || __instance.grid.tiles[tile].biome.defName == "AB_GallatrossGraveyard" || __instance.grid.tiles[tile].biome.defName == "AB_GelatinousSuperorganism" || __instance.grid.tiles[tile].biome.defName == "AB_MechanoidIntrusion" || __instance.grid.tiles[tile].biome.defName == "AB_RockyCrags") {
return;
// Pick a set of random rocks
Rand.PushState();
Rand.Seed = tile;
int num = Rand.RangeInclusive(MineralsMain.Settings.terrainCountRangeSetting.min, MineralsMain.Settings.terrainCountRangeSetting.max);
if (num > allRockDefs.Count)
{
num = allRockDefs.Count;
}
else
List<ThingDef> tempRockDefList = new List<ThingDef>(allRockDefs).Distinct().ToList();
List<ThingDef> resultList = tempRockDefList.TakeRandom(num).ToList();
for (int i = 0; i < num; i++)
{
// Pick a set of random rocks
Rand.PushState();
Rand.Seed = tile;

// 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)
{
num = list.Count;
}
List<ThingDef> list2 = new List<ThingDef>();
for (int i = 0; i < num; i++)
{
ThingDef item = list.RandomElement<ThingDef>();
list.Remove(item);
list2.Add(item);
}
Rand.PopState();
__result = list2;
yield return resultList[i];
}
Rand.PopState();
}
}



[StaticConstructorOnStartup]
static class HarmonyPatches
{
// this static constructor runs to create a HarmonyInstance and install a patch.
static HarmonyPatches()
{
Harmony harmony = new Harmony("com.zacharyfoster.minerals");

// Spawn rocks on map generation
MethodInfo targetmethod = AccessTools.Method(typeof(GenStep_RockChunks), "Generate");
HarmonyMethod postfixmethod = new HarmonyMethod(typeof(HarmonyPatches).GetMethod("initNewMapRocks"));
harmony.Patch(targetmethod, null, postfixmethod);

// Spawn ice after plants
MethodInfo icetargetmethod = AccessTools.Method(typeof(GenStep_Plants), "Generate");
HarmonyMethod icepostfixmethod = new HarmonyMethod(typeof(HarmonyPatches).GetMethod("initNewMapIce"));
harmony.Patch(icetargetmethod, null, icepostfixmethod);


harmony.PatchAll();


}

public static void initNewMapRocks(GenStep_RockChunks __instance, Map map)
Expand All @@ -127,7 +81,7 @@ public static void initNewMapIce(GenStep_RockChunks __instance, Map map)

[HarmonyPatch(typeof(SK.SkyfallerUtil))]
[HarmonyPatch("SpawnSkyfaller")]
[HarmonyPatch(new Type[] {typeof(ThingDef), typeof(IEnumerable<Thing>), typeof(IntVec3), typeof(Map) })]
[HarmonyPatch(new Type[] { typeof(ThingDef), typeof(IEnumerable<Thing>), typeof(IntVec3), typeof(Map) })]
static class ImpactPatch
{
[HarmonyPrefix]
Expand All @@ -137,7 +91,7 @@ public static void Prefix(ref IEnumerable<Thing> things)
foreach (Thing item in things)
{
Thing toReturn = item;
if (item.def.mineable && (! StaticMineral.isMineral(item)))
if (item.def.mineable && (!StaticMineral.isMineral(item)))
{
// check if any of the minerals replace this one
foreach (ThingDef_StaticMineral mineralType in DefDatabase<ThingDef_StaticMineral>.AllDefs)
Expand All @@ -149,7 +103,7 @@ public static void Prefix(ref IEnumerable<Thing> things)

if (mineralType.ThingsToReplace.Any(item.def.defName.Equals))
{
toReturn = (StaticMineral) ThingMaker.MakeThing(mineralType);
toReturn = (StaticMineral)ThingMaker.MakeThing(mineralType);
break;
}
}
Expand All @@ -163,7 +117,7 @@ public static void Prefix(ref IEnumerable<Thing> things)

[HarmonyPatch(typeof(GenStep_PreciousLump))]
[HarmonyPatch("Generate")]
[HarmonyPatch(new Type[] { typeof(Map), typeof(GenStepParams)})]
[HarmonyPatch(new Type[] { typeof(Map), typeof(GenStepParams) })]
static class GenStep_PreciousLump_Patch
{
[HarmonyPrefix]
Expand All @@ -187,8 +141,8 @@ public static bool Prefix(GenStep_PreciousLump __instance, Map map, GenStepParam
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 /
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);
Expand All @@ -203,7 +157,7 @@ public static bool Prefix(GenStep_PreciousLump __instance, Map map, GenStepParam
forcedLumpSize = __instance.forcedLumpSize
};

gen.Generate(map,parms);
gen.Generate(map, parms);

return false;
}
Expand All @@ -219,7 +173,7 @@ static class SetDefaultTargetMineral_Patch
[HarmonyPostfix]
public static void Postfix(CompLongRangeMineralScanner __instance)
{
Traverse.Create(__instance).Field("targetMineable").SetValue(DefDatabase<ThingDef>.GetNamed("SolidOreGold"));
Traverse.Create(__instance).Field("targetMineable").SetValue(ThingDefOfLocal.SolidOreGold);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Mods/Minerals/Source/Minerals/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Krafs.Publicizer" version="2.3.0" targetFramework="net48" developmentDependency="true" />
<package id="Lib.Harmony" version="2.3.5" targetFramework="net48" />
</packages>

0 comments on commit b3c09dd

Please sign in to comment.