Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string antennaeKeyword = "laser"; // Keyword to specify which laser antennae are used
- public bool
- setRangeIfNotInfinite = true, // Set range on laser antennae if they're not set to infinite
- preferIdle = true; // Prefer to use idle antennae
- public double rangeMultiplier = 1.1; // Multiply range by this number when setting range (1000 * 1.1 = 1100)
- //
- // ---------- END OF USER SETTINGS ----------
- //
- public List<IMyLaserAntenna> antennae = new List<IMyLaserAntenna>();
- public Program()
- {
- Scan();
- Echo("Known Laser Antennae: " + antennae.Count);
- }
- public void Save() {}
- public void Main(string arg, UpdateType updateSource)
- {
- if (arg != "") Commands(arg);
- Echo("Known Laser Antennae: " + antennae.Count);
- }
- public void Commands(string argument)
- {
- string arg = argument.ToLower();
- if (arg == "scan" || arg == "rescan" || arg == "find" || arg == "look") Scan();
- else if (arg.StartsWith("gps:") && arg.EndsWith(":"))
- {
- if (antennae.Count > 0) SetTarget(argument);
- else Echo("No antennae found");
- }
- }
- public void SetTarget(string argument)
- {
- try {
- string subArg = argument.Substring(argument.IndexOf(":") + 1), name = "", X = "", Y = "", Z = "";
- string[] argArray = subArg.Split(':');
- name = argArray[0];
- X = argArray[1];
- Y = argArray[2];
- Z = argArray[3];
- Vector3D targetVector = new Vector3D(double.Parse(X), double.Parse(Y), double.Parse(Z));
- int closestIndex = 0, closestIdleIndex = -1;
- double closestDistance = Vector3D.Distance(targetVector, antennae[0].GetPosition()), closestIdleDistance = double.MaxValue, nextDistance = 0;
- if (preferIdle && antennae[0].Status == MyLaserAntennaStatus.Idle)
- {
- closestIdleIndex = 0;
- closestIdleDistance = closestDistance;
- }
- for (int i = 1; i < antennae.Count; i++)
- {
- nextDistance = Vector3D.Distance(targetVector, antennae[i].GetPosition());
- if (nextDistance < closestDistance)
- {
- closestDistance = nextDistance;
- closestIndex = i;
- }
- if (preferIdle && nextDistance < closestIdleDistance && antennae[i].Status == MyLaserAntennaStatus.Idle)
- {
- closestIdleDistance = nextDistance;
- closestIdleIndex = i;
- }
- }
- if (preferIdle && closestIdleIndex != -1) closestIndex = closestIdleIndex;
- if (setRangeIfNotInfinite && antennae[closestIndex].Range < 100000000f) antennae[closestIndex].Range = (float)(closestDistance * rangeMultiplier);
- antennae[closestIndex].SetTargetCoords(argument);
- antennae[closestIndex].Connect();
- Echo("Setting Target For: " + name + " At: (" + X + ", " + Y + ", " + Z + ")");
- } catch { Echo("Error setting target to: " + argument); }
- }
- public void Scan()
- {
- GridTerminalSystem.GetBlocksOfType<IMyLaserAntenna>(antennae, a => a.IsWorking && a.CustomName.ToLower().Contains(antennaeKeyword.ToLower()));
- if (antennae.Count == 0) GridTerminalSystem.GetBlocksOfType<IMyLaserAntenna>(antennae, a => a.IsWorking);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement