Skip to content

Commit

Permalink
Updated for Rimworld 1.4; Added smarter work tab settings;
Browse files Browse the repository at this point in the history
  • Loading branch information
Willer, Armin committed Oct 23, 2022
1 parent f99475b commit 1518262
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 90 deletions.
3 changes: 2 additions & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<li>1.1</li>
<li>1.2</li>
<li>1.3</li>
<li>1.4</li>
</supportedVersions>
<packageId>Heremeus.MedicalDissection</packageId>
<description>Medical Dissection adds a dissection table to the game, allowing your doctors to train on human corpses. You can add the mod to an existing save.
Expand All @@ -20,7 +21,7 @@ Feature overview
- A corpse can only be dissected once (A "Allow dissected" and "Allow not dissected" filter can help you to set up your storages and butcher bills efficiently)
- Custom thoughts and tales

v2.6
v2.8
</description>
<modDependencies>
<li>
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>MedicalDissection</identifier>
<version>2.6</version>
<version>2.8</version>
<dependencies>
<li>HugsLib</li>
<li>Harmony</li>
Expand Down
2 changes: 1 addition & 1 deletion About/Version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!--overrideVersion>1.0.0</overrideVersion-->
<!-- Optional. Use this to specify the version of HugsLib you are targeting.
See https://github.com/UnlimitedHugs/RimworldHugsLib/releases for the current version of the library.-->
<requiredLibraryVersion>9.0.0</requiredLibraryVersion>
<requiredLibraryVersion>10.0.0</requiredLibraryVersion>
<!-- Optional. This is read by the build.js script for the purpose of release publishing. Not used if you don't use the script. -->
<gitHubRepository>UnlimitedHugs/RimworldHugsLibChecker</gitHubRepository>
</VersionData>
1 change: 0 additions & 1 deletion Common/Defs/WorkTypeDefs/WorkTypes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<description>Train Medicine by dissecting corpses.\n(Medical Dissection mod)</description>
<verb>dissect</verb>
<naturalPriority>478</naturalPriority>
<alwaysStartActive>true</alwaysStartActive>
<relevantSkills>
<li>Medicine</li>
</relevantSkills>
Expand Down
5 changes: 5 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
<li>Common</li>
<li>v1.3</li>
</v1.3>
<v1.4>
<li>/</li>
<li>Common</li>
<li>v1.4</li>
</v1.4>
</loadFolders>
10 changes: 5 additions & 5 deletions Source/HMDissection/Dissection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public Dissection() : base()
Singleton = this;
}

public override void StaticInitialize()
{
base.StaticInitialize();
HarmonyPatches.Patch();
public override void Initialize()
{
base.Initialize();
HarmonyPatches.Patch();
}

public override void DefsLoaded()
{
Log.Message("Medical Dissection v2.5 loaded");
Log.Message("Medical Dissection v2.8 loaded");
expHandle = Settings.GetHandle("expPerCorpse", "Dissection_ExpSetting_title".Translate(), "Dissection_ExpSetting_desc".Translate(), 3000, Validators.IntRangeValidator(0, 1000000));
expHandle.SpinnerIncrement = 100;
ignoreDailyLimitHandle = Settings.GetHandle("ignoreDailyLimit", "Dissection_DailyLimitSetting_title".Translate(), "Dissection_DailyLimitSetting_desc".Translate(), false);
Expand Down
1 change: 1 addition & 0 deletions Source/HMDissection/DissectionDefOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public static class DissectionDefOf
public static HediffDef DissectedHediff;
public static BodyPartDef Lung;
public static JobDef DoDissectionBill;
public static WorkTypeDef MedicalTraining;
}
}
153 changes: 77 additions & 76 deletions Source/HMDissection/HMDissection.csproj
Original file line number Diff line number Diff line change
@@ -1,83 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5E782404-F6C3-41C0-9B55-B10DB1145145}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HMDissection</RootNamespace>
<AssemblyName>HMDissection</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\v1.3\Assemblies\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\v1.3\Assemblies\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Lib.Harmony.2.1.0\lib\net472\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HugsLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\UnlimitedHugs.Rimworld.HugsLib.9.0.0\lib\net472\HugsLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CompatibilityUtility.cs" />
<Compile Include="Dissection.cs" />
<Compile Include="DissectionDefOf.cs" />
<Compile Include="DissectionUtility.cs" />
<Compile Include="Filters\DissectedFilter.cs" />
<Compile Include="HarmonyPatches.cs" />
<Compile Include="JobDriver_DoDissectionBill.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Toils_Dissection.cs" />
<Compile Include="WorkGiver_DoDissectionBill.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5E782404-F6C3-41C0-9B55-B10DB1145145}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HMDissection</RootNamespace>
<AssemblyName>HMDissection</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\v1.4\Assemblies\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\v1.4\Assemblies\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\References\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HugsLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\References\HugsLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CompatibilityUtility.cs" />
<Compile Include="Dissection.cs" />
<Compile Include="DissectionDefOf.cs" />
<Compile Include="DissectionUtility.cs" />
<Compile Include="Filters\DissectedFilter.cs" />
<Compile Include="HarmonyPatches.cs" />
<Compile Include="JobDriver_DoDissectionBill.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Toils_Dissection.cs" />
<Compile Include="WorkGiver_DoDissectionBill.cs" />
<Compile Include="WorkSettingsPatches.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>
10 changes: 10 additions & 0 deletions Source/HMDissection/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public static void Patch()
HarmonyMethod prefixmethod = new HarmonyMethod(typeof(HarmonyPatches).GetMethod("Notify_Resurrected_Prefix"));
harmony.Patch(targetMethod, prefixmethod);

// Set dissection work type priority based on medicine passion for starting pawns
targetMethod = AccessTools.Method(typeof(GameInitData), "PrepForMapGen");
postfixmethod = new HarmonyMethod(typeof(WorkSettingsPatches).GetMethod("PrepForMapGen_Postfix"));
harmony.Patch(targetMethod, null, postfixmethod);

// Set dissection work type priority based on medicine passion for new pawns
targetMethod = AccessTools.Method(typeof(Pawn_WorkSettings), "EnableAndInitialize");
postfixmethod = new HarmonyMethod(typeof(WorkSettingsPatches).GetMethod("EnableAndInitialize_Postfix"));
harmony.Patch(targetMethod, null, postfixmethod);

// Patch HasJobOnThing for Harvest Organs Post Morten to stop duplicate work givers
if (ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name.Contains("Harvest Organs Post Mortem")))
{
Expand Down
2 changes: 1 addition & 1 deletion Source/HMDissection/JobDriver_DoDissectionBill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override IEnumerable<Toil> MakeNewToils()
yield return gotoBillGiver;

// Strip body
Toil doDissectionRecipeWork = Toils_Dissection.DoDissectionRecipeWork().FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
Toil doDissectionRecipeWork = Toils_Dissection.DoDissectionRecipeWork().FailOnDespawnedNullOrForbiddenPlacedThings(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
yield return Toils_Jump.JumpIf(doDissectionRecipeWork, () =>
{
LocalTargetInfo targetInfo = job.GetTarget(TargetIndex.B);
Expand Down
8 changes: 4 additions & 4 deletions Source/HMDissection/Toils_Dissection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static Toil FinishRecipeAndStartStoringCorpse(TargetIndex corpseIndex)
}
else
{
Log.ErrorOnce("Unknown store mode", 9158246, false);
Log.ErrorOnce("Unknown store mode", 9158246);
}

if (bestStoreCell.IsValid)
Expand Down Expand Up @@ -167,7 +167,7 @@ public static Toil PlaceHauledThingInCell(TargetIndex cellInd, Toil nextToilOnPl
IntVec3 cell = curJob.GetTarget(cellInd).Cell;
if (actor.carryTracker.CarriedThing == null)
{
Log.Error(actor + " tried to place hauled thing in cell but is not hauling anything.", false);
Log.Error(actor + " tried to place hauled thing in cell but is not hauling anything.");
return;
}
SlotGroup slotGroup = actor.Map.haulDestinationManager.SlotGroupAt(cell);
Expand Down Expand Up @@ -231,7 +231,7 @@ public static Toil PlaceHauledThingInCell(TargetIndex cellInd, Toil nextToilOnPl
" near ",
actor.Position,
". Destroying. This should never happen!"
}), false);
}));
actor.carryTracker.CarriedThing.Destroy(DestroyMode.Vanish);
}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ public static Toil JumpToCollectNextIntoHandsForBill(Toil gotoGetTargetToil, Tar
Pawn actor = toil.actor;
if (actor.carryTracker.CarriedThing == null)
{
Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.", false);
Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.");
return;
}
if (actor.carryTracker.Full)
Expand Down
40 changes: 40 additions & 0 deletions Source/HMDissection/WorkSettingsPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace HMDissection
{
public static class WorkSettingsPatches
{

public static void EnableAndInitialize_Postfix(Pawn ___pawn)
{
SetDissectionPriorityForPassionatedPawns(___pawn);
}

public static void PrepForMapGen_Postfix(List<Pawn> ___startingAndOptionalPawns)
{
// Set priority for medical training if the pawn has a passion for medicine
// This way the pawn will practice medicine by default, even if it has 0 medicine skill
foreach (Pawn pawn in ___startingAndOptionalPawns)
{
SetDissectionPriorityForPassionatedPawns(pawn);
}
}

private static void SetDissectionPriorityForPassionatedPawns(Pawn pawn)
{
// Set priority for medical training if the pawn has a passion for medicine
// This way the pawn will practice medicine by default, even if it has 0 medicine skill
Passion? passion = pawn?.skills?.GetSkill(SkillDefOf.Medicine)?.passion;
if (passion.HasValue && passion.Value != Passion.None)
{
pawn.workSettings?.SetPriority(DissectionDefOf.MedicalTraining, 3);
}
}
}
}
Binary file added Source/References/0Harmony.dll
Binary file not shown.
Binary file added Source/References/HugsLib.dll
Binary file not shown.
Binary file added v1.4/Assemblies/HMDissection.dll
Binary file not shown.

0 comments on commit 1518262

Please sign in to comment.