Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double
- minimumSpeed = 33;
- public string timerKeyword = "control"; // Put into Custom Data of a timer you want triggered
- public bool triggerTimer = true;
- /**
- ---------- END OF USER SETTINGS ----------
- **/
- public Vector3D currentOverride = new Vector3D(0, 0, 0);
- public IMyShipController controller;
- public IMyTimerBlock timer;
- public List<IMyGyro> gyroList = new List<IMyGyro>();
- public bool idle = true, appliedOverride = false, triggeredTimer = false;
- public Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update10;
- Change();
- GridTerminalSystem.GetBlocksOfType<IMyGyro>(gyroList);
- List<IMyTimerBlock> timerList = new List<IMyTimerBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyTimerBlock>(timerList, b => b.CustomData.ToLower().Contains(timerKeyword.ToLower()));
- if (timerList.Count > 0) timer = timerList[0];
- }
- public void Save() { }
- public void Main(string argument, UpdateType updateSource)
- {
- try
- {
- if (controller == null) GetController();
- else
- {
- double currentSpeed = controller.GetShipSpeed();
- if (idle && currentSpeed >= minimumSpeed) idle = false;
- if (currentSpeed >= minimumSpeed && appliedOverride) StopOverride();
- else if (!idle && currentSpeed < minimumSpeed && !appliedOverride) Uncontrol();
- }
- }
- catch { Echo("Error caught in main"); }
- }
- public void Uncontrol()
- {
- if (!triggeredTimer && triggerTimer)
- {
- triggeredTimer = true;
- try {
- if (timer != null) timer.Trigger();
- } catch { }
- }
- ApplyGyroOverride();
- appliedOverride = true;
- }
- public void Change()
- {
- int reps = 0;
- Random rnd = new Random();
- while (reps < 10 && (Math.Abs(currentOverride.X) < Math.PI * 0.05 || Math.Abs(currentOverride.Y) < Math.PI * 0.05 || Math.Abs(currentOverride.Z) < Math.PI * 0.05))
- {
- currentOverride = new Vector3D(Math.PI * ((double)rnd.Next(-1000, 1000) / 1000.0), Math.PI * ((double)rnd.Next(-1000, 1000) / 1000.0), Math.PI * ((double)rnd.Next(-1000, 1000) / 1000.0));
- reps++;
- }
- }
- public void StopOverride()
- {
- appliedOverride = false;
- triggeredTimer = false;
- for (int i = 0; i < gyroList.Count; i++)
- {
- try
- {
- gyroList[i].Pitch = 0f;
- gyroList[i].Yaw = 0f;
- gyroList[i].Roll = 0f;
- gyroList[i].GyroOverride = false;
- } catch { }
- }
- }
- //Whip's ApplyGyroOverride Method v9 - 8/19/17
- public void ApplyGyroOverride()
- {
- MatrixD refMatrix = controller.WorldMatrix;
- var rotationVec = new Vector3D(-currentOverride.X, currentOverride.Y, currentOverride.Z); //because keen does some weird stuff with signs
- var relativeRotationVec = Vector3D.TransformNormal(rotationVec, refMatrix);
- for (int i = 0; i < gyroList.Count; i++)
- {
- try {
- var gyroMatrix = gyroList[i].WorldMatrix;
- var transformedRotationVec = Vector3D.TransformNormal(relativeRotationVec, Matrix.Transpose(gyroMatrix));
- gyroList[i].GyroOverride = true;
- gyroList[i].Pitch = (float)transformedRotationVec.X;
- gyroList[i].Yaw = (float)transformedRotationVec.Y;
- gyroList[i].Roll = (float)transformedRotationVec.Z;
- } catch { }
- }
- }
- public void GetController()
- {
- List<IMyShipController> controllerList = new List<IMyShipController>();
- GridTerminalSystem.GetBlocksOfType<IMyShipController>(controllerList);
- if (controllerList.Count > 0) controller = controllerList[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement