-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/StarCoreSE/TLB
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |