Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string thrustPanelKeyword = "thrust";
- public float
- largeGridSmallIon = 345600,
- largeGridLargeIon = 4320000,
- smallGridSmallIon = 14400,
- smallGridLargeIon = 172800,
- largeGridSmallHydro = 920000,
- largeGridLargeHydro = 8200000,
- smallGridSmallHydro = 88000,
- smallGridLargeHydro = 480000,
- largeGridSmallAtmo = 648000,
- largeGridLargeAtmo = 6480000,
- smallGridSmallAtmo = 96000,
- smallGridLargeAtmo = 576000;
- public IMyShipController controller;
- public List<string> knownThrusterDefinitions = new List<string>();
- public List<ThrusterDefinition> thrusterDefinitionList = new List<ThrusterDefinition>();
- public Program()
- {
- List<IMyShipController> blocks = new List<IMyShipController>();
- GridTerminalSystem.GetBlocksOfType<IMyShipController>(blocks, b => b.CubeGrid == Me.CubeGrid);
- if (blocks.Count > 0) controller = blocks[0];
- else throw new Exception("\nNo ship controller found on grid (Remote Controller or Cockpit)");
- CreateDefinitionList();
- FindThrusters();
- Save();
- }
- public void Save() { }
- public void Main(string argument, UpdateType updateSource)
- {
- MyShipMass shipMass = controller.CalculateShipMass();
- float mass = shipMass.PhysicalMass, gravityAcceleration = (float)controller.GetNaturalGravity().Length();
- if (mass == 0f) mass = shipMass.TotalMass;
- if (argument != "") {
- try {
- if (argument.ToLower() == "update") UpdateThrust();
- else if (argument.Contains(" "))
- {
- mass = float.Parse(argument.Substring(0, argument.IndexOf(" ")));
- gravityAcceleration = float.Parse(argument.Substring(argument.IndexOf(" ") + 1)) * 9.81f;
- } else mass = float.Parse(argument);
- } catch { }
- }
- float newtonsRequired = (mass * gravityAcceleration);
- StringBuilder builder = new StringBuilder();
- builder.AppendLine("Mass: " + mass);
- builder.AppendLine("Current Gravity: " + gravityAcceleration.ToString() + " : " + (gravityAcceleration / 9.81f));
- Echo("Mass: " + mass);
- Echo("Current Gravity: " + gravityAcceleration.ToString() + " : " + (gravityAcceleration / 9.81f));
- for (int i = 0; i < thrusterDefinitionList.Count; i++)
- {
- string thrusterDefinition = thrusterDefinitionList[i].blockDefinition.Substring(23);
- builder.AppendLine(thrusterDefinition + " : " + (newtonsRequired / thrusterDefinitionList[i].thrustInNewtons));
- Echo(thrusterDefinition + " : " + (newtonsRequired / thrusterDefinitionList[i].thrustInNewtons));
- }
- Output(builder);
- }
- public void Output(StringBuilder builder)
- {
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(blocks, b => b.CustomName.ToLower().Contains(thrustPanelKeyword.ToLower()));
- for (int i = 0; i < blocks.Count; i++)
- {
- ((IMyTextSurface)blocks[i]).ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;
- ((IMyTextSurface)blocks[i]).WriteText(builder);
- }
- }
- public void UpdateThrust()
- {
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- for (int i = 0; i < thrusterDefinitionList.Count; i++)
- {
- GridTerminalSystem.GetBlocksOfType<IMyThrust>(blocks, b => b.BlockDefinition.ToString() == thrusterDefinitionList[i].blockDefinition);
- if (blocks.Count > 0) thrusterDefinitionList[i].thrustInNewtons = ((IMyThrust)blocks[i]).MaxEffectiveThrust;
- }
- }
- public void SyncRemote()
- {
- if (controller == null || !Me.CubeGrid.CubeExists(controller.Position)) {
- controller = null;
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(blocks, b => b.CubeGrid == Me.CubeGrid);
- if (blocks.Count == 0)
- GridTerminalSystem.GetBlocksOfType<IMyCockpit>(blocks, b => b.CubeGrid == Me.CubeGrid);
- if (blocks.Count > 0)
- controller = (IMyShipController)blocks[0];
- }
- }
- public void FindThrusters()
- {
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyThrust>(blocks, b => UnknownThrusterDefinition(b.BlockDefinition.ToString()));
- for (int i = 0; i < blocks.Count; i++)
- {
- ThrusterDefinition def = new ThrusterDefinition();
- def.thrustInNewtons = ((IMyThrust)blocks[i]).MaxThrust;
- def.blockDefinition = blocks[i].BlockDefinition.ToString();
- thrusterDefinitionList.Add(def);
- }
- }
- public bool UnknownThrusterDefinition(string def)
- {
- if (!knownThrusterDefinitions.Contains(def))
- {
- knownThrusterDefinitions.Add(def);
- return true;
- }
- return false;
- }
- public void CreateDefinitionList()
- {
- ThrusterDefinition def = new ThrusterDefinition();
- def.thrustInNewtons = largeGridSmallIon;
- def.blockDefinition = "MyObjectBuilder_Thrust/LargeBlockSmallThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = largeGridLargeIon;
- def.blockDefinition = "MyObjectBuilder_Thrust/LargeBlockLargeThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = smallGridSmallIon;
- def.blockDefinition = "MyObjectBuilder_Thrust/SmallBlockSmallThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = smallGridLargeIon;
- def.blockDefinition = "MyObjectBuilder_Thrust/SmallBlockLargeThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = largeGridSmallHydro;
- def.blockDefinition = "MyObjectBuilder_Thrust/LargeBlockSmallHydrogenThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = largeGridLargeHydro;
- def.blockDefinition = "MyObjectBuilder_Thrust/LargeBlockLargeHydrogenThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = smallGridSmallHydro;
- def.blockDefinition = "MyObjectBuilder_Thrust/SmallBlockSmallHydrogenThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = smallGridLargeHydro;
- def.blockDefinition = "MyObjectBuilder_Thrust/SmallBlockLargeHydrogenThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = largeGridSmallAtmo;
- def.blockDefinition = "MyObjectBuilder_Thrust/LargeBlockSmallAtmosphericThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = largeGridLargeAtmo;
- def.blockDefinition = "MyObjectBuilder_Thrust/LargeBlockLargeAtmosphericThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = smallGridSmallAtmo;
- def.blockDefinition = "MyObjectBuilder_Thrust/SmallBlockSmallAtmosphericThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- def = new ThrusterDefinition();
- def.thrustInNewtons = smallGridLargeAtmo;
- def.blockDefinition = "MyObjectBuilder_Thrust/SmallBlockLargeAtmosphericThrust";
- knownThrusterDefinitions.Add(def.blockDefinition);
- thrusterDefinitionList.Add(def);
- }
- public class ThrusterDefinition
- {
- public float thrustInNewtons = 0f;
- public string blockDefinition = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement