Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #170 from aw1621107/port-ksp-ro-1.2.2-backports-to…
Browse files Browse the repository at this point in the history
…-1.3.0

Port KSP-RO/1.2.2 backports to KSP 1.3.0
  • Loading branch information
magico13 authored Oct 13, 2017
2 parents a51d4fa + 39c5071 commit 49ea73a
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 60 deletions.
4 changes: 4 additions & 0 deletions Kerbal_Construction_Time/KCT_BuildListStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class BuildListItem
[Persistent]
float cost = 0, mass = 0, kscDistance = 0;
[Persistent]
int rushBuildClicks = 0;
[Persistent]
int EditorFacility = 0, LaunchPadID = -1;
[Persistent]
List<string> desiredManifest = new List<string>();
Expand All @@ -135,6 +137,7 @@ public KCT_BuildListVessel ToBuildListVessel()
ret.cannotEarnScience = cannotEarnScience;
ret.TotalMass = mass;
ret.DistanceFromKSC = kscDistance;
ret.rushBuildClicks = rushBuildClicks;
ret.launchSiteID = LaunchPadID;
ret.DesiredManifest = desiredManifest;
return ret;
Expand All @@ -151,6 +154,7 @@ public BuildListItem FromBuildListVessel(KCT_BuildListVessel blv)
this.shipID = blv.id.ToString();
this.cannotEarnScience = blv.cannotEarnScience;
this.cost = blv.cost;
this.rushBuildClicks = blv.rushBuildClicks;
this.mass = blv.TotalMass;
this.kscDistance = blv.DistanceFromKSC;
this.EditorFacility = (int)blv.GetEditorFacility();
Expand Down
28 changes: 28 additions & 0 deletions Kerbal_Construction_Time/KCT_BuildListVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public enum ListType { None, VAB, SPH, TechNode, Reconditioning, KSC };
public Guid id;
public bool cannotEarnScience;
public float cost = 0, TotalMass = 0, DistanceFromKSC = 0;
public int rushBuildClicks = 0;
public int numStages = 0;
public int numStageParts = 0;
public double stagePartCost = 0d;
public float emptyCost = 0, emptyMass = 0;
public double buildRate { get { return KCT_Utilities.GetBuildRate(this); } }
public double timeLeft
Expand Down Expand Up @@ -103,6 +107,20 @@ public KCT_BuildListVessel(ShipConstruct s, String ls, double bP, String flagURL
cost = s.GetShipCosts(out emptyCost, out fuel);
TotalMass = s.GetShipMass(out emptyMass, out fuel);

HashSet<int> stages = new HashSet<int>();
numStageParts = 0;
stagePartCost = 0d;
foreach (Part p in s.Parts)
{
if (p.stagingOn)
{
stages.Add(p.inverseStage);
++numStageParts;
stagePartCost += p.GetModuleCosts(p.partInfo.cost, ModifierStagingSituation.CURRENT) + p.partInfo.cost;
}
}
numStages = stages.Count;

launchSite = ls;
buildPoints = bP;
progress = 0;
Expand Down Expand Up @@ -164,10 +182,13 @@ public KCT_BuildListVessel(Vessel vessel) //For recovered vessels
emptyCost = KCT_Utilities.GetTotalVesselCost(shipNode, false);
TotalMass = 0;
emptyMass = 0;

HashSet<int> stages = new HashSet<int>();
foreach (ProtoPartSnapshot p in vessel.protoVessel.protoPartSnapshots)
{
string name = p.partInfo.name;

stages.Add(p.inverseStageIndex);
TotalMass += p.mass;
emptyMass += p.mass;
foreach (ProtoPartResourceSnapshot rsc in p.resources)
Expand All @@ -178,12 +199,16 @@ public KCT_BuildListVessel(Vessel vessel) //For recovered vessels
}
}
cannotEarnScience = true;
numStages = stages.Count;
// FIXME ignore stageable part count and cost - it'll be fixed when we put this back in the editor.

buildPoints = KCT_Utilities.GetBuildTime(shipNode.GetNodes("PART").ToList(), false);
flag = HighLogic.CurrentGame.flagURL;
progress = buildPoints;

DistanceFromKSC = (float)SpaceCenter.Instance.GreatCircleDistance(SpaceCenter.Instance.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));

rushBuildClicks = 0;
}

private ConfigNode FromInFlightVessel(Vessel VesselToSave)
Expand Down Expand Up @@ -396,6 +421,9 @@ public KCT_BuildListVessel NewCopy(bool RecalcTime)
ret.emptyMass = this.emptyMass;
ret.cost = this.cost;
ret.emptyCost = this.emptyCost;
ret.numStageParts = this.numStageParts;
ret.numStages = this.numStages;
ret.stagePartCost = this.stagePartCost;
return ret;
}

Expand Down
10 changes: 10 additions & 0 deletions Kerbal_Construction_Time/KCT_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void addEvents()
GameEvents.onEditorShipModified.Add(ShipModifiedEvent);
GameEvents.OnPartPurchased.Add(PartPurchasedEvent);
//GameEvents.OnVesselRecoveryRequested.Add(RecoveryRequested);
GameEvents.onGUIRnDComplexSpawn.Add(TechEnableEvent);
GameEvents.onGUIRnDComplexDespawn.Add(TechDisableEvent);
GameEvents.OnKSCFacilityUpgraded.Add(FacilityUpgradedEvent);
GameEvents.onGameStateLoad.Add(PersistenceLoadEvent);
Expand Down Expand Up @@ -391,6 +392,15 @@ public void TechDisableEvent()
TechDisableEventFinal(true);
}

public void TechEnableEvent()
{
if (KCT_PresetManager.Instance.ActivePreset.generalSettings.TechUnlockTimes && KCT_PresetManager.Instance.ActivePreset.generalSettings.BuildTimes)
{
foreach (KCT_TechItem techItem in KCT_GameStates.TechList)
techItem.EnableTech();
}
}

public void TechDisableEventFinal(bool save=false)
{
if (KCT_PresetManager.Instance != null && KCT_PresetManager.Instance.ActivePreset != null)
Expand Down
Loading

0 comments on commit 49ea73a

Please sign in to comment.