Skip to content

Commit

Permalink
v1.0.9
Browse files Browse the repository at this point in the history
- Fixed default rules not applying to new pawns
  • Loading branch information
Jaxe-Dev committed Sep 8, 2018
1 parent bf5a880 commit 0a85b5a
Show file tree
Hide file tree
Showing 36 changed files with 98 additions and 104 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<name>Pawn Rules</name>
<author>Jaxe</author>
<targetVersion>0.19.0</targetVersion>
<description>Pawn Rules is a mod that allows custom rules to be assigned individually to your colonists, animals, guests and prisoners.\n\nCurrently the following rules can be applied:\n\n- Disallow certain foods\n- Disallow bonding with certain animals\n- Disallow new romances\n- Disallow constructing items that have a quality level\n\nAny of these rules can be disabled and hidden from the rules window.</description>
<description>Mod Version: 1.0.9\n\n\nPawn Rules is a mod that allows custom rules to be assigned individually to your colonists, animals, guests and prisoners.\n\nCurrently the following rules can be applied:\n\n- Disallow certain foods\n- Disallow bonding with certain animals\n- Disallow new romances\n- Disallow constructing items that have a quality level\n\nAny of these rules can be disabled and hidden from the rules window.</description>
<url>https://ludeon.com/forums/index.php?topic=43086.0</url>
</ModMetaData>
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.8</Version>
<Version>v1.0.9</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>Jaxe-Dev</Owner>
Expand Down
72 changes: 36 additions & 36 deletions Assemblies/PawnRules.xml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Pawn Rules
![](https://img.shields.io/badge/Version-1.0.8-brightgreen.svg)
![](https://img.shields.io/badge/Version-1.0.9-brightgreen.svg)

Built for **RimWorld B19**\
Powered by **Harmony**\
Supports **ModSync RW**

[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)
[Link to Steam Workshop page](https://steamcommunity.com/sharedfiles/filedetails/?id=1499843448)\
[Link to Ludeon Forum thread](https://ludeon.com/forums/index.php?topic=43086.0)

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

Expand Down Expand Up @@ -52,12 +52,12 @@ RimWorld.InteractionWorker_RomanceAttempt.RandomSelectionWeight : Prefix
RimWorld.InteractionWorker_RomanceAttempt.SuccessChance : Prefix
RimWorld.JobGiver_PackFood.IsGoodPackableFoodFor : Postfix
RimWorld.JoyGiver_Ingest.CanIngestForJoy : Prefix
RimWorld.Pawn_GuestTracker.SetGuestStatus : Prefix
RimWorld.PawnUtility.TrySpawnHatchedOrBornPawn : Postfix
RimWorld.RelationsUtility.TryDevelopBondRelation : Prefix
Verse.Game.FinalizeInit : Postfix
Verse.Pawn.GetGizmos : Postfix
Verse.Pawn.Kill : Postfix
Verse.Pawn.SetFaction : Prefix
Verse.PawnGenerator.GeneratePawn : Postfix
Verse.Pawn_GuestTracker.SetGuestStatus : Prefix
```
2 changes: 1 addition & 1 deletion Source/SDK/OptionHandle.cs → Source/API/OptionHandle.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using PawnRules.Data;
using Verse;

namespace PawnRules.SDK
namespace PawnRules.API
{
/// <summary>
/// The base class of a rules option handle.
Expand Down
2 changes: 1 addition & 1 deletion Source/SDK/OptionTarget.cs → Source/API/OptionTarget.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace PawnRules.SDK
namespace PawnRules.API
{
/// <summary>
/// Used to set the target type of the pawn that a rule will be applied to. Multiple flags may be set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using PawnRules.Interface;
using Verse;

namespace PawnRules.SDK
namespace PawnRules.API
{
/// <summary>
/// Provides a link to Pawn Rules and is used to add options to the rules dialog.
Expand Down
2 changes: 1 addition & 1 deletion Source/Data/AddonOption.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using PawnRules.API;
using PawnRules.Interface;
using PawnRules.SDK;
using Verse;

namespace PawnRules.Data
Expand Down
2 changes: 1 addition & 1 deletion Source/Data/PawnType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Linq;
using PawnRules.SDK;
using PawnRules.API;

namespace PawnRules.Data
{
Expand Down
12 changes: 3 additions & 9 deletions Source/Data/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PawnRules.API;
using PawnRules.Interface;
using PawnRules.Patch;
using PawnRules.SDK;
using RimWorld;
using RimWorld.Planet;
using Verse;
Expand Down Expand Up @@ -165,11 +165,7 @@ public static Rules GetOrDefaultRules(Pawn pawn)
public static void ReplaceRules(Pawn pawn, Rules rules) => Instance._rules[pawn] = rules;
public static void ReplaceDefaultRules(PawnType type, Rules rules) => Instance._defaults[type] = rules;

private static Rules ChangeTypeOrCreateRules(Pawn pawn, PawnType type)
{
Instance._rules[pawn] = new Rules(pawn, type ?? pawn.GetTargetType());
return Instance._rules[pawn];
}
private static void ChangeTypeOrCreateRules(Pawn pawn, PawnType type) => Instance._rules[pawn] = GetDefaultRules(type);

public static Rules CloneRules(Pawn original, Pawn cloner)
{
Expand All @@ -191,7 +187,7 @@ public static void DeleteRules(Pawn pawn)

public static void FactionUpdate(Thing thing, Faction newFaction, bool? guest = null)
{
if (!(thing is Pawn pawn) || !pawn.Spawned || !pawn.Dead) { return; }
if (!(thing is Pawn pawn) || !pawn.Spawned || pawn.Dead) { return; }

PawnType type;

Expand All @@ -207,8 +203,6 @@ public static void FactionUpdate(Thing thing, Faction newFaction, bool? guest =
}
else { return; }

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

ChangeTypeOrCreateRules(pawn, type);
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Interface/Dialog_Alert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public Dialog_Alert(string message, Buttons buttons = Buttons.Ok, Action onAccep
public override void DoWindowContents(Rect rect)
{
var listing = new Listing_Standard();
var vGrid = rect.GetVGrid(4f, 0f, 30f);
var vGrid = rect.GetVGrid(4f, -1f, 30f);

listing.Begin(vGrid[0]);
listing.Label(_message);
listing.End();

var hGrid = vGrid[1].GetHGrid(4f, 100f, 0f);
var hGrid = vGrid[1].GetHGrid(4f, 100f, -1f);

listing.Begin(_buttons == Buttons.Ok ? vGrid[1] : hGrid[0]);

Expand Down
2 changes: 1 addition & 1 deletion Source/Interface/Dialog_PresetName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override void DoContent(Rect rect)
listing.Gap();
listing.End();

var grid = rect.AdjustedBy(0f, listing.CurHeight, 0f, -listing.CurHeight).GetHGrid(4f, 0f, 0f);
var grid = rect.AdjustedBy(0f, listing.CurHeight, 0f, -listing.CurHeight).GetHGrid(4f, -1f, -1f);

listing.Begin(grid[0]);
if (listing.ButtonText(Lang.Get("Button.OK"), null, valid))
Expand Down
10 changes: 5 additions & 5 deletions Source/Interface/Dialog_Restrictions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public override void DoContent(Rect rect)

_color = GUI.color;

var vGrid = rect.GetVGrid(4f, 42f, 0f);
var hGrid = vGrid[1].GetHGrid(8f, 200f, 0f, 0f);
var vGrid = rect.GetVGrid(4f, 42f, -1f);
var hGrid = vGrid[1].GetHGrid(8f, 200f, -1f, -1f);
DoHeader(vGrid[0]);

_presetList.DoContent(hGrid[0]);
Expand All @@ -86,7 +86,7 @@ public override void DoContent(Rect rect)

private void DoHeader(Rect rect)
{
var grid = rect.GetHGrid(8f, 200f, 0f, 0f);
var grid = rect.GetHGrid(8f, 200f, -1f, -1f);
_headerList.Begin(grid[0]);
_headerList.Label(Lang.Get("Preset.Header").Italic().Bold());
_headerList.GapLine();
Expand All @@ -105,7 +105,7 @@ private void DoHeader(Rect rect)

private void DoCategories(Rect rect)
{
var vGrid = rect.GetVGrid(4f, 0f, 30f);
var vGrid = rect.GetVGrid(4f, -1f, 30f);
_categoryList.Begin(vGrid[0]);

foreach (var category in _template.Categories)
Expand All @@ -129,7 +129,7 @@ private void DoCategories(Rect rect)

if (!_presetList.EditMode) { return; }

var hGrid = vGrid[1].GetHGrid(4f, 0f, 0f);
var hGrid = vGrid[1].GetHGrid(4f, -1f, -1f);
_categoryList.Begin(hGrid[0]);
if (_categoryList.ButtonText(Lang.Get("Button.RestrictionsAllowOn"))) { _template.ToggleAll(true); }
_categoryList.End();
Expand Down
10 changes: 5 additions & 5 deletions Source/Interface/Dialog_Rules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ public override void DoContent(Rect rect)
Title = _type == null ? Lang.Get("Dialog_Rules.Title", _pawn.Name.ToStringFull.Bold(), _preset.Type.Label) : Lang.Get("Dialog_Rules.TitleDefault", _type.LabelPlural.Bold());

var listing = new Listing_StandardPlus();
var hGrid = rect.GetHGrid(8f, 200f, 0f);
var lGrid = hGrid[0].GetVGrid(4f, 42f, 0f);
var hGrid = rect.GetHGrid(8f, 200f, -1f);
var lGrid = hGrid[0].GetVGrid(4f, 42f, -1f);

listing.Begin(lGrid[0]);
listing.Label(Lang.Get("Preset.Header").Italic().Bold());
listing.GapLine();
listing.End();
_preset.DoContent(lGrid[1]);

var vGrid = hGrid[1].GetVGrid(4f, 42f, 0f, 62f);
var vGrid = hGrid[1].GetVGrid(4f, 42f, -1f, 62f);
listing.Begin(vGrid[0]);
listing.Label(Lang.Get("Dialog_Rules.Configuration").Italic().Bold());
listing.GapLine();
Expand Down Expand Up @@ -238,15 +238,15 @@ public override void DoContent(Rect rect)

if (_template.HasAddons)
{
var addonsRect = vGrid[1].GetVGrid(4f, listing.CurHeight, 0f)[1];
var addonsRect = vGrid[1].GetVGrid(4f, listing.CurHeight, -1f)[1];
_addons.Begin(addonsRect, addonsRect.height <= _template.AddonsRectHeight);
GuiPlus.DoAddonsListing(_addons, _template, editMode);
_addons.End();
}

GUI.color = color;

var optionGrid = vGrid[2].GetVGrid(2f, 0f, 0f);
var optionGrid = vGrid[2].GetVGrid(2f, -1f, -1f);
listing.Begin(optionGrid[0]);
if (listing.ButtonText(Lang.Get("Button.AssignTo"), Lang.Get("Button.AssignToDesc"), (_floatMenuAssign.Count > 0) && (!editMode || (_template == _personalized)))) { Find.WindowStack.Add(new FloatMenu(_floatMenuAssign)); }
listing.End();
Expand Down
2 changes: 1 addition & 1 deletion Source/Interface/GuiPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class GuiPlus
private static readonly Color InactiveColor = new Color(0.37f, 0.37f, 0.37f, 0.8f);
public static readonly Color ReadOnlyColor = new Color(0.75f, 0.75f, 0.75f, 0.75f);

private static readonly Texture2D EditRulesTexture = ContentFinder<Texture2D>.Get("UI/EditRules");
private static readonly Texture2D EditRulesTexture = ContentFinder<Texture2D>.Get("PawnRules/EditRules");

public static Command_Action EditRulesCommand(Pawn pawn) => new Command_Action
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Interface/Listing_Preset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void DoContent(Rect rect)
if (presets.Any()) { _listing.GapLine(); }
_listing.End();

var presetGrid = rect.GetVGrid(4f, _listing.CurHeight, 0f, 62f);
var presetGrid = rect.GetVGrid(4f, _listing.CurHeight, -1f, 62f);

_presetListing.Begin(presetGrid[1], true);
foreach (var preset in presets)
Expand All @@ -68,7 +68,7 @@ public void DoContent(Rect rect)
}
_presetListing.End();

var buttonGrid = presetGrid[2].GetHGrid(4f, 0f, 0f);
var buttonGrid = presetGrid[2].GetHGrid(4f, -1f, -1f);
_listing.Begin(buttonGrid[0]);

if (_listing.ButtonText(Lang.Get("Button.PresetNew"), Lang.Get("Button.PresetNewDesc"), !EditMode))
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.8";
public const string Version = "1.0.9";

public static ModContentPack ContentPack { get; private set; }

Expand Down
12 changes: 6 additions & 6 deletions Source/Patch/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public static Rect[] GetHGrid(this Rect self, float spacing, params float[] widt
for (var index = 0; index < widths.Length; index++)
{
var width = widths[index];
if (width > 0) { fixedWidths += width; }
if (width >= 0f) { fixedWidths += width; }
else { unfixedCount++; }

if (index != widths.LastIndex()) { fixedWidths += spacing; }
}

var unfixedWidth = unfixedCount > 0 ? (self.width - fixedWidths) / unfixedCount : 0;
var unfixedWidth = unfixedCount > 0 ? (self.width - fixedWidths) / unfixedCount : 0f;

for (var index = 0; index < widths.Length; index++)
{
var width = widths[index];
float newWidth;
if (width > 0)
if (width >= 0f)
{
newWidth = width;
rects[index] = new Rect(currentX, self.y, newWidth, self.height);
Expand All @@ -78,19 +78,19 @@ public static Rect[] GetVGrid(this Rect self, float spacing, params float[] heig
for (var index = 0; index < heights.Length; index++)
{
var height = heights[index];
if (height > 0) { fixedHeights += height; }
if (height >= 0f) { fixedHeights += height; }
else { unfixedCount++; }

if (index != heights.LastIndex()) { fixedHeights += spacing; }
}

var unfixedWidth = unfixedCount > 0 ? (self.height - fixedHeights) / unfixedCount : 0;
var unfixedWidth = unfixedCount > 0 ? (self.height - fixedHeights) / unfixedCount : 0f;

for (var index = 0; index < heights.Length; index++)
{
var height = heights[index];
float newHeight;
if (height > 0)
if (height >= 0f)
{
newHeight = height;
rects[index] = new Rect(self.x, currentY, self.width, newHeight);
Expand Down
2 changes: 1 addition & 1 deletion Source/Patch/RimWorld_FoodUtility_BestFoodInInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(FoodUtility), nameof(FoodUtility.BestFoodInInventory))]
[HarmonyPatch(typeof(FoodUtility), "BestFoodInInventory")]
internal static class RimWorld_FoodUtility_BestFoodInInventory
{
private static bool Prefix(ref Thing __result, Pawn holder, Pawn eater = null, FoodPreferability minFoodPref = FoodPreferability.NeverForNutrition, FoodPreferability maxFoodPref = FoodPreferability.MealLavish, float minStackNutrition = 0.0f, bool allowDrug = false)
Expand Down
2 changes: 1 addition & 1 deletion Source/Patch/RimWorld_FoodUtility_BestFoodSourceOnMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(FoodUtility), nameof(FoodUtility.BestFoodSourceOnMap))]
[HarmonyPatch(typeof(FoodUtility), "BestFoodSourceOnMap")]
internal static class RimWorld_FoodUtility_BestFoodSourceOnMap
{
private static bool Prefix(ref Thing __result, Pawn getter, Pawn eater, bool desperate, out ThingDef foodDef, FoodPreferability maxPref = FoodPreferability.MealLavish, bool allowPlant = true, bool allowDrug = true, bool allowCorpse = true, bool allowDispenserFull = true, bool allowDispenserEmpty = true, bool allowForbidden = false, bool allowSociallyImproper = false, bool allowHarvest = false, bool forceScanWholeMap = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(FoodUtility), nameof(FoodUtility.TryFindBestFoodSourceFor))]
[HarmonyPatch(typeof(FoodUtility), "TryFindBestFoodSourceFor")]
internal static class RimWorld_FoodUtility_TryFindBestFoodSourceFor
{
private static bool Prefix(ref bool __result, Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool allowForbidden = false, bool allowCorpse = true, bool allowSociallyImproper = false, bool allowHarvest = false, bool forceScanWholeMap = false)
Expand Down
2 changes: 1 addition & 1 deletion Source/Patch/RimWorld_GenConstruct_CanConstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(GenConstruct), nameof(GenConstruct.CanConstruct))]
[HarmonyPatch(typeof(GenConstruct), "CanConstruct")]
internal static class RimWorld_GenConstruct_CanConstruct
{
private static void Postfix(ref bool __result, Thing t, Pawn p, bool checkConstructionSkill = true, bool forced = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(InteractionWorker_RomanceAttempt), nameof(InteractionWorker_RomanceAttempt.RandomSelectionWeight))]
[HarmonyPatch(typeof(InteractionWorker_RomanceAttempt), "RandomSelectionWeight")]
internal static class RimWorld_InteractionWorker_RomanceAttempt_RandomSelectionWeight
{
private static bool Prefix(ref float __result, Pawn initiator, Pawn recipient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(InteractionWorker_RomanceAttempt), nameof(InteractionWorker_RomanceAttempt.SuccessChance))]
[HarmonyPatch(typeof(InteractionWorker_RomanceAttempt), "SuccessChance")]
internal static class RimWorld_InteractionWorker_RomanceAttempt_SuccessChance
{
private static bool Prefix(ref float __result, Pawn initiator, Pawn recipient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace PawnRules.Patch
{
[HarmonyPatch(typeof(JobGiver_PackFood), "IsGoodPackableFoodFor")]
internal static class RimWorld_JobGiver_PackFood
internal static class RimWorld_JobGiver_PackFood_IsGoodPackableFoodFor
{
private static void Postfix(ref bool __result, Thing food, Pawn forPawn)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace PawnRules.Patch
{
[HarmonyPatch(typeof(JoyGiver_Ingest), "CanIngestForJoy")]
internal static class RimWorld_JoyGiver_Ingest
internal static class RimWorld_JoyGiver_Ingest_CanIngestForJoy
{
private static bool Prefix(ref bool __result, Pawn pawn, Thing t)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(PawnUtility), nameof(PawnUtility.TrySpawnHatchedOrBornPawn))]
[HarmonyPatch(typeof(PawnUtility), "TrySpawnHatchedOrBornPawn")]
internal static class RimWorld_PawnUtility_TrySpawnHatchedOrBornPawn
{
private static void Postfix(bool __result, Pawn pawn, Thing motherOrEgg)
Expand Down
Loading

0 comments on commit 0a85b5a

Please sign in to comment.