Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double CruiseControlSpeed = 50;
- IMyTextPanel lcd;
- IMyTextPanel statusLCD;
- IMyTextPanel fancyLCD;
- int lightState = 0;
- double targetAccel = 0;
- bool prevState = false;
- bool done2 = false;
- bool CruiseControl = false;
- IMyShipController shipController = null;
- Color colorOff = new Color(0, 0, 0);
- Color colorOn = new Color(255,255,255);
- Color colorRear = new Color(100,0,0,255);
- Color colorYel = new Color(175,175,100,255);
- public void Main(string argument)
- {
- if (argument == "+5" && CruiseControlSpeed <= 95)
- {
- CruiseControlSpeed = CruiseControlSpeed + 5;
- }
- if (argument == "-5" && CruiseControlSpeed >= 15)
- {
- CruiseControlSpeed = CruiseControlSpeed - 5;
- }
- if (argument == "CC")
- {
- if (CruiseControl == false)
- {
- CruiseControl = true;
- }
- else
- {
- CruiseControl = false;
- }
- }
- shipController = GridTerminalSystem?.GetBlockWithName("shipController") as IMyShipController;
- if (shipController == null) //// error check
- {
- Echo("Aww shit! Aint no damn ship controllers yo!");
- return; //stops running the code
- }
- var hdg = shipController.MoveIndicator;
- lcd = GridTerminalSystem.GetBlockWithName("Speed Out") as IMyTextPanel;
- statusLCD = GridTerminalSystem.GetBlockWithName("Status LCD") as IMyTextPanel;
- lcd?.WritePublicText(""); //// added quesion marks
- var ToggledLights = GridTerminalSystem.GetBlockGroupWithName("LTOGGLE");
- var Toggled = new List<IMyInteriorLight>();
- ToggledLights?.GetBlocksOfType(Toggled);
- var RearLights = GridTerminalSystem.GetBlockGroupWithName("REAR");
- var RedLights = new List<IMyInteriorLight>();
- RearLights?.GetBlocksOfType(RedLights);
- var YellowLights = GridTerminalSystem.GetBlockGroupWithName("YEL");
- var YelLights = new List<IMyInteriorLight>();
- YellowLights?.GetBlocksOfType(YelLights);
- var BrekLights = GridTerminalSystem.GetBlockGroupWithName("BRK");
- var BRKLights = new List<IMyInteriorLight>();
- BrekLights?.GetBlocksOfType(BRKLights);
- ////Never differentiate variables by case. They should be descriptive
- //"wheels" should be something like "wheelGroup"
- //"Wheels" should then be named "wheels". Only methods start capital
- var wheelGroup = GridTerminalSystem.GetBlockGroupWithName("Wheels");
- var wheels = new List<IMyMotorSuspension>();
- wheelGroup?.GetBlocksOfType(wheels);
- var wheelStabilityGroup = GridTerminalSystem.GetBlockGroupWithName("WheelsExtend");
- var wheelStabilizers = new List<IMyMotorSuspension>();
- wheelStabilityGroup?.GetBlocksOfType(wheelStabilizers);
- ////
- /*
- question mark is a null check
- Means the same as:
- if (wheelGroup != null)
- wheelGroup.GetBlocksOfType(wheels);
- */
- PrintSpeed(shipController.GetShipSpeed());
- IMyReflectorLight spotlight = GridTerminalSystem.GetBlockWithName("Spotlight R") as IMyReflectorLight;
- if (spotlight.Enabled != prevState && spotlight != null) ////null check
- {
- lightState = lightState + 1;
- if (lightState > 2)
- {
- lightState = 0;
- }
- prevState = spotlight.Enabled;
- }
- if (lightState == 0)
- {
- foreach (IMyInteriorLight light in Toggled)
- light.SetValue("Color", colorOff);
- }
- foreach (IMyInteriorLight light in RedLights)
- {
- light.SetValue("Color", colorOff);
- }
- foreach (IMyInteriorLight light in YelLights)
- {
- light.SetValue("Color", colorYel);
- }
- IMyReflectorLight spotlight2 = GridTerminalSystem.GetBlockWithName("Spotlight") as IMyReflectorLight;
- spotlight2?.SetValue("Color", colorOff); ////null check
- statusLCD?.WritePublicText("LIGHTS Off"); ////null check
- }
- else if (lightState == 1)
- {
- foreach (IMyInteriorLight light in Toggled)
- {
- light.SetValue("Color", colorOn);
- }
- foreach (IMyInteriorLight light in RedLights)
- {
- light.SetValue("Color", colorYel);
- }
- foreach (IMyInteriorLight light in YelLights)
- {
- light.SetValue("Color", colorOn);
- }
- statusLCD?.WritePublicText("LIGHTS Low Beam"); ////null check
- }
- else if (lightState == 2)
- {
- IMyReflectorLight spotlight2 = GridTerminalSystem.GetBlockWithName("Spotlight") as IMyReflectorLight;
- spotlight2?.SetValue("Color", colorOn); ////null check
- statusLCD?.WritePublicText("LIGHTS High Beam"); ////null check
- }
- if (hdg.Z == -1 && done2 == false)
- {
- foreach(IMyMotorSuspension wheel in wheels)
- wheel.SetValue("Height", 40f); ////fixed single sillyness
- done2 = true;
- }
- else if (hdg.Z == 1 && done2 == false)
- {
- foreach(IMyMotorSuspension wheel in wheels)
- wheel.SetValue("Height", -30f); ////fixed single sillyness
- done2 = true;
- }
- else
- {
- done2 = false;
- }
- if(!shipController.HandBrake || CruiseControl == true)
- {
- foreach(IMyMotorSuspension wheel in wheels)
- wheel.SetValue("Friction", 0f); ////fixed single sillyness
- foreach (IMyInteriorLight light in BRKLights)
- light.SetValue("Color", colorOff);
- }
- else
- {
- foreach(IMyMotorSuspension wheel in wheels)
- wheel.SetValue("Friction", 40f); ////fixed single sillyness
- foreach (IMyInteriorLight light in BRKLights)
- light.SetValue("Color", colorRear);
- }
- if (shipController.GetShipSpeed() > 45)
- {
- foreach (IMyMotorSuspension wheel in wheelStabilizers)
- {
- var a = Single.Parse("40");
- wheel.SetValue("Height", a);
- }
- statusLCD.WritePublicText("\nSTABILITY Active\n", true);
- }
- else
- {
- foreach (IMyMotorSuspension wheel in wheelStabilizers)
- {
- var a = Single.Parse("-30");
- wheel.SetValue("Height", a);
- }
- statusLCD.WritePublicText("\nSTABILITY Inactive\n", true);
- }
- statusLCD.WritePublicText("Cruise Speed: " + CruiseControlSpeed.ToString(), true);
- if (CruiseControl == true)
- {
- var AccelThrusterGroup = GridTerminalSystem.GetBlockGroupWithName("ACL");
- var Accelerators = new List<IMyThrust>();
- AccelThrusterGroup.GetBlocksOfType(Accelerators);
- statusLCD.WritePublicText(" ACTIVE", true);
- if (!shipController.DampenersOverride)
- {
- shipController.ApplyAction("DampenersOverride");
- }
- lcd.WritePublicText(" CRUISE", true);
- if (shipController.GetShipSpeed() > CruiseControlSpeed)
- {
- var val = Single.Parse("40");
- foreach(IMyMotorSuspension wheel in wheels)
- {
- wheel.SetValue("Friction", val);
- }
- foreach(IMyThrust thruster in Accelerators)
- {
- var thrustPower = Single.Parse("0");
- thruster.SetValue("Override", thrustPower);
- }
- }
- else
- {
- targetAccel = (CruiseControlSpeed - shipController.GetShipSpeed()) * 100;
- foreach(IMyThrust thruster in Accelerators)
- thruster.SetValue("Override", (float)targetAccel); ////Got rid of the single sillyness
- }
- }
- else
- {
- var AccelThrusterGroup = GridTerminalSystem.GetBlockGroupWithName("ACL");
- var Accelerators = new List<IMyThrust>();
- AccelThrusterGroup.GetBlocksOfType(Accelerators);
- foreach(IMyThrust thruster in Accelerators)
- thruster.SetValue("Override", 0f); ////Got rid of the single sillyness
- }
- Echo($"Current Inst: {Runtime.CurrentInstructionCount}\nMax Inst:{Runtime.MaxInstructionCount}");
- fancyLCD = GridTerminalSystem.GetBlockWithName("Left Center LCD") as IMyTextPanel;
- fancyLCD?.WritePublicText(" Systems ONLINE\n ELEKTRON Speed Display Active\n ZIVATAR Ready to drive"); ////added question mark
- }
- // My Random Crap
- static char rgb(byte r, byte g, byte b)
- {
- return (char)(0xe100 + (r << 6) + (g << 3) + b);
- }
- void PrintSpeed(double spd)
- {
- //ONLY CALL WRITEPUBLICTEXT() ONCE!!!!!11!!!1!!
- string line = new string(rgb(7, 0, 0), 20);
- string speedFill = new string(rgb(7, 7, 0), (int)(spd / 5));
- lcd.WritePublicText($"{line}\n{speedFill}\n{line}\nSpeed: {spd:N2} m/s");
- if (!shipController.DampenersOverride)
- {
- lcd?.WritePublicText(" DAMP OFF", true); ////added question mark
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment