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
11 changes: 9 additions & 2 deletions Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,24 @@ public bool Notify_PostShotFired()
/// available in the inventory.
/// </remarks>
/// <returns></returns>
public bool TryPrepareShot()
public bool TryPrepareShot(int ammoConsumedPerShot = 1)
{
if (HasMagazine)
{
ammoConsumedPerShot = (ammoConsumedPerShot > 0) ? ammoConsumedPerShot : 1;
// If magazine is empty, return false
if (curMagCountInt <= 0)
{
CurMagCount = 0;
return false;
}

if (curMagCountInt - ammoConsumedPerShot < 0)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic makes the game loop if the pawn has no ammo left in the inventory and can`t fire the UB because of insuficcient ammo. More checks could be done to improve logic further

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably make most sense to automatically switch them back to the normal weapon firing mode in that case.

{
TryStartReload();
return false;
}

return true;
}

Expand Down Expand Up @@ -639,7 +646,7 @@ public Job TryMakeReloadJob()

private void DoOutOfAmmoAction()
{
//Don't stow weapon for player pawns when in god mode, can be ammoying when testing single shot weapons.
//Don't stow weapon for player pawns when in god mode, can be annoying when testing single shot weapons.
if (this.parent.def.weaponTags.Contains("NoSwitch") || (DebugSettings.godMode && Wielder != null && (Wielder.IsColonistPlayerControlled || Wielder.IsColonyMech)))
{
return;
Expand Down
5 changes: 3 additions & 2 deletions Source/CombatExtended/CombatExtended/Verbs/Verb_ShootCE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ public void ExternalCallDropCasing(int randomSeedOffset = -1)

public override bool TryCastShot()
{
if (!CompAmmo?.TryPrepareShot() ?? false)
int ammoConsumedPerShot = (CompAmmo.Props.ammoSet?.ammoConsumedPerShot ?? 1) * VerbPropsCE.ammoConsumedPerShotCount;
if (!CompAmmo?.TryPrepareShot(ammoConsumedPerShot) ?? false)
{
return false;
}
Expand Down Expand Up @@ -392,7 +393,7 @@ protected virtual bool OnCastSuccessful()
int ammoConsumedPerShot = (CompAmmo.Props.ammoSet?.ammoConsumedPerShot ?? 1) * VerbPropsCE.ammoConsumedPerShotCount;
CompAmmo.Notify_ShotFired(ammoConsumedPerShot);

if (ShooterPawn != null && !CompAmmo.CanBeFiredNow)
if (ShooterPawn != null && (!CompAmmo.CanBeFiredNow || ammoConsumedPerShot > CompAmmo.CurMagCount))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to add this logic to CompAmmoUser.CanFBeFiredNow(), but I'm not sure if it can/should have access to ammoConsumedPerShot since it comes from VerbPropsCE
Guidance would be welcome :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see... Yeah, kinda unfortunate that the ammo per shot is on the verb rather than on the ammo user. You can get there via CompEquippable.PrimaryVerb within the ammo user comp, just make sure to null-check it in case something strange is going on.

{
CompAmmo.TryStartReload();
resetRetarget();
Expand Down