@pkmn/engine 0.1.0-dev.e5b5a998 → 0.1.0-dev.f3aaee39
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 +53 -42
- package/build/pkg/addon.js +3 -2
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/layout.json +24 -2
- package/build/pkg/gen1.js +13 -16
- package/build/pkg/gen1.js.map +1 -1
- package/build.zig +79 -54
- package/package.json +23 -14
- package/src/bin/install-pkmn-engine +10 -5
- package/src/lib/binding/node.zig +45 -140
- package/src/lib/binding/wasm.zig +4 -2
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +11 -11
- package/src/lib/common/debug.zig +20 -11
- package/src/lib/common/js.zig +118 -0
- package/src/lib/common/optional.zig +60 -0
- package/src/lib/common/options.zig +9 -0
- package/src/lib/common/protocol.zig +133 -76
- package/src/lib/common/rational.zig +353 -0
- package/src/lib/common/rng.zig +10 -10
- package/src/lib/common/util.zig +12 -0
- package/src/lib/gen1/README.md +254 -176
- package/src/lib/gen1/calc.zig +427 -0
- package/src/lib/gen1/chance.zig +1044 -0
- package/src/lib/gen1/data/types.zig +1 -1
- package/src/lib/gen1/data.zig +51 -29
- package/src/lib/gen1/helpers.zig +588 -17
- package/src/lib/gen1/mechanics.zig +751 -473
- package/src/lib/gen2/README.md +12 -13
- package/src/lib/gen2/data/items.zig +1 -1
- package/src/lib/gen2/data.zig +27 -16
- package/src/lib/gen2/helpers.zig +8 -10
- package/src/lib/gen2/mechanics.zig +5 -4
- package/src/lib/pkmn.zig +61 -2
|
@@ -102,6 +102,9 @@ pub const ArgType = enum(u8) {
|
|
|
102
102
|
// Gen 8
|
|
103
103
|
CanDynamax,
|
|
104
104
|
SwapSideConditions,
|
|
105
|
+
|
|
106
|
+
// Gen 9
|
|
107
|
+
Terastallize,
|
|
105
108
|
};
|
|
106
109
|
|
|
107
110
|
pub const Move = enum(u8) {
|
|
@@ -219,8 +222,12 @@ pub const Immune = enum(u8) {
|
|
|
219
222
|
OHKO,
|
|
220
223
|
};
|
|
221
224
|
|
|
225
|
+
/// Null object pattern implementation of `Log` backed by a `std.io.null_writer`.
|
|
226
|
+
/// Ignores anything sent to it, though protocol logging should additionally be turned off
|
|
227
|
+
/// entirely with `options.log`.
|
|
222
228
|
pub const NULL = Log(@TypeOf(std.io.null_writer)){ .writer = std.io.null_writer };
|
|
223
229
|
|
|
230
|
+
/// Logs protocol information to its `Writer` during a battle update when `options.log` is enabled.
|
|
224
231
|
pub fn Log(comptime Writer: type) type {
|
|
225
232
|
return struct {
|
|
226
233
|
const Self = @This();
|
|
@@ -231,12 +238,13 @@ pub fn Log(comptime Writer: type) type {
|
|
|
231
238
|
|
|
232
239
|
pub fn move(self: Self, source: ID, m: anytype, target: ID, from: anytype) Error!void {
|
|
233
240
|
if (!enabled) return;
|
|
241
|
+
|
|
234
242
|
assert(m != .None);
|
|
235
243
|
try self.writer.writeAll(&.{
|
|
236
244
|
@intFromEnum(ArgType.Move),
|
|
237
|
-
@
|
|
245
|
+
@as(u8, @bitCast(source)),
|
|
238
246
|
@intFromEnum(m),
|
|
239
|
-
@
|
|
247
|
+
@as(u8, @bitCast(target)),
|
|
240
248
|
});
|
|
241
249
|
const none = &[_]u8{@intFromEnum(Move.None)};
|
|
242
250
|
try self.writer.writeAll(switch (@typeInfo(@TypeOf(from))) {
|
|
@@ -254,7 +262,8 @@ pub fn Log(comptime Writer: type) type {
|
|
|
254
262
|
|
|
255
263
|
pub fn switched(self: Self, ident: ID, pokemon: anytype) Error!void {
|
|
256
264
|
if (!enabled) return;
|
|
257
|
-
|
|
265
|
+
|
|
266
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Switch), @as(u8, @bitCast(ident)) });
|
|
258
267
|
try self.writer.writeAll(&.{ @intFromEnum(pokemon.species), pokemon.level });
|
|
259
268
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
260
269
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
@@ -263,19 +272,21 @@ pub fn Log(comptime Writer: type) type {
|
|
|
263
272
|
|
|
264
273
|
pub fn cant(self: Self, ident: ID, reason: Cant) Error!void {
|
|
265
274
|
if (!enabled) return;
|
|
275
|
+
|
|
266
276
|
assert(reason != .Disable);
|
|
267
277
|
try self.writer.writeAll(&.{
|
|
268
278
|
@intFromEnum(ArgType.Cant),
|
|
269
|
-
@
|
|
279
|
+
@as(u8, @bitCast(ident)),
|
|
270
280
|
@intFromEnum(reason),
|
|
271
281
|
});
|
|
272
282
|
}
|
|
273
283
|
|
|
274
284
|
pub fn disabled(self: Self, ident: ID, m: anytype) Error!void {
|
|
275
285
|
if (!enabled) return;
|
|
286
|
+
|
|
276
287
|
try self.writer.writeAll(&.{
|
|
277
288
|
@intFromEnum(ArgType.Cant),
|
|
278
|
-
@
|
|
289
|
+
@as(u8, @bitCast(ident)),
|
|
279
290
|
@intFromEnum(Cant.Disable),
|
|
280
291
|
@intFromEnum(m),
|
|
281
292
|
});
|
|
@@ -283,12 +294,14 @@ pub fn Log(comptime Writer: type) type {
|
|
|
283
294
|
|
|
284
295
|
pub fn faint(self: Self, ident: ID, done: bool) Error!void {
|
|
285
296
|
if (!enabled) return;
|
|
286
|
-
|
|
297
|
+
|
|
298
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Faint), @as(u8, @bitCast(ident)) });
|
|
287
299
|
if (done) try self.writer.writeByte(@intFromEnum(ArgType.None));
|
|
288
300
|
}
|
|
289
301
|
|
|
290
302
|
pub fn turn(self: Self, num: u16) Error!void {
|
|
291
303
|
if (!enabled) return;
|
|
304
|
+
|
|
292
305
|
try self.writer.writeByte(@intFromEnum(ArgType.Turn));
|
|
293
306
|
try self.writer.writeIntNative(u16, num);
|
|
294
307
|
try self.writer.writeByte(@intFromEnum(ArgType.None));
|
|
@@ -296,6 +309,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
296
309
|
|
|
297
310
|
pub fn win(self: Self, player: Player) Error!void {
|
|
298
311
|
if (!enabled) return;
|
|
312
|
+
|
|
299
313
|
try self.writer.writeAll(&.{
|
|
300
314
|
@intFromEnum(ArgType.Win),
|
|
301
315
|
@intFromEnum(player),
|
|
@@ -305,13 +319,15 @@ pub fn Log(comptime Writer: type) type {
|
|
|
305
319
|
|
|
306
320
|
pub fn tie(self: Self) Error!void {
|
|
307
321
|
if (!enabled) return;
|
|
322
|
+
|
|
308
323
|
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Tie), @intFromEnum(ArgType.None) });
|
|
309
324
|
}
|
|
310
325
|
|
|
311
326
|
pub fn damage(self: Self, ident: ID, pokemon: anytype, reason: Damage) Error!void {
|
|
312
327
|
if (!enabled) return;
|
|
328
|
+
|
|
313
329
|
assert(@intFromEnum(reason) <= @intFromEnum(Damage.LeechSeed));
|
|
314
|
-
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @
|
|
330
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @as(u8, @bitCast(ident)) });
|
|
315
331
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
316
332
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
317
333
|
try self.writer.writeAll(&.{ pokemon.status, @intFromEnum(reason) });
|
|
@@ -325,21 +341,23 @@ pub fn Log(comptime Writer: type) type {
|
|
|
325
341
|
source: ID,
|
|
326
342
|
) Error!void {
|
|
327
343
|
if (!enabled) return;
|
|
344
|
+
|
|
328
345
|
assert(@intFromEnum(reason) == @intFromEnum(Damage.RecoilOf));
|
|
329
|
-
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @
|
|
346
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @as(u8, @bitCast(ident)) });
|
|
330
347
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
331
348
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
332
349
|
try self.writer.writeAll(&.{
|
|
333
350
|
pokemon.status,
|
|
334
351
|
@intFromEnum(reason),
|
|
335
|
-
@
|
|
352
|
+
@as(u8, @bitCast(source)),
|
|
336
353
|
});
|
|
337
354
|
}
|
|
338
355
|
|
|
339
356
|
pub fn heal(self: Self, ident: ID, pokemon: anytype, reason: Heal) Error!void {
|
|
340
357
|
if (!enabled) return;
|
|
358
|
+
|
|
341
359
|
assert(reason != .Drain);
|
|
342
|
-
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @
|
|
360
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(ident)) });
|
|
343
361
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
344
362
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
345
363
|
try self.writer.writeAll(&.{ pokemon.status, @intFromEnum(reason) });
|
|
@@ -347,22 +365,24 @@ pub fn Log(comptime Writer: type) type {
|
|
|
347
365
|
|
|
348
366
|
pub fn drain(self: Self, source: ID, pokemon: anytype, target: ID) Error!void {
|
|
349
367
|
if (!enabled) return;
|
|
350
|
-
|
|
368
|
+
|
|
369
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(source)) });
|
|
351
370
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
352
371
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
353
372
|
try self.writer.writeAll(&.{
|
|
354
373
|
pokemon.status,
|
|
355
374
|
@intFromEnum(Heal.Drain),
|
|
356
|
-
@
|
|
375
|
+
@as(u8, @bitCast(target)),
|
|
357
376
|
});
|
|
358
377
|
}
|
|
359
378
|
|
|
360
379
|
pub fn status(self: Self, ident: ID, value: u8, reason: Status) Error!void {
|
|
361
380
|
if (!enabled) return;
|
|
381
|
+
|
|
362
382
|
assert(reason != .From);
|
|
363
383
|
try self.writer.writeAll(&.{
|
|
364
384
|
@intFromEnum(ArgType.Status),
|
|
365
|
-
@
|
|
385
|
+
@as(u8, @bitCast(ident)),
|
|
366
386
|
value,
|
|
367
387
|
@intFromEnum(reason),
|
|
368
388
|
});
|
|
@@ -370,9 +390,10 @@ pub fn Log(comptime Writer: type) type {
|
|
|
370
390
|
|
|
371
391
|
pub fn statusFrom(self: Self, ident: ID, value: u8, m: anytype) Error!void {
|
|
372
392
|
if (!enabled) return;
|
|
393
|
+
|
|
373
394
|
try self.writer.writeAll(&.{
|
|
374
395
|
@intFromEnum(ArgType.Status),
|
|
375
|
-
@
|
|
396
|
+
@as(u8, @bitCast(ident)),
|
|
376
397
|
value,
|
|
377
398
|
@intFromEnum(Status.From),
|
|
378
399
|
@intFromEnum(m),
|
|
@@ -381,9 +402,10 @@ pub fn Log(comptime Writer: type) type {
|
|
|
381
402
|
|
|
382
403
|
pub fn curestatus(self: Self, ident: ID, value: u8, reason: CureStatus) Error!void {
|
|
383
404
|
if (!enabled) return;
|
|
405
|
+
|
|
384
406
|
try self.writer.writeAll(&.{
|
|
385
407
|
@intFromEnum(ArgType.CureStatus),
|
|
386
|
-
@
|
|
408
|
+
@as(u8, @bitCast(ident)),
|
|
387
409
|
value,
|
|
388
410
|
@intFromEnum(reason),
|
|
389
411
|
});
|
|
@@ -391,98 +413,113 @@ pub fn Log(comptime Writer: type) type {
|
|
|
391
413
|
|
|
392
414
|
pub fn boost(self: Self, ident: ID, reason: Boost, num: i8) Error!void {
|
|
393
415
|
if (!enabled) return;
|
|
416
|
+
|
|
394
417
|
assert(num != 0 and (reason != .Rage or num > 0));
|
|
395
418
|
try self.writer.writeAll(&.{
|
|
396
419
|
@intFromEnum(ArgType.Boost),
|
|
397
|
-
@
|
|
420
|
+
@as(u8, @bitCast(ident)),
|
|
398
421
|
@intFromEnum(reason),
|
|
399
|
-
@
|
|
422
|
+
@as(u8, @intCast(num + 6)),
|
|
400
423
|
});
|
|
401
424
|
}
|
|
402
425
|
|
|
403
426
|
pub fn clearallboost(self: Self) Error!void {
|
|
404
427
|
if (!enabled) return;
|
|
428
|
+
|
|
405
429
|
try self.writer.writeAll(&.{@intFromEnum(ArgType.ClearAllBoost)});
|
|
406
430
|
}
|
|
407
431
|
|
|
408
432
|
pub fn fail(self: Self, ident: ID, reason: Fail) Error!void {
|
|
409
433
|
if (!enabled) return;
|
|
434
|
+
|
|
410
435
|
try self.writer.writeAll(&.{
|
|
411
436
|
@intFromEnum(ArgType.Fail),
|
|
412
|
-
@
|
|
437
|
+
@as(u8, @bitCast(ident)),
|
|
413
438
|
@intFromEnum(reason),
|
|
414
439
|
});
|
|
415
440
|
}
|
|
416
441
|
|
|
417
442
|
pub fn miss(self: Self, source: ID) Error!void {
|
|
418
443
|
if (!enabled) return;
|
|
419
|
-
|
|
444
|
+
|
|
445
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Miss), @as(u8, @bitCast(source)) });
|
|
420
446
|
}
|
|
421
447
|
|
|
422
448
|
pub fn hitcount(self: Self, ident: ID, num: u8) Error!void {
|
|
423
449
|
if (!enabled) return;
|
|
450
|
+
|
|
424
451
|
try self.writer.writeAll(&.{
|
|
425
452
|
@intFromEnum(ArgType.HitCount),
|
|
426
|
-
@
|
|
453
|
+
@as(u8, @bitCast(ident)),
|
|
427
454
|
num,
|
|
428
455
|
});
|
|
429
456
|
}
|
|
430
457
|
|
|
431
458
|
pub fn prepare(self: Self, source: ID, m: anytype) Error!void {
|
|
432
459
|
if (!enabled) return;
|
|
460
|
+
|
|
433
461
|
try self.writer.writeAll(&.{
|
|
434
462
|
@intFromEnum(ArgType.Prepare),
|
|
435
|
-
@
|
|
463
|
+
@as(u8, @bitCast(source)),
|
|
436
464
|
@intFromEnum(m),
|
|
437
465
|
});
|
|
438
466
|
}
|
|
439
467
|
|
|
440
468
|
pub fn mustrecharge(self: Self, ident: ID) Error!void {
|
|
441
469
|
if (!enabled) return;
|
|
442
|
-
|
|
470
|
+
|
|
471
|
+
try self.writer.writeAll(&.{
|
|
472
|
+
@intFromEnum(ArgType.MustRecharge),
|
|
473
|
+
@as(u8, @bitCast(ident)),
|
|
474
|
+
});
|
|
443
475
|
}
|
|
444
476
|
|
|
445
477
|
pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
|
|
446
478
|
if (!enabled) return;
|
|
479
|
+
|
|
447
480
|
try self.writer.writeAll(&.{
|
|
448
481
|
@intFromEnum(ArgType.Activate),
|
|
449
|
-
@
|
|
482
|
+
@as(u8, @bitCast(ident)),
|
|
450
483
|
@intFromEnum(reason),
|
|
451
484
|
});
|
|
452
485
|
}
|
|
453
486
|
|
|
454
487
|
pub fn fieldactivate(self: Self) Error!void {
|
|
455
488
|
if (!enabled) return;
|
|
489
|
+
|
|
456
490
|
try self.writer.writeAll(&.{@intFromEnum(ArgType.FieldActivate)});
|
|
457
491
|
}
|
|
458
492
|
|
|
459
493
|
pub fn start(self: Self, ident: ID, reason: Start) Error!void {
|
|
460
494
|
if (!enabled) return;
|
|
495
|
+
|
|
461
496
|
assert(@intFromEnum(reason) < @intFromEnum(Start.TypeChange));
|
|
462
497
|
try self.writer.writeAll(&.{
|
|
463
498
|
@intFromEnum(ArgType.Start),
|
|
464
|
-
@
|
|
499
|
+
@as(u8, @bitCast(ident)),
|
|
465
500
|
@intFromEnum(reason),
|
|
466
501
|
});
|
|
467
502
|
}
|
|
468
503
|
|
|
469
504
|
pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
|
|
470
505
|
if (!enabled) return;
|
|
506
|
+
|
|
471
507
|
try self.writer.writeAll(&.{
|
|
472
508
|
@intFromEnum(ArgType.Start),
|
|
473
|
-
@
|
|
509
|
+
@as(u8, @bitCast(source)),
|
|
474
510
|
@intFromEnum(Start.TypeChange),
|
|
475
|
-
@
|
|
476
|
-
@
|
|
511
|
+
@as(u8, @bitCast(types)),
|
|
512
|
+
@as(u8, @bitCast(target)),
|
|
477
513
|
});
|
|
478
514
|
}
|
|
479
515
|
|
|
480
516
|
pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
|
|
481
517
|
if (!enabled) return;
|
|
518
|
+
|
|
482
519
|
assert(@intFromEnum(reason) > @intFromEnum(Start.TypeChange));
|
|
483
520
|
try self.writer.writeAll(&.{
|
|
484
521
|
@intFromEnum(ArgType.Start),
|
|
485
|
-
@
|
|
522
|
+
@as(u8, @bitCast(ident)),
|
|
486
523
|
@intFromEnum(reason),
|
|
487
524
|
@intFromEnum(m),
|
|
488
525
|
});
|
|
@@ -490,68 +527,84 @@ pub fn Log(comptime Writer: type) type {
|
|
|
490
527
|
|
|
491
528
|
pub fn end(self: Self, ident: ID, reason: End) Error!void {
|
|
492
529
|
if (!enabled) return;
|
|
530
|
+
|
|
493
531
|
try self.writer.writeAll(&.{
|
|
494
532
|
@intFromEnum(ArgType.End),
|
|
495
|
-
@
|
|
533
|
+
@as(u8, @bitCast(ident)),
|
|
496
534
|
@intFromEnum(reason),
|
|
497
535
|
});
|
|
498
536
|
}
|
|
499
537
|
|
|
500
538
|
pub fn ohko(self: Self) Error!void {
|
|
501
539
|
if (!enabled) return;
|
|
540
|
+
|
|
502
541
|
try self.writer.writeAll(&.{@intFromEnum(ArgType.OHKO)});
|
|
503
542
|
}
|
|
504
543
|
|
|
505
544
|
pub fn crit(self: Self, ident: ID) Error!void {
|
|
506
545
|
if (!enabled) return;
|
|
507
|
-
|
|
546
|
+
|
|
547
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Crit), @as(u8, @bitCast(ident)) });
|
|
508
548
|
}
|
|
509
549
|
|
|
510
550
|
pub fn supereffective(self: Self, ident: ID) Error!void {
|
|
511
551
|
if (!enabled) return;
|
|
552
|
+
|
|
512
553
|
try self.writer.writeAll(&.{
|
|
513
554
|
@intFromEnum(ArgType.SuperEffective),
|
|
514
|
-
@
|
|
555
|
+
@as(u8, @bitCast(ident)),
|
|
515
556
|
});
|
|
516
557
|
}
|
|
517
558
|
|
|
518
559
|
pub fn resisted(self: Self, ident: ID) Error!void {
|
|
519
560
|
if (!enabled) return;
|
|
520
|
-
|
|
561
|
+
|
|
562
|
+
try self.writer.writeAll(&.{
|
|
563
|
+
@intFromEnum(ArgType.Resisted),
|
|
564
|
+
@as(u8, @bitCast(ident)),
|
|
565
|
+
});
|
|
521
566
|
}
|
|
522
567
|
|
|
523
568
|
pub fn immune(self: Self, ident: ID, reason: Immune) Error!void {
|
|
524
569
|
if (!enabled) return;
|
|
570
|
+
|
|
525
571
|
try self.writer.writeAll(&.{
|
|
526
572
|
@intFromEnum(ArgType.Immune),
|
|
527
|
-
@
|
|
573
|
+
@as(u8, @bitCast(ident)),
|
|
528
574
|
@intFromEnum(reason),
|
|
529
575
|
});
|
|
530
576
|
}
|
|
531
577
|
|
|
532
578
|
pub fn transform(self: Self, source: ID, target: ID) Error!void {
|
|
533
579
|
if (!enabled) return;
|
|
580
|
+
|
|
534
581
|
try self.writer.writeAll(&.{
|
|
535
582
|
@intFromEnum(ArgType.Transform),
|
|
536
|
-
@
|
|
537
|
-
@
|
|
583
|
+
@as(u8, @bitCast(source)),
|
|
584
|
+
@as(u8, @bitCast(target)),
|
|
538
585
|
});
|
|
539
586
|
}
|
|
540
587
|
|
|
541
588
|
pub fn laststill(self: Self) Error!void {
|
|
542
589
|
if (!enabled) return;
|
|
590
|
+
|
|
543
591
|
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastStill)});
|
|
544
592
|
}
|
|
545
593
|
|
|
546
594
|
pub fn lastmiss(self: Self) Error!void {
|
|
547
595
|
if (!enabled) return;
|
|
596
|
+
|
|
548
597
|
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastMiss)});
|
|
549
598
|
}
|
|
550
599
|
};
|
|
551
600
|
}
|
|
552
601
|
|
|
602
|
+
/// `Log` type backed by the optimized `ByteStream.Writer`.
|
|
553
603
|
pub const FixedLog = Log(ByteStream.Writer);
|
|
554
604
|
|
|
605
|
+
/// Stripped down version of `std.io.FixedBufferStream` optimized for efficiently writing the
|
|
606
|
+
/// individual protocol bytes. Note that the `ByteStream.Writer` is **not** a `std.io.Writer` and
|
|
607
|
+
/// should not be used for general purpose writing.
|
|
555
608
|
pub const ByteStream = struct {
|
|
556
609
|
buffer: []u8,
|
|
557
610
|
pos: usize = 0,
|
|
@@ -600,7 +653,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
600
653
|
|
|
601
654
|
var i: usize = 0;
|
|
602
655
|
while (i < a.len) {
|
|
603
|
-
const arg = @enumFromInt(
|
|
656
|
+
const arg: ArgType = @enumFromInt(a[i]);
|
|
604
657
|
const name = switch (arg) {
|
|
605
658
|
.None => if (color) "\x1b[2m-\x1b[0m" else "-",
|
|
606
659
|
.LastStill => "|[still]",
|
|
@@ -646,17 +699,17 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
646
699
|
.OHKO,
|
|
647
700
|
=> {},
|
|
648
701
|
.Move => {
|
|
649
|
-
const source = ID.from(@intCast(
|
|
702
|
+
const source = ID.from(@intCast(a[i]));
|
|
650
703
|
printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
|
|
651
704
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
652
|
-
const target = ID.from(@intCast(
|
|
705
|
+
const target = ID.from(@intCast(a[i]));
|
|
653
706
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
654
|
-
const reason = @enumFromInt(
|
|
707
|
+
const reason: Move = @enumFromInt(a[i]);
|
|
655
708
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
656
709
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
657
710
|
},
|
|
658
711
|
.Switch => {
|
|
659
|
-
const id = ID.from(@intCast(
|
|
712
|
+
const id = ID.from(@intCast(a[i]));
|
|
660
713
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
661
714
|
printc(" {s}", .{formatter(.Species, a[i])}, a, b, &i, 1, color);
|
|
662
715
|
printc(" L{d}", .{a[i]}, a, b, &i, 1, color);
|
|
@@ -677,9 +730,9 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
677
730
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
678
731
|
},
|
|
679
732
|
.Cant => {
|
|
680
|
-
const id = ID.from(@intCast(
|
|
733
|
+
const id = ID.from(@intCast(a[i]));
|
|
681
734
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
682
|
-
const reason = @enumFromInt(
|
|
735
|
+
const reason: Cant = @enumFromInt(a[i]);
|
|
683
736
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
684
737
|
if (reason == .Disable) {
|
|
685
738
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
@@ -692,7 +745,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
692
745
|
.SuperEffective,
|
|
693
746
|
.Resisted,
|
|
694
747
|
=> {
|
|
695
|
-
const id = ID.from(@intCast(
|
|
748
|
+
const id = ID.from(@intCast(a[i]));
|
|
696
749
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
697
750
|
},
|
|
698
751
|
.Turn => {
|
|
@@ -702,9 +755,11 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
702
755
|
};
|
|
703
756
|
printc(" {d}", .{turn}, a, b, &i, 2, color);
|
|
704
757
|
},
|
|
705
|
-
.Win =>
|
|
758
|
+
.Win => {
|
|
759
|
+
printc(" {s}", .{@tagName(@as(Player, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
760
|
+
},
|
|
706
761
|
.Damage, .Heal => {
|
|
707
|
-
var id = ID.from(@intCast(
|
|
762
|
+
var id = ID.from(@intCast(a[i]));
|
|
708
763
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
709
764
|
switch (endian) {
|
|
710
765
|
.Big => {
|
|
@@ -722,68 +777,69 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
722
777
|
}
|
|
723
778
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
724
779
|
if (arg == .Damage) {
|
|
725
|
-
const reason = a[i];
|
|
726
|
-
printc(" {s}", .{@tagName(
|
|
727
|
-
if (reason ==
|
|
728
|
-
id = ID.from(@intCast(
|
|
780
|
+
const reason: Damage = @enumFromInt(a[i]);
|
|
781
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
782
|
+
if (reason == .RecoilOf) {
|
|
783
|
+
id = ID.from(@intCast(a[i]));
|
|
729
784
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
730
785
|
}
|
|
731
786
|
} else {
|
|
732
|
-
const reason = @enumFromInt(
|
|
787
|
+
const reason: Heal = @enumFromInt(a[i]);
|
|
733
788
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
734
789
|
if (reason == .Drain) {
|
|
735
|
-
id = ID.from(@intCast(
|
|
790
|
+
id = ID.from(@intCast(a[i]));
|
|
736
791
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
737
792
|
}
|
|
738
793
|
}
|
|
739
794
|
},
|
|
740
795
|
.Status => {
|
|
741
|
-
const id = ID.from(@intCast(
|
|
796
|
+
const id = ID.from(@intCast(a[i]));
|
|
742
797
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
743
798
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
744
|
-
const reason = @enumFromInt(
|
|
799
|
+
const reason: Status = @enumFromInt(a[i]);
|
|
745
800
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
746
801
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
747
802
|
},
|
|
748
803
|
.CureStatus => {
|
|
749
|
-
const id = ID.from(@intCast(
|
|
804
|
+
const id = ID.from(@intCast(a[i]));
|
|
750
805
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
751
806
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
752
|
-
|
|
807
|
+
const reason: CureStatus = @enumFromInt(a[i]);
|
|
808
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
753
809
|
},
|
|
754
810
|
.Boost => {
|
|
755
|
-
const id = ID.from(@intCast(
|
|
811
|
+
const id = ID.from(@intCast(a[i]));
|
|
756
812
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
757
|
-
printc(" {s}", .{@tagName(@
|
|
813
|
+
printc(" {s}", .{@tagName(@as(Boost, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
758
814
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
759
815
|
},
|
|
760
816
|
.Fail => {
|
|
761
|
-
const id = ID.from(@intCast(
|
|
817
|
+
const id = ID.from(@intCast(a[i]));
|
|
762
818
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
763
|
-
printc(" {s}", .{@tagName(@
|
|
819
|
+
printc(" {s}", .{@tagName(@as(Fail, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
764
820
|
},
|
|
765
821
|
.HitCount => {
|
|
766
|
-
const id = ID.from(@intCast(
|
|
822
|
+
const id = ID.from(@intCast(a[i]));
|
|
767
823
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
768
824
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
769
825
|
},
|
|
770
826
|
.Prepare => {
|
|
771
|
-
const id = ID.from(@intCast(
|
|
827
|
+
const id = ID.from(@intCast(a[i]));
|
|
772
828
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
773
829
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
774
830
|
},
|
|
775
831
|
.Activate => {
|
|
776
|
-
const id = ID.from(@intCast(
|
|
832
|
+
const id = ID.from(@intCast(a[i]));
|
|
777
833
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
778
|
-
printc(" {s}", .{@tagName(@
|
|
834
|
+
printc(" {s}", .{@tagName(@as(Activate, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
779
835
|
},
|
|
780
836
|
.Start => {
|
|
781
|
-
const id = ID.from(@intCast(
|
|
837
|
+
const id = ID.from(@intCast(a[i]));
|
|
782
838
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
783
839
|
const reason = a[i];
|
|
784
|
-
printc(" {s}", .{@tagName(@
|
|
785
|
-
if (@
|
|
786
|
-
const types = @
|
|
840
|
+
printc(" {s}", .{@tagName(@as(Start, @enumFromInt(reason)))}, a, b, &i, 1, color);
|
|
841
|
+
if (@as(Start, @enumFromInt(reason)) == .TypeChange) {
|
|
842
|
+
const types = @as(gen1.Types, @bitCast(a[i]));
|
|
787
843
|
const args = .{
|
|
788
844
|
formatter(.Type, @intFromEnum(types.type1)),
|
|
789
845
|
formatter(.Type, @intFromEnum(types.type2)),
|
|
@@ -794,19 +850,19 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
794
850
|
}
|
|
795
851
|
},
|
|
796
852
|
.End => {
|
|
797
|
-
const id = ID.from(@intCast(
|
|
853
|
+
const id = ID.from(@intCast(a[i]));
|
|
798
854
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
799
|
-
printc(" {s}", .{@tagName(@
|
|
855
|
+
printc(" {s}", .{@tagName(@as(End, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
800
856
|
},
|
|
801
857
|
.Immune => {
|
|
802
|
-
const id = ID.from(@intCast(
|
|
858
|
+
const id = ID.from(@intCast(a[i]));
|
|
803
859
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
804
|
-
printc(" {s}", .{@tagName(@
|
|
860
|
+
printc(" {s}", .{@tagName(@as(Immune, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
805
861
|
},
|
|
806
862
|
.Transform => {
|
|
807
|
-
const source = ID.from(@intCast(
|
|
863
|
+
const source = ID.from(@intCast(a[i]));
|
|
808
864
|
printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
|
|
809
|
-
const target = ID.from(@intCast(
|
|
865
|
+
const target = ID.from(@intCast(a[i]));
|
|
810
866
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
811
867
|
},
|
|
812
868
|
else => unreachable,
|
|
@@ -846,6 +902,7 @@ pub fn expectLog(
|
|
|
846
902
|
offset: usize,
|
|
847
903
|
) !void {
|
|
848
904
|
if (!enabled) return;
|
|
905
|
+
|
|
849
906
|
const color = color: {
|
|
850
907
|
if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
|
|
851
908
|
break :color true;
|
|
@@ -912,9 +969,9 @@ fn expectLog1(expected: []const u8, actual: []const u8) !void {
|
|
|
912
969
|
|
|
913
970
|
fn gen1Formatter(kind: Kind, byte: u8) []const u8 {
|
|
914
971
|
return switch (kind) {
|
|
915
|
-
.Move => @tagName(@
|
|
916
|
-
.Species => @tagName(@
|
|
917
|
-
.Type => @tagName(@
|
|
972
|
+
.Move => @tagName(@as(M, @enumFromInt(byte))),
|
|
973
|
+
.Species => @tagName(@as(S, @enumFromInt(byte))),
|
|
974
|
+
.Type => @tagName(@as(gen1.Type, @enumFromInt(byte))),
|
|
918
975
|
.Status => gen1.Status.name(byte),
|
|
919
976
|
};
|
|
920
977
|
}
|