forked from MikeG621/Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseFlightGroup.BaseWaypoint.cs
114 lines (106 loc) · 3.85 KB
/
BaseFlightGroup.BaseWaypoint.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Idmr.Platform.dll, X-wing series mission library file, XW95-XWA
* Copyright (C) 2009-2018 Michael Gaisser ([email protected])
* Licensed under the MPL v2.0 or later
*
* Full notice in ../help/Idmr.Platform.chm
* Version: 2.1
*/
/* CHANGELOG
* v2.1, 141214
* [UPD] change to MPL
* v2.0, 120525
* - Release
*/
using System;
using Idmr.Common;
namespace Idmr.Platform
{
public abstract partial class BaseFlightGroup
{
/// <summary>Base class for FlightGroup waypoints</summary>
[Serializable] public abstract class BaseWaypoint : Indexer<short>
{
/// <summary>Default constructor for derived classes</summary>
protected BaseWaypoint() { /* do nothing */ }
/// <summary>Default constructor for derived classes</summary>
/// <param name="raw">Raw data</param>
protected BaseWaypoint(short[] raw) : base(raw) { /* do nothing */ }
/// <summary>Returns a representative string of the Waypoint</summary>
/// <returns>Waypoint coordinates in the form of <b>"(X, Y, Z)"</b>if enabled, otherwise <b>"Disabled"</b></returns>
public override string ToString() { return (Enabled ? "(" + X + ", " + Y + ", " + Z + ") " : "Disabled"); }
#region public properties
/// <summary>Array form of the waypoint</summary>
/// <remarks><see cref="Enabled"/> restricted to <b>0</b> and <b>1</b>, <see cref="Idmr.Platform.Xwa.FlightGroup.Waypoint.Region"/> restricted to <b>0-3</b>. No effect for invalid values</remarks>
/// <param name="index">X, Y, Z, Enabled, Region (XWA only)</param>
/// <exception cref="IndexOutOfRangeException">Invalid <i>index</i> value</exception>
public override short this[int index]
{
get { return _items[index]; }
set
{
if (index == 3 && value != 0) _items[index] = 1;
else if (Length == 5 && index == 4 && (value < 0 || value > 3)) return;
else _items[index] = value;
}
}
/// <summary>Gets or sets if the Waypoint is active for use</summary>
public bool Enabled
{
get { return Convert.ToBoolean(_items[3]); }
set { _items[3] = Convert.ToInt16(value); }
}
/// <summary>Gets or sets the stored X value</summary>
public short RawX
{
get { return _items[0]; }
set { _items[0] = value; }
}
/// <summary>Gets or sets the stored Y value</summary>
/// <remarks>Is multipled by -1 during read/write to plot as positive-Y-Up in map and briefing.</remarks>
public short RawY
{
get { return _items[1]; }
set { _items[1] = value; }
}
/// <summary>Gets or sets the stored Z value</summary>
public short RawZ
{
get { return _items[2]; }
set { _items[2] = value; }
}
/// <summary>Gets or sets the X value in kilometers</summary>
/// <remarks>Equals <see cref="RawX"/> divided by 160</remarks>
public double X
{
get { return (double)RawX / 160; }
set { RawX = (short)(value * 160); }
}
/// <summary>Gets or sets the Y value in kilometers</summary>
/// <remarks>Equals <see cref="RawY"/> divided by 160</remarks>
public double Y
{
get { return (double)RawY / 160; }
set { RawY = (short)(value * 160); }
}
/// <summary>Gets or sets the Z value in kilometers</summary>
/// <remarks>Equals <see cref="RawZ"/> divided by 160</remarks>
public double Z
{
get { return (double)RawZ / 160; }
set { RawZ = (short)(value * 160); }
}
#endregion public properties
/// <summary>Converts a waypoint to a short array</summary>
/// <remarks>Always returns Length 4 array, even for XWA, due to how values are stored in the file</remarks>
/// <param name="wp">The waypoint to convert</param>
/// <returns>An array of shorts containing <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/> and <see cref="Enabled"/></returns>
public static explicit operator short[](BaseWaypoint wp)
{
short[] s = new short[4];
for (int i = 0; i < 4; i++) s[i] = wp[i];
return s;
}
}
}
}