@clunkyard/sdk 0.0.0-stage → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/words.js ADDED
@@ -0,0 +1,265 @@
1
+ 'use strict';
2
+ // Generated from protocol/v2/api.json by protocol/v2/codegen/dsl.js; do not edit. Run `make api`.
3
+ //
4
+ // The DSL words, as the core gives them: one f64 a word in the record
5
+ // cy_dsl_words_v1 (776 bytes), which cy_dsl_fill_v1 fills once a
6
+ // turn, outside the DSL budget. read() turns it into the interpreter's words;
7
+ // booleans are booleans and enums their protocol 2 names, except where the
8
+ // DSL keeps an older spelling (control-model reads "targets" for direct).
9
+ // Older names (ALIASES) read the same slot. CONTROLS maps each DSL action
10
+ // keyword to the core setter for its act field; the core clamps and writes
11
+ // the act.
12
+
13
+ const API_VERSION = '2.0.0';
14
+ const RECORD = 'cy_dsl_words_v1';
15
+ const SIZE = 776;
16
+ // The Tracker keeps a passive cue this many ticks.
17
+ const CUE_TICKS = 60;
18
+ // What a distance reads when the thing it measures to is absent.
19
+ const FAR = 1000000000000;
20
+
21
+ const RULESET = Object.freeze([null, "classic", "inertial-2d", "gravity-flat", "gravity-hills", "zero-g"]);
22
+ const CONTROL = Object.freeze([null, "targets", "forces"]);
23
+ const TERRAIN_KIND = Object.freeze([null, "none", "flat", "hills"]);
24
+
25
+ const WORDS = Object.freeze([
26
+ { name: "ruleset", index: 0, type: 'text', enum: 'ruleset' },
27
+ { name: "physics-mode", index: 1, type: 'boolean' },
28
+ { name: "zero-g", index: 2, type: 'boolean' },
29
+ { name: "control-model", index: 3, type: 'text', enum: 'control' },
30
+ { name: "inertial", index: 4, type: 'boolean' },
31
+ { name: "mode3", index: 5, type: 'boolean' },
32
+ { name: "tick", index: 6, type: 'number' },
33
+ { name: "time", index: 7, type: 'number' },
34
+ { name: "remaining", index: 8, type: 'number' },
35
+ { name: "width", index: 9, type: 'number' },
36
+ { name: "height", index: 10, type: 'number' },
37
+ { name: "depth", index: 11, type: 'number' },
38
+ { name: "gravity-x", index: 12, type: 'number' },
39
+ { name: "gravity-y", index: 13, type: 'number' },
40
+ { name: "gravity-z", index: 14, type: 'number' },
41
+ { name: "terrain-kind", index: 15, type: 'text', enum: 'terrain_kind' },
42
+ { name: "hills", index: 16, type: 'boolean' },
43
+ { name: "health", index: 17, type: 'number' },
44
+ { name: "x", index: 18, type: 'number' },
45
+ { name: "y", index: 19, type: 'number' },
46
+ { name: "z", index: 20, type: 'number' },
47
+ { name: "vx", index: 21, type: 'number' },
48
+ { name: "vy", index: 22, type: 'number' },
49
+ { name: "vz", index: 23, type: 'number' },
50
+ { name: "heading", index: 24, type: 'number' },
51
+ { name: "pitch", index: 25, type: 'number' },
52
+ { name: "yaw-rate", index: 26, type: 'number' },
53
+ { name: "pitch-rate", index: 27, type: 'number' },
54
+ { name: "roll-rate", index: 28, type: 'number' },
55
+ { name: "forward-x", index: 29, type: 'number' },
56
+ { name: "forward-y", index: 30, type: 'number' },
57
+ { name: "forward-z", index: 31, type: 'number' },
58
+ { name: "right-x", index: 32, type: 'number' },
59
+ { name: "right-y", index: 33, type: 'number' },
60
+ { name: "right-z", index: 34, type: 'number' },
61
+ { name: "up-x", index: 35, type: 'number' },
62
+ { name: "up-y", index: 36, type: 'number' },
63
+ { name: "up-z", index: 37, type: 'number' },
64
+ { name: "grounded", index: 38, type: 'boolean' },
65
+ { name: "altitude", index: 39, type: 'number' },
66
+ { name: "battery", index: 40, type: 'number' },
67
+ { name: "battery-capacity", index: 41, type: 'number' },
68
+ { name: "aim", index: 42, type: 'number' },
69
+ { name: "aim-pitch", index: 43, type: 'number' },
70
+ { name: "cooldown", index: 44, type: 'number' },
71
+ { name: "scan-heading", index: 45, type: 'number' },
72
+ { name: "scan-pitch", index: 46, type: 'number' },
73
+ { name: "scan-arc", index: 47, type: 'number' },
74
+ { name: "scan-range", index: 48, type: 'number' },
75
+ { name: "contact", index: 49, type: 'boolean' },
76
+ { name: "range", index: 50, type: 'number' },
77
+ { name: "bearing", index: 51, type: 'number' },
78
+ { name: "elevation", index: 52, type: 'number' },
79
+ { name: "cue-present", index: 53, type: 'boolean' },
80
+ { name: "cue-error", index: 54, type: 'number' },
81
+ { name: "bearing-rate", index: 55, type: 'number' },
82
+ { name: "zone-active", index: 56, type: 'boolean' },
83
+ { name: "zone-radius", index: 57, type: 'number' },
84
+ { name: "storm-active", index: 58, type: 'boolean' },
85
+ { name: "storm-radius", index: 59, type: 'number' },
86
+ { name: "hill-active", index: 60, type: 'boolean' },
87
+ { name: "hill-radius", index: 61, type: 'number' },
88
+ { name: "score", index: 62, type: 'number' },
89
+ { name: "score-best", index: 63, type: 'number' },
90
+ { name: "speed", index: 64, type: 'number' },
91
+ { name: "gravity", index: 65, type: 'boolean' },
92
+ { name: "terrain-height", index: 66, type: 'number' },
93
+ { name: "battery-fraction", index: 67, type: 'number' },
94
+ { name: "aim-error", index: 68, type: 'number' },
95
+ { name: "power-min", index: 69, type: 'number' },
96
+ { name: "power-max", index: 70, type: 'number' },
97
+ { name: "shot-speed-base", index: 71, type: 'number' },
98
+ { name: "shot-speed-per-power", index: 72, type: 'number' },
99
+ { name: "shot-cost-base", index: 73, type: 'number' },
100
+ { name: "shot-cost-per-power", index: 74, type: 'number' },
101
+ { name: "zone-distance", index: 75, type: 'number' },
102
+ { name: "zone-bearing", index: 76, type: 'number' },
103
+ { name: "zone-elevation", index: 77, type: 'number' },
104
+ { name: "storm-distance", index: 78, type: 'number' },
105
+ { name: "storm-bearing", index: 79, type: 'number' },
106
+ { name: "storm-heading", index: 80, type: 'number' },
107
+ { name: "cue-muzzle", index: 81, type: 'boolean' },
108
+ { name: "cue-bearing", index: 82, type: 'number' },
109
+ { name: "cue-elevation", index: 83, type: 'number' },
110
+ { name: "cue-range", index: 84, type: 'number' },
111
+ { name: "cue-age", index: 85, type: 'number' },
112
+ { name: "pickup-present", index: 86, type: 'boolean' },
113
+ { name: "pickup-bearing", index: 87, type: 'number' },
114
+ { name: "pickup-elevation", index: 88, type: 'number' },
115
+ { name: "pickup-range", index: 89, type: 'number' },
116
+ { name: "on-hill", index: 90, type: 'boolean' },
117
+ { name: "hill-held", index: 91, type: 'boolean' },
118
+ { name: "hill-bearing", index: 92, type: 'number' },
119
+ { name: "hill-elevation", index: 93, type: 'number' },
120
+ { name: "hill-range", index: 94, type: 'number' },
121
+ { name: "hill-time", index: 95, type: 'number' },
122
+ { name: "hill-to-win", index: 96, type: 'number' },
123
+ ]);
124
+
125
+ const ALIASES = Object.freeze({
126
+ energy: "battery",
127
+ "max-energy": "battery-capacity",
128
+ "energy-fraction": "battery-fraction",
129
+ "fire-base": "shot-cost-base",
130
+ "fire-per-power": "shot-cost-per-power",
131
+ });
132
+
133
+ const CONTROLS = Object.freeze({
134
+ drive: { symbol: 'cy_drive_throttle', act: ["drive","throttle"], type: 'number', glyph: "drive!" },
135
+ turn: { symbol: 'cy_drive_turn', act: ["drive","turn"], type: 'number', glyph: "turn!" },
136
+ pitch: { symbol: 'cy_drive_pitch_turn', act: ["drive","pitchTurn"], type: 'number', glyph: "pitch-turn!" },
137
+ thrust: { symbol: 'cy_drive_thrust', act: ["forces","thrust"], type: 'number', glyph: "thrust!" },
138
+ strafe: { symbol: 'cy_drive_strafe', act: ["forces","strafe"], type: 'number', glyph: "strafe!" },
139
+ lift: { symbol: 'cy_drive_lift', act: ["forces","lift"], type: 'number', glyph: "lift!" },
140
+ "yaw-torque": { symbol: 'cy_drive_yaw_torque', act: ["forces","yawTorque"], type: 'number', glyph: "yaw-torque!" },
141
+ "pitch-torque": { symbol: 'cy_drive_pitch_torque', act: ["forces","pitchTorque"], type: 'number', glyph: "pitch-torque!" },
142
+ "roll-torque": { symbol: 'cy_drive_roll_torque', act: ["forces","rollTorque"], type: 'number', glyph: "roll-torque!" },
143
+ brake: { symbol: 'cy_drive_brake', act: ["forces","brake"], type: 'number', glyph: "brake!" },
144
+ "aim-heading": { symbol: 'cy_gun_aim_heading', act: ["aim","heading"], type: 'number', glyph: "aim!" },
145
+ "aim-pitch": { symbol: 'cy_gun_aim_pitch', act: ["aim","pitch"], type: 'number', glyph: "aim-pitch!" },
146
+ fire: { symbol: 'cy_gun_fire', act: ["fire",null], type: 'flag', glyph: "fire!" },
147
+ power: { symbol: 'cy_gun_power', act: ["fire","power"], type: 'number', glyph: "power!" },
148
+ "scan-heading": { symbol: 'cy_scanner_heading', act: ["scan","heading"], type: 'number', glyph: "scan-heading!" },
149
+ "scan-arc": { symbol: 'cy_scanner_arc', act: ["scan","arc"], type: 'number', glyph: "scan-arc!" },
150
+ "scan-pitch": { symbol: 'cy_scanner_pitch', act: ["scan","pitch"], type: 'number', glyph: "scan-pitch!" },
151
+ "status-text": { symbol: 'cy_status_text', act: ["status","text"], type: 'text', glyph: "status-text!" },
152
+ "status-value": { symbol: 'cy_status_value', act: ["status","value"], type: 'number', glyph: "status-value!" },
153
+ });
154
+
155
+ // The words from the record: w is a Float64Array (or an array of numbers)
156
+ // holding it at element base.
157
+ function read(w, base = 0) {
158
+ const words = {
159
+ ruleset: RULESET[w[base + 0]] ?? null,
160
+ "physics-mode": w[base + 1] !== 0,
161
+ "zero-g": w[base + 2] !== 0,
162
+ "control-model": CONTROL[w[base + 3]] ?? null,
163
+ inertial: w[base + 4] !== 0,
164
+ mode3: w[base + 5] !== 0,
165
+ tick: w[base + 6],
166
+ time: w[base + 7],
167
+ remaining: w[base + 8],
168
+ width: w[base + 9],
169
+ height: w[base + 10],
170
+ depth: w[base + 11],
171
+ "gravity-x": w[base + 12],
172
+ "gravity-y": w[base + 13],
173
+ "gravity-z": w[base + 14],
174
+ "terrain-kind": TERRAIN_KIND[w[base + 15]] ?? null,
175
+ hills: w[base + 16] !== 0,
176
+ health: w[base + 17],
177
+ x: w[base + 18],
178
+ y: w[base + 19],
179
+ z: w[base + 20],
180
+ vx: w[base + 21],
181
+ vy: w[base + 22],
182
+ vz: w[base + 23],
183
+ heading: w[base + 24],
184
+ pitch: w[base + 25],
185
+ "yaw-rate": w[base + 26],
186
+ "pitch-rate": w[base + 27],
187
+ "roll-rate": w[base + 28],
188
+ "forward-x": w[base + 29],
189
+ "forward-y": w[base + 30],
190
+ "forward-z": w[base + 31],
191
+ "right-x": w[base + 32],
192
+ "right-y": w[base + 33],
193
+ "right-z": w[base + 34],
194
+ "up-x": w[base + 35],
195
+ "up-y": w[base + 36],
196
+ "up-z": w[base + 37],
197
+ grounded: w[base + 38] !== 0,
198
+ altitude: w[base + 39],
199
+ battery: w[base + 40],
200
+ "battery-capacity": w[base + 41],
201
+ aim: w[base + 42],
202
+ "aim-pitch": w[base + 43],
203
+ cooldown: w[base + 44],
204
+ "scan-heading": w[base + 45],
205
+ "scan-pitch": w[base + 46],
206
+ "scan-arc": w[base + 47],
207
+ "scan-range": w[base + 48],
208
+ contact: w[base + 49] !== 0,
209
+ range: w[base + 50],
210
+ bearing: w[base + 51],
211
+ elevation: w[base + 52],
212
+ "cue-present": w[base + 53] !== 0,
213
+ "cue-error": w[base + 54],
214
+ "bearing-rate": w[base + 55],
215
+ "zone-active": w[base + 56] !== 0,
216
+ "zone-radius": w[base + 57],
217
+ "storm-active": w[base + 58] !== 0,
218
+ "storm-radius": w[base + 59],
219
+ "hill-active": w[base + 60] !== 0,
220
+ "hill-radius": w[base + 61],
221
+ score: w[base + 62],
222
+ "score-best": w[base + 63],
223
+ speed: w[base + 64],
224
+ gravity: w[base + 65] !== 0,
225
+ "terrain-height": w[base + 66],
226
+ "battery-fraction": w[base + 67],
227
+ "aim-error": w[base + 68],
228
+ "power-min": w[base + 69],
229
+ "power-max": w[base + 70],
230
+ "shot-speed-base": w[base + 71],
231
+ "shot-speed-per-power": w[base + 72],
232
+ "shot-cost-base": w[base + 73],
233
+ "shot-cost-per-power": w[base + 74],
234
+ "zone-distance": w[base + 75],
235
+ "zone-bearing": w[base + 76],
236
+ "zone-elevation": w[base + 77],
237
+ "storm-distance": w[base + 78],
238
+ "storm-bearing": w[base + 79],
239
+ "storm-heading": w[base + 80],
240
+ "cue-muzzle": w[base + 81] !== 0,
241
+ "cue-bearing": w[base + 82],
242
+ "cue-elevation": w[base + 83],
243
+ "cue-range": w[base + 84],
244
+ "cue-age": w[base + 85],
245
+ "pickup-present": w[base + 86] !== 0,
246
+ "pickup-bearing": w[base + 87],
247
+ "pickup-elevation": w[base + 88],
248
+ "pickup-range": w[base + 89],
249
+ "on-hill": w[base + 90] !== 0,
250
+ "hill-held": w[base + 91] !== 0,
251
+ "hill-bearing": w[base + 92],
252
+ "hill-elevation": w[base + 93],
253
+ "hill-range": w[base + 94],
254
+ "hill-time": w[base + 95],
255
+ "hill-to-win": w[base + 96],
256
+ };
257
+ words["energy"] = words["battery"];
258
+ words["max-energy"] = words["battery-capacity"];
259
+ words["energy-fraction"] = words["battery-fraction"];
260
+ words["fire-base"] = words["shot-cost-base"];
261
+ words["fire-per-power"] = words["shot-cost-per-power"];
262
+ return words;
263
+ }
264
+
265
+ module.exports = { API_VERSION, RECORD, SIZE, CUE_TICKS, FAR, WORDS, ALIASES, CONTROLS, read, RULESET, CONTROL, TERRAIN_KIND };