Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move static LaunchProjectileCE to CE_Utility #3567

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading