Skip to content

Commit

Permalink
Cheat on Projectile and Weapon drawing positions to mask camera probl…
Browse files Browse the repository at this point in the history
…ems.
  • Loading branch information
perkinslr committed Sep 1, 2024
1 parent d3129ed commit ba9d81d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Source/CombatExtended/CombatExtended/Projectiles/ProjectileCE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public abstract class ProjectileCE : ThingWithComps
protected float initialSpeed;
#endregion

#region Drawing
protected int ticksToTruePosition;
#endregion

#region Origin destination
public bool OffMapOrigin = false;

Expand Down Expand Up @@ -199,6 +203,10 @@ public override Vector3 DrawPos
get
{
var sh = Mathf.Max(0f, (ExactPosition.y) * 0.84f);
if (FlightTicks < ticksToTruePosition)
{
sh *= FlightTicks / ticksToTruePosition;
}
return new Vector3(ExactPosition.x, def.Altitude, ExactPosition.z + sh);
}
}
Expand Down Expand Up @@ -539,12 +547,14 @@ protected void RayCastSuppression(IntVec3 muzzle, IntVec3 destination, Map map =
/// <param name="shotSpeed">The shot speed (default: def.projectile.speed)</param>
/// <param name="equipment">The equipment used to fire the projectile.</param>
/// <param name="distance">The distance to the estimated intercept point</param>
public virtual void Launch(Thing launcher, Vector2 origin, float shotAngle, float shotRotation, float shotHeight = 0f, float shotSpeed = -1f, Thing equipment = null, float distance = -1)
/// <param name="ticksToTruePosition">The number of ticks before the bullet is drawn at its true height instead of the muzzle height</param>
public virtual void Launch(Thing launcher, Vector2 origin, float shotAngle, float shotRotation, float shotHeight = 0f, float shotSpeed = -1f, Thing equipment = null, float distance = -1, int ticksToTruePosition = 3)
{
this.shotAngle = shotAngle;
this.shotHeight = shotHeight;
this.shotRotation = shotRotation;
this.shotSpeed = Math.Max(shotSpeed, def.projectile.speed);
this.ticksToTruePosition = ticksToTruePosition;
if (def.projectile is ProjectilePropertiesCE props)
{
this.castShadow = props.castShadow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void ExposeData()
Scribe_Values.Look(ref this.ticksToBurst, "ticksToBurst", -1, false);
}

public override void Launch(Thing launcher, Vector2 origin, float shotAngle, float shotRotation, float shotHeight = 0f, float shotSpeed = -1f, Thing equipment = null, float distance = -1)
public override void Launch(Thing launcher, Vector2 origin, float shotAngle, float shotRotation, float shotHeight = 0f, float shotSpeed = -1f, Thing equipment = null, float distance = -1, int ticksToTruePosition = 3)
{
int armingDelay = 0;
if (def.projectile is ProjectilePropertiesCE props)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class VerbPropertiesCE : VerbProperties
public float indirectFirePenalty = 0;
public float circularError = 0;
public float meleeArmorPenetration = 0;
public float firingOffset = 0.19f;
public int ticksToTruePosition = 5;
public bool ejectsCasings = true;
public bool ignorePartialLoSBlocker = false;
public bool interruptibleBurst = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ public override bool TryCastShot()

float spreadDegrees = 0;
float aperatureSize = 0;
int ticksToTruePosition = VerbPropsCE.ticksToTruePosition;

if (Projectile.projectile is ProjectilePropertiesCE pprop)
{
Expand Down Expand Up @@ -1118,7 +1119,8 @@ public override bool TryCastShot()
ShotHeight,
ShotSpeed,
EquipmentSource,
distance);
distance,
ticksToTruePosition);
}
pelletMechanicsOnly = true;
}
Expand Down
10 changes: 9 additions & 1 deletion Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ private static void RecoilCE(Thing eq, Vector3 position, float aimAngle, float n

private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int layer, Thing eq, Vector3 position, float aimAngle)
{
CompEquippable compEquippable = eq.TryGetComp<CompEquippable>();
GunDrawExtension drawData = eq.def.GetModExtension<GunDrawExtension>() ?? 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);
Vector3 posVec = new Vector3(drawData.DrawOffset.x, 0, drawData.DrawOffset.y);
if (compEquippable != null && compEquippable.PrimaryVerb is Verb_LaunchProjectileCE verbLPCE)
{
VerbPropertiesCE vpce = verbLPCE.VerbPropsCE;
if (verbLPCE.ShooterPawn != null && verbLPCE.WarmingUp || muzzleJump != 0)
{
posVec.z += verbLPCE.ShotHeight * vpce.firingOffset * Mathf.Abs(Mathf.Sin(aimAngle * 2 * 3.14f / 360f));
}
}
Vector3 casingOffset = new Vector3(drawData.CasingOffset.x, 0, drawData.CasingOffset.y);
if (aimAngle > 200 && aimAngle < 340)
{
Expand All @@ -61,7 +70,6 @@ private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int laye
casingOffset.x *= -1;
}
matrix.SetTRS(position + posVec.RotatedBy(matrix.rotation.eulerAngles.y) + recoilOffset, Quaternion.AngleAxis(matrix.rotation.eulerAngles.y + muzzleJump, Vector3.up), scale);
CompEquippable compEquippable = eq.TryGetComp<CompEquippable>();
if (compEquippable != null && compEquippable.PrimaryVerb is Verb_ShootCE verbCE)
{
verbCE.drawPos = casingDrawPos + (casingOffset + posVec).RotatedBy(matrix.rotation.eulerAngles.y);
Expand Down

0 comments on commit ba9d81d

Please sign in to comment.