public static bool Capacity(ref float __result, Pawn p, StringBuilder explanation = null) { bool enableCarryingCapacityMass = settings.enableCarryingCapacityMass; if (enableCarryingCapacityMass) { if (!MassUtility.CanEverCarryAnything(p)) { __result = 0f; return(false); } float capacity = p.BodySize * 35f * p.GetStatValue(StatDefOf.CarryingCapacity); if (explanation != null) { if (explanation.Length > 0) { explanation.AppendLine(); } explanation.Append(" - " + p.LabelShortCap + ": " + capacity.ToStringMassOffset()); } __result = capacity; } return(false); }
public static bool Capacity(ref float __result, Pawn p, StringBuilder explanation) { if (!MassUtility.CanEverCarryAnything(p)) { __result = 0f; return(false); } /* Smash Phil Edit */ if (p.def.HasComp(Type.GetType("RimShips.CompShips, RimShips"))) { return(true); } /*=================*/ __result = p.BodySize * p.GetStatValue(StatDefOf.CarryingCapacity); if (explanation != null) { if (explanation.Length > 0) { explanation.AppendLine(); } explanation.Append(" - " + p.LabelShortCap + ": " + __result.ToStringMassOffset()); } return(false); }
public override void TransformValue(StatRequest req, ref float val) { if (req.Thing is Pawn pawn) { if (Compatibility_GiddyUp.GetMount(pawn) != null) { return; } val = Mathf.Clamp(Mathf.RoundToInt(val * _modifier), 0.1f, 100f); if (!MassUtility.CanEverCarryAnything(pawn) || _carrymodifier <= 0f) { return; } var pawnMass = pawn.GetStatValue(StatDefOf.Mass); var ignoredMass = pawnMass * (pawn.RaceProps.packAnimal ? 0.5f : 0.2f); // add our own modifiers var mass = MassUtility.GearAndInventoryMass(pawn); if (Compatibility_GiddyUp.GetRider(pawn) is Pawn rider) { mass += rider.GetStatValue(StatDefOf.Mass, true); var riderCarriedThing = rider.carryTracker.CarriedThing; if (riderCarriedThing != null) { mass += riderCarriedThing.stackCount * riderCarriedThing.GetStatValue(StatDefOf.Mass, true); if (riderCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier val *= 1.666f; } } } var capacity = pawn.GetStatValue(StatDefOf.CarryingCapacity, true); var pawnCarriedThing = pawn.carryTracker.CarriedThing; if (pawnCarriedThing != null) { mass += pawnCarriedThing.stackCount * pawnCarriedThing.GetStatValue(StatDefOf.Mass, true); if (pawnCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier val *= 1.666f; } } var encumbrance = Mathf.Max(mass - ignoredMass, 0f) / capacity; var modifier = 1 / (1 + (encumbrance * _carrymodifier)); val *= modifier; } }
internal static float Capacity(Pawn p) { if (!MassUtility.CanEverCarryAnything(p)) { return(0f); } else { return(p.GetStatValue(CR_StatDefOf.CarryWeight)); } }
private static bool CanMoveInventoryTo(Pawn pawn) { return(MassUtility.CanEverCarryAnything(pawn)); }
private void DrawMass(Rect rect, TransferableOneWay trad, float availableMass) { if (!trad.HasAnyThing) { return; } Thing anyThing = trad.AnyThing; Pawn pawn = anyThing as Pawn; if (pawn != null && !includePawnsMassInMassUsage && !MassUtility.CanEverCarryAnything(pawn)) { return; } Widgets.DrawHighlightIfMouseover(rect); if (pawn == null || includePawnsMassInMassUsage) { float mass = GetMass(anyThing); if (Mouse.IsOver(rect)) { if (pawn != null) { float gearMass = 0f; float invMass = 0f; gearMass = MassUtility.GearMass(pawn); if (!InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignorePawnInventoryMass)) { invMass = MassUtility.InventoryMass(pawn); } TooltipHandler.TipRegion(rect, () => GetPawnMassTip(trad, 0f, mass - gearMass - invMass, gearMass, invMass), trad.GetHashCode() * 59); } else { TooltipHandler.TipRegion(rect, "ItemWeightTip".Translate()); } } if (mass > availableMass) { GUI.color = ColoredText.RedReadable; } else { GUI.color = TransferableOneWayWidget.ItemMassColor; } Widgets.Label(rect, mass.ToStringMass()); } else { float cap = MassUtility.Capacity(pawn, null); float gearMass = MassUtility.GearMass(pawn); float invMass = InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignorePawnInventoryMass) ? 0f : MassUtility.InventoryMass(pawn); float num = cap - gearMass - invMass; if (num > 0f) { GUI.color = Color.green; } else if (num < 0f) { GUI.color = ColoredText.RedReadable; } else { GUI.color = Color.gray; } Widgets.Label(rect, num.ToStringMassOffset()); if (Mouse.IsOver(rect)) { TooltipHandler.TipRegion(rect, () => GetPawnMassTip(trad, cap, 0f, gearMass, invMass), trad.GetHashCode() * 59); } } GUI.color = Color.white; }
//[HarmonyPostfix] public static void TicksPerMove(bool diagonal, Pawn __instance, ref int __result) { if (_carrymodifier == 0f) { return; } if (!MassUtility.CanEverCarryAnything(__instance)) { __result = Mathf.Clamp(Mathf.RoundToInt(__result / _modifier), 1, 450); return; } var c = (float)__result; var pawnMass = __instance.GetStatValue(StatDefOf.Mass); var ignoredMass = pawnMass * (__instance.RaceProps.packAnimal ? 0.5f : 0.2f); if (Compatibility_GiddyUp.GetMount(__instance) is Pawn mount) { __result = diagonal ? mount.TicksPerMoveDiagonal : mount.TicksPerMoveCardinal; return; } // add our own modifiers var mass = ignoredMass - MassUtility.GearAndInventoryMass(__instance); if (Compatibility_GiddyUp.GetRider(__instance) is Pawn rider) { mass += MassUtility.GearAndInventoryMass(rider); mass += rider.GetStatValue(StatDefOf.Mass, true); var riderCarriedThing = rider.carryTracker.CarriedThing; if (riderCarriedThing != null) { mass += riderCarriedThing.stackCount * riderCarriedThing.GetStatValue(StatDefOf.Mass); if (riderCarriedThing is Pawn p) { mass += MassUtility.GearAndInventoryMass(p); // undo carry pawn modifier c /= 1.666f; } } } var capacity = MassUtility.Capacity(__instance, null); var pawnCarriedThing = __instance.carryTracker.CarriedThing; if (pawnCarriedThing != null) { mass += pawnCarriedThing.stackCount * pawnCarriedThing.GetStatValue(StatDefOf.Mass); if (pawnCarriedThing is Pawn p) { mass += MassUtility.GearAndInventoryMass(p); // undo carry pawn modifier c /= 1.666f; } } var encumbrance = Mathf.Clamp(mass / capacity, 0f, 1f); var modifier = 1 + (encumbrance * _carrymodifier); c *= modifier; __result = Mathf.Clamp(Mathf.RoundToInt(c / _modifier), 1, 450); }
public override string ExplanationPart(StatRequest req) { if (_modifier <= 0f) { return(string.Empty); } var sb = new StringBuilder(); if (req.Thing is Pawn pawn) { if (Compatibility_GiddyUp.GetMount(pawn) != null) { return(string.Empty); } sb.AppendLine($"Global speed factor: x{_modifier.ToStringByStyle(ToStringStyle.FloatMaxOne)}"); if (!MassUtility.CanEverCarryAnything(pawn) || _carrymodifier <= 0f) { return(sb.ToString()); } var pawnMass = pawn.GetStatValue(StatDefOf.Mass); var ignoredMass = pawnMass * (pawn.RaceProps.packAnimal ? 0.5f : 0.2f); // add our own modifiers var mass = MassUtility.GearAndInventoryMass(pawn); if (Compatibility_GiddyUp.GetRider(pawn) is Pawn rider) { sb.AppendLine($"Mounted by {rider}, adding {rider.GetStatValue(StatDefOf.Mass, true)} to carried mass."); mass += rider.GetStatValue(StatDefOf.Mass, true); var riderCarriedThing = rider.carryTracker.CarriedThing; if (riderCarriedThing != null) { mass += riderCarriedThing.stackCount * riderCarriedThing.GetStatValue(StatDefOf.Mass, true); if (riderCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier sb.AppendLine($"Carrying {riderCarriedThing}: Undoing hardcoded carrying penalty: x1.6)"); } } } var capacity = pawn.GetStatValue(StatDefOf.CarryingCapacity, true); var pawnCarriedThing = pawn.carryTracker.CarriedThing; if (pawnCarriedThing != null) { mass += pawnCarriedThing.stackCount * pawnCarriedThing.GetStatValue(StatDefOf.Mass, true); if (pawnCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier sb.AppendLine($"Carrying {pawnCarriedThing}: Undoing hardcoded carrying penalty: x1.6)"); } } var encumbrance = Mathf.Max(mass - ignoredMass, 0f) / capacity; var modifier = 1 / (1 + (encumbrance * _carrymodifier)); sb.AppendLine($"Carrying {(int)mass} ({(int)ignoredMass} free) with capacity {(int)capacity} (encumbrance {encumbrance.ToStringByStyle(ToStringStyle.FloatMaxTwo)}) and global factor {_carrymodifier}: x{modifier.ToStringByStyle(ToStringStyle.PercentOne)}"); } return(sb.ToString()); }