diff --git a/Patches/Temp - Delete Me/Temp Delete Me.xml b/Patches/Temp - Delete Me/Temp Delete Me.xml index e8a9670558..71c0186d9f 100644 --- a/Patches/Temp - Delete Me/Temp Delete Me.xml +++ b/Patches/Temp - Delete Me/Temp Delete Me.xml @@ -11,9 +11,7 @@
  • Defs/ThingDef[ - defName="Turret_ZPU_1_Base" or - defName="Turret_ZPU_2_Base" or - defName="Turret_ZPU_4_Base" + defName="Turret_ZPU_1_Base" ] diff --git a/Source/CombatExtended/CombatExtended/Comps/CompCIWS.cs b/Source/CombatExtended/CombatExtended/Comps/CompCIWS.cs index 8cb05c1764..1b14bfe65c 100644 --- a/Source/CombatExtended/CombatExtended/Comps/CompCIWS.cs +++ b/Source/CombatExtended/CombatExtended/Comps/CompCIWS.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using UnityEngine; using Verse; using Verse.AI; @@ -30,5 +31,41 @@ private CompPowerTrader PowerTrader return powerTrader; } } + public static IEnumerable GetGizmos(IEnumerable all, List active) + { + if (!all.Any()) + { + yield break; + } + List options = new List(); + + options.AddRange(all.Select(x => new FloatMenuOption(x.Props.label.Translate(), () => + { + active.Clear(); + active.Add(x); + }))); + options.Add(new FloatMenuOption("AllCiws".Translate(), () => + { + active.Clear(); + active.AddRange(all); + })); + options.Add(new FloatMenuOption("CiwsDisabled".Translate(), () => + { + active.Clear(); + })); + yield return new Command_Action + { + defaultLabel = "CE_ChooseCIWS".Translate() + "...", + defaultDesc = "CE_ChooseCIWSDesc".Translate(), + icon = active.SequenceEqual(all) ? CIWS_All_Active_Icon : active.FirstOrDefault()?.CIWS_Icon ?? CIWS_Deactivated_Icon, + action = delegate () + { + Find.WindowStack.Add(new FloatMenu(options)); + } + }; + } + static Texture CIWS_Deactivated_Icon => null; + static Texture CIWS_All_Active_Icon => HumanEmbryo.ImplantIcon.Texture; + protected virtual Texture CIWS_Icon => null; } } diff --git a/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS.cs b/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS.cs index f885aa3c8c..e49b4b5221 100644 --- a/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS.cs +++ b/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS.cs @@ -6,5 +6,6 @@ public abstract class CompProperties_CIWS : CompProperties { public bool radarRequired = false; public float hitChance = 0.33f; + public string label; } } diff --git a/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Projectile.cs b/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Projectile.cs index 8c021ce9e6..0864818692 100644 --- a/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Projectile.cs +++ b/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Projectile.cs @@ -12,6 +12,7 @@ public class CompProperties_CIWS_Projectile : CompProperties_CIWS public CompProperties_CIWS_Projectile() { compClass = typeof(CompCIWS_Projectile); + this.label = "CE_CIWS_Projectile"; } public bool interceptOnGroundProjectiles = false; } diff --git a/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Skyfaller.cs b/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Skyfaller.cs index 806814f835..febc483a4e 100644 --- a/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Skyfaller.cs +++ b/Source/CombatExtended/CombatExtended/Comps/CompProperties_CIWS_Skyfaller.cs @@ -12,6 +12,7 @@ public class CompProperties_CIWS_Skyfaller : CompProperties_CIWS public CompProperties_CIWS_Skyfaller() { compClass = typeof(CompCIWS_Skyfaller); + this.label = "CE_CIWS_Skyfaller"; } } } diff --git a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs index cfd7267aa3..55a6ef9417 100644 --- a/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs +++ b/Source/CombatExtended/CombatExtended/Things/Building_TurretGunCE.cs @@ -42,7 +42,8 @@ public class Building_TurretGunCE : Building_Turret public CompInitiatable initiatableComp; public CompMannable mannableComp; public List ciws; - private CompCIWS activeCIWS; + public List enabledCIWS = new List(); //Used for targeting + private CompCIWS activeCIWS; // Used for current target public static Material ForcedTargetLineMat = MaterialPool.MatFrom(GenDraw.LineTexPath, ShaderDatabase.Transparent, new Color(1f, 0.5f, 0.5f)); // New fields @@ -207,6 +208,8 @@ public override void SpawnSetup(Map map, bool respawningAfterLoad) //Add ma { ticksUntilAutoReload = minTicksBeforeAutoReload; } + enabledCIWS.Clear(); + enabledCIWS.AddRange(CIWS); } // if (CompAmmo == null || CompAmmo.Props == null || CompAmmo.Props.ammoSet == null || CompAmmo.Props.ammoSet.ammoTypes.NullOrEmpty()) @@ -265,8 +268,13 @@ public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) // Added Scribe_TargetInfo.Look(ref this.currentTargetInt, "currentTarget"); Scribe_Values.Look(ref this.holdFire, "holdFire", false, false); Scribe_Values.Look(ref this.everSpawned, "everSpawned", false, false); + Scribe_Collections.Look(ref this.enabledCIWS, "enabledCIWS", LookMode.Value); Scribe_TargetInfo.Look(ref globalTargetInfo, "globalSourceInfo"); + if (Scribe.mode == LoadSaveMode.PostLoadInit && enabledCIWS == null) + { + enabledCIWS = new List(); + } BackCompatibility.PostExposeData(this); } @@ -443,7 +451,7 @@ public LocalTargetInfo TryFindNewTarget() // Core method Faction faction = attackTargetSearcher.Thing.Faction; float range = this.AttackVerb.verbProps.range; - foreach (var ciws in CIWS) + foreach (var ciws in enabledCIWS) { if (ciws.TryFindTarget(attackTargetSearcher, out var ciwsTarget)) { @@ -800,6 +808,10 @@ public override IEnumerable GetGizmos() // Modified isActive = (() => holdFire) }; } + foreach (var ciwsGizmo in CompCIWS.GetGizmos(CIWS, enabledCIWS)) + { + yield return ciwsGizmo; + } } }