From c72441e65b8f355fd29a893061b6eb20d5e83162 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sat, 9 Sep 2023 18:58:18 +0100 Subject: [PATCH 01/15] initPush --- .../CombatExtended/CE_Utility.cs | 53 +++++++++++++++++++ .../Things/Building_TurretGunCE.cs | 5 +- .../Verbs/Verb_LaunchProjectileCE.cs | 1 + 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index b4b9af0c63..5119c5bbcd 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -733,6 +733,59 @@ public static Thing GetWeaponFromLauncher(Thing launcher) } */ + /// + /// A copy of the same function in Rimworld.EquipmentUtility, except changing requirement to Verb. + /// + /// + private static readonly SimpleCurve RecoilCurveAxisX = new SimpleCurve + { + new CurvePoint(0f, 0f), + new CurvePoint(1f, 0.02f), + new CurvePoint(2f, 0.03f) + }; + + private static readonly SimpleCurve RecoilCurveAxisY = new SimpleCurve + { + new CurvePoint(0f, 0f), + new CurvePoint(1f, 0.05f), + new CurvePoint(2f, 0.075f) + }; + + private static readonly SimpleCurve RecoilCurveRotation = new SimpleCurve + { + new CurvePoint(0f, 0f), + new CurvePoint(1f, 3f), + new CurvePoint(2f, 4f) + }; + + public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle) + { + drawOffset = Vector3.zero; + angleOffset = 0f; + float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount * 10; + if (!(recoil > 0f) || shootVerb == null) + { + return; + } + Rand.PushState(shootVerb.LastShotTick); + try + { + int num = Find.TickManager.TicksGame - shootVerb.LastShotTick; + if ((float)num < weaponDef.verbs[0].ticksBetweenBurstShots) + { + float num2 = Mathf.Clamp01((float)num / weaponDef.verbs[0].ticksBetweenBurstShots); + float num3 = Mathf.Lerp(recoil, 0f, num2); + drawOffset = new Vector3((float)Rand.Sign * RecoilCurveAxisX.Evaluate(num2), 0f, 0f - RecoilCurveAxisY.Evaluate(num2)) * num3; + angleOffset = (float)Rand.Sign * RecoilCurveRotation.Evaluate(num2) * num3; + drawOffset = drawOffset.RotatedBy(aimAngle); + } + } + finally + { + Log.Message(drawOffset.ToString() + " " + angleOffset.ToString()); + Rand.PopState(); + } + } #endregion Misc #region MoteThrower diff --git a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs index 99bb02f5d3..bd0ca7af6f 100644 --- a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs +++ b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs @@ -574,7 +574,10 @@ public override string GetInspectString() // Replaced vanilla loaded text public override void Draw() { - top.DrawTurret(Vector3.zero, 0f); + Vector3 drawOffset = Vector3.zero; + float angleOffset = 0f; + CE_Utility.Recoil(def.building.turretGunDef, AttackVerb, out drawOffset, out angleOffset, top.CurRotation); + top.DrawTurret(drawOffset, angleOffset); base.Draw(); } diff --git a/Source/CombatExtended/CombatExtended/Verbs/Verb_LaunchProjectileCE.cs b/Source/CombatExtended/CombatExtended/Verbs/Verb_LaunchProjectileCE.cs index 34f0835f61..3a96eafa35 100644 --- a/Source/CombatExtended/CombatExtended/Verbs/Verb_LaunchProjectileCE.cs +++ b/Source/CombatExtended/CombatExtended/Verbs/Verb_LaunchProjectileCE.cs @@ -1085,6 +1085,7 @@ public override bool TryCastShot() CompReloadable.UsedOnce(); } } + lastShotTick = Find.TickManager.TicksGame; return true; } From c6526b61c6ae1f3485195367b20b2261c584b333 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sat, 9 Sep 2023 19:01:34 +0100 Subject: [PATCH 02/15] add angle offset back before I decide if to remove it --- Source/CombatExtended/CombatExtended/CE_Utility.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 5119c5bbcd..bef7c01282 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -777,6 +777,7 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf float num3 = Mathf.Lerp(recoil, 0f, num2); drawOffset = new Vector3((float)Rand.Sign * RecoilCurveAxisX.Evaluate(num2), 0f, 0f - RecoilCurveAxisY.Evaluate(num2)) * num3; angleOffset = (float)Rand.Sign * RecoilCurveRotation.Evaluate(num2) * num3; + aimAngle += angleOffset; drawOffset = drawOffset.RotatedBy(aimAngle); } } From 01924ad37c09365ede804cf64543e3e8e21e804c Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sat, 9 Sep 2023 19:43:45 +0100 Subject: [PATCH 03/15] more fiddles --- .../CombatExtended/CE_Utility.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index bef7c01282..064b0bc5d5 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -737,12 +737,6 @@ public static Thing GetWeaponFromLauncher(Thing launcher) /// A copy of the same function in Rimworld.EquipmentUtility, except changing requirement to Verb. /// /// - private static readonly SimpleCurve RecoilCurveAxisX = new SimpleCurve - { - new CurvePoint(0f, 0f), - new CurvePoint(1f, 0.02f), - new CurvePoint(2f, 0.03f) - }; private static readonly SimpleCurve RecoilCurveAxisY = new SimpleCurve { @@ -758,11 +752,14 @@ public static Thing GetWeaponFromLauncher(Thing launcher) new CurvePoint(2f, 4f) }; + const float recoilMagicNumber = 20; + public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle) { drawOffset = Vector3.zero; angleOffset = 0f; - float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount * 10; + float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount * Math.Min(recoilMagicNumber, recoilMagicNumber / weaponDef.verbs[0].ticksBetweenBurstShots); + float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) / 2f; if (!(recoil > 0f) || shootVerb == null) { return; @@ -771,19 +768,18 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf try { int num = Find.TickManager.TicksGame - shootVerb.LastShotTick; - if ((float)num < weaponDef.verbs[0].ticksBetweenBurstShots) + if ((float)num < recoilRelaxation) { - float num2 = Mathf.Clamp01((float)num / weaponDef.verbs[0].ticksBetweenBurstShots); + float num2 = Mathf.Clamp01((float)num / recoilRelaxation); float num3 = Mathf.Lerp(recoil, 0f, num2); - drawOffset = new Vector3((float)Rand.Sign * RecoilCurveAxisX.Evaluate(num2), 0f, 0f - RecoilCurveAxisY.Evaluate(num2)) * num3; + drawOffset = new Vector3(0f, 0f, 0f - RecoilCurveAxisY.Evaluate(num2)) * num3; angleOffset = (float)Rand.Sign * RecoilCurveRotation.Evaluate(num2) * num3; - aimAngle += angleOffset; drawOffset = drawOffset.RotatedBy(aimAngle); + aimAngle += angleOffset; } } finally { - Log.Message(drawOffset.ToString() + " " + angleOffset.ToString()); Rand.PopState(); } } From e6c0b8485c88d6b2cb21844e530f7f6aeb736eb7 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sat, 9 Sep 2023 20:28:08 +0100 Subject: [PATCH 04/15] squared recoil --- Source/CombatExtended/CombatExtended/CE_Utility.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 064b0bc5d5..26b27180fb 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -752,15 +752,17 @@ public static Thing GetWeaponFromLauncher(Thing launcher) new CurvePoint(2f, 4f) }; - const float recoilMagicNumber = 20; + const float RecoilMagicNumber = 20; public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle) { drawOffset = Vector3.zero; angleOffset = 0f; - float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount * Math.Min(recoilMagicNumber, recoilMagicNumber / weaponDef.verbs[0].ticksBetweenBurstShots); - float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) / 2f; - if (!(recoil > 0f) || shootVerb == null) + float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount; + recoil = recoil * recoil * Mathf.Clamp(RecoilMagicNumber / weaponDef.verbs[0].ticksBetweenBurstShots, 1, RecoilMagicNumber); + + float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; + if (recoil <= 0f || shootVerb == null) { return; } @@ -776,6 +778,8 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf angleOffset = (float)Rand.Sign * RecoilCurveRotation.Evaluate(num2) * num3; drawOffset = drawOffset.RotatedBy(aimAngle); aimAngle += angleOffset; + + Log.Message(recoil.ToString() + " " + recoilRelaxation.ToString()); } } finally From b4d5cd603e13bfdb027173bfe1320813c600e27c Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sat, 9 Sep 2023 21:44:05 +0100 Subject: [PATCH 05/15] mod extension for outliers --- .../CombatExtended/CombatExtended/CE_Utility.cs | 12 ++++++++++-- .../CombatExtended/Defs/RecoilAdjustExtension.cs | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 26b27180fb..0116354ea7 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -759,13 +759,21 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf drawOffset = Vector3.zero; angleOffset = 0f; float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount; - recoil = recoil * recoil * Mathf.Clamp(RecoilMagicNumber / weaponDef.verbs[0].ticksBetweenBurstShots, 1, RecoilMagicNumber); - + recoil = Math.Min(recoil * recoil, 20) * Mathf.Clamp(RecoilMagicNumber / weaponDef.verbs[0].ticksBetweenBurstShots, 1, RecoilMagicNumber); float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; + RecoilAdjustExtension RecoilAdjustExtension = weaponDef.GetModExtension(); + + if (RecoilAdjustExtension != null) + { + recoil *= RecoilAdjustExtension.recoilModifier; + recoilRelaxation = RecoilAdjustExtension.recoilTick > 0 ? RecoilAdjustExtension.recoilTick : recoilRelaxation; + } + if (recoil <= 0f || shootVerb == null) { return; } + Rand.PushState(shootVerb.LastShotTick); try { diff --git a/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs b/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs new file mode 100644 index 0000000000..07461ed357 --- /dev/null +++ b/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace CombatExtended +{ + public class RecoilAdjustExtension : DefModExtension + { + public float recoilModifier = 1; + public int recoilTick = -1; + } +} From cabfec4dfce4b5988de25a587ddf8d4bf195b881 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sat, 9 Sep 2023 22:42:29 +0100 Subject: [PATCH 06/15] fixed wrong relation with RoF --- Source/CombatExtended/CombatExtended/CE_Utility.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 0116354ea7..ed7369860d 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -752,14 +752,14 @@ public static Thing GetWeaponFromLauncher(Thing launcher) new CurvePoint(2f, 4f) }; - const float RecoilMagicNumber = 20; + const float RecoilMagicNumber = 2; public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle) { drawOffset = Vector3.zero; angleOffset = 0f; float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount; - recoil = Math.Min(recoil * recoil, 20) * Mathf.Clamp(RecoilMagicNumber / weaponDef.verbs[0].ticksBetweenBurstShots, 1, RecoilMagicNumber); + recoil = Math.Min(recoil * recoil, 20) * RecoilMagicNumber * Mathf.Clamp(weaponDef.verbs[0].ticksBetweenBurstShots, 1, 10); float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; RecoilAdjustExtension RecoilAdjustExtension = weaponDef.GetModExtension(); @@ -769,7 +769,8 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf recoilRelaxation = RecoilAdjustExtension.recoilTick > 0 ? RecoilAdjustExtension.recoilTick : recoilRelaxation; } - if (recoil <= 0f || shootVerb == null) + //Prevents recoil for something with absurd ROF, it's too fast for any meaningful recoil animation + if (recoil <= 0f || shootVerb == null || recoilRelaxation < 2) { return; } From 6e11f3a333f7b2724247ff430e25fc33d7f6fe5f Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sun, 10 Sep 2023 07:47:35 +0100 Subject: [PATCH 07/15] more fiddle --- Source/CombatExtended/CombatExtended/CE_Utility.cs | 7 ++++--- .../CombatExtended/Defs/RecoilAdjustExtension.cs | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index ed7369860d..adf53a46da 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -752,14 +752,14 @@ public static Thing GetWeaponFromLauncher(Thing launcher) new CurvePoint(2f, 4f) }; - const float RecoilMagicNumber = 2; + const float RecoilMagicNumber = 2.6f; public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle) { drawOffset = Vector3.zero; angleOffset = 0f; float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount; - recoil = Math.Min(recoil * recoil, 20) * RecoilMagicNumber * Mathf.Clamp(weaponDef.verbs[0].ticksBetweenBurstShots, 1, 10); + recoil = Math.Min(recoil * recoil, 20) * RecoilMagicNumber * Mathf.Clamp((float)Math.Log10(weaponDef.verbs[0].ticksBetweenBurstShots), 0.1f, 10); float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; RecoilAdjustExtension RecoilAdjustExtension = weaponDef.GetModExtension(); @@ -767,6 +767,7 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf { recoil *= RecoilAdjustExtension.recoilModifier; recoilRelaxation = RecoilAdjustExtension.recoilTick > 0 ? RecoilAdjustExtension.recoilTick : recoilRelaxation; + recoil = RecoilAdjustExtension.recoilScale > 0 ? RecoilAdjustExtension.recoilScale : recoil; } //Prevents recoil for something with absurd ROF, it's too fast for any meaningful recoil animation @@ -788,7 +789,7 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf drawOffset = drawOffset.RotatedBy(aimAngle); aimAngle += angleOffset; - Log.Message(recoil.ToString() + " " + recoilRelaxation.ToString()); + Log.Message(recoil.ToString() + " " + Mathf.Clamp((float)Math.Log10(weaponDef.verbs[0].ticksBetweenBurstShots), 0.1f, 10).ToString()); } } finally diff --git a/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs b/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs index 07461ed357..7b87c73a86 100644 --- a/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs +++ b/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs @@ -10,6 +10,7 @@ namespace CombatExtended public class RecoilAdjustExtension : DefModExtension { public float recoilModifier = 1; + public float recoilScale = -1; public int recoilTick = -1; } } From 6fabd7c93ff7389153b2857dc5688886d865541b Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sun, 10 Sep 2023 19:40:49 +0100 Subject: [PATCH 08/15] handheld weapon recoil the harmony transpiler is in a mess. probably need someone better at coding to clean it up --- .../CombatExtended/CE_Utility.cs | 29 ++++++----- .../CombatExtended/Defs/GunDrawExtension.cs | 5 ++ .../Defs/RecoilAdjustExtension.cs | 16 ------ .../Things/Building_TurretGunCE.cs | 2 +- .../Harmony/Harmony_PawnRenderer.cs | 51 ++++++++++++++++++- 5 files changed, 72 insertions(+), 31 deletions(-) delete mode 100644 Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index adf53a46da..fda4ca90c6 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -754,22 +754,18 @@ public static Thing GetWeaponFromLauncher(Thing launcher) const float RecoilMagicNumber = 2.6f; - public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle) + public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle, bool handheld) { drawOffset = Vector3.zero; angleOffset = 0f; float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount; recoil = Math.Min(recoil * recoil, 20) * RecoilMagicNumber * Mathf.Clamp((float)Math.Log10(weaponDef.verbs[0].ticksBetweenBurstShots), 0.1f, 10); - float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; - RecoilAdjustExtension RecoilAdjustExtension = weaponDef.GetModExtension(); - - if (RecoilAdjustExtension != null) + if (recoil > 5 && handheld) { - recoil *= RecoilAdjustExtension.recoilModifier; - recoilRelaxation = RecoilAdjustExtension.recoilTick > 0 ? RecoilAdjustExtension.recoilTick : recoilRelaxation; - recoil = RecoilAdjustExtension.recoilScale > 0 ? RecoilAdjustExtension.recoilScale : recoil; + recoil = 5; } + float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; //Prevents recoil for something with absurd ROF, it's too fast for any meaningful recoil animation if (recoil <= 0f || shootVerb == null || recoilRelaxation < 2) { @@ -779,17 +775,24 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf Rand.PushState(shootVerb.LastShotTick); try { + float muzzleJumpModifier = 1; + GunDrawExtension recoilAdjustExtension = weaponDef.GetModExtension(); + if (recoilAdjustExtension != null) + { + recoil *= recoilAdjustExtension.recoilModifier; + recoilRelaxation = recoilAdjustExtension.recoilTick > 0 ? recoilAdjustExtension.recoilTick : recoilRelaxation; + recoil = recoilAdjustExtension.recoilScale > 0 ? recoilAdjustExtension.recoilScale : recoil; + muzzleJumpModifier = recoilAdjustExtension.muzzleJumpModifier > 0 ? recoilAdjustExtension.muzzleJumpModifier : 1; + } int num = Find.TickManager.TicksGame - shootVerb.LastShotTick; - if ((float)num < recoilRelaxation) + if (num < recoilRelaxation) { - float num2 = Mathf.Clamp01((float)num / recoilRelaxation); + float num2 = Mathf.Clamp01(num / recoilRelaxation); float num3 = Mathf.Lerp(recoil, 0f, num2); drawOffset = new Vector3(0f, 0f, 0f - RecoilCurveAxisY.Evaluate(num2)) * num3; - angleOffset = (float)Rand.Sign * RecoilCurveRotation.Evaluate(num2) * num3; + angleOffset = (handheld ? -1 : Rand.Sign) * RecoilCurveRotation.Evaluate(num2) * num3 * recoil * 0.6f * muzzleJumpModifier; drawOffset = drawOffset.RotatedBy(aimAngle); aimAngle += angleOffset; - - Log.Message(recoil.ToString() + " " + Mathf.Clamp((float)Math.Log10(weaponDef.verbs[0].ticksBetweenBurstShots), 0.1f, 10).ToString()); } } finally diff --git a/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs b/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs index ccb65a230f..026fe93f70 100644 --- a/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs +++ b/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs @@ -7,5 +7,10 @@ public class GunDrawExtension : DefModExtension { public Vector2 DrawSize = Vector2.one; public Vector2 DrawOffset = Vector2.zero; + + public float recoilModifier = 1; + public float recoilScale = -1; + public int recoilTick = -1; + public float muzzleJumpModifier = -1; } } diff --git a/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs b/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs deleted file mode 100644 index 7b87c73a86..0000000000 --- a/Source/CombatExtended/CombatExtended/Defs/RecoilAdjustExtension.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Verse; - -namespace CombatExtended -{ - public class RecoilAdjustExtension : DefModExtension - { - public float recoilModifier = 1; - public float recoilScale = -1; - public int recoilTick = -1; - } -} diff --git a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs index bd0ca7af6f..e6c110a32e 100644 --- a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs +++ b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs @@ -576,7 +576,7 @@ public override void Draw() { Vector3 drawOffset = Vector3.zero; float angleOffset = 0f; - CE_Utility.Recoil(def.building.turretGunDef, AttackVerb, out drawOffset, out angleOffset, top.CurRotation); + CE_Utility.Recoil(def.building.turretGunDef, AttackVerb, out drawOffset, out angleOffset, top.CurRotation, false); top.DrawTurret(drawOffset, angleOffset); base.Draw(); } diff --git a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs index 463d2a2216..f434daa3e1 100644 --- a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs +++ b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; @@ -413,8 +414,27 @@ public static void Prefix(PawnRenderer __instance, Thing eq) equipment = eq; } + private static void RecoilCE(Thing eq, Vector3 position, float aimAngle, float num, CompEquippable compEquippable) + { + if (compEquippable.PrimaryVerb.verbProps is VerbPropertiesCE) + { + //CE_Utility.Recoil(eq.def, compEquippable.PrimaryVerb, out var drawOffset, out var angleOffset, aimAngle); + //drawLoc += drawOffset; + //num += angleOffset; + } + } + private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int layer, Thing eq, Vector3 position, float aimAngle) { + CompEquippable compEquippable = eq.TryGetComp(); + Vector3 recoilOffset = new Vector3(); + float muzzleJump = 0; + if (compEquippable.PrimaryVerb.verbProps is VerbPropertiesCE) + { + CE_Utility.Recoil(eq.def, compEquippable.PrimaryVerb, out var drawOffset, out var angleOffset, aimAngle, true); + recoilOffset = drawOffset; + muzzleJump = angleOffset; + } GunDrawExtension drawData = eq.def.GetModExtension() ?? new GunDrawExtension() { DrawSize = eq.def.graphicData.drawSize }; if (drawData.DrawSize == Vector2.one) { drawData.DrawSize = eq.def.graphicData.drawSize; } Vector3 scale = new Vector3(drawData.DrawSize.x, 1, drawData.DrawSize.y); @@ -422,8 +442,9 @@ private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int laye if (aimAngle > 200 && aimAngle < 340) { posVec.x *= -1; + muzzleJump = -muzzleJump; } - matrix.SetTRS(position + posVec.RotatedBy(matrix.rotation.eulerAngles.y), matrix.rotation, scale); + matrix.SetTRS(position + posVec.RotatedBy(matrix.rotation.eulerAngles.y) + recoilOffset, Quaternion.AngleAxis(matrix.rotation.eulerAngles.y + muzzleJump, Vector3.up), scale); if (eq is WeaponPlatform platform) { platform.DrawPlatform(matrix, mesh == MeshPool.plane10Flip, layer); @@ -434,12 +455,40 @@ private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int laye } } + /* * This replace the last DrawMesh in */ internal static IEnumerable Transpiler(IEnumerable instructions) { var codes = instructions.ToList(); + /* + var recoil_opcodes = new CodeInstruction[] + { + new CodeInstruction(OpCodes.Ldarg_1), + new CodeInstruction(OpCodes.Ldarg_2), + new CodeInstruction(OpCodes.Ldarg_3), + new CodeInstruction(OpCodes.Ldloc_1), + new CodeInstruction(OpCodes.Ldloc_2), + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Harmony_PawnRenderer_DrawEquipmentAiming), nameof(RecoilCE))) + }; + bool foundRecoil = false; + int index = 0; + for (int i = 0; i < codes.Count; i++) + { + CodeInstruction code = codes[i]; + if (foundRecoil && code.opcode == OpCodes.Stloc_1) + { + index = i + 1; + break; + } + else if (code.opcode == OpCodes.Call && ReferenceEquals(code.operand, typeof(EquipmentUtility).GetMethod("Recoil"))) + { + foundRecoil = true; + } + } + codes.InsertRange(index, recoil_opcodes); + */ codes[codes.Count - 2].operand = AccessTools.Method(typeof(Harmony_PawnRenderer_DrawEquipmentAiming), nameof(DrawMesh)); codes.InsertRange(codes.Count - 2, new[] From 374483c09a3da527735d0693ef1fffea607e1326 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sun, 10 Sep 2023 21:39:11 +0100 Subject: [PATCH 09/15] upgrade? tidied up code make single hand weapon behave differently muzzle rise no longer affected by recoil modifier semi-auto weapons are affected by RoF based recoil reduction too, fixing chain shotgun included mod setting to turn this off --- .../CombatExtended/CE_Utility.cs | 36 ++++++++++++++----- .../CombatExtended/CombatExtended/Settings.cs | 5 +++ .../Things/Building_TurretGunCE.cs | 5 ++- .../Harmony/Harmony_PawnRenderer.cs | 23 +++++------- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index fda4ca90c6..420e29f9cc 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -753,19 +753,18 @@ public static Thing GetWeaponFromLauncher(Thing launcher) }; const float RecoilMagicNumber = 2.6f; + const float MuzzleRiseMagicNumber = 0.04f; public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle, bool handheld) { drawOffset = Vector3.zero; angleOffset = 0f; float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount; - recoil = Math.Min(recoil * recoil, 20) * RecoilMagicNumber * Mathf.Clamp((float)Math.Log10(weaponDef.verbs[0].ticksBetweenBurstShots), 0.1f, 10); - if (recoil > 5 && handheld) - { - recoil = 5; - } float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; + + recoil = Math.Min(recoil * recoil, 20) * RecoilMagicNumber * Mathf.Clamp((float)Math.Log10(recoilRelaxation), 0.1f, 10); + //Prevents recoil for something with absurd ROF, it's too fast for any meaningful recoil animation if (recoil <= 0f || shootVerb == null || recoilRelaxation < 2) { @@ -775,24 +774,45 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf Rand.PushState(shootVerb.LastShotTick); try { - float muzzleJumpModifier = 1; + float muzzleJumpModifier = recoil; GunDrawExtension recoilAdjustExtension = weaponDef.GetModExtension(); if (recoilAdjustExtension != null) { recoil *= recoilAdjustExtension.recoilModifier; recoilRelaxation = recoilAdjustExtension.recoilTick > 0 ? recoilAdjustExtension.recoilTick : recoilRelaxation; recoil = recoilAdjustExtension.recoilScale > 0 ? recoilAdjustExtension.recoilScale : recoil; - muzzleJumpModifier = recoilAdjustExtension.muzzleJumpModifier > 0 ? recoilAdjustExtension.muzzleJumpModifier : 1; + muzzleJumpModifier *= recoilAdjustExtension.muzzleJumpModifier > 0 ? recoilAdjustExtension.muzzleJumpModifier : 1; } + + + if (handheld) + { + if (weaponDef.weaponTags.Contains("CE_OneHandedWeapon")) + { + recoil /= 3; + muzzleJumpModifier *= 1.5f; + } + else + { + recoil /= 1.3f; + muzzleJumpModifier /= 1.5f; + } + if (recoil > 15) + { + recoil = 15; + } + } + int num = Find.TickManager.TicksGame - shootVerb.LastShotTick; if (num < recoilRelaxation) { float num2 = Mathf.Clamp01(num / recoilRelaxation); float num3 = Mathf.Lerp(recoil, 0f, num2); drawOffset = new Vector3(0f, 0f, 0f - RecoilCurveAxisY.Evaluate(num2)) * num3; - angleOffset = (handheld ? -1 : Rand.Sign) * RecoilCurveRotation.Evaluate(num2) * num3 * recoil * 0.6f * muzzleJumpModifier; + angleOffset = (handheld ? -1 : Rand.Sign) * RecoilCurveRotation.Evaluate(num2) * num3 * MuzzleRiseMagicNumber * muzzleJumpModifier; drawOffset = drawOffset.RotatedBy(aimAngle); aimAngle += angleOffset; + Log.Message(recoil.ToString()); } } finally diff --git a/Source/CombatExtended/CombatExtended/Settings.cs b/Source/CombatExtended/CombatExtended/Settings.cs index 33c0f1d18c..52f838ef68 100644 --- a/Source/CombatExtended/CombatExtended/Settings.cs +++ b/Source/CombatExtended/CombatExtended/Settings.cs @@ -19,6 +19,7 @@ public class Settings : ModSettings, ISettingsCE private bool autosetup = true; private bool showCasings = true; private bool createCasingsFilth = true; + private bool recoilAnim = true; private bool showTaunts = true; private bool allowMeleeHunting = false; private bool smokeEffects = true; @@ -128,6 +129,8 @@ public class Settings : ModSettings, ISettingsCE public bool CreateCasingsFilth => createCasingsFilth; + public bool RecoilAnim => recoilAnim; + #endregion private bool lastAmmoSystemStatus; @@ -139,6 +142,7 @@ public override void ExposeData() base.ExposeData(); Scribe_Values.Look(ref showCasings, "showCasings", true); Scribe_Values.Look(ref createCasingsFilth, "createCasingsFilth", true); + Scribe_Values.Look(ref recoilAnim, "recoilAnim", true); Scribe_Values.Look(ref showTaunts, "showTaunts", true); Scribe_Values.Look(ref allowMeleeHunting, "allowMeleeHunting", false); Scribe_Values.Look(ref smokeEffects, "smokeEffects", true); @@ -210,6 +214,7 @@ public void DoWindowContents(Rect canvas, ref int offset) list.CheckboxLabeled("CE_Settings_PartialStats_Title".Translate(), ref partialstats, "CE_Settings_PartialStats_Desc".Translate()); list.CheckboxLabeled("CE_Settings_ShowCasings_Title".Translate(), ref showCasings, "CE_Settings_ShowCasings_Desc".Translate()); list.CheckboxLabeled("CE_Settings_СreateCasingsFilth_Title".Translate(), ref createCasingsFilth, "CE_Settings_СreateCasingsFilth_Desc".Translate()); + list.CheckboxLabeled("CE_Settings_RecoilAnim_Title".Translate(), ref recoilAnim, "CE_Settings_RecoilAnim_Desc".Translate()); list.CheckboxLabeled("CE_Settings_ShowTaunts_Title".Translate(), ref showTaunts, "CE_Settings_ShowTaunts_Desc".Translate()); list.CheckboxLabeled("CE_Settings_AllowMeleeHunting_Title".Translate(), ref allowMeleeHunting, "CE_Settings_AllowMeleeHunting_Desc".Translate()); list.CheckboxLabeled("CE_Settings_SmokeEffects_Title".Translate(), ref smokeEffects, "CE_Settings_SmokeEffects_Desc".Translate()); diff --git a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs index e6c110a32e..f63514568a 100644 --- a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs +++ b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs @@ -576,7 +576,10 @@ public override void Draw() { Vector3 drawOffset = Vector3.zero; float angleOffset = 0f; - CE_Utility.Recoil(def.building.turretGunDef, AttackVerb, out drawOffset, out angleOffset, top.CurRotation, false); + if (Controller.settings.RecoilAnim) + { + CE_Utility.Recoil(def.building.turretGunDef, AttackVerb, out drawOffset, out angleOffset, top.CurRotation, false); + } top.DrawTurret(drawOffset, angleOffset); base.Draw(); } diff --git a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs index f434daa3e1..e548680486 100644 --- a/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs +++ b/Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs @@ -404,6 +404,10 @@ internal static class Harmony_PawnRenderer_DrawEquipmentAiming private static Pawn pawn; + private static Vector3 recoilOffset = new Vector3(); + + private static float muzzleJump = 0; + private static readonly Matrix4x4 TBot5 = Matrix4x4.Translate(new Vector3(0, -0.006f, 0)); private static readonly Matrix4x4 TBot3 = Matrix4x4.Translate(new Vector3(0, -0.004f, 0)); @@ -416,25 +420,16 @@ public static void Prefix(PawnRenderer __instance, Thing eq) private static void RecoilCE(Thing eq, Vector3 position, float aimAngle, float num, CompEquippable compEquippable) { - if (compEquippable.PrimaryVerb.verbProps is VerbPropertiesCE) + if (Controller.settings.RecoilAnim && compEquippable.PrimaryVerb.verbProps is VerbPropertiesCE) { - //CE_Utility.Recoil(eq.def, compEquippable.PrimaryVerb, out var drawOffset, out var angleOffset, aimAngle); - //drawLoc += drawOffset; - //num += angleOffset; + CE_Utility.Recoil(eq.def, compEquippable.PrimaryVerb, out var drawOffset, out var angleOffset, aimAngle, true); + recoilOffset = drawOffset; + muzzleJump = angleOffset; } } private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int layer, Thing eq, Vector3 position, float aimAngle) { - CompEquippable compEquippable = eq.TryGetComp(); - Vector3 recoilOffset = new Vector3(); - float muzzleJump = 0; - if (compEquippable.PrimaryVerb.verbProps is VerbPropertiesCE) - { - CE_Utility.Recoil(eq.def, compEquippable.PrimaryVerb, out var drawOffset, out var angleOffset, aimAngle, true); - recoilOffset = drawOffset; - muzzleJump = angleOffset; - } GunDrawExtension drawData = eq.def.GetModExtension() ?? new GunDrawExtension() { DrawSize = eq.def.graphicData.drawSize }; if (drawData.DrawSize == Vector2.one) { drawData.DrawSize = eq.def.graphicData.drawSize; } Vector3 scale = new Vector3(drawData.DrawSize.x, 1, drawData.DrawSize.y); @@ -462,7 +457,6 @@ private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int laye internal static IEnumerable Transpiler(IEnumerable instructions) { var codes = instructions.ToList(); - /* var recoil_opcodes = new CodeInstruction[] { new CodeInstruction(OpCodes.Ldarg_1), @@ -488,7 +482,6 @@ internal static IEnumerable Transpiler(IEnumerable Date: Sun, 10 Sep 2023 21:59:02 +0100 Subject: [PATCH 10/15] Update CE_Utility.cs slightly increased muzzle rise for low recoil guns and reduce it on high recoil ones, for visual effect --- Source/CombatExtended/CombatExtended/CE_Utility.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 420e29f9cc..734b2dddb1 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -753,7 +753,7 @@ public static Thing GetWeaponFromLauncher(Thing launcher) }; const float RecoilMagicNumber = 2.6f; - const float MuzzleRiseMagicNumber = 0.04f; + const float MuzzleRiseMagicNumber = 0.1f; public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOffset, out float angleOffset, float aimAngle, bool handheld) { @@ -774,7 +774,7 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf Rand.PushState(shootVerb.LastShotTick); try { - float muzzleJumpModifier = recoil; + float muzzleJumpModifier = 10 * (float)Math.Log10(recoil) + 3; GunDrawExtension recoilAdjustExtension = weaponDef.GetModExtension(); if (recoilAdjustExtension != null) { @@ -795,7 +795,6 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf else { recoil /= 1.3f; - muzzleJumpModifier /= 1.5f; } if (recoil > 15) { @@ -812,7 +811,6 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf angleOffset = (handheld ? -1 : Rand.Sign) * RecoilCurveRotation.Evaluate(num2) * num3 * MuzzleRiseMagicNumber * muzzleJumpModifier; drawOffset = drawOffset.RotatedBy(aimAngle); aimAngle += angleOffset; - Log.Message(recoil.ToString()); } } finally From 7167e2a4c16e3eac4f04e3460effa0ce3de0f8f0 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sun, 10 Sep 2023 22:12:59 +0100 Subject: [PATCH 11/15] fixed breaking when holding melee weapon --- Source/CombatExtended/CombatExtended/CE_Utility.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 734b2dddb1..592d94ed4c 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -759,6 +759,10 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf { drawOffset = Vector3.zero; angleOffset = 0f; + if (shootVerb == null || shootVerb.IsMeleeAttack) + { + return; + } float recoil = ((VerbPropertiesCE)weaponDef.verbs[0]).recoilAmount; float recoilRelaxation = weaponDef.verbs[0].burstShotCount > 1 ? weaponDef.verbs[0].ticksBetweenBurstShots : weaponDef.GetStatValueDef(StatDefOf.RangedWeapon_Cooldown) * 20f; @@ -766,7 +770,7 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf recoil = Math.Min(recoil * recoil, 20) * RecoilMagicNumber * Mathf.Clamp((float)Math.Log10(recoilRelaxation), 0.1f, 10); //Prevents recoil for something with absurd ROF, it's too fast for any meaningful recoil animation - if (recoil <= 0f || shootVerb == null || recoilRelaxation < 2) + if (recoilRelaxation < 2) { return; } @@ -782,6 +786,7 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf recoilRelaxation = recoilAdjustExtension.recoilTick > 0 ? recoilAdjustExtension.recoilTick : recoilRelaxation; recoil = recoilAdjustExtension.recoilScale > 0 ? recoilAdjustExtension.recoilScale : recoil; muzzleJumpModifier *= recoilAdjustExtension.muzzleJumpModifier > 0 ? recoilAdjustExtension.muzzleJumpModifier : 1; + if (recoil <= 0) { return; } } From 9f6905c886b7d81496fe0d1fd4e6f81a0c36b14a Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Sun, 10 Sep 2023 22:17:16 +0100 Subject: [PATCH 12/15] fix turret without recoil --- Source/CombatExtended/CombatExtended/CE_Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 592d94ed4c..00aca19d41 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -786,9 +786,9 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf recoilRelaxation = recoilAdjustExtension.recoilTick > 0 ? recoilAdjustExtension.recoilTick : recoilRelaxation; recoil = recoilAdjustExtension.recoilScale > 0 ? recoilAdjustExtension.recoilScale : recoil; muzzleJumpModifier *= recoilAdjustExtension.muzzleJumpModifier > 0 ? recoilAdjustExtension.muzzleJumpModifier : 1; - if (recoil <= 0) { return; } } + if (recoil <= 0) { return; } if (handheld) { From 1eaf226e4a6fca14987b9864ca1c56e13ad408eb Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Tue, 12 Sep 2023 18:04:33 +0100 Subject: [PATCH 13/15] recoil animation for trycastshotglobal --- Source/CombatExtended/CombatExtended/Verbs/Verb_ShootMortarCE.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootMortarCE.cs b/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootMortarCE.cs index 134917c780..2f548cd217 100644 --- a/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootMortarCE.cs +++ b/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootMortarCE.cs @@ -215,6 +215,7 @@ public virtual bool TryCastGlobalShot() CompReloadable.UsedOnce(); } } + lastShotTick = Find.TickManager.TicksGame; return true; } From ee60e3bd75130a3d836bb729d41dd0c758d8f212 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Tue, 12 Sep 2023 20:04:26 +0100 Subject: [PATCH 14/15] Update WorldObjectDamageWorker.cs --- .../CombatExtended/WorldObjects/WorldObjectDamageWorker.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs b/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs index d4370b5e48..fdfd57740c 100644 --- a/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs +++ b/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs @@ -37,12 +37,12 @@ public virtual float CalculateDamage(ThingDef projectile, Faction faction) var result = FragmentsPotentialDamage(projectile) + ExplosionPotentialDamage(projectile) + FirePotentialDamage(projectile) + EMPPotentialDamage(projectile, empModifier); //Damage calculated as in-map damage, needs to be converted into world object damage. 3500f experimentally obtained result /= 3500f; - //Crit/Miss imitation - result *= Rand.Range(0.4f, 1.5f); if (projectile.projectile is ProjectilePropertiesCE projectileProperties && projectileProperties.shellingProps.damage > 0f) { - result *= projectileProperties.shellingProps.damage; + result = projectileProperties.shellingProps.damage; } + //Crit/Miss imitation + result *= Rand.Range(0.4f, 1.5f); return result; } protected const float fragDamageMultipler = 0.04f; From 71f53812edbb61c886de23495ac56b0947af91b5 Mon Sep 17 00:00:00 2001 From: CMDR-Bill-Doors Date: Tue, 12 Sep 2023 20:04:41 +0100 Subject: [PATCH 15/15] Revert "Update WorldObjectDamageWorker.cs" This reverts commit ee60e3bd75130a3d836bb729d41dd0c758d8f212. --- .../CombatExtended/WorldObjects/WorldObjectDamageWorker.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs b/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs index fdfd57740c..d4370b5e48 100644 --- a/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs +++ b/Source/CombatExtended/CombatExtended/WorldObjects/WorldObjectDamageWorker.cs @@ -37,12 +37,12 @@ public virtual float CalculateDamage(ThingDef projectile, Faction faction) var result = FragmentsPotentialDamage(projectile) + ExplosionPotentialDamage(projectile) + FirePotentialDamage(projectile) + EMPPotentialDamage(projectile, empModifier); //Damage calculated as in-map damage, needs to be converted into world object damage. 3500f experimentally obtained result /= 3500f; + //Crit/Miss imitation + result *= Rand.Range(0.4f, 1.5f); if (projectile.projectile is ProjectilePropertiesCE projectileProperties && projectileProperties.shellingProps.damage > 0f) { - result = projectileProperties.shellingProps.damage; + result *= projectileProperties.shellingProps.damage; } - //Crit/Miss imitation - result *= Rand.Range(0.4f, 1.5f); return result; } protected const float fragDamageMultipler = 0.04f;