| 1 |
# ============================================================================== |
| 2 |
# K14 Reticle |
| 3 |
# ============================================================================== |
| 4 |
|
| 5 |
var propertyTreeRoot = "/controls/armament/gunsight/"; |
| 6 |
var sideEdge = 0.08; |
| 7 |
var zCenterLine = getprop(propertyTreeRoot, "zCenterLine"); |
| 8 |
var topEdge = zCenterLine + 0.04; |
| 9 |
|
| 10 |
var pipperVisibility = func() |
| 11 |
{ |
| 12 |
if (getprop(propertyTreeRoot, "reticleSelectorPos") < 2 and |
| 13 |
getprop(propertyTreeRoot, "power-on") != 0 and |
| 14 |
getprop("/controls/engines/engine/master-bat") == 1) |
| 15 |
{ |
| 16 |
setprop(propertyTreeRoot, "fixedReticleOn", 1); |
| 17 |
} |
| 18 |
else |
| 19 |
{ |
| 20 |
setprop(propertyTreeRoot, "fixedReticleOn", 0); |
| 21 |
} |
| 22 |
|
| 23 |
if (getprop(propertyTreeRoot, "computer-on") == 1 and |
| 24 |
getprop(propertyTreeRoot, "reticleSelectorPos") > 0 and |
| 25 |
getprop(propertyTreeRoot, "power-on") != 0 and |
| 26 |
getprop("/controls/engines/engine/master-bat") == 1) |
| 27 |
{ |
| 28 |
var elevation = call(func getprop(propertyTreeRoot, "elevation"), var err = []); |
| 29 |
if (!size(err)) |
| 30 |
{ |
| 31 |
elevation = elevation * 0.401885 + zCenterLine; |
| 32 |
var azimuth = call(func getprop(propertyTreeRoot, "azimuth"), var err1 = []); |
| 33 |
if (!size(err1)) |
| 34 |
{ |
| 35 |
azimuth = azimuth * 0.401885; |
| 36 |
var ringSize = call(func getprop(propertyTreeRoot, "rangeRingSize"), var err2 = []); |
| 37 |
if (!size(err2)) |
| 38 |
{ |
| 39 |
if (elevation + ringSize > topEdge |
| 40 |
or (azimuth > 0 and azimuth > sideEdge) |
| 41 |
or (azimuth < 0 and azimuth < -sideEdge)) |
| 42 |
{ |
| 43 |
setprop(propertyTreeRoot, "diamondTopVisibility", 0); |
| 44 |
} |
| 45 |
else |
| 46 |
{ |
| 47 |
setprop(propertyTreeRoot, "diamondTopVisibility", 1); |
| 48 |
} |
| 49 |
|
| 50 |
if (elevation - ringSize > topEdge |
| 51 |
or (azimuth > 0 and azimuth > sideEdge) |
| 52 |
or (azimuth < 0 and azimuth < -sideEdge)) |
| 53 |
{ |
| 54 |
setprop(propertyTreeRoot, "diamondBottomVisibility", 0); |
| 55 |
} |
| 56 |
else |
| 57 |
{ |
| 58 |
setprop(propertyTreeRoot, "diamondBottomVisibility", 1); |
| 59 |
} |
| 60 |
|
| 61 |
if (elevation + (0.5 * ringSize) > topEdge |
| 62 |
or (azimuth > 0 and azimuth + (0.866025 * ringSize) > sideEdge) |
| 63 |
or (azimuth < 0 and azimuth + (0.866025 * ringSize) < -sideEdge)) |
| 64 |
{ |
| 65 |
setprop(propertyTreeRoot, "diamondURVisibility", 0); |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
setprop(propertyTreeRoot, "diamondURVisibility", 1); |
| 70 |
} |
| 71 |
|
| 72 |
if (elevation + (0.5 * ringSize) > topEdge |
| 73 |
or (azimuth < 0 and azimuth - (0.866025 * ringSize) < -sideEdge) |
| 74 |
or (azimuth > 0 and azimuth - (0.866025 * ringSize) > sideEdge)) |
| 75 |
{ |
| 76 |
setprop(propertyTreeRoot, "diamondULVisibility", 0); |
| 77 |
} |
| 78 |
else |
| 79 |
{ |
| 80 |
setprop(propertyTreeRoot, "diamondULVisibility", 1); |
| 81 |
} |
| 82 |
|
| 83 |
if (elevation - (0.5 * ringSize) > topEdge |
| 84 |
or (azimuth > 0 and azimuth + (0.866025 * ringSize) > sideEdge) |
| 85 |
or (azimuth < 0 and azimuth + (0.866025 * ringSize) < -sideEdge)) |
| 86 |
{ |
| 87 |
setprop(propertyTreeRoot, "diamondLRVisibility", 0); |
| 88 |
} |
| 89 |
else |
| 90 |
{ |
| 91 |
setprop(propertyTreeRoot, "diamondLRVisibility", 1); |
| 92 |
} |
| 93 |
|
| 94 |
if (elevation - (0.5 * ringSize) > topEdge |
| 95 |
or (azimuth < 0 and azimuth - (0.866025 * ringSize) < -sideEdge) |
| 96 |
or (azimuth > 0 and azimuth - (0.866025 * ringSize) > sideEdge)) |
| 97 |
{ |
| 98 |
setprop(propertyTreeRoot, "diamondLLVisibility", 0); |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
setprop(propertyTreeRoot, "diamondLLVisibility", 1); |
| 103 |
} |
| 104 |
|
| 105 |
if (elevation > topEdge |
| 106 |
or (azimuth > 0 and azimuth > sideEdge) |
| 107 |
or (azimuth < 0 and azimuth < -sideEdge)) |
| 108 |
{ |
| 109 |
setprop(propertyTreeRoot, "pipperVisibility", 0); |
| 110 |
} |
| 111 |
else |
| 112 |
{ |
| 113 |
setprop(propertyTreeRoot, "pipperVisibility", 1); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
else |
| 120 |
{ |
| 121 |
setprop(propertyTreeRoot, "diamondTopVisibility", 0); |
| 122 |
setprop(propertyTreeRoot, "diamondBottomVisibility", 0); |
| 123 |
setprop(propertyTreeRoot, "diamondURVisibility", 0); |
| 124 |
setprop(propertyTreeRoot, "diamondULVisibility", 0); |
| 125 |
setprop(propertyTreeRoot, "diamondLRVisibility", 0); |
| 126 |
setprop(propertyTreeRoot, "diamondLLVisibility", 0); |
| 127 |
setprop(propertyTreeRoot, "pipperVisibility", 0); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
var scaleRangeFindingReticle = func() |
| 132 |
{ |
| 133 |
if (getprop(propertyTreeRoot, "gunsightComputerInitialized") == 1) |
| 134 |
{ |
| 135 |
var span = getprop(propertyTreeRoot, "span"); |
| 136 |
if (span < 30) |
| 137 |
{ |
| 138 |
setprop(propertyTreeRoot, "span", 30); |
| 139 |
} |
| 140 |
else if (span > 120) |
| 141 |
{ |
| 142 |
setprop(propertyTreeRoot, "span", 120); |
| 143 |
} |
| 144 |
|
| 145 |
var range = getprop(propertyTreeRoot, "range"); |
| 146 |
if (range < 600) |
| 147 |
{ |
| 148 |
setprop(propertyTreeRoot, "range", 600); |
| 149 |
} |
| 150 |
else if (range > 2400) |
| 151 |
{ |
| 152 |
setprop(propertyTreeRoot, "range", 2400); |
| 153 |
} |
| 154 |
|
| 155 |
var mils = 1000 * (span / range); |
| 156 |
setprop(propertyTreeRoot, "mils", mils); |
| 157 |
var newRangeRingSize = 0.00019 * mils; # scale mils to meters |
| 158 |
setprop(propertyTreeRoot, "rangeRingSize", newRangeRingSize); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
setlistener("/controls/armament/gunsight/gunsightComputerInitialized", scaleRangeFindingReticle, 1, 0); |
| 163 |
setlistener("/controls/armament/gunsight/span", scaleRangeFindingReticle, 1, 0); |
| 164 |
setlistener("/controls/armament/gunsight/range", scaleRangeFindingReticle, 1, 0); |
| 165 |
setlistener("/controls/armament/gunsight/elevation", pipperVisibility, 1, 0); |
| 166 |
setlistener("/controls/armament/gunsight/gunsightComputerInitialized", pipperVisibility, 1, 0); |
| 167 |
setlistener("/controls/armament/gunsight/reticleSelectorPos", pipperVisibility, 1, 0); |
| 168 |
setlistener("/controls/armament/gunsight/power-on", pipperVisibility, 1, 0); |