Skip to content

Commit

Permalink
Merge 2.7.2.0 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
TriggerAu committed Jun 29, 2015
2 parents 6d15ea7 + 656ee88 commit 9bf0ec9
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 62 deletions.
55 changes: 34 additions & 21 deletions AlternateResourcePanel/ARP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private KSPAlternateResourcePanel()
internal List<ModuleEngines> lstLastStageEngineModules;
internal List<ModuleEnginesFX> lstLastStageEngineFXModules;

internal ARPPartDefList lstParts;

public Dictionary<Int32, ARPResourceList> lstResourcesVesselPerStage;


Expand Down Expand Up @@ -208,6 +210,10 @@ internal override void Start()
void OnStageActivate(Int32 StageNum)
{
StageCheckAlarmAudio = true;

//trigger the autostage
if (AutoStagingArmed && !AutoStagingRunning)
AutoStagingRunning=true;
}

void OnFlightReady()
Expand Down Expand Up @@ -481,7 +487,8 @@ internal override void RepeatingWorker()
}

//flush the temporary lists
lstPartsLastStageEngines= new ARPPartList();
lstPartsLastStageEngines = new ARPPartList();
lstParts = new ARPPartDefList();
List<Int32> lstVesselResourceIDs = new List<Int32>();
//Now loop through and update em
foreach (Part p in active.parts)
Expand Down Expand Up @@ -577,24 +584,24 @@ internal override void RepeatingWorker()
// lstResourcesVesselPerStage.Remove(stageID);
//}

#if DEBUG
String File = "";
File += String.Format("Stage,Name,Amount\r\n");
for (int i = 0; i < lstResourcesVesselPerStage.Count; i++)
{
ARPResourceList tmp = lstResourcesVesselPerStage.OrderBy(x => x.Key).ToList()[i].Value;
foreach (ARPResource item in tmp.Values)
{
String strline = "";
//#if DEBUG
// String File = "";
// File += String.Format("Stage,Name,Amount\r\n");
// for (int i = 0; i < lstResourcesVesselPerStage.Count; i++)
// {
// ARPResourceList tmp = lstResourcesVesselPerStage.OrderBy(x => x.Key).ToList()[i].Value;
// foreach (ARPResource item in tmp.Values)
// {
// String strline = "";

strline += String.Format("{0},{1},{2:0}", i, item.ResourceDef.name, item.Amount);
// strline += String.Format("{0},{1},{2:0}", i, item.ResourceDef.name, item.Amount);

File += strline + "\r\n";
}
}
// File += strline + "\r\n";
// }
// }

System.IO.File.WriteAllText(String.Format("{0}/AllStages.csv", Resources.PathPlugin), File);
#endif
// System.IO.File.WriteAllText(String.Format("{0}/AllStages.csv", Resources.PathPlugin), File);
//#endif

//Set the alarm flags
foreach (ARPResource r in lstResourcesVessel.Values)
Expand Down Expand Up @@ -722,11 +729,17 @@ internal override void RepeatingWorker()
AutoStagingStatus = "Running";

//are all the engines that are active flamed out in the last stage
if (AutoStagingTriggeredAt == 0 && (lstLastStageEngineModules.Where(x => x.staged).All(x => x.getFlameoutState)) && (lstLastStageEngineFXModules.Where(x => x.staged).All(x => x.getFlameoutState)))
if (AutoStagingTriggeredAt == 0 && lstPartsLastStageEngines.Count > 0 &&
(lstLastStageEngineModules.Where(x => x.staged).All(x => x.getFlameoutState)) &&
(lstLastStageEngineFXModules.Where(x => x.staged).All(x => x.getFlameoutState)))
{
LogFormatted_DebugOnly("Engine Flameouts Detected");
AutoStagingTriggeredAt = Planetarium.GetUniversalTime();
}
else if (AutoStagingTriggeredAt != 0){
} else if(AutoStagingTriggeredAt == 0 && lstResourcesLastStage.Sum(r=>r.Value.Amount)<=0 & lstPartsLastStageEngines.Count==0) {
//or is the last stage just emoty tanks?
LogFormatted_DebugOnly("Empty Resource Stage Detected");
AutoStagingTriggeredAt = Planetarium.GetUniversalTime();
} else if (AutoStagingTriggeredAt != 0){
if (Planetarium.GetUniversalTime() - AutoStagingTriggeredAt > ((Double)settings.AutoStagingDelayInTenths / 10))
{
//if (!settings.StagingIgnoreLock || Staging.stackLocked || FlightInputHandler.fetch.stageLock)
Expand Down Expand Up @@ -846,7 +859,7 @@ internal override void LateUpdate()
List<ARPPartWindow> LeftWindows = lstPartWindows.Values.Where(x => x.LeftSide).OrderByDescending(x => x.PartScreenPos.y).ToList();
if (LeftWindows.Count > 0)
{
Double LeftPos = lstPartWindows.Values.Where(x => x.LeftSide).Min(x => x.PartScreenPos.x) - ARPPartWindow.WindowOffset - (ARPPartWindow.WindowWidth / 2);
Double LeftPos = lstPartWindows.Values.Where(x => x.LeftSide).Min(x => x.PartScreenPos.x) - ARPPartWindow.WindowOffset - (ARPPartWindow.WindowWidthForBars / 2);
foreach (ARPPartWindow pwTemp in LeftWindows)
{
pwTemp.WindowRect.y = Screen.height - (float)pwTemp.PartScreenPos.y - (pwTemp.WindowRect.height / 2); //this sets an initial y used for sorting later
Expand All @@ -857,7 +870,7 @@ internal override void LateUpdate()
List<ARPPartWindow> RightWindows = lstPartWindows.Values.Where(x => !x.LeftSide).OrderByDescending(x => x.PartScreenPos.y).ToList();
if (RightWindows.Count > 0)
{
Double RightPos = (float)lstPartWindows.Values.Where(x => !x.LeftSide).Max(x => x.PartScreenPos.x) + ARPPartWindow.WindowOffset - (ARPPartWindow.WindowWidth / 2);
Double RightPos = (float)lstPartWindows.Values.Where(x => !x.LeftSide).Max(x => x.PartScreenPos.x) + ARPPartWindow.WindowOffset - (ARPPartWindow.WindowWidthForBars / 2);
foreach (ARPPartWindow pwTemp in RightWindows)
{
pwTemp.WindowRect.y = Screen.height - (float)pwTemp.PartScreenPos.y - (pwTemp.WindowRect.height / 2); //this sets an initial y used for sorting later
Expand Down
45 changes: 32 additions & 13 deletions AlternateResourcePanel/ARPPartWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ internal Vector3d PartScreenPos { get {
internal static Single SideThreshold = 8;
internal static Single WindowOffset = 200;
internal static Single WindowSpaceOffset = 5;
internal static Single WindowWidth = 169;
internal static Single WindowWidthForBars = 169;
internal static Single WindowWidthForFlowControl = 16;

internal static Int32 Icon2BarOffset = 36;

Expand All @@ -79,7 +80,7 @@ internal Vector3d PartScreenPos { get {
private void UpdateWindowSizeAndVariables()
{
Rect NewPosition = new Rect(WindowRect);
NewPosition.width = WindowWidth;
NewPosition.width = WindowWidthForBars + WindowWidthForFlowControl;
NewPosition.height = ((this.ResourceList.Count + 1 + this.TransfersCount ) * mbARP.windowMain.intLineHeight) + 1;

//where to position the window
Expand Down Expand Up @@ -183,11 +184,11 @@ internal override void DrawWindow(int id)
TransfersCount = 0;
if (SkinsLibrary.CurrentSkin.name=="Unity")
{
GUI.Box(new Rect(0, 0, WindowWidth - 1,WindowRect.height- 1), "", SkinsLibrary.CurrentSkin.window);
GUI.Box(new Rect(0, 0, WindowWidthForBars - 1,WindowRect.height- 1), "", SkinsLibrary.CurrentSkin.window);
}

GUILayout.BeginVertical();
GUI.Label(new Rect(0,0,WindowWidth-1,18), this.PartRef.partInfo.title, Styles.stylePartWindowHead);
GUI.Label(new Rect(0,0,WindowWidthForBars+WindowWidthForFlowControl-1,18), this.PartRef.partInfo.title, Styles.stylePartWindowHead);
GUILayout.Space(18);
int i = 0;
foreach (int key in this.ResourceList.Keys)
Expand Down Expand Up @@ -218,16 +219,34 @@ internal override void DrawWindow(int id)
Styles.styleBarGreen_Back, Styles.styleBarGreen, Styles.styleBarGreen_Thin,
settings.ShowRatesForParts, TransferActive, Highlight))
{
//toggle the transfer line
if (TransferExists)
//if (this.ResourceList[key].ResourceDef.resourceTransferMode != ResourceTransferMode.NONE)
if (this.ResourceList[key].ResourceDef.resourceTransferMode != ResourceTransferMode.NONE &&
(
HighLogic.CurrentGame.Mode != Game.Modes.CAREER ||
GameVariables.Instance.UnlockedFuelTransfer(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment))
)
)
{
mbARP.lstTransfers.RemoveItem(this.PartID, key);
TransferExists = false;
}
else {
mbARP.lstTransfers.AddItem(this.PartRef, this.ResourceList[key].ResourceDef, TransferStateEnum.None);

//toggle the transfer line
if (TransferExists)
{
mbARP.lstTransfers.RemoveItem(this.PartID, key);
TransferExists = false;
}
else
{
mbARP.lstTransfers.AddItem(this.PartRef, this.ResourceList[key].ResourceDef, TransferStateEnum.None);
}
}
}

if (this.ResourceList[key].ResourceDef.resourceFlowMode != ResourceFlowMode.NO_FLOW)
{
if (Drawing.DrawFlowControlButton(rectBar, this.PartRef.Resources.Get(key).flowState))
this.PartRef.Resources.Get(key).flowState = !this.PartRef.Resources.Get(key).flowState;
}

GUILayout.EndHorizontal();

if (TransferExists)
Expand All @@ -246,6 +265,7 @@ internal override void DrawWindow(int id)

GUILayout.Space(21);


GUIStyle styleTransferButton = new GUIStyle(SkinsLibrary.CurrentSkin.button);
styleTransferButton.fixedHeight = 19;
styleTransferButton.fixedWidth = 40;
Expand All @@ -262,7 +282,7 @@ internal override void DrawWindow(int id)
if (blnTempOut && (tmpTransfer.transferState != TransferStateEnum.Out))
{
//if there are any transfers in place for this resource then turn off the In
if (mbARP.lstTransfers.Any(x=>x.ResourceID==key && x.Active))
if (mbARP.lstTransfers.Any(x => x.ResourceID == key && x.Active))
mbARP.lstTransfers.SetStateNone(key);
else
mbARP.lstTransfers.SetStateNone(key, TransferStateEnum.Out);
Expand All @@ -283,7 +303,6 @@ internal override void DrawWindow(int id)
else if (!blnTempIn && !blnTempOut && (tmpTransfer.transferState != TransferStateEnum.None))
tmpTransfer.transferState = TransferStateEnum.None;


//if (tmpTransfer.Active)
//{
// GUILayout.Space(20);
Expand Down
61 changes: 39 additions & 22 deletions AlternateResourcePanel/ARPWindowDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class ARPWindowDebug: MonoBehaviourWindowPlus
internal KSPAlternateResourcePanel mbARP;
internal Settings settings;

public Int32 intTest1 = 8;
public Int32 intTest1 = 16;
public Int32 intTest2=56;
public Int32 intTest3=8;
public Int32 intTest4 = 56;
Expand Down Expand Up @@ -80,32 +80,49 @@ internal override void DrawWindow(int id)
GUILayout.Label(String.Format("Draw Main Duration: {0:0.00}ms", mbARP.windowMain.DrawWindowInternalDuration.TotalMilliseconds));


GUILayout.Label(String.Format("{0}", Staging.StageCount));
//GUILayout.Label(String.Format("{0}", Staging.StageCount));

for (int i = 1; i < mbARP.lstResourcesVesselPerStage.Keys.Max(); i++)
{
GUILayout.Label(String.Format("{0}-{1}",i,mbARP.lstResourcesVesselPerStage[i].Values.Count));
}

foreach (ARPPartWindow pw in mbARP.lstPartWindows.Values)
{
// GUILayout.Label(string.Format("{0}-{1}-{2}-{3}-{4}", pw.PartRef.partInfo.title, pw.WindowID,
GUILayout.Label(string.Format("{0}-{1}", (pw.PartRef.transform.position).ToString(), pw.WindowRect ));
}

//for (int i = 1; i < mbARP.lstResourcesVesselPerStage.Keys.Max(); i++)
//{
// GUILayout.Label(String.Format("{0}-{1}",i,mbARP.lstResourcesVesselPerStage[i].Values.Count));
//}

//GUILayout.Label(String.Format("AutostaginTermAt: {0}", mbARP.AutoStagingTerminateAt));
//GUILayout.Label(String.Format("lstLastStageEngineModules: {0}", mbARP.lstLastStageEngineModules.Count));
//GUILayout.Label(String.Format("lstLastStageEngineFXModules: {0}", mbARP.lstLastStageEngineFXModules.Count));

//GUILayout.Label(String.Format("AutostaginTriggeredAt: {0}", mbARP.AutoStagingTerminateAt));
//GUILayout.Label(String.Format("lstStage Engine count: {0}", mbARP.lstPartsLastStageEngines.Count));
//GUILayout.Label(String.Format("LastStage Resource Sum: {0}", mbARP.lstResourcesLastStage.Sum(r => r.Value.Amount)));



//Stuff for extra staging

if (GUILayout.Button("Save Parts")){
System.IO.File.Delete(String.Format("{0}/AllStages2.csv", Resources.PathPlugin));
System.IO.File.AppendAllText(String.Format("{0}/AllStages2.csv", Resources.PathPlugin),
String.Format("StageOffset,StageBefore,StageAfter,DecoupledAt,Resource,Amount\r\n"),
Encoding.ASCII);
foreach (Part p in FlightGlobals.ActiveVessel.Parts)
{
foreach (PartResource pr in p.Resources)
{
System.IO.File.AppendAllText(String.Format("{0}/AllStages2.csv", Resources.PathPlugin),
String.Format("{0},{1},{2},{3},{4},{5}\r\n",p.stageOffset,p.stageBefore,p.stageAfter,p.DecoupledAt(),pr.info.name,pr.amount),
Encoding.ASCII);
}
//GUILayout.Label(String.Format("{0}-{1}-{2}-{3}-{4}-{5}", item.getFlameoutState, item.getIgnitionState, item.EngineIgnited, item.isOperational, item.staged, item.status));
}
//if (GUILayout.Button("Save Parts")){
// System.IO.File.Delete(String.Format("{0}/AllStages2.csv", Resources.PathPlugin));
// System.IO.File.AppendAllText(String.Format("{0}/AllStages2.csv", Resources.PathPlugin),
// String.Format("StageOffset,StageBefore,StageAfter,DecoupledAt,Resource,Amount\r\n"),
// Encoding.ASCII);
// foreach (Part p in FlightGlobals.ActiveVessel.Parts)
// {
// foreach (PartResource pr in p.Resources)
// {
// System.IO.File.AppendAllText(String.Format("{0}/AllStages2.csv", Resources.PathPlugin),
// String.Format("{0},{1},{2},{3},{4},{5}\r\n",p.stageOffset,p.stageBefore,p.stageAfter,p.DecoupledAt(),pr.info.name,pr.amount),
// Encoding.ASCII);
// }
// //GUILayout.Label(String.Format("{0}-{1}-{2}-{3}-{4}-{5}", item.getFlameoutState, item.getIgnitionState, item.EngineIgnited, item.isOperational, item.staged, item.status));
// }

}
//}

//GUILayout.Label(String.Format("IntakeAir Requested:{0}",mbARP.IntakeAirRequested));

Expand Down
45 changes: 43 additions & 2 deletions AlternateResourcePanel/ClassDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,46 @@ namespace KSPAlternateResourcePanel
// // }
// //}
//}


internal class ARPPartDef
{
internal ARPPartDef(Part p) { part = p; DecoupledAt = p.DecoupledAt(); }
internal Part part;
internal Int32 DecoupledAt;
}
internal class ARPPartDefList : List<ARPPartDef> {

internal Boolean LastStageIsResourceOnlyAndEmpty()
{
Int32 LastStage = GetLastStage();

//check each part in the stage
foreach (ARPPartDef p in this.Where(pa=>pa.DecoupledAt==LastStage)) {

//if theres an engine then ignore this case
if (p.part.Modules.OfType<ModuleEngines>().Any() || p.part.Modules.OfType<ModuleEnginesFX>().Any()){
return false;
}
//if theres any resource then ignore this case
foreach (PartResource r in p.part.Resources)
{
if (r.amount>0)
return false;
}
}
return true;
//return !HasEngine && !HasFuel;
}


internal Int32 GetLastStage()
{
if (this.Count > 0)
return this.Max(x => x.DecoupledAt);
else return -1;
}
}

internal class ARPPartList: List<Part>
{
//internal Int32 LastStage { get { return this.Max(x => x.DecoupledAt()); } }
Expand Down Expand Up @@ -321,7 +360,9 @@ internal String DisplayValue(Double AmountToDisplay)
{
Double Amount = AmountToDisplay;
if (ResourceConfig.DisplayValueAs == ResourceSettings.DisplayUnitsEnum.Tonnes)
Amount = AmountToDisplay / 1000;
Amount = AmountToDisplay * this.ResourceDef.density;
else if (ResourceConfig.DisplayValueAs == ResourceSettings.DisplayUnitsEnum.Kilograms)
Amount = AmountToDisplay * this.ResourceDef.density * 1000;

//Format string - Default
String strFormat = "{0:0}";
Expand Down
4 changes: 2 additions & 2 deletions AlternateResourcePanel/KSPAlternateResourcePanel.version
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"VERSION": {
"MAJOR": 2,
"MINOR": 7,
"PATCH": 1,
"PATCH": 2,
"BUILD": 0
},
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 0,
"PATCH": 2
"PATCH": 4
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
4 changes: 2 additions & 2 deletions AlternateResourcePanel/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.7.1.0")]
[assembly: AssemblyFileVersion("2.7.1.0")]
[assembly: AssemblyVersion("2.7.2.0")]
[assembly: AssemblyFileVersion("2.7.2.0")]
Loading

0 comments on commit 9bf0ec9

Please sign in to comment.