Repository navigation
Expand file tree
/
Copy pathcontrols.zig
More file actions
382 lines (371 loc) · 16.2 KB
/
Copy pathcontrols.zig
File metadata and controls
382 lines (371 loc) · 16.2 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
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
//! The player's actions, and the keys and joystick buttons the game binds them to at first; the
//! keys an action can be bound to; and the order the controls screens list the actions in.
//!
//! Generated by `src/tools/tablegen` from the payload executable's control bindings at
//! 0x004E2380, 74 actions. The names are the game's own. Do not edit by hand; run
//! `make control-tables`.
const std = @import("std");
/// The modifier held with a key; `docs/engine/controls.md` describes how each counts.
pub const Modifier = @import("../input.zig").ControlBinding.Modifier;
/// Every action, numbered as the game numbers them.
pub const Action = enum(u32) {
cockpit_camera = 0,
left_view_camera = 1,
right_view_camera = 2,
rear_view_camera = 3,
flyby_camera = 4,
target_camera = 5,
external_camera = 6,
missile_camera = 7,
next_enemy_target = 8,
previous_enemy_target = 9,
next_friendly_target = 10,
previous_friendly_target = 11,
next_subtarget = 12,
previous_subtarget = 13,
target_under_reticule = 14,
target_nearest_enemy = 15,
target_nearest_friendly = 16,
target_torpedo = 17,
smart_target = 18,
primary_target = 19,
afterburners = 20,
afterburner_toggle = 21,
reverse_thrust = 22,
jump_drive = 23,
match_speed = 24,
accelerate = 25,
decelerate = 26,
zero_throttle = 27,
full_throttle = 28,
roll_ship_clockwise = 29,
roll_ship_anti_clockwise = 30,
nose_up = 31,
nose_down = 32,
rotate_clockwise = 33,
rotate_anti_clockwise = 34,
strafe_left = 35,
strafe_right = 36,
joystick_roll = 37,
fire_lasers = 38,
full_guns = 39,
gunnery_window = 40,
gunnery_window_locked = 41,
synchronise_guns = 42,
toggle_blindfire = 43,
launch_missile = 44,
missile_window = 45,
rotate_missiles_clockwise = 46,
rotate_missiles_anticlockwise = 47,
comms_window = 48,
powerball_window = 49,
powerball_window_locked = 50,
full_power_to_gunnery = 51,
full_power_to_engines = 52,
full_power_to_shields = 53,
equalize_power = 54,
objectives_window = 55,
wing_status_window = 56,
wing_status_window_locked = 57,
damage_window = 58,
damage_window_locked = 59,
radar_ranges = 60,
shield_balancing = 61,
countermeasures = 62,
eject = 63,
cloak_ship = 64,
ecm = 65,
spectral_shields = 66,
attack_my_target = 67,
back_off = 68,
help_me = 69,
permission_to_land = 70,
display_kills = 71,
send_comms_message = 72,
key_config = 73,
};
pub const Binding = struct {
/// The name `starlancer.ini` keys its bindings by.
name: []const u8,
/// The language string of the name the controls screens show.
string: u16,
/// A DirectInput scan code (`DIK_*`).
key: u16,
modifier: Modifier,
/// A joystick button, or null for none.
button: ?u8,
};
/// The bindings the game starts with, indexed by `Action`.
pub const defaults = [_]Binding{
.{ .name = "COCKPIT CAMERA", .string = 0x330, .key = 0x02, .modifier = .none, .button = null },
.{ .name = "LEFT VIEW CAMERA", .string = 0x331, .key = 0x03, .modifier = .none, .button = null },
.{ .name = "RIGHT VIEW CAMERA", .string = 0x332, .key = 0x04, .modifier = .none, .button = null },
.{ .name = "REAR VIEW CAMERA", .string = 0x333, .key = 0x05, .modifier = .none, .button = null },
.{ .name = "FLYBY CAMERA", .string = 0x334, .key = 0x06, .modifier = .none, .button = null },
.{ .name = "TARGET CAMERA", .string = 0x335, .key = 0x07, .modifier = .none, .button = null },
.{ .name = "EXTERNAL CAMERA", .string = 0x336, .key = 0x08, .modifier = .none, .button = null },
.{ .name = "MISSILE CAMERA", .string = 0x337, .key = 0x09, .modifier = .none, .button = null },
.{ .name = "NEXT ENEMY TARGET", .string = 0x338, .key = 0x12, .modifier = .none, .button = null },
.{ .name = "PREVIOUS ENEMY TARGET", .string = 0x339, .key = 0x12, .modifier = .shift, .button = null },
.{ .name = "NEXT FRIENDLY TARGET", .string = 0x33A, .key = 0x10, .modifier = .none, .button = 5 },
.{ .name = "PREVIOUS FRIENDLY TARGET", .string = 0x33B, .key = 0x10, .modifier = .shift, .button = null },
.{ .name = "NEXT SUBTARGET", .string = 0x33C, .key = 0x1F, .modifier = .none, .button = null },
.{ .name = "PREVIOUS SUBTARGET", .string = 0x33D, .key = 0x1F, .modifier = .shift, .button = null },
.{ .name = "TARGET UNDER RETICULE", .string = 0x33E, .key = 0x15, .modifier = .none, .button = null },
.{ .name = "TARGET NEAREST ENEMY", .string = 0x365, .key = 0x13, .modifier = .none, .button = 3 },
.{ .name = "TARGET NEAREST FRIENDLY", .string = 0x366, .key = 0x11, .modifier = .none, .button = null },
.{ .name = "TARGET TORPEDO", .string = 0x370, .key = 0x14, .modifier = .none, .button = null },
.{ .name = "SMART TARGET", .string = 0x35B, .key = 0x12, .modifier = .control, .button = null },
.{ .name = "PRIMARY TARGET", .string = 0x362, .key = 0x1E, .modifier = .none, .button = null },
.{ .name = "AFTERBURNERS", .string = 0x34A, .key = 0x0F, .modifier = .none, .button = 2 },
.{ .name = "AFTERBURNER TOGGLE", .string = 0x34B, .key = 0x29, .modifier = .none, .button = null },
.{ .name = "REVERSE THRUST", .string = 0x35C, .key = 0x0F, .modifier = .shift, .button = null },
.{ .name = "JUMP DRIVE", .string = 0x34E, .key = 0x24, .modifier = .none, .button = null },
.{ .name = "MATCH SPEED", .string = 0x34F, .key = 0x2C, .modifier = .none, .button = null },
.{ .name = "ACCELERATE", .string = 0x350, .key = 0x0D, .modifier = .none, .button = null },
.{ .name = "DECELERATE", .string = 0x351, .key = 0x0C, .modifier = .none, .button = null },
.{ .name = "ZERO THROTTLE", .string = 0x352, .key = 0x0E, .modifier = .none, .button = null },
.{ .name = "FULL THROTTLE", .string = 0x353, .key = 0x2B, .modifier = .none, .button = null },
.{ .name = "ROLL SHIP CLOCKWISE", .string = 0x354, .key = 0xC9, .modifier = .none, .button = null },
.{ .name = "ROLL SHIP ANTI-CLOCKWISE", .string = 0x355, .key = 0xC7, .modifier = .none, .button = null },
.{ .name = "NOSE UP", .string = 0x356, .key = 0xD0, .modifier = .none, .button = null },
.{ .name = "NOSE DOWN", .string = 0x357, .key = 0xC8, .modifier = .none, .button = null },
.{ .name = "ROTATE CLOCKWISE", .string = 0x359, .key = 0xCB, .modifier = .none, .button = null },
.{ .name = "ROTATE ANTI-CLOCKWISE", .string = 0x358, .key = 0xCD, .modifier = .none, .button = null },
.{ .name = "STRAFE LEFT", .string = 0x36D, .key = 0xCF, .modifier = .none, .button = 7 },
.{ .name = "STRAFE RIGHT", .string = 0x36E, .key = 0xD1, .modifier = .none, .button = 4 },
.{ .name = "JOYSTICK ROLL", .string = 0x544, .key = 0xD2, .modifier = .none, .button = null },
.{ .name = "FIRE LASERS", .string = 0x35A, .key = 0x39, .modifier = .none, .button = 0 },
.{ .name = "FULL GUNS", .string = 0x346, .key = 0x21, .modifier = .none, .button = null },
.{ .name = "GUNNERY WINDOW", .string = 0x341, .key = 0x22, .modifier = .none, .button = null },
.{ .name = "GUNNERY WINDOW LOCKED", .string = 0x342, .key = 0x22, .modifier = .shift, .button = null },
.{ .name = "SYNCHRONISE GUNS", .string = 0x347, .key = 0x22, .modifier = .control, .button = null },
.{ .name = "TOGGLE BLINDFIRE", .string = 0x415, .key = 0x21, .modifier = .shift, .button = null },
.{ .name = "LAUNCH MISSILE", .string = 0x340, .key = 0x1C, .modifier = .none, .button = 1 },
.{ .name = "MISSILE WINDOW", .string = 0x363, .key = 0x32, .modifier = .none, .button = null },
.{ .name = "ROTATE MISSILES CLOCKWISE", .string = 0x35E, .key = 0x34, .modifier = .none, .button = null },
.{ .name = "ROTATE MISSILES ANTICLOCKWISE", .string = 0x35F, .key = 0x33, .modifier = .none, .button = null },
.{ .name = "COMMS WINDOW", .string = 0x33F, .key = 0x2E, .modifier = .none, .button = null },
.{ .name = "POWERBALL WINDOW", .string = 0x343, .key = 0x19, .modifier = .none, .button = null },
.{ .name = "POWERBALL WINDOW LOCKED", .string = 0x344, .key = 0x19, .modifier = .shift, .button = null },
.{ .name = "FULL POWER TO GUNNERY", .string = 0x369, .key = 0x16, .modifier = .none, .button = null },
.{ .name = "FULL POWER TO ENGINES", .string = 0x36A, .key = 0x17, .modifier = .none, .button = null },
.{ .name = "FULL POWER TO SHIELDS", .string = 0x36B, .key = 0x18, .modifier = .none, .button = null },
.{ .name = "EQUALIZE POWER", .string = 0x36C, .key = 0x1A, .modifier = .none, .button = null },
.{ .name = "OBJECTIVES WINDOW", .string = 0x345, .key = 0x30, .modifier = .none, .button = null },
.{ .name = "WING STATUS WINDOW", .string = 0x348, .key = 0x2D, .modifier = .none, .button = null },
.{ .name = "WING STATUS WINDOW LOCKED", .string = 0x349, .key = 0x2D, .modifier = .shift, .button = null },
.{ .name = "DAMAGE WINDOW", .string = 0x34C, .key = 0x20, .modifier = .none, .button = null },
.{ .name = "DAMAGE WINDOW LOCKED", .string = 0x34D, .key = 0x20, .modifier = .shift, .button = null },
.{ .name = "RADAR RANGES", .string = 0x360, .key = 0x2F, .modifier = .none, .button = null },
.{ .name = "SHIELD BALANCING", .string = 0x367, .key = 0x31, .modifier = .none, .button = null },
.{ .name = "COUNTERMEASURES", .string = 0x35D, .key = 0x23, .modifier = .none, .button = null },
.{ .name = "EJECT", .string = 0x361, .key = 0x58, .modifier = .none, .button = null },
.{ .name = "CLOAK SHIP", .string = 0x364, .key = 0x25, .modifier = .none, .button = null },
.{ .name = "ECM", .string = 0x368, .key = 0x26, .modifier = .none, .button = null },
.{ .name = "SPECTRAL SHIELDS", .string = 0x36F, .key = 0x27, .modifier = .none, .button = null },
.{ .name = "ATTACK MY TARGET", .string = 0x371, .key = 0x3F, .modifier = .none, .button = null },
.{ .name = "BACK OFF", .string = 0x372, .key = 0x40, .modifier = .none, .button = null },
.{ .name = "HELP ME", .string = 0x373, .key = 0x41, .modifier = .none, .button = null },
.{ .name = "PERMISSION TO LAND", .string = 0x548, .key = 0x42, .modifier = .none, .button = null },
.{ .name = "DISPLAY KILLS", .string = 0x549, .key = 0x44, .modifier = .none, .button = null },
.{ .name = "SEND COMMS MESSAGE", .string = 0x543, .key = 0x28, .modifier = .none, .button = null },
.{ .name = "KEY CONFIG", .string = 0x55B, .key = 0x3B, .modifier = .none, .button = null },
};
pub fn binding(action: Action) Binding {
return defaults[@backingInt(action)];
}
comptime {
if (defaults.len != std.enums.values(Action).len) @compileError("one binding per action");
}
/// A key an action can be bound to: its scan code, and the name the game gives it before the
/// keyboard's own (`key_names`, 0x004E5CD0).
pub const Key = struct {
code: u8,
name: []const u8,
};
pub const keys = [_]Key{
.{ .code = 0x1E, .name = "A" },
.{ .code = 0x30, .name = "B" },
.{ .code = 0x2E, .name = "C" },
.{ .code = 0x20, .name = "D" },
.{ .code = 0x12, .name = "E" },
.{ .code = 0x21, .name = "F" },
.{ .code = 0x22, .name = "G" },
.{ .code = 0x23, .name = "H" },
.{ .code = 0x17, .name = "I" },
.{ .code = 0x24, .name = "J" },
.{ .code = 0x25, .name = "K" },
.{ .code = 0x26, .name = "L" },
.{ .code = 0x32, .name = "M" },
.{ .code = 0x31, .name = "N" },
.{ .code = 0x18, .name = "O" },
.{ .code = 0x19, .name = "P" },
.{ .code = 0x10, .name = "Q" },
.{ .code = 0x13, .name = "R" },
.{ .code = 0x1F, .name = "S" },
.{ .code = 0x14, .name = "T" },
.{ .code = 0x16, .name = "U" },
.{ .code = 0x2F, .name = "V" },
.{ .code = 0x11, .name = "W" },
.{ .code = 0x2D, .name = "X" },
.{ .code = 0x15, .name = "Y" },
.{ .code = 0x2C, .name = "Z" },
.{ .code = 0x39, .name = "SPACE" },
.{ .code = 0x34, .name = "PERIOD" },
.{ .code = 0x33, .name = "COMMA" },
.{ .code = 0x02, .name = "1" },
.{ .code = 0x03, .name = "2" },
.{ .code = 0x04, .name = "3" },
.{ .code = 0x05, .name = "4" },
.{ .code = 0x06, .name = "5" },
.{ .code = 0x07, .name = "6" },
.{ .code = 0x08, .name = "7" },
.{ .code = 0x09, .name = "8" },
.{ .code = 0x0A, .name = "9" },
.{ .code = 0x0B, .name = "0" },
.{ .code = 0xCF, .name = "END" },
.{ .code = 0xD3, .name = "DELETE" },
.{ .code = 0x0C, .name = "-" },
.{ .code = 0x0D, .name = "=" },
.{ .code = 0x1C, .name = "ENTER" },
.{ .code = 0xC8, .name = "CURSOR UP" },
.{ .code = 0xD0, .name = "CURSOR DOWN" },
.{ .code = 0xCB, .name = "CURSOR LEFT" },
.{ .code = 0xCD, .name = "CURSOR RIGHT" },
.{ .code = 0x3B, .name = "F1" },
.{ .code = 0x3C, .name = "F2" },
.{ .code = 0x3D, .name = "F3" },
.{ .code = 0x3E, .name = "F4" },
.{ .code = 0x3F, .name = "F5" },
.{ .code = 0x40, .name = "F6" },
.{ .code = 0x41, .name = "F7" },
.{ .code = 0x42, .name = "F8" },
.{ .code = 0x43, .name = "F9" },
.{ .code = 0x44, .name = "F10" },
.{ .code = 0x57, .name = "F11" },
.{ .code = 0x58, .name = "F12" },
.{ .code = 0xD2, .name = "INSERT" },
.{ .code = 0xC7, .name = "HOME" },
.{ .code = 0xC9, .name = "PAGE UP" },
.{ .code = 0xD1, .name = "PAGE DOWN" },
.{ .code = 0x9C, .name = "PAD ENTER" },
.{ .code = 0x0E, .name = "BACKSPACE" },
.{ .code = 0x4A, .name = "PAD MINUS" },
.{ .code = 0x4E, .name = "PAD PLUS" },
.{ .code = 0x1A, .name = "[" },
.{ .code = 0x1B, .name = "]" },
.{ .code = 0x28, .name = "'" },
.{ .code = 0x27, .name = ";" },
.{ .code = 0xB5, .name = "NUMPAD /" },
.{ .code = 0x37, .name = "NUMPAD *" },
.{ .code = 0x52, .name = "NUMPAD 0" },
.{ .code = 0x4F, .name = "NUMPAD 1" },
.{ .code = 0x50, .name = "NUMPAD 2" },
.{ .code = 0x51, .name = "NUMPAD 3" },
.{ .code = 0x4B, .name = "NUMPAD 4" },
.{ .code = 0x4C, .name = "NUMPAD 5" },
.{ .code = 0x4D, .name = "NUMPAD 6" },
.{ .code = 0x47, .name = "NUMPAD 7" },
.{ .code = 0x48, .name = "NUMPAD 8" },
.{ .code = 0x49, .name = "NUMPAD 9" },
.{ .code = 0x0F, .name = "TAB" },
.{ .code = 0x2B, .name = "\\" },
.{ .code = 0x35, .name = "/" },
.{ .code = 0x29, .name = "`" },
.{ .code = 0x53, .name = "NUMPAD ." },
};
/// The rows of the controls screens, in order (`controls_list`, 0x004E75E8): an action, the
/// actions in turn, or null for a divider between groups.
pub const list = [_]?Action{
.cockpit_camera,
.left_view_camera,
.right_view_camera,
.rear_view_camera,
.flyby_camera,
.target_camera,
.external_camera,
.missile_camera,
null,
.next_enemy_target,
.previous_enemy_target,
.next_friendly_target,
.previous_friendly_target,
.next_subtarget,
.previous_subtarget,
.target_under_reticule,
.target_nearest_enemy,
.target_nearest_friendly,
.target_torpedo,
.smart_target,
.primary_target,
null,
.afterburners,
.afterburner_toggle,
.reverse_thrust,
.jump_drive,
.match_speed,
.accelerate,
.decelerate,
.zero_throttle,
.full_throttle,
.roll_ship_clockwise,
.roll_ship_anti_clockwise,
.nose_up,
.nose_down,
.rotate_clockwise,
.rotate_anti_clockwise,
.strafe_left,
.strafe_right,
.joystick_roll,
null,
.fire_lasers,
.full_guns,
.gunnery_window,
.gunnery_window_locked,
.synchronise_guns,
.toggle_blindfire,
.launch_missile,
.missile_window,
.rotate_missiles_clockwise,
.rotate_missiles_anticlockwise,
null,
.comms_window,
.powerball_window,
.powerball_window_locked,
.full_power_to_gunnery,
.full_power_to_engines,
.full_power_to_shields,
.equalize_power,
.objectives_window,
.wing_status_window,
.wing_status_window_locked,
.damage_window,
.damage_window_locked,
.radar_ranges,
.shield_balancing,
null,
.countermeasures,
.eject,
.cloak_ship,
.ecm,
.spectral_shields,
null,
.attack_my_target,
.back_off,
.help_me,
.permission_to_land,
null,
.display_kills,
.send_comms_message,
};
test binding {
for (std.enums.values(Action)) |action| {
const name = binding(action).name;
const tag = @tagName(action);
try std.testing.expectEqual(name.len, tag.len);
for (name, tag) |c, t| {
try std.testing.expectEqual(if (c == ' ' or c == '-') '_' else std.ascii.toLower(c), t);
}
}
}