Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double timeToResetTurretsInSeconds = 10;
- public int turretsToResetPerTick = 5;
- public bool disableIdleRotation = true;
- // ----------- END OF USER SETTINGS -----------
- public List<IMyLargeTurretBase> turrets = new List<IMyLargeTurretBase>();
- public TimeSpan
- getTurretTime = new TimeSpan(0, 0, 0),
- resetTurretTime = new TimeSpan(0, 0, 0);
- public bool resettingTurrets = false;
- public int currentTurretIndex = 0, checkingMode = 0, activeTurretCount = 0;
- public Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update10;
- GetTurrets();
- }
- public void Save()
- {
- }
- public void Main(string argument, UpdateType updateSource)
- {
- try {
- string pluralA = "", pluralB = "es", pluralC = "", pluralD = "s";
- if (turrets.Count > 1) {
- pluralA = "s";
- pluralB = "";
- }
- if (activeTurretCount > 1) {
- pluralC = "s";
- pluralD = "ve";
- }
- if (getTurretTime.TotalSeconds >= 30.0) GetTurrets();
- else
- {
- TimeSpan timeSinceLastRun = Runtime.TimeSinceLastRun;
- getTurretTime += timeSinceLastRun;
- switch (checkingMode)
- {
- case 0:
- resettingTurrets = ResetTurrets();
- if (!resettingTurrets) {
- Echo(activeTurretCount + " Turret" + pluralC + " ha" + pluralD + " active target");
- currentTurretIndex = 0;
- resetTurretTime = new TimeSpan(0, 0, 0);
- }
- else if (turrets.Count > 0) {
- Echo(turrets.Count + " Turret" + pluralA + " do" + pluralB + " not have active target");
- if (resetTurretTime.TotalSeconds >= timeToResetTurretsInSeconds) checkingMode = 1;
- else resetTurretTime += timeSinceLastRun;
- if (resetTurretTime.TotalSeconds < timeToResetTurretsInSeconds)
- Echo("Time until reset: " + (timeToResetTurretsInSeconds - resetTurretTime.TotalSeconds).ToString("N1") + "s");
- else Echo("Resetting " + currentTurretIndex + "/" + turrets.Count + " turret" + pluralA);
- }
- break;
- case 1:
- Echo(turrets.Count + " Turret" + pluralA + " do" + pluralB + " not have active target");
- Echo("Resetting " + currentTurretIndex + "/" + turrets.Count + " turret" + pluralA);
- if (disableIdleRotation) Echo("Disabling idle rotation");
- else Echo("Not disabling idle rotation");
- ZeroTurrets();
- checkingMode = 0;
- break;
- }
- }
- } catch { Echo("Error Caught In Main"); }
- }
- public void ZeroTurrets()
- {
- int reps = 0;
- for (int i = currentTurretIndex; i < turrets.Count; i++)
- {
- try
- {
- if (!turrets[i].IsUnderControl)
- {
- if (disableIdleRotation)
- {
- turrets[i].EnableIdleRotation = false;
- turrets[i].SyncEnableIdleRotation();
- }
- turrets[i].Azimuth = 0f;
- turrets[i].Elevation = 0f;
- turrets[i].SyncElevation();
- turrets[i].SyncAzimuth();
- }
- } catch { }
- reps++;
- currentTurretIndex++;
- if (reps >= turretsToResetPerTick) break;
- }
- if (currentTurretIndex >= turrets.Count)
- {
- currentTurretIndex = 0;
- resetTurretTime = new TimeSpan(0, 0, 0);
- }
- }
- public bool ResetTurrets()
- {
- List<IMyLargeTurretBase> tempTurrets = new List<IMyLargeTurretBase>();
- GridTerminalSystem.GetBlocksOfType<IMyLargeTurretBase>(tempTurrets, t => ((IMyLargeTurretBase)t).HasTarget);
- activeTurretCount = tempTurrets.Count;
- return activeTurretCount == 0;
- }
- public void GetTurrets()
- {
- getTurretTime = new TimeSpan(0, 0, 0);
- GridTerminalSystem.GetBlocksOfType<IMyLargeTurretBase>(turrets);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement