Skip to content

Commit

Permalink
v1.0.6
Browse files Browse the repository at this point in the history
- Better handling of default rules
- Pawns who have been disallowed new romances should now no longer still try
  • Loading branch information
Jaxe-Wilde committed Sep 3, 2018
1 parent a906c90 commit bde66cc
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 33 deletions.
2 changes: 1 addition & 1 deletion About/ModSync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ModSyncNinjaData>
<ID>59f538ed-f86d-4506-a4a5-7e9faaa37508</ID>
<ModName>Pawn Rules</ModName>
<Version>v1.0.5</Version>
<Version>v1.0.6</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>Jaxe-Dev</Owner>
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Pawn Rules
![](https://img.shields.io/badge/Version-1.0.5-brightgreen.svg)

Built for **RimWorld 1.0.x / 0.19.x**\
Built for **RimWorld B19**\
Powered by **Harmony**\
Supports **ModSync RW**

[Link to Ludeon Forum Post](https://ludeon.com/forums/index.php?topic=43086.0)
[Link to Ludeon Forum thread](https://ludeon.com/forums/index.php?topic=43086.0)\
[Link to Steam Workshop page](https://steamcommunity.com/sharedfiles/filedetails/?id=1499843448)

------------

Expand Down Expand Up @@ -47,6 +48,7 @@ RimWorld.FoodUtility.BestFoodSourceOnMap : Prefix
RimWorld.FoodUtility.BestFoodInInventory : Prefix
RimWorld.FoodUtility.TryFindBestFoodSourceFor : Prefix
RimWorld.GenConstruct.CanConstruct : Postfix
RimWorld.InteractionWorker_RomanceAttempt.RandomSelectionWeight : Prefix
RimWorld.InteractionWorker_RomanceAttempt.SuccessChance : Prefix
RimWorld.JobGiver_PackFood.IsGoodPackableFoodFor : Postfix
RimWorld.JoyGiver_Ingest.CanIngestForJoy : Prefix
Expand All @@ -56,6 +58,6 @@ Verse.Game.FinalizeInit : Postfix
Verse.Pawn.GetGizmos : Postfix
Verse.Pawn.Kill : Postfix
Verse.Pawn.SetFaction : Prefix
Verse.Pawn.SetFactionDirect : Prefix
Verse.PawnGenerator.GeneratePawn : Postfix
Verse.Pawn_GuestTracker.SetGuestStatus : Prefix
```
18 changes: 15 additions & 3 deletions Source/Data/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,18 @@ public static Rules GetRules(Pawn pawn)
return Instance._rules.ContainsKey(pawn) ? Instance._rules[pawn] : null;
}

public static Rules GetOrCreateRules(Pawn pawn)
public static Rules GetOrNewRules(Pawn pawn)
{
if (!pawn.CanHaveRules()) { return null; }
if (Instance._rules.ContainsKey(pawn)) { return Instance._rules[pawn]; }

var rules = GetVoidPreset<Rules>(pawn.GetTargetType()).CloneRulesFor(pawn);
Instance._rules.Add(pawn, rules);

return rules;
}

public static Rules GetOrDefaultRules(Pawn pawn)
{
if (!pawn.CanHaveRules()) { return null; }
if (Instance._rules.ContainsKey(pawn)) { return Instance._rules[pawn]; }
Expand All @@ -163,7 +174,7 @@ private static Rules ChangeTypeOrCreateRules(Pawn pawn, PawnType type)
public static Rules CloneRules(Pawn original, Pawn cloner)
{
if (!original.CanHaveRules()) { return null; }
if (!Instance._rules.ContainsKey(original)) { return GetOrCreateRules(cloner); }
if (!Instance._rules.ContainsKey(original)) { return GetOrDefaultRules(cloner); }
if (Instance._rules.ContainsKey(cloner)) { DeleteRules(cloner); }

var cloned = Instance._rules[original].CloneRulesFor(cloner);
Expand Down Expand Up @@ -196,7 +207,7 @@ public static void FactionUpdate(Thing thing, Faction newFaction, bool? guest =
}
else { return; }

if (GetDefaultRules(type).IsIgnored()) { return; }
if (GetDefaultRules(type).IsVoid) { return; }

ChangeTypeOrCreateRules(pawn, type);
}
Expand Down Expand Up @@ -251,6 +262,7 @@ public override void PostAdd()
InitVoids();
InitDefaults();
}

public override void SpawnSetup()
{ }

Expand Down
4 changes: 2 additions & 2 deletions Source/Interface/Dialog_Rules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private Dialog_Rules(Pawn pawn, Rules rules) : base(new Vector2(700f, 600f))
_floatMenuAssign = GetAssignmentOptions();
}

public static void OpenFromPawn(Pawn pawn) => Find.WindowStack.Add(new Dialog_Rules(pawn, Registry.GetOrCreateRules(pawn)));
public static void OpenFromPawn(Pawn pawn) => Find.WindowStack.Add(new Dialog_Rules(pawn, Registry.GetOrNewRules(pawn)));

private void ChangeType(PawnType type)
{
Expand All @@ -47,7 +47,7 @@ private void ChangeType(PawnType type)
_preset.FixedPresets = _type == null ? new[] { _personalized } : new[] { Registry.GetVoidPreset<Rules>(_template.Type) };
if (type == null)
{
var rules = Registry.GetOrCreateRules(_pawn);
var rules = Registry.GetOrNewRules(_pawn);
_preset.Selected = rules.IsPreset ? rules : _personalized;
}
else { _preset.Selected = Registry.GetDefaultRules(type); }
Expand Down
2 changes: 1 addition & 1 deletion Source/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class Mod : Verse.Mod
public const string Id = "PawnRules";
public const string Name = "Pawn Rules";
public const string Author = "Jaxe";
public const string Version = "1.0.5";
public const string Version = "1.0.6";

public static ModContentPack ContentPack { get; private set; }

Expand Down
6 changes: 2 additions & 4 deletions Source/Patch/RimWorld_FoodUtility_TryFindBestFoodSourceFor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ private static bool Prefix(ref bool __result, Pawn getter, Pawn eater, bool desp
var thing1 = (Thing) null;
if (canUseInventory)
{
if (flag)
{
thing1 = FoodUtility.BestFoodInInventory(getter, eater, FoodPreferability.MealAwful);
}
if (flag) { thing1 = FoodUtility.BestFoodInInventory(getter, eater, FoodPreferability.MealAwful); }
if (thing1 != null)
{
if (getter.Faction != Faction.OfPlayer)
Expand All @@ -28,6 +25,7 @@ private static bool Prefix(ref bool __result, Pawn getter, Pawn eater, bool desp
__result = true;
return false;
}

var comp = thing1.TryGetComp<CompRottable>();
if ((comp != null) && (comp.Stage == RotStage.Fresh) && (comp.TicksUntilRotAtCurrentTemp < 30000))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Harmony;
using PawnRules.Data;
using RimWorld;
using Verse;

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(InteractionWorker_RomanceAttempt), nameof(InteractionWorker_RomanceAttempt.RandomSelectionWeight))]
internal static class RimWorld_InteractionWorker_RomanceAttempt_RandomSelectionWeight
{
private static bool Prefix(ref float __result, Pawn initiator, Pawn recipient)
{
if (!Registry.IsActive) { return true; }

var initiatorCanCourt = Registry.GetRules(initiator)?.AllowCourting ?? true;
var recipientCanCourt = Registry.GetRules(recipient)?.AllowCourting ?? true;

if (initiatorCanCourt && recipientCanCourt) { return true; }

__result = 0f;
return false;
}
}
}
20 changes: 20 additions & 0 deletions Source/Patch/Verse_PawnGenerator_GeneratePawn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Harmony;
using PawnRules.Data;
using RimWorld;
using Verse;

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(PawnGenerator), nameof(PawnGenerator.GeneratePawn), typeof(PawnGenerationRequest))]
internal static class Verse_PawnGenerator_GeneratePawn
{
private static void Postfix(ref Pawn __result)
{
if (!Registry.IsActive) { return; }

if ((__result == null) || ((__result.Faction != Faction.OfPlayer) && (__result.HostFaction != Faction.OfPlayer))) { return; }

Registry.GetOrDefaultRules(__result);
}
}
}
17 changes: 0 additions & 17 deletions Source/Patch/Verse_Pawn_SetFactionDirect.cs

This file was deleted.

5 changes: 3 additions & 2 deletions Source/PawnRules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Patch\RimWorld_InteractionWorker_RomanceAttempt_RandomSelectionWeight.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Mod.cs" />
<Compile Include="Controller.cs" />
Expand Down Expand Up @@ -93,10 +94,10 @@
<Compile Include="Patch\RimWorld_RelationsUtility_TryDevelopBondRelation.cs" />
<Compile Include="Patch\Verse_Game_FinalizeInit.cs" />
<Compile Include="Patch\Verse_Pawn_GetGizmos.cs" />
<Compile Include="Patch\Verse_Pawn_GuestTracker_SetGuestStatus.cs" />
<Compile Include="Patch\Verse_Pawn_Kill.cs" />
<Compile Include="Patch\Verse_Pawn_SetFaction.cs" />
<Compile Include="Patch\Verse_Pawn_SetFactionDirect.cs" />
<Compile Include="Patch\Verse_PawnGenerator_GeneratePawn.cs" />
<Compile Include="Patch\Verse_Pawn_GuestTracker_SetGuestStatus.cs" />
<Compile Include="SDK\OptionHandle.cs" />
<Compile Include="SDK\OptionTarget.cs" />
<Compile Include="SDK\PawnRulesLink.cs" />
Expand Down

0 comments on commit bde66cc

Please sign in to comment.