-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathEngineIgnitorExternal.cs
90 lines (77 loc) · 3.08 KB
/
EngineIgnitorExternal.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.Collections.Generic;
using UnityEngine;
namespace EngineIgnitor
{
public class ModuleExternalIgnitor : PartModule
{
public static List<ModuleExternalIgnitor> ExternalIgnitors = new List<ModuleExternalIgnitor>();
[KSPField(isPersistant = false)]
public int IgnitionsAvailable = -1;
[KSPField(isPersistant = true)]
public int IgnitionsRemained = -1;
[KSPField(isPersistant = false, guiActiveEditor = true, guiActive = true, guiName = "Ignitions")]
private string _ignitionsAvailableString = "Infinite";
[KSPField(isPersistant = false)]
public string IgnitorType = "universal";
[KSPField(isPersistant = false, guiActiveEditor = true, guiActive = true, guiName = "Engines in range:")]
private string _enginesInRange = "NO";
[KSPField(isPersistant = false)]
public float IgniteRange = 1f;
private StartState _startState = StartState.None;
private float _distanceToEngine;
public override void OnStart(StartState state)
{
_startState = state;
if (state != StartState.None && state != StartState.Editor)
{
if(ExternalIgnitors.Contains(this) == false)
ExternalIgnitors.Add(this);
}
}
private void Update()
{
if (HighLogic.LoadedSceneIsEditor && EditorLogic.fetch.ship != null)
{
foreach (var p in EditorLogic.fetch.ship.parts)
{
if (p.FindModuleImplementing<ModuleEngineIgnitor>() == true)
{
_distanceToEngine = Vector3.Distance(part.transform.position, p.transform.position);
}
}
if (_distanceToEngine <= IgniteRange && EditorLogic.fetch.ship != null) _enginesInRange = "YES";
else _enginesInRange = "NO";
}
else
{
foreach (var p in vessel.parts)
{
if (p.FindModuleImplementing<ModuleEngineIgnitor>() == true)
{
_distanceToEngine = Vector3.Distance(part.transform.position, p.transform.position);
}
}
if (_distanceToEngine <= IgniteRange && vessel != null) _enginesInRange = "YES";
else _enginesInRange = "NO";
}
if (_startState != StartState.None && _startState != StartState.Editor)
{
if (IgnitionsRemained != -1)
_ignitionsAvailableString = IgnitorType + " - " + IgnitionsRemained + "/" + IgnitionsAvailable;
else
_ignitionsAvailableString = IgnitorType + " - " + "Infinite";
if (vessel == null)
{
ExternalIgnitors.Remove(this);
}
}
}
public override string GetInfo()
{
if (IgnitionsAvailable != -1)
return "Can ignite for " + IgnitionsAvailable + " time(s).\n" + "Ignitor type: " + IgnitorType + "\n";
else
return "Can ignite for infinite times.\n" + "Ignitor type: " + IgnitorType + "\n";
}
}
}