Version 1.10.3 1.10.3
[AntennaRange.git] /
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
// AntennaRange
//
// AntennaRelay.cs
//
// Copyright © 2014-2015, toadicus
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
//    this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation and/or other
//    materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used
//    to endorse or promote products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

using System;
using System.Collections.Generic;
using ToadicusTools;

namespace AntennaRange
{
	/// <summary>
	/// Relay code at the heart of AntennaRange
	/// </summary>
	public class AntennaRelay
	{
		// We don't have a Bard, so we'll hide Kerbin here.
		private static CelestialBody _Kerbin;

		/// <summary>
		/// Fetches, caches, and returns a <see cref="CelestialBody"/> reference to Kerbin
		/// </summary>
		public static CelestialBody Kerbin
		{
			get
			{
				if (_Kerbin == null && FlightGlobals.ready)
				{
					_Kerbin = FlightGlobals.GetHomeBody();
				}

				return _Kerbin;
			}
		}

		private bool canTransmit;
		private bool isChecked;

		private IAntennaRelay nearestRelay;
		private IAntennaRelay bestOccludedRelay;

		/// <summary>
		/// The <see cref="AntennaRange.ModuleLimitedDataTransmitter"/> reference underlying this AntennaRelay, as an
		/// <see cref="AntennaRange.IAntennaRelay"/>
		/// </summary>
		protected IAntennaRelay moduleRef;

		/// <summary>
		/// Gets the parent Vessel.
		/// </summary>
		/// <value>The parent Vessel.</value>
		public virtual Vessel vessel
		{
			get
			{
				return this.moduleRef.vessel;
			}
		}

		/// <summary>
		/// Gets the target <see cref="AntennaRange.IAntennaRelay"/>relay.
		/// </summary>
		public IAntennaRelay targetRelay
		{
			get;
			protected set;
		}

		/// <summary>
		/// Gets the first <see cref="CelestialBody"/> found to be blocking line of sight.
		/// </summary>
		public virtual CelestialBody firstOccludingBody
		{
			get;
			protected set;
		}

		/// <summary>
		/// Gets the transmit distance.
		/// </summary>
		/// <value>The transmit distance.</value>
		public double transmitDistance
		{
			get
			{
				if (this.KerbinDirect || this.targetRelay == null)
				{
					return this.DistanceTo(Kerbin);
				}
				else
				{
					return this.DistanceTo(this.targetRelay);
				}
			}
		}

		/// <summary>
		/// Gets the nominal transmit distance at which the Antenna behaves just as prescribed by Squad's config.
		/// </summary>
		public virtual double nominalTransmitDistance
		{
			get;
			set;
		}

		/// <summary>
		/// The maximum distance at which this relay can operate.
		/// </summary>
		/// <value>The max transmit distance.</value>
		public virtual double maxTransmitDistance
		{
			get;
			set;
		}

		/// <summary>
		/// Gets a value indicating whether this <see cref="AntennaRange.IAntennaRelay"/> Relay is communicating
		/// directly with Kerbin.
		/// </summary>
		public virtual bool KerbinDirect
		{
			get;
			protected set;
		}

		/// <summary>
		/// Determines whether this instance can transmit.
		/// </summary>
		/// <returns><c>true</c> if this instance can transmit; otherwise, <c>false</c>.</returns>
		public virtual bool CanTransmit()
		{
			return this.canTransmit;
		}

		/// <summary>
		/// Finds the nearest relay.
		/// </summary>
		/// <returns>The nearest relay or null, if no relays in range.</returns>
		public void FindNearestRelay()
		{
			if (!FlightGlobals.ready)
			{
				return;
			}

			Tools.DebugLogger log;
			#if DEBUG
			log = Tools.DebugLogger.New(this);
			#endif

			// Skip vessels that have already been checked for a nearest relay this pass.
			if (this.isChecked)
			{
				log.AppendFormat("{0}: Target search skipped because our vessel has been checked already this search.",
					this);
				log.Print();
				return;
			}

			log.AppendFormat("{0}: Target search started).", this.ToString());

			#if DEBUG
			try {
			#endif
			// Set this vessel as checked, so that we don't check it again.
			this.isChecked = true;

			// Blank everything we're trying to find before the search.
			this.firstOccludingBody = null;
			this.bestOccludedRelay = null;
			this.targetRelay = null;
			this.nearestRelay = null;

			// Default to KerbinDirect = true in case something in here doesn't work right.
			this.KerbinDirect = true;

			CelestialBody bodyOccludingBestOccludedRelay = null;
			IAntennaRelay needle;

			double nearestRelaySqrDistance = double.PositiveInfinity;
			double bestOccludedSqrDistance = double.PositiveInfinity;
			double maxTransmitSqrDistance = this.maxTransmitDistance * this.maxTransmitDistance;

			/*
			 * Loop through all the vessels and exclude this vessel, vessels of the wrong type, and vessels that are too
			 * far away.  When we find a candidate, get through its antennae for relays which have not been checked yet
			 * and that can transmit.  Once we find a suitable candidate, assign it to nearestRelay for comparison
			 * against future finds.
			 * */
			Vessel potentialVessel;
			IAntennaRelay potentialBestRelay;
			CelestialBody fob;

			// IList<IAntennaRelay> vesselRelays;
			for (int vIdx = 0; vIdx < FlightGlobals.Vessels.Count; vIdx++)
			{
				log.AppendFormat("\nFetching vessel at index {0}", vIdx);
				potentialVessel = FlightGlobals.Vessels[vIdx];
				
				if (potentialVessel == null)
				{
					Tools.PostErrorMessage("{0}: Skipping vessel at index {1} because it is null.", this, vIdx);
					log.AppendFormat("\n\tSkipping vessel at index {0} because it is null.", vIdx);
					log.Print();
					return;
				}
				#if DEBUG
				else
				{
					log.AppendFormat("\n\tGot vessel {0}", potentialVessel);
				}
				#endif

				// Skip vessels of the wrong type.
				log.Append("\n\tchecking vessel type");
				switch (potentialVessel.vesselType)
				{
					case VesselType.Debris:
					case VesselType.Flag:
					case VesselType.EVA:
					case VesselType.SpaceObject:
					case VesselType.Unknown:
							log.Append("\n\tSkipping because vessel is the wrong type.");
						continue;
					default:
						break;
				}
				
				log.Append("\n\tchecking if vessel is this vessel");
				// Skip vessels with the wrong ID
				if (potentialVessel.id == vessel.id)
				{
					log.Append("\n\tSkipping because vessel is this vessel.");
					continue;
				}

				// Find the distance from here to the vessel...
				log.Append("\n\tgetting distance to potential vessel");
				double potentialSqrDistance = this.sqrDistanceTo(potentialVessel);
				log.Append("\n\tgetting best vessel relay");

				potentialBestRelay = potentialVessel.GetBestRelay();
				log.AppendFormat("\n\t\tgot best vessel relay {0}",
					potentialBestRelay == null ? "null" : potentialBestRelay.ToString());

				if (potentialBestRelay == null)
				{
					log.Append("\n\t\t...skipping null relay");
					continue;
				}

				log.Append("\n\t\tdoing LOS check");
				// Skip vessels to which we do not have line of sight.
				if (
					ARConfiguration.RequireLineOfSight &&
					!this.vessel.hasLineOfSightTo(potentialVessel, out fob, ARConfiguration.RadiusRatio)
				)
				{
					log.Append("\n\t\t...failed LOS check");

					log.AppendFormat("\n\t\t\t{0}: Vessel {1} not in line of sight.",
						this.ToString(), potentialVessel.vesselName);
					
					log.AppendFormat("\n\t\t\tpotentialSqrDistance: {0}", potentialSqrDistance);
					log.AppendFormat("\n\t\t\tbestOccludedSqrDistance: {0}", bestOccludedSqrDistance);
					log.AppendFormat("\n\t\t\tmaxTransmitSqrDistance: {0}", maxTransmitSqrDistance);

					if (
						(potentialSqrDistance < bestOccludedSqrDistance) &&
						(potentialSqrDistance < maxTransmitSqrDistance) &&
						potentialBestRelay.CanTransmit()
					)
					{
						log.Append("\n\t\t...vessel is close enough to and potentialBestRelay can transmit");
						log.AppendFormat("\n\t\t...{0} found new best occluded relay {1}", this, potentialBestRelay);

						this.bestOccludedRelay = potentialBestRelay;
						bodyOccludingBestOccludedRelay = fob;
						bestOccludedSqrDistance = potentialSqrDistance;
					}
					else
					{
						log.Append("\n\t\t...vessel is not close enough to check for occluded relays, carrying on");
					}
					
					continue;
				}

				log.Append("\n\t\t...passed LOS check");

				/*
				 * ...so that we can skip the vessel if it is further away than a vessel we've already checked.
				 * */
				if (potentialSqrDistance > nearestRelaySqrDistance)
				{
					
					log.AppendFormat("\n\t{0}: Vessel {1} discarded because it is farther than another the nearest relay.",
						this.ToString(),
						potentialVessel.vesselName
					);
					continue;
				}

				log.Append("\n\t\t...passed distance check");

				if (potentialBestRelay.CanTransmit())
				{
					needle = potentialBestRelay;
					bool isCircular = false;

					while (needle != null)
					{
						if (needle.KerbinDirect)
						{
							break;
						}

						if (needle.targetRelay == null)
						{
							break;
						}

						if (needle.targetRelay.vessel == this.vessel || needle == this.moduleRef)
						{
							isCircular = true;
							break;
						}

						needle = needle.targetRelay;
					}

					if (!isCircular)
					{
						nearestRelaySqrDistance = potentialSqrDistance;
						this.nearestRelay = potentialBestRelay;

						log.AppendFormat("\n\t{0}: found new nearest relay {1} ({2}m)",
							this.ToString(),
							this.nearestRelay.ToString(),
							Math.Sqrt(nearestRelaySqrDistance)
						);
					}
					else
					{
						log.AppendFormat("\n\t\t...connection to {0} would result in a circular network, skipping",
							potentialBestRelay
						);
					}
				}
			}

			CelestialBody bodyOccludingKerbin = null;

			double kerbinSqrDistance = this.vessel.DistanceTo(Kerbin) - Kerbin.Radius;
			kerbinSqrDistance *= kerbinSqrDistance;

			log.AppendFormat("\n{0} ({1}): Search done, figuring status.", this.ToString(), this.GetType().Name);
			log.AppendFormat(
				"\n{0}: nearestRelay={1} ({2}m²)), bestOccludedRelay={3} ({4}m²), kerbinSqrDistance={5}m²)",
				this,
				this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
				nearestRelaySqrDistance,
				this.bestOccludedRelay == null ? "null" : this.bestOccludedRelay.ToString(),
				bestOccludedSqrDistance,
				kerbinSqrDistance
			);

			// If we don't have LOS to Kerbin, focus on relays
			if (!this.vessel.hasLineOfSightTo(Kerbin, out bodyOccludingKerbin, ARConfiguration.RadiusRatio))
			{
				log.AppendFormat("\n\tKerbin LOS is blocked by {0}.", bodyOccludingKerbin.bodyName);

				// nearestRelaySqrDistance will be infinity if all relays are occluded or none exist.
				// Therefore, this will only be true if a valid relay is in range.
				if (nearestRelaySqrDistance <= maxTransmitSqrDistance)
				{
					log.AppendFormat("\n\t\tCan transmit to nearby relay {0} ({1} <= {2}).",
						this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
							nearestRelaySqrDistance, maxTransmitSqrDistance);

					this.KerbinDirect = false;
					this.canTransmit = true;
					this.targetRelay = this.nearestRelay;
				}
				// If this isn't true, we can't transmit, but pick a second best of bestOccludedRelay and Kerbin anyway
				else
				{
					log.AppendFormat("\n\t\tCan't transmit to nearby relay {0} ({1} > {2}).",
						this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
							nearestRelaySqrDistance, maxTransmitSqrDistance);

					this.canTransmit = false;

					// If the best occluded relay is closer than Kerbin, check it against the nearest relay.
					// Since bestOccludedSqrDistance is infinity if there are no occluded relays, this is safe
					if (bestOccludedSqrDistance < kerbinSqrDistance)
					{
						log.AppendFormat("\n\t\t\tBest occluded relay is closer than Kerbin ({0} < {1})",
							bestOccludedRelay, kerbinSqrDistance);
						
						this.KerbinDirect = false;

						// If the nearest relay is closer than the best occluded relay, pick it.
						// Since nearestRelaySqrDistane is infinity if there are no nearby relays, this is safe.
						if (nearestRelaySqrDistance < bestOccludedSqrDistance)
						{
							log.AppendFormat("\n\t\t\t\t...but the nearest relay is closer ({0} < {1}), so picking it.",
								nearestRelaySqrDistance, bestOccludedSqrDistance);
							
							this.targetRelay = this.nearestRelay;
							this.firstOccludingBody = null;
						}
						// Otherwise, target the best occluded relay.
						else
						{
							log.AppendFormat("\n\t\t\t\t...and closer than the nearest relay ({0} >= {1}), so picking it.",
								nearestRelaySqrDistance, bestOccludedSqrDistance);
							
							this.targetRelay = bestOccludedRelay;
							this.firstOccludingBody = bodyOccludingBestOccludedRelay;
						}
					}
					// Otherwise, check Kerbin against the nearest relay.
					// Since we have LOS, blank the first occluding body.
					else
					{
						log.AppendFormat("\n\t\t\tKerbin is closer than the best occluded relay ({0} >= {1})",
							bestOccludedRelay, kerbinSqrDistance);
						
						this.firstOccludingBody = null;

						// If the nearest relay is closer than Kerbin, pick it.
						// Since nearestRelaySqrDistane is infinity if there are no nearby relays, this is safe.
						if (nearestRelaySqrDistance < kerbinSqrDistance)
						{
							log.AppendFormat("\n\t\t\t\t...but the nearest relay is closer ({0} < {1}), so picking it.",
								nearestRelaySqrDistance, kerbinSqrDistance);
							
							this.KerbinDirect = false;
							this.targetRelay = this.nearestRelay;
						}
						// Otherwise, pick Kerbin.
						else
						{
							log.AppendFormat("\n\t\t\t\t...and closer than the nearest relay ({0} >= {1}), so picking it.",
								nearestRelaySqrDistance, kerbinSqrDistance);
							
							this.KerbinDirect = true;
							this.targetRelay = null;
						}
					}
				}
			}
			// If we do have LOS to Kerbin, try to prefer the closest of nearestRelay and Kerbin
			else
			{
				log.AppendFormat("\n\tKerbin is in LOS.");

				// If the nearest relay is closer than Kerbin and in range, transmit to it.
				if (nearestRelaySqrDistance <= maxTransmitSqrDistance)
				{
					log.AppendFormat("\n\t\tCan transmit to nearby relay {0} ({1} <= {2}).",
						this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
							nearestRelaySqrDistance, maxTransmitSqrDistance);

					this.canTransmit = true;

					// If the nearestRelay is closer than Kerbin, use it.
					if (nearestRelaySqrDistance < kerbinSqrDistance)
					{
						log.AppendFormat("\n\t\t\tPicking relay {0} over Kerbin ({1} < {2}).",
							this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
							nearestRelaySqrDistance, kerbinSqrDistance);

						this.KerbinDirect = false;
						this.targetRelay = this.nearestRelay;
					}
					// Otherwise, Kerbin is closer, so use it.
					else
					{
						log.AppendFormat("\n\t\t\tBut picking Kerbin over nearby relay {0} ({1} >= {2}).",
							this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
								nearestRelaySqrDistance, kerbinSqrDistance);

						this.KerbinDirect = true;
						this.targetRelay = null;
					}
				}
				// If the nearest relay is out of range, we still need to check on Kerbin.
				else
				{
					log.AppendFormat("\n\t\tCan't transmit to nearby relay {0} ({1} > {2}).",
						this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
							nearestRelaySqrDistance, maxTransmitSqrDistance);

					// If Kerbin is in range, use it.
					if (kerbinSqrDistance <= maxTransmitSqrDistance)
					{
						log.AppendFormat("\n\t\t\tCan transmit to Kerbin ({0} <= {1}).",
							kerbinSqrDistance, maxTransmitSqrDistance);

						this.canTransmit = true;
						this.KerbinDirect = true;
						this.targetRelay = null;
					}
					// If Kerbin is out of range and the nearest relay is out of range, pick a second best between
					// Kerbin and bestOccludedRelay
					else
					{
						log.AppendFormat("\n\t\t\tCan't transmit to Kerbin ({0} > {1}).",
							kerbinSqrDistance, maxTransmitSqrDistance);

						this.canTransmit = false;

						// If the best occluded relay is closer than Kerbin, check it against the nearest relay.
						// Since bestOccludedSqrDistance is infinity if there are no occluded relays, this is safe
						if (bestOccludedSqrDistance < kerbinSqrDistance)
						{
							log.AppendFormat("\n\t\t\tBest occluded relay is closer than Kerbin ({0} < {1})",
								bestOccludedRelay, kerbinSqrDistance);
							
							this.KerbinDirect = false;

							// If the nearest relay is closer than the best occluded relay, pick it.
							// Since nearestRelaySqrDistane is infinity if there are no nearby relays, this is safe.
							if (nearestRelaySqrDistance < bestOccludedSqrDistance)
							{
								log.AppendFormat("\n\t\t\t\t...but the nearest relay is closer ({0} < {1}), so picking it.",
									nearestRelaySqrDistance, bestOccludedSqrDistance);
								
								this.targetRelay = this.nearestRelay;
								this.firstOccludingBody = null;
							}
							// Otherwise, target the best occluded relay.
							else
							{
								log.AppendFormat("\n\t\t\t\t...and closer than the nearest relay ({0} >= {1}), so picking it.",
									nearestRelaySqrDistance, bestOccludedSqrDistance);
								
								this.targetRelay = bestOccludedRelay;
								this.firstOccludingBody = bodyOccludingBestOccludedRelay;
							}
						}
						// Otherwise, check Kerbin against the nearest relay.
						// Since we have LOS, blank the first occluding body.
						else
						{
							log.AppendFormat("\n\t\t\tKerbin is closer than the best occluded relay ({0} >= {1})",
								bestOccludedRelay, kerbinSqrDistance);
							
							this.firstOccludingBody = null;

							// If the nearest relay is closer than Kerbin, pick it.
							// Since nearestRelaySqrDistane is infinity if there are no nearby relays, this is safe.
							if (nearestRelaySqrDistance < kerbinSqrDistance)
							{
								log.AppendFormat("\n\t\t\t\t...but the nearest relay is closer ({0} < {1}), so picking it.",
									nearestRelaySqrDistance, kerbinSqrDistance);
								
								this.KerbinDirect = false;
								this.targetRelay = this.nearestRelay;
							}
							// Otherwise, pick Kerbin.
							else
							{
								log.AppendFormat("\n\t\t\t\t...and closer than the nearest relay ({0} >= {1}), so picking it.",
									nearestRelaySqrDistance, kerbinSqrDistance);
								
								this.KerbinDirect = true;
								this.targetRelay = null;
							}
						}
					}
				}
			}

			log.AppendFormat("\n{0}: Target search and status determination complete.", this.ToString());
			
			#if DEBUG
			} catch (Exception ex) {
				log.AppendFormat("\nCaught {0}: {1}\n{2}", ex.GetType().FullName, ex.ToString(), ex.StackTrace);
			#if QUIT_ON_EXCEPTION
				UnityEngine.Application.Quit();
			#endif
			} finally {
			#endif
			log.Print(false);
			#if DEBUG
			}
			#endif
			// Now that we're done with our recursive CanTransmit checks, flag this relay as not checked so it can be
			// used next time.
			this.isChecked = false;
		}

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents the current <see cref="AntennaRange.AntennaRelay"/>.
		/// </summary>
		/// <returns>A <see cref="System.String"/> that represents the current <see cref="AntennaRange.AntennaRelay"/>.</returns>
		public override string ToString()
		{
			if (this is ProtoAntennaRelay)
			{
				return (this as ProtoAntennaRelay).ToString();
			}
			return this.moduleRef.ToString();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="AntennaRange.AntennaRelay"/> class.
		/// </summary>
		/// <param name="module">The module reference underlying this AntennaRelay,
		/// as an <see cref="AntennaRange.IAntennaRelay"/></param>
		public AntennaRelay(IAntennaRelay module)
		{
			this.moduleRef = module;
			this.isChecked = false;

			Tools.PostLogMessage("{0}: constructed {1}", this.GetType().Name, this.ToString());
		}
	}
}