Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/StarCoreSE/TLB
Browse files Browse the repository at this point in the history
  • Loading branch information
xianson committed Jun 28, 2024
2 parents 82c3e27 + 6e2f6c0 commit 876ce0c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
80 changes: 80 additions & 0 deletions SkyPiratesAntennaAlwaysOn/Data/Scripts/AlwaysOn/Core.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Sandbox.Common.ObjectBuilders;
using Sandbox.ModAPI;
using Sandbox.ModAPI.Interfaces.Terminal;
using System.Collections.Generic;
using VRage.Game.Components;
using VRage.ModAPI;
using VRage.ObjectBuilders;


namespace AntennaAlwaysOn
{
[MyEntityComponentDescriptor(typeof(MyObjectBuilder_RadioAntenna), true)]
public class Core : MyGameLogicComponent
{
public const float rangeSmallGrid = 1000f;
public const float rangeLargeGrid = 3000f;

private IMyRadioAntenna beacon;


public override void Init(MyObjectBuilder_EntityBase objectBuilder)
{
beacon = Entity as IMyRadioAntenna;
if (beacon.Radius < rangeSmallGrid)
beacon.Radius = rangeSmallGrid;

NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
}

/// <summary>
/// Avoid crashes when block is removed by stopping any posible action
/// </summary>
public override void Close()
{
NeedsUpdate = MyEntityUpdateEnum.NONE;
}

/// <summary>
/// sets range minimums
/// </summary>
public override void UpdateBeforeSimulation()
{
if (!MyAPIGateway.Utilities.IsDedicated)
{
List<IMyTerminalControl> controls;
MyAPIGateway.TerminalControls.GetControls<IMyRadioAntenna>(out controls);

foreach (IMyTerminalControl control in controls)
{
if (control.Id == "Radius")
{
if (beacon.CubeGrid.GridSizeEnum == VRage.Game.MyCubeSize.Small)
{
((IMyTerminalControlSlider)control).SetLimits(rangeSmallGrid, 50000f);
}
else if (beacon.CubeGrid.GridSizeEnum == VRage.Game.MyCubeSize.Large)
{
((IMyTerminalControlSlider)control).SetLimits(rangeLargeGrid, 50000f);
}

// stop running this logic but keep the always on check.
NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME;
break;
}
}
}
}

/// <summary>
/// forces the beacon to always be on
/// </summary>
public override void UpdateBeforeSimulation100()
{
if (MyAPIGateway.Multiplayer.IsServer)
{
beacon.Enabled = true;
}
}
}
}
4 changes: 4 additions & 0 deletions SkyPiratesAntennaAlwaysOn/metadata.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ModVersion>1.0</ModVersion>
</ModMetadata>

0 comments on commit 876ce0c

Please sign in to comment.