Jump to content

[PLUGIN,0.15.X,0.16] Start-Stop Engines V 0.1 (Alpha)


jgjiscool

Recommended Posts

Finally it will be possible! You will be able to shut down engines when you don\'t need them, and start them back up when you do... WITHOUT JUST STOPPING THE THRUST!!! Big Red Button Pressers presents to you:

Start-Stop Plugin

It\'s still a work in progress, but here it is so far:

F8Vcl.jpg

Download Links:

https://dl.dropbox.com/u/59317800/BRBP_LFEControl.dll

This version hopefully works for 0.16. I haven\'t tested it so let me know if it works or not.

http://dl.dropbox.com/u/59317800/BRBP%20LFE%20Control%20Part%20Class%20Only.zip

This version creates a new part class that stops the override of the main engines. Use this if you use another plugin to control your engines or you don\'t want this ridiculous function on the other engines.

http://dl.dropbox.com/u/59317800/BRBP%20LFE%20Complete%20Override.zip

This version creates a complete override of the existing LiquidEngine part class giving Start-Stop functions to any engine. It does not appear to work with other plugins that take exclusive control of the engines.

by_nc_sa.gif

License: Attribution-Noncommercial-Share Alike (BY-NC-SA)


using System;
using System.Collections.Generic;

/*
LIQUID ENGINE CONTROL PLUGIN
Created By: Jayson Grieve (jgjiscool)
Credit to: N3X15
Cephei

Description: This is the part for the budding plane engineers! It allows you to disable parts that you aren\'t using
and reactivate them later!

License: Creative Commons Attribution ShareAlike 3.0
*/

// The Separate Part Class has LiquidEngineControlONLY instead of LiquidEngine
public class LiquidEngine : Part
{
private Rect windowPos;
protected float inFL;
public float maxThrust = 200f;
public float fuelConsumption = 8f;
public float heatProduction = 370f;
public float gimbalRange = 2.5f;
public Vector3 thrustVector = Vector3.up;
public float minThrust;
public float gimbalAngleH;
public float gimbalAngleV;
protected Vector3 thrVector;
private RaycastHit hit;
public bool thrustVectoringCapable;
protected float thrust;
private FXGroup activeGroup;
private VInfoBox tempIndicator;
protected Part fuelSource;
protected Transform gimbal;
protected Quaternion initRot;
protected static int guiQueueSpot = 2;
private int myguiQueueSpot;
private void WindowGUI(int windowID)
{
GUI.DragWindow(new Rect(0, 0, 10000, 20));
GUIStyle mySty = new GUIStyle(GUI.skin.button);
mySty.normal.textColor = mySty.focused.textColor = Color.white;
mySty.hover.textColor = mySty.active.textColor = Color.yellow;
mySty.onNormal.textColor = mySty.onFocused.textColor = mySty.onHover.textColor = mySty.onActive.textColor = Color.green;
mySty.padding = new RectOffset(8, 8, 8, 8);
GUILayout.BeginVertical();
if (GUILayout.Button('Stop', mySty, GUILayout.ExpandWidth(true)))
{
this.deactivate();
}
if (GUILayout.Button('Start', mySty, GUILayout.ExpandWidth(true)))
{
this.force_activate();
}
if (GUILayout.Button('Close', mySty, GUILayout.ExpandWidth(true)))
{
RenderingManager.RemoveFromPostDrawQueue(myguiQueueSpot, new Callback(drawGUI));
}
GUILayout.EndVertical();

}
protected override void onCtrlUpd(FlightCtrlState ctrlState)
{
this.thrust = (this.maxThrust - this.minThrust) * ctrlState.mainThrottle + this.minThrust;
this.gimbalAngleH = ctrlState.yaw * this.gimbalRange;
this.gimbalAngleV = ctrlState.pitch * this.gimbalRange;
}
private void drawGUI()
{
GUI.skin = HighLogic.Skin;
windowPos = GUILayout.Window(1, windowPos, WindowGUI, 'Engine Control', GUILayout.MinWidth(150));
}
void OnMouseUpAsButton() {
if (inFL == 1f)
{
RenderingManager.AddToPostDrawQueue(myguiQueueSpot, new Callback(drawGUI));
}
}
protected override bool onPartActivate()
{
if ((UnityEngine.Object)this.fuelSource == (UnityEngine.Object)null)
{ this.deactivate(); inFL = 0; RenderingManager.RemoveFromPostDrawQueue(myguiQueueSpot, new Callback(drawGUI)); }
this.stackIcon.SetIconColor(XKCDColors.AcidGreen);
return true;
}
protected override void onActiveFixedUpdate()
{
if (fuelSource.GetType().Name == 'FuelTank')
{

}
else if ((this.parent.parent.name) == 'FuelTank')
{
if (this.parent.fuelCrossFeed == true)
{
this.fuelSource = this.parent.parent;
}
}

this.activeGroup.Power = Mathf.Max(Mathf.Min(this.thrust / (this.maxThrust * 0.5f), 1.75f), 0.5f);
if (!this.RequestFuel((Part)this, (float)((double)this.fuelConsumption * (double)Time.deltaTime * ((double)this.thrust / (double)this.maxThrust)), Part.getFuelReqId()) && !this.RequestFuel((Part)this, (float)((double)this.fuelConsumption * (double)Time.deltaTime * ((double)this.thrust / (double)this.maxThrust)), Part.getFuelReqId()))
{
this.deactivate();
}
else
{
this.thrVector = this.transform.rotation * this.thrustVector;
if (this.thrustVectoringCapable)
this.thrustVectoring();
if ((double)this.thrust > 0.0)
{
this.Rigidbody.AddForceAtPosition(this.thrVector * this.thrust, this.transform.position, ForceMode.Force);
Debug.DrawRay(this.transform.position + this.Rigidbody.velocity * Time.deltaTime, -this.thrVector, XKCDColors.RedOrange);
if (Physics.Raycast(this.transform.position, -this.thrVector, out this.hit, 10f, 524289) && (bool)((UnityEngine.Object)this.hit.collider.transform.root.GetComponent<Part>()))
{
MonoBehaviour.print((object)('Exhaust damage on ' + this.hit.collider.transform.root.gameObject.name));
this.hit.collider.transform.root.GetComponent<Part>().temperature += this.heatProduction * (this.thrust / this.maxThrust) * Time.deltaTime;
this.hit.rigidbody.AddForceAtPosition(-this.thrVector * this.thrust, this.hit.point, ForceMode.Force);
FlightLogger.ReportEvent(new EventReport(FlightEvents.SPLASHDAMAGE, (Part)this, this.hit.collider.transform.root.gameObject.name, this.name, 0, string.Empty));
}
}
LiquidEngine liquidengine = this;
double num = (double)liquidengine.temperature + (double)this.heatProduction * ((double)this.thrust / (double)this.maxThrust) * (double)Time.deltaTime;
liquidengine.temperature = (float)num;
if ((double)this.thrust == 0.0)
{
if (this.activeGroup.Active)
this.activeGroup.setActive(false);
}
else if (!this.activeGroup.Active)
this.activeGroup.setActive(true);
if ((double)this.temperature / (double)this.maxTemp >= 0.699999988079071)
{
if (this.tempIndicator == null)
{
this.tempIndicator = this.stackIcon.DisplayInfo();
XKCDColors.NextColorAlpha = 0.6f;
this.tempIndicator.SetMsgBgColor(XKCDColors.DarkRed);
this.tempIndicator.SetMsgTextColor(XKCDColors.OrangeYellow);
this.tempIndicator.SetMessage('Overheat!');
this.tempIndicator.SetProgressBarBgColor(XKCDColors.DarkRed);
this.tempIndicator.SetProgressBarColor(XKCDColors.OrangeYellow);
XKCDColors.NextColorAlpha = 1f;
}
this.tempIndicator.SetValue(this.temperature / this.maxTemp, 0.7f, 1f);
}
else
{
if (this.tempIndicator == null)
return;
this.stackIcon.RemoveInfo(this.tempIndicator);
this.tempIndicator = (VInfoBox)null;
}
}
}
protected void onDeactivate()
{
RenderingManager.RemoveFromPostDrawQueue(myguiQueueSpot, new Callback(drawGUI));
this.stackIcon.SetIconColor(XKCDColors.Blue);
this.stackIcon.ClearInfoBoxes();
this.tempIndicator = (VInfoBox)null;
}
protected override void onFlightStart()
{
inFL = 1f;
myguiQueueSpot = guiQueueSpot;
guiQueueSpot += 1;
this.activeGroup = this.findFxGroup('active');
this.gimbal = this.transform.FindChild('model').FindChild('obj_gimbal');
if ((UnityEngine.Object)this.gimbal != (UnityEngine.Object)null)
this.initRot = this.gimbal.localRotation;
this.fuelSource = this.parent;
}
protected override void onPartStart()
{
this.stackIcon.SetIcon(DefaultIcons.LIQUID_ENGINE);
print('Liquid Engine Control Plugin Part Loaded');
if ((windowPos.x == 0) && (windowPos.y == 0))
{
windowPos = new Rect(Screen.width / 2, Screen.height / 2, 10, 10);
}
}
protected override void onPartDestroy()
{
RenderingManager.RemoveFromPostDrawQueue(myguiQueueSpot, new Callback(drawGUI));
}
protected override void onDecouple(float breakForce)
{
inFL = 0;
this.deactivate();
RenderingManager.RemoveFromPostDrawQueue(myguiQueueSpot, new Callback(drawGUI));
}
private void thrustVectoring()
{
this.thrVector = Quaternion.AngleAxis(this.gimbalAngleV, this.localRoot.transform.right) * this.thrVector;
this.thrVector = Quaternion.AngleAxis(this.gimbalAngleH, this.localRoot.transform.forward) * this.thrVector;
using (List<GameObject>.Enumerator enumerator = this.activeGroup.fxEmitters.GetEnumerator())
{
while (enumerator.MoveNext())
enumerator.Current.transform.up = this.thrVector;
}
if (!((UnityEngine.Object)this.gimbal != (UnityEngine.Object)null))
return;
this.gimbal.localRotation = this.initRot * Quaternion.AngleAxis(this.gimbalAngleV, this.gimbal.InverseTransformDirection(this.localRoot.transform.right)) * Quaternion.AngleAxis(this.gimbalAngleH, this.gimbal.InverseTransformDirection(this.localRoot.transform.forward));
}

public override void OnDrawStats()
{
object[] objArray = new object[8];
int index1 = 0;
string str1 = 'Max Thrust: ';
objArray[index1] = (object)str1;
int index2 = 1;
objArray[index2] = (object)(ValueType)this.maxThrust;
int index3 = 2;
string str2 = '\nMin Thrust: ';
objArray[index3] = (object)str2;
int index4 = 3;
objArray[index4] = (object)(ValueType)this.minThrust;
int index5 = 4;
string str3 = '\nBurn rate: ';
objArray[index5] = (object)str3;
int index6 = 5;
objArray[index6] = (object)(ValueType)this.fuelConsumption;
int index7 = 6;
string str4 = '\nThrust Vectoring: ';
objArray[index7] = (object)str4;
int index8 = 7;
string str5 = !this.thrustVectoringCapable ? 'No' : 'Yes\nGimbal Range: ' + this.gimbalRange.ToString('0.0');
objArray[index8] = (object)str5;
string text = string.Concat(objArray);
GUILayoutOption[] guiLayoutOptionArray = new GUILayoutOption[1];
int index9 = 0;
GUILayoutOption guiLayoutOption = GUILayout.ExpandHeight(true);
guiLayoutOptionArray[index9] = guiLayoutOption;
GUILayout.TextArea(text, guiLayoutOptionArray);
}
}



using UnityEngine;

KNOWN ISSUES:

* Does not work with tri-couplers (FIXED) *

* Can not spawn multiple windows *

Good Luck Kerbalnauts!!!

P.s. DO NOT TRY TO OPEN MULTIPLE WINDOWS!!! CLOSE THEM BEFORE YOU OPEN ANOTHER ONE!!!

Link to comment
Share on other sites

This is how we do in flight tweakables. Click on the part to open adjust settings window, adjust settings, commit.

If one were to extend this and combine it with the ASAS or MechJeb, would modifying the KIP parameters from frame to frame force the ASAS/Jeb to update its behavior?

Link to comment
Share on other sites

This would work, BUT not as an extension of the class. At least that I know of. I have tried to commit my code to the LiquidEngine module, but it doesn\'t appear to work. Not that I checked after I resolved the internal naming conflict...

Link to comment
Share on other sites

GUESS WHAT!!!??? If I use the same class definition as an existing part module, MY PLUGIN WILL OVERRIDE THE BUILT IN MODULE!!! Brilliant! Now to get it working just like the standard engine! :P

Set the maxThrust of your engines to 0 when you disable them if you will override the default code... I\'ll need to poke at the engines to find the available thrust at any moment, if some engine is disabled but reporting thrust, it will end up with the rocket not getting into a proper orbit with the ascent module, or crashing to the surface with the descent one.

Also remember that if anyone else decides to replace the stock LiquidEngine, things will go BAD.

A better option would be for you to make an extra part that scans the vessel for LiquidEngines and control them.

Link to comment
Share on other sites

Oh... This basically works just like the standard LiquidEngine component except it adds a new GUI. Would it really do *that* much damage? They do work at the moment by the way. But only one on a rocket, because the GUI screws up for the others, and you can\'t put them under a tricoupler, strut, etc. But I\'m working on it.

Link to comment
Share on other sites

  • 4 months later...

Since .16, the LiquidEngine module has been considered replaced by the LiquidFuelEngine module, any chance of updating this plugin jgjiscool? I\'ve found it useful on some ship designs which use mixed engine types for variable thrust vs fuel consumption capability.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...