forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProtoAntenna.cs
More file actions
102 lines (89 loc) · 3.24 KB
/
Copy pathProtoAntenna.cs
File metadata and controls
102 lines (89 loc) · 3.24 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Linq;
namespace RemoteTech.Modules
{
internal class ProtoAntenna : IAntenna
{
public String Name { get; private set; }
public Guid Guid { get; private set; }
public bool Powered { get; private set; }
public bool Activated { get; set; }
public float Consumption { get; private set; }
public bool CanTarget { get { return Dish != -1; } }
public Guid Target
{
get { return mDishTarget; }
set
{
mDishTarget = value;
if (mProtoModule != null)
{
ConfigNode n = new ConfigNode();
mProtoModule.Save(n);
n.SetValue("RTAntennaTarget", value.ToString());
int i = mProtoPart.modules.FindIndex(x => x == mProtoModule);
if (i != -1)
{
mProtoPart.modules[i] = new ProtoPartModuleSnapshot(n);
}
}
}
}
public float Dish { get; private set; }
public double CosAngle { get; private set; }
public float Omni { get; private set; }
private readonly ProtoPartSnapshot mProtoPart;
private readonly ProtoPartModuleSnapshot mProtoModule;
private Guid mDishTarget;
public ProtoAntenna(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot ppms)
{
ConfigNode n = new ConfigNode();
ppms.Save(n);
Name = p.partInfo.title;
Consumption = 0;
Guid = v.id;
mProtoPart = p;
mProtoModule = ppms;
try
{
mDishTarget = new Guid(n.GetValue("RTAntennaTarget"));
}
catch (ArgumentException)
{
mDishTarget = Guid.Empty;
}
double temp_double;
float temp_float;
bool temp_bool;
Dish = Single.TryParse(n.GetValue("RTDishRange"), out temp_float) ? temp_float : 0.0f;
CosAngle = Double.TryParse(n.GetValue("RTDishCosAngle"), out temp_double) ? temp_double : 0.0;
Omni = Single.TryParse(n.GetValue("RTOmniRange"), out temp_float) ? temp_float : 0.0f;
Powered = Boolean.TryParse(n.GetValue("IsRTPowered"), out temp_bool) ? temp_bool : false;
Activated = Boolean.TryParse(n.GetValue("IsRTActive"), out temp_bool) ? temp_bool : false;
RTLog.Notify(ToString());
}
public ProtoAntenna(String name, Guid guid, float omni)
{
Name = name;
Guid = guid;
Omni = omni;
Dish = 0;
Target = Guid.Empty;
CosAngle = 1.0f;
Activated = true;
Powered = true;
}
public void OnConnectionRefresh()
{
;
}
public int CompareTo(IAntenna antenna)
{
return Consumption.CompareTo(antenna.Consumption);
}
public override string ToString()
{
return String.Format("ProtoAntenna(Name: {0}, Guid: {1}, Dish: {2}, Omni: {3}, Target: {4}, CosAngle: {5})", Name, Guid, Dish, Omni, Target, CosAngle);
}
}
}