Skip to content

Commit

Permalink
CIWS activation/deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDorob committed Jan 7, 2024
1 parent 52b4d14 commit 94652a6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
4 changes: 1 addition & 3 deletions Patches/Temp - Delete Me/Temp Delete Me.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<li Class="PatchOperationAdd">
<xpath>
Defs/ThingDef[
defName="Turret_ZPU_1_Base" or
defName="Turret_ZPU_2_Base" or
defName="Turret_ZPU_4_Base"
defName="Turret_ZPU_1_Base"
]
</xpath>
<value>
Expand Down
37 changes: 37 additions & 0 deletions Source/CombatExtended/CombatExtended/Comps/CompCIWS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using Verse.AI;

Expand All @@ -30,5 +31,41 @@ private CompPowerTrader PowerTrader
return powerTrader;
}
}
public static IEnumerable<Gizmo> GetGizmos(IEnumerable<CompCIWS> all, List<CompCIWS> active)
{
if (!all.Any())
{
yield break;
}
List<FloatMenuOption> options = new List<FloatMenuOption>();

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public abstract class CompProperties_CIWS : CompProperties
{
public bool radarRequired = false;
public float hitChance = 0.33f;
public string label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class CompProperties_CIWS_Skyfaller : CompProperties_CIWS
public CompProperties_CIWS_Skyfaller()
{
compClass = typeof(CompCIWS_Skyfaller);
this.label = "CE_CIWS_Skyfaller";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class Building_TurretGunCE : Building_Turret
public CompInitiatable initiatableComp;
public CompMannable mannableComp;
public List<CompCIWS> ciws;
private CompCIWS activeCIWS;
public List<CompCIWS> enabledCIWS = new List<CompCIWS>(); //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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -265,8 +268,13 @@ public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) // Added
Scribe_TargetInfo.Look(ref this.currentTargetInt, "currentTarget");
Scribe_Values.Look<bool>(ref this.holdFire, "holdFire", false, false);
Scribe_Values.Look<bool>(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<CompCIWS>();
}
BackCompatibility.PostExposeData(this);
}

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -800,6 +808,10 @@ public override IEnumerable<Gizmo> GetGizmos() // Modified
isActive = (() => holdFire)
};
}
foreach (var ciwsGizmo in CompCIWS.GetGizmos(CIWS, enabledCIWS))
{
yield return ciwsGizmo;
}
}
}

Expand Down

0 comments on commit 94652a6

Please sign in to comment.