@pkmn/engine 0.1.0-dev.30c63015 → 0.1.0-dev.32adfe77

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.
@@ -1,8 +1,10 @@
1
1
  const std = @import("std");
2
2
  const builtin = @import("builtin");
3
3
 
4
- const data = @import("./data.zig");
5
- const options = @import("./options.zig");
4
+ const pkmn = @import("../pkmn.zig");
5
+
6
+ const data = @import("data.zig");
7
+ const options = @import("options.zig");
6
8
 
7
9
  const assert = std.debug.assert;
8
10
  const print = std.debug.print;
@@ -12,6 +14,8 @@ const enabled = options.log;
12
14
  const Player = data.Player;
13
15
  const ID = data.ID;
14
16
 
17
+ const endian = builtin.cpu.arch.endian();
18
+
15
19
  pub const ArgType = enum(u8) {
16
20
  None,
17
21
 
@@ -69,7 +73,7 @@ pub const ArgType = enum(u8) {
69
73
  EndAbility,
70
74
  ClearNegativeBoost,
71
75
  FormeChange,
72
- NoTarget,
76
+ LastNoTarget, // FIXME
73
77
 
74
78
  // Gen 4
75
79
  SwapBoost,
@@ -102,6 +106,7 @@ pub const ArgType = enum(u8) {
102
106
  // Gen 8
103
107
  CanDynamax,
104
108
  SwapSideConditions,
109
+ UpdatePoke,
105
110
 
106
111
  // Gen 9
107
112
  Terastallize,
@@ -320,7 +325,7 @@ pub fn Log(comptime Writer: type) type {
320
325
 
321
326
  pub const Error = Writer.Error;
322
327
 
323
- // source: ID, m: anytype, target: ID, from?: anytype
328
+ // source: ID, move: <Move>, target: ID, from?: <Move>
324
329
  pub fn move(self: Self, args: anytype) Error!void {
325
330
  if (!enabled) return;
326
331
 
@@ -337,12 +342,12 @@ pub fn Log(comptime Writer: type) type {
337
342
  &.{ @intFromEnum(Move.From), @intFromEnum(args[3]) });
338
343
  }
339
344
 
340
- // ident: ID, pokemon: anytype
345
+ // ident: ID, pokemon: <Pokemon>
341
346
  pub fn switched(self: Self, args: anytype) Error!void {
342
347
  return switchDrag(self, .Switch, args);
343
348
  }
344
349
 
345
- // ident: ID, pokemon: anytype
350
+ // ident: ID, pokemon: <Pokemon>
346
351
  fn switchDrag(self: Self, arg: ArgType, args: anytype) Error!void {
347
352
  if (!enabled) return;
348
353
 
@@ -356,12 +361,13 @@ pub fn Log(comptime Writer: type) type {
356
361
  } else {
357
362
  try self.writer.writeAll(&.{ @intFromEnum(args[1].species), args[1].level });
358
363
  }
359
- try self.writer.writeIntNative(u16, args[1].hp);
360
- try self.writer.writeIntNative(u16, args[1].stats.hp);
364
+ try self.writer.writeInt(u16, args[1].hp, endian);
365
+ try self.writer.writeInt(u16, args[1].stats.hp, endian);
361
366
  try self.writer.writeAll(&.{args[1].status});
362
367
  }
363
368
 
364
- // ident: ID, reason: Cant, m?: anytype
369
+ // ident: ID, reason: Cant
370
+ // ident: ID, reason: .Disable, move: <Move>
365
371
  pub fn cant(self: Self, args: anytype) Error!void {
366
372
  if (!enabled) return;
367
373
 
@@ -369,7 +375,7 @@ pub fn Log(comptime Writer: type) type {
369
375
  try self.writer.writeAll(&.{
370
376
  @intFromEnum(ArgType.Cant),
371
377
  @as(u8, @bitCast(args[0])),
372
- @intFromEnum(args[1]),
378
+ @intFromEnum(@as(Cant, args[1])),
373
379
  });
374
380
  if (args.len == 3) try self.writer.writeByte(@intFromEnum(args[2]));
375
381
  }
@@ -387,7 +393,7 @@ pub fn Log(comptime Writer: type) type {
387
393
  if (!enabled) return;
388
394
 
389
395
  try self.writer.writeByte(@intFromEnum(ArgType.Turn));
390
- try self.writer.writeIntNative(u16, args[0]);
396
+ try self.writer.writeInt(u16, args[0], endian);
391
397
  try self.writer.writeByte(@intFromEnum(ArgType.None));
392
398
  }
393
399
 
@@ -397,7 +403,7 @@ pub fn Log(comptime Writer: type) type {
397
403
 
398
404
  try self.writer.writeAll(&.{
399
405
  @intFromEnum(ArgType.Win),
400
- @intFromEnum(args[0]),
406
+ @intFromEnum(@as(Player, args[0])),
401
407
  @intFromEnum(ArgType.None),
402
408
  });
403
409
  }
@@ -409,34 +415,37 @@ pub fn Log(comptime Writer: type) type {
409
415
  try self.writer.writeAll(&.{ @intFromEnum(ArgType.Tie), @intFromEnum(ArgType.None) });
410
416
  }
411
417
 
412
- // ident: ID, pokemon: anytype, reason: Damage, source?: ID
418
+ // ident: ID, pokemon: <Pokemon>, reason: Damage
419
+ // ident: ID, pokemon: <Pokemon>, reason: .RecoilOf, source: ID
413
420
  pub fn damage(self: Self, args: anytype) Error!void {
414
421
  if (!enabled) return;
415
422
 
416
- assert(@intFromEnum(args[2]) <= @intFromEnum(Damage.LeechSeed) or args.len == 4);
423
+ assert(args[2] != .RecoilOf or args.len == 4);
417
424
  try self.writer.writeAll(&.{
418
425
  @intFromEnum(ArgType.Damage),
419
426
  @as(u8, @bitCast(args[0])),
420
427
  });
421
- try self.writer.writeIntNative(u16, args[1].hp);
422
- try self.writer.writeIntNative(u16, args[1].stats.hp);
423
- try self.writer.writeAll(&.{ args[1].status, @intFromEnum(args[2]) });
428
+ try self.writer.writeInt(u16, args[1].hp, endian);
429
+ try self.writer.writeInt(u16, args[1].stats.hp, endian);
430
+ try self.writer.writeAll(&.{ args[1].status, @intFromEnum(@as(Damage, args[2])) });
424
431
  if (args.len == 4) try self.writer.writeByte(@as(u8, @bitCast(args[3])));
425
432
  }
426
433
 
427
- // ident: ID, pokemon: anytype, reason: Heal, target?: ID)
434
+ // ident: ID, pokemon: <Pokemon>, reason: Heal
435
+ // ident: ID, pokemon: <Pokemon>, reason: .Drain, target: ID
428
436
  pub fn heal(self: Self, args: anytype) Error!void {
429
437
  if (!enabled) return;
430
438
 
431
439
  assert(args[2] != .Drain or args.len == 4);
432
440
  try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(args[0])) });
433
- try self.writer.writeIntNative(u16, args[1].hp);
434
- try self.writer.writeIntNative(u16, args[1].stats.hp);
435
- try self.writer.writeAll(&.{ args[1].status, @intFromEnum(args[2]) });
441
+ try self.writer.writeInt(u16, args[1].hp, endian);
442
+ try self.writer.writeInt(u16, args[1].stats.hp, endian);
443
+ try self.writer.writeAll(&.{ args[1].status, @intFromEnum(@as(Heal, args[2])) });
436
444
  if (args.len == 4) try self.writer.writeByte(@as(u8, @bitCast(args[3])));
437
445
  }
438
446
 
439
- // ident: ID, value: u8, reason: Status, m?: anytype)
447
+ // ident: ID, value: u8, reason: Status
448
+ // ident: ID, value: u8, reason: .From, m: <Move>
440
449
  pub fn status(self: Self, args: anytype) Error!void {
441
450
  if (!enabled) return;
442
451
 
@@ -445,7 +454,7 @@ pub fn Log(comptime Writer: type) type {
445
454
  @intFromEnum(ArgType.Status),
446
455
  @as(u8, @bitCast(args[0])),
447
456
  args[1],
448
- @intFromEnum(args[2]),
457
+ @intFromEnum(@as(Status, args[2])),
449
458
  });
450
459
  if (args.len == 4) try self.writer.writeByte(@intFromEnum(args[3]));
451
460
  }
@@ -458,7 +467,7 @@ pub fn Log(comptime Writer: type) type {
458
467
  @intFromEnum(ArgType.CureStatus),
459
468
  @as(u8, @bitCast(args[0])),
460
469
  args[1],
461
- @intFromEnum(args[2]),
470
+ @intFromEnum(@as(CureStatus, args[2])),
462
471
  });
463
472
  }
464
473
 
@@ -470,7 +479,7 @@ pub fn Log(comptime Writer: type) type {
470
479
  try self.writer.writeAll(&.{
471
480
  @intFromEnum(ArgType.Boost),
472
481
  @as(u8, @bitCast(args[0])),
473
- @intFromEnum(args[1]),
482
+ @intFromEnum(@as(Boost, args[1])),
474
483
  @as(u8, @intCast(@as(i8, args[2]) + 6)),
475
484
  });
476
485
  }
@@ -489,7 +498,7 @@ pub fn Log(comptime Writer: type) type {
489
498
  try self.writer.writeAll(&.{
490
499
  @intFromEnum(ArgType.Fail),
491
500
  @as(u8, @bitCast(args[0])),
492
- @intFromEnum(args[1]),
501
+ @intFromEnum(@as(Fail, args[1])),
493
502
  });
494
503
  }
495
504
 
@@ -511,7 +520,7 @@ pub fn Log(comptime Writer: type) type {
511
520
  });
512
521
  }
513
522
 
514
- // source: ID, m: anytype
523
+ // source: ID, m: <Move>
515
524
  pub fn prepare(self: Self, args: anytype) Error!void {
516
525
  if (!enabled) return;
517
526
 
@@ -532,38 +541,27 @@ pub fn Log(comptime Writer: type) type {
532
541
  });
533
542
  }
534
543
 
535
- pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
544
+ // ident: ID, reason: Activate
545
+ // ident: ID, reason: .SubstituteBlock, m: <Move>
546
+ // ident: ID, reason: .Magnitude, num: u8
547
+ pub fn activate(self: Self, args: anytype) Error!void {
536
548
  if (!enabled) return;
537
549
 
538
- assert(reason != .SubstituteBlock); // TODO
550
+ assert(args.len <= 4);
551
+ const reason: Activate = args[1];
539
552
  try self.writer.writeAll(&.{
540
553
  @intFromEnum(ArgType.Activate),
541
- @as(u8, @bitCast(ident)),
542
- @intFromEnum(reason),
543
- });
544
- }
545
-
546
- pub fn activateMove(self: Self, ident: ID, reason: Activate, m: anytype) Error!void {
547
- if (!enabled) return;
548
-
549
- assert(reason == .SubstituteBlock); // TODO
550
- try self.writer.writeAll(&.{
551
- @intFromEnum(ArgType.Activate),
552
- @as(u8, @bitCast(ident)),
554
+ @as(u8, @bitCast(args[0])),
553
555
  @intFromEnum(reason),
554
- @intFromEnum(m),
555
- });
556
- }
557
-
558
- pub fn magnitude(self: Self, ident: ID, num: u8) Error!void {
559
- if (!enabled) return;
560
-
561
- try self.writer.writeAll(&.{
562
- @intFromEnum(ArgType.Activate),
563
- @as(u8, @bitCast(ident)),
564
- @intFromEnum(Activate.Magnitude),
565
- num,
566
556
  });
557
+ if (args.len == 3) {
558
+ if (reason == .SubstituteBlock) {
559
+ try self.writer.writeByte(@intFromEnum(args[2]));
560
+ } else {
561
+ assert(reason == .Magnitude);
562
+ try self.writer.writeByte(args[2]);
563
+ }
564
+ }
567
565
  }
568
566
 
569
567
  // -
@@ -573,49 +571,40 @@ pub fn Log(comptime Writer: type) type {
573
571
  try self.writer.writeAll(&.{@intFromEnum(ArgType.FieldActivate)});
574
572
  }
575
573
 
576
- pub fn start(self: Self, ident: ID, reason: Start) Error!void {
577
- if (!enabled) return;
578
-
579
- assert(@intFromEnum(reason) < @intFromEnum(Start.TypeChange));
580
- try self.writer.writeAll(&.{
581
- @intFromEnum(ArgType.Start),
582
- @as(u8, @bitCast(ident)),
583
- @intFromEnum(reason),
584
- });
585
- }
586
-
587
- pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
588
- if (!enabled) return;
589
-
590
- try self.writer.writeAll(&.{
591
- @intFromEnum(ArgType.Start),
592
- @as(u8, @bitCast(source)),
593
- @intFromEnum(Start.TypeChange),
594
- @as(u8, @bitCast(types)),
595
- @as(u8, @bitCast(target)),
596
- });
597
- }
598
-
599
- pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
574
+ // ident: ID, reason: Start
575
+ // ident: ID, reason: .Disable | .Mimic | .Encore, m: <Move>
576
+ // ident: ID, reason: .TypeChange, types: <Types>, target: ID
577
+ pub fn start(self: Self, args: anytype) Error!void {
600
578
  if (!enabled) return;
601
579
 
602
- assert(@intFromEnum(reason) > @intFromEnum(Start.TypeChange));
580
+ assert(args.len <= 4);
581
+ const reason: Start = args[1];
603
582
  try self.writer.writeAll(&.{
604
583
  @intFromEnum(ArgType.Start),
605
- @as(u8, @bitCast(ident)),
584
+ @as(u8, @bitCast(args[0])),
606
585
  @intFromEnum(reason),
607
- @intFromEnum(m),
608
586
  });
587
+ if (args.len == 3) {
588
+ assert(reason == .Disable or reason == .Mimic or reason == .Encore);
589
+ try self.writer.writeByte(@intFromEnum(args[2]));
590
+ } else if (args.len == 4) {
591
+ assert(reason == .TypeChange);
592
+ // FIXME: u16 types in Generation II
593
+ try self.writer.writeAll(&.{
594
+ @as(u8, @bitCast(args[2])),
595
+ @as(u8, @bitCast(args[3])),
596
+ });
597
+ }
609
598
  }
610
599
 
611
- // ident: ID, reason: End)
600
+ // ident: ID, reason: End
612
601
  pub fn end(self: Self, args: anytype) Error!void {
613
602
  if (!enabled) return;
614
603
 
615
604
  try self.writer.writeAll(&.{
616
605
  @intFromEnum(ArgType.End),
617
606
  @as(u8, @bitCast(args[0])),
618
- @intFromEnum(args[1]),
607
+ @intFromEnum(@as(End, args[1])),
619
608
  });
620
609
  }
621
610
 
@@ -660,7 +649,7 @@ pub fn Log(comptime Writer: type) type {
660
649
  try self.writer.writeAll(&.{
661
650
  @intFromEnum(ArgType.Immune),
662
651
  @as(u8, @bitCast(args[0])),
663
- @intFromEnum(args[1]),
652
+ @intFromEnum(@as(Immune, args[1])),
664
653
  });
665
654
  }
666
655
 
@@ -675,12 +664,12 @@ pub fn Log(comptime Writer: type) type {
675
664
  });
676
665
  }
677
666
 
678
- // ident: ID, pokemon: anytype
667
+ // ident: ID, pokemon: <Pokemon>
679
668
  pub fn drag(self: Self, args: anytype) Error!void {
680
669
  return switchDrag(self, .Drag, args);
681
670
  }
682
671
 
683
- // target: ID, i: anytype, source: ID
672
+ // target: ID, item: <Item>, source: ID
684
673
  pub fn item(self: Self, args: anytype) Error!void {
685
674
  if (!enabled) return;
686
675
 
@@ -692,7 +681,7 @@ pub fn Log(comptime Writer: type) type {
692
681
  });
693
682
  }
694
683
 
695
- // ident: ID, i: anytype, reason: EndItem
684
+ // ident: ID, item: <Item>, reason: EndItem
696
685
  pub fn enditem(self: Self, args: anytype) Error!void {
697
686
  if (!enabled) return;
698
687
 
@@ -700,7 +689,7 @@ pub fn Log(comptime Writer: type) type {
700
689
  @intFromEnum(ArgType.EndItem),
701
690
  @as(u8, @bitCast(args[0])),
702
691
  @intFromEnum(args[1]),
703
- @intFromEnum(args[2]),
692
+ @intFromEnum(@as(EndItem, args[2])),
704
693
  });
705
694
  }
706
695
 
@@ -714,15 +703,15 @@ pub fn Log(comptime Writer: type) type {
714
703
  });
715
704
  }
716
705
 
717
- // ident: ID, pokemon: anytype, reason: SetHP
706
+ // ident: ID, pokemon: <Pokemon>, reason: SetHP
718
707
  pub fn sethp(self: Self, args: anytype) Error!void {
719
708
  if (!enabled) return;
720
709
 
721
710
  try self.writer.writeAll(&.{ @intFromEnum(ArgType.SetHP), @as(u8, @bitCast(args[0])) });
722
- try self.writer.writeIntNative(u16, args[1].hp);
723
- try self.writer.writeIntNative(u16, args[1].stats.hp);
711
+ try self.writer.writeInt(u16, args[1].hp, endian);
712
+ try self.writer.writeInt(u16, args[1].stats.hp, endian);
724
713
  try self.writer.writeAll(&.{args[1].status});
725
- try self.writer.writeByte(@intFromEnum(args[2]));
714
+ try self.writer.writeByte(@intFromEnum(@as(SetHP, args[2])));
726
715
  }
727
716
 
728
717
  // ident: ID, num: i8
@@ -753,35 +742,36 @@ pub fn Log(comptime Writer: type) type {
753
742
 
754
743
  try self.writer.writeAll(&.{
755
744
  @intFromEnum(ArgType.SideStart),
756
- @intFromEnum(args[0]),
757
- @intFromEnum(args[1]),
745
+ @intFromEnum(@as(Player, args[0])),
746
+ @intFromEnum(@as(Side, args[1])),
758
747
  });
759
748
  }
760
749
 
761
- // player: Player, reason: Side, source?: ID
750
+ // player: Player, reason: Side
751
+ // player: Player, reason: .Spikes, source: ID
762
752
  pub fn sideend(self: Self, args: anytype) Error!void {
763
753
  if (!enabled) return;
764
754
 
765
- assert(@intFromEnum(args[1]) != @intFromEnum(Side.Spikes) or args.len == 3);
755
+ assert(args[1] != .Spikes or args.len == 3);
766
756
  try self.writer.writeAll(&.{
767
757
  @intFromEnum(ArgType.SideEnd),
768
- @intFromEnum(args[0]),
769
- @intFromEnum(args[1]),
758
+ @intFromEnum(@as(Player, args[0])),
759
+ @intFromEnum(@as(Side, args[1])),
770
760
  });
771
761
  if (args.len == 3) try self.writer.writeByte(@as(u8, @bitCast(args[2])));
772
762
  }
773
763
 
774
- // ident: ID, move: anytype
764
+ // ident: ID, move: <Move>
775
765
  pub fn singlemove(self: Self, args: anytype) Error!void {
776
766
  return single(self, .SingleMove, args);
777
767
  }
778
768
 
779
- // ident: ID, m: anytype
769
+ // ident: ID, move: <Move>
780
770
  pub fn singleturn(self: Self, args: anytype) Error!void {
781
771
  return single(self, .SingleTurn, args);
782
772
  }
783
773
 
784
- // ident: ID, move: anytype
774
+ // ident: ID, move: <Move>
785
775
  fn single(self: Self, arg: ArgType, args: anytype) Error!void {
786
776
  if (!enabled) return;
787
777
 
@@ -792,7 +782,7 @@ pub fn Log(comptime Writer: type) type {
792
782
  });
793
783
  }
794
784
 
795
- // w: anytype, reason: Weather
785
+ // weather: <Weather>, reason: Weather
796
786
  pub fn weather(self: Self, args: anytype) Error!void {
797
787
  if (!enabled) return;
798
788
 
@@ -800,7 +790,7 @@ pub fn Log(comptime Writer: type) type {
800
790
  try self.writer.writeAll(&.{
801
791
  @intFromEnum(ArgType.Weather),
802
792
  @intFromEnum(args[0]),
803
- @intFromEnum(args[1]),
793
+ @intFromEnum(@as(Weather, args[1])),
804
794
  });
805
795
  }
806
796
 
@@ -843,10 +833,10 @@ pub const ByteStream = struct {
843
833
  try self.stream.writeByte(byte);
844
834
  }
845
835
 
846
- pub fn writeIntNative(self: Writer, comptime T: type, value: T) Error!void {
836
+ pub fn writeInt(self: Writer, comptime T: type, v: T, end: std.builtin.Endian) Error!void {
847
837
  // TODO: rework this to write directly to the buffer?
848
- var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;
849
- std.mem.writeIntNative(T, &bytes, value);
838
+ var bytes: [@divExact(@typeInfo(T).Int.bits, 8)]u8 = undefined;
839
+ std.mem.writeInt(std.math.ByteAlignedInt(@TypeOf(v)), &bytes, v, end);
850
840
  return self.writeAll(&bytes);
851
841
  }
852
842
  };
@@ -955,19 +945,19 @@ pub fn format(
955
945
  if (a[i] == N(gen.Gender.Unknown)) {
956
946
  i += 1;
957
947
  } else {
958
- var gender = if (a[i] == N(gen.Gender.Male)) "M" else "F";
948
+ const gender = if (a[i] == N(gen.Gender.Male)) "M" else "F";
959
949
  printc(", {s}", .{gender}, a, b, &i, 1, color);
960
950
  }
961
951
  }
962
952
  printc(" L{d}", .{a[i]}, a, b, &i, 1, color);
963
953
  switch (endian) {
964
- .Big => {
954
+ .big => {
965
955
  var hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
966
956
  printc(" {d}", .{hp}, a, b, &i, 2, color);
967
957
  hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
968
958
  printc("/{d}", .{hp}, a, b, &i, 2, color);
969
959
  },
970
- .Little => {
960
+ .little => {
971
961
  var hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
972
962
  printc(" {d}", .{hp}, a, b, &i, 2, color);
973
963
  hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
@@ -998,8 +988,8 @@ pub fn format(
998
988
  },
999
989
  .Turn => {
1000
990
  const turn = switch (endian) {
1001
- .Big => @as(u16, a[i]) << 8 | @as(u16, a[i + 1]),
1002
- .Little => @as(u16, a[i + 1]) << 8 | @as(u16, a[i]),
991
+ .big => @as(u16, a[i]) << 8 | @as(u16, a[i + 1]),
992
+ .little => @as(u16, a[i + 1]) << 8 | @as(u16, a[i]),
1003
993
  };
1004
994
  printc(" {d}", .{turn}, a, b, &i, 2, color);
1005
995
  },
@@ -1010,13 +1000,13 @@ pub fn format(
1010
1000
  var id = ID.from(@intCast(a[i]));
1011
1001
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
1012
1002
  switch (endian) {
1013
- .Big => {
1003
+ .big => {
1014
1004
  var hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
1015
1005
  printc(" {d}", .{hp}, a, b, &i, 2, color);
1016
1006
  hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
1017
1007
  printc("/{d}", .{hp}, a, b, &i, 2, color);
1018
1008
  },
1019
- .Little => {
1009
+ .little => {
1020
1010
  var hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
1021
1011
  printc(" {d}", .{hp}, a, b, &i, 2, color);
1022
1012
  hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
@@ -1081,7 +1071,13 @@ pub fn format(
1081
1071
  .Activate => {
1082
1072
  const id = ID.from(@intCast(a[i]));
1083
1073
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
1084
- printc(" {s}", .{@tagName(@as(Activate, @enumFromInt(a[i])))}, a, b, &i, 1, color);
1074
+ const reason: Activate = @enumFromInt(a[i]);
1075
+ printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
1076
+ if (reason == .SubstituteBlock) {
1077
+ printc(" {s}", .{formatter(gen, .Move, a[i])}, a, b, &i, 1, color);
1078
+ } else if (reason == .Magnitude) {
1079
+ printc(" {d}", .{a[i]}, a, b, &i, 1, color);
1080
+ }
1085
1081
  },
1086
1082
  .Start => {
1087
1083
  const id = ID.from(@intCast(a[i]));
@@ -1089,6 +1085,7 @@ pub fn format(
1089
1085
  const reason = a[i];
1090
1086
  printc(" {s}", .{@tagName(@as(Start, @enumFromInt(reason)))}, a, b, &i, 1, color);
1091
1087
  if (@as(Start, @enumFromInt(reason)) == .TypeChange) {
1088
+ // FIXME
1092
1089
  const types = @as(gen1.Types, @bitCast(a[i]));
1093
1090
  const args = .{
1094
1091
  formatter(gen, .Type, @intFromEnum(types.type1)),
@@ -1131,13 +1128,13 @@ pub fn format(
1131
1128
  const id = ID.from(@intCast(a[i]));
1132
1129
  printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
1133
1130
  switch (endian) {
1134
- .Big => {
1131
+ .big => {
1135
1132
  var hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
1136
1133
  printc(" {d}", .{hp}, a, b, &i, 2, color);
1137
1134
  hp = @as(u16, a[i]) << 8 | @as(u16, a[i + 1]);
1138
1135
  printc("/{d}", .{hp}, a, b, &i, 2, color);
1139
1136
  },
1140
- .Little => {
1137
+ .little => {
1141
1138
  var hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
1142
1139
  printc(" {d}", .{hp}, a, b, &i, 2, color);
1143
1140
  hp = @as(u16, a[i + 1]) << 8 | @as(u16, a[i]);
@@ -1205,14 +1202,11 @@ pub fn expectLog(
1205
1202
  ) !void {
1206
1203
  if (!enabled) return;
1207
1204
 
1208
- const color = color: {
1209
- if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
1210
- break :color true;
1211
- } else if (std.process.hasEnvVarConstant("NO_COLOR")) {
1212
- break :color false;
1213
- } else {
1214
- break :color std.io.getStdErr().supportsAnsiEscapeCodes();
1215
- }
1205
+ const color = if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR"))
1206
+ true
1207
+ else switch (std.io.tty.detectConfig(std.io.getStdErr())) {
1208
+ .escape_codes => true,
1209
+ else => false,
1216
1210
  };
1217
1211
 
1218
1212
  expectEqualBytes(expected, actual, offset) catch |err| switch (err) {
@@ -1244,8 +1238,6 @@ fn expectEqualBytes(expected: []const u8, actual: []const u8, offset: usize) !vo
1244
1238
  }
1245
1239
  }
1246
1240
 
1247
- const endian = builtin.target.cpu.arch.endian();
1248
-
1249
1241
  fn N(e: anytype) u8 {
1250
1242
  return @intFromEnum(e);
1251
1243
  }
@@ -1253,20 +1245,13 @@ fn N(e: anytype) u8 {
1253
1245
  const p1 = Player.P1;
1254
1246
  const p2 = Player.P2;
1255
1247
 
1256
- const gen1 = struct {
1257
- pub usingnamespace @import("../gen1/data.zig");
1258
- pub const helpers = @import("../gen1/helpers.zig");
1259
- };
1260
-
1261
- const gen2 = struct {
1262
- pub usingnamespace @import("../gen2/data.zig");
1263
- pub const helpers = @import("../gen2/helpers.zig");
1264
- };
1265
-
1266
- var buf: [gen1.LOGS_SIZE]u8 = undefined;
1248
+ var buf: [pkmn.LOGS_SIZE]u8 = undefined;
1267
1249
  var stream: ByteStream = .{ .buffer = &buf };
1268
1250
  var log: FixedLog = .{ .writer = stream.writer() };
1269
1251
 
1252
+ const gen1 = pkmn.gen1;
1253
+ const gen2 = pkmn.gen2;
1254
+
1270
1255
  const M1 = gen1.Move;
1271
1256
  const S1 = gen1.Species;
1272
1257
 
@@ -1355,8 +1340,8 @@ test "|switch|" {
1355
1340
  try log.switched(.{ p2.ident(3), &snorlax });
1356
1341
  const par = 0b1000000;
1357
1342
  var expected: []const u8 = switch (endian) {
1358
- .Big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 91, 0, 200, 1, 144, par },
1359
- .Little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 91, 200, 0, 144, 1, par },
1343
+ .big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 91, 0, 200, 1, 144, par },
1344
+ .little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 91, 200, 0, 144, 1, par },
1360
1345
  };
1361
1346
  try expectLog1(expected, buf[0..9]);
1362
1347
  stream.reset();
@@ -1366,8 +1351,8 @@ test "|switch|" {
1366
1351
  snorlax.status = 0;
1367
1352
  try log.switched(.{ p2.ident(3), &snorlax });
1368
1353
  expected = switch (endian) {
1369
- .Big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 0, 0, 1, 144, 0 },
1370
- .Little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 0, 0, 144, 1, 0 },
1354
+ .big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 0, 0, 1, 144, 0 },
1355
+ .little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 0, 0, 144, 1, 0 },
1371
1356
  };
1372
1357
  try expectLog1(expected, buf[0..9]);
1373
1358
  stream.reset();
@@ -1375,8 +1360,8 @@ test "|switch|" {
1375
1360
  snorlax.hp = 400;
1376
1361
  try log.switched(.{ p2.ident(3), &snorlax });
1377
1362
  expected = switch (endian) {
1378
- .Big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 1, 144, 1, 144, 0 },
1379
- .Little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 144, 1, 144, 1, 0 },
1363
+ .big => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 1, 144, 1, 144, 0 },
1364
+ .little => &.{ N(ArgType.Switch), 0b1011, N(S1.Snorlax), 100, 144, 1, 144, 1, 0 },
1380
1365
  };
1381
1366
  try expectLog1(expected, buf[0..9]);
1382
1367
  stream.reset();
@@ -1394,19 +1379,19 @@ test "|switch|" {
1394
1379
  N(gen2.Gender.Female),
1395
1380
  91,
1396
1381
  } ++ switch (endian) {
1397
- .Big => .{ 0, 200, 1, 144, par },
1398
- .Little => .{ 200, 0, 144, 1, par },
1382
+ .big => .{ 0, 200, 1, 144, par },
1383
+ .little => .{ 200, 0, 144, 1, par },
1399
1384
  });
1400
1385
  try expectLog2(expected, buf[0..10]);
1401
1386
  stream.reset();
1402
1387
  }
1403
1388
 
1404
1389
  test "|cant|" {
1405
- try log.cant(.{ p2.ident(6), Cant.Bound });
1390
+ try log.cant(.{ p2.ident(6), .Bound });
1406
1391
  try expectLog1(&.{ N(ArgType.Cant), 0b1110, N(Cant.Bound) }, buf[0..3]);
1407
1392
  stream.reset();
1408
1393
 
1409
- try log.cant(.{ p1.ident(2), Cant.Disable, M1.Earthquake });
1394
+ try log.cant(.{ p1.ident(2), .Disable, M1.Earthquake });
1410
1395
  try expectLog1(&.{ N(ArgType.Cant), 2, N(Cant.Disable), N(M1.Earthquake) }, buf[0..4]);
1411
1396
  stream.reset();
1412
1397
  }
@@ -1423,16 +1408,16 @@ test "|faint|" {
1423
1408
 
1424
1409
  test "|turn|" {
1425
1410
  try log.turn(.{42});
1426
- var expected = switch (endian) {
1427
- .Big => &.{ N(ArgType.Turn), 0, 42, N(ArgType.None) },
1428
- .Little => &.{ N(ArgType.Turn), 42, 0, N(ArgType.None) },
1411
+ const expected = switch (endian) {
1412
+ .big => &.{ N(ArgType.Turn), 0, 42, N(ArgType.None) },
1413
+ .little => &.{ N(ArgType.Turn), 42, 0, N(ArgType.None) },
1429
1414
  };
1430
1415
  try expectLog1(expected, buf[0..4]);
1431
1416
  stream.reset();
1432
1417
  }
1433
1418
 
1434
1419
  test "|win|" {
1435
- try log.win(.{Player.P2});
1420
+ try log.win(.{.P2});
1436
1421
  try expectLog1(&.{ N(ArgType.Win), 1, N(ArgType.None) }, buf[0..3]);
1437
1422
  stream.reset();
1438
1423
  }
@@ -1447,10 +1432,10 @@ test "|-damage|" {
1447
1432
  var chansey = gen1.helpers.Pokemon.init(.{ .species = .Chansey, .moves = &.{.Splash} });
1448
1433
  chansey.hp = 612;
1449
1434
  chansey.status = gen1.Status.slp(1);
1450
- try log.damage(.{ p2.ident(2), &chansey, Damage.None });
1435
+ try log.damage(.{ p2.ident(2), &chansey, .None });
1451
1436
  var expected: []const u8 = switch (endian) {
1452
- .Big => &.{ N(ArgType.Damage), 0b1010, 2, 100, 2, 191, 1, N(Damage.None) },
1453
- .Little => &.{ N(ArgType.Damage), 0b1010, 100, 2, 191, 2, 1, N(Damage.None) },
1437
+ .big => &.{ N(ArgType.Damage), 0b1010, 2, 100, 2, 191, 1, N(Damage.None) },
1438
+ .little => &.{ N(ArgType.Damage), 0b1010, 100, 2, 191, 2, 1, N(Damage.None) },
1454
1439
  };
1455
1440
  try expectLog1(expected, buf[0..8]);
1456
1441
  stream.reset();
@@ -1458,19 +1443,19 @@ test "|-damage|" {
1458
1443
  chansey.hp = 100;
1459
1444
  chansey.stats.hp = 256;
1460
1445
  chansey.status = 0;
1461
- try log.damage(.{ p2.ident(2), &chansey, Damage.Confusion });
1446
+ try log.damage(.{ p2.ident(2), &chansey, .Confusion });
1462
1447
  expected = switch (endian) {
1463
- .Big => &.{ N(ArgType.Damage), 0b1010, 0, 100, 1, 0, 0, N(Damage.Confusion) },
1464
- .Little => &.{ N(ArgType.Damage), 0b1010, 100, 0, 0, 1, 0, N(Damage.Confusion) },
1448
+ .big => &.{ N(ArgType.Damage), 0b1010, 0, 100, 1, 0, 0, N(Damage.Confusion) },
1449
+ .little => &.{ N(ArgType.Damage), 0b1010, 100, 0, 0, 1, 0, N(Damage.Confusion) },
1465
1450
  };
1466
1451
  try expectLog1(expected, buf[0..8]);
1467
1452
  stream.reset();
1468
1453
 
1469
1454
  chansey.status = gen1.Status.init(.PSN);
1470
- try log.damage(.{ p2.ident(2), &chansey, Damage.RecoilOf, p1.ident(1) });
1455
+ try log.damage(.{ p2.ident(2), &chansey, .RecoilOf, p1.ident(1) });
1471
1456
  expected = switch (endian) {
1472
- .Big => &.{ N(ArgType.Damage), 0b1010, 0, 100, 1, 0, 0b1000, N(Damage.RecoilOf), 1 },
1473
- .Little => &.{ N(ArgType.Damage), 0b1010, 100, 0, 0, 1, 0b1000, N(Damage.RecoilOf), 1 },
1457
+ .big => &.{ N(ArgType.Damage), 0b1010, 0, 100, 1, 0, 0b1000, N(Damage.RecoilOf), 1 },
1458
+ .little => &.{ N(ArgType.Damage), 0b1010, 100, 0, 0, 1, 0b1000, N(Damage.RecoilOf), 1 },
1474
1459
  };
1475
1460
  try expectLog1(expected, buf[0..9]);
1476
1461
  stream.reset();
@@ -1480,10 +1465,10 @@ test "|-heal|" {
1480
1465
  var chansey = gen1.helpers.Pokemon.init(.{ .species = .Chansey, .moves = &.{.Splash} });
1481
1466
  chansey.hp = 612;
1482
1467
  chansey.status = gen1.Status.slp(1);
1483
- try log.heal(.{ p2.ident(2), &chansey, Heal.None });
1468
+ try log.heal(.{ p2.ident(2), &chansey, .None });
1484
1469
  var expected: []const u8 = switch (endian) {
1485
- .Big => &.{ N(ArgType.Heal), 0b1010, 2, 100, 2, 191, 1, N(Heal.None) },
1486
- .Little => &.{ N(ArgType.Heal), 0b1010, 100, 2, 191, 2, 1, N(Heal.None) },
1470
+ .big => &.{ N(ArgType.Heal), 0b1010, 2, 100, 2, 191, 1, N(Heal.None) },
1471
+ .little => &.{ N(ArgType.Heal), 0b1010, 100, 2, 191, 2, 1, N(Heal.None) },
1487
1472
  };
1488
1473
  try expectLog1(expected, buf[0..8]);
1489
1474
  stream.reset();
@@ -1491,33 +1476,33 @@ test "|-heal|" {
1491
1476
  chansey.hp = 100;
1492
1477
  chansey.stats.hp = 256;
1493
1478
  chansey.status = 0;
1494
- try log.heal(.{ p2.ident(2), &chansey, Heal.Silent });
1479
+ try log.heal(.{ p2.ident(2), &chansey, .Silent });
1495
1480
  expected = switch (endian) {
1496
- .Big => &.{ N(ArgType.Heal), 0b1010, 0, 100, 1, 0, 0, N(Heal.Silent) },
1497
- .Little => &.{ N(ArgType.Heal), 0b1010, 100, 0, 0, 1, 0, N(Heal.Silent) },
1481
+ .big => &.{ N(ArgType.Heal), 0b1010, 0, 100, 1, 0, 0, N(Heal.Silent) },
1482
+ .little => &.{ N(ArgType.Heal), 0b1010, 100, 0, 0, 1, 0, N(Heal.Silent) },
1498
1483
  };
1499
1484
  try expectLog1(expected, buf[0..8]);
1500
1485
  stream.reset();
1501
1486
 
1502
- try log.heal(.{ p2.ident(2), &chansey, Heal.Drain, p1.ident(1) });
1487
+ try log.heal(.{ p2.ident(2), &chansey, .Drain, p1.ident(1) });
1503
1488
  expected = switch (endian) {
1504
- .Big => &.{ N(ArgType.Heal), 0b1010, 0, 100, 1, 0, 0, N(Heal.Drain), 1 },
1505
- .Little => &.{ N(ArgType.Heal), 0b1010, 100, 0, 0, 1, 0, N(Heal.Drain), 1 },
1489
+ .big => &.{ N(ArgType.Heal), 0b1010, 0, 100, 1, 0, 0, N(Heal.Drain), 1 },
1490
+ .little => &.{ N(ArgType.Heal), 0b1010, 100, 0, 0, 1, 0, N(Heal.Drain), 1 },
1506
1491
  };
1507
1492
  try expectLog1(expected, buf[0..9]);
1508
1493
  stream.reset();
1509
1494
  }
1510
1495
 
1511
1496
  test "|-status|" {
1512
- try log.status(.{ p2.ident(6), gen1.Status.init(.BRN), Status.None });
1497
+ try log.status(.{ p2.ident(6), gen1.Status.init(.BRN), .None });
1513
1498
  try expectLog1(&.{ N(ArgType.Status), 0b1110, 0b10000, N(Status.None) }, buf[0..4]);
1514
1499
  stream.reset();
1515
1500
 
1516
- try log.status(.{ p2.ident(2), gen1.Status.init(.PSN), Status.Silent });
1501
+ try log.status(.{ p2.ident(2), gen1.Status.init(.PSN), .Silent });
1517
1502
  try expectLog1(&.{ N(ArgType.Status), 0b1010, 0b1000, N(Status.Silent) }, buf[0..4]);
1518
1503
  stream.reset();
1519
1504
 
1520
- try log.status(.{ p1.ident(1), gen1.Status.init(.PAR), Status.From, M1.BodySlam });
1505
+ try log.status(.{ p1.ident(1), gen1.Status.init(.PAR), .From, M1.BodySlam });
1521
1506
  try expectLog1(
1522
1507
  &.{ N(ArgType.Status), 0b0001, 0b1000000, N(Status.From), N(M1.BodySlam) },
1523
1508
  buf[0..5],
@@ -1526,11 +1511,11 @@ test "|-status|" {
1526
1511
  }
1527
1512
 
1528
1513
  test "|-curestatus|" {
1529
- try log.curestatus(.{ p2.ident(6), gen1.Status.slp(7), CureStatus.Message });
1514
+ try log.curestatus(.{ p2.ident(6), gen1.Status.slp(7), .Message });
1530
1515
  try expectLog1(&.{ N(ArgType.CureStatus), 0b1110, 0b111, N(CureStatus.Message) }, buf[0..4]);
1531
1516
  stream.reset();
1532
1517
 
1533
- try log.curestatus(.{ p1.ident(2), gen1.Status.TOX, CureStatus.Silent });
1518
+ try log.curestatus(.{ p1.ident(2), gen1.Status.TOX, .Silent });
1534
1519
  try expectLog1(&.{
1535
1520
  N(ArgType.CureStatus),
1536
1521
  0b0010,
@@ -1541,15 +1526,15 @@ test "|-curestatus|" {
1541
1526
  }
1542
1527
 
1543
1528
  test "|-boost|" {
1544
- try log.boost(.{ p2.ident(6), Boost.Speed, 2 });
1529
+ try log.boost(.{ p2.ident(6), .Speed, 2 });
1545
1530
  try expectLog1(&.{ N(ArgType.Boost), 0b1110, N(Boost.Speed), 8 }, buf[0..4]);
1546
1531
  stream.reset();
1547
1532
 
1548
- try log.boost(.{ p1.ident(2), Boost.Rage, 1 });
1533
+ try log.boost(.{ p1.ident(2), .Rage, 1 });
1549
1534
  try expectLog1(&.{ N(ArgType.Boost), 0b0010, N(Boost.Rage), 7 }, buf[0..4]);
1550
1535
  stream.reset();
1551
1536
 
1552
- try log.boost(.{ p2.ident(3), Boost.Defense, -2 });
1537
+ try log.boost(.{ p2.ident(3), .Defense, -2 });
1553
1538
  try expectLog1(&.{ N(ArgType.Boost), 0b1011, N(Boost.Defense), 4 }, buf[0..4]);
1554
1539
  stream.reset();
1555
1540
  }
@@ -1561,19 +1546,19 @@ test "|-clearallboost|" {
1561
1546
  }
1562
1547
 
1563
1548
  test "|-fail|" {
1564
- try log.fail(.{ p2.ident(6), Fail.None });
1549
+ try log.fail(.{ p2.ident(6), .None });
1565
1550
  try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.None) }, buf[0..3]);
1566
1551
  stream.reset();
1567
1552
 
1568
- try log.fail(.{ p2.ident(6), Fail.Sleep });
1553
+ try log.fail(.{ p2.ident(6), .Sleep });
1569
1554
  try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.Sleep) }, buf[0..3]);
1570
1555
  stream.reset();
1571
1556
 
1572
- try log.fail(.{ p2.ident(6), Fail.Substitute });
1557
+ try log.fail(.{ p2.ident(6), .Substitute });
1573
1558
  try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.Substitute) }, buf[0..3]);
1574
1559
  stream.reset();
1575
1560
 
1576
- try log.fail(.{ p2.ident(6), Fail.Weak });
1561
+ try log.fail(.{ p2.ident(6), .Weak });
1577
1562
  try expectLog1(&.{ N(ArgType.Fail), 0b1110, N(Fail.Weak) }, buf[0..3]);
1578
1563
  stream.reset();
1579
1564
  }
@@ -1602,25 +1587,32 @@ test "|-mustrecharge|" {
1602
1587
  }
1603
1588
 
1604
1589
  test "|-activate|" {
1605
- try log.activate(p1.ident(2), .Struggle);
1590
+ try log.activate(.{ p1.ident(2), .Struggle });
1606
1591
  try expectLog1(&.{ N(ArgType.Activate), 0b0010, N(Activate.Struggle) }, buf[0..3]);
1607
1592
  stream.reset();
1608
1593
 
1609
- try log.activate(p2.ident(4), .Mist);
1594
+ try log.activate(.{ p2.ident(4), .Mist });
1610
1595
  try expectLog1(&.{ N(ArgType.Activate), 0b1100, N(Activate.Mist) }, buf[0..3]);
1611
1596
  stream.reset();
1612
1597
 
1613
- try log.activate(p2.ident(6), .Substitute);
1598
+ try log.activate(.{ p2.ident(6), .Substitute });
1614
1599
  try expectLog1(&.{ N(ArgType.Activate), 0b1110, N(Activate.Substitute) }, buf[0..3]);
1615
1600
  stream.reset();
1616
1601
 
1617
- try log.activate(p1.ident(2), .Splash);
1602
+ try log.activate(.{ p1.ident(2), .Splash });
1618
1603
  try expectLog1(&.{ N(ArgType.Activate), 0b0010, N(Activate.Splash) }, buf[0..3]);
1619
1604
  stream.reset();
1620
1605
 
1621
- // TODO activateMove
1606
+ try log.activate(.{ p1.ident(4), .SubstituteBlock, M2.Spite });
1607
+ try expectLog1(&.{
1608
+ N(ArgType.Activate),
1609
+ 0b0100,
1610
+ N(Activate.SubstituteBlock),
1611
+ N(M2.Spite),
1612
+ }, buf[0..4]);
1613
+ stream.reset();
1622
1614
 
1623
- try log.magnitude(p1.ident(3), 5);
1615
+ try log.activate(.{ p1.ident(3), .Magnitude, 5 });
1624
1616
  try expectLog1(&.{ N(ArgType.Activate), 0b0011, N(Activate.Magnitude), 5 }, buf[0..4]);
1625
1617
  stream.reset();
1626
1618
  }
@@ -1632,43 +1624,53 @@ test "|-fieldactivate|" {
1632
1624
  }
1633
1625
 
1634
1626
  test "|-start|" {
1635
- try log.start(p2.ident(6), .Bide);
1627
+ try log.start(.{ p2.ident(6), .Bide });
1636
1628
  try expectLog1(&.{ N(ArgType.Start), 0b1110, N(Start.Bide) }, buf[0..3]);
1637
1629
  stream.reset();
1638
1630
 
1639
- try log.start(p1.ident(2), .ConfusionSilent);
1631
+ try log.start(.{ p1.ident(2), .ConfusionSilent });
1640
1632
  try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.ConfusionSilent) }, buf[0..3]);
1641
1633
  stream.reset();
1642
1634
 
1643
- try log.typechange(p2.ident(6), gen1.Types{ .type1 = .Fire, .type2 = .Fire }, p2.ident(5));
1635
+ try log.start(.{
1636
+ p2.ident(6),
1637
+ .TypeChange,
1638
+ gen1.Types{ .type1 = .Fire, .type2 = .Fire },
1639
+ p2.ident(5),
1640
+ });
1644
1641
  try expectLog1(
1645
1642
  &.{ N(ArgType.Start), 0b1110, N(Start.TypeChange), 0b1000_1000, 0b1101 },
1646
1643
  buf[0..5],
1647
1644
  );
1648
1645
  stream.reset();
1649
1646
 
1650
- try log.typechange(p1.ident(2), gen1.Types{ .type1 = .Bug, .type2 = .Poison }, p2.ident(4));
1647
+ try log.start(.{
1648
+ p1.ident(2),
1649
+ .TypeChange,
1650
+ gen1.Types{ .type1 = .Bug, .type2 = .Poison },
1651
+ p2.ident(4),
1652
+ });
1651
1653
  try expectLog1(
1652
1654
  &.{ N(ArgType.Start), 0b0010, N(Start.TypeChange), 0b0011_0110, 0b1100 },
1653
1655
  buf[0..5],
1654
1656
  );
1655
1657
  stream.reset();
1656
1658
 
1657
- try log.startEffect(p1.ident(2), .Disable, M1.Surf);
1659
+ try log.start(.{ p1.ident(2), .Disable, M1.Surf });
1658
1660
  try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.Disable), N(M1.Surf) }, buf[0..4]);
1659
1661
  stream.reset();
1660
1662
 
1661
- try log.startEffect(p1.ident(2), .Mimic, M1.Surf);
1663
+ try log.start(.{ p1.ident(2), .Mimic, M1.Surf });
1662
1664
  try expectLog1(&.{ N(ArgType.Start), 0b0010, N(Start.Mimic), N(M1.Surf) }, buf[0..4]);
1663
1665
  stream.reset();
1664
1666
  }
1665
1667
 
1666
1668
  test "|-end|" {
1667
- try log.end(.{ p2.ident(6), End.Bide });
1669
+ try log.end(.{ p2.ident(6), .Bide });
1668
1670
  try expectLog1(&.{ N(ArgType.End), 0b1110, N(End.Bide) }, buf[0..3]);
1669
1671
  stream.reset();
1670
1672
 
1671
- try log.end(.{ p1.ident(2), End.ConfusionSilent });
1673
+ try log.end(.{ p1.ident(2), .ConfusionSilent });
1672
1674
  try expectLog1(&.{ N(ArgType.End), 0b0010, N(End.ConfusionSilent) }, buf[0..3]);
1673
1675
  stream.reset();
1674
1676
  }
@@ -1698,11 +1700,11 @@ test "|-resisted|" {
1698
1700
  }
1699
1701
 
1700
1702
  test "|-immune|" {
1701
- try log.immune(.{ p1.ident(3), Immune.None });
1703
+ try log.immune(.{ p1.ident(3), .None });
1702
1704
  try expectLog1(&.{ N(ArgType.Immune), 0b0011, N(Immune.None) }, buf[0..3]);
1703
1705
  stream.reset();
1704
1706
 
1705
- try log.immune(.{ p2.ident(2), Immune.OHKO });
1707
+ try log.immune(.{ p2.ident(2), .OHKO });
1706
1708
  try expectLog1(&.{ N(ArgType.Immune), 0b1010, N(Immune.OHKO) }, buf[0..3]);
1707
1709
  stream.reset();
1708
1710
  }
@@ -1728,8 +1730,8 @@ test "|drag|" {
1728
1730
  N(gen2.Gender.Female),
1729
1731
  91,
1730
1732
  } ++ switch (endian) {
1731
- .Big => .{ 0, 200, 1, 144, par },
1732
- .Little => .{ 200, 0, 144, 1, par },
1733
+ .big => .{ 0, 200, 1, 144, par },
1734
+ .little => .{ 200, 0, 144, 1, par },
1733
1735
  });
1734
1736
  try expectLog2(expected, buf[0..10]);
1735
1737
  stream.reset();
@@ -1742,11 +1744,11 @@ test "|-item|" {
1742
1744
  }
1743
1745
 
1744
1746
  test "|-enditem|" {
1745
- try log.enditem(.{ p1.ident(1), I2.BerserkGene, EndItem.None });
1747
+ try log.enditem(.{ p1.ident(1), I2.BerserkGene, .None });
1746
1748
  try expectLog2(&.{ N(ArgType.EndItem), 0b0001, N(I2.BerserkGene), N(EndItem.None) }, buf[0..4]);
1747
1749
  stream.reset();
1748
1750
 
1749
- try log.enditem(.{ p2.ident(4), I2.PRZCureBerry, EndItem.Eat });
1751
+ try log.enditem(.{ p2.ident(4), I2.PRZCureBerry, .Eat });
1750
1752
  try expectLog2(&.{ N(ArgType.EndItem), 0b1100, N(I2.PRZCureBerry), N(EndItem.Eat) }, buf[0..4]);
1751
1753
  stream.reset();
1752
1754
  }
@@ -1760,10 +1762,10 @@ test "|-cureteam|" {
1760
1762
  test "|-sethp|" {
1761
1763
  var blissey = gen2.helpers.Pokemon.init(.{ .species = .Blissey, .moves = &.{.PainSplit} });
1762
1764
  blissey.hp = 612;
1763
- try log.sethp(.{ p2.ident(2), &blissey, SetHP.Silent });
1764
- var expected: []const u8 = switch (endian) {
1765
- .Big => &.{ N(ArgType.SetHP), 0b1010, 2, 100, 2, 201, 0, N(SetHP.Silent) },
1766
- .Little => &.{ N(ArgType.SetHP), 0b1010, 100, 2, 201, 2, 0, N(SetHP.Silent) },
1765
+ try log.sethp(.{ p2.ident(2), &blissey, .Silent });
1766
+ const expected: []const u8 = switch (endian) {
1767
+ .big => &.{ N(ArgType.SetHP), 0b1010, 2, 100, 2, 201, 0, N(SetHP.Silent) },
1768
+ .little => &.{ N(ArgType.SetHP), 0b1010, 100, 2, 201, 2, 0, N(SetHP.Silent) },
1767
1769
  };
1768
1770
  try expectLog2(expected, buf[0..8]);
1769
1771
  stream.reset();
@@ -1786,17 +1788,17 @@ test "|-copyboost|" {
1786
1788
  }
1787
1789
 
1788
1790
  test "|-sidestart|" {
1789
- try log.sidestart(.{ Player.P2, Side.Reflect });
1791
+ try log.sidestart(.{ .P2, .Reflect });
1790
1792
  try expectLog2(&.{ N(ArgType.SideStart), 1, N(Side.Reflect) }, buf[0..3]);
1791
1793
  stream.reset();
1792
1794
  }
1793
1795
 
1794
1796
  test "|-sideend|" {
1795
- try log.sideend(.{ Player.P2, Side.LightScreen });
1797
+ try log.sideend(.{ .P2, .LightScreen });
1796
1798
  try expectLog2(&.{ N(ArgType.SideEnd), 1, N(Side.LightScreen) }, buf[0..3]);
1797
1799
  stream.reset();
1798
1800
 
1799
- try log.sideend(.{ Player.P1, Side.Spikes, p1.ident(3) });
1801
+ try log.sideend(.{ .P1, .Spikes, p1.ident(3) });
1800
1802
  try expectLog2(&.{
1801
1803
  N(ArgType.SideEnd),
1802
1804
  0,
@@ -1819,11 +1821,11 @@ test "|-singleturn|" {
1819
1821
  }
1820
1822
 
1821
1823
  test "|-weather|" {
1822
- try log.weather(.{ W2.Rain, Weather.Upkeep });
1824
+ try log.weather(.{ W2.Rain, .Upkeep });
1823
1825
  try expectLog2(&.{ N(ArgType.Weather), N(W2.Rain), N(Weather.Upkeep) }, buf[0..3]);
1824
1826
  stream.reset();
1825
1827
 
1826
- try log.weather(.{ W2.None, Weather.None });
1828
+ try log.weather(.{ W2.None, .None });
1827
1829
  try expectLog2(&.{ N(ArgType.Weather), N(W2.None), N(Weather.None) }, buf[0..3]);
1828
1830
  stream.reset();
1829
1831
  }