Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed class AdvAntenna
- {
- public IMyRadioAntenna Antenna { get; private set; }
- public int DatagramsStored => Antenna.GetValue<int>("DatagramsStored");
- public bool AllowReceive
- {
- get { return Antenna.GetValueBool("AllowReceive"); }
- set { Antenna.SetValueBool("AllowReceive", value); }
- }
- public AdvAntenna(IMyRadioAntenna Antenna)
- {
- this.Antenna = Antenna;
- }
- public void Broadcast(string Datagram)
- {
- var Broadcast = Antenna.GetValue<Action<string>>("Broadcast");
- Broadcast(Datagram);
- }
- public void Send(string Datagram, string Protocol)
- {
- var Send = Antenna.GetValue<Action<string, string>>("Send");
- Send(Datagram, Protocol);
- }
- public void AllowProtocol(string Protocol)
- {
- var AllowProtocol = Antenna.GetValue<Action<string>>("AllowProtocol");
- AllowProtocol(Protocol);
- }
- public void DisallowProtocol(string Protocol)
- {
- var DisallowProtocol = Antenna.GetValue<Action<string>>("DisallowProtocol");
- DisallowProtocol(Protocol);
- }
- public void ClearProtocols()
- {
- var ClearProtocols = Antenna.GetValue<Action>("ClearProtocolList");
- ClearProtocols();
- }
- public string ReadFirstDatagram()
- {
- var ReadFirstDatagram = Antenna.GetValue<Func<string>>("ReadFirstDatagram");
- return ReadFirstDatagram();
- }
- public string ReadFirstDatagram(string Protocol)
- {
- var ReadFirstDatagram = Antenna.GetValue<Func<string, string>>("ReadFirstDatagramByProtocol");
- return ReadFirstDatagram(Protocol);
- }
- public void ClearDatagrams()
- {
- var ClearDatagramStorage = Antenna.GetValue<Action>("ClearDatagramStorage");
- ClearDatagramStorage();
- }
- public bool AnyDatagrams(string Protocol)
- {
- var AnyDatagrams = Antenna.GetValue<Func<string, bool>>("AnyDatagrams");
- return AnyDatagrams(Protocol);
- }
- public bool AnyDatagrams()
- {
- return DatagramsStored > 0;
- }
- }
- sealed class AdvRemote
- {
- public IMyRemoteControl RCBlock { get; private set; }
- public bool Enabled
- {
- get { return RCBlock.IsAutoPilotEnabled; }
- set { RCBlock.SetAutoPilotEnabled(value); }
- }
- public bool CollisionAvoidance
- {
- get { return RCBlock.GetValueBool("CollisionAvoidance"); }
- set { RCBlock.SetValueBool("CollisionAvoidance", value); }
- }
- public float SpeedLimit
- {
- get { return RCBlock.GetValueFloat("SpeedLimit"); }
- set { RCBlock.SetValueFloat("SpeedLimit", value); }
- }
- /// <summary>
- /// Note that this acquires the list of waypoints for Advanced Autopilot.
- /// </summary>
- public List<Vector3D> Waypoints => RCBlock.GetValue<List<Vector3D>>("AdvAutopilotListWP");
- public enum FlightModes : int
- {
- OneWay = 2,
- Circle = 1,
- Patrol = 0
- }
- public FlightModes FlightMode
- {
- get { return (FlightModes)RCBlock.GetValue<long>("FlightMode"); }
- set { RCBlock.SetValue<long>("FlightMode", (int)value); }
- }
- public AdvRemote(IMyRemoteControl RCBlock)
- {
- this.RCBlock = RCBlock;
- }
- /// <summary>
- /// Adds waypoint for the Advanced Autopilot.
- /// </summary>
- public void AddWaypoint(Vector3D Waypoint)
- {
- var AddWP = RCBlock.GetValue<Action<Vector3D>>("AdvAutopilotAddWP");
- AddWP(Waypoint);
- }
- /// <summary>
- /// Attention! If you aren't going to add a new waypoint immediately after clearing, disable the autopilot.
- /// <para/>
- /// Otherwise, the ship may start spinning uncontrollably due to a bug in the game itself.
- /// </summary>
- public void ClearWaypoints(bool DisableAutopilot = true)
- {
- if (DisableAutopilot) Enabled = false;
- var ClearWP = RCBlock.GetValue<Action>("AdvAutopilotClearWP");
- ClearWP();
- }
- public void Enable() { Enabled = true; }
- public void Disable() { Enabled = false; }
- }
- sealed class AdvTurret
- {
- public IMyLargeTurretBase TurretBlock { get; private set; }
- public bool Enabled
- {
- get { return TurretBlock.Enabled; }
- set { TurretBlock.Enabled = value; }
- }
- public AdvTurret(IMyLargeTurretBase TurretBlock)
- {
- this.TurretBlock = TurretBlock;
- }
- public MyDetectedEntityInfo Target => TurretBlock.GetValue<MyDetectedEntityInfo>("CurrentTarget");
- public bool TrackTarget(MyDetectedEntityInfo Target, long SubtargetEntityID)
- {
- var Track = TurretBlock.GetValue<Func<MyDetectedEntityInfo, long, bool>>("TrackSubtarget");
- return Track(Target, SubtargetEntityID);
- }
- public bool TrackTarget(MyDetectedEntityInfo Target)
- {
- var Track = TurretBlock.GetValue<Func<MyDetectedEntityInfo, bool>>("TrackTarget");
- return Track(Target);
- }
- }
- sealed class IMyRadar
- {
- public IMyUpgradeModule RadarBlock { get; private set; }
- public Vector3D Position { get; private set; }
- public HashSet<MyDetectedEntityInfo> RadarData => RadarBlock.GetValue<HashSet<MyDetectedEntityInfo>>("RadarData");
- public bool Enabled
- {
- get { return RadarBlock.Enabled; }
- set { RadarBlock.Enabled = value; }
- }
- public int RadarPower
- {
- get { return (int)RadarBlock.GetValueFloat("RadarPower"); }
- set { RadarBlock.SetValueFloat("RadarPower", value); }
- }
- public int MaxRadarPower => (int)RadarBlock.GetProperty("RadarPower").AsFloat().GetMaximum(RadarBlock);
- public bool ActiveMode
- {
- get { return RadarBlock.GetValueBool("ActiveMode"); }
- set { RadarBlock.SetValueBool("ActiveMode", value); }
- }
- public IMyRadar(IMyTerminalBlock RadarBlock)
- {
- this.RadarBlock = RadarBlock as IMyUpgradeModule;
- if (this.RadarBlock == null) throw new ArgumentNullException("Radar(): Block is not valid");
- if (this.RadarBlock.GetValue<HashSet<MyDetectedEntityInfo>>("RadarData") == null) throw new ArgumentException("Radar(): supplied block isn't a Radar");
- }
- public bool CanScan(MyDetectedEntityInfo Target)
- {
- var CanScanFunc = RadarBlock.GetValue<Func<MyDetectedEntityInfo, bool>>("CanScan");
- if (CanScanFunc == null) return false;
- return CanScanFunc(Target);
- }
- public List<TargetBlock> ScanTarget(MyDetectedEntityInfo Target)
- {
- var SerializedData = RadarBlock.GetValue<Func<MyDetectedEntityInfo, List<Dictionary<string, string>>>>("ScanTarget")(Target);
- if (SerializedData == null) return null;
- List<TargetBlock> retval = new List<TargetBlock>();
- foreach (var Data in SerializedData) retval.Add(new TargetBlock(Data));
- return retval;
- }
- public class TargetBlock
- {
- public readonly string TypeID;
- public readonly string SubtypeID;
- public readonly long EntityID;
- public readonly long GridID;
- public readonly bool? Enabled;
- public readonly bool Functional;
- public readonly Vector3D WorldPosition;
- public readonly long OwnerID;
- public readonly bool Accessible;
- public TargetBlock(Dictionary<string, string> SerializedData)
- {
- TypeID = SerializedData["Type"];
- SubtypeID = SerializedData["Subtype"];
- EntityID = long.Parse(SerializedData["EntityID"]);
- GridID = long.Parse(SerializedData["Grid"]);
- string enabled = SerializedData["Enabled"];
- if (enabled == "True") Enabled = true;
- if (enabled == "False") Enabled = false;
- if (enabled == "null") Enabled = null;
- Functional = bool.Parse(SerializedData["Functional"]);
- Vector3D.TryParse(SerializedData["WorldPosition"], out WorldPosition);
- OwnerID = long.Parse(SerializedData["OwnerID"]);
- Accessible = bool.Parse(SerializedData["Accessible"]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement