Skip to content

Commit

Permalink
Merge pull request #3567 from CombatExtended-Continued/move-launchpro…
Browse files Browse the repository at this point in the history
…jectilece

Move static LaunchProjectileCE to CE_Utility
  • Loading branch information
N7Huntsman authored Nov 26, 2024
2 parents 4fc5f61 + 6217609 commit 983bb6a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 77 deletions.
78 changes: 78 additions & 0 deletions Source/CombatExtended/CombatExtended/CE_Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorldStrengthTracker>().GetFactionTracker(faction);
}
}
78 changes: 1 addition & 77 deletions Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<bool, Vector2> _GetCollisionBodyFactors(Pawn pawn)
{
Vector2 ret = new Vector2();
Expand Down

0 comments on commit 983bb6a

Please sign in to comment.