Skip to content

Commit

Permalink
v1.1 fix; source code branched into 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
flyfire2002 committed Feb 25, 2020
1 parent 45b1d73 commit eb2621a
Show file tree
Hide file tree
Showing 29 changed files with 640 additions and 2 deletions.
8 changes: 6 additions & 2 deletions About/About.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>Field Medic [1.0]</name>
<packageId>Flyfire2002.FieldMedic</packageId>
<name>Field Medic [1.0+]</name>
<author>flyfire2002</author>
<targetVersion>1.0.2059</targetVersion>
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
</supportedVersions>
<description>
This mod adds the functionality to stabilize bleeding pawns so that you buy time to move pawns to more formal medical facilities.
</description>
Expand Down
Binary file modified Assemblies/FieldMedic.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<loadFolders>
<v1.1>
<li>/</li>
<li>v1.1</li>
</v1.1>
</loadFolders>
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions Source/FieldMedic 1.1/Comps/HediffCompProperties_Stabilize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using UnityEngine;

// Modified from the same named file from Combat Extended, under CC-BY-NC-SA-4.0.

namespace FieldMedic
{
public class HediffCompProperties_Stabilize : HediffCompProperties
{
public HediffCompProperties_Stabilize()
{
compClass = typeof(HediffComp_Stabilize);
}
}
}
145 changes: 145 additions & 0 deletions Source/FieldMedic 1.1/Comps/HediffComp_Stabilize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using UnityEngine;

// Modified from the same named file from Combat Extended, under CC-BY-NC-SA-4.0.

// This file has two logical parts. The first part is the FieldMedic_Util class that defines
// CanBeStabilized() function, determining whether a Hediff (injury) is stabilizable.
// The second part is HediffComp_Stabilize, the modifier for an injury. This class is triggered
// after an stabilize job actually begins. It contains internal math of how much bleeding to surpress,
// how fast the bleeding resumes, and what icon to display for the stabilized effect.

namespace FieldMedic
{
static class FieldMedic_Util
{
public static bool CanBeStabilized(this Hediff diff)
{
HediffWithComps hediff = diff as HediffWithComps;
if (hediff == null)
{
return false;
}
if (hediff.BleedRate == 0f || hediff.IsTended() || hediff.IsPermanent())
{
return false;
}
HediffComp_Stabilize comp = hediff.TryGetComp<HediffComp_Stabilize>();
return comp != null && !comp.Stabilized;
}
}

[StaticConstructorOnStartup]
public class HediffComp_Stabilize : HediffComp
{
private const float bleedIncreasePerSec = 0.0075f; // After stabilizing, bleed modifier is increased by this much
private const float internalBleedOffset = 0.3f;

// Use ReductionLeft / Reduction to decide which icon to display.
private float bleedReduction;
private float bleedReductionLeft;

private static readonly Texture2D Stabilized100Icon = ContentFinder<Texture2D>.Get("UI/Stabilized_icon_100");
private static readonly Texture2D Stabilized75Icon = ContentFinder<Texture2D>.Get("UI/Stabilized_icon_75");
private static readonly Texture2D Stabilized50Icon = ContentFinder<Texture2D>.Get("UI/Stabilized_icon_50");
private static readonly Texture2D Stabilized25Icon = ContentFinder<Texture2D>.Get("UI/Stabilized_icon_25");

private bool stabilized = false;
private float bleedModifier = 1;

public HediffCompProperties_Stabilize Props { get { return props as HediffCompProperties_Stabilize; } }
public bool Stabilized { get { return stabilized; } }
public float BleedModifier
{
get
{
float mod = bleedModifier;
if (parent.Part.depth == BodyPartDepth.Inside) mod += internalBleedOffset;
return Mathf.Clamp01(mod);
}
}

public void Stabilize(Pawn medic, Apparel_flyfire2002_MedicBag medicbag)
{
if (stabilized)
{
Log.Error("FieldMedic tried to stabilize an injury that is already stabilized");
return;
}
if (medicbag == null)
{
Log.Error("FieldMedic tried to stabilize without a medicbag");
return;
}
bleedReduction = 1.0f - 0.8f * medic.GetStatValue(StatDefOf.MedicalTendQuality);
// Especially high treatment quality extends time at 0% bleed by setting bleedModifier to a negative number,
// which is then clampped [0, 1] in BleedModifier getter. However, the overflow is diminished by half.
if (bleedReduction < 0)
{
bleedReduction /= 2;
}
bleedModifier = bleedReduction;
// Now we get the "real" bleed reduction amount, and set the numerator for the icon fullness.
bleedReduction = 1.0f - bleedModifier;
bleedReductionLeft = bleedReduction;
stabilized = true;
}

public override void CompExposeData()
{
Scribe_Values.Look(ref stabilized, "stabilized", false);
Scribe_Values.Look(ref bleedModifier, "bleedModifier", 1);
}

public override void CompPostTick(ref float severityAdjustment)
{
// Increase bleed modifier once per second
if (stabilized && bleedModifier < 1 && parent.ageTicks % 60 == 0)
{
bleedModifier += bleedIncreasePerSec;
bleedReductionLeft -= bleedIncreasePerSec;
if (bleedModifier >= 1)
{
bleedModifier = 1;
stabilized = false;
}
}
}

public override TextureAndColor CompStateIcon
{
get
{
if (bleedModifier < 1 && !parent.IsPermanent() && !parent.IsTended())
{
if (bleedReductionLeft / bleedReduction > 0.75f) {
return new TextureAndColor(Stabilized100Icon, Color.white);
}
if (bleedReductionLeft / bleedReduction > 0.5f)
{
return new TextureAndColor(Stabilized75Icon, Color.white);
}
if (bleedReductionLeft / bleedReduction > 0.25f)
{
return new TextureAndColor(Stabilized50Icon, Color.white);
}
return new TextureAndColor(Stabilized25Icon, Color.white);

}
return TextureAndColor.None;
}
}

public override string CompDebugString()
{
if (parent.BleedRate < 0) return "Not bleeding";
if (!stabilized) return "Not stabilized";
return String.Concat("Stabilized", parent.Part.depth == BodyPartDepth.Inside ? " internal bleeding" : "", "\nbleed rate modifier: ", bleedModifier.ToString());
}
}
}
16 changes: 16 additions & 0 deletions Source/FieldMedic 1.1/DefOfs/FieldMedic_JobDefOf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using Verse.AI;

namespace FieldMedic
{
[DefOf]
public static class FieldMedic_JobDefOf
{
public static JobDef Stabilize;
}
}
83 changes: 83 additions & 0 deletions Source/FieldMedic 1.1/FieldMedic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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>{38324373-61CA-4B93-A5E2-5337652127BF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FieldMedic</RootNamespace>
<AssemblyName>FieldMedic</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.1\Assemblies\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=1.0.9.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\v1.1\Assemblies\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="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Comps\HediffCompProperties_Stabilize.cs" />
<Compile Include="Comps\HediffComp_Stabilize.cs" />
<Compile Include="DefOfs\FieldMedic_JobDefOf.cs" />
<Compile Include="Harmony\Harmony-HediffWithComps.cs" />
<Compile Include="Harmony\Harmony-FloatMenuMakerMap.cs" />
<Compile Include="Harmony\HarmonyBase.cs" />
<Compile Include="Jobs\JobDriver_Stabilize.cs" />
<Compile Include="Things\Apparel_flyfire2002_MedicBag.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- 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>
104 changes: 104 additions & 0 deletions Source/FieldMedic 1.1/FieldMedic.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FieldMedic", "FieldMedic.csproj", "{38324373-61CA-4B93-A5E2-5337652127BF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "About", "About", "{2C94E0FF-0828-4484-A3BC-C2853D0F59BD}"
ProjectSection(SolutionItems) = preProject
..\..\About\About.xml = ..\..\About\About.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Defs", "Defs", "{4342AB82-4806-42BC-A2A5-49107E88329C}"
ProjectSection(SolutionItems) = preProject
..\..\Defs\ThingDefs\Apparel_MedicBag.xml = ..\..\Defs\ThingDefs\Apparel_MedicBag.xml
..\..\Defs\JobDefs\Jobs_FieldMedic.xml = ..\..\Defs\JobDefs\Jobs_FieldMedic.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Patches", "Patches", "{56F8E260-C2F0-4937-BE49-F0BD9B13CC0E}"
ProjectSection(SolutionItems) = preProject
..\..\Patches\Core\HediffDefs\Hediffs_Local_Injuries.xml = ..\..\Patches\Core\HediffDefs\Hediffs_Local_Injuries.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "English", "English", "{A6E8476F-EAB9-4A48-A06A-348A734118E2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Keyed", "Keyed", "{DF571483-D2F2-4C52-B1D8-66175192912E}"
ProjectSection(SolutionItems) = preProject
..\..\Languages\English\Keyed\Keys.xml = ..\..\Languages\English\Keyed\Keys.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Languages", "Languages", "{F19B0847-DDCF-497E-8C25-93CC81D7EE0A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ChineseSimplified", "ChineseSimplified", "{66BD7D15-252A-4743-ACC1-83A495571624}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Keyed", "Keyed", "{E6DA5501-5C7E-440C-BFB7-89502F1A12DA}"
ProjectSection(SolutionItems) = preProject
..\..\Languages\ChineseSimplified\Keyed\Keys.xml = ..\..\Languages\ChineseSimplified\Keyed\Keys.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DefInjected", "DefInjected", "{EF5B24B6-04A1-422F-AAB5-28A8F430454B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThingDefs", "ThingDefs", "{DB4746AB-5438-430F-BDF3-2E74F319B42D}"
ProjectSection(SolutionItems) = preProject
..\..\Languages\ChineseSimplified\DefInjected\ThingDefs\Apparel_MedicBag.xml = ..\..\Languages\ChineseSimplified\DefInjected\ThingDefs\Apparel_MedicBag.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "JobDefs", "JobDefs", "{1C3C14F7-B10D-46EE-BED9-21567F841EB0}"
ProjectSection(SolutionItems) = preProject
..\..\Languages\ChineseSimplified\DefInjected\JobDefs\Jobs_FieldMedic.xml = ..\..\Languages\ChineseSimplified\DefInjected\JobDefs\Jobs_FieldMedic.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ChineseTraditional", "ChineseTraditional", "{C4740C61-49EB-463B-AE91-EB295FD38216}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Keyed", "Keyed", "{44B363E2-6735-450A-8529-69BC128723C5}"
ProjectSection(SolutionItems) = preProject
..\..\Languages\ChineseTraditional\Keyed\Keys.xml = ..\..\Languages\ChineseTraditional\Keyed\Keys.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DefInjected", "DefInjected", "{46462EF7-AAD6-408F-856D-A3D38EAA6FEE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "JobDefs", "JobDefs", "{EA201165-D46C-4136-9FE1-59C53457E450}"
ProjectSection(SolutionItems) = preProject
..\..\Languages\ChineseTraditional\DefInjected\JobDefs\Jobs_FieldMedic.xml = ..\..\Languages\ChineseTraditional\DefInjected\JobDefs\Jobs_FieldMedic.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThingDefs", "ThingDefs", "{9DAB7040-D7FE-4BF8-B6C8-0E4BA31B2377}"
ProjectSection(SolutionItems) = preProject
..\..\Languages\ChineseTraditional\DefInjected\ThingDefs\Apparel_MedicBag.xml = ..\..\Languages\ChineseTraditional\DefInjected\ThingDefs\Apparel_MedicBag.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2A5700F9-C489-48C9-8172-EE1C7D249F57}"
ProjectSection(SolutionItems) = preProject
..\..\LoadFolders.xml = ..\..\LoadFolders.xml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{38324373-61CA-4B93-A5E2-5337652127BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38324373-61CA-4B93-A5E2-5337652127BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38324373-61CA-4B93-A5E2-5337652127BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38324373-61CA-4B93-A5E2-5337652127BF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A6E8476F-EAB9-4A48-A06A-348A734118E2} = {F19B0847-DDCF-497E-8C25-93CC81D7EE0A}
{DF571483-D2F2-4C52-B1D8-66175192912E} = {A6E8476F-EAB9-4A48-A06A-348A734118E2}
{66BD7D15-252A-4743-ACC1-83A495571624} = {F19B0847-DDCF-497E-8C25-93CC81D7EE0A}
{E6DA5501-5C7E-440C-BFB7-89502F1A12DA} = {66BD7D15-252A-4743-ACC1-83A495571624}
{EF5B24B6-04A1-422F-AAB5-28A8F430454B} = {66BD7D15-252A-4743-ACC1-83A495571624}
{DB4746AB-5438-430F-BDF3-2E74F319B42D} = {EF5B24B6-04A1-422F-AAB5-28A8F430454B}
{1C3C14F7-B10D-46EE-BED9-21567F841EB0} = {EF5B24B6-04A1-422F-AAB5-28A8F430454B}
{C4740C61-49EB-463B-AE91-EB295FD38216} = {F19B0847-DDCF-497E-8C25-93CC81D7EE0A}
{44B363E2-6735-450A-8529-69BC128723C5} = {C4740C61-49EB-463B-AE91-EB295FD38216}
{46462EF7-AAD6-408F-856D-A3D38EAA6FEE} = {C4740C61-49EB-463B-AE91-EB295FD38216}
{EA201165-D46C-4136-9FE1-59C53457E450} = {46462EF7-AAD6-408F-856D-A3D38EAA6FEE}
{9DAB7040-D7FE-4BF8-B6C8-0E4BA31B2377} = {46462EF7-AAD6-408F-856D-A3D38EAA6FEE}
EndGlobalSection
EndGlobal
Loading

0 comments on commit eb2621a

Please sign in to comment.