Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

[Fix in #1039] Reloading a weapon does not update its weight/bulk values. #937

Closed
Tostov opened this issue Dec 9, 2019 · 5 comments · Fixed by #1039
Closed

[Fix in #1039] Reloading a weapon does not update its weight/bulk values. #937

Tostov opened this issue Dec 9, 2019 · 5 comments · Fixed by #1039
Assignees
Labels
bug C# Requires C# solution

Comments

@Tostov
Copy link
Contributor

Tostov commented Dec 9, 2019

When reloading a weapon, the ammo's mass/bulk that is loaded into the gun is not accounted for after the reload, until the inventory is altered again (e.g. picking up/dropping a item, shooting a weapon, equipping a different weapon.)

@Tostov
Copy link
Contributor Author

Tostov commented Dec 9, 2019

A simmilar issue occurs when unloading a weapon as well. The previously loaded ammo is added to the inventory, but its bulk/mass from being loaded in the gun remains until the inventory is altered again.

@Alicecomma
Copy link
Contributor

The issue suggests that there's a missing CompInventory.UpdateInventory call in CompAmmoUser.LoadAmmo:

LoadAmmo considers the case of ammo == null (unloading) without any calls to UpdateInventory. So, a fix would be to add "if (CompInventory != null) CompInventory.UpdateInventory();".
Similarly, LoadAmmo considers the case where all ammo in the inventory is used up without any calls to UpdateInventory.

@Alicecomma Alicecomma self-assigned this Feb 18, 2020
@Alicecomma
Copy link
Contributor

Further inspection:

  • Loading a weapon decreases inventory mass/bulk but doesn't change weapon mass/bulk
  • Unloading increases mass/bulk but doesn't change weapon mass/bulk
  • Dropping a weapon and equiping it again DOES check whether the weapon is loaded, adding mass/bulk for the loaded weapon: CompInventory.GetEquipmentStats considers loaded bullet weights.

An alternative way to fix this issue is to have a statworker for both mass and bulk, which takes into consideration loaded bullets. This way, loaded guns are heavier also in caravans. This is the desired change:

  • Add StatWorker_Mass, which considers loaded rounds
  • Add StatWorker_Bulk, which considers loaded rounds

The issue with such a change is that if there's other mods with custom StatWorker for Mass or Bulk, they are not accounted for properly. Perhaps there's an alternative way to update these stats on a Thing level.

@Alicecomma
Copy link
Contributor

Simplified the StatWorker stuff into a single StatWorker_LoadedAmmo, which considers Mass or Bulk separately for whatever stat (mass or bulk) it is attached to. This means that any StatDef could re-use this method of accessing loaded projectiles.

image

Alicecomma added a commit that referenced this issue Feb 18, 2020
- CE_StatsReport_LoadedAmmo added to language keys (needs translation)
- Stats.xml patched to add CombatExtended.StatPart_LoadedAmmo to Mass stat
- Added file StatPart_LoadedAmmo
- CompAmmoUser now immediately calls UpdateInventory WHENEVER CurMagCount is changed, as it should be
- CompInventory stopped looking at loaded ammo for weight/bulk
- StatPart_LoadedAmmo was added, which does everything previously done in CompInventory, but which is common in current RimWorld versions
@zozilin zozilin linked a pull request Feb 18, 2020 that will close this issue
@Alicecomma
Copy link
Contributor

Alicecomma commented Feb 19, 2020

Issue to be resolved:

  • Add XML tag to weapons to decide whether loading ammo into them increases bulk/wornbulk
    Added XML tag "loadedAmmoBulkFactor" to CompProperties_AmmoUser. Intended use:
<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
    <defName>CE_Gun_RPGSeven</defName>
    <AmmoUser>
        <loadedAmmoBulkFactor>1</loadedAmmoBulkFactor>
    </AmmoUser>
</Operation>
<ThingDef ParentName="BaseMakeableGun">
    <defName>CE_Gun_RPGSeven</defName>
    <comps>
        <li Class="CombatExtended.CompProperties_AmmoUser">
            <loadedAmmoBulkFactor>1</loadedAmmoBulkFactor>
        </li>
    </comps>
</ThingDef>

@Alicecomma Alicecomma changed the title Reloading a weapon does not update its weight/bulk values. [Fixed in #999] Reloading a weapon does not update its weight/bulk values. Feb 19, 2020
@Alicecomma Alicecomma changed the title [Fixed in #999] Reloading a weapon does not update its weight/bulk values. [Fix in #999] Reloading a weapon does not update its weight/bulk values. Feb 19, 2020
Alicecomma added a commit that referenced this issue Feb 21, 2020
- CE_StatsReport_LoadedAmmo added to language keys (needs translation)
- Stats.xml patched to add CombatExtended.StatPart_LoadedAmmo to Mass stat
- Added file StatPart_LoadedAmmo
- CompAmmoUser now immediately calls UpdateInventory WHENEVER CurMagCount is changed, as it should be
- CompInventory stopped looking at loaded ammo for weight/bulk
- StatPart_LoadedAmmo was added, which does everything previously done in CompInventory, but which is common in current RimWorld versions
- Bulk StatDef now uses StatPart_LoadedAmmo
- AmmoUser CompProperties include a loadedAmmoBulkFactor with default value 0f. This allows RPG-7 and similar weapons to have a higher bulkiness (volume) when loaded.
- StatPart_LoadedAmmo multiplies by loadedAmmoBulkFactor when parentStat is Bulk
@Alicecomma Alicecomma changed the title [Fix in #999] Reloading a weapon does not update its weight/bulk values. [Fix in #1039] Reloading a weapon does not update its weight/bulk values. Feb 21, 2020
@Alicecomma Alicecomma added the C# Requires C# solution label Feb 22, 2020
@zozilin zozilin linked a pull request Feb 22, 2020 that will close this issue
zozilin added a commit that referenced this issue Feb 22, 2020
Fix #937 (loaded ammo has weight/bulk update properly)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug C# Requires C# solution
Projects
None yet
3 participants