From 550a8578f5f3739cf5d2a53c06c5e968cef2a34e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Sep 2020 10:27:02 +0900 Subject: [PATCH 1/9] Delay build of resource list by a frame InterstellarFuelSwitch does its work in OnStart rather than OnLoad (like ModularFuelTanks does) and thus the placement of the tanks with respect to the placement of the pad (in the vessel's part list) can cause the pad's OnStart to be called before the tank's OnStart, resulting in the resource list being built before the tank has been initialized. Thus it is necessary to delay the building of the resource list by a frame. Just in case it matters, the build is delayed a frame for onVesselWasModified as well. Fixes #115 (hopefully) --- Source/BuildControl.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/BuildControl.cs b/Source/BuildControl.cs index 50e2fbcd..022b74bc 100644 --- a/Source/BuildControl.cs +++ b/Source/BuildControl.cs @@ -818,7 +818,7 @@ internal HashSet CraftParts () return part_set; } - internal void FindVesselResources () + void FindVesselResources () { var craft_parts = CraftParts (); var pad_parts = new HashSet (builder.vessel.parts); @@ -843,6 +843,14 @@ internal void FindVesselResources () } } + IEnumerator WaitAndFindVesselResources () + { + yield return null; + if (builder.vessel != null) { + FindVesselResources (); + } + } + public void Load (ConfigNode node) { if (node.HasValue ("filename")) { @@ -911,7 +919,7 @@ internal void OnStart () } } PlaceCraftHull (); - FindVesselResources (); + (builder as PartModule).StartCoroutine (WaitAndFindVesselResources ()); SetPadMass (); } @@ -1100,7 +1108,7 @@ void onVesselWasModified (Vessel v) if (craftRoot != null && craftRoot.vessel != builder.vessel) { CleanupAfterRelease (); } - FindVesselResources (); + (builder as PartModule).StartCoroutine (WaitAndFindVesselResources ()); } } } From 3f7675b8e5d4f9c48eb6f98e2d57bd7b63729cd2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Sep 2020 11:14:04 +0900 Subject: [PATCH 2/9] Put non-master branch name in version string I think one of the reasons I shied away from git-branching is the worry I'd forget to merge to master before releasing. While this won't prevent a release tag on a branch, it will at least catch it for many cases (tag on branch but branch merged into master and currently on master might be interesting). --- tools/git-version-gen | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/git-version-gen b/tools/git-version-gen index b011bb22..ed87c5b6 100755 --- a/tools/git-version-gen +++ b/tools/git-version-gen @@ -190,10 +190,17 @@ fi v=`echo "$v" |sed "s/^$prefix//"` -# Test whether to append the "-dirty" suffix only if the version +# Test whether to append the branch "-dirty" suffixes only if the version # string we're using came from git. I.e., skip the test if it's "UNKNOWN" # or if it came from .tarball-version. if test -n "$v_from_git"; then + branch=`git branch --show-current` + case "$branch" in + 'master') ;; + *) + v="$v-$branch" + ;; + esac # Don't declare a version "dirty" merely because a time stamp has changed. git update-index --refresh > /dev/null 2>&1 From e5fa75de4bbde0d0c3dda3fa0ad37e55b408b61e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Sep 2020 13:03:59 +0900 Subject: [PATCH 3/9] Switch to using csc for compiling I seem to remember reading that msc has been deprecated. --- Makefile | 4 ++-- Source/Makefile | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index af9b35d1..36c77f89 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ export PLUGINDIR := ${MODGAMEDATA}/Plugins export APIEXTDATA := ${PLUGINDIR} RESGEN2 := resgen2 -GMCS := gmcs +CSC := csc GIT := git TAR := tar ZIP := zip @@ -24,7 +24,7 @@ all clean install: info: @echo "${MODNAME} Build Information" @echo " resgen2: ${RESGEN2}" - @echo " gmcs: ${GMCS}" + @echo " gmcs: ${CSC}" @echo " git: ${GIT}" @echo " tar: ${TAR}" @echo " zip: ${ZIP}" diff --git a/Source/Makefile b/Source/Makefile index 399f500b..8421f515 100644 --- a/Source/Makefile +++ b/Source/Makefile @@ -94,8 +94,8 @@ EL_FILES := \ $e RESGEN2 := resgen2 -GMCS := mcs -GMCSFLAGS := -optimize -warnaserror -debug +CSC := csc +CSCFLAGS := -highentropyva- -noconfig -nostdlib+ -t:library -optimize -warnaserror -debug GIT := git TAR := tar ZIP := zip @@ -109,27 +109,38 @@ version: info: @echo "${MODNAME} Build Information" @echo " resgen2: ${RESGEN2}" - @echo " gmcs: ${GMCS}" - @echo " gmcs flags: ${GMCSFLAGS}" + @echo " csc: ${CSC}" + @echo " csc flags: ${CSCFLAGS}" @echo " git: ${GIT}" @echo " tar: ${TAR}" @echo " zip: ${ZIP}" @echo " KSP Data: ${KSPDIR}" +SYSTEM := \ + -lib:${MANAGED} \ + -r:${MANAGED}/mscorlib.dll \ + -r:${MANAGED}/System.dll \ + -r:${MANAGED}/System.Core.dll + +KSP := \ + -r:Assembly-CSharp.dll \ + -r:Assembly-CSharp-firstpass.dll + +UNITY := \ + -r:UnityEngine.dll \ + -r:UnityEngine.UI.dll \ + -r:UnityEngine.UIModule.dll \ + -r:UnityEngine.IMGUIModule.dll \ + -r:UnityEngine.TextRenderingModule.dll \ + -r:UnityEngine.AnimationModule.dll \ + -r:UnityEngine.CoreModule.dll \ + -r:UnityEngine.PhysicsModule.dll \ + -r:UnityEngine.InputLegacyModule.dll \ + $e + bin/Launchpad.dll: ${EL_FILES} @mkdir -p bin - ${GMCS} ${GMCSFLAGS} -t:library -lib:${MANAGED} \ - -r:Assembly-CSharp,Assembly-CSharp-firstpass \ - -r:UnityEngine \ - -r:UnityEngine.UI \ - -r:UnityEngine.UIModule \ - -r:UnityEngine.IMGUIModule \ - -r:UnityEngine.TextRenderingModule \ - -r:UnityEngine.AnimationModule \ - -r:UnityEngine.CoreModule \ - -r:UnityEngine.PhysicsModule \ - -r:UnityEngine.InputLegacyModule \ - -out:$@ $^ + ${CSC} ${CSCFLAGS} ${SYSTEM} ${KSP} ${UNITY} -out:$@ $^ clean: rm -f ${TARGETS}* assembly/AssemblyInfo.cs bin/${MODNAME}.version From ad4e17ec7ed370e9f106429d3e42ee6ac94bdd28 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Sep 2020 13:04:51 +0900 Subject: [PATCH 4/9] Fix a warning that resulted from the csc change --- Source/LaunchClamp/LaunchClamp.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/LaunchClamp/LaunchClamp.cs b/Source/LaunchClamp/LaunchClamp.cs index 0ae8e27d..bd9891ae 100644 --- a/Source/LaunchClamp/LaunchClamp.cs +++ b/Source/LaunchClamp/LaunchClamp.cs @@ -58,7 +58,7 @@ public class ELExtendingLaunchClamp : PartModule bool can_stretch; bool enableExtension; - FXGroup release_fx; + FXGroup release_fx = null; ConfigurableJoint clampJoint; GameObject []clones; From 5636dea34297285e15d7bb41d31d2f5c423a1973 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Sep 2020 13:44:34 +0900 Subject: [PATCH 5/9] Clean up an incorrect usage of Linq --- Source/Survey/SurveyStake.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Survey/SurveyStake.cs b/Source/Survey/SurveyStake.cs index c861c15e..32472b48 100644 --- a/Source/Survey/SurveyStake.cs +++ b/Source/Survey/SurveyStake.cs @@ -16,13 +16,9 @@ You should have received a copy of the GNU General Public License . */ using System; -using System.Collections.Generic; -using System.Linq; using UnityEngine; using UnityEngine.UI; -using TMPro; -using KSP.IO; using Highlighting; namespace ExtraplanetaryLaunchpads { @@ -160,7 +156,7 @@ public void OnPartDie () unfocusedRange = 200f, guiName = "")] public void NextUse() { - use = (use + 1) % StakeUses.Count(); + use = (use + 1) % StakeUses.Length; Events["NextUse"].guiName = StakeUses[use]; UpdatePlaque (); ELSurveyTracker.onStakeModified.Fire (this); From 82b1c14722dc6334c18d33711013b04fd48107aa Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 13 Sep 2020 16:28:38 +0900 Subject: [PATCH 6/9] Ensure BoM updates when switch loaded craft files --- Source/BuildControl.cs | 4 ++++ Source/GUI/BuildWindow.cs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/Source/BuildControl.cs b/Source/BuildControl.cs index 022b74bc..8eed0ae9 100644 --- a/Source/BuildControl.cs +++ b/Source/BuildControl.cs @@ -85,6 +85,7 @@ public RMResourceSet craftResources } } public List craftBoM { get; private set; } + public bool craftBoMdirty { get; private set; } public CostReport buildCost { get; private set; } public CostReport builtStuff { get; private set; } public State state { get; private set; } @@ -725,6 +726,7 @@ public void LoadCraft (string filename, string flagname) } PlaceCraftHull(); state = State.Planning; + craftBoMdirty = true; } public void UnloadCraft () @@ -739,6 +741,7 @@ public bool CreateBoM () { string str; + craftBoMdirty = false; if (craftConfig != null) { craftBoM = new List (); var partCounts = new Dictionary (); @@ -761,6 +764,7 @@ public bool CreateBoM () } return true; } + craftBoM = null; return false; } diff --git a/Source/GUI/BuildWindow.cs b/Source/GUI/BuildWindow.cs index 67033771..7408cb90 100644 --- a/Source/GUI/BuildWindow.cs +++ b/Source/GUI/BuildWindow.cs @@ -729,6 +729,14 @@ void CloseButton () void WindowGUI (int windowID) { + var e = Event.current; + switch (e.type) { + case EventType.Layout: + if (control.craftBoMdirty) { + control.CreateBoM (); + } + break; + } ELStyles.Init (); SelectPad_start (); From f14a78084c112ea58885f9b692a7ab5f86b40ad0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 13 Sep 2020 16:29:40 +0900 Subject: [PATCH 7/9] Make ReStock launch clamps rotate and extend The rotation is waiting on a PR to ReStock, but the extension is the critical part and was caused by incorrect checking for the module (not sure why LaunchClamp didn't work: maybe something to do with the recent optimizations). --- Source/BuildControl.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/BuildControl.cs b/Source/BuildControl.cs index 8eed0ae9..e5463968 100644 --- a/Source/BuildControl.cs +++ b/Source/BuildControl.cs @@ -600,6 +600,11 @@ void RotateLaunchClamps (ShipConstruct ship) for (int j = 0; j < elc.Count; j++) { elc[j].RotateTower (); } + if (elc.Count < 1) { + if (p.Modules["ModuleRestockLaunchClamp"] != null) { + p.SendMessage("RotateTower", SendMessageOptions.DontRequireReceiver); + } + } } } @@ -617,9 +622,9 @@ void EnableExtendingLaunchClamps (ShipConstruct ship) // ReplaceLaunchClamps will not do any replacement because // the module uses a different name. Thus this will pick up // the ReStock module. - var lc = p.FindModulesImplementing (); - for (int j = 0; j < elc.Count; j++) { - lc[j].EnableExtension (); + var lc = p.Modules["ModuleRestockLaunchClamp"]; + if (lc != null) { + (lc as LaunchClamp).EnableExtension (); } } } From 00bdede2355b7e1e46ade9748813b4a64ebc696c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 20 Sep 2020 10:54:28 +0900 Subject: [PATCH 8/9] Force the landed status of vessels touching pads It seems that recent versions of KSP have a bug in their landed logic that causes vessels landed on other (landed) vessels to sometimes not be landed (particularly if things glitch during scene load, tossing the upper vessel up and it landing again) but still suborbital. Copying the landed and splashed flags seems to be sufficient fix it (at least when several colliders are touching) as the vessel sets its situation correctly the next frame. --- Source/Pad/Launchpad.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/Pad/Launchpad.cs b/Source/Pad/Launchpad.cs index 02ae787c..53b7a0d3 100644 --- a/Source/Pad/Launchpad.cs +++ b/Source/Pad/Launchpad.cs @@ -334,5 +334,20 @@ public void OnRename () { ELBuildWindow.updateCurrentPads (); } + + void OnCollisionStay (Collision collision) + { + // force any vessels landed on the pad to share the same situation + // works around a bug in KSP that sometimes glitches the landed + // vessel to not-landed + Part p = FlightGlobals.GetPartUpwardsCached (collision.collider.gameObject); + if (p != null) { + if (vessel.LandedOrSplashed) { + p.vessel.Landed = vessel.Landed; + p.vessel.Splashed = vessel.Splashed; + p.vessel.SetLandedAt (vessel.landedAt, null, vessel.displaylandedAt); + } + } + } } } From a510e990cc8736b15c30fa0c3c694d649289b266 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 21 Sep 2020 08:39:23 +0900 Subject: [PATCH 9/9] Keep track of selected pad on vessels Bases and stations with multiple pads could get confusing due to the first pad in the parts list being selected every time a vessel switch occurred (eg, every time a build is finalized). --- Source/BuildControl.cs | 2 ++ Source/DisposablePad/DisposablePad.cs | 2 ++ Source/GUI/BuildWindow.cs | 31 +++++++++++++++++++++++++++ Source/Pad/Launchpad.cs | 2 ++ Source/Survey/SurveyStation.cs | 2 ++ Source/Workshop/VesselWorkNet.cs | 3 +++ 6 files changed, 42 insertions(+) diff --git a/Source/BuildControl.cs b/Source/BuildControl.cs index e5463968..c8c0e885 100644 --- a/Source/BuildControl.cs +++ b/Source/BuildControl.cs @@ -50,6 +50,8 @@ public interface IBuilder string Name { get; set; } string LandedAt { get; } string LaunchedFrom { get; } + + uint ID { get; } } public IBuilder builder { get; private set; } diff --git a/Source/DisposablePad/DisposablePad.cs b/Source/DisposablePad/DisposablePad.cs index 9b9d7064..1c92fe8a 100644 --- a/Source/DisposablePad/DisposablePad.cs +++ b/Source/DisposablePad/DisposablePad.cs @@ -106,6 +106,8 @@ public string Name public string LandedAt { get { return ""; } } public string LaunchedFrom { get { return ""; } } + public uint ID { get { return part.flightID; } } + public void PadSelection_start () { } diff --git a/Source/GUI/BuildWindow.cs b/Source/GUI/BuildWindow.cs index 7408cb90..13f91202 100644 --- a/Source/GUI/BuildWindow.cs +++ b/Source/GUI/BuildWindow.cs @@ -48,6 +48,7 @@ public class ELBuildWindow : MonoBehaviour static Texture2D flagTexture; List launchpads; + ELVesselWorkNet worknet; DropDownList pad_list; ELBuildControl control; @@ -154,10 +155,34 @@ public static void SaveSettings (ConfigNode node) node.AddValue ("link_lfo_sliders", link_lfo_sliders); } + static ELVesselWorkNet FindWorkNet (Vessel v) + { + for (int i = 0; i < v.vesselModules.Count; i++) { + var worknet = v.vesselModules[i] as ELVesselWorkNet; + if (worknet != null) { + return worknet; + } + } + return null; + } + + static ELBuildControl FindControl (Vessel v, uint id) + { + Part part = v[id]; + if (part != null) { + var pad = part.FindModuleImplementing (); + if (pad != null) { + return pad.control; + } + } + return null; + } + void BuildPadList (Vessel v) { launchpads = null; pad_list = null; + worknet = null; if (v.isEVA) { control = null; @@ -167,6 +192,10 @@ void BuildPadList (Vessel v) if (pads.Count < 1) { control = null; } else { + worknet = FindWorkNet (v); + if (worknet != null) { + control = FindControl (v, worknet.selectedPad); + } launchpads = new List (); int control_index = -1; for (int i = 0; i < pads.Count; i++) { @@ -177,6 +206,7 @@ void BuildPadList (Vessel v) } if (control_index < 0) { control_index = 0; + control = pads[0].control; } var pad_names = new List (); for (int ind = 0; ind < launchpads.Count; ind++) { @@ -424,6 +454,7 @@ void Select_Pad (ELBuildControl selected_pad) control.builder.Highlight (false); } control = selected_pad; + worknet.selectedPad = control.builder.ID; pad_list.SelectItem (launchpads.IndexOf (control)); UpdateGUIState (); } diff --git a/Source/Pad/Launchpad.cs b/Source/Pad/Launchpad.cs index 53b7a0d3..105344fa 100644 --- a/Source/Pad/Launchpad.cs +++ b/Source/Pad/Launchpad.cs @@ -120,6 +120,8 @@ public string Name public string LandedAt { get { return ""; } } public string LaunchedFrom { get { return ""; } } + public uint ID { get { return part.flightID; } } + public void PadSelection_start () { } diff --git a/Source/Survey/SurveyStation.cs b/Source/Survey/SurveyStation.cs index 212b20b2..9f92c8a9 100644 --- a/Source/Survey/SurveyStation.cs +++ b/Source/Survey/SurveyStation.cs @@ -135,6 +135,8 @@ public string LaunchedFrom } } + public uint ID { get { return part.flightID; } } + public bool isBusy { get { diff --git a/Source/Workshop/VesselWorkNet.cs b/Source/Workshop/VesselWorkNet.cs index fda0b36f..c2056853 100644 --- a/Source/Workshop/VesselWorkNet.cs +++ b/Source/Workshop/VesselWorkNet.cs @@ -35,6 +35,9 @@ public class ELVesselWorkNet : VesselModule public double lastUpdate; public double Productivity { get; private set; } + [KSPField (isPersistant = true)] + public uint selectedPad; + public void ForceProductivityUpdate() { forceProductivityUpdate = true;