Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Killface1980 committed Nov 16, 2017
1 parent b126f21 commit 859ab4a
Show file tree
Hide file tree
Showing 20 changed files with 500 additions and 759 deletions.
Binary file modified Assemblies/Outfitter.dll
Binary file not shown.
9 changes: 0 additions & 9 deletions Defs/JobDefs/Job.xml

This file was deleted.

49 changes: 0 additions & 49 deletions Defs/ThingDefs_Buildings/Buildings_Misc.xml

This file was deleted.

90 changes: 40 additions & 50 deletions Source/Outfitter/ApparelStatCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Outfitter

public partial class ApparelStatCache
{
// public List<Apparel> recentApparel = new List<Apparel>();
// public List<Apparel> recentApparel = new List<Apparel>();

public readonly List<StatPriority> Cache;

Expand All @@ -39,15 +39,15 @@ public partial class ApparelStatCache
private int lastWeightUpdate;

public ApparelStatCache(Pawn pawn)
: this(GameComponent_Outfitter.GetCache(pawn))
: this(pawn.GetSaveablePawn())
{
}

// public NeededWarmth neededWarmth;
public ApparelStatCache([NotNull] SaveablePawn saveablePawn)
{
this.pawn = saveablePawn.Pawn;
this.pawnSave = GameComponent_Outfitter.GetCache(this.pawn);
this.pawnSave = this.pawn.GetSaveablePawn();
this.Cache = new List<StatPriority>();
this.lastStatUpdate = -5000;
this.lastTempUpdate = -5000;
Expand Down Expand Up @@ -75,7 +75,7 @@ public List<StatPriority> StatCache
get
{
// update auto stat priorities roughly between every vanilla gear check cycle
if (Find.TickManager.TicksGame - this.lastStatUpdate > JobGiver_OptimizeApparel.ApparelStatCheck
if (Find.TickManager.TicksGame - this.lastStatUpdate > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck
|| this.pawnSave.forceStatUpdate)
{
// list of auto stats
Expand Down Expand Up @@ -219,6 +219,8 @@ private FloatRange TemperatureWeight
}
}

public Dictionary<Apparel, Pawn> ToDropList = new Dictionary<Apparel, Pawn>();

public static float ApparelScoreRaw_ProtectionBaseStat(Apparel ap)
{
float num = 1f;
Expand Down Expand Up @@ -468,6 +470,7 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel)
// temperature
FloatRange targetTemperatures = this.TargetTemperatures;


// offsets on apparel
float insulationCold = apparel.GetStatValue(StatDefOf.Insulation_Cold);
float insulationHeat = apparel.GetStatValue(StatDefOf.Insulation_Heat);
Expand All @@ -476,48 +479,49 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel)
insulationHeat += apparel.def.equippedStatOffsets.GetStatOffsetFromList(StatDefOf.Insulation_Heat);
{
// offsets on apparel infusions
DoApparelScoreRaw_PawnStatsHandlers(apparel, StatDefOf.Insulation_Cold, out float infInsulationCold);
DoApparelScoreRaw_PawnStatsHandlers(apparel, StatDefOf.Insulation_Heat, out float infInsulationHeat);
DoApparelScoreRaw_PawnStatsHandlers(apparel, StatDefOf.ComfyTemperatureMin, out float infInsulationCold);
DoApparelScoreRaw_PawnStatsHandlers(apparel, StatDefOf.ComfyTemperatureMax, out float infInsulationHeat);
insulationCold += infInsulationCold;
insulationHeat += infInsulationHeat;
}

// string log = apparel.LabelCap + " - InsCold: " + insulationCold + " - InsHeat: " + insulationHeat + " - TargTemp: "
// + targetTemperatures + "\nMinComfy: " + minComfyTemperature + " - MaxComfy: "
// + maxComfyTemperature;
// string log = apparel.LabelCap + " - InsCold: " + insulationCold + " - InsHeat: " + insulationHeat + " - TargTemp: "
// + targetTemperatures + "\nMinComfy: " + minComfyTemperature + " - MaxComfy: "
// + maxComfyTemperature;

// if this gear is currently worn, we need to make sure the contribution to the pawn's comfy temps is removed so the gear is properly scored
List<Apparel> wornApparel = this.pawn.apparel.WornApparel;
if (!wornApparel.NullOrEmpty())
{
if (wornApparel.Contains(apparel))
{
// log += "\nPawn is wearer of this apparel.";
minComfyTemperature -= insulationCold;
maxComfyTemperature -= insulationHeat;
}
else
{
// check if the candidate will replace existing gear
foreach (Apparel ap in wornApparel)
foreach (Apparel wornAp in wornApparel)
{
if (!ApparelUtility.CanWearTogether(ap.def, apparel.def, this.pawn.RaceProps.body))
if (!ApparelUtility.CanWearTogether(wornAp.def, apparel.def, this.pawn.RaceProps.body))
{
float insulationColdWorn = ap.GetStatValue(StatDefOf.Insulation_Cold);
float insulationHeatWorn = ap.GetStatValue(StatDefOf.Insulation_Heat);
float insulationColdWorn = wornAp.GetStatValue(StatDefOf.Insulation_Cold);
float insulationHeatWorn = wornAp.GetStatValue(StatDefOf.Insulation_Heat);

insulationColdWorn +=
ap.def.equippedStatOffsets.GetStatOffsetFromList(StatDefOf.Insulation_Cold);
wornAp.def.equippedStatOffsets.GetStatOffsetFromList(StatDefOf.Insulation_Cold);
insulationHeatWorn +=
ap.def.equippedStatOffsets.GetStatOffsetFromList(StatDefOf.Insulation_Heat);
wornAp.def.equippedStatOffsets.GetStatOffsetFromList(StatDefOf.Insulation_Heat);
{
// offsets on apparel infusions
DoApparelScoreRaw_PawnStatsHandlers(
ap,
StatDefOf.Insulation_Cold,
wornAp,
StatDefOf.ComfyTemperatureMin,
out float infInsulationColdWorn);
DoApparelScoreRaw_PawnStatsHandlers(
ap,
StatDefOf.Insulation_Heat,
wornAp,
StatDefOf.ComfyTemperatureMax,
out float infInsulationHeatWorn);
insulationColdWorn += infInsulationColdWorn;
insulationHeatWorn += infInsulationHeatWorn;
Expand All @@ -532,7 +536,7 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel)
}
}

// log += "\nBasic stat - MinComfy: " + minComfyTemperature + " - MaxComfy: " + maxComfyTemperature;
// log += "\nBasic stat - MinComfy: " + minComfyTemperature + " - MaxComfy: " + maxComfyTemperature;

// now for the interesting bit.
FloatRange temperatureScoreOffset = new FloatRange(0f, 0f);
Expand All @@ -544,15 +548,14 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel)
// isolation_warm is given as positive numbers.
float neededInsulation_Warmth = targetTemperatures.max - maxComfyTemperature;

// log += "\nWeight: " + tempWeight + " - NeedInsCold: " + neededInsulation_Cold + " - NeedInsWarmth: "
// + neededInsulation_Warmth;
// log += "\nWeight: " + tempWeight + " - NeedInsCold: " + neededInsulation_Cold + " - NeedInsWarmth: "
// + neededInsulation_Warmth;

// currently too cold
if (neededInsulation_Cold < 0)
{
temperatureScoreOffset.min += -insulationCold * Math.Abs(tempWeight.min);
}

// currently warm enough
else
{
Expand All @@ -568,7 +571,6 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel)
{
temperatureScoreOffset.max += insulationHeat * Math.Abs(tempWeight.max);
}

// currently cool enough
else
{
Expand All @@ -579,21 +581,21 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel)
* Math.Abs(tempWeight.max);
}
}

// log += "\nScoreOffsetMin: " + temperatureScoreOffset.min + " - ScoreOffsetMax: "
// + temperatureScoreOffset.max + " => 1 +" + (temperatureScoreOffset.min + temperatureScoreOffset.max)
// / 50;
// Log.Message(log);

// Punish bad apparel
temperatureScoreOffset.min *= temperatureScoreOffset.min < 0 ? 2f : 1f;
temperatureScoreOffset.max *= temperatureScoreOffset.max < 0 ? 2f : 1f;

// log += "\nScoreOffsetMin: " + temperatureScoreOffset.min + " - ScoreOffsetMax: "
// + temperatureScoreOffset.max + " => " + 1 + (temperatureScoreOffset.min + temperatureScoreOffset.max) / 25;
//
// Log.Message(log);

return 1 + (temperatureScoreOffset.min + temperatureScoreOffset.max) / 25;
}

public void UpdateTemperatureIfNecessary(bool force = false, bool forceweight = false)
{
if (Find.TickManager.TicksGame - this.lastTempUpdate > JobGiver_OptimizeApparel.ApparelStatCheck || force)
if (Find.TickManager.TicksGame - this.lastTempUpdate > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck || force)
{
// get desired temperatures
if (!this.pawnSave.TargetTemperaturesOverride)
Expand Down Expand Up @@ -627,36 +629,24 @@ public void UpdateTemperatureIfNecessary(bool force = false, bool forceweight =
}
}

if (!this.pawnSave.SetRealComfyTemperatures)
{
this.pawnSave.RealComfyTemperatures.min =
this.pawn.GetStatValue(StatDefOf.ComfyTemperatureMin);
this.pawnSave.RealComfyTemperatures.max =
this.pawn.GetStatValue(StatDefOf.ComfyTemperatureMax);
this.pawnSave.SetRealComfyTemperatures = true;

// this.pawnSave.RealComfyTemperatures.min =
// this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin);
// this.pawnSave.RealComfyTemperatures.max =
// this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax);
// this.pawnSave.SetRealComfyTemperatures = true;
}
var RealComfyTemperatures = this.pawn.ComfortableTemperatureRange();


if (Find.TickManager.TicksGame - this.lastWeightUpdate > JobGiver_OptimizeApparel.ApparelStatCheck
if (Find.TickManager.TicksGame - this.lastWeightUpdate > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck
|| forceweight)
{
FloatRange weight = new FloatRange(1f, 1f);

if (this.pawnSave.TargetTemperatures.min < this.pawnSave.RealComfyTemperatures.min)
if (this.pawnSave.TargetTemperatures.min < RealComfyTemperatures.min)
{
weight.min += Math.Abs(
(this.pawnSave.TargetTemperatures.min - this.pawnSave.RealComfyTemperatures.min) / 100);
(this.pawnSave.TargetTemperatures.min - RealComfyTemperatures.min) / 100);
}

if (this.pawnSave.TargetTemperatures.max > this.pawnSave.RealComfyTemperatures.max)
if (this.pawnSave.TargetTemperatures.max > RealComfyTemperatures.max)
{
weight.max += Math.Abs(
(this.pawnSave.TargetTemperatures.max - this.pawnSave.RealComfyTemperatures.max) / 100);
(this.pawnSave.TargetTemperatures.max - RealComfyTemperatures.max) / 100);
}

this.pawnSave.Temperatureweight = weight;
Expand Down
51 changes: 37 additions & 14 deletions Source/Outfitter/ApparelStatsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static Dictionary<StatDef, float> GetWeightedApparelArmorStats([NotNull]
public static Dictionary<StatDef, float> GetWeightedApparelIndividualStats(this Pawn pawn)
{
Dictionary<StatDef, float> dict = new Dictionary<StatDef, float>();
SaveablePawn pawnSave = GameComponent_Outfitter.GetCache(pawn);
SaveablePawn pawnSave = pawn.GetSaveablePawn();

// dict.Add(StatDefOf.ArmorRating_Blunt, 0.25f);
// dict.Add(StatDefOf.ArmorRating_Sharp, 0.25f);
Expand Down Expand Up @@ -329,7 +329,7 @@ public static Dictionary<StatDef, float> GetWeightedApparelIndividualStats(this
public static Dictionary<StatDef, float> GetWeightedApparelStats(this Pawn pawn)
{
Dictionary<StatDef, float> dict = new Dictionary<StatDef, float>();
SaveablePawn pawnSave = GameComponent_Outfitter.GetCache(pawn);
SaveablePawn pawnSave = pawn.GetSaveablePawn();

// dict.Add(StatDefOf.ArmorRating_Blunt, 0.25f);
// dict.Add(StatDefOf.ArmorRating_Sharp, 0.25f);
Expand All @@ -338,31 +338,51 @@ public static Dictionary<StatDef, float> GetWeightedApparelStats(this Pawn pawn)
if (pawnSave.AddWorkStats)
{
// add weights for all worktypes, multiplied by job priority
List<WorkTypeDef> allDefsListForReading = DefDatabase<WorkTypeDef>.AllDefsListForReading
List<WorkTypeDef> workTypes = DefDatabase<WorkTypeDef>.AllDefsListForReading
.Where(def => pawn.workSettings.WorkIsActive(def)).ToList();

int maxPriority = allDefsListForReading.Aggregate(
int maxPriority = workTypes.Aggregate(
1,
(current, workType) => Mathf.Max(current, pawn.workSettings.GetPriority(workType)));
if (maxPriority < 4)
{
maxPriority = 4;
}
(current, workType) => Mathf.Max(current, pawn.GetWorkPriority(workType)));

int minPriority = workTypes.Aggregate(
1,
(current, workType) => Mathf.Min(current, pawn.GetWorkPriority(workType)));

foreach (WorkTypeDef workType in allDefsListForReading)
var log = "Outfitter Priorities, Pawn: " + pawn + " - Max: " + minPriority + "/" + maxPriority;

foreach (WorkTypeDef workType in workTypes)
{
foreach (KeyValuePair<StatDef, float> stat in GetStatsOfWorkType(pawn, workType))
{
int priority = pawn.workSettings.GetPriority(workType);
int priority = Find.PlaySettings.useWorkPriorities ? pawn.GetWorkPriority(workType) : 3;

float priorityAdjust = 1f / priority / maxPriority;

float weight = stat.Value * priorityAdjust;
for (int i = 0; i < workType.relevantSkills.Count; i++)
{
var relSkill = workType.relevantSkills[i];
SkillRecord record = pawn.skills.GetSkill(relSkill);
float skillMod = 1 + (record.Level / 20);
switch (record.passion)
{
case Passion.None: break;
case Passion.Minor:
skillMod *= 2;
break;
case Passion.Major:
skillMod *= 4;
break;
}
priorityAdjust *= skillMod;
}

AddStatToDict(stat.Key, weight, ref dict);
log += "\n" + workType.defName + " - priority " + "-" + priority + " - adjusted " + priorityAdjust;
}
}

Log.Message(log);
// adjustments for traits
AdjustStatsForTraits(pawn, ref dict);
}
Expand All @@ -377,10 +397,13 @@ public static Dictionary<StatDef, float> GetWeightedApparelStats(this Pawn pawn)
dict[key] /= max / num;
}
}
dict.OrderByDescending(x => x.Value);

return dict;
}



[NotNull]
public static List<StatDef> NotYetAssignedStatDefs([NotNull] this Pawn pawn)
{
Expand Down Expand Up @@ -501,7 +524,7 @@ private static IEnumerable<KeyValuePair<StatDef, float>> GetStatsOfArmorRanged()

private static IEnumerable<KeyValuePair<StatDef, float>> GetStatsOfWorkType(Pawn pawn, WorkTypeDef worktype)
{
SaveablePawn pawnSave = GameComponent_Outfitter.GetCache(pawn);
SaveablePawn pawnSave = pawn.GetSaveablePawn();

if (pawnSave.mainJob == MainJob.Soldier00Close_Combat)
{
Expand Down Expand Up @@ -539,7 +562,7 @@ private static IEnumerable<KeyValuePair<StatDef, float>> GetStatsOfWorkType(Pawn
{
case "Firefighter": yield break;

case "PatientEmergency": yield break;
case "Patient": yield break;

case "Doctor":
if (pawnSave.mainJob == MainJob.Doctor)
Expand Down
Loading

0 comments on commit 859ab4a

Please sign in to comment.