@pkmn/engine 0.1.0-dev.c4dec0f7 → 0.1.0-dev.c544e10e
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/README.md +102 -63
- package/build/pkg/addon.d.ts +7 -0
- package/build/pkg/addon.js +112 -0
- package/build/pkg/addon.js.map +1 -0
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +27 -5
- package/build/pkg/data/protocol.json +69 -12
- package/build/pkg/data.d.ts +3 -4
- package/build/pkg/data.js +3 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +5 -4
- package/build/pkg/gen1.js +49 -33
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +15 -12
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +4 -2
- package/build/pkg/protocol.js +61 -40
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +400 -0
- package/build/test/display.js.map +1 -0
- package/build/tools/debug.js +135 -0
- package/build/tools/debug.js.map +1 -0
- package/build.zig +118 -98
- package/package.json +74 -42
- package/src/bin/install-pkmn-engine +68 -36
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +47 -142
- package/src/lib/binding/wasm.zig +6 -4
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +19 -31
- package/src/lib/common/debug.zig +21 -11
- package/src/lib/common/js.zig +118 -0
- package/src/lib/common/optional.zig +67 -0
- package/src/lib/common/options.zig +12 -3
- package/src/lib/common/protocol.zig +905 -361
- package/src/lib/common/rational.zig +353 -0
- package/src/lib/common/rng.zig +24 -15
- package/src/lib/common/util.zig +12 -0
- package/src/lib/gen1/README.md +309 -193
- package/src/lib/gen1/calc.zig +426 -0
- package/src/lib/gen1/chance.zig +1060 -0
- package/src/lib/gen1/data/moves.zig +202 -190
- package/src/lib/gen1/data/species.zig +4 -4
- package/src/lib/gen1/data/types.zig +10 -10
- package/src/lib/gen1/data.zig +90 -76
- package/src/lib/gen1/helpers.zig +577 -32
- package/src/lib/gen1/mechanics.zig +1173 -813
- package/src/lib/gen2/README.md +105 -85
- package/src/lib/gen2/calc.zig +143 -0
- package/src/lib/gen2/chance.zig +1314 -0
- package/src/lib/gen2/data/items.zig +14 -20
- package/src/lib/gen2/data/moves.zig +664 -570
- package/src/lib/gen2/data/species.zig +2 -2
- package/src/lib/gen2/data/types.zig +137 -34
- package/src/lib/gen2/data.zig +128 -90
- package/src/lib/gen2/generated.zig +808 -0
- package/src/lib/gen2/helpers.zig +16 -22
- package/src/lib/gen2/mechanics.zig +3510 -12
- package/src/lib/pkmn.zig +68 -9
- package/src/test/display/pkmn.html.tmpl +368 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const builtin = @import("builtin");
|
|
3
3
|
|
|
4
|
+
const pkmn = @import("../pkmn.zig");
|
|
5
|
+
|
|
4
6
|
const data = @import("./data.zig");
|
|
5
7
|
const options = @import("./options.zig");
|
|
6
8
|
|
|
7
9
|
const assert = std.debug.assert;
|
|
8
10
|
const print = std.debug.print;
|
|
9
11
|
|
|
10
|
-
const
|
|
12
|
+
const enabled = options.log;
|
|
11
13
|
|
|
12
14
|
const Player = data.Player;
|
|
13
15
|
const ID = data.ID;
|
|
@@ -102,6 +104,10 @@ pub const ArgType = enum(u8) {
|
|
|
102
104
|
// Gen 8
|
|
103
105
|
CanDynamax,
|
|
104
106
|
SwapSideConditions,
|
|
107
|
+
UpdatePoke,
|
|
108
|
+
|
|
109
|
+
// Gen 9
|
|
110
|
+
Terastallize,
|
|
105
111
|
};
|
|
106
112
|
|
|
107
113
|
pub const Move = enum(u8) {
|
|
@@ -118,12 +124,19 @@ pub const Cant = enum(u8) {
|
|
|
118
124
|
Disable,
|
|
119
125
|
Recharge,
|
|
120
126
|
PP,
|
|
127
|
+
|
|
128
|
+
Attract,
|
|
121
129
|
};
|
|
122
130
|
|
|
123
131
|
pub const Heal = enum(u8) {
|
|
124
132
|
None,
|
|
125
133
|
Silent,
|
|
126
134
|
Drain,
|
|
135
|
+
|
|
136
|
+
Leftovers,
|
|
137
|
+
Berry,
|
|
138
|
+
BerryJuice,
|
|
139
|
+
GoldBerry,
|
|
127
140
|
};
|
|
128
141
|
|
|
129
142
|
pub const Damage = enum(u8) {
|
|
@@ -133,6 +146,17 @@ pub const Damage = enum(u8) {
|
|
|
133
146
|
Confusion,
|
|
134
147
|
LeechSeed,
|
|
135
148
|
RecoilOf,
|
|
149
|
+
|
|
150
|
+
Bind,
|
|
151
|
+
Wrap,
|
|
152
|
+
FireSpin,
|
|
153
|
+
Clamp,
|
|
154
|
+
Whirlpool,
|
|
155
|
+
Spikes,
|
|
156
|
+
|
|
157
|
+
Nightmare,
|
|
158
|
+
Curse,
|
|
159
|
+
Sandstorm,
|
|
136
160
|
};
|
|
137
161
|
|
|
138
162
|
pub const Status = enum(u8) {
|
|
@@ -175,8 +199,25 @@ pub const Activate = enum(u8) {
|
|
|
175
199
|
Haze,
|
|
176
200
|
Mist,
|
|
177
201
|
Struggle,
|
|
178
|
-
Substitute,
|
|
202
|
+
Substitute, // FIXME SubstituteDamage
|
|
179
203
|
Splash,
|
|
204
|
+
|
|
205
|
+
Rage, // TODO
|
|
206
|
+
|
|
207
|
+
Attract,
|
|
208
|
+
LockOn,
|
|
209
|
+
Bind,
|
|
210
|
+
Wrap,
|
|
211
|
+
FireSpin,
|
|
212
|
+
Clamp,
|
|
213
|
+
Whirlpool,
|
|
214
|
+
SubstituteBlock,
|
|
215
|
+
|
|
216
|
+
DestinyBond,
|
|
217
|
+
|
|
218
|
+
BeatUp, // FIXME of
|
|
219
|
+
|
|
220
|
+
Magnitude,
|
|
180
221
|
};
|
|
181
222
|
|
|
182
223
|
pub const Start = enum(u8) {
|
|
@@ -194,6 +235,19 @@ pub const Start = enum(u8) {
|
|
|
194
235
|
|
|
195
236
|
Disable,
|
|
196
237
|
Mimic,
|
|
238
|
+
|
|
239
|
+
Attract,
|
|
240
|
+
Nightmare,
|
|
241
|
+
Curse,
|
|
242
|
+
Foresight,
|
|
243
|
+
Encore,
|
|
244
|
+
FutureSight,
|
|
245
|
+
|
|
246
|
+
PerishSong0,
|
|
247
|
+
PerishSong1,
|
|
248
|
+
PerishSong2,
|
|
249
|
+
PerishSong3,
|
|
250
|
+
PerishSong3Silent,
|
|
197
251
|
};
|
|
198
252
|
|
|
199
253
|
pub const End = enum(u8) {
|
|
@@ -202,16 +256,30 @@ pub const End = enum(u8) {
|
|
|
202
256
|
Bide,
|
|
203
257
|
Substitute,
|
|
204
258
|
|
|
205
|
-
|
|
259
|
+
Nightmare,
|
|
260
|
+
Curse,
|
|
261
|
+
Foresight,
|
|
262
|
+
Encore,
|
|
263
|
+
FutureSight,
|
|
264
|
+
LeechSeed,
|
|
265
|
+
|
|
266
|
+
Bind,
|
|
267
|
+
Wrap,
|
|
268
|
+
FireSpin,
|
|
269
|
+
Clamp,
|
|
270
|
+
Whirlpool,
|
|
271
|
+
|
|
206
272
|
DisableSilent,
|
|
207
273
|
ConfusionSilent,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
274
|
+
MistSilent,
|
|
275
|
+
FocusEnergySilent,
|
|
276
|
+
LeechSeedSilent,
|
|
277
|
+
ToxicSilent,
|
|
278
|
+
LightScreenSilent,
|
|
279
|
+
ReflectSilent,
|
|
280
|
+
BideSilent,
|
|
281
|
+
|
|
282
|
+
LeechSeedFrom,
|
|
215
283
|
};
|
|
216
284
|
|
|
217
285
|
pub const Immune = enum(u8) {
|
|
@@ -219,8 +287,34 @@ pub const Immune = enum(u8) {
|
|
|
219
287
|
OHKO,
|
|
220
288
|
};
|
|
221
289
|
|
|
290
|
+
pub const EndItem = enum(u8) {
|
|
291
|
+
None,
|
|
292
|
+
Eat,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
pub const SetHP = enum(u8) {
|
|
296
|
+
None,
|
|
297
|
+
Silent,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
pub const Side = enum(u8) {
|
|
301
|
+
Safeguard,
|
|
302
|
+
Reflect,
|
|
303
|
+
LightScreen,
|
|
304
|
+
Spikes,
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
pub const Weather = enum(u8) {
|
|
308
|
+
None,
|
|
309
|
+
Upkeep,
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/// Null object pattern implementation of `Log` backed by a `std.io.null_writer`.
|
|
313
|
+
/// Ignores anything sent to it, though protocol logging should additionally be turned off
|
|
314
|
+
/// entirely with `options.log`.
|
|
222
315
|
pub const NULL = Log(@TypeOf(std.io.null_writer)){ .writer = std.io.null_writer };
|
|
223
316
|
|
|
317
|
+
/// Logs protocol information to its `Writer` during a battle update when `options.log` is enabled.
|
|
224
318
|
pub fn Log(comptime Writer: type) type {
|
|
225
319
|
return struct {
|
|
226
320
|
const Self = @This();
|
|
@@ -229,322 +323,497 @@ pub fn Log(comptime Writer: type) type {
|
|
|
229
323
|
|
|
230
324
|
pub const Error = Writer.Error;
|
|
231
325
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
326
|
+
// source: ID, move: <Move>, target: ID, from?: <Move>
|
|
327
|
+
pub fn move(self: Self, args: anytype) Error!void {
|
|
328
|
+
if (!enabled) return;
|
|
329
|
+
|
|
330
|
+
assert(args[1] != .None);
|
|
235
331
|
try self.writer.writeAll(&.{
|
|
236
|
-
@
|
|
237
|
-
@
|
|
238
|
-
@
|
|
239
|
-
@
|
|
332
|
+
@intFromEnum(ArgType.Move),
|
|
333
|
+
@as(u8, @bitCast(args[0])),
|
|
334
|
+
@intFromEnum(args[1]),
|
|
335
|
+
@as(u8, @bitCast(args[2])),
|
|
240
336
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
337
|
+
try self.writer.writeAll(if (args.len < 4 or @intFromEnum(args[3]) == 0)
|
|
338
|
+
&.{@intFromEnum(Move.None)}
|
|
339
|
+
else
|
|
340
|
+
&.{ @intFromEnum(Move.From), @intFromEnum(args[3]) });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ident: ID, pokemon: <Pokemon>
|
|
344
|
+
pub fn switched(self: Self, args: anytype) Error!void {
|
|
345
|
+
return switchDrag(self, .Switch, args);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// ident: ID, pokemon: <Pokemon>
|
|
349
|
+
fn switchDrag(self: Self, arg: ArgType, args: anytype) Error!void {
|
|
350
|
+
if (!enabled) return;
|
|
351
|
+
|
|
352
|
+
try self.writer.writeAll(&.{ @intFromEnum(arg), @as(u8, @bitCast(args[0])) });
|
|
353
|
+
if (@hasField(@TypeOf(args[1].*), "dvs")) {
|
|
354
|
+
try self.writer.writeAll(&.{
|
|
355
|
+
@intFromEnum(args[1].species),
|
|
356
|
+
@intFromEnum(args[1].dvs.gender),
|
|
357
|
+
args[1].level,
|
|
358
|
+
});
|
|
359
|
+
} else {
|
|
360
|
+
try self.writer.writeAll(&.{ @intFromEnum(args[1].species), args[1].level });
|
|
361
|
+
}
|
|
362
|
+
try self.writer.writeIntNative(u16, args[1].hp);
|
|
363
|
+
try self.writer.writeIntNative(u16, args[1].stats.hp);
|
|
364
|
+
try self.writer.writeAll(&.{args[1].status});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ident: ID, reason: Cant
|
|
368
|
+
// ident: ID, reason: .Disable, move: <Move>
|
|
369
|
+
pub fn cant(self: Self, args: anytype) Error!void {
|
|
370
|
+
if (!enabled) return;
|
|
371
|
+
|
|
372
|
+
assert(args[1] != .Disable or args.len == 3);
|
|
373
|
+
try self.writer.writeAll(&.{
|
|
374
|
+
@intFromEnum(ArgType.Cant),
|
|
375
|
+
@as(u8, @bitCast(args[0])),
|
|
376
|
+
@intFromEnum(@as(Cant, args[1])),
|
|
252
377
|
});
|
|
378
|
+
if (args.len == 3) try self.writer.writeByte(@intFromEnum(args[2]));
|
|
253
379
|
}
|
|
254
380
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
try self.writer.
|
|
260
|
-
try self.writer.
|
|
261
|
-
try self.writer.writeAll(&.{pokemon.status});
|
|
381
|
+
// ident: ID, done: bool
|
|
382
|
+
pub fn faint(self: Self, args: anytype) Error!void {
|
|
383
|
+
if (!enabled) return;
|
|
384
|
+
|
|
385
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Faint), @as(u8, @bitCast(args[0])) });
|
|
386
|
+
if (args[1]) try self.writer.writeByte(@intFromEnum(ArgType.None));
|
|
262
387
|
}
|
|
263
388
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
389
|
+
// num: u16
|
|
390
|
+
pub fn turn(self: Self, args: anytype) Error!void {
|
|
391
|
+
if (!enabled) return;
|
|
392
|
+
|
|
393
|
+
try self.writer.writeByte(@intFromEnum(ArgType.Turn));
|
|
394
|
+
try self.writer.writeIntNative(u16, args[0]);
|
|
395
|
+
try self.writer.writeByte(@intFromEnum(ArgType.None));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// player: Player
|
|
399
|
+
pub fn win(self: Self, args: anytype) Error!void {
|
|
400
|
+
if (!enabled) return;
|
|
401
|
+
|
|
267
402
|
try self.writer.writeAll(&.{
|
|
268
|
-
@
|
|
269
|
-
@
|
|
270
|
-
@
|
|
403
|
+
@intFromEnum(ArgType.Win),
|
|
404
|
+
@intFromEnum(@as(Player, args[0])),
|
|
405
|
+
@intFromEnum(ArgType.None),
|
|
271
406
|
});
|
|
272
407
|
}
|
|
273
408
|
|
|
274
|
-
|
|
275
|
-
|
|
409
|
+
// -
|
|
410
|
+
pub fn tie(self: Self, _: anytype) Error!void {
|
|
411
|
+
if (!enabled) return;
|
|
412
|
+
|
|
413
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Tie), @intFromEnum(ArgType.None) });
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ident: ID, pokemon: <Pokemon>, reason: Damage
|
|
417
|
+
// ident: ID, pokemon: <Pokemon>, reason: .RecoilOf, source: ID
|
|
418
|
+
pub fn damage(self: Self, args: anytype) Error!void {
|
|
419
|
+
if (!enabled) return;
|
|
420
|
+
|
|
421
|
+
assert(args[2] != .RecoilOf or args.len == 4);
|
|
276
422
|
try self.writer.writeAll(&.{
|
|
277
|
-
@
|
|
278
|
-
@
|
|
279
|
-
@enumToInt(Cant.Disable),
|
|
280
|
-
@enumToInt(m),
|
|
423
|
+
@intFromEnum(ArgType.Damage),
|
|
424
|
+
@as(u8, @bitCast(args[0])),
|
|
281
425
|
});
|
|
426
|
+
try self.writer.writeIntNative(u16, args[1].hp);
|
|
427
|
+
try self.writer.writeIntNative(u16, args[1].stats.hp);
|
|
428
|
+
try self.writer.writeAll(&.{ args[1].status, @intFromEnum(@as(Damage, args[2])) });
|
|
429
|
+
if (args.len == 4) try self.writer.writeByte(@as(u8, @bitCast(args[3])));
|
|
282
430
|
}
|
|
283
431
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (
|
|
432
|
+
// ident: ID, pokemon: <Pokemon>, reason: Heal
|
|
433
|
+
// ident: ID, pokemon: <Pokemon>, reason: .Drain, target: ID
|
|
434
|
+
pub fn heal(self: Self, args: anytype) Error!void {
|
|
435
|
+
if (!enabled) return;
|
|
436
|
+
|
|
437
|
+
assert(args[2] != .Drain or args.len == 4);
|
|
438
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(args[0])) });
|
|
439
|
+
try self.writer.writeIntNative(u16, args[1].hp);
|
|
440
|
+
try self.writer.writeIntNative(u16, args[1].stats.hp);
|
|
441
|
+
try self.writer.writeAll(&.{ args[1].status, @intFromEnum(@as(Heal, args[2])) });
|
|
442
|
+
if (args.len == 4) try self.writer.writeByte(@as(u8, @bitCast(args[3])));
|
|
288
443
|
}
|
|
289
444
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
445
|
+
// ident: ID, value: u8, reason: Status
|
|
446
|
+
// ident: ID, value: u8, reason: .From, m: <Move>
|
|
447
|
+
pub fn status(self: Self, args: anytype) Error!void {
|
|
448
|
+
if (!enabled) return;
|
|
449
|
+
|
|
450
|
+
assert(args[2] != .From or args.len == 4);
|
|
451
|
+
try self.writer.writeAll(&.{
|
|
452
|
+
@intFromEnum(ArgType.Status),
|
|
453
|
+
@as(u8, @bitCast(args[0])),
|
|
454
|
+
args[1],
|
|
455
|
+
@intFromEnum(@as(Status, args[2])),
|
|
456
|
+
});
|
|
457
|
+
if (args.len == 4) try self.writer.writeByte(@intFromEnum(args[3]));
|
|
295
458
|
}
|
|
296
459
|
|
|
297
|
-
|
|
298
|
-
|
|
460
|
+
// ident: ID, value: u8, reason: CureStatus
|
|
461
|
+
pub fn curestatus(self: Self, args: anytype) Error!void {
|
|
462
|
+
if (!enabled) return;
|
|
463
|
+
|
|
299
464
|
try self.writer.writeAll(&.{
|
|
300
|
-
@
|
|
301
|
-
@
|
|
302
|
-
|
|
465
|
+
@intFromEnum(ArgType.CureStatus),
|
|
466
|
+
@as(u8, @bitCast(args[0])),
|
|
467
|
+
args[1],
|
|
468
|
+
@intFromEnum(@as(CureStatus, args[2])),
|
|
303
469
|
});
|
|
304
470
|
}
|
|
305
471
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
472
|
+
// ident: ID, reason: Boost, num: i8
|
|
473
|
+
pub fn boost(self: Self, args: anytype) Error!void {
|
|
474
|
+
if (!enabled) return;
|
|
475
|
+
|
|
476
|
+
assert(args[2] != 0 and (args[1] != .Rage or args[2] > 0));
|
|
477
|
+
try self.writer.writeAll(&.{
|
|
478
|
+
@intFromEnum(ArgType.Boost),
|
|
479
|
+
@as(u8, @bitCast(args[0])),
|
|
480
|
+
@intFromEnum(@as(Boost, args[1])),
|
|
481
|
+
@as(u8, @intCast(@as(i8, args[2]) + 6)),
|
|
482
|
+
});
|
|
309
483
|
}
|
|
310
484
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
try self.writer.
|
|
316
|
-
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
317
|
-
try self.writer.writeAll(&.{ pokemon.status, @enumToInt(reason) });
|
|
485
|
+
// -
|
|
486
|
+
pub fn clearallboost(self: Self, _: anytype) Error!void {
|
|
487
|
+
if (!enabled) return;
|
|
488
|
+
|
|
489
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.ClearAllBoost)});
|
|
318
490
|
}
|
|
319
491
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
reason: Damage,
|
|
325
|
-
source: ID,
|
|
326
|
-
) Error!void {
|
|
327
|
-
if (!trace) return;
|
|
328
|
-
assert(@enumToInt(reason) == @enumToInt(Damage.RecoilOf));
|
|
329
|
-
try self.writer.writeAll(&.{ @enumToInt(ArgType.Damage), @bitCast(u8, ident) });
|
|
330
|
-
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
331
|
-
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
492
|
+
// ident: ID, reason: Fail
|
|
493
|
+
pub fn fail(self: Self, args: anytype) Error!void {
|
|
494
|
+
if (!enabled) return;
|
|
495
|
+
|
|
332
496
|
try self.writer.writeAll(&.{
|
|
333
|
-
|
|
334
|
-
@
|
|
335
|
-
@
|
|
497
|
+
@intFromEnum(ArgType.Fail),
|
|
498
|
+
@as(u8, @bitCast(args[0])),
|
|
499
|
+
@intFromEnum(@as(Fail, args[1])),
|
|
336
500
|
});
|
|
337
501
|
}
|
|
338
502
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
try self.writer.
|
|
344
|
-
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
345
|
-
try self.writer.writeAll(&.{ pokemon.status, @enumToInt(reason) });
|
|
503
|
+
// source: ID
|
|
504
|
+
pub fn miss(self: Self, args: anytype) Error!void {
|
|
505
|
+
if (!enabled) return;
|
|
506
|
+
|
|
507
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Miss), @as(u8, @bitCast(args[0])) });
|
|
346
508
|
}
|
|
347
509
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
510
|
+
// ident: ID, num: u8
|
|
511
|
+
pub fn hitcount(self: Self, args: anytype) Error!void {
|
|
512
|
+
if (!enabled) return;
|
|
513
|
+
|
|
353
514
|
try self.writer.writeAll(&.{
|
|
354
|
-
|
|
355
|
-
@
|
|
356
|
-
|
|
515
|
+
@intFromEnum(ArgType.HitCount),
|
|
516
|
+
@as(u8, @bitCast(args[0])),
|
|
517
|
+
args[1],
|
|
357
518
|
});
|
|
358
519
|
}
|
|
359
520
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
521
|
+
// source: ID, m: <Move>
|
|
522
|
+
pub fn prepare(self: Self, args: anytype) Error!void {
|
|
523
|
+
if (!enabled) return;
|
|
524
|
+
|
|
363
525
|
try self.writer.writeAll(&.{
|
|
364
|
-
@
|
|
365
|
-
@
|
|
366
|
-
|
|
367
|
-
@enumToInt(reason),
|
|
526
|
+
@intFromEnum(ArgType.Prepare),
|
|
527
|
+
@as(u8, @bitCast(args[0])),
|
|
528
|
+
@intFromEnum(args[1]),
|
|
368
529
|
});
|
|
369
530
|
}
|
|
370
531
|
|
|
371
|
-
|
|
372
|
-
|
|
532
|
+
// ident: ID
|
|
533
|
+
pub fn mustrecharge(self: Self, args: anytype) Error!void {
|
|
534
|
+
if (!enabled) return;
|
|
535
|
+
|
|
373
536
|
try self.writer.writeAll(&.{
|
|
374
|
-
@
|
|
375
|
-
@
|
|
376
|
-
value,
|
|
377
|
-
@enumToInt(Status.From),
|
|
378
|
-
@enumToInt(m),
|
|
537
|
+
@intFromEnum(ArgType.MustRecharge),
|
|
538
|
+
@as(u8, @bitCast(args[0])),
|
|
379
539
|
});
|
|
380
540
|
}
|
|
381
541
|
|
|
382
|
-
|
|
383
|
-
|
|
542
|
+
// ident: ID, reason: Activate
|
|
543
|
+
// ident: ID, reason: .SubstituteBlock, m: <Move>
|
|
544
|
+
// ident: ID, reason: .Magnitude, num: u8
|
|
545
|
+
pub fn activate(self: Self, args: anytype) Error!void {
|
|
546
|
+
if (!enabled) return;
|
|
547
|
+
|
|
548
|
+
assert(args.len <= 4);
|
|
549
|
+
const reason: Activate = args[1];
|
|
384
550
|
try self.writer.writeAll(&.{
|
|
385
|
-
@
|
|
386
|
-
@
|
|
387
|
-
|
|
388
|
-
@enumToInt(reason),
|
|
551
|
+
@intFromEnum(ArgType.Activate),
|
|
552
|
+
@as(u8, @bitCast(args[0])),
|
|
553
|
+
@intFromEnum(reason),
|
|
389
554
|
});
|
|
555
|
+
if (args.len == 3) {
|
|
556
|
+
if (reason == .SubstituteBlock) {
|
|
557
|
+
try self.writer.writeByte(@intFromEnum(args[2]));
|
|
558
|
+
} else {
|
|
559
|
+
assert(reason == .Magnitude);
|
|
560
|
+
try self.writer.writeByte(args[2]);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
390
563
|
}
|
|
391
564
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
565
|
+
// -
|
|
566
|
+
pub fn fieldactivate(self: Self, _: anytype) Error!void {
|
|
567
|
+
if (!enabled) return;
|
|
568
|
+
|
|
569
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.FieldActivate)});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// ident: ID, reason: Start
|
|
573
|
+
// ident: ID, reason: .Disable | .Mimic | .Encore, m: <Move>
|
|
574
|
+
// ident: ID, reason: .TypeChange, types: <Types>, target: ID
|
|
575
|
+
pub fn start(self: Self, args: anytype) Error!void {
|
|
576
|
+
if (!enabled) return;
|
|
577
|
+
|
|
578
|
+
assert(args.len <= 4);
|
|
579
|
+
const reason: Start = args[1];
|
|
395
580
|
try self.writer.writeAll(&.{
|
|
396
|
-
@
|
|
397
|
-
@
|
|
398
|
-
@
|
|
399
|
-
@intCast(u8, num + 6),
|
|
581
|
+
@intFromEnum(ArgType.Start),
|
|
582
|
+
@as(u8, @bitCast(args[0])),
|
|
583
|
+
@intFromEnum(reason),
|
|
400
584
|
});
|
|
585
|
+
if (args.len == 3) {
|
|
586
|
+
assert(reason == .Disable or reason == .Mimic or reason == .Encore);
|
|
587
|
+
try self.writer.writeByte(@intFromEnum(args[2]));
|
|
588
|
+
} else if (args.len == 4) {
|
|
589
|
+
assert(reason == .TypeChange);
|
|
590
|
+
// FIXME: u16 types in Generation II
|
|
591
|
+
try self.writer.writeAll(&.{
|
|
592
|
+
@as(u8, @bitCast(args[2])),
|
|
593
|
+
@as(u8, @bitCast(args[3])),
|
|
594
|
+
});
|
|
595
|
+
}
|
|
401
596
|
}
|
|
402
597
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
598
|
+
// ident: ID, reason: End
|
|
599
|
+
pub fn end(self: Self, args: anytype) Error!void {
|
|
600
|
+
if (!enabled) return;
|
|
407
601
|
|
|
408
|
-
pub fn fail(self: Self, ident: ID, reason: Fail) Error!void {
|
|
409
|
-
if (!trace) return;
|
|
410
602
|
try self.writer.writeAll(&.{
|
|
411
|
-
@
|
|
412
|
-
@
|
|
413
|
-
@
|
|
603
|
+
@intFromEnum(ArgType.End),
|
|
604
|
+
@as(u8, @bitCast(args[0])),
|
|
605
|
+
@intFromEnum(@as(End, args[1])),
|
|
414
606
|
});
|
|
415
607
|
}
|
|
416
608
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
609
|
+
// -
|
|
610
|
+
pub fn ohko(self: Self, _: anytype) Error!void {
|
|
611
|
+
if (!enabled) return;
|
|
612
|
+
|
|
613
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.OHKO)});
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// ident: ID
|
|
617
|
+
pub fn crit(self: Self, args: anytype) Error!void {
|
|
618
|
+
if (!enabled) return;
|
|
619
|
+
|
|
620
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Crit), @as(u8, @bitCast(args[0])) });
|
|
420
621
|
}
|
|
421
622
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
623
|
+
// ident: ID
|
|
624
|
+
pub fn supereffective(self: Self, args: anytype) Error!void {
|
|
625
|
+
if (!enabled) return;
|
|
626
|
+
|
|
627
|
+
try self.writer.writeAll(&.{
|
|
628
|
+
@intFromEnum(ArgType.SuperEffective),
|
|
629
|
+
@as(u8, @bitCast(args[0])),
|
|
630
|
+
});
|
|
425
631
|
}
|
|
426
632
|
|
|
427
|
-
|
|
428
|
-
|
|
633
|
+
// ident: ID
|
|
634
|
+
pub fn resisted(self: Self, args: anytype) Error!void {
|
|
635
|
+
if (!enabled) return;
|
|
636
|
+
|
|
429
637
|
try self.writer.writeAll(&.{
|
|
430
|
-
@
|
|
431
|
-
@
|
|
432
|
-
@enumToInt(m),
|
|
638
|
+
@intFromEnum(ArgType.Resisted),
|
|
639
|
+
@as(u8, @bitCast(args[0])),
|
|
433
640
|
});
|
|
434
641
|
}
|
|
435
642
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
643
|
+
// ident: ID, reason: Immune
|
|
644
|
+
pub fn immune(self: Self, args: anytype) Error!void {
|
|
645
|
+
if (!enabled) return;
|
|
646
|
+
|
|
647
|
+
try self.writer.writeAll(&.{
|
|
648
|
+
@intFromEnum(ArgType.Immune),
|
|
649
|
+
@as(u8, @bitCast(args[0])),
|
|
650
|
+
@intFromEnum(@as(Immune, args[1])),
|
|
651
|
+
});
|
|
439
652
|
}
|
|
440
653
|
|
|
441
|
-
|
|
442
|
-
|
|
654
|
+
// source: ID, target: ID
|
|
655
|
+
pub fn transform(self: Self, args: anytype) Error!void {
|
|
656
|
+
if (!enabled) return;
|
|
657
|
+
|
|
443
658
|
try self.writer.writeAll(&.{
|
|
444
|
-
@
|
|
445
|
-
@
|
|
446
|
-
@
|
|
659
|
+
@intFromEnum(ArgType.Transform),
|
|
660
|
+
@as(u8, @bitCast(args[0])),
|
|
661
|
+
@as(u8, @bitCast(args[1])),
|
|
447
662
|
});
|
|
448
663
|
}
|
|
449
664
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
665
|
+
// ident: ID, pokemon: <Pokemon>
|
|
666
|
+
pub fn drag(self: Self, args: anytype) Error!void {
|
|
667
|
+
return switchDrag(self, .Drag, args);
|
|
453
668
|
}
|
|
454
669
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
670
|
+
// target: ID, item: <Item>, source: ID
|
|
671
|
+
pub fn item(self: Self, args: anytype) Error!void {
|
|
672
|
+
if (!enabled) return;
|
|
673
|
+
|
|
458
674
|
try self.writer.writeAll(&.{
|
|
459
|
-
@
|
|
460
|
-
@
|
|
461
|
-
@
|
|
675
|
+
@intFromEnum(ArgType.Item),
|
|
676
|
+
@as(u8, @bitCast(args[0])),
|
|
677
|
+
@intFromEnum(args[1]),
|
|
678
|
+
@as(u8, @bitCast(args[2])),
|
|
462
679
|
});
|
|
463
680
|
}
|
|
464
681
|
|
|
465
|
-
|
|
466
|
-
|
|
682
|
+
// ident: ID, item: <Item>, reason: EndItem
|
|
683
|
+
pub fn enditem(self: Self, args: anytype) Error!void {
|
|
684
|
+
if (!enabled) return;
|
|
685
|
+
|
|
467
686
|
try self.writer.writeAll(&.{
|
|
468
|
-
@
|
|
469
|
-
@
|
|
470
|
-
@
|
|
471
|
-
@
|
|
472
|
-
@bitCast(u8, target),
|
|
687
|
+
@intFromEnum(ArgType.EndItem),
|
|
688
|
+
@as(u8, @bitCast(args[0])),
|
|
689
|
+
@intFromEnum(args[1]),
|
|
690
|
+
@intFromEnum(@as(EndItem, args[2])),
|
|
473
691
|
});
|
|
474
692
|
}
|
|
475
693
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
694
|
+
// source: ID
|
|
695
|
+
pub fn cureteam(self: Self, args: anytype) Error!void {
|
|
696
|
+
if (!enabled) return;
|
|
697
|
+
|
|
479
698
|
try self.writer.writeAll(&.{
|
|
480
|
-
@
|
|
481
|
-
@
|
|
482
|
-
@enumToInt(reason),
|
|
483
|
-
@enumToInt(m),
|
|
699
|
+
@intFromEnum(ArgType.CureTeam),
|
|
700
|
+
@as(u8, @bitCast(args[0])),
|
|
484
701
|
});
|
|
485
702
|
}
|
|
486
703
|
|
|
487
|
-
|
|
488
|
-
|
|
704
|
+
// ident: ID, pokemon: <Pokemon>, reason: SetHP
|
|
705
|
+
pub fn sethp(self: Self, args: anytype) Error!void {
|
|
706
|
+
if (!enabled) return;
|
|
707
|
+
|
|
708
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.SetHP), @as(u8, @bitCast(args[0])) });
|
|
709
|
+
try self.writer.writeIntNative(u16, args[1].hp);
|
|
710
|
+
try self.writer.writeIntNative(u16, args[1].stats.hp);
|
|
711
|
+
try self.writer.writeAll(&.{args[1].status});
|
|
712
|
+
try self.writer.writeByte(@intFromEnum(@as(SetHP, args[2])));
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// ident: ID, num: i8
|
|
716
|
+
pub fn setboost(self: Self, args: anytype) Error!void {
|
|
717
|
+
if (!enabled) return;
|
|
718
|
+
|
|
489
719
|
try self.writer.writeAll(&.{
|
|
490
|
-
@
|
|
491
|
-
@
|
|
492
|
-
@
|
|
720
|
+
@intFromEnum(ArgType.SetBoost),
|
|
721
|
+
@as(u8, @bitCast(args[0])),
|
|
722
|
+
@as(u8, @intCast(args[1] + 6)),
|
|
493
723
|
});
|
|
494
724
|
}
|
|
495
725
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
726
|
+
// source: ID, target: ID
|
|
727
|
+
pub fn copyboost(self: Self, args: anytype) Error!void {
|
|
728
|
+
if (!enabled) return;
|
|
729
|
+
|
|
730
|
+
try self.writer.writeAll(&.{
|
|
731
|
+
@intFromEnum(ArgType.CopyBoost),
|
|
732
|
+
@as(u8, @bitCast(args[0])),
|
|
733
|
+
@as(u8, @bitCast(args[1])),
|
|
734
|
+
});
|
|
499
735
|
}
|
|
500
736
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
737
|
+
// player: Player, reason: Side
|
|
738
|
+
pub fn sidestart(self: Self, args: anytype) Error!void {
|
|
739
|
+
if (!enabled) return;
|
|
740
|
+
|
|
741
|
+
try self.writer.writeAll(&.{
|
|
742
|
+
@intFromEnum(ArgType.SideStart),
|
|
743
|
+
@intFromEnum(@as(Player, args[0])),
|
|
744
|
+
@intFromEnum(@as(Side, args[1])),
|
|
745
|
+
});
|
|
504
746
|
}
|
|
505
747
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
748
|
+
// player: Player, reason: Side
|
|
749
|
+
// player: Player, reason: .Spikes, source: ID
|
|
750
|
+
pub fn sideend(self: Self, args: anytype) Error!void {
|
|
751
|
+
if (!enabled) return;
|
|
752
|
+
|
|
753
|
+
assert(args[1] != .Spikes or args.len == 3);
|
|
754
|
+
try self.writer.writeAll(&.{
|
|
755
|
+
@intFromEnum(ArgType.SideEnd),
|
|
756
|
+
@intFromEnum(@as(Player, args[0])),
|
|
757
|
+
@intFromEnum(@as(Side, args[1])),
|
|
758
|
+
});
|
|
759
|
+
if (args.len == 3) try self.writer.writeByte(@as(u8, @bitCast(args[2])));
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// ident: ID, move: <Move>
|
|
763
|
+
pub fn singlemove(self: Self, args: anytype) Error!void {
|
|
764
|
+
return single(self, .SingleMove, args);
|
|
509
765
|
}
|
|
510
766
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
767
|
+
// ident: ID, move: <Move>
|
|
768
|
+
pub fn singleturn(self: Self, args: anytype) Error!void {
|
|
769
|
+
return single(self, .SingleTurn, args);
|
|
514
770
|
}
|
|
515
771
|
|
|
516
|
-
|
|
517
|
-
|
|
772
|
+
// ident: ID, move: <Move>
|
|
773
|
+
fn single(self: Self, arg: ArgType, args: anytype) Error!void {
|
|
774
|
+
if (!enabled) return;
|
|
775
|
+
|
|
518
776
|
try self.writer.writeAll(&.{
|
|
519
|
-
@
|
|
520
|
-
@
|
|
521
|
-
@
|
|
777
|
+
@intFromEnum(arg),
|
|
778
|
+
@as(u8, @bitCast(args[0])),
|
|
779
|
+
@intFromEnum(args[1]),
|
|
522
780
|
});
|
|
523
781
|
}
|
|
524
782
|
|
|
525
|
-
|
|
526
|
-
|
|
783
|
+
// weather: <Weather>, reason: Weather
|
|
784
|
+
pub fn weather(self: Self, args: anytype) Error!void {
|
|
785
|
+
if (!enabled) return;
|
|
786
|
+
|
|
787
|
+
assert(!(args[0] == .None and args[1] == .Upkeep));
|
|
527
788
|
try self.writer.writeAll(&.{
|
|
528
|
-
@
|
|
529
|
-
@
|
|
530
|
-
@
|
|
789
|
+
@intFromEnum(ArgType.Weather),
|
|
790
|
+
@intFromEnum(args[0]),
|
|
791
|
+
@intFromEnum(@as(Weather, args[1])),
|
|
531
792
|
});
|
|
532
793
|
}
|
|
533
794
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
795
|
+
// -
|
|
796
|
+
pub fn laststill(self: Self, _: anytype) Error!void {
|
|
797
|
+
if (!enabled) return;
|
|
798
|
+
|
|
799
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastStill)});
|
|
537
800
|
}
|
|
538
801
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
802
|
+
// -
|
|
803
|
+
pub fn lastmiss(self: Self, _: anytype) Error!void {
|
|
804
|
+
if (!enabled) return;
|
|
805
|
+
|
|
806
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastMiss)});
|
|
542
807
|
}
|
|
543
808
|
};
|
|
544
809
|
}
|
|
545
810
|
|
|
811
|
+
/// `Log` type backed by the optimized `ByteStream.Writer`.
|
|
546
812
|
pub const FixedLog = Log(ByteStream.Writer);
|
|
547
813
|
|
|
814
|
+
/// Stripped down version of `std.io.FixedBufferStream` optimized for efficiently writing the
|
|
815
|
+
/// individual protocol bytes. Note that the `ByteStream.Writer` is **not** a `std.io.Writer` and
|
|
816
|
+
/// should not be used for general purpose writing.
|
|
548
817
|
pub const ByteStream = struct {
|
|
549
818
|
buffer: []u8,
|
|
550
819
|
pos: usize = 0,
|
|
@@ -585,15 +854,19 @@ pub const ByteStream = struct {
|
|
|
585
854
|
}
|
|
586
855
|
};
|
|
587
856
|
|
|
588
|
-
pub const Kind = enum { Move, Species, Type, Status };
|
|
589
|
-
pub const Formatter = fn (Kind, u8) []const u8;
|
|
857
|
+
pub const Kind = enum { Move, Species, Type, Status, Item, Weather };
|
|
590
858
|
|
|
591
|
-
pub fn format(
|
|
859
|
+
pub fn format(
|
|
860
|
+
comptime gen: anytype,
|
|
861
|
+
a: []const u8,
|
|
862
|
+
b: ?[]const u8,
|
|
863
|
+
color: bool,
|
|
864
|
+
) void {
|
|
592
865
|
print("\n", .{});
|
|
593
866
|
|
|
594
867
|
var i: usize = 0;
|
|
595
868
|
while (i < a.len) {
|
|
596
|
-
const arg = @
|
|
869
|
+
const arg: ArgType = @enumFromInt(a[i]);
|
|
597
870
|
const name = switch (arg) {
|
|
598
871
|
.None => if (color) "\x1b[2m-\x1b[0m" else "-",
|
|
599
872
|
.LastStill => "|[still]",
|
|
@@ -626,6 +899,18 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
626
899
|
.Resisted => "|-resisted|",
|
|
627
900
|
.Immune => "|-immune|",
|
|
628
901
|
.Transform => "|-transform|",
|
|
902
|
+
.Drag => "|drag|",
|
|
903
|
+
.Item => "|-item|",
|
|
904
|
+
.EndItem => "|-enditem|",
|
|
905
|
+
.CureTeam => "|-cureteam|",
|
|
906
|
+
.SetHP => "|-sethp|",
|
|
907
|
+
.SetBoost => "|-setboost|",
|
|
908
|
+
.CopyBoost => "|-copyboost|",
|
|
909
|
+
.SideStart => "|-sidestart|",
|
|
910
|
+
.SideEnd => "|-sideend|",
|
|
911
|
+
.SingleMove => "|-singlemove|",
|
|
912
|
+
.SingleTurn => "|-singleturn|",
|
|
913
|
+
.Weather => "|-weather|",
|
|
629
914
|
else => unreachable,
|
|
630
915
|
};
|
|
631
916
|
printc("{s}", .{name}, a, b, &i, 1, color);
|
|
@@ -639,19 +924,29 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
639
924
|
.OHKO,
|
|
640
925
|
=> {},
|
|
641
926
|
.Move => {
|
|
642
|
-
const source = ID.from(@intCast(
|
|
927
|
+
const source = ID.from(@intCast(a[i]));
|
|
643
928
|
printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
|
|
644
|
-
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
645
|
-
const target = ID.from(@intCast(
|
|
929
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
930
|
+
const target = ID.from(@intCast(a[i]));
|
|
646
931
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
647
|
-
const reason = @
|
|
932
|
+
const reason: Move = @enumFromInt(a[i]);
|
|
648
933
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
649
|
-
if (reason == .From)
|
|
934
|
+
if (reason == .From) {
|
|
935
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
936
|
+
}
|
|
650
937
|
},
|
|
651
|
-
.Switch => {
|
|
652
|
-
const id = ID.from(@intCast(
|
|
938
|
+
.Switch, .Drag => {
|
|
939
|
+
const id = ID.from(@intCast(a[i]));
|
|
653
940
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
654
|
-
printc(" {s}", .{formatter(.Species, a[i])}, a, b, &i, 1, color);
|
|
941
|
+
printc(" {s}", .{formatter(gen, .Species, a[i])}, a, b, &i, 1, color);
|
|
942
|
+
if (@hasDecl(gen, "Gender")) {
|
|
943
|
+
if (a[i] == N(gen.Gender.Unknown)) {
|
|
944
|
+
i += 1;
|
|
945
|
+
} else {
|
|
946
|
+
var gender = if (a[i] == N(gen.Gender.Male)) "M" else "F";
|
|
947
|
+
printc(", {s}", .{gender}, a, b, &i, 1, color);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
655
950
|
printc(" L{d}", .{a[i]}, a, b, &i, 1, color);
|
|
656
951
|
switch (endian) {
|
|
657
952
|
.Big => {
|
|
@@ -667,15 +962,15 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
667
962
|
printc("/{d}", .{hp}, a, b, &i, 2, color);
|
|
668
963
|
},
|
|
669
964
|
}
|
|
670
|
-
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
965
|
+
printc(" {s}", .{formatter(gen, .Status, a[i])}, a, b, &i, 1, color);
|
|
671
966
|
},
|
|
672
967
|
.Cant => {
|
|
673
|
-
const id = ID.from(@intCast(
|
|
968
|
+
const id = ID.from(@intCast(a[i]));
|
|
674
969
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
675
|
-
const reason = @
|
|
970
|
+
const reason: Cant = @enumFromInt(a[i]);
|
|
676
971
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
677
972
|
if (reason == .Disable) {
|
|
678
|
-
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
973
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
679
974
|
}
|
|
680
975
|
},
|
|
681
976
|
.Faint,
|
|
@@ -684,8 +979,9 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
684
979
|
.Crit,
|
|
685
980
|
.SuperEffective,
|
|
686
981
|
.Resisted,
|
|
982
|
+
.CureTeam,
|
|
687
983
|
=> {
|
|
688
|
-
const id = ID.from(@intCast(
|
|
984
|
+
const id = ID.from(@intCast(a[i]));
|
|
689
985
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
690
986
|
},
|
|
691
987
|
.Turn => {
|
|
@@ -695,9 +991,11 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
695
991
|
};
|
|
696
992
|
printc(" {d}", .{turn}, a, b, &i, 2, color);
|
|
697
993
|
},
|
|
698
|
-
.Win =>
|
|
994
|
+
.Win => {
|
|
995
|
+
printc(" {s}", .{@tagName(@as(Player, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
996
|
+
},
|
|
699
997
|
.Damage, .Heal => {
|
|
700
|
-
var id = ID.from(@intCast(
|
|
998
|
+
var id = ID.from(@intCast(a[i]));
|
|
701
999
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
702
1000
|
switch (endian) {
|
|
703
1001
|
.Big => {
|
|
@@ -713,95 +1011,157 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
713
1011
|
printc("/{d}", .{hp}, a, b, &i, 2, color);
|
|
714
1012
|
},
|
|
715
1013
|
}
|
|
716
|
-
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
1014
|
+
printc(" {s}", .{formatter(gen, .Status, a[i])}, a, b, &i, 1, color);
|
|
717
1015
|
if (arg == .Damage) {
|
|
718
|
-
const reason = a[i];
|
|
719
|
-
printc(" {s}", .{@tagName(
|
|
720
|
-
if (reason ==
|
|
721
|
-
id = ID.from(@intCast(
|
|
1016
|
+
const reason: Damage = @enumFromInt(a[i]);
|
|
1017
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
1018
|
+
if (reason == .RecoilOf) {
|
|
1019
|
+
id = ID.from(@intCast(a[i]));
|
|
722
1020
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
723
1021
|
}
|
|
724
1022
|
} else {
|
|
725
|
-
const reason = @
|
|
1023
|
+
const reason: Heal = @enumFromInt(a[i]);
|
|
726
1024
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
727
1025
|
if (reason == .Drain) {
|
|
728
|
-
id = ID.from(@intCast(
|
|
1026
|
+
id = ID.from(@intCast(a[i]));
|
|
729
1027
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
730
1028
|
}
|
|
731
1029
|
}
|
|
732
1030
|
},
|
|
733
1031
|
.Status => {
|
|
734
|
-
const id = ID.from(@intCast(
|
|
1032
|
+
const id = ID.from(@intCast(a[i]));
|
|
735
1033
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
736
|
-
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
737
|
-
const reason = @
|
|
1034
|
+
printc(" {s}", .{formatter(gen, .Status, a[i])}, a, b, &i, 1, color);
|
|
1035
|
+
const reason: Status = @enumFromInt(a[i]);
|
|
738
1036
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
739
|
-
if (reason == .From)
|
|
1037
|
+
if (reason == .From) {
|
|
1038
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
1039
|
+
}
|
|
740
1040
|
},
|
|
741
1041
|
.CureStatus => {
|
|
742
|
-
const id = ID.from(@intCast(
|
|
1042
|
+
const id = ID.from(@intCast(a[i]));
|
|
743
1043
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
744
|
-
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
745
|
-
|
|
1044
|
+
printc(" {s}", .{formatter(gen, .Status, a[i])}, a, b, &i, 1, color);
|
|
1045
|
+
const reason: CureStatus = @enumFromInt(a[i]);
|
|
1046
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
746
1047
|
},
|
|
747
1048
|
.Boost => {
|
|
748
|
-
const id = ID.from(@intCast(
|
|
1049
|
+
const id = ID.from(@intCast(a[i]));
|
|
749
1050
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
750
|
-
printc(" {s}", .{@tagName(@
|
|
1051
|
+
printc(" {s}", .{@tagName(@as(Boost, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
751
1052
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
752
1053
|
},
|
|
753
1054
|
.Fail => {
|
|
754
|
-
const id = ID.from(@intCast(
|
|
1055
|
+
const id = ID.from(@intCast(a[i]));
|
|
755
1056
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
756
|
-
printc(" {s}", .{@tagName(@
|
|
1057
|
+
printc(" {s}", .{@tagName(@as(Fail, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
757
1058
|
},
|
|
758
|
-
.HitCount => {
|
|
759
|
-
const id = ID.from(@intCast(
|
|
1059
|
+
.HitCount, .SetBoost => {
|
|
1060
|
+
const id = ID.from(@intCast(a[i]));
|
|
760
1061
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
761
1062
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
762
1063
|
},
|
|
763
|
-
.Prepare => {
|
|
764
|
-
const id = ID.from(@intCast(
|
|
1064
|
+
.Prepare, .SingleMove, .SingleTurn => {
|
|
1065
|
+
const id = ID.from(@intCast(a[i]));
|
|
765
1066
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
766
|
-
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
1067
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
767
1068
|
},
|
|
768
1069
|
.Activate => {
|
|
769
|
-
const id = ID.from(@intCast(
|
|
1070
|
+
const id = ID.from(@intCast(a[i]));
|
|
770
1071
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
771
|
-
|
|
1072
|
+
const reason: Activate = @enumFromInt(a[i]);
|
|
1073
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
1074
|
+
if (reason == .SubstituteBlock) {
|
|
1075
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
1076
|
+
} else if (reason == .Magnitude) {
|
|
1077
|
+
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
1078
|
+
}
|
|
772
1079
|
},
|
|
773
1080
|
.Start => {
|
|
774
|
-
const id = ID.from(@intCast(
|
|
1081
|
+
const id = ID.from(@intCast(a[i]));
|
|
775
1082
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
776
1083
|
const reason = a[i];
|
|
777
|
-
printc(" {s}", .{@tagName(@
|
|
778
|
-
if (@
|
|
779
|
-
|
|
1084
|
+
printc(" {s}", .{@tagName(@as(Start, @enumFromInt(reason)))}, a, b, &i, 1, color);
|
|
1085
|
+
if (@as(Start, @enumFromInt(reason)) == .TypeChange) {
|
|
1086
|
+
// FIXME
|
|
1087
|
+
const types = @as(gen1.Types, @bitCast(a[i]));
|
|
780
1088
|
const args = .{
|
|
781
|
-
formatter(.Type, @
|
|
782
|
-
formatter(.Type, @
|
|
1089
|
+
formatter(gen, .Type, @intFromEnum(types.type1)),
|
|
1090
|
+
formatter(gen, .Type, @intFromEnum(types.type2)),
|
|
783
1091
|
};
|
|
784
1092
|
printc(" {s}/{s}", args, a, b, &i, 1, color);
|
|
785
|
-
} else if (reason >= @
|
|
786
|
-
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
1093
|
+
} else if (reason >= @intFromEnum(Start.Disable)) {
|
|
1094
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
787
1095
|
}
|
|
788
1096
|
},
|
|
789
1097
|
.End => {
|
|
790
|
-
const id = ID.from(@intCast(
|
|
1098
|
+
const id = ID.from(@intCast(a[i]));
|
|
791
1099
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
792
|
-
printc(" {s}", .{@tagName(@
|
|
1100
|
+
printc(" {s}", .{@tagName(@as(End, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
793
1101
|
},
|
|
794
1102
|
.Immune => {
|
|
795
|
-
const id = ID.from(@intCast(
|
|
1103
|
+
const id = ID.from(@intCast(a[i]));
|
|
796
1104
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
797
|
-
printc(" {s}", .{@tagName(@
|
|
1105
|
+
printc(" {s}", .{@tagName(@as(Immune, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
798
1106
|
},
|
|
799
|
-
.Transform => {
|
|
800
|
-
const source = ID.from(@intCast(
|
|
1107
|
+
.Transform, .CopyBoost => {
|
|
1108
|
+
const source = ID.from(@intCast(a[i]));
|
|
801
1109
|
printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
|
|
802
|
-
const target = ID.from(@intCast(
|
|
1110
|
+
const target = ID.from(@intCast(a[i]));
|
|
803
1111
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
804
1112
|
},
|
|
1113
|
+
.Item, .EndItem => {
|
|
1114
|
+
var id = ID.from(@intCast(a[i]));
|
|
1115
|
+
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
1116
|
+
printc(" {s}", .{formatter(gen, .Item, a[i])}, a, b, &i, 1, color);
|
|
1117
|
+
if (arg == .Item) {
|
|
1118
|
+
id = ID.from(@intCast(a[i]));
|
|
1119
|
+
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
1120
|
+
} else {
|
|
1121
|
+
const reason: EndItem = @enumFromInt(a[i]);
|
|
1122
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
1123
|
+
}
|
|
1124
|
+
},
|
|
1125
|
+
.SetHP => {
|
|
1126
|
+
const id = ID.from(@intCast(a[i]));
|
|
1127
|
+
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
1128
|
+
switch (endian) {
|
|
1129
|
+
.Big => {
|
|
1130
|
+
var hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
|
|
1131
|
+
printc(" {d}", .{hp}, a, b, &i, 2, color);
|
|
1132
|
+
hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
|
|
1133
|
+
printc("/{d}", .{hp}, a, b, &i, 2, color);
|
|
1134
|
+
},
|
|
1135
|
+
.Little => {
|
|
1136
|
+
var hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
|
|
1137
|
+
printc(" {d}", .{hp}, a, b, &i, 2, color);
|
|
1138
|
+
hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
|
|
1139
|
+
printc("/{d}", .{hp}, a, b, &i, 2, color);
|
|
1140
|
+
},
|
|
1141
|
+
}
|
|
1142
|
+
printc(" {s}", .{formatter(gen, .Status, a[i])}, a, b, &i, 1, color);
|
|
1143
|
+
printc(" {s}", .{@tagName(@as(SetHP, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
1144
|
+
},
|
|
1145
|
+
.SideStart => {
|
|
1146
|
+
const id = ID.from(@intCast(a[i]));
|
|
1147
|
+
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
1148
|
+
printc(" {s}", .{@tagName(@as(Side, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
1149
|
+
},
|
|
1150
|
+
.SideEnd => {
|
|
1151
|
+
var id = ID.from(@intCast(a[i]));
|
|
1152
|
+
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
1153
|
+
const reason: Side = @enumFromInt(a[i]);
|
|
1154
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
1155
|
+
if (reason == .Spikes) {
|
|
1156
|
+
printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
|
|
1157
|
+
id = ID.from(@intCast(a[i]));
|
|
1158
|
+
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1161
|
+
.Weather => {
|
|
1162
|
+
printc(" {s}", .{formatter(gen, .Weather, a[i])}, a, b, &i, 1, color);
|
|
1163
|
+
printc(" {s}", .{@tagName(@as(Weather, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
1164
|
+
},
|
|
805
1165
|
else => unreachable,
|
|
806
1166
|
}
|
|
807
1167
|
print("\n", .{});
|
|
@@ -833,12 +1193,13 @@ fn printc(
|
|
|
833
1193
|
}
|
|
834
1194
|
|
|
835
1195
|
pub fn expectLog(
|
|
836
|
-
comptime
|
|
1196
|
+
comptime gen: anytype,
|
|
837
1197
|
expected: []const u8,
|
|
838
1198
|
actual: []const u8,
|
|
839
1199
|
offset: usize,
|
|
840
1200
|
) !void {
|
|
841
|
-
if (!
|
|
1201
|
+
if (!enabled) return;
|
|
1202
|
+
|
|
842
1203
|
const color = color: {
|
|
843
1204
|
if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
|
|
844
1205
|
break :color true;
|
|
@@ -851,8 +1212,8 @@ pub fn expectLog(
|
|
|
851
1212
|
|
|
852
1213
|
expectEqualBytes(expected, actual, offset) catch |err| switch (err) {
|
|
853
1214
|
error.TestExpectedEqual => {
|
|
854
|
-
format(
|
|
855
|
-
format(
|
|
1215
|
+
format(gen, expected, null, color);
|
|
1216
|
+
format(gen, actual, expected, color);
|
|
856
1217
|
return err;
|
|
857
1218
|
},
|
|
858
1219
|
else => return err,
|
|
@@ -881,7 +1242,7 @@ fn expectEqualBytes(expected: []const u8, actual: []const u8, offset: usize) !vo
|
|
|
881
1242
|
const endian = builtin.target.cpu.arch.endian();
|
|
882
1243
|
|
|
883
1244
|
fn N(e: anytype) u8 {
|
|
884
|
-
return @
|
|
1245
|
+
return @intFromEnum(e);
|
|
885
1246
|
}
|
|
886
1247
|
|
|
887
1248
|
const p1 = Player.P1;
|
|
@@ -892,49 +1253,70 @@ const gen1 = struct {
|
|
|
892
1253
|
pub const helpers = @import("../gen1/helpers.zig");
|
|
893
1254
|
};
|
|
894
1255
|
|
|
895
|
-
|
|
896
|
-
|
|
1256
|
+
const gen2 = struct {
|
|
1257
|
+
pub usingnamespace @import("../gen2/data.zig");
|
|
1258
|
+
pub const helpers = @import("../gen2/helpers.zig");
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
var buf: [pkmn.LOGS_SIZE]u8 = undefined;
|
|
1262
|
+
var stream: ByteStream = .{ .buffer = &buf };
|
|
897
1263
|
var log: FixedLog = .{ .writer = stream.writer() };
|
|
898
1264
|
|
|
899
|
-
const
|
|
900
|
-
const
|
|
1265
|
+
const M1 = gen1.Move;
|
|
1266
|
+
const S1 = gen1.Species;
|
|
1267
|
+
|
|
1268
|
+
const M2 = gen2.Move;
|
|
1269
|
+
const S2 = gen2.Species;
|
|
1270
|
+
const I2 = gen2.Item;
|
|
1271
|
+
const W2 = gen2.Weather;
|
|
901
1272
|
|
|
902
1273
|
fn expectLog1(expected: []const u8, actual: []const u8) !void {
|
|
903
|
-
return expectLog(
|
|
1274
|
+
return expectLog(gen1, expected, actual, 0);
|
|
904
1275
|
}
|
|
905
1276
|
|
|
906
|
-
fn
|
|
1277
|
+
fn expectLog2(expected: []const u8, actual: []const u8) !void {
|
|
1278
|
+
return expectLog(gen2, expected, actual, 0);
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
fn formatter(comptime gen: anytype, kind: Kind, byte: u8) []const u8 {
|
|
907
1282
|
return switch (kind) {
|
|
908
|
-
.Move => @tagName(@
|
|
909
|
-
.Species => @tagName(@
|
|
910
|
-
.Type => @tagName(@
|
|
911
|
-
.Status =>
|
|
1283
|
+
.Move => @tagName(@as(gen.Move, @enumFromInt(byte))),
|
|
1284
|
+
.Species => @tagName(@as(gen.Species, @enumFromInt(byte))),
|
|
1285
|
+
.Type => @tagName(@as(gen.Type, @enumFromInt(byte))),
|
|
1286
|
+
.Status => gen.Status.name(byte),
|
|
1287
|
+
.Item => if (@hasDecl(gen, "Item"))
|
|
1288
|
+
@tagName(@as(gen.Item, @enumFromInt(byte)))
|
|
1289
|
+
else
|
|
1290
|
+
unreachable,
|
|
1291
|
+
.Weather => if (@hasDecl(gen, "Weather"))
|
|
1292
|
+
@tagName(@as(gen.Weather, @enumFromInt(byte)))
|
|
1293
|
+
else
|
|
1294
|
+
unreachable,
|
|
912
1295
|
};
|
|
913
1296
|
}
|
|
914
1297
|
|
|
915
1298
|
test "|move|" {
|
|
916
|
-
try log.move(p2.ident(4),
|
|
1299
|
+
try log.move(.{ p2.ident(4), M1.Thunderbolt, p1.ident(5) });
|
|
917
1300
|
try expectLog1(
|
|
918
|
-
&.{ N(ArgType.Move), 0b1100, N(
|
|
1301
|
+
&.{ N(ArgType.Move), 0b1100, N(M1.Thunderbolt), 0b0101, N(Move.None) },
|
|
919
1302
|
buf[0..5],
|
|
920
1303
|
);
|
|
921
1304
|
stream.reset();
|
|
922
1305
|
|
|
923
|
-
try log.move(p2.ident(4),
|
|
924
|
-
const wrap = N(M.Wrap);
|
|
1306
|
+
try log.move(.{ p2.ident(4), M1.Pound, p1.ident(5), M1.Metronome });
|
|
925
1307
|
try expectLog1(
|
|
926
|
-
&.{ N(ArgType.Move), 0b1100,
|
|
1308
|
+
&.{ N(ArgType.Move), 0b1100, N(M1.Pound), 0b0101, N(Move.From), N(M1.Metronome) },
|
|
927
1309
|
buf[0..6],
|
|
928
1310
|
);
|
|
929
1311
|
stream.reset();
|
|
930
1312
|
|
|
931
|
-
try log.move(p2.ident(4),
|
|
932
|
-
try log.laststill();
|
|
1313
|
+
try log.move(.{ p2.ident(4), M1.SkullBash, ID{} });
|
|
1314
|
+
try log.laststill(.{});
|
|
933
1315
|
try expectLog1(
|
|
934
1316
|
&.{
|
|
935
1317
|
N(ArgType.Move),
|
|
936
1318
|
0b1100,
|
|
937
|
-
N(
|
|
1319
|
+
N(M1.SkullBash),
|
|
938
1320
|
0,
|
|
939
1321
|
N(Move.None),
|
|
940
1322
|
N(ArgType.LastStill),
|
|
@@ -943,13 +1325,13 @@ test "|move|" {
|
|
|
943
1325
|
);
|
|
944
1326
|
stream.reset();
|
|
945
1327
|
|
|
946
|
-
try log.move(p2.ident(4),
|
|
947
|
-
try log.lastmiss();
|
|
1328
|
+
try log.move(.{ p2.ident(4), M1.Tackle, p1.ident(5) });
|
|
1329
|
+
try log.lastmiss(.{});
|
|
948
1330
|
try expectLog1(
|
|
949
1331
|
&.{
|
|
950
1332
|
N(ArgType.Move),
|
|
951
1333
|
0b1100,
|
|
952
|
-
N(
|
|
1334
|
+
N(M1.Tackle),
|
|
953
1335
|
0b0101,
|
|
954
1336
|
N(Move.None),
|
|
955
1337
|
N(ArgType.LastMiss),
|
|
@@ -965,11 +1347,11 @@ test "|switch|" {
|
|
|
965
1347
|
snorlax.hp = 200;
|
|
966
1348
|
snorlax.stats.hp = 400;
|
|
967
1349
|
snorlax.status = gen1.Status.init(.PAR);
|
|
968
|
-
try log.switched(p2.ident(3), &snorlax);
|
|
1350
|
+
try log.switched(.{ p2.ident(3), &snorlax });
|
|
969
1351
|
const par = 0b1000000;
|
|
970
1352
|
var expected: []const u8 = switch (endian) {
|
|
971
|
-
.Big => &.{ N(ArgType.Switch), 0b1011, N(
|
|
972
|
-
.Little => &.{ N(ArgType.Switch), 0b1011, N(
|
|
1353
|
+
.Big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 91, 0, 200, 1, 144, par },
|
|
1354
|
+
.Little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 91, 200, 0, 144, 1, par },
|
|
973
1355
|
};
|
|
974
1356
|
try expectLog1(expected, buf[0..9]);
|
|
975
1357
|
stream.reset();
|
|
@@ -977,46 +1359,65 @@ test "|switch|" {
|
|
|
977
1359
|
snorlax.level = 100;
|
|
978
1360
|
snorlax.hp = 0;
|
|
979
1361
|
snorlax.status = 0;
|
|
980
|
-
try log.switched(p2.ident(3), &snorlax);
|
|
1362
|
+
try log.switched(.{ p2.ident(3), &snorlax });
|
|
981
1363
|
expected = switch (endian) {
|
|
982
|
-
.Big => &.{ N(ArgType.Switch), 0b1011, N(
|
|
983
|
-
.Little => &.{ N(ArgType.Switch), 0b1011, N(
|
|
1364
|
+
.Big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 0, 0, 1, 144, 0 },
|
|
1365
|
+
.Little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 0, 0, 144, 1, 0 },
|
|
984
1366
|
};
|
|
985
1367
|
try expectLog1(expected, buf[0..9]);
|
|
986
1368
|
stream.reset();
|
|
987
1369
|
|
|
988
1370
|
snorlax.hp = 400;
|
|
989
|
-
try log.switched(p2.ident(3), &snorlax);
|
|
1371
|
+
try log.switched(.{ p2.ident(3), &snorlax });
|
|
990
1372
|
expected = switch (endian) {
|
|
991
|
-
.Big => &.{ N(ArgType.Switch), 0b1011, N(
|
|
992
|
-
.Little => &.{ N(ArgType.Switch), 0b1011, N(
|
|
1373
|
+
.Big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 1, 144, 1, 144, 0 },
|
|
1374
|
+
.Little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 144, 1, 144, 1, 0 },
|
|
993
1375
|
};
|
|
994
1376
|
try expectLog1(expected, buf[0..9]);
|
|
995
1377
|
stream.reset();
|
|
1378
|
+
|
|
1379
|
+
var blissey = gen2.helpers.Pokemon.init(.{ .species = .Blissey, .moves = &.{.Splash} });
|
|
1380
|
+
blissey.level = 91;
|
|
1381
|
+
blissey.hp = 200;
|
|
1382
|
+
blissey.stats.hp = 400;
|
|
1383
|
+
blissey.status = gen2.Status.init(.PAR);
|
|
1384
|
+
try log.switched(.{ p2.ident(3), &blissey });
|
|
1385
|
+
expected = &(.{
|
|
1386
|
+
N(ArgType.Switch),
|
|
1387
|
+
0b1011,
|
|
1388
|
+
N(S2.Blissey),
|
|
1389
|
+
N(gen2.Gender.Female),
|
|
1390
|
+
91,
|
|
1391
|
+
} ++ switch (endian) {
|
|
1392
|
+
.Big => .{ 0, 200, 1, 144, par },
|
|
1393
|
+
.Little => .{ 200, 0, 144, 1, par },
|
|
1394
|
+
});
|
|
1395
|
+
try expectLog2(expected, buf[0..10]);
|
|
1396
|
+
stream.reset();
|
|
996
1397
|
}
|
|
997
1398
|
|
|
998
1399
|
test "|cant|" {
|
|
999
|
-
try log.cant(p2.ident(6), .Bound);
|
|
1400
|
+
try log.cant(.{ p2.ident(6), .Bound });
|
|
1000
1401
|
try expectLog1(&.{ N(ArgType.Cant), 0b1110, N(Cant.Bound) }, buf[0..3]);
|
|
1001
1402
|
stream.reset();
|
|
1002
1403
|
|
|
1003
|
-
try log.
|
|
1004
|
-
try expectLog1(&.{ N(ArgType.Cant), 2, N(Cant.Disable), N(
|
|
1404
|
+
try log.cant(.{ p1.ident(2), .Disable, M1.Earthquake });
|
|
1405
|
+
try expectLog1(&.{ N(ArgType.Cant), 2, N(Cant.Disable), N(M1.Earthquake) }, buf[0..4]);
|
|
1005
1406
|
stream.reset();
|
|
1006
1407
|
}
|
|
1007
1408
|
|
|
1008
1409
|
test "|faint|" {
|
|
1009
|
-
try log.faint(p2.ident(2), false);
|
|
1410
|
+
try log.faint(.{ p2.ident(2), false });
|
|
1010
1411
|
try expectLog1(&.{ N(ArgType.Faint), 0b1010 }, buf[0..2]);
|
|
1011
1412
|
stream.reset();
|
|
1012
1413
|
|
|
1013
|
-
try log.faint(p2.ident(2), true);
|
|
1414
|
+
try log.faint(.{ p2.ident(2), true });
|
|
1014
1415
|
try expectLog1(&.{ N(ArgType.Faint), 0b1010, N(ArgType.None) }, buf[0..3]);
|
|
1015
1416
|
stream.reset();
|
|
1016
1417
|
}
|
|
1017
1418
|
|
|
1018
1419
|
test "|turn|" {
|
|
1019
|
-
try log.turn(42);
|
|
1420
|
+
try log.turn(.{42});
|
|
1020
1421
|
var expected = switch (endian) {
|
|
1021
1422
|
.Big => &.{ N(ArgType.Turn), 0, 42, N(ArgType.None) },
|
|
1022
1423
|
.Little => &.{ N(ArgType.Turn), 42, 0, N(ArgType.None) },
|
|
@@ -1026,13 +1427,13 @@ test "|turn|" {
|
|
|
1026
1427
|
}
|
|
1027
1428
|
|
|
1028
1429
|
test "|win|" {
|
|
1029
|
-
try log.win(.P2);
|
|
1430
|
+
try log.win(.{.P2});
|
|
1030
1431
|
try expectLog1(&.{ N(ArgType.Win), 1, N(ArgType.None) }, buf[0..3]);
|
|
1031
1432
|
stream.reset();
|
|
1032
1433
|
}
|
|
1033
1434
|
|
|
1034
1435
|
test "|tie|" {
|
|
1035
|
-
try log.tie();
|
|
1436
|
+
try log.tie(.{});
|
|
1036
1437
|
try expectLog1(&.{ N(ArgType.Tie), N(ArgType.None) }, buf[0..2]);
|
|
1037
1438
|
stream.reset();
|
|
1038
1439
|
}
|
|
@@ -1041,7 +1442,7 @@ test "|-damage|" {
|
|
|
1041
1442
|
var chansey = gen1.helpers.Pokemon.init(.{ .species = .Chansey, .moves = &.{.Splash} });
|
|
1042
1443
|
chansey.hp = 612;
|
|
1043
1444
|
chansey.status = gen1.Status.slp(1);
|
|
1044
|
-
try log.damage(p2.ident(2), &chansey, .None);
|
|
1445
|
+
try log.damage(.{ p2.ident(2), &chansey, .None });
|
|
1045
1446
|
var expected: []const u8 = switch (endian) {
|
|
1046
1447
|
.Big => &.{ N(ArgType.Damage), 0b1010, 2, 100, 2, 191, 1, N(Damage.None) },
|
|
1047
1448
|
.Little => &.{ N(ArgType.Damage), 0b1010, 100, 2, 191, 2, 1, N(Damage.None) },
|
|
@@ -1052,7 +1453,7 @@ test "|-damage|" {
|
|
|
1052
1453
|
chansey.hp = 100;
|
|
1053
1454
|
chansey.stats.hp = 256;
|
|
1054
1455
|
chansey.status = 0;
|
|
1055
|
-
try log.damage(p2.ident(2), &chansey, .Confusion);
|
|
1456
|
+
try log.damage(.{ p2.ident(2), &chansey, .Confusion });
|
|
1056
1457
|
expected = switch (endian) {
|
|
1057
1458
|
.Big => &.{ N(ArgType.Damage), 0b1010, 0, 100, 1, 0, 0, N(Damage.Confusion) },
|
|
1058
1459
|
.Little => &.{ N(ArgType.Damage), 0b1010, 100, 0, 0, 1, 0, N(Damage.Confusion) },
|
|
@@ -1061,7 +1462,7 @@ test "|-damage|" {
|
|
|
1061
1462
|
stream.reset();
|
|
1062
1463
|
|
|
1063
1464
|
chansey.status = gen1.Status.init(.PSN);
|
|
1064
|
-
try log.
|
|
1465
|
+
try log.damage(.{ p2.ident(2), &chansey, .RecoilOf, p1.ident(1) });
|
|
1065
1466
|
expected = switch (endian) {
|
|
1066
1467
|
.Big => &.{ N(ArgType.Damage), 0b1010, 0, 100, 1, 0, 0b1000, N(Damage.RecoilOf), 1 },
|
|
1067
1468
|
.Little => &.{ N(ArgType.Damage), 0b1010, 100, 0, 0, 1, 0b1000, N(Damage.RecoilOf), 1 },
|
|
@@ -1074,7 +1475,7 @@ test "|-heal|" {
|
|
|
1074
1475
|
var chansey = gen1.helpers.Pokemon.init(.{ .species = .Chansey, .moves = &.{.Splash} });
|
|
1075
1476
|
chansey.hp = 612;
|
|
1076
1477
|
chansey.status = gen1.Status.slp(1);
|
|
1077
|
-
try log.heal(p2.ident(2), &chansey, .None);
|
|
1478
|
+
try log.heal(.{ p2.ident(2), &chansey, .None });
|
|
1078
1479
|
var expected: []const u8 = switch (endian) {
|
|
1079
1480
|
.Big => &.{ N(ArgType.Heal), 0b1010, 2, 100, 2, 191, 1, N(Heal.None) },
|
|
1080
1481
|
.Little => &.{ N(ArgType.Heal), 0b1010, 100, 2, 191, 2, 1, N(Heal.None) },
|
|
@@ -1085,7 +1486,7 @@ test "|-heal|" {
|
|
|
1085
1486
|
chansey.hp = 100;
|
|
1086
1487
|
chansey.stats.hp = 256;
|
|
1087
1488
|
chansey.status = 0;
|
|
1088
|
-
try log.heal(p2.ident(2), &chansey, .Silent);
|
|
1489
|
+
try log.heal(.{ p2.ident(2), &chansey, .Silent });
|
|
1089
1490
|
expected = switch (endian) {
|
|
1090
1491
|
.Big => &.{ N(ArgType.Heal), 0b1010, 0, 100, 1, 0, 0, N(Heal.Silent) },
|
|
1091
1492
|
.Little => &.{ N(ArgType.Heal), 0b1010, 100, 0, 0, 1, 0, N(Heal.Silent) },
|
|
@@ -1093,7 +1494,7 @@ test "|-heal|" {
|
|
|
1093
1494
|
try expectLog1(expected, buf[0..8]);
|
|
1094
1495
|
stream.reset();
|
|
1095
1496
|
|
|
1096
|
-
try log.
|
|
1497
|
+
try log.heal(.{ p2.ident(2), &chansey, .Drain, p1.ident(1) });
|
|
1097
1498
|
expected = switch (endian) {
|
|
1098
1499
|
.Big => &.{ N(ArgType.Heal), 0b1010, 0, 100, 1, 0, 0, N(Heal.Drain), 1 },
|
|
1099
1500
|
.Little => &.{ N(ArgType.Heal), 0b1010, 100, 0, 0, 1, 0, N(Heal.Drain), 1 },
|
|
@@ -1103,28 +1504,28 @@ test "|-heal|" {
|
|
|
1103
1504
|
}
|
|
1104
1505
|
|
|
1105
1506
|
test "|-status|" {
|
|
1106
|
-
try log.status(p2.ident(6), gen1.Status.init(.BRN), .None);
|
|
1507
|
+
try log.status(.{ p2.ident(6), gen1.Status.init(.BRN), .None });
|
|
1107
1508
|
try expectLog1(&.{ N(ArgType.Status), 0b1110, 0b10000, N(Status.None) }, buf[0..4]);
|
|
1108
1509
|
stream.reset();
|
|
1109
1510
|
|
|
1110
|
-
try log.status(p2.ident(2), gen1.Status.init(.PSN), .Silent);
|
|
1511
|
+
try log.status(.{ p2.ident(2), gen1.Status.init(.PSN), .Silent });
|
|
1111
1512
|
try expectLog1(&.{ N(ArgType.Status), 0b1010, 0b1000, N(Status.Silent) }, buf[0..4]);
|
|
1112
1513
|
stream.reset();
|
|
1113
1514
|
|
|
1114
|
-
try log.
|
|
1515
|
+
try log.status(.{ p1.ident(1), gen1.Status.init(.PAR), .From, M1.BodySlam });
|
|
1115
1516
|
try expectLog1(
|
|
1116
|
-
&.{ N(ArgType.Status), 0b0001, 0b1000000, N(Status.From), N(
|
|
1517
|
+
&.{ N(ArgType.Status), 0b0001, 0b1000000, N(Status.From), N(M1.BodySlam) },
|
|
1117
1518
|
buf[0..5],
|
|
1118
1519
|
);
|
|
1119
1520
|
stream.reset();
|
|
1120
1521
|
}
|
|
1121
1522
|
|
|
1122
1523
|
test "|-curestatus|" {
|
|
1123
|
-
try log.curestatus(p2.ident(6), gen1.Status.slp(7), .Message);
|
|
1524
|
+
try log.curestatus(.{ p2.ident(6), gen1.Status.slp(7), .Message });
|
|
1124
1525
|
try expectLog1(&.{ N(ArgType.CureStatus), 0b1110, 0b111, N(CureStatus.Message) }, buf[0..4]);
|
|
1125
1526
|
stream.reset();
|
|
1126
1527
|
|
|
1127
|
-
try log.curestatus(p1.ident(2), gen1.Status.TOX, .Silent);
|
|
1528
|
+
try log.curestatus(.{ p1.ident(2), gen1.Status.TOX, .Silent });
|
|
1128
1529
|
try expectLog1(&.{
|
|
1129
1530
|
N(ArgType.CureStatus),
|
|
1130
1531
|
0b0010,
|
|
@@ -1135,163 +1536,306 @@ test "|-curestatus|" {
|
|
|
1135
1536
|
}
|
|
1136
1537
|
|
|
1137
1538
|
test "|-boost|" {
|
|
1138
|
-
try log.boost(p2.ident(6), .Speed, 2);
|
|
1539
|
+
try log.boost(.{ p2.ident(6), .Speed, 2 });
|
|
1139
1540
|
try expectLog1(&.{ N(ArgType.Boost), 0b1110, N(Boost.Speed), 8 }, buf[0..4]);
|
|
1140
1541
|
stream.reset();
|
|
1141
1542
|
|
|
1142
|
-
try log.boost(p1.ident(2), .Rage, 1);
|
|
1543
|
+
try log.boost(.{ p1.ident(2), .Rage, 1 });
|
|
1143
1544
|
try expectLog1(&.{ N(ArgType.Boost), 0b0010, N(Boost.Rage), 7 }, buf[0..4]);
|
|
1144
1545
|
stream.reset();
|
|
1145
1546
|
|
|
1146
|
-
try log.boost(p2.ident(3), .Defense, -2);
|
|
1547
|
+
try log.boost(.{ p2.ident(3), .Defense, -2 });
|
|
1147
1548
|
try expectLog1(&.{ N(ArgType.Boost), 0b1011, N(Boost.Defense), 4 }, buf[0..4]);
|
|
1148
1549
|
stream.reset();
|
|
1149
1550
|
}
|
|
1150
1551
|
|
|
1151
1552
|
test "|-clearallboost|" {
|
|
1152
|
-
try log.clearallboost();
|
|
1553
|
+
try log.clearallboost(.{});
|
|
1153
1554
|
try expectLog1(&.{N(ArgType.ClearAllBoost)}, buf[0..1]);
|
|
1154
1555
|
stream.reset();
|
|
1155
1556
|
}
|
|
1156
1557
|
|
|
1157
1558
|
test "|-fail|" {
|
|
1158
|
-
try log.fail(p2.ident(6), .None);
|
|
1559
|
+
try log.fail(.{ p2.ident(6), .None });
|
|
1159
1560
|
try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.None) }, buf[0..3]);
|
|
1160
1561
|
stream.reset();
|
|
1161
1562
|
|
|
1162
|
-
try log.fail(p2.ident(6), .Sleep);
|
|
1563
|
+
try log.fail(.{ p2.ident(6), .Sleep });
|
|
1163
1564
|
try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.Sleep) }, buf[0..3]);
|
|
1164
1565
|
stream.reset();
|
|
1165
1566
|
|
|
1166
|
-
try log.fail(p2.ident(6), .Substitute);
|
|
1567
|
+
try log.fail(.{ p2.ident(6), .Substitute });
|
|
1167
1568
|
try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.Substitute) }, buf[0..3]);
|
|
1168
1569
|
stream.reset();
|
|
1169
1570
|
|
|
1170
|
-
try log.fail(p2.ident(6), .Weak);
|
|
1571
|
+
try log.fail(.{ p2.ident(6), .Weak });
|
|
1171
1572
|
try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.Weak) }, buf[0..3]);
|
|
1172
1573
|
stream.reset();
|
|
1173
1574
|
}
|
|
1174
1575
|
|
|
1175
1576
|
test "|-miss|" {
|
|
1176
|
-
try log.miss(p2.ident(4));
|
|
1577
|
+
try log.miss(.{p2.ident(4)});
|
|
1177
1578
|
try expectLog1(&.{ N(ArgType.Miss), 0b1100 }, buf[0..2]);
|
|
1178
1579
|
stream.reset();
|
|
1179
1580
|
}
|
|
1180
1581
|
test "|-hitcount|" {
|
|
1181
|
-
try log.hitcount(p2.ident(1), 5);
|
|
1582
|
+
try log.hitcount(.{ p2.ident(1), 5 });
|
|
1182
1583
|
try expectLog1(&.{ N(ArgType.HitCount), 0b1001, 5 }, buf[0..3]);
|
|
1183
1584
|
stream.reset();
|
|
1184
1585
|
}
|
|
1185
1586
|
|
|
1186
1587
|
test "|-prepare|" {
|
|
1187
|
-
try log.prepare(p2.ident(2),
|
|
1188
|
-
try expectLog1(&.{ N(ArgType.Prepare), 0b1010, N(
|
|
1588
|
+
try log.prepare(.{ p2.ident(2), M1.Dig });
|
|
1589
|
+
try expectLog1(&.{ N(ArgType.Prepare), 0b1010, N(M1.Dig) }, buf[0..3]);
|
|
1189
1590
|
stream.reset();
|
|
1190
1591
|
}
|
|
1191
1592
|
|
|
1192
1593
|
test "|-mustrecharge|" {
|
|
1193
|
-
try log.mustrecharge(p1.ident(6));
|
|
1594
|
+
try log.mustrecharge(.{p1.ident(6)});
|
|
1194
1595
|
try expectLog1(&.{ N(ArgType.MustRecharge), 0b0110 }, buf[0..2]);
|
|
1195
1596
|
stream.reset();
|
|
1196
1597
|
}
|
|
1197
1598
|
|
|
1198
1599
|
test "|-activate|" {
|
|
1199
|
-
try log.activate(p1.ident(2), .Struggle);
|
|
1600
|
+
try log.activate(.{ p1.ident(2), .Struggle });
|
|
1200
1601
|
try expectLog1(&.{ N(ArgType.Activate), 0b0010, N(Activate.Struggle) }, buf[0..3]);
|
|
1201
1602
|
stream.reset();
|
|
1202
1603
|
|
|
1203
|
-
try log.activate(p2.ident(4), .Mist);
|
|
1604
|
+
try log.activate(.{ p2.ident(4), .Mist });
|
|
1204
1605
|
try expectLog1(&.{ N(ArgType.Activate), 0b1100, N(Activate.Mist) }, buf[0..3]);
|
|
1205
1606
|
stream.reset();
|
|
1206
1607
|
|
|
1207
|
-
try log.activate(p2.ident(6), .Substitute);
|
|
1608
|
+
try log.activate(.{ p2.ident(6), .Substitute });
|
|
1208
1609
|
try expectLog1(&.{ N(ArgType.Activate), 0b1110, N(Activate.Substitute) }, buf[0..3]);
|
|
1209
1610
|
stream.reset();
|
|
1210
1611
|
|
|
1211
|
-
try log.activate(p1.ident(2), .Splash);
|
|
1612
|
+
try log.activate(.{ p1.ident(2), .Splash });
|
|
1212
1613
|
try expectLog1(&.{ N(ArgType.Activate), 0b0010, N(Activate.Splash) }, buf[0..3]);
|
|
1213
1614
|
stream.reset();
|
|
1615
|
+
|
|
1616
|
+
try log.activate(.{ p1.ident(4), .SubstituteBlock, M2.Spite });
|
|
1617
|
+
try expectLog1(&.{
|
|
1618
|
+
N(ArgType.Activate),
|
|
1619
|
+
0b0100,
|
|
1620
|
+
N(Activate.SubstituteBlock),
|
|
1621
|
+
N(M2.Spite),
|
|
1622
|
+
}, buf[0..4]);
|
|
1623
|
+
stream.reset();
|
|
1624
|
+
|
|
1625
|
+
try log.activate(.{ p1.ident(3), .Magnitude, 5 });
|
|
1626
|
+
try expectLog1(&.{ N(ArgType.Activate), 0b0011, N(Activate.Magnitude), 5 }, buf[0..4]);
|
|
1627
|
+
stream.reset();
|
|
1214
1628
|
}
|
|
1215
1629
|
|
|
1216
1630
|
test "|-fieldactivate|" {
|
|
1217
|
-
try log.fieldactivate();
|
|
1631
|
+
try log.fieldactivate(.{});
|
|
1218
1632
|
try expectLog1(&.{N(ArgType.FieldActivate)}, buf[0..1]);
|
|
1219
1633
|
stream.reset();
|
|
1220
1634
|
}
|
|
1221
1635
|
|
|
1222
1636
|
test "|-start|" {
|
|
1223
|
-
try log.start(p2.ident(6), .Bide);
|
|
1637
|
+
try log.start(.{ p2.ident(6), .Bide });
|
|
1224
1638
|
try expectLog1(&.{ N(ArgType.Start), 0b1110, N(Start.Bide) }, buf[0..3]);
|
|
1225
1639
|
stream.reset();
|
|
1226
1640
|
|
|
1227
|
-
try log.start(p1.ident(2), .ConfusionSilent);
|
|
1641
|
+
try log.start(.{ p1.ident(2), .ConfusionSilent });
|
|
1228
1642
|
try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.ConfusionSilent) }, buf[0..3]);
|
|
1229
1643
|
stream.reset();
|
|
1230
1644
|
|
|
1231
|
-
try log.
|
|
1645
|
+
try log.start(.{
|
|
1646
|
+
p2.ident(6),
|
|
1647
|
+
.TypeChange,
|
|
1648
|
+
gen1.Types{ .type1 = .Fire, .type2 = .Fire },
|
|
1649
|
+
p2.ident(5),
|
|
1650
|
+
});
|
|
1232
1651
|
try expectLog1(
|
|
1233
1652
|
&.{ N(ArgType.Start), 0b1110, N(Start.TypeChange), 0b1000_1000, 0b1101 },
|
|
1234
1653
|
buf[0..5],
|
|
1235
1654
|
);
|
|
1236
1655
|
stream.reset();
|
|
1237
1656
|
|
|
1238
|
-
try log.
|
|
1657
|
+
try log.start(.{
|
|
1658
|
+
p1.ident(2),
|
|
1659
|
+
.TypeChange,
|
|
1660
|
+
gen1.Types{ .type1 = .Bug, .type2 = .Poison },
|
|
1661
|
+
p2.ident(4),
|
|
1662
|
+
});
|
|
1239
1663
|
try expectLog1(
|
|
1240
1664
|
&.{ N(ArgType.Start), 0b0010, N(Start.TypeChange), 0b0011_0110, 0b1100 },
|
|
1241
1665
|
buf[0..5],
|
|
1242
1666
|
);
|
|
1243
1667
|
stream.reset();
|
|
1244
1668
|
|
|
1245
|
-
try log.
|
|
1246
|
-
try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.Disable), N(
|
|
1669
|
+
try log.start(.{ p1.ident(2), .Disable, M1.Surf });
|
|
1670
|
+
try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.Disable), N(M1.Surf) }, buf[0..4]);
|
|
1247
1671
|
stream.reset();
|
|
1248
1672
|
|
|
1249
|
-
try log.
|
|
1250
|
-
try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.Mimic), N(
|
|
1673
|
+
try log.start(.{ p1.ident(2), .Mimic, M1.Surf });
|
|
1674
|
+
try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.Mimic), N(M1.Surf) }, buf[0..4]);
|
|
1251
1675
|
stream.reset();
|
|
1252
1676
|
}
|
|
1253
1677
|
|
|
1254
1678
|
test "|-end|" {
|
|
1255
|
-
try log.end(p2.ident(6), .Bide);
|
|
1679
|
+
try log.end(.{ p2.ident(6), .Bide });
|
|
1256
1680
|
try expectLog1(&.{ N(ArgType.End), 0b1110, N(End.Bide) }, buf[0..3]);
|
|
1257
1681
|
stream.reset();
|
|
1258
1682
|
|
|
1259
|
-
try log.end(p1.ident(2), .ConfusionSilent);
|
|
1683
|
+
try log.end(.{ p1.ident(2), .ConfusionSilent });
|
|
1260
1684
|
try expectLog1(&.{ N(ArgType.End), 0b0010, N(End.ConfusionSilent) }, buf[0..3]);
|
|
1261
1685
|
stream.reset();
|
|
1262
1686
|
}
|
|
1263
1687
|
|
|
1264
1688
|
test "|-ohko|" {
|
|
1265
|
-
try log.ohko();
|
|
1689
|
+
try log.ohko(.{});
|
|
1266
1690
|
try expectLog1(&.{N(ArgType.OHKO)}, buf[0..1]);
|
|
1267
1691
|
stream.reset();
|
|
1268
1692
|
}
|
|
1693
|
+
|
|
1269
1694
|
test "|-crit|" {
|
|
1270
|
-
try log.crit(p2.ident(5));
|
|
1695
|
+
try log.crit(.{p2.ident(5)});
|
|
1271
1696
|
try expectLog1(&.{ N(ArgType.Crit), 0b1101 }, buf[0..2]);
|
|
1272
1697
|
stream.reset();
|
|
1273
1698
|
}
|
|
1699
|
+
|
|
1274
1700
|
test "|-supereffective|" {
|
|
1275
|
-
try log.supereffective(p1.ident(1));
|
|
1701
|
+
try log.supereffective(.{p1.ident(1)});
|
|
1276
1702
|
try expectLog1(&.{ N(ArgType.SuperEffective), 0b0001 }, buf[0..2]);
|
|
1277
1703
|
stream.reset();
|
|
1278
1704
|
}
|
|
1705
|
+
|
|
1279
1706
|
test "|-resisted|" {
|
|
1280
|
-
try log.resisted(p2.ident(2));
|
|
1707
|
+
try log.resisted(.{p2.ident(2)});
|
|
1281
1708
|
try expectLog1(&.{ N(ArgType.Resisted), 0b1010 }, buf[0..2]);
|
|
1282
1709
|
stream.reset();
|
|
1283
1710
|
}
|
|
1711
|
+
|
|
1284
1712
|
test "|-immune|" {
|
|
1285
|
-
try log.immune(p1.ident(3), .None);
|
|
1713
|
+
try log.immune(.{ p1.ident(3), .None });
|
|
1286
1714
|
try expectLog1(&.{ N(ArgType.Immune), 0b0011, N(Immune.None) }, buf[0..3]);
|
|
1287
1715
|
stream.reset();
|
|
1288
1716
|
|
|
1289
|
-
try log.immune(p2.ident(2), .OHKO);
|
|
1717
|
+
try log.immune(.{ p2.ident(2), .OHKO });
|
|
1290
1718
|
try expectLog1(&.{ N(ArgType.Immune), 0b1010, N(Immune.OHKO) }, buf[0..3]);
|
|
1291
1719
|
stream.reset();
|
|
1292
1720
|
}
|
|
1721
|
+
|
|
1293
1722
|
test "|-transform|" {
|
|
1294
|
-
try log.transform(p2.ident(4), p1.ident(5));
|
|
1723
|
+
try log.transform(.{ p2.ident(4), p1.ident(5) });
|
|
1295
1724
|
try expectLog1(&.{ N(ArgType.Transform), 0b1100, 0b0101 }, buf[0..3]);
|
|
1296
1725
|
stream.reset();
|
|
1297
1726
|
}
|
|
1727
|
+
|
|
1728
|
+
test "|drag|" {
|
|
1729
|
+
var blissey = gen2.helpers.Pokemon.init(.{ .species = .Blissey, .moves = &.{.Splash} });
|
|
1730
|
+
blissey.level = 91;
|
|
1731
|
+
blissey.hp = 200;
|
|
1732
|
+
blissey.stats.hp = 400;
|
|
1733
|
+
blissey.status = gen2.Status.init(.PAR);
|
|
1734
|
+
try log.drag(.{ p2.ident(3), &blissey });
|
|
1735
|
+
const par = 0b1000000;
|
|
1736
|
+
const expected = &(.{
|
|
1737
|
+
N(ArgType.Drag),
|
|
1738
|
+
0b1011,
|
|
1739
|
+
N(S2.Blissey),
|
|
1740
|
+
N(gen2.Gender.Female),
|
|
1741
|
+
91,
|
|
1742
|
+
} ++ switch (endian) {
|
|
1743
|
+
.Big => .{ 0, 200, 1, 144, par },
|
|
1744
|
+
.Little => .{ 200, 0, 144, 1, par },
|
|
1745
|
+
});
|
|
1746
|
+
try expectLog2(expected, buf[0..10]);
|
|
1747
|
+
stream.reset();
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
test "|-item|" {
|
|
1751
|
+
try log.item(.{ p2.ident(2), I2.GoldBerry, p1.ident(4) });
|
|
1752
|
+
try expectLog2(&.{ N(ArgType.Item), 0b1010, N(I2.GoldBerry), 0b0100 }, buf[0..4]);
|
|
1753
|
+
stream.reset();
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
test "|-enditem|" {
|
|
1757
|
+
try log.enditem(.{ p1.ident(1), I2.BerserkGene, .None });
|
|
1758
|
+
try expectLog2(&.{ N(ArgType.EndItem), 0b0001, N(I2.BerserkGene), N(EndItem.None) }, buf[0..4]);
|
|
1759
|
+
stream.reset();
|
|
1760
|
+
|
|
1761
|
+
try log.enditem(.{ p2.ident(4), I2.PRZCureBerry, .Eat });
|
|
1762
|
+
try expectLog2(&.{ N(ArgType.EndItem), 0b1100, N(I2.PRZCureBerry), N(EndItem.Eat) }, buf[0..4]);
|
|
1763
|
+
stream.reset();
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
test "|-cureteam|" {
|
|
1767
|
+
try log.cureteam(.{p2.ident(5)});
|
|
1768
|
+
try expectLog2(&.{ N(ArgType.CureTeam), 0b1101 }, buf[0..2]);
|
|
1769
|
+
stream.reset();
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
test "|-sethp|" {
|
|
1773
|
+
var blissey = gen2.helpers.Pokemon.init(.{ .species = .Blissey, .moves = &.{.PainSplit} });
|
|
1774
|
+
blissey.hp = 612;
|
|
1775
|
+
try log.sethp(.{ p2.ident(2), &blissey, .Silent });
|
|
1776
|
+
var expected: []const u8 = switch (endian) {
|
|
1777
|
+
.Big => &.{ N(ArgType.SetHP), 0b1010, 2, 100, 2, 201, 0, N(SetHP.Silent) },
|
|
1778
|
+
.Little => &.{ N(ArgType.SetHP), 0b1010, 100, 2, 201, 2, 0, N(SetHP.Silent) },
|
|
1779
|
+
};
|
|
1780
|
+
try expectLog2(expected, buf[0..8]);
|
|
1781
|
+
stream.reset();
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
test "|-setboost|" {
|
|
1785
|
+
try log.setboost(.{ p2.ident(6), 6 });
|
|
1786
|
+
try expectLog2(&.{ N(ArgType.SetBoost), 0b1110, 12 }, buf[0..3]);
|
|
1787
|
+
stream.reset();
|
|
1788
|
+
|
|
1789
|
+
try log.setboost(.{ p2.ident(3), 2 });
|
|
1790
|
+
try expectLog2(&.{ N(ArgType.SetBoost), 0b1011, 8 }, buf[0..3]);
|
|
1791
|
+
stream.reset();
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
test "|-copyboost|" {
|
|
1795
|
+
try log.copyboost(.{ p2.ident(3), p1.ident(6) });
|
|
1796
|
+
try expectLog2(&.{ N(ArgType.CopyBoost), 0b1011, 0b0110 }, buf[0..3]);
|
|
1797
|
+
stream.reset();
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
test "|-sidestart|" {
|
|
1801
|
+
try log.sidestart(.{ .P2, .Reflect });
|
|
1802
|
+
try expectLog2(&.{ N(ArgType.SideStart), 1, N(Side.Reflect) }, buf[0..3]);
|
|
1803
|
+
stream.reset();
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
test "|-sideend|" {
|
|
1807
|
+
try log.sideend(.{ .P2, .LightScreen });
|
|
1808
|
+
try expectLog2(&.{ N(ArgType.SideEnd), 1, N(Side.LightScreen) }, buf[0..3]);
|
|
1809
|
+
stream.reset();
|
|
1810
|
+
|
|
1811
|
+
try log.sideend(.{ .P1, .Spikes, p1.ident(3) });
|
|
1812
|
+
try expectLog2(&.{
|
|
1813
|
+
N(ArgType.SideEnd),
|
|
1814
|
+
0,
|
|
1815
|
+
N(Side.Spikes),
|
|
1816
|
+
0b0011,
|
|
1817
|
+
}, buf[0..4]);
|
|
1818
|
+
stream.reset();
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
test "|-singlemove|" {
|
|
1822
|
+
try log.singlemove(.{ p2.ident(2), M2.DestinyBond });
|
|
1823
|
+
try expectLog2(&.{ N(ArgType.SingleMove), 0b1010, N(M2.DestinyBond) }, buf[0..3]);
|
|
1824
|
+
stream.reset();
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
test "|-singleturn|" {
|
|
1828
|
+
try log.singleturn(.{ p1.ident(3), M2.Protect });
|
|
1829
|
+
try expectLog2(&.{ N(ArgType.SingleTurn), 0b0011, N(M2.Protect) }, buf[0..3]);
|
|
1830
|
+
stream.reset();
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
test "|-weather|" {
|
|
1834
|
+
try log.weather(.{ W2.Rain, .Upkeep });
|
|
1835
|
+
try expectLog2(&.{ N(ArgType.Weather), N(W2.Rain), N(Weather.Upkeep) }, buf[0..3]);
|
|
1836
|
+
stream.reset();
|
|
1837
|
+
|
|
1838
|
+
try log.weather(.{ W2.None, .None });
|
|
1839
|
+
try expectLog2(&.{ N(ArgType.Weather), N(W2.None), N(Weather.None) }, buf[0..3]);
|
|
1840
|
+
stream.reset();
|
|
1841
|
+
}
|