diff --git a/Source/CombatExtended/CombatExtended/Defs/TurretDrawExtension.cs b/Source/CombatExtended/CombatExtended/Defs/TurretDrawExtension.cs new file mode 100644 index 0000000000..9ab1bf0925 --- /dev/null +++ b/Source/CombatExtended/CombatExtended/Defs/TurretDrawExtension.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using Verse; + +namespace CombatExtended +{ + public class TurretDrawExtension : DefModExtension + { + public GraphicData TurretBottomGraphicData; + + public GraphicData TurretTopGraphicData; + + public List Barrels = new List(); + } + + public class TurretDrawExtension_BarrelOffsetPair + { + public Vector2 BarrelOffset; + public Material BarrelMaterial; + public GraphicData BarrelGraphicData; + } +} diff --git a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs index f13f4eb3c2..e16f9d42b6 100644 --- a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs +++ b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs @@ -54,6 +54,10 @@ public class Building_TurretGunCE : Building_Turret private bool everSpawned = false; public GlobalTargetInfo globalTargetInfo = GlobalTargetInfo.Invalid; + public Material TurretTopBaseMaterial; + public Material TurretTopTopMaterial; + public List BarrelOffsetPairs = new List(); + #endregion #region Properties @@ -193,6 +197,21 @@ public override void SpawnSetup(Map map, bool respawningAfterLoad) //Add ma } } + TurretDrawExtension turretDrawExtension = this.def.GetModExtension(); + if (turretDrawExtension != null) + { + TurretTopBaseMaterial = turretDrawExtension.TurretBottomGraphicData?.Graphic.MatSingle; + TurretTopTopMaterial = turretDrawExtension.TurretTopGraphicData?.Graphic.MatSingle; + if (turretDrawExtension.Barrels.Any()) + { + foreach (var barrel in turretDrawExtension.Barrels) + { + TurretDrawExtension_BarrelOffsetPair barrelCache = barrel; + barrelCache.BarrelMaterial = barrel.BarrelGraphicData.Graphic.MatSingle; + BarrelOffsetPairs.Add(barrelCache); + } + } + } // if (CompAmmo == null || CompAmmo.Props == null || CompAmmo.Props.ammoSet == null || CompAmmo.Props.ammoSet.ammoTypes.NullOrEmpty()) // return; @@ -587,10 +606,55 @@ public override void Draw() { CE_Utility.Recoil(def.building.turretGunDef, AttackVerb, out drawOffset, out angleOffset, top.CurRotation, false); } - top.DrawTurret(drawOffset, angleOffset); + if (TurretTopBaseMaterial != null) + { + DrawTurretComponents(TurretTopBaseMaterial); + } + if (BarrelOffsetPairs.Any()) + { + for (int i = 0; i < BarrelOffsetPairs.Count(); i++) + { + if (i == AttackVerb.burstShotsLeft % BarrelOffsetPairs.Count()) + { + DrawTurretComponentRecoiled(BarrelOffsetPairs[i].BarrelMaterial, BarrelOffsetPairs[i].BarrelOffset, drawOffset, angleOffset); + } + else + { + DrawTurretComponentRecoiled(BarrelOffsetPairs[i].BarrelMaterial, BarrelOffsetPairs[i].BarrelOffset, Vector3.zero, 0); + } + } + } + else + { + top.DrawTurret(drawOffset, angleOffset); + } + if (TurretTopTopMaterial != null) + { + DrawTurretComponents(TurretTopTopMaterial, true); + } base.Draw(); } + public void DrawTurretComponents(Material mat, bool above = false) + { + Vector3 v = new Vector3(def.building.turretTopOffset.x, 0f, def.building.turretTopOffset.y).RotatedBy(top.CurRotation); + float turretTopDrawSize = def.building.turretTopDrawSize; + float num = CurrentEffectiveVerb?.AimAngleOverride ?? top.CurRotation; + Matrix4x4 matrix = default(Matrix4x4); + matrix.SetTRS(DrawPos + (above ? 2 * Altitudes.AltIncVect : Altitudes.AltIncVect / 2) + v, (-90 + num).ToQuat(), new Vector3(turretTopDrawSize, 1f, turretTopDrawSize)); + Graphics.DrawMesh(MeshPool.plane10, matrix, mat, 0); + } + + public void DrawTurretComponentRecoiled(Material mat, Vector2 offset, Vector3 recoilDrawOffset, float recoilAngleOffset) + { + float turretTopDrawSize = def.building.turretTopDrawSize; + Vector3 v = recoilDrawOffset; + float num = CurrentEffectiveVerb?.AimAngleOverride ?? top.CurRotation; + Matrix4x4 matrix = default(Matrix4x4); + matrix.SetTRS(DrawPos + Altitudes.AltIncVect + v + new Vector3(offset.x, 0f, offset.y).RotatedBy(top.CurRotation), (-90 + num).ToQuat(), new Vector3(turretTopDrawSize, 1f, turretTopDrawSize)); + Graphics.DrawMesh(MeshPool.plane10, matrix, mat, 0); + } + public override void DrawExtraSelectionOverlays() // Draw at range less than 1.42 tiles { float range = this.GunCompEq.PrimaryVerb.verbProps.range;