Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi stack held weapon reloading #3450

Draft
wants to merge 3 commits into
base: Development
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ public bool TryPickupAmmo()
return false;
}

public void LoadAmmo(Thing ammo = null)
public void LoadAmmo(Thing ammo = null, bool emptyMag = false)
{
Building_AutoloaderCE AutoLoader = null;
if (parent is Building_AutoloaderCE)
Expand Down Expand Up @@ -770,7 +770,7 @@ public void LoadAmmo(Thing ammo = null)
else
{
int newAmmoCount = ammoThing.stackCount;
if (turret != null || AutoLoader != null) //Turrets are reloaded without unloading the mag first (if using same ammo type), to support very high capacity magazines
if (!emptyMag) //Turrets are reloaded without unloading the mag first (if using same ammo type), to support very high capacity magazines
{
newAmmoCount += curMagCountInt;
}
Expand Down
14 changes: 13 additions & 1 deletion Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public override IEnumerable<Toil> MakeNewToils()

//Actual reloader
Toil reloadToil = new Toil();
reloadToil.AddFinishAction(() => compReloader.LoadAmmo(initAmmo));
reloadToil.AddFinishAction(() => DoReload());
yield return reloadToil;

// If reloading one shot at a time and if possible to reload, jump back to do-nothing toil
Expand All @@ -218,6 +218,18 @@ public override IEnumerable<Toil> MakeNewToils()
yield return continueToil;
}

void DoReload()
{
compReloader.LoadAmmo(initAmmo, true);
if (!(compReloader.Props.reloadOneAtATime || compReloader.FullMagazine))
{
while (!compReloader.FullMagazine && compReloader.TryFindAmmoInInventory(out initAmmo))
{
compReloader.LoadAmmo(initAmmo);
}
}
}

public override bool TryMakePreToilReservations(bool errorOnFailed)
{
return true;
Expand Down
Loading