public static bool Notify_CapacityLevelsDirty(PawnCapacitiesHandler __instance) { if (cachedCapacityLevelsDict[__instance] == null) { cachedCapacityLevelsDict[__instance] = new DefMap <PawnCapacityDef, CacheElement2>(); } for (int i = 0; i < cachedCapacityLevelsDict[__instance].Count; i++) { cachedCapacityLevelsDict[__instance][i].status = CacheStatus.Uncached; } return(false); }
public static bool GetLevel(PawnCapacitiesHandler __instance, ref float __result, PawnCapacityDef capacity) { if (pawn(__instance).health.Dead) { __result = 0f; return(false); } //if (cachedCapacityLevels == null) //REMOVED //CacheElement cacheElement = cachedCapacityLevels[capacity]; //REMOVED __result = getCacheElementResult(__instance, capacity); return(false); }
public PawnCapacity(PawnCapacitiesHandler c) { capacities.Add(new KeyValuePair("BloodFiltration", "" + c.GetLevel(PawnCapacityDefOf.BloodFiltration))); capacities.Add(new KeyValuePair("BloodPumping", "" + c.GetLevel(PawnCapacityDefOf.BloodPumping))); capacities.Add(new KeyValuePair("Breathing", "" + c.GetLevel(PawnCapacityDefOf.Breathing))); capacities.Add(new KeyValuePair("Consciousness", "" + c.GetLevel(PawnCapacityDefOf.Consciousness))); capacities.Add(new KeyValuePair("Eating", "" + c.GetLevel(PawnCapacityDefOf.Eating))); capacities.Add(new KeyValuePair("Hearing", "" + c.GetLevel(PawnCapacityDefOf.Hearing))); capacities.Add(new KeyValuePair("Manipulation", "" + c.GetLevel(PawnCapacityDefOf.Manipulation))); capacities.Add(new KeyValuePair("Metabolism", "" + c.GetLevel(PawnCapacityDefOf.Metabolism))); capacities.Add(new KeyValuePair("Moving", "" + c.GetLevel(PawnCapacityDefOf.Moving))); capacities.Add(new KeyValuePair("Sight", "" + c.GetLevel(PawnCapacityDefOf.Sight))); capacities.Add(new KeyValuePair("Talking", "" + c.GetLevel(PawnCapacityDefOf.Talking))); }
private static CacheElement2 get_cacheElement(PawnCapacitiesHandler __instance, PawnCapacityDef capacity) { DefMap <PawnCapacityDef, CacheElement2> defMap = cachedCapacityLevelsDict[__instance]; if (defMap == null) { defMap = new DefMap <PawnCapacityDef, CacheElement2>(); cachedCapacityLevelsDict[__instance] = defMap; for (int i = 0; i < defMap.Count; i++) { defMap[i].status = CacheStatus.Uncached; } } return(defMap[capacity]); }
internal static bool WouldDieWithoutLifeSupport(this Pawn pawn) { PawnCapacitiesHandler capacitiesHandler = pawn.health.capacities; bool isFlesh = pawn.RaceProps.IsFlesh; foreach (PawnCapacityDef pawnCapacityDef in DefDatabase <PawnCapacityDef> .AllDefsListForReading) { if (isFlesh ? !pawnCapacityDef.lethalFlesh : !pawnCapacityDef.lethalMechanoids) { // not deadly } else if (!capacitiesHandler.CapableOf(pawnCapacityDef)) { return(true); } } return(false); }
public static bool GetLevel(PawnCapacitiesHandler __instance, ref float __result, PawnCapacityDef capacity) { if (__instance.pawn.health.Dead) { __result = 0f; return(false); } if (__instance.cachedCapacityLevels == null) { __instance.Notify_CapacityLevelsDirty(); } lock (__instance) { CacheElement cacheElement = __instance.cachedCapacityLevels[capacity]; if (cacheElement.status == CacheStatus.Caching) { Log.Error($"Detected infinite stat recursion when evaluating {capacity}"); __result = 0f; return(false); } if (cacheElement.status == CacheStatus.Uncached) { cacheElement.status = CacheStatus.Caching; try { cacheElement.value = PawnCapacityUtility.CalculateCapacityLevel(__instance.pawn.health.hediffSet, capacity); } finally { cacheElement.status = CacheStatus.Cached; } } __result = cacheElement.value; return(false); } }
public override void PostSpawnSetup(bool respawningAfterLoad) { base.PostSpawnSetup(respawningAfterLoad); setupDone = true; calculated = false; lastPosition = iv3Invalid; lastSightRange = -9999; lastIsPeeking = false; viewMap1 = null; viewMap2 = null; viewRect = new CellRect(-1, -1, 0, 0); viewPositions = new IntVec3[5]; compHiddenable = mainComponent.compHiddenable; compGlower = parent.GetComp <CompGlower>(); compPowerTrader = parent.GetComp <CompPowerTrader>(); compRefuelable = parent.GetComp <CompRefuelable>(); compFlickable = parent.GetComp <CompFlickable>(); compMannable = parent.GetComp <CompMannable>(); compProvideVision = parent.GetComp <CompProvideVision>(); pawn = parent as Pawn; building = parent as Building; turret = parent as Building_TurretGun; if (pawn != null) { raceProps = pawn.RaceProps; hediffs = pawn.health.hediffSet.hediffs; capacities = pawn.health.capacities; } initMap(); def = parent.def; if (def.race != null) { isMechanoid = def.race.IsMechanoid; } else { isMechanoid = false; } if (!isMechanoid) { baseViewRange = NON_MECH_DEFAULT_RANGE; } else { baseViewRange = MECH_DEFAULT_RANGE; } disabled = false; lastMovementTick = Find.TickManager.TicksGame; lastPositionUpdateTick = lastMovementTick; updateFoV(); }
public static bool Clear(PawnCapacitiesHandler __instance) { cachedCapacityLevelsDict[__instance] = null; return(false); }
public static void Postfix_Constructor(PawnCapacitiesHandler __instance, Pawn pawn) { cachedCapacityLevelsDict[__instance] = new DefMap <PawnCapacityDef, CacheElement2>(); }
public override void PostSpawnSetup(bool respawningAfterLoad) { setupDone = true; calculated = false; lastPosition = iv3Invalid; lastSightRange = 0; lastIsPeeking = false; viewMap1 = null; viewMap2 = null; viewRect = new CellRect(-1, -1, 0, 0); viewPositions = new IntVec3[5]; compHiddenable = mainComponent.compHiddenable; compGlower = parent.GetComp <CompGlower>(); compPowerTrader = parent.GetComp <CompPowerTrader>(); compRefuelable = parent.GetComp <CompRefuelable>(); compFlickable = parent.GetComp <CompFlickable>(); compMannable = parent.GetComp <CompMannable>(); compProvideVision = parent.GetComp <CompProvideVision>(); pawn = parent as Pawn; building = parent as Building; turret = parent as Building_TurretGun; if (pawn != null) { raceProps = pawn.RaceProps; hediffs = pawn.health.hediffSet.hediffs; capacities = pawn.health.capacities; pawnPather = pawn.pather; } def = parent.def; if (def.race != null) { isMechanoid = def.race.IsMechanoid; } else { isMechanoid = false; } if (!isMechanoid) { baseViewRange = NON_MECH_DEFAULT_RANGE; } else { baseViewRange = MECH_DEFAULT_RANGE; } if ((pawn == null) && !(turret != null && compMannable == null) && (compProvideVision == null) && (building == null)) { // Disable the component and remove from the main one (this thing doesn't need the FoV calculation). Log.Message("Removing unneeded FoV watcher from " + parent.ThingID); disabled = true; mainComponent.compFieldOfViewWatcher = null; } else { disabled = false; } initMap(); lastMovementTick = Find.TickManager.TicksGame; lastPositionUpdateTick = lastMovementTick; updateFoV(); }