Skip to content

Commit

Permalink
Added normalized stats, officially 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehni committed Dec 13, 2020
1 parent 6c1c3c2 commit 60e889b
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 55 deletions.
Binary file modified 1.1/Assemblies/Numbers.dll
Binary file not shown.
11 changes: 7 additions & 4 deletions 1.1/Defs/PawnColumnDef/PawnColumns_Numbers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<sortable>true</sortable>
<label>Title</label>
</PawnColumnDef>

<PawnColumnDef>
<defName>Numbers_Psyfocus</defName>
<workerClass>Numbers.PawnColumnWorker_Psyfocus</workerClass>
Expand All @@ -54,7 +54,7 @@
<li Class="Numbers.DefModExtension_NeedsRoyalty"/>
</modExtensions>
</PawnColumnDef>

<PawnColumnDef>
<defName>Numbers_Entropy</defName>
<workerClass>Numbers.PawnColumnWorker_Entropy</workerClass>
Expand All @@ -64,7 +64,7 @@
<li Class="Numbers.DefModExtension_NeedsRoyalty"/>
</modExtensions>
</PawnColumnDef>

<PawnColumnDef>
<defName>Numbers_PsylinkLevel</defName>
<workerClass>Numbers.PawnColumnWorker_PsylinkLevel</workerClass>
Expand Down Expand Up @@ -240,11 +240,14 @@
<label>Filth rate</label>
</PawnColumnDef>

<PawnColumnDef>
<PawnColumnDef>
<defName>Numbers_Meditation</defName>
<workerClass>Numbers.PawnColumnWorker_Meditation</workerClass>
<sortable>true</sortable>
<label>Focus</label>
<modExtensions>
<li Class="Numbers.DefModExtension_NeedsRoyalty"/>
</modExtensions>
</PawnColumnDef>

</Defs>
6 changes: 3 additions & 3 deletions 1.1/Defs/PawnTableDef/Numbers_PawnTableDef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<li>Numbers_Pain</li>
<li>Numbers_RimWorld_StatDef_MeleeDPS</li>
<li>Numbers_RimWorld_StatDef_ShootingAccuracyPawn</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed_Normalized</li>
</columns>
<modExtensions>
<li Class="Numbers.DefModExtension_PawnTableDefs">
Expand Down Expand Up @@ -196,7 +196,7 @@
<li>Numbers_Equipment</li>
<li>Numbers_RimWorld_StatDef_ShootingAccuracyPawn</li>
<li>Numbers_RimWorld_RecordDef_Kills</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed_Normalized</li>
<li>Numbers_RimWorld_StatDef_MeleeDPS</li>
<li>Numbers_RimWorld_NeedDef_Food</li>
<li>Numbers_RimWorld_NeedDef_Mood</li>
Expand All @@ -217,7 +217,7 @@
<workerClass>Numbers.PawnTable_NumbersMain</workerClass>
<columns>
<li>Label</li>
<li>Numbers_RimWorld_StatDef_WorkSpeedGlobal</li>
<li>Numbers_RimWorld_StatDef_WorkSpeedGlobal_Normalized</li>
<li>WorkPriority_Patient</li>
<li>Numbers_NeedsTreatment</li>
<li>WorkPriority_Doctor</li>
Expand Down
37 changes: 37 additions & 0 deletions 1.1/Defs/StatDefs/NormalizedStatDefs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>

<StatDef>
<defName>WorkSpeedGlobal_Normalized</defName>
<label>global work speed (normalized)</label>
<description>A multiplier on a character's speed at doing any kind of work. Environmental factors such as darkness are removed for better comparison values.</description>
<category>PawnWork</category>
<defaultBaseValue>1</defaultBaseValue>
<minValue>0.3</minValue>
<toStringStyle>PercentZero</toStringStyle>
<alwaysHide>true</alwaysHide>
<scenarioRandomizable>true</scenarioRandomizable>
<displayPriorityInCategory>5000</displayPriorityInCategory>
</StatDef>

<StatDef>
<defName>MoveSpeed_Normalized</defName>
<label>move speed (normalized)</label>
<description>Speed of movement in cells per second. Environmental factors such as darkness are removed for better comparison values.</description>
<category>BasicsPawn</category>
<defaultBaseValue>3.0</defaultBaseValue>
<minValue>0.15</minValue>
<toStringStyle>FloatTwo</toStringStyle>
<formatString>{0} c/s</formatString>
<capacityFactors>
<li>
<capacity>Moving</capacity>
<weight>1</weight>
</li>
</capacityFactors>
<alwaysHide>true</alwaysHide>
<scenarioRandomizable>true</scenarioRandomizable>
<displayPriorityInCategory>2500</displayPriorityInCategory>
</StatDef>

</Defs>
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
<li>1.2</li>
</supportedVersions>
<description>Adds a customizable general overview tab, allowing you to see any stats on all your colonists or prisoners in a single window. Original by koisama. Updated, expanded and maintained by Mehni.</description>
</ModMetaData>
6 changes: 3 additions & 3 deletions Defs/PawnTableDef/Numbers_PawnTableDef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<li>Numbers_Pain</li>
<li>Numbers_RimWorld_StatDef_MeleeDPS</li>
<li>Numbers_RimWorld_StatDef_ShootingAccuracyPawn</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed_Normalized</li>
</columns>
<modExtensions>
<li Class="Numbers.DefModExtension_PawnTableDefs">
Expand Down Expand Up @@ -195,7 +195,7 @@
<li>Numbers_Equipment</li>
<li>Numbers_RimWorld_StatDef_ShootingAccuracyPawn</li>
<li>Numbers_RimWorld_RecordDef_Kills</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed</li>
<li>Numbers_RimWorld_StatDef_MoveSpeed_Normalized</li>
<li>Numbers_RimWorld_StatDef_MeleeDPS</li>
<li>Numbers_RimWorld_NeedDef_Food</li>
<li>Numbers_RimWorld_NeedDef_Mood</li>
Expand All @@ -216,7 +216,7 @@
<workerClass>Numbers.PawnTable_NumbersMain</workerClass>
<columns>
<li>Label</li>
<li>Numbers_RimWorld_StatDef_WorkSpeedGlobal</li>
<li>Numbers_RimWorld_StatDef_WorkSpeedGlobal_Normalized</li>
<li>WorkPriority_Patient</li>
<li>Numbers_NeedsTreatment</li>
<li>WorkPriority_Doctor</li>
Expand Down
12 changes: 9 additions & 3 deletions Numbers/MainTabWindow_Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,18 @@ private List<StatDef> GetHumanLikeStatDefs()
var pawnHumanlikeStatDef = source
.Concat(tmpPawn.def.SpecialDisplayStats(StatRequest.For(tmpPawn)))
.Where(s => s.stat != null && s.ShouldDisplay && s.stat.Worker != null)
.Select(s => s.stat)
.OrderBy(stat => stat.LabelCap.Resolve());
.Select(s => s.stat);

tmpPawn.Destroy(DestroyMode.KillFinalize);

return pawnHumanlikeStatDef.ToList();
return SubstituteEnvironmentalStatDefsForNormalizedVersion(pawnHumanlikeStatDef).OrderBy(stat => stat.LabelCap.Resolve()).ToList();
}

private IEnumerable<StatDef> SubstituteEnvironmentalStatDefsForNormalizedVersion(IEnumerable<StatDef> list)
{
return list
.Concat(new[] { DefDatabase<StatDef>.GetNamed("MoveSpeed_Normalized"), DefDatabase<StatDef>.GetNamed("WorkSpeedGlobal_Normalized") })
.Where(x => x.parts == null || x.GetStatPart<StatPart_Glow>() == null);
}
}
}
8 changes: 7 additions & 1 deletion Numbers/Numbers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.8, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\..\..\workshop\content\294100\2009463077\v1.1\Assemblies\0Harmony.dll</HintPath>
<HintPath>..\..\..\..\..\workshop\content\294100\2009463077\Current\Assemblies\0Harmony.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
Expand Down Expand Up @@ -74,16 +74,19 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DefModExtension_NeedsRoyalty.cs" />
<Compile Include="DefModExtension_PawnTableDefs.cs" />
<Compile Include="Dialog_IHaveToCreateAnEntireFuckingDialogForANOKAYBUTTONFFS.cs" />
<Compile Include="MainTabWindow_Numbers.cs" />
<Compile Include="DefModExtension_PawnColumnDefs.cs" />
<Compile Include="HorribleStringParsersForSaving.cs" />
<Compile Include="MainTabWindow_NumbersAnimals.cs" />
<Compile Include="Numbers_PawnColumnDef.cs" />
<Compile Include="Numbers_Settings.cs" />
<Compile Include="Numbers_SettingsHelper.cs" />
<Compile Include="Numbers_Utility.cs" />
<Compile Include="OptionsMaker.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Ability.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Age.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_AllHediffs.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_AnimalMilkFullness.cs" />
Expand All @@ -95,6 +98,7 @@
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Capacity.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_AnimalEggProgress.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_DiseaseProgression.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Entropy.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Faction.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Forbidden.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Gear.cs" />
Expand All @@ -111,6 +115,8 @@
<Compile Include="PawnColumnWorkers\PawnColumnWorker_PrisonerRecruitmentDifficulty.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_PrisonerResistance.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_JobQueued.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Psyfocus.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_PsylinkLevel.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Race.cs" />
<Compile Include="Numbers.cs" />
<Compile Include="PawnColumnWorkers\PawnColumnWorker_Record.cs" />
Expand Down
6 changes: 1 addition & 5 deletions Numbers/Numbers_PawnColumnDef.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using RimWorld;
using Verse;

namespace Numbers
Expand Down
22 changes: 13 additions & 9 deletions Numbers/Numbers_Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,28 @@ public static bool IsWildAnimal(this Pawn p)
=> p.Faction == null
&& p.AnimalOrWildMan();

public static DefModExtension_PawnColumnDefs Ext(this PawnColumnDef def, bool throwError = true)
public static DefModExtension_PawnColumnDefs Ext(this PawnColumnDef def, bool logError = true)
{
if (throwError && !def.HasModExtension<DefModExtension_PawnColumnDefs>())
var ext = def.GetModExtension<DefModExtension_PawnColumnDefs>();

if (logError && ext == null)
{
Log.Error("Numbers expected DefModExtension PawnColumnDefs, got null");
return null;
Log.Error($"Numbers expected DefModExtension PawnColumnDefs, got null for def {def.defName}");
}
return def.GetModExtension<DefModExtension_PawnColumnDefs>();

return ext;
}

public static DefModExtension_PawnTableDefs Ext(this PawnTableDef def)
{
if (!def.HasModExtension<DefModExtension_PawnTableDefs>())
var ext = def.GetModExtension<DefModExtension_PawnTableDefs>();

if (ext == null)
{
Log.Error("Numbers expected DefModExtension PawnTableDef, got null");
return null;
Log.Error($"Numbers expected DefModExtension PawnTableDef, got null for def {def.defName}");
}
return def.GetModExtension<DefModExtension_PawnTableDefs>();

return ext;
}

public static string WordWrapAt(this string text, float length, PawnTable table = null)
Expand Down
2 changes: 1 addition & 1 deletion Numbers/PawnColumnWorkers/PawnColumnWorker_Bleedrate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Color FindPrettyColourForBleedingPawn(Pawn pawn)

return Mathf.Approximately(isThisMyBlood, 1f)
? SeverePainColor
: HealthUtility.DarkRedColor;
: HealthUtility.RedColor;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
bool redFlag = !(severityChangePerDayFromTendD + severityChangePerDayFromImmu > immunityPerDay);

Texture2D texture2D = redFlag ? StaticConstructorOnGameStart.SortingIcon : StaticConstructorOnGameStart.SortingDescendingIcon;
GUI.color = redFlag ? HealthUtility.GoodConditionColor : HealthUtility.DarkRedColor;
GUI.color = redFlag ? HealthUtility.GoodConditionColor : HealthUtility.RedColor;
Rect position2 = new Rect(rect.xMax - texture2D.width - 1f, rect.yMax - texture2D.height - 1f, texture2D.width, texture2D.height);
GUI.DrawTexture(position2, texture2D);
GUI.color = Color.white;
Expand Down Expand Up @@ -132,7 +132,7 @@ private float GetTextFor(HediffWithComps hediff)
private Color GetPrettyColorFor(float deltaSeverity)
{
if (deltaSeverity <= -0.4f)
return HealthUtility.DarkRedColor;
return HealthUtility.RedColor;

if (deltaSeverity <= -0.2f)
return SeverePainColor;
Expand Down
29 changes: 10 additions & 19 deletions Numbers/PawnColumnWorkers/PawnColumnWorker_Gear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private void DrawThing(Rect rect, Thing thing, Pawn selPawn)

if (selPawn.IsColonistPlayerControlled)
{
Action action = DropThing(thing, selPawn);
list.Add(new FloatMenuOption("DropThing".Translate(), action));
Action dropAction = DropThing(thing, selPawn);
list.Add(new FloatMenuOption("DropThing".Translate(), dropAction));
}
FloatMenu window = new FloatMenu(list, thing.LabelCap);
Find.WindowStack.Add(window);
Expand All @@ -77,31 +77,22 @@ private void DrawThing(Rect rect, Thing thing, Pawn selPawn)

private static Action DropThing(Thing thing, Pawn selPawn)
{
Action action = null;
ThingWithComps eq = thing as ThingWithComps;
if (thing is Apparel ap && selPawn.apparel != null && selPawn.apparel.WornApparel.Contains(ap))
{
action = delegate
{
selPawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.RemoveApparel, ap));
};
return () => selPawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.RemoveApparel, ap));
}
else if (eq != null && selPawn.equipment.AllEquipmentListForReading.Contains(eq))

if (thing is ThingWithComps eq && selPawn.equipment.AllEquipmentListForReading.Contains(eq))
{
action = delegate
{
selPawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.DropEquipment, eq));
};
return() => selPawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.DropEquipment, eq));
}
else if (!thing.def.destroyOnDrop)

if (!thing.def.destroyOnDrop)
{
action = delegate
{
selPawn.inventory.innerContainer.TryDrop(thing, selPawn.Position, selPawn.Map, ThingPlaceMode.Near, out Thing unused);
};
return () => selPawn.inventory.innerContainer.TryDrop(thing, selPawn.Position, selPawn.Map, ThingPlaceMode.Near, out Thing unused);
}

return action;
return null;
}

public override int Compare(Pawn a, Pawn b)
Expand Down
1 change: 0 additions & 1 deletion Numbers/PawnColumnWorkers/PawnColumnWorker_PsylinkLevel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Numbers
{
using System;
using RimWorld;
using Verse;

Expand Down
8 changes: 4 additions & 4 deletions Numbers/StaticConstructorOnGameStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static StaticConstructorOnGameStart()

AddRemainingSpaceToPawnTableDefs();

AddHeadersToPawnColumns();
AddHeaderToolTipToPawnColumns();

PopulatePresets();

Expand Down Expand Up @@ -72,7 +72,7 @@ private static void AddRemainingSpaceToPawnTableDefs()
}
}

private static void AddHeadersToPawnColumns()
private static void AddHeaderToolTipToPawnColumns()
{
foreach (PawnColumnDef pawnColumnDef in DefDatabase<PawnColumnDef>
.AllDefsListForReading
Expand All @@ -81,7 +81,7 @@ private static void AddHeadersToPawnColumns()
&& !(x.Worker is PawnColumnWorker_AllHediffs
|| x.Worker is PawnColumnWorker_SelfTend
|| x.Worker is PawnColumnWorker_ManhunterOnTameFailChance
|| x.Worker is PawnColumnWorker_Ability))) //special treatment for those.
|| x.Worker is PawnColumnWorker_Ability))) //these PawnColumnWorkers override GetHeaderTip.
{
pawnColumnDef.headerTip += (pawnColumnDef.headerTip.NullOrEmpty() ? "" : "\n\n") + "Numbers_ColumnHeader_Tooltip".Translate();
}
Expand All @@ -103,7 +103,7 @@ private static void PopulatePsycastingPreset()
psycastingPreset.Add(DefDatabase<PawnColumnDef>.GetNamed("Numbers_Psyfocus"));
psycastingPreset.Add(DefDatabase<PawnColumnDef>.GetNamed("Numbers_Entropy"));
psycastingPreset.AddRange(
DefDatabase<PawnColumnDef>.AllDefsListForReading.Where(pcd => pcd.Ext(throwError: false)?.ability != null).ToList()
DefDatabase<PawnColumnDef>.AllDefsListForReading.Where(pcd => pcd.Ext(logError: false)?.ability != null).ToList()
.OrderBy(x => x.Ext().ability.level)
.ThenBy(x => x.Ext().ability.PsyfocusCost)
.ThenBy(x => x.Ext().ability.EntropyGain)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ It can be added to existing saves without problems.
- [GitHub](https://github.com/Mehni/kNumbers)
- [All the releases](https://github.com/Mehni/kNumbers/releases)

## Credits

Much thanks to [Maarxx](https://github.com/maarxx) for singlehandedly adding support for Royalty. Check out their mods [here](https://ludeon.com/forums/index.php?topic=53539)!

## License

Original idea by koisama: https://github.com/koisama/kNumbers, whose original license I respect by the preceding link. For the license since 2018/11/21, see LICENSE.

0 comments on commit 60e889b

Please sign in to comment.