Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Languages/English/Keyed/BulkAndWeight.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<CE_drugs>drug policy</CE_drugs>
<CE_loadout>loadout</CE_loadout>
<CE_DetailedWeightTip>Current weight: {1}\nCapacity: {0}\n\nMove speed factor: {2}\nMelee dodge chance factor: {3}\nEncumbrance penalty: {4}</CE_DetailedWeightTip>
<CE_DetailedBulkTip>Current bulk: {1}\nCapacity: {0}\n\nWork speed factor: {2}\nMelee hit chance factor: {3}\nMelee dodge chance factor: {4}</CE_DetailedBulkTip>
<CE_DetailedBulkTip>Current bulk: {1}\nCapacity: {0}\nWorn bulk: {5}\n\nWork speed factor: {2}\nMelee hit chance factor: {3}\nMelee dodge chance factor: {4}</CE_DetailedBulkTip>
<CE_DetailedBaseWeightTip>Current weight: {1}\nBase capacity: {0}\n\nMove speed factor: {2}\nMelee dodge chance factor: {3}\nEncumbrance penalty: {4}</CE_DetailedBaseWeightTip>
<CE_DetailedBaseBulkTip>Current bulk: {1}\nBase capacity: {0}\n\nWork speed factor: {2}\nMelee hit chance factor: {3}\nMelee dodge chance factor: {4}</CE_DetailedBaseBulkTip>
<CE_EmptyLoadoutName>Nothing</CE_EmptyLoadoutName>
Expand Down
32 changes: 20 additions & 12 deletions Source/CombatExtended/CombatExtended/Comps/CompInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CompInventory : ThingComp
private const int CLEANUPTICKINTERVAL = 2100;
private float currentWeightCached;
private float currentBulkCached;
private float currentWornBulkCached;
private List<Thing> ammoListCached = new List<Thing>();
private List<ThingWithComps> meleeWeaponListCached = new List<ThingWithComps>();
private List<ThingWithComps> rangedWeaponListCached = new List<ThingWithComps>();
Expand Down Expand Up @@ -47,6 +48,15 @@ public float currentBulk
return currentBulkCached;
}
}

public float currentWornBulk
{
get
{
return currentWornBulkCached;
}
}

private float availableWeight
{
get
Expand Down Expand Up @@ -97,28 +107,28 @@ public float dodgeChanceFactorWeight
{
get
{
return MassBulkUtility.DodgeWeightFactor(currentWeight, capacityWeight);
return MassBulkUtility.DodgeWeightFactor(currentWeight, capacityWeight) - (1 - MassBulkUtility.DodgeWeightFactor(currentWornBulk, CE_StatDefOf.CarryBulk.defaultBaseValue));
}
}
public float meleeHitChanceFactorBulk
{
get
{
return MassBulkUtility.HitChanceBulkFactor(currentBulk, capacityBulk);
return MassBulkUtility.HitChanceBulkFactor(currentBulk, capacityBulk) - (1 - MassBulkUtility.HitChanceBulkFactor(currentWornBulk, CE_StatDefOf.CarryBulk.defaultBaseValue));
}
}
public float dodgeChanceFactorBulk
{
get
{
return MassBulkUtility.DodgeChanceFactor(currentBulk, capacityBulk);
return MassBulkUtility.DodgeChanceFactor(currentBulk + currentWornBulkCached, capacityBulk) - (1 - MassBulkUtility.DodgeChanceFactor(currentWornBulk, CE_StatDefOf.CarryBulk.defaultBaseValue));
}
}
public float workSpeedFactor
{
get
{
return MassBulkUtility.WorkSpeedFactor(currentBulk, capacityBulk);
return MassBulkUtility.WorkSpeedFactor(currentBulk, capacityBulk) - (1 - MassBulkUtility.WorkSpeedFactor(currentWornBulk, CE_StatDefOf.CarryBulk.defaultBaseValue));
}
}
public float encumberPenalty
Expand Down Expand Up @@ -223,6 +233,7 @@ public void UpdateInventory()
return;
}
float newBulk = 0f;
float newWornBulk = 0f;
float newWeight = 0f;

// Add equipped weapon
Expand All @@ -238,7 +249,7 @@ public void UpdateInventory()
{
float apparelBulk = apparel.GetStatValue(CE_StatDefOf.WornBulk);
float apparelWeight = apparel.GetStatValue(StatDefOf.Mass);
newBulk += apparelBulk;
newWornBulk += apparelBulk;
newWeight += apparelWeight;
if (age > CLEANUPTICKINTERVAL && apparelBulk > 0 && (parentPawn?.Spawned ?? false) && (parentPawn.factionInt?.IsPlayer ?? false))
{
Expand Down Expand Up @@ -299,6 +310,7 @@ public void UpdateInventory()
}
}
currentBulkCached = newBulk;
currentWornBulkCached = newWornBulk;
currentWeightCached = newWeight;
}

Expand All @@ -313,20 +325,18 @@ public void UpdateInventory()
public bool CanFitInInventory(ThingDef thingDef, out int count, bool ignoreEquipment = false, bool useApparelCalculations = false)
{
float thingWeight;
float thingBulk;
float thingBulk = 0f;

if (useApparelCalculations)
{
thingWeight = thingDef.GetStatValueAbstract(StatDefOf.Mass);
thingBulk = thingDef.GetStatValueAbstract(CE_StatDefOf.WornBulk);
if (thingWeight <= 0 && thingBulk <= 0)
if (thingWeight <= 0)
{
count = 1;
return true;
}
// Subtract the stat offsets we get from wearing this
thingWeight -= thingDef.equippedStatOffsets.GetStatOffsetFromList(CE_StatDefOf.CarryWeight);
thingBulk -= thingDef.equippedStatOffsets.GetStatOffsetFromList(CE_StatDefOf.CarryBulk);
}
else
{
Expand Down Expand Up @@ -360,20 +370,18 @@ public bool CanFitInInventory(ThingDef thingDef, out int count, bool ignoreEquip
public bool CanFitInInventory(Thing thing, out int count, bool ignoreEquipment = false, bool useApparelCalculations = false)
{
float thingWeight;
float thingBulk;
float thingBulk = 0f;

if (useApparelCalculations)
{
thingWeight = thing.GetStatValue(StatDefOf.Mass);
thingBulk = thing.GetStatValue(CE_StatDefOf.WornBulk);
if (thingWeight <= 0 && thingBulk <= 0)
{
count = 1;
return true;
}
// Subtract the stat offsets we get from wearing this
thingWeight -= thing.def.equippedStatOffsets.GetStatOffsetFromList(CE_StatDefOf.CarryWeight);
thingBulk -= thing.def.equippedStatOffsets.GetStatOffsetFromList(CE_StatDefOf.CarryBulk);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public static string GetBulkTip(this Pawn pawn)
CE_StatDefOf.CarryBulk.ValueToString(comp.currentBulk, CE_StatDefOf.CarryBulk.toStringNumberSense),
comp.workSpeedFactor.ToStringPercent(),
comp.meleeHitChanceFactorBulk.ToStringPercent(),
comp.dodgeChanceFactorBulk.ToStringPercent());
comp.dodgeChanceFactorBulk.ToStringPercent(),
CE_StatDefOf.WornBulk.ValueToString(comp.currentWornBulk));
}
else
{
Expand Down