Skip to content

Commit

Permalink
implemented almost there mod!
Browse files Browse the repository at this point in the history
  • Loading branch information
rheirman committed Jan 24, 2021
1 parent d42f76a commit 213de1b
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 13 deletions.
Binary file added 1.2/Assemblies/AlmostThere.dll
Binary file not shown.
Binary file removed 1.2/Assemblies/SearchAndDestroy.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions 1.2/Source/AlmostThere/AlmostThere.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{EB0FDC31-0570-42FC-A3C9-3E9248B62858}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SearchAndDestroy</RootNamespace>
<AssemblyName>SearchAndDestroy</AssemblyName>
<RootNamespace>AlmostThere</RootNamespace>
<AssemblyName>AlmostThere</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -154,14 +154,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Base.cs" />
<Compile Include="Harmony\Pawn_DraftController.cs" />
<Compile Include="Harmony\Pawn_JobTracker.cs" />
<Compile Include="Harmony\Caravan.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Storage\ExtendedDataStorage.cs" />
<Compile Include="Storage\ExtendedCaravanData.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
14 changes: 11 additions & 3 deletions 1.2/Source/AlmostThere/Base.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using HugsLib;
using HugsLib.Utils;
using SearchAndDestroy.Storage;
using AlmostThere.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using HugsLib.Settings;

namespace SearchAndDestroy
namespace AlmostThere
{
class Base : ModBase
public class Base : ModBase
{
public override string ModIdentifier => "AlmostThere";
public static Base Instance { get; private set; }
private ExtendedDataStorage _extendedDataStorage;
internal static SettingHandle<int> almostThereHours;

public Base()
{
Expand All @@ -31,6 +33,12 @@ public override void WorldLoaded()
}
base.WorldLoaded();
}

public override void DefsLoaded()
{
almostThereHours = Settings.GetHandle<int>("AlmostThereHours", "AT_AlmostThereHours_Title".Translate(), "AT_AlmostThereHours_Desciption".Translate(), 4, Validators.IntRangeValidator(0, 1000));
base.DefsLoaded();
}
}


Expand Down
111 changes: 111 additions & 0 deletions 1.2/Source/AlmostThere/Harmony/Caravan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using AlmostThere;
using AlmostThere.Storage;
using HarmonyLib;
using RimWorld;
using RimWorld.Planet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

namespace SearchAndDestroy.Harmony
{
[HarmonyPatch(typeof(Caravan), "get_NightResting")]
class Caravan_get_NightResting
{
private static float nHours = 5f;
static bool Prefix(Caravan __instance)
{

if(Base.Instance.GetExtendedDataStorage() is ExtendedDataStorage store)
{
if (store.GetExtendedDataFor(__instance) is ExtendedCaravanData data)
{
if (data.fullyIgnoreRest)
{
return false;
}
if (data.almostThere)
{
var estimatedTicks = (float)CaravanArrivalTimeEstimator.EstimatedTicksToArrive(__instance, allowCaching: false);
var restTicksLeft = CaravanNightRestUtility.LeftRestTicksAt(__instance.Tile, Find.TickManager.TicksAbs);
estimatedTicks -= restTicksLeft;
if (estimatedTicks/GenDate.TicksPerHour < Base.almostThereHours.Value)
{
return false;
}
}
}
}
return true;

}
}


[HarmonyPatch(typeof(Caravan), "GetGizmos")]
class Caravan_GetGizmos
{
static void Postfix(Caravan __instance, ref IEnumerable<Gizmo> __result)
{
var gizmoList = __result.ToList();
var store = Base.Instance.GetExtendedDataStorage();
var caravanData = store.GetExtendedDataFor(__instance);
if(__instance.Faction == Faction.OfPlayer)
{
if(caravanData != null)
{
gizmoList.Add(CreateAlmostThereCommand(__instance, caravanData));
gizmoList.Add(CreateIgnoreRestCommand(__instance, caravanData));
gizmoList.Add(CreateForceRestCommand(__instance, caravanData));
}
}
__result = gizmoList;
}

private static Command_Toggle CreateIgnoreRestCommand(Caravan __instance, ExtendedCaravanData caravanData)
{
Command_Toggle command_Toggle = new Command_Toggle();
command_Toggle.isActive = (() => caravanData.fullyIgnoreRest);
command_Toggle.toggleAction = delegate
{
caravanData.fullyIgnoreRest = !caravanData.fullyIgnoreRest;
};
command_Toggle.defaultDesc = "AT_Command_DontRest_Description".Translate();
command_Toggle.icon = ContentFinder<Texture2D>.Get(("UI/" + "DontRest"), true);
command_Toggle.defaultLabel = "AT_Command_DontRest_Label".Translate();
return command_Toggle;
}
private static Command_Toggle CreateAlmostThereCommand(Caravan __instance, ExtendedCaravanData caravanData)
{
Command_Toggle command_Toggle = new Command_Toggle();
command_Toggle.isActive = (() => caravanData.almostThere);
command_Toggle.toggleAction = delegate
{
caravanData.almostThere = !caravanData.almostThere;
};
command_Toggle.defaultDesc = "AT_Command_AlmostThere_Description".Translate(Base.almostThereHours.Value);
command_Toggle.icon = ContentFinder<Texture2D>.Get(("UI/" + "AlmostThere"), true);
command_Toggle.defaultLabel = "AT_Command_AlmostThere_Label".Translate();
return command_Toggle;
}

private static Command_Toggle CreateForceRestCommand(Caravan __instance, ExtendedCaravanData caravanData)
{
Command_Toggle command_Toggle = new Command_Toggle();
command_Toggle.isActive = (() => caravanData.almostThere);
command_Toggle.toggleAction = delegate
{
caravanData.forceRest = !caravanData.forceRest;
};
command_Toggle.defaultDesc = "AT_Command_ForceRest_Description".Translate();
command_Toggle.icon = ContentFinder<Texture2D>.Get(("UI/" + "ForceRest"), true);
command_Toggle.defaultLabel = "AT_Command_ForceRest_Title".Translate();
return command_Toggle;
}
}

}
10 changes: 7 additions & 3 deletions 1.2/Source/AlmostThere/Storage/ExtendedCaravanData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
//Note: Currently this class contains information specific for other mods (caravanMount, caravanRider, etc), which is of course not ideal for a core framework. Ideally it should be completely generic. However I have yet to come up with an
// way to do this properly without introducing a lot of extra work. So for now I'll just keep it as it is.

namespace SearchAndDestroy.Storage
namespace AlmostThere.Storage
{
public class ExtendedCaravanData : IExposable
{
public bool SD_enabled = false;
public bool fullyIgnoreRest = false;
public bool forceRest = false;
public bool almostThere = true;
public void ExposeData()
{
Scribe_Values.Look(ref SD_enabled, "SD_enabled", false);
Scribe_Values.Look(ref almostThere, "almostThere", false);
Scribe_Values.Look(ref fullyIgnoreRest, "fullyIgnoreRest", false);
Scribe_Values.Look(ref forceRest, "forceRest", false);
}
}
}
2 changes: 1 addition & 1 deletion 1.2/Source/AlmostThere/Storage/ExtendedDataStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using RimWorld.Planet;
using Verse;

namespace SearchAndDestroy.Storage
namespace AlmostThere.Storage
{


Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d9a011d753278146b3f8a10166bf4579e51d1f2e
aacb1f610ca57470c6fb8901f9e12f888f37f874
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AlmostThere\1.2\Source\AlmostThere\obj\Debug\AlmostThere.csprojAssemblyReference.cache
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AlmostThere\1.2\Source\AlmostThere\obj\Debug\AlmostThere.csproj.CoreCompileInputs.cache
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AlmostThere\1.2\Source\AlmostThere\obj\Debug\SearchAndDestroy.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AlmostThere\1.2\Assemblies\AlmostThere.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\AlmostThere\1.2\Source\AlmostThere\obj\Debug\AlmostThere.dll
Binary file not shown.
Binary file added 1.2/Source/AlmostThere/obj/Debug/AlmostThere.dll
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions Languages/English/Keyed/AlmostThere_keys.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<AT_AlmostThereHours_Title>Almost there hours</AT_AlmostThereHours_Title>
<AT_AlmostThereHours_Description>Set how many hours away a target has to be for "Almost there" to trigger.</AT_AlmostThereHours_Description>
<AT_Command_DontRest_Label>Never rest</AT_Command_DontRest_Label>
<AT_Command_DontRest_Description>Turning this on will prevent the caravan from ever resting. Use at your own risk!</AT_Command_DontRest_Description>
<AT_Command_AlmostThere_Label>Almost there!</AT_Command_AlmostThere_Label>
<AT_Command_AlmostThere_Description>Cmon guys, we're almost there! With this enabled, your caravan won't rest when {0} hours away from its target.</AT_Command_AlmostThere_Description>
<AT_Command_ForceRest_Title>Force rest</AT_Command_ForceRest_Title>
<AT_Command_ForceRest_Description>Turning this on will force the caravan to rest. Turn it off to let them stop resting again.</AT_Command_ForceRest_Description>
</LanguageData>
Binary file added Textures/UI/AlmostThere.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Textures/UI/DontRest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Textures/UI/ForceRest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 213de1b

Please sign in to comment.