From 62176092cf6d324f82f5c780315decddad757d10 Mon Sep 17 00:00:00 2001 From: logan Date: Sun, 24 Nov 2024 12:24:03 -0800 Subject: [PATCH] Move static LaunchProjectileCE to CE_Utility --- .../CombatExtended/CE_Utility.cs | 78 +++++++++++++++++++ .../VehiclesCompat/VehiclesCompat.cs | 78 +------------------ 2 files changed, 79 insertions(+), 77 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CE_Utility.cs b/Source/CombatExtended/CombatExtended/CE_Utility.cs index 6e4c6887a8..e57858b013 100644 --- a/Source/CombatExtended/CombatExtended/CE_Utility.cs +++ b/Source/CombatExtended/CombatExtended/CE_Utility.cs @@ -1617,6 +1617,84 @@ public static Pawn GetRandomWorldPawn(this Faction faction, bool capableOfCombat return pawn; } + public static object LaunchProjectileCE(ThingDef projectileDef, + ThingDef _ammoDef, + Def _ammosetDef, + Vector2 origin, + LocalTargetInfo target, + Pawn launcher, + float shotAngle, + float shotRotation, + float shotHeight, + float shotSpeed) + { + if (_ammoDef is AmmoDef ammoDef && _ammosetDef is AmmoSetDef ammosetDef) + { + foreach (var al in ammosetDef.ammoTypes) + { + if (al.ammo == ammoDef) + { + projectileDef = al.projectile; + break; + } + } + } + else + { + projectileDef = projectileDef.GetProjectile(); + } + var p = ThingMaker.MakeThing(projectileDef, null); + ProjectileCE projectile = (ProjectileCE)p; + GenSpawn.Spawn(projectile, launcher.Position, launcher.Map); + projectile.ExactPosition = origin; + projectile.canTargetSelf = false; + projectile.minCollisionDistance = 1; + projectile.intendedTarget = target; + projectile.mount = null; + projectile.AccuracyFactor = 1; + + ProjectilePropertiesCE pprop = projectileDef.projectile as ProjectilePropertiesCE; + bool instant = false; + float spreadDegrees = 0; + float aperatureSize = 0.03f; + // Hard coded as a super high max range - TODO: change in 1.6 to pass the range from the turret to this function. + // Should also update ProjectileCE.RayCast to not need a VerbPropertiesCE input just a float for range (Since thats all its used for). + VerbPropertiesCE verbPropsRange = new VerbPropertiesCE + { + range = 1000 + }; + if (pprop != null) + { + instant = pprop.isInstant; + } + if (instant) + { + projectile.RayCast( + launcher, + verbPropsRange, + origin, + shotAngle, + shotRotation, + shotHeight, + shotSpeed, + spreadDegrees, + aperatureSize, + launcher); + } + else + { + projectile.Launch( + launcher, + origin, + shotAngle, + shotRotation, + shotHeight, + shotSpeed, + launcher); + } + return projectile; + } + public static FactionStrengthTracker GetStrengthTracker(this Faction faction) => Find.World.GetComponent().GetFactionTracker(faction); } } diff --git a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs index 8685e1a663..1d1fab7ef1 100644 --- a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs +++ b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs @@ -27,7 +27,7 @@ public void PostLoad(ModContentPack content, ISettingsCE vehicleSettings) { VehicleTurret.ProjectileAngleCE = ProjectileAngleCE; VehicleTurret.LookupAmmosetCE = LookupAmmosetCE; - VehicleTurret.LaunchProjectileCE = LaunchProjectileCE; + VehicleTurret.LaunchProjectileCE = CE_Utility.LaunchProjectileCE; VehicleTurret.LookupProjectileCountAndSpreadCE = LookupProjectileCountAndSpreadCE; VehicleTurret.NotifyShotFiredCE = NotifyShotFiredCE; global::CombatExtended.Compatibility.Patches.RegisterCollisionBodyFactorCallback(_GetCollisionBodyFactors); @@ -146,83 +146,7 @@ public static Vector2 ProjectileAngleCE(float speed, float range, Thing shooter, return new Vector2(dTurretRotation, shotAngle); } - public static object LaunchProjectileCE(ThingDef projectileDef, - ThingDef _ammoDef, - Def _ammosetDef, - Vector2 origin, - LocalTargetInfo target, - VehiclePawn vehicle, - float shotAngle, - float shotRotation, - float shotHeight, - float shotSpeed) - { - if (_ammoDef is AmmoDef ammoDef && _ammosetDef is AmmoSetDef ammosetDef) - { - foreach (var al in ammosetDef.ammoTypes) - { - if (al.ammo == ammoDef) - { - projectileDef = al.projectile; - break; - } - } - } - else - { - projectileDef = projectileDef.GetProjectile(); - } - var p = ThingMaker.MakeThing(projectileDef, null); - ProjectileCE projectile = (ProjectileCE)p; - GenSpawn.Spawn(projectile, vehicle.Position, vehicle.Map); - projectile.ExactPosition = origin; - projectile.canTargetSelf = false; - projectile.minCollisionDistance = 1; - projectile.intendedTarget = target; - projectile.mount = null; - projectile.AccuracyFactor = 1; - ProjectilePropertiesCE pprop = projectileDef.projectile as ProjectilePropertiesCE; - bool instant = false; - float spreadDegrees = 0; - float aperatureSize = 0.03f; - // Hard coded as a super high max range - TODO: change in 1.6 to pass the range from the turret to this function. - // Should also update ProjectileCE.RayCast to not need a VerbPropertiesCE input just a float for range (Since thats all its used for). - VerbPropertiesCE verbPropsRange = new VerbPropertiesCE - { - range = 1000 - }; - if (pprop != null) - { - instant = pprop.isInstant; - } - if (instant) - { - projectile.RayCast( - vehicle, - verbPropsRange, - origin, - shotAngle, - shotRotation, - shotHeight, - shotSpeed, - spreadDegrees, - aperatureSize, - vehicle); - } - else - { - projectile.Launch( - vehicle, - origin, - shotAngle, - shotRotation, - shotHeight, - shotSpeed, - vehicle); - } - return projectile; - } private static Tuple _GetCollisionBodyFactors(Pawn pawn) { Vector2 ret = new Vector2();