Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const string cockpitName = "Cockpit"; // Drivers Cockpit Name.
- const string remotecontrolName = "Remote Control";
- const string headLight = "Head light"; // Head Light Name.
- const string brakeLight = "Brake light"; // Brake Light Name.
- const string leftIndicator = "Left Indicator"; // Left Indicator Name.
- const string rightIndicator = "Right Indicator"; // Right Indicator Name.
- const string reverseLight = "ReverseLight"; // Reverse Light Name.
- const string speedometer = "Speedometer"; // LCD to display a speedometer on your vehicle. This will be in meters per second.
- // Maximum speed before turn indicators stop turning on.
- int indicatorSpeed = 10; // this is in m/s
- // Let Program use other grids?
- bool useSubGrid = false;
- List<IMyTerminalBlock> allCockpit = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> allRemoteControl = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> allLights = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> allLcd = new List<IMyTerminalBlock>();
- Vector3D position = new Vector3D(0,0,0);
- Vector3 WASDControl;
- public Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update10;
- }
- void Main()
- {
- if (useSubGrid == true)
- {
- GridTerminalSystem.GetBlocksOfType<IMyCockpit>(allCockpit);
- GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(allRemoteControl);
- GridTerminalSystem.GetBlocksOfType<IMyLightingBlock>(allLights);
- GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(allLcd);
- }
- else if (useSubGrid == false)
- {
- GridTerminalSystem.GetBlocksOfType<IMyCockpit>(allCockpit, b => b.CubeGrid == Me.CubeGrid);
- GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(allRemoteControl, b => b.CubeGrid == Me.CubeGrid);
- GridTerminalSystem.GetBlocksOfType<IMyLightingBlock>(allLights, b => b.CubeGrid == Me.CubeGrid);
- GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(allLcd, b => b.CubeGrid == Me.CubeGrid);
- }
- bool handBrake = false;
- bool lightsOn = false;
- double mySpeed = get_speed();
- StringBuilder outputSpeed = new StringBuilder();
- outputSpeed.Append("Speed: \n" + mySpeed.ToString() + " m/s");
- foreach(IMyTextPanel lcd in allLcd)
- {
- if (lcd.CustomName.Contains(speedometer))
- {
- lcd.WritePublicText(outputSpeed.ToString());
- lcd.ShowPublicTextOnScreen();
- }
- }
- foreach(IMyCockpit cockpit in allCockpit)
- {
- if (cockpit.CustomName.Contains(cockpitName))
- {
- handBrake = cockpit.GetValue<bool>("HandBrake");
- WASDControl = cockpit.MoveIndicator;
- }
- /*********
- A => X:-1
- D => X: 1
- C => Y:-1
- Sp => Y: 1
- W => Z:-1
- S => Z: 1
- **********/
- }
- foreach(IMyRemoteControl remotecontrol in allRemoteControl)
- {
- if (remotecontrol.CustomName.Contains(remotecontrolName))
- {
- handBrake = remotecontrol.GetValue<bool>("HandBrake");
- WASDControl = remotecontrol.MoveIndicator;
- }
- /*********
- A => X:-1
- D => X: 1
- C => Y:-1
- Sp => Y: 1
- W => Z:-1
- S => Z: 1
- **********/
- }
- foreach (IMyLightingBlock light in allLights)
- {
- if (light.CustomName.Contains(headLight))
- {
- lightsOn = light.GetValue<bool>("OnOff");
- }
- }
- foreach (IMyLightingBlock light in allLights)
- {
- if (light.CustomName.Contains(leftIndicator) || light.CustomName.Contains(rightIndicator))
- {
- light.SetValue("Color", new Color(255, 255, 0));
- light.SetValue("Blink Interval", Convert.ToSingle(1));
- light.SetValue("Blink Lenght", Convert.ToSingle(20));
- }
- if (light.CustomName.Contains(brakeLight))
- {
- light.SetValue("Color", new Color(255, 0, 0));
- }
- if (mySpeed < indicatorSpeed)
- {
- if (WASDControl.X < 0)
- {
- if (light.CustomName.Contains(leftIndicator))
- {
- light.ApplyAction("OnOff_On");
- }
- else if (light.CustomName.Contains(rightIndicator))
- {
- light.ApplyAction("OnOff_Off");
- }
- }
- if (WASDControl.X > 0)
- {
- if (light.CustomName.Contains(rightIndicator))
- {
- light.ApplyAction("OnOff_On");
- }
- else if (light.CustomName.Contains(leftIndicator))
- {
- light.ApplyAction("OnOff_Off");
- }
- }
- }
- if (light.CustomName.Contains(leftIndicator) || light.CustomName.Contains(rightIndicator))
- {
- if (WASDControl.X == 0)
- {
- light.ApplyAction("OnOff_Off");
- }
- else if (mySpeed >= indicatorSpeed)
- {
- light.ApplyAction("OnOff_Off");
- }
- }
- if (light.CustomName.Contains(reverseLight))
- {
- light.SetValue("Color", new Color(255, 255, 255));
- light.SetValue("Intensity", Convert.ToSingle(5));
- light.SetValue("Radius", Convert.ToSingle(3));
- if (mySpeed > 0 && WASDControl.Z > 0)
- {
- light.ApplyAction("OnOff_On");
- }
- else
- {
- light.ApplyAction("OnOff_Off");
- }
- }
- if (light.CustomName.Contains(brakeLight))
- {
- if (handBrake == true && lightsOn == false)
- {
- light.ApplyAction("OnOff_On");
- light.SetValue("Intensity", Convert.ToSingle(5));
- light.SetValue("Radius", Convert.ToSingle(3));
- }
- else if (handBrake == true && lightsOn == true)
- {
- light.ApplyAction("OnOff_On");
- light.SetValue("Intensity", Convert.ToSingle(5));
- light.SetValue("Radius", Convert.ToSingle(3));
- }
- else if (handBrake == false && lightsOn == false)
- {
- if(WASDControl.Y > 0)//Press space
- {
- light.ApplyAction("OnOff_On");
- light.SetValue("Intensity", Convert.ToSingle(5));
- light.SetValue("Radius", Convert.ToSingle(3));
- }
- else //Space is free
- {
- light.ApplyAction("OnOff_Off");
- light.SetValue("Intensity", Convert.ToSingle(0));
- light.SetValue("Radius", Convert.ToSingle(0));
- }
- }
- else if (handBrake == false && lightsOn == true)
- {
- if(WASDControl.Y > 0)//Press space
- {
- light.ApplyAction("OnOff_On");
- light.SetValue("Intensity", Convert.ToSingle(5));
- light.SetValue("Radius", Convert.ToSingle(3));
- }
- else//Space is free
- {
- light.ApplyAction("OnOff_On");
- light.SetValue("Intensity", Convert.ToSingle(1));
- light.SetValue("Radius", Convert.ToSingle(2));
- }
- }
- }
- }
- allCockpit.Clear();
- allRemoteControl.Clear();
- allLights.Clear();
- }
- double get_speed()
- {
- Vector3D current_position = Me.GetPosition(); // the position of this programmable block
- double speed = ((current_position-position)*6).Length();
- // double speed = (((current_position-position)*60)*60/1000).Length(); // KMH
- // double speed = ((current_position-position)*60).Length(); // M/H
- // double speed = ((current_position-position)*6).Length(); // M/S
- position = current_position; // update the global variable, which will be used on the next run
- speed = Math.Round(speed,0);
- return speed;
- }
Advertisement
Add Comment
Please, Sign In to add comment