Skip to content

Commit 3196e4b

Browse files
author
Sander Hoksbergen
committed
1 parent 2a96f16 commit 3196e4b

10 files changed

Lines changed: 169 additions & 93 deletions

File tree

GameData/RemoteTech2/RemoteTech_Squad_Antennas.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
MODULE
44
{
55
name = ModuleRTAntennaPassive
6-
OmniRange = 3000
6+
OmniRange = 5000
77
}
88
}
99

GameData/RemoteTech2/RemoteTech_Squad_Probes.cfg

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
{
55
name = ModuleSPU
66
}
7+
8+
MODULE
9+
{
10+
name = ModuleRTAntennaPassive
11+
TechRequired = advUnmanned
12+
OmniRange = 3000
13+
14+
TRANSMITTER
15+
{
16+
PacketInterval = 0.3
17+
PacketSize = 2
18+
PacketResourceCost = 15.0
19+
}
20+
}
721
}
822

923
@PART[probeStackLarge]
@@ -17,6 +31,7 @@
1731
MODULE
1832
{
1933
name = ModuleRTAntennaPassive
34+
TechRequired = advUnmanned
2035
OmniRange = 3000
2136

2237
TRANSMITTER
@@ -38,6 +53,7 @@
3853
MODULE
3954
{
4055
name = ModuleRTAntennaPassive
56+
TechRequired = advUnmanned
4157
OmniRange = 3000
4258

4359
TRANSMITTER
@@ -59,6 +75,7 @@
5975
MODULE
6076
{
6177
name = ModuleRTAntennaPassive
78+
TechRequired = advUnmanned
6279
OmniRange = 3000
6380

6481
TRANSMITTER
@@ -76,6 +93,20 @@
7693
{
7794
name = ModuleSPU
7895
}
96+
97+
MODULE
98+
{
99+
name = ModuleRTAntennaPassive
100+
TechRequired = advUnmanned
101+
OmniRange = 3000
102+
103+
TRANSMITTER
104+
{
105+
PacketInterval = 0.3
106+
PacketSize = 2
107+
PacketResourceCost = 15.0
108+
}
109+
}
79110
}
80111

81112
@PART[probeCoreHex]
@@ -84,6 +115,20 @@
84115
{
85116
name = ModuleSPU
86117
}
118+
119+
MODULE
120+
{
121+
name = ModuleRTAntennaPassive
122+
TechRequired = advUnmanned
123+
OmniRange = 3000
124+
125+
TRANSMITTER
126+
{
127+
PacketInterval = 0.3
128+
PacketSize = 2
129+
PacketResourceCost = 15.0
130+
}
131+
}
87132
}
88133

89134
@PART[probeCoreCube]
@@ -96,6 +141,7 @@
96141
MODULE
97142
{
98143
name = ModuleRTAntennaPassive
144+
TechRequired = advUnmanned
99145
OmniRange = 3000
100146

101147
TRANSMITTER
10 Bytes
Loading
4.32 KB
Loading

src/RemoteTech2/FlightComputer/FlightComputer.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public void Enqueue(DelayedCommand fc)
7575

7676
public void OnUpdate()
7777
{
78-
78+
var satellite = RTCore.Instance.Satellites[mParent.Guid];
79+
if (satellite == null || satellite.SignalProcessor != mParent) return;
80+
if (!mParent.Powered) return;
81+
if (mVessel.packed) return;
82+
PopCommand();
7983
}
8084

8185
public void OnFixedUpdate()
@@ -84,12 +88,6 @@ public void OnFixedUpdate()
8488
mVessel.OnFlyByWire -= OnFlyByWirePost;
8589
mVessel = mParent.Vessel;
8690
mVessel.OnFlyByWire = OnFlyByWirePre + mVessel.OnFlyByWire + OnFlyByWirePost;
87-
88-
var satellite = RTCore.Instance.Satellites[mParent.Guid];
89-
if (satellite == null || satellite.SignalProcessor != mParent) return;
90-
if (!mParent.Powered) return;
91-
if (mVessel.packed) return;
92-
PopCommand();
9391
}
9492

9593
private void Enqueue(FlightCtrlState fs)

src/RemoteTech2/Modules/ModuleRTAntennaPassive.cs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ public class ModuleRTAntennaPassive : PartModule, IAntenna
1111
{
1212
public String Name { get { return part.partInfo.title; } }
1313
public Guid Guid { get { return vessel.id; } }
14-
public bool Powered { get { return part.isControllable; } }
15-
public bool Activated { get { return true; } set { return; } }
14+
public bool Powered { get { return part.isControllable && Activated; } }
15+
public bool Activated { get { return Unlocked; } set { return; } }
1616
public bool Animating { get { return false; } }
1717

1818
public bool CanTarget { get { return false; } }
1919
public Guid Target { get { return Guid.Empty; } set { return; } }
2020

2121
public float Dish { get { return 0.0f; } }
2222
public double Radians { get { return 1.0f; } }
23-
public float Omni { get { return OmniRange; } }
23+
public float Omni { get { return Activated ? OmniRange : 0.0f; } }
2424
public float Consumption { get { return 0.0f; } }
2525

26+
private bool Unlocked { get { return ResearchAndDevelopment.GetTechnologyState(TechRequired) == RDTech.State.Available || TechRequired.Equals("None"); } }
27+
2628
[KSPField]
2729
public bool
2830
ShowEditor_OmniRange = true,
@@ -31,6 +33,10 @@ public bool
3133
[KSPField(guiName = "Omni range")]
3234
public String GUI_OmniRange;
3335

36+
[KSPField]
37+
public String
38+
TechRequired = "None";
39+
3440
[KSPField]
3541
public float
3642
OmniRange;
@@ -59,26 +65,20 @@ public float
5965
public ConfigNode mTransmitterConfig;
6066
private IScienceDataTransmitter mTransmitter;
6167

62-
private enum State
63-
{
64-
Off,
65-
Operational,
66-
NoResources,
67-
Malfunction,
68-
}
69-
7068
private Guid mRegisteredId;
7169

7270
public override string GetInfo()
7371
{
7472
var info = new StringBuilder();
75-
76-
if (ShowEditor_OmniRange && OmniRange > 0)
73+
if (ShowEditor_OmniRange && Unlocked)
7774
{
78-
info.AppendFormat("Integrated Omni: {0} / {1}", RTUtil.FormatSI(OmniRange, "m"), RTUtil.FormatSI(OmniRange, "m")).AppendLine();
75+
if(!TechRequired.Equals("None")) {
76+
info.Append("<Technology Perk>").AppendLine();
77+
}
78+
info.AppendFormat("Integrated Omni: {1} always-on", RTUtil.FormatSI(OmniRange, "m"), RTUtil.FormatSI(OmniRange, "m"));
7979
}
8080

81-
return info.ToString().TrimEnd(Environment.NewLine.ToCharArray());
81+
return info.ToString();
8282
}
8383

8484
public virtual void SetState(bool state)
@@ -114,8 +114,6 @@ public override void OnLoad(ConfigNode node)
114114

115115
public override void OnStart(StartState state)
116116
{
117-
Fields["GUI_OmniRange"].guiActive = ShowGUI_OmniRange;
118-
119117
if (RTCore.Instance != null)
120118
{
121119
GameEvents.onVesselWasModified.Add(OnVesselModified);
@@ -128,6 +126,11 @@ public override void OnStart(StartState state)
128126
}
129127
}
130128

129+
private void FixedUpdate()
130+
{
131+
Fields["GUI_OmniRange"].guiActive = Activated && ShowGUI_OmniRange;
132+
}
133+
131134
private void AddTransmitter()
132135
{
133136
if (mTransmitterConfig == null || !mTransmitterConfig.HasValue("name")) return;
@@ -214,4 +217,29 @@ public override string ToString()
214217
return String.Format("ModuleRTAntennaPassive({0}, {1})", Name, GetInstanceID());
215218
}
216219
}
220+
221+
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
222+
public class ModuleRTAntennaPassive_ReloadPartInfo : MonoBehaviour
223+
{
224+
public void Start()
225+
{
226+
StartCoroutine(RefreshPartInfo());
227+
}
228+
229+
private IEnumerator RefreshPartInfo()
230+
{
231+
yield return null;
232+
foreach (var ap in PartLoader.LoadedPartsList.Where(ap => ap.partPrefab.Modules != null && ap.partPrefab.Modules.Contains("ModuleRTAntennaPassive")))
233+
{
234+
var new_info = new StringBuilder();
235+
foreach (PartModule pm in ap.partPrefab.Modules)
236+
{
237+
var info = pm.GetInfo();
238+
new_info.Append(info);
239+
if (info != String.Empty) new_info.AppendLine();
240+
}
241+
ap.moduleInfo = new_info.ToString().TrimEnd(Environment.NewLine.ToCharArray());
242+
}
243+
}
244+
}
217245
}

src/RemoteTech2/NetworkRenderer.cs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ public enum MapFilter
1111
None = 0,
1212
Omni = 1,
1313
Dish = 2,
14-
OmniDish = MapFilter.Omni | MapFilter.Dish,
1514
Planet = 4,
16-
Any = 8,
17-
Path = 16
15+
Path = 8
1816
}
1917

20-
public class NetworkRenderer : MonoBehaviour, IConfigNode
18+
public class NetworkRenderer : MonoBehaviour
2119
{
2220
public MapFilter Filter { get; set; }
2321

@@ -26,10 +24,10 @@ public class NetworkRenderer : MonoBehaviour, IConfigNode
2624
private List<NetworkLine> mLines = new List<NetworkLine>();
2725
private List<NetworkCone> mCones = new List<NetworkCone>();
2826

29-
public bool ShowOmni { get { return (Filter & (MapFilter.Any | MapFilter.Omni)) == (MapFilter.Any | MapFilter.Omni); } }
30-
public bool ShowDish { get { return (Filter & (MapFilter.Any | MapFilter.Dish)) == (MapFilter.Any | MapFilter.Dish); } }
31-
public bool ShowPath { get { return (Filter & MapFilter.Path) == MapFilter.Path || ShowAll; } }
32-
public bool ShowAll { get { return (Filter & MapFilter.Any) == MapFilter.Any; } }
27+
public bool ShowOmni { get { return (Filter & MapFilter.Omni) == MapFilter.Omni; } }
28+
public bool ShowDish { get { return (Filter & MapFilter.Dish) == MapFilter.Dish; } }
29+
public bool ShowPath { get { return (Filter & MapFilter.Path) == MapFilter.Path; } }
30+
public bool ShowPlanet { get { return (Filter & MapFilter.Planet) == MapFilter.Planet; } }
3331

3432
static NetworkRenderer()
3533
{
@@ -45,31 +43,13 @@ public static NetworkRenderer AttachToMapView()
4543
}
4644

4745
renderer = MapView.MapCamera.gameObject.AddComponent<NetworkRenderer>();
48-
renderer.Filter = MapFilter.Any | MapFilter.OmniDish;
46+
renderer.Filter = MapFilter.Path | MapFilter.Omni | MapFilter.Dish;
4947
RTCore.Instance.Network.OnLinkAdd += renderer.OnLinkAdd;
5048
RTCore.Instance.Network.OnLinkRemove += renderer.OnLinkRemove;
5149
RTCore.Instance.Satellites.OnUnregister += renderer.OnSatelliteUnregister;
5250
return renderer;
5351
}
5452

55-
public void Load(ConfigNode node)
56-
{
57-
try
58-
{
59-
if (!node.HasValue("MapFilter")) throw new ArgumentException("MapFilter non-exist");
60-
Filter = (MapFilter)Enum.Parse(typeof(MapFilter), node.GetValue("MapFilter"));
61-
}
62-
catch (ArgumentException)
63-
{
64-
Filter = MapFilter.Any | MapFilter.OmniDish;
65-
}
66-
}
67-
68-
public void Save(ConfigNode node)
69-
{
70-
node.AddValue("MapFilter", Filter.ToString());
71-
}
72-
7353
public void OnPreRender()
7454
{
7555
if (MapView.MapIsEnabled)
@@ -116,7 +96,7 @@ private void UpdateNetworkCones()
11696
mCones[i].Antenna = antennas[i];
11797
mCones[i].Planet = RTCore.Instance.Network.Planets[antennas[i].Target];
11898
mCones[i].Color = Color.gray;
119-
mCones[i].Active = true;
99+
mCones[i].Active = ShowPlanet;
120100
}
121101
}
122102

@@ -206,6 +186,12 @@ public void Detach()
206186
{
207187
mLines[i].Destroy();
208188
}
189+
mLines.Clear();
190+
for (int i = 0; i < mCones.Count; i++)
191+
{
192+
mCones[i].Destroy();
193+
}
194+
mCones.Clear();
209195
DestroyImmediate(this);
210196
}
211197

src/RemoteTech2/RTUtil.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,27 +279,36 @@ public static IEnumerable<Transform> FindTransformsWithCollider(Transform input)
279279
}
280280
}
281281

282-
public static TSource MinElement<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> selector, IComparer<TKey> comparer)
282+
// Thanks Fractal_UK!
283+
public static bool IsTechUnlocked(string techid)
283284
{
284-
using (IEnumerator<TSource> sourceIterator = source.GetEnumerator())
285+
if (techid.Equals("None")) return true;
286+
try
285287
{
286-
if (!sourceIterator.MoveNext())
288+
if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) return true;
289+
string persistentfile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/persistent.sfs";
290+
ConfigNode config = ConfigNode.Load(persistentfile);
291+
ConfigNode gameconf = config.GetNode("GAME");
292+
ConfigNode[] scenarios = gameconf.GetNodes("SCENARIO");
293+
foreach (ConfigNode scenario in scenarios)
287294
{
288-
throw new InvalidOperationException("Sequence was empty");
289-
}
290-
TSource min = sourceIterator.Current;
291-
TKey minKey = selector(min);
292-
while (sourceIterator.MoveNext())
293-
{
294-
TSource candidate = sourceIterator.Current;
295-
TKey candidateProjected = selector(candidate);
296-
if (comparer.Compare(candidateProjected, minKey) < 0)
295+
if (scenario.GetValue("name") == "ResearchAndDevelopment")
297296
{
298-
min = candidate;
299-
minKey = candidateProjected;
297+
ConfigNode[] techs = scenario.GetNodes("Tech");
298+
foreach (ConfigNode technode in techs)
299+
{
300+
if (technode.GetValue("id") == techid)
301+
{
302+
return true;
303+
}
304+
}
300305
}
301306
}
302-
return min;
307+
return false;
308+
}
309+
catch (Exception)
310+
{
311+
return false;
303312
}
304313
}
305314
}

0 commit comments

Comments
 (0)