Skip to content

Commit

Permalink
Merge pull request #27 from BDCarrillo/Phant
Browse files Browse the repository at this point in the history
Big Badda Boom
  • Loading branch information
Ash-LikeSnow authored Mar 5, 2024
2 parents 074f457 + b2b62e5 commit c471866
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 104 deletions.
1 change: 1 addition & 0 deletions Data/Scripts/CoreSystems/Ai/AiFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public partial class Ai
internal readonly List<QueuedSoundEvent> QueuedSounds = new List<QueuedSoundEvent>();
internal readonly List<WeaponComponent> TrackingComps = new List<WeaponComponent>();
internal readonly List<WeaponComponent> WeaponComps = new List<WeaponComponent>(32);
internal readonly List<WeaponComponent> CriticalComps = new List<WeaponComponent>();
internal readonly List<Upgrade.UpgradeComponent> UpgradeComps = new List<Upgrade.UpgradeComponent>(32);
internal readonly List<SupportSys.SupportComponent> SupportComps = new List<SupportSys.SupportComponent>(32);
internal readonly List<ControlSys.ControlComponent> ControlComps = new List<ControlSys.ControlComponent>(32);
Expand Down
8 changes: 8 additions & 0 deletions Data/Scripts/CoreSystems/Ai/AiSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ internal void CompChange(bool add, CoreComponent comp)
WeaponIdx.Add(wComp, WeaponComps.Count);
WeaponComps.Add(wComp);

if (wComp.HasArming || wComp.IsBomb)
CriticalComps.Add(wComp);

if (wComp.Data.Repo.Values.Set.Overrides.WeaponGroupId > 0)
CompWeaponGroups[wComp] = wComp.Data.Repo.Values.Set.Overrides.WeaponGroupId;

Expand All @@ -56,6 +59,10 @@ internal void CompChange(bool add, CoreComponent comp)

var wCompMaxWepRange = wComp.MaxDetectDistance;
WeaponComps.RemoveAtFast(weaponIdx);

if (wComp.HasArming || wComp.IsBomb)
CriticalComps.Remove(wComp);

if (weaponIdx < WeaponComps.Count)
WeaponIdx[WeaponComps[weaponIdx]] = weaponIdx;
WeaponIdx.Remove(wComp);
Expand Down Expand Up @@ -505,6 +512,7 @@ internal void CleanUp()
TrackingComps.Clear();
PlayerControl.Clear();
WeaponComps.Clear();
CriticalComps.Clear();
UpgradeComps.Clear();
SupportComps.Clear();
ControlComps.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void CreateArmReaction(Session session)
{
var action = MyAPIGateway.TerminalControls.CreateAction<T>("Arm");
action.Icon = @"Textures\GUI\Icons\Actions\Toggle.dds";
action.Name = new StringBuilder("Arm Critical Reaction");
action.Name = new StringBuilder("Arm Warhead");
action.Action = CustomActions.RequestSetArmed;
action.Writer = CustomActions.ArmWriter;
action.Enabled = TerminalHelpers.CanBeArmed;
Expand All @@ -22,6 +22,19 @@ public static void CreateArmReaction(Session session)
MyAPIGateway.TerminalControls.AddAction<T>(action);
session.CustomActions.Add(action);
}
public static void CreateTriggerNow(Session session)
{
var action = MyAPIGateway.TerminalControls.CreateAction<T>("Detonate");
action.Icon = @"Textures\GUI\Icons\Actions\SwitchOn.dds";
action.Name = new StringBuilder("Detonate Now");
action.Action = CustomActions.TriggerCriticalReaction;
action.Writer = TerminalHelpers.EmptyStringBuilder;
action.Enabled = TerminalHelpers.CanBeArmed;
action.ValidForGroups = true;

MyAPIGateway.TerminalControls.AddAction<T>(action);
session.CustomActions.Add(action);
}

internal static void CreateShootMode(Session session)
{
Expand Down
25 changes: 21 additions & 4 deletions Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static void AddUiControls<T>(Session session) where T : IMyTerminalBloc
AddWeaponCrticalTimeSliderRange<T>(session, "Detonation", Localization.GetText("TerminalDetonationTitle"), Localization.GetText("TerminalDetonationTooltip"), BlockUi.GetArmedTimer, BlockUi.RequestSetArmedTimer, NotCounting, CanBeArmed, BlockUi.GetMinCriticalTime, BlockUi.GetMaxCriticalTime, true);
AddButtonNoAction<T>(session, "StartCount", Localization.GetText("TerminalStartCountTitle"), Localization.GetText("TerminalStartCountTooltip"), BlockUi.StartCountDown, NotCounting, CanBeArmed);
AddButtonNoAction<T>(session, "StopCount", Localization.GetText("TerminalStopCountTitle"), Localization.GetText("TerminalStopCountTooltip"), BlockUi.StopCountDown, IsCounting, CanBeArmed);
AddCheckboxNoAction<T>(session, "Arm", Localization.GetText("TerminalArmTitle"), Localization.GetText("TerminalArmTooltip"), BlockUi.GetArmed, BlockUi.RequestSetArmed, true, CanBeArmed);
AddCheckboxWarhead<T>(session, "Arm", Localization.GetText("TerminalArmTitle"), Localization.GetText("TerminalArmTooltip"), BlockUi.GetArmed, BlockUi.RequestSetArmed, true, CanBeArmed);
AddButtonNoAction<T>(session, "Trigger", Localization.GetText("TerminalTriggerTitle"), Localization.GetText("TerminalTriggerTooltip"), BlockUi.TriggerCriticalReaction, IsArmed, CanBeArmed);
}

Expand Down Expand Up @@ -239,7 +239,7 @@ internal static bool KeyShootWeapon(IMyTerminalBlock block)
{
var comp = block.Components.Get<CoreComponent>();

return comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon;
return comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon && !comp.HasArming;
}

internal static bool UiRofSlider(IMyTerminalBlock block)
Expand Down Expand Up @@ -353,6 +353,7 @@ internal static bool NotCounting(IMyTerminalBlock block)
var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Data?.Repo != null;
if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip())
return false;
comp.Cube.UpdateTerminalWarhead();

return !comp.Data.Repo.Values.State.CountingDown;
}
Expand Down Expand Up @@ -394,7 +395,7 @@ internal static bool IsFalse(IMyTerminalBlock block)
internal static bool WeaponIsReadyAndSorter(IMyTerminalBlock block)
{
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon && comp.TypeSpecific == CoreComponent.CompTypeSpecific.SorterWeapon && comp.Data?.Repo != null;
var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Type == CoreComponent.CompType.Weapon && comp.TypeSpecific == CoreComponent.CompTypeSpecific.SorterWeapon && comp.Data?.Repo != null && !comp.HasArming;
if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip())
return false;

Expand All @@ -405,7 +406,7 @@ internal static bool WeaponIsReadyAndSorter(IMyTerminalBlock block)
internal static bool IsReady(IMyTerminalBlock block)
{
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Data?.Repo != null;
var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Data?.Repo != null && !comp.HasArming;
if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip())
return false;

Expand Down Expand Up @@ -984,6 +985,22 @@ internal static IMyTerminalControlCheckbox AddCheckboxNoAction<T>(Session sessio

return c;
}
internal static IMyTerminalControlCheckbox AddCheckboxWarhead<T>(Session session, string name, string title, string tooltip, Func<IMyTerminalBlock, bool> getter, Action<IMyTerminalBlock, bool> setter, bool allowGroup, Func<IMyTerminalBlock, bool> visibleGetter = null, bool forceEnable = false) where T : IMyTerminalBlock
{
var c = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlCheckbox, T>("WC_" + name);

c.Title = MyStringId.GetOrCompute(title);
c.Tooltip = MyStringId.GetOrCompute(tooltip);
c.Getter = getter;
c.Setter = setter;
c.Visible = visibleGetter;
c.Enabled = CanBeArmed;

MyAPIGateway.TerminalControls.AddControl<T>(c);
session.CustomControls.Add(c);

return c;
}

internal static IMyTerminalControlOnOffSwitch AddOnOffSwitchNoAction<T>(Session session, string name, string title, string tooltip, Func<IMyTerminalBlock, bool> getter, Action<IMyTerminalBlock, bool> setter, bool allowGroup, Func<IMyTerminalBlock, bool> visibleGetter = null) where T : IMyTerminalBlock
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ internal static void RequestSetArmed(IMyTerminalBlock blk)
Weapon.WeaponComponent.RequestSetValue(comp, "Armed", newValue, Session.I.PlayerId);
}

internal static void TriggerCriticalReaction(IMyTerminalBlock blk)
{
var comp = blk?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready)
return;

Weapon.WeaponComponent.RequestCriticalReaction(comp);
}

internal static void TerminalActionToggleShoot(IMyTerminalBlock blk)
{
var comp = blk?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
Expand Down Expand Up @@ -485,9 +494,9 @@ internal static void ArmWriter(IMyTerminalBlock blk, StringBuilder sb)
var comp = blk.Components.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return;
if (comp.Data.Repo.Values.Set.Overrides.Armed)
sb.Append(Localization.GetText("ActionStateOn"));
sb.Append("Armed");
else
sb.Append(Localization.GetText("ActionStateOff"));
sb.Append("Disarmed");
}

internal static void ShootStateWriter(IMyTerminalBlock blk, StringBuilder sb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ internal static void RequestSetArmed(IMyTerminalBlock block, bool newValue)

var value = newValue ? 1 : 0;
Weapon.WeaponComponent.RequestSetValue(comp, "Armed", value, Session.I.PlayerId);
if (Session.I.IsServer) comp.Cube.UpdateTerminal();
comp.Cube.UpdateTerminalWarhead();
}

internal static void TriggerCriticalReaction(IMyTerminalBlock block)
Expand All @@ -951,15 +951,15 @@ internal static void StartCountDown(IMyTerminalBlock block)
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return;
Weapon.WeaponComponent.RequestCountDown(comp, true);
if (Session.I.IsServer) comp.Cube.UpdateTerminal();
comp.Cube.UpdateTerminalWarhead();
}

internal static void StopCountDown(IMyTerminalBlock block)
{
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return;
Weapon.WeaponComponent.RequestCountDown(comp, false);
if (Session.I.IsServer) comp.Cube.UpdateTerminal();
comp.Cube.UpdateTerminalWarhead();
}

internal static bool ShowCamera(IMyTerminalBlock block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal WeaponComponent(MyEntity coreEntity, MyDefinitionId id)
internal void WeaponInit()
{
var wValues = Data.Repo.Values;
var triggered = wValues.State.Trigger == Trigger.On;
var triggered = wValues.State.Trigger == Trigger.On || wValues.State.Trigger == Trigger.Once;
for (int i = 0; i < Collection.Count; i++)
{
var w = Collection[i];
Expand Down Expand Up @@ -129,6 +129,8 @@ internal void WeaponInit()
}
else if (TypeSpecific == CompTypeSpecific.Phantom)
{
if(triggered)
w.ProtoWeaponAmmo.CurrentAmmo = 1;
Ai.OnlyWeaponComp = w.Comp;
var maxRange = w.Comp.PrimaryWeapon.GetMaxWeaponRange();
if (maxRange > w.Comp.Ai.MaxTargetingRange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void CriticalMonitor()
{
if (--cSet.Overrides.ArmedTimer == 0)
{
CriticalOnDestruction();
CriticalOnDestruction(true);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/Projectiles/ProjectileHits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ internal int GetEntityCompareDist(HitEntity x, HitEntity y, ProInfo info)
{
var posI = hitEnt.Vector3ICache[j];
var firstBlock = grid.GetCubeBlock(posI) as IMySlimBlock;
if (firstBlock != null && firstBlock != lastBlockHit && !firstBlock.IsDestroyed && (hitEnt.Info.Ai.AiType != Ai.AiTypes.Grid || firstBlock != hitEnt.Info.Weapon.Comp.Cube.SlimBlock || ewarWeaponDamage && firstBlock == hitEnt.Info.Weapon.Comp.Cube.SlimBlock))
if (firstBlock != null && firstBlock != lastBlockHit && !firstBlock.IsDestroyed && (hitEnt.Info.Ai.AiType != Ai.AiTypes.Grid || firstBlock != hitEnt.Info.Weapon.Comp.Cube?.SlimBlock || ewarWeaponDamage && firstBlock == hitEnt.Info.Weapon.Comp.Cube?.SlimBlock))
{
lastBlockHit = firstBlock;
hitEnt.Blocks.Add(new HitEntity.RootBlocks {Block = firstBlock, QueryPos = posI});
Expand Down
1 change: 1 addition & 0 deletions Data/Scripts/CoreSystems/Session/SessionControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ internal static void CreateCustomCameraActions<T>(Session session) where T : IMy
internal static void CreateCustomActionSet<T>(Session session) where T : IMyTerminalBlock
{
CreateCustomActions<T>.CreateArmReaction(session);
CreateCustomActions<T>.CreateTriggerNow(session);
CreateCustomActions<T>.CreateShootToggle(session);
CreateCustomActions<T>.CreateShootOn(session);
CreateCustomActions<T>.CreateShootOff(session);
Expand Down
Loading

0 comments on commit c471866

Please sign in to comment.