From bf03319daaa9f4891780c15b0244c7ee8f7232a3 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Thu, 26 Sep 2024 14:19:45 +0100 Subject: [PATCH 1/3] Update JobDriver_Reload.cs --- .../CombatExtended/Jobs/JobDriver_Reload.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs b/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs index ede693b6b1..e89b51b3bb 100644 --- a/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs +++ b/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs @@ -199,7 +199,7 @@ public override IEnumerable 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 @@ -218,6 +218,18 @@ public override IEnumerable MakeNewToils() yield return continueToil; } + void DoReload() + { + compReloader.LoadAmmo(initAmmo); + if (!(compReloader.Props.reloadOneAtATime || compReloader.FullMagazine)) + { + while (!compReloader.FullMagazine && compReloader.TryFindAmmoInInventory(out initAmmo)) + { + compReloader.LoadAmmo(initAmmo); + } + } + } + public override bool TryMakePreToilReservations(bool errorOnFailed) { return true; From 6390226793cd478a57a2e4358cd246b998115312 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Thu, 26 Sep 2024 14:51:01 +0100 Subject: [PATCH 2/3] Update CompAmmoUser.cs --- Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs b/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs index 154a0445ba..d4b492816c 100644 --- a/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs +++ b/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs @@ -789,7 +789,7 @@ public void LoadAmmo(Thing ammo = null) { newMagCount = (Props.reloadOneAtATime) ? (curMagCountInt + 1) : MagSize; } - CurMagCount = newMagCount; + CurMagCount += newMagCount; if (turret != null) { turret.SetReloading(false); From b68877c357ad8b324c55add6dd2ae8e44ab3a5f8 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Thu, 26 Sep 2024 15:10:22 +0100 Subject: [PATCH 3/3] change again --- Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs | 6 +++--- .../CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs b/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs index d4b492816c..5629deacf5 100644 --- a/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs +++ b/Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs @@ -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) @@ -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; } @@ -789,7 +789,7 @@ public void LoadAmmo(Thing ammo = null) { newMagCount = (Props.reloadOneAtATime) ? (curMagCountInt + 1) : MagSize; } - CurMagCount += newMagCount; + CurMagCount = newMagCount; if (turret != null) { turret.SetReloading(false); diff --git a/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs b/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs index e89b51b3bb..2d4e64c68d 100644 --- a/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs +++ b/Source/CombatExtended/CombatExtended/Jobs/JobDriver_Reload.cs @@ -220,7 +220,7 @@ public override IEnumerable MakeNewToils() void DoReload() { - compReloader.LoadAmmo(initAmmo); + compReloader.LoadAmmo(initAmmo, true); if (!(compReloader.Props.reloadOneAtATime || compReloader.FullMagazine)) { while (!compReloader.FullMagazine && compReloader.TryFindAmmoInInventory(out initAmmo))