Skip to content

Commit

Permalink
Hold fire for CIWS
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDorob committed Nov 18, 2024
1 parent c0694fd commit 719332d
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 40 deletions.
6 changes: 6 additions & 0 deletions Defs/ThingDefs_Misc/Weapons_CIWS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<soundCastTail>GunTail_Heavy</soundCastTail>
<muzzleFlashScale>9</muzzleFlashScale>
<recoilPattern>Mounted</recoilPattern>
<holdFireLabel>HoldCloseInProjectilesFire</holdFireLabel>
<holdFireDesc>HoldCloseInProjectilesFireDesc</holdFireDesc>
</li>
<li Class="CombatExtended.VerbProperties_CIWSSkyfaller">
<verbClass>CombatExtended.VerbCIWSSkyfaller</verbClass>
Expand All @@ -61,6 +63,7 @@
<soundCastTail>GunTail_Heavy</soundCastTail>
<muzzleFlashScale>9</muzzleFlashScale>
<recoilPattern>Mounted</recoilPattern>
<holdFireLabel>HoldCloseInSkyfallersFire</holdFireLabel>
</li>
</verbs>
<comps>
Expand All @@ -69,6 +72,9 @@
<reloadTime>7.8</reloadTime>
<ammoSet>AmmoSet_8x35mmCharged</ammoSet>
</li>
<li>
<compClass>CombatExtended.CompVerbDisabler</compClass>
</li>
</comps>
</ThingDef>

Expand Down
38 changes: 38 additions & 0 deletions Source/CombatExtended/CombatExtended/Comps/CompVerbDisabler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace CombatExtended
{
public class CompVerbDisabler : ThingComp
{
public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
foreach (var gizmo in base.CompGetGizmosExtra())
{
yield return gizmo;
}
var verbs = parent.GetComp<CompEquippable>()?.AllVerbs.OfType<IVerbDisableable>();
if (verbs != null)
{
foreach (var verb in verbs)
{
var command = new Command_Toggle()
{
defaultDesc = verb.HoldFireDesc.Translate(),
defaultLabel = verb.HoldFireLabel.Translate(),
icon = verb.HoldFireIcon,
isActive = () => verb.HoldFire,
toggleAction = () => verb.HoldFire = !verb.HoldFire,

};
yield return command;
}
}
}
}
}
66 changes: 31 additions & 35 deletions Source/CombatExtended/CombatExtended/Comps/VerbCIWS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,34 @@
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SocialPlatforms;
using UnityEngine.UI;
using Verse;
using Verse.Sound;

namespace CombatExtended
{
public abstract class VerbCIWS : Verb_ShootCE_CIWS, ITargetSearcher
public abstract class VerbCIWS : Verb_ShootCE_CIWS, ITargetSearcher, IVerbDisableable
{
protected bool debug;
protected bool holdFire;
protected Texture2D icon;
public virtual bool HoldFire { get; set; }

public VerbProperties_CIWS Props => verbProps as VerbProperties_CIWS;
protected abstract string HoldLabel { get; }
protected abstract string HoldDesc { get; }
protected virtual string HoldIcon => "UI/Commands/HoldFire";

//public override IEnumerable<Gizmo> CompGetGizmosExtra()
//{
// foreach (var gizmo in base.CompGetGizmosExtra())
// {
// yield return gizmo;
// }
// if (Turret.CanToggleHoldFire)
// {
// yield return new Command_Toggle
// {
// defaultLabel = HoldLabel.Translate(),
// defaultDesc = HoldDesc.Translate(),
// icon = ContentFinder<Texture2D>.Get(HoldIcon, true),
// hotKey = KeyBindingDefOf.Misc6,
// toggleAction = delegate ()
// {
// this.holdFire = !this.holdFire;
// if (this.holdFire && HasTarget)
// {
// Turret.ResetForcedTarget();
// }
// },
// isActive = (() => this.holdFire)
// };
// }
//}
public virtual string HoldFireLabel => Props.holdFireLabel;
public virtual string HoldFireDesc => Props.holdFireDesc;
public virtual Texture2D HoldFireIcon
{
get
{
if (icon == null)
{
icon = ContentFinder<Texture2D>.Get(Props.holdFireIcon);
}
return icon;
}
}
protected override bool ShouldAim => false;
public virtual bool Active => !holdFire && Turret.Active;
public virtual bool Active => !HoldFire && Turret.Active;
protected override bool LockRotationAndAngle => false;
public abstract bool TryFindNewTarget(out LocalTargetInfo target);
public virtual void ShowTrajectories()
Expand Down Expand Up @@ -102,14 +87,22 @@ protected override bool KeepBurstOnNoShootLine(bool suppressing, out ShootLine s
{
shootLine = lastShootLine.HasValue ? lastShootLine.Value : default;
return !currentTarget.ThingDestroyed;
}

}
public override bool Available()
{
return Active && base.Available();
}
}
public abstract class VerbCIWS<TargetType> : VerbCIWS where TargetType : Thing
{

public override bool TryFindNewTarget(out LocalTargetInfo target)
{
if (!Active)
{
target = LocalTargetInfo.Invalid;
return false;
}
float range = this.verbProps.range;
var _target = Targets.Where(x => Props.Interceptable(x.def) && !Turret.IgnoredDefs.Contains(x.def)).Where(x => !IsFriendlyTo(x)).FirstOrDefault(t =>
{
Expand Down Expand Up @@ -229,6 +222,9 @@ public override bool TryFindCEShootLineFromTo(IntVec3 root, LocalTargetInfo targ

public abstract class VerbProperties_CIWS : VerbPropertiesCE
{
public string holdFireIcon = "UI/Commands/HoldFire";
public string holdFireLabel = "HoldFire";
public string holdFireDesc;
public List<ThingDef> ignored = new List<ThingDef>();
public IEnumerable<ThingDef> Ignored => ignored;
public virtual bool Interceptable(ThingDef targetDef) => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace CombatExtended
{
public class VerbCIWSProjectile : VerbCIWS<ProjectileCE>
{
protected override string HoldDesc => "HoldCloseInProjectilesFireDesc";
protected override string HoldLabel => "HoldCloseInProjectilesFire";
public new VerbProperties_CIWSProjectile Props => verbProps as VerbProperties_CIWSProjectile;

public override IEnumerable<ProjectileCE> Targets => Caster.Map?.listerThings.ThingsInGroup(ThingRequestGroup.Projectile).OfType<ProjectileCE>() ?? Array.Empty<ProjectileCE>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace CombatExtended
{
public class VerbCIWSSkyfaller : VerbCIWS<Skyfaller>
{
protected override string HoldDesc => "HoldSkyfallerFireDesc";
protected override string HoldLabel => "HoldSkyfallerFire";
public override IEnumerable<Skyfaller> Targets => Caster.Map?.listerThings.ThingsInGroup(Verse.ThingRequestGroup.ActiveDropPod).OfType<Skyfaller>();


Expand Down
17 changes: 17 additions & 0 deletions Source/CombatExtended/CombatExtended/IVerbDisableable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace CombatExtended
{
public interface IVerbDisableable
{
bool HoldFire { get; set; }
string HoldFireLabel { get; }
string HoldFireDesc { get; }
Texture2D HoldFireIcon { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -67,5 +68,23 @@ public override void ResetForcedTarget()
base.ResetForcedTarget();
activeVerb = null;
}
public override IEnumerable<Gizmo> GetGizmos()
{
foreach (var gizmo in base.GetGizmos())
{
yield return gizmo;
}
if (PlayerControlled)
{
var disablerComp = Gun.TryGetComp<CompVerbDisabler>();
if (disablerComp != null)
{
foreach (var gizmo in disablerComp.CompGetGizmosExtra())
{
yield return gizmo;
}
}
}
}
}
}

0 comments on commit 719332d

Please sign in to comment.