diff --git a/Patches/Core/ThingDefs_Misc/Weapons_Guns.xml b/Patches/Core/ThingDefs_Misc/Weapons_Guns.xml index 88d2e4c0d5..ab421429e9 100644 --- a/Patches/Core/ThingDefs_Misc/Weapons_Guns.xml +++ b/Patches/Core/ThingDefs_Misc/Weapons_Guns.xml @@ -2,14 +2,14 @@ - Defs/ThingDef[defName="Gun_ChargeLance"] + Defs/ThingDef[defName="Gun_ChargeLance"] 0 - Defs/ThingDef[@Name="BaseWeaponTurret"] + Defs/ThingDef[@Name="BaseWeaponTurret"] 0 @@ -18,30 +18,30 @@ - Defs/ThingDef[defName="Gun_Revolver" or defName="Gun_Autopistol" or defName="Gun_MachinePistol"]/tools + Defs/ThingDef[defName="Gun_Revolver" or defName="Gun_Autopistol" or defName="Gun_MachinePistol"]/tools -
  • - - -
  • Blunt
  • - - 2 - 1.54 - 1.5 - 0.555 - Grip - -
  • - - -
  • Poke
  • - - 2 - 1.54 - 0.555 - Muzzle - +
  • + + +
  • Blunt
  • + + 2 + 1.54 + 1.5 + 0.555 + Grip + +
  • + + +
  • Poke
  • + + 2 + 1.54 + 0.555 + Muzzle +
    @@ -62,55 +62,55 @@ -
  • - - -
  • Blunt
  • - - 8 - 1.55 - 1.5 - 2.755 - Stock - -
  • - - -
  • Blunt
  • - - 5 - 2.02 - 1.630 - Barrel - -
  • - - -
  • Poke
  • - - 8 - 1.55 - 2.755 - Muzzle - +
  • + + +
  • Blunt
  • + + 8 + 1.55 + 1.5 + 2.755 + Stock + +
  • + + +
  • Blunt
  • + + 5 + 2.02 + 1.630 + Barrel + +
  • + + +
  • Poke
  • + + 8 + 1.55 + 2.755 + Muzzle +
    - Defs/ThingDef[defName="Gun_TripleRocket" or defName="Gun_DoomsdayRocket"]/tools + Defs/ThingDef[defName="Gun_TripleRocket" or defName="Gun_DoomsdayRocket"]/tools -
  • - - -
  • Blunt
  • - - 10 - 2.44 - 3.5 - Barrel - +
  • + + +
  • Blunt
  • + + 10 + 2.44 + 3.5 + Barrel +
    @@ -126,7 +126,8 @@ 0.18 1.27 2.41 - + + 7000 @@ -165,8 +166,8 @@ Defs/ThingDef[defName="Gun_Revolver"]
  • - 1.00,1.00 - 0.0,0.0 + 1.00,1.00 + 0.0,0.0
  • @@ -214,14 +215,14 @@
  • CE_OneHandedWeapon
  • BlowbackOperation - + - + Defs/ThingDef[defName="Gun_Autopistol"]
  • - 0.93,0.93 - 0.0,0.0 + 0.93,0.93 + 0.0,0.0
  • @@ -275,8 +276,8 @@ Defs/ThingDef[defName="Gun_PumpShotgun"]
  • - 1.03,1.25 - 0.05,0.0 + 1.03,1.25 + 0.05,0.0
  • @@ -336,10 +337,10 @@ Defs/ThingDef[defName="Gun_ChainShotgun"]
  • - 1.04,1.23 - 0.05,-0.05 - 0,0.2 - -30 + 1.04,1.23 + 0.05,-0.05 + 0,0.2 + -30
  • @@ -387,15 +388,15 @@ Gunsmithing false - + Defs/ThingDef[defName="Gun_BoltActionRifle"]
  • - 1.3,1.3 - 0.12,0.04 - -0.1,0.1 + 1.3,1.3 + 0.12,0.04 + -0.1,0.1
  • @@ -451,9 +452,9 @@ Defs/ThingDef[defName="Gun_AssaultRifle"]
  • - 1.16,1.16 - 0.08,0.0 - -0.05,0 + 1.16,1.16 + 0.08,0.0 + -0.05,0
  • @@ -507,9 +508,9 @@ Defs/ThingDef[defName="Gun_SniperRifle"]
  • - 1.25,1.45 - 0.15,-0.05 - -0.3,0.1 + 1.25,1.45 + 0.15,-0.05 + -0.3,0.1
  • @@ -566,10 +567,10 @@ Defs/ThingDef[defName="Gun_MachinePistol"]
  • - 0.84,0.84 - -0.10,-0.07 - 0.1,0.1 - -30 + 0.84,0.84 + -0.10,-0.07 + 0.1,0.1 + -30
  • @@ -626,9 +627,9 @@ Defs/ThingDef[defName="Gun_HeavySMG"]
  • - 0.85,0.85 - 0.00,-0.03 - 0.1,0 + 0.85,0.85 + 0.00,-0.03 + 0.1,0
  • @@ -664,7 +665,7 @@ GunTail_Medium 9 - true + true @@ -696,8 +697,8 @@ Defs/ThingDef[defName="Gun_IncendiaryLauncher"]
  • - 1.16,1.16 - 0.1,-0.05 + 1.16,1.16 + 0.1,-0.05
  • @@ -733,7 +734,7 @@ GunTail_Medium 9 - true + true Mounted @@ -760,8 +761,8 @@ Defs/ThingDef[defName="Gun_LMG"]
  • - 1.35,1.18 - 0.13,-0.03 + 1.35,1.18 + 0.13,-0.03
  • @@ -820,8 +821,8 @@ Defs/ThingDef[defName="Gun_ChargeRifle"]
  • - 1.03,1.03 - 0.05,0.0 + 1.03,1.03 + 0.05,0.0
  • @@ -915,16 +916,16 @@ Defs/ThingDef[defName="Gun_Minigun"]/tools -
  • - - -
  • Blunt
  • - - 10 - 2.44 - 3.5 - Barrels - +
  • + + +
  • Blunt
  • + + 10 + 2.44 + 3.5 + Barrels +
    @@ -939,7 +940,7 @@
  • 1.00,1.00 0.1,-0.15 - -0.2,0 + -0.2,-0.1 -30
  • @@ -976,12 +977,12 @@ Defs/ThingDef[defName="Bullet_DoomsdayRocket"]/projectile - Bomb - 250 - 7.8 - 3.0 - 2.0 - 100 + Bomb + 250 + 7.8 + 3.0 + 2.0 + 100 @@ -991,7 +992,7 @@ Defs/ThingDef[defName="Bullet_DoomsdayRocket"] - + @@ -1000,10 +1001,10 @@ Defs/ThingDef[defName="Bullet_DoomsdayRocket"]/comps
  • - 1 - - 400 - + 1 + + 400 +
  • @@ -1037,7 +1038,7 @@ GunTail_Heavy true - true + true 14 @@ -1055,8 +1056,8 @@ Defs/ThingDef[defName="Gun_DoomsdayRocket"]
  • - 1.45,1.45 - -0.15,0 + 1.45,1.45 + -0.15,0
  • @@ -1076,12 +1077,12 @@ Defs/ThingDef[defName="Bullet_Rocket"]/projectile - Bomb - 180 - 3.0 - 3.0 - 2.0 - 100 + Bomb + 180 + 3.0 + 3.0 + 2.0 + 100 @@ -1091,7 +1092,7 @@ Defs/ThingDef[defName="Bullet_Rocket"] - + @@ -1100,10 +1101,10 @@ Defs/ThingDef[defName="Bullet_Rocket"]/comps
  • - 1 - - 150 - + 1 + + 150 +
  • @@ -1140,7 +1141,7 @@ false false - true + true 14 @@ -1159,8 +1160,8 @@ Defs/ThingDef[defName="Gun_TripleRocket"]
  • - 1.16,1.16 - -0.25,0 + 1.16,1.16 + -0.25,0
  • @@ -1209,16 +1210,16 @@ Defs/ThingDef[@Name="Gun_ChargeBlasterHeavyBase"]/tools -
  • - - -
  • Blunt
  • - - 10 - 2.44 - 3.5 - Barrel - +
  • + + +
  • Blunt
  • + + 10 + 2.44 + 3.5 + Barrel +
    @@ -1269,16 +1270,16 @@ Defs/ThingDef[@Name="Gun_InfernoCannonBase"]/tools -
  • - - -
  • Blunt
  • - - 10 - 2.44 - 3.5 - Barrel - +
  • + + +
  • Blunt
  • + + 10 + 2.44 + 3.5 + Barrel +
    @@ -1329,16 +1330,16 @@ Defs/ThingDef[defName="Gun_ThumpCannon"]/tools -
  • - - -
  • Blunt
  • - - 10 - 2.44 - 3.5 - Barrel - +
  • + + +
  • Blunt
  • + + 10 + 2.44 + 3.5 + Barrel +
    @@ -1383,16 +1384,16 @@ Defs/ThingDef[defName="Gun_ChargeLance"]/tools -
  • - - -
  • Blunt
  • - - 10 - 2.44 - 3.5 - Barrel - +
  • + + +
  • Blunt
  • + + 10 + 2.44 + 3.5 + Barrel +
    @@ -1401,7 +1402,7 @@ Defs/ThingDef[defName="Gun_ChargeLance"]
  • - True + True
  • @@ -1480,16 +1481,16 @@ Defs/ThingDef[defName="Gun_Needle"]/tools -
  • - - -
  • Blunt
  • - - 10 - 2.44 - 3.5 - Barrel - +
  • + + +
  • Blunt
  • + + 10 + 2.44 + 3.5 + Barrel +
    diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 2edb471272..2c319e90b7 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -845,13 +845,13 @@ public static void Recoil(ThingDef weaponDef, Verb shootVerb, out Vector3 drawOf #endregion Misc #region MoteThrower - public static void GenerateAmmoCasings(ProjectilePropertiesCE projProps, Vector3 drawPosition, Map map, float shotRotation = -180f, float recoilAmount = 2f, bool fromPawn = false, float casingAngleOffset = 0) + public static void GenerateAmmoCasings(ProjectilePropertiesCE projProps, Vector3 drawPosition, Map map, float shotRotation = -180f, float recoilAmount = 2f, bool fromPawn = false, GunDrawExtension extension = null) { if (projProps.dropsCasings) { if (Controller.settings.ShowCasings) { - ThrowEmptyCasing(drawPosition, map, DefDatabase.GetNamed(projProps.casingMoteDefname), recoilAmount, shotRotation, 1f, fromPawn, casingAngleOffset); + ThrowEmptyCasing(drawPosition, map, DefDatabase.GetNamed(projProps.casingMoteDefname), recoilAmount, shotRotation, 1f, fromPawn, extension); } if (Controller.settings.CreateCasingsFilth) { @@ -861,7 +861,28 @@ public static void GenerateAmmoCasings(ProjectilePropertiesCE projProps, Vector3 } - public static void ThrowEmptyCasing(Vector3 loc, Map map, FleckDef casingFleckDef, float recoilAmount, float shotRotation, float size = 1f, bool fromPawn = false, float casingAngleOffset = 0) + //Don't use it when frompawn since pawn gun draw harmony patch handled it. + static Vector3 CasingOffsetRotated(GunDrawExtension ext, float shotRotation, bool flip) + { + if (ext == null || ext.CasingOffset == Vector2.zero) + { + return Vector3.zero; + } + return (new Vector3(flip ? -ext.CasingOffset.x : ext.CasingOffset.x, 0, ext.CasingOffset.y) + RandomOriginOffset(ext.CasingOffsetRandomRange)).RotatedBy(shotRotation); + } + + //No need to null check as the function calling it already handled it + static Vector3 RandomOriginOffset(Vector2 randRange) + { + if (randRange.y == 0 && randRange.x == 0) + { + return Vector3.zero; + } + return new Vector3(Rand.Range(-randRange.x, randRange.x), 0, Rand.Range(-randRange.y, randRange.y)); + } + + + public static void ThrowEmptyCasing(Vector3 loc, Map map, FleckDef casingFleckDef, float recoilAmount, float shotRotation, float size = 1f, bool fromPawn = false, GunDrawExtension extension = null) { if (!loc.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority) { @@ -875,6 +896,14 @@ public static void ThrowEmptyCasing(Vector3 loc, Map map, FleckDef casingFleckDe FleckCreationData creationData = FleckMaker.GetDataStatic(loc, map, casingFleckDef); creationData.velocitySpeed = Rand.Range(1.5f, 2f) * recoilAmount; creationData.airTimeLeft = Rand.Range(1f, 1.5f) / creationData.velocitySpeed; + + //Just in case a super low recoil caused the airtimeleft to be super high. + if (creationData.airTimeLeft > 1.5f) + { + creationData.airTimeLeft = Rand.Range(1f, 1.5f); + } + + creationData.scale = Rand.Range(0.5f, 0.3f) * size; creationData.spawnPosition = loc; int randomAngle = Rand.Range(-20, 20); @@ -886,9 +915,55 @@ public static void ThrowEmptyCasing(Vector3 loc, Map map, FleckDef casingFleckDe { flip = true; } - creationData.velocityAngle = flip ? shotRotation - 90 - casingAngleOffset + randomAngle : shotRotation + 90 + casingAngleOffset + randomAngle; - creationData.rotation = (flip ? shotRotation - 90 : shotRotation + 90) + Rand.Range(-3f, 4f); + + + creationData.rotation = (flip ? shotRotation + 90 : shotRotation + 90) + Rand.Range(-3f, 4f); creationData.rotationRate = (float)Rand.Range(-150, 150) / recoilAmount; + + + float casingAngleOffset = 0; + //Extension overrides + if (extension != null) + { + if (fromPawn) + { + creationData.spawnPosition += RandomOriginOffset(extension.CasingOffsetRandomRange).RotatedBy(shotRotation); + } + else + { + creationData.spawnPosition += CasingOffsetRotated(extension, shotRotation, flip); + } + casingAngleOffset = extension.CasingAngleOffset; + + if (extension.AdvancedCasingVariables) + { + casingAngleOffset += extension.CasingAngleOffsetRange.RandomInRange; + + if (extension.CasingLifeTimeOverrideRange.min > 0) + { + creationData.airTimeLeft = extension.CasingLifeTimeOverrideRange.RandomInRange; + } + else if (extension.CasingLifeTimeMultiplier > 0) + { + creationData.airTimeLeft *= extension.CasingLifeTimeMultiplier; + } + + if (extension.CasingSpeedOverrideRange.min > 0) + { + creationData.velocitySpeed = extension.CasingSpeedOverrideRange.RandomInRange; + } + else if (extension.CasingSpeedMultiplier > 0) + { + creationData.velocitySpeed *= extension.CasingSpeedMultiplier; + } + } + + creationData.scale *= extension.CasingSizeOffset; + + creationData.rotation += Rand.Range(-extension.CasingRotationRandomRange, extension.CasingRotationRandomRange); + } + + creationData.velocityAngle = flip ? shotRotation - 90 - casingAngleOffset + randomAngle : shotRotation + 90 + casingAngleOffset + randomAngle; map.flecks.CreateFleck(creationData); Rand.PopState(); } diff --git a/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs b/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs index 0ea966afe4..7733ccc97f 100644 --- a/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs +++ b/Source/CombatExtended/CombatExtended/Defs/GunDrawExtension.cs @@ -13,8 +13,26 @@ public class GunDrawExtension : DefModExtension public int recoilTick = -1; public float muzzleJumpModifier = -1; + //Angle: eject direction + //Rotation: casing's orientation + public Vector2 CasingOffset = Vector2.zero; public float CasingAngleOffset = 0; + public bool AdvancedCasingVariables = false; + + public FloatRange CasingAngleOffsetRange = new FloatRange(0, 0); + public float CasingLifeTimeMultiplier = -1; + //having a min value below 0 disables lifetime override range. Override disables multiplier + public FloatRange CasingLifeTimeOverrideRange = new FloatRange(-1, 1); + + public float CasingSpeedMultiplier = -1; + public FloatRange CasingSpeedOverrideRange = new FloatRange(-1, 1); + + public float CasingSizeOffset = 1; + + //for edge cases (read: Phalanx or Type-1130, where casings fell from a deflector chute) + public Vector2 CasingOffsetRandomRange = Vector2.zero; + public float CasingRotationRandomRange = 0; } } diff --git a/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootCE.cs b/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootCE.cs index d0f55930c5..a014675001 100644 --- a/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootCE.cs +++ b/Source/CombatExtended/CombatExtended/Verbs/Verb_ShootCE.cs @@ -394,7 +394,7 @@ protected virtual bool OnCastSuccessful() //Drop casings if (VerbPropsCE.ejectsCasings) { - CE_Utility.GenerateAmmoCasings(projectilePropsCE, fromPawn ? drawPos : caster.DrawPos + CasingOffsetRotated(ext), caster.Map, AimAngle, VerbPropsCE.recoilAmount, fromPawn: fromPawn, casingAngleOffset: EquipmentSource?.def.GetModExtension()?.CasingAngleOffset ?? 0); + CE_Utility.GenerateAmmoCasings(projectilePropsCE, fromPawn ? drawPos : caster.DrawPos, caster.Map, AimAngle, VerbPropsCE.recoilAmount, fromPawn: fromPawn, extension: ext); } // This needs to here for weapons without magazine to ensure their last shot plays sounds if (CompAmmo != null && !CompAmmo.HasMagazine && CompAmmo.UseAmmo) @@ -425,16 +425,6 @@ protected virtual bool OnCastSuccessful() } return true; } - - Vector3 CasingOffsetRotated(GunDrawExtension ext) - { - if (ext == null || ext.CasingOffset == Vector2.zero) - { - return Vector3.zero; - } - return new Vector3(ext.CasingOffset.x, 0, ext.CasingOffset.y).RotatedBy(AimAngle); - - } #endregion } }