@pkmn/engine 0.1.0-dev.954f650d → 0.1.0-dev.95e81bfe

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.
Files changed (47) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +37 -14
  3. package/build/pkg/addon.js.map +1 -1
  4. package/build/pkg/data/ids.json +12 -12
  5. package/build/pkg/data/layout.json +2 -2
  6. package/build/pkg/data/protocol.json +69 -12
  7. package/build/pkg/data.d.ts +3 -2
  8. package/build/pkg/data.js.map +1 -1
  9. package/build/pkg/gen1.js +2 -2
  10. package/build/pkg/gen1.js.map +1 -1
  11. package/build/pkg/index.d.ts +2 -1
  12. package/build/pkg/index.js.map +1 -1
  13. package/build/pkg/protocol.js +57 -38
  14. package/build/pkg/protocol.js.map +1 -1
  15. package/build/test/display.js.map +1 -1
  16. package/build/tools/debug.js +3 -1
  17. package/build/tools/debug.js.map +1 -1
  18. package/build.zig +80 -70
  19. package/package.json +43 -23
  20. package/src/bin/install-pkmn-engine +14 -14
  21. package/src/lib/common/data.zig +9 -9
  22. package/src/lib/common/optional.zig +9 -2
  23. package/src/lib/common/protocol.zig +734 -318
  24. package/src/lib/common/rational.zig +12 -8
  25. package/src/lib/common/rng.zig +25 -16
  26. package/src/lib/gen1/README.md +28 -28
  27. package/src/lib/gen1/calc.zig +9 -9
  28. package/src/lib/gen1/chance.zig +72 -48
  29. package/src/lib/gen1/data/moves.zig +24 -10
  30. package/src/lib/gen1/data/species.zig +3 -3
  31. package/src/lib/gen1/data/types.zig +7 -7
  32. package/src/lib/gen1/data.zig +41 -41
  33. package/src/lib/gen1/helpers.zig +33 -48
  34. package/src/lib/gen1/mechanics.zig +340 -355
  35. package/src/lib/gen2/README.md +18 -72
  36. package/src/lib/gen2/calc.zig +143 -0
  37. package/src/lib/gen2/chance.zig +1314 -0
  38. package/src/lib/gen2/data/items.zig +12 -18
  39. package/src/lib/gen2/data/moves.zig +69 -36
  40. package/src/lib/gen2/data/species.zig +1 -1
  41. package/src/lib/gen2/data/types.zig +134 -31
  42. package/src/lib/gen2/data.zig +52 -44
  43. package/src/lib/gen2/generated.zig +806 -0
  44. package/src/lib/gen2/mechanics.zig +2935 -244
  45. package/src/lib/{binding/node.zig → node.zig} +10 -13
  46. package/src/lib/pkmn.zig +26 -3
  47. package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
@@ -1,4 +1,4 @@
1
- //! Code generated by `tools/generate` - manual edits will be overwritten
1
+ //! Code generated by `tools/generate` - manual edits will be overwritten.
2
2
 
3
3
  const std = @import("std");
4
4
 
@@ -11,15 +11,15 @@ const Type = data.Type;
11
11
  /// Representation of a held item in Generation II Pokémon.
12
12
  pub const Item = enum(u8) {
13
13
  None,
14
+ SoftSand, // Ground
15
+ HardStone, // Rock
16
+ MetalCoat, // Steel
14
17
  PinkBow, // Normal
15
18
  BlackBelt, // Fighting
16
19
  SharpBeak, // Flying
17
20
  PoisonBarb, // Poison
18
- SoftSand, // Ground
19
- HardStone, // Rock
20
21
  SilverPowder, // Bug
21
22
  SpellTag, // Ghost
22
- MetalCoat, // Steel
23
23
  PolkadotBow, // ??? (Normal)
24
24
  Charcoal, // Fire
25
25
  MysticWater, // Water
@@ -36,21 +36,21 @@ pub const Item = enum(u8) {
36
36
  Stick,
37
37
  ThickClub,
38
38
  FocusBand, // FocusBand
39
- BerryJuice, // Berry
40
39
  ScopeLens, // CriticalUp
41
40
  Leftovers, // Leftovers
42
41
  BerserkGene,
43
42
  LightBall,
43
+ Berry, // Berry
44
+ BerryJuice, // Berry
45
+ GoldBerry, // Berry
46
+ MintBerry, // HealSleep
44
47
  PSNCureBerry, // HealPoison
45
48
  PRZCureBerry, // HealParalyze
46
- BurntBerry, // HealFreeze
47
49
  IceBerry, // HealBurn
48
- BitterBerry, // HealConfusion
49
- MintBerry, // HealSleep
50
+ BurntBerry, // HealFreeze
50
51
  MiracleBerry, // HealStatus
52
+ BitterBerry, // HealConfusion
51
53
  MysteryBerry, // RestorePP
52
- Berry, // Berry
53
- GoldBerry, // Berry
54
54
  MasterBall,
55
55
  UltraBall,
56
56
  GreatBall,
@@ -216,20 +216,14 @@ pub const Item = enum(u8) {
216
216
  pub const size = 196;
217
217
 
218
218
  /// Returns a `Type` boosted by this item or `null` if the item is not a type-boosting item.
219
- pub inline fn boost(item: Item) ?Type {
219
+ pub fn boost(item: Item) ?Type {
220
220
  assert(item != .None);
221
221
  if (item == .PolkadotBow) return .Normal;
222
222
  return if (@intFromEnum(item) <= 18) @enumFromInt(@intFromEnum(item) - 1) else null;
223
223
  }
224
224
 
225
- /// Whether or not this item is a Berry.
226
- pub inline fn berry(item: Item) bool {
227
- assert(item != .None);
228
- return @intFromEnum(item) > 30 and @intFromEnum(item) <= 40;
229
- }
230
-
231
225
  /// Whether or not this item is Mail.
232
- pub inline fn mail(item: Item) bool {
226
+ pub fn isMail(item: Item) bool {
233
227
  assert(item != .None);
234
228
  return @intFromEnum(item) > 60 and @intFromEnum(item) <= 70;
235
229
  }
@@ -1,4 +1,4 @@
1
- //! Code generated by `tools/generate` - manual edits will be overwritten
1
+ //! Code generated by `tools/generate` - manual edits will be overwritten.
2
2
 
3
3
  const std = @import("std");
4
4
 
@@ -281,17 +281,23 @@ pub const Move = enum(u8) {
281
281
  chance: u8 = 0,
282
282
  /// The priority of the move.
283
283
  priority: i8 = 0,
284
- /// Miscellaneous flags.
285
- flags: Flags = .{},
284
+ /// Miscellaneous extra data/flags.
285
+ extra: Extra = .{},
286
286
 
287
- /// Miscellaneous move related flags.
288
- const Flags = packed struct(u8) {
287
+ /// Miscellaneous extra move related data/flags.
288
+ const Extra = packed struct(u8) {
289
289
  /// Whether this move can be called via Metronome.
290
290
  metronome: bool = true,
291
+ /// Whether this move can be called via Sleep Talk.
292
+ sleep_talk: bool = true,
291
293
  /// Whether this move is considered to be "continuous".
292
294
  continuous: bool = false,
293
-
294
- _: u6 = 0,
295
+ /// Whether this move can hit a flying target.
296
+ flying: bool = false,
297
+ /// Whether this move can hit an underground target.
298
+ underground: bool = false,
299
+ /// Protocol reason offset associated with this move.
300
+ protocol: u3 = 0,
295
301
  };
296
302
 
297
303
  comptime {
@@ -406,7 +412,7 @@ pub const Move = enum(u8) {
406
412
  .type = .Normal,
407
413
  .accuracy = percent(75),
408
414
  .target = .Foes,
409
- .flags = .{ .continuous = true },
415
+ .extra = .{ .sleep_talk = false, .continuous = true },
410
416
  },
411
417
  // SwordsDance
412
418
  .{
@@ -431,6 +437,7 @@ pub const Move = enum(u8) {
431
437
  .type = .Flying,
432
438
  .accuracy = percent(100),
433
439
  .target = .Any,
440
+ .extra = .{ .flying = true },
434
441
  },
435
442
  // WingAttack
436
443
  .{
@@ -448,15 +455,16 @@ pub const Move = enum(u8) {
448
455
  .accuracy = percent(100),
449
456
  .target = .Other,
450
457
  .priority = -1,
458
+ .extra = .{ .flying = true },
451
459
  },
452
460
  // Fly
453
461
  .{
454
- .effect = .Fly,
462
+ .effect = .FlyDig,
455
463
  .bp = 70,
456
464
  .type = .Flying,
457
465
  .accuracy = percent(95),
458
466
  .target = .Any,
459
- .flags = .{ .continuous = true },
467
+ .extra = .{ .sleep_talk = false, .continuous = true },
460
468
  },
461
469
  // Bind
462
470
  .{
@@ -465,6 +473,7 @@ pub const Move = enum(u8) {
465
473
  .type = .Normal,
466
474
  .accuracy = percent(75),
467
475
  .target = .Other,
476
+ .extra = .{ .protocol = 1 },
468
477
  },
469
478
  // Slam
470
479
  .{
@@ -589,6 +598,7 @@ pub const Move = enum(u8) {
589
598
  .type = .Normal,
590
599
  .accuracy = percent(85),
591
600
  .target = .Other,
601
+ .extra = .{ .protocol = 2 },
592
602
  },
593
603
  // TakeDown
594
604
  .{
@@ -605,7 +615,7 @@ pub const Move = enum(u8) {
605
615
  .type = .Normal,
606
616
  .accuracy = percent(100),
607
617
  .target = .RandomFoe,
608
- .flags = .{ .continuous = true },
618
+ .extra = .{ .continuous = true },
609
619
  },
610
620
  // DoubleEdge
611
621
  .{
@@ -868,7 +878,7 @@ pub const Move = enum(u8) {
868
878
  .accuracy = percent(100),
869
879
  .target = .Depends,
870
880
  .priority = -1,
871
- .flags = .{ .metronome = false },
881
+ .extra = .{ .metronome = false },
872
882
  },
873
883
  // SeismicToss
874
884
  .{
@@ -928,12 +938,12 @@ pub const Move = enum(u8) {
928
938
  },
929
939
  // SolarBeam
930
940
  .{
931
- .effect = .Solarbeam,
941
+ .effect = .SolarBeam,
932
942
  .bp = 120,
933
943
  .type = .Grass,
934
944
  .accuracy = percent(100),
935
945
  .target = .Other,
936
- .flags = .{ .continuous = true },
946
+ .extra = .{ .sleep_talk = false, .continuous = true },
937
947
  },
938
948
  // PoisonPowder
939
949
  .{
@@ -966,7 +976,7 @@ pub const Move = enum(u8) {
966
976
  .type = .Grass,
967
977
  .accuracy = percent(100),
968
978
  .target = .RandomFoe,
969
- .flags = .{ .continuous = true },
979
+ .extra = .{ .continuous = true },
970
980
  },
971
981
  // StringShot
972
982
  .{
@@ -991,6 +1001,7 @@ pub const Move = enum(u8) {
991
1001
  .type = .Fire,
992
1002
  .accuracy = percent(70),
993
1003
  .target = .Other,
1004
+ .extra = .{ .protocol = 3 },
994
1005
  },
995
1006
  // ThunderShock
996
1007
  .{
@@ -1026,6 +1037,7 @@ pub const Move = enum(u8) {
1026
1037
  .accuracy = percent(70),
1027
1038
  .target = .Other,
1028
1039
  .chance = percent(30),
1040
+ .extra = .{ .flying = true },
1029
1041
  },
1030
1042
  // RockThrow
1031
1043
  .{
@@ -1042,6 +1054,7 @@ pub const Move = enum(u8) {
1042
1054
  .type = .Ground,
1043
1055
  .accuracy = percent(100),
1044
1056
  .target = .AllOthers,
1057
+ .extra = .{ .underground = true },
1045
1058
  },
1046
1059
  // Fissure
1047
1060
  .{
@@ -1050,14 +1063,16 @@ pub const Move = enum(u8) {
1050
1063
  .type = .Ground,
1051
1064
  .accuracy = percent(30),
1052
1065
  .target = .Other,
1066
+ .extra = .{ .underground = true },
1053
1067
  },
1054
1068
  // Dig
1055
1069
  .{
1056
- .effect = .Fly,
1070
+ .effect = .FlyDig,
1057
1071
  .bp = 60,
1058
1072
  .type = .Ground,
1059
1073
  .accuracy = percent(100),
1060
1074
  .target = .Other,
1075
+ .extra = .{ .sleep_talk = false },
1061
1076
  },
1062
1077
  // Toxic
1063
1078
  .{
@@ -1149,7 +1164,7 @@ pub const Move = enum(u8) {
1149
1164
  .type = .Normal,
1150
1165
  .accuracy = percent(100),
1151
1166
  .target = .Other,
1152
- .flags = .{ .metronome = false },
1167
+ .extra = .{ .metronome = false },
1153
1168
  },
1154
1169
  // Screech
1155
1170
  .{
@@ -1270,7 +1285,7 @@ pub const Move = enum(u8) {
1270
1285
  .type = .Normal,
1271
1286
  .accuracy = percent(100),
1272
1287
  .target = .Self,
1273
- .flags = .{ .continuous = true },
1288
+ .extra = .{ .sleep_talk = false, .continuous = true },
1274
1289
  },
1275
1290
  // Metronome
1276
1291
  .{
@@ -1279,7 +1294,7 @@ pub const Move = enum(u8) {
1279
1294
  .type = .Normal,
1280
1295
  .accuracy = percent(100),
1281
1296
  .target = .Self,
1282
- .flags = .{ .metronome = false },
1297
+ .extra = .{ .metronome = false },
1283
1298
  },
1284
1299
  // MirrorMove
1285
1300
  .{
@@ -1365,6 +1380,7 @@ pub const Move = enum(u8) {
1365
1380
  .type = .Water,
1366
1381
  .accuracy = percent(75),
1367
1382
  .target = .Other,
1383
+ .extra = .{ .protocol = 4 },
1368
1384
  },
1369
1385
  // Swift
1370
1386
  .{
@@ -1381,7 +1397,7 @@ pub const Move = enum(u8) {
1381
1397
  .type = .Normal,
1382
1398
  .accuracy = percent(100),
1383
1399
  .target = .Other,
1384
- .flags = .{ .continuous = true },
1400
+ .extra = .{ .sleep_talk = false, .continuous = true },
1385
1401
  },
1386
1402
  // SpikeCannon
1387
1403
  .{
@@ -1487,7 +1503,7 @@ pub const Move = enum(u8) {
1487
1503
  .type = .Flying,
1488
1504
  .accuracy = percent(90),
1489
1505
  .target = .Any,
1490
- .flags = .{ .continuous = true },
1506
+ .extra = .{ .sleep_talk = false, .continuous = true },
1491
1507
  },
1492
1508
  // Transform
1493
1509
  .{
@@ -1669,7 +1685,7 @@ pub const Move = enum(u8) {
1669
1685
  .type = .Normal,
1670
1686
  .accuracy = percent(100),
1671
1687
  .target = .RandomFoe,
1672
- .flags = .{ .metronome = false },
1688
+ .extra = .{ .metronome = false },
1673
1689
  },
1674
1690
  // Sketch
1675
1691
  .{
@@ -1678,7 +1694,7 @@ pub const Move = enum(u8) {
1678
1694
  .type = .Normal,
1679
1695
  .accuracy = percent(100),
1680
1696
  .target = .Other,
1681
- .flags = .{ .metronome = false },
1697
+ .extra = .{ .metronome = false },
1682
1698
  },
1683
1699
  // TripleKick
1684
1700
  .{
@@ -1696,7 +1712,7 @@ pub const Move = enum(u8) {
1696
1712
  .accuracy = percent(100),
1697
1713
  .target = .Other,
1698
1714
  .chance = percent(100),
1699
- .flags = .{ .metronome = false },
1715
+ .extra = .{ .metronome = false },
1700
1716
  },
1701
1717
  // SpiderWeb
1702
1718
  .{
@@ -1813,7 +1829,7 @@ pub const Move = enum(u8) {
1813
1829
  .accuracy = percent(100),
1814
1830
  .target = .Self,
1815
1831
  .priority = 2,
1816
- .flags = .{ .metronome = false },
1832
+ .extra = .{ .metronome = false },
1817
1833
  },
1818
1834
  // MachPunch
1819
1835
  .{
@@ -1915,7 +1931,7 @@ pub const Move = enum(u8) {
1915
1931
  .type = .Ghost,
1916
1932
  .accuracy = percent(100),
1917
1933
  .target = .Self,
1918
- .flags = .{ .metronome = false },
1934
+ .extra = .{ .metronome = false },
1919
1935
  },
1920
1936
  // PerishSong
1921
1937
  .{
@@ -1942,7 +1958,7 @@ pub const Move = enum(u8) {
1942
1958
  .accuracy = percent(100),
1943
1959
  .target = .Self,
1944
1960
  .priority = 2,
1945
- .flags = .{ .metronome = false },
1961
+ .extra = .{ .metronome = false },
1946
1962
  },
1947
1963
  // BoneRush
1948
1964
  .{
@@ -1967,7 +1983,7 @@ pub const Move = enum(u8) {
1967
1983
  .type = .Dragon,
1968
1984
  .accuracy = percent(100),
1969
1985
  .target = .RandomFoe,
1970
- .flags = .{ .continuous = true },
1986
+ .extra = .{ .continuous = true },
1971
1987
  },
1972
1988
  // Sandstorm
1973
1989
  .{
@@ -1993,7 +2009,7 @@ pub const Move = enum(u8) {
1993
2009
  .accuracy = percent(100),
1994
2010
  .target = .Self,
1995
2011
  .priority = 2,
1996
- .flags = .{ .metronome = false },
2012
+ .extra = .{ .metronome = false },
1997
2013
  },
1998
2014
  // Charm
1999
2015
  .{
@@ -2010,7 +2026,7 @@ pub const Move = enum(u8) {
2010
2026
  .type = .Rock,
2011
2027
  .accuracy = percent(90),
2012
2028
  .target = .Other,
2013
- .flags = .{ .continuous = true },
2029
+ .extra = .{ .continuous = true },
2014
2030
  },
2015
2031
  // FalseSwipe
2016
2032
  .{
@@ -2085,7 +2101,7 @@ pub const Move = enum(u8) {
2085
2101
  .type = .Normal,
2086
2102
  .accuracy = percent(100),
2087
2103
  .target = .Self,
2088
- .flags = .{ .metronome = false },
2104
+ .extra = .{ .metronome = false },
2089
2105
  },
2090
2106
  // HealBell
2091
2107
  .{
@@ -2151,6 +2167,7 @@ pub const Move = enum(u8) {
2151
2167
  .type = .Ground,
2152
2168
  .accuracy = percent(100),
2153
2169
  .target = .AllOthers,
2170
+ .extra = .{ .underground = true },
2154
2171
  },
2155
2172
  // DynamicPunch
2156
2173
  .{
@@ -2293,6 +2310,7 @@ pub const Move = enum(u8) {
2293
2310
  .accuracy = percent(100),
2294
2311
  .target = .Foes,
2295
2312
  .chance = percent(20),
2313
+ .extra = .{ .flying = true },
2296
2314
  },
2297
2315
  // RainDance
2298
2316
  .{
@@ -2327,7 +2345,7 @@ pub const Move = enum(u8) {
2327
2345
  .accuracy = percent(100),
2328
2346
  .target = .Depends,
2329
2347
  .priority = -1,
2330
- .flags = .{ .metronome = false },
2348
+ .extra = .{ .metronome = false },
2331
2349
  },
2332
2350
  // PsychUp
2333
2351
  .{
@@ -2388,6 +2406,7 @@ pub const Move = enum(u8) {
2388
2406
  .type = .Water,
2389
2407
  .accuracy = percent(70),
2390
2408
  .target = .Other,
2409
+ .extra = .{ .protocol = 5 },
2391
2410
  },
2392
2411
  // BeatUp
2393
2412
  .{
@@ -2447,7 +2466,7 @@ pub const Move = enum(u8) {
2447
2466
  FixedDamage,
2448
2467
  FlameWheel,
2449
2468
  FlinchChance,
2450
- Fly,
2469
+ FlyDig,
2451
2470
  FocusEnergy,
2452
2471
  ForceSwitch,
2453
2472
  Foresight,
@@ -2510,7 +2529,7 @@ pub const Move = enum(u8) {
2510
2529
  Sleep,
2511
2530
  SleepTalk,
2512
2531
  Snore,
2513
- Solarbeam,
2532
+ SolarBeam,
2514
2533
  SpAtkUp1,
2515
2534
  SpDefDownChance,
2516
2535
  SpDefUp2,
@@ -2543,7 +2562,7 @@ pub const Move = enum(u8) {
2543
2562
  }
2544
2563
 
2545
2564
  /// Whether this effect has a high critical rate.
2546
- pub inline fn isHighCritical(effect: Effect) bool {
2565
+ pub fn isHighCritical(effect: Effect) bool {
2547
2566
  return effect == .HighCritical or effect == .RazorWind;
2548
2567
  }
2549
2568
  };
@@ -2831,8 +2850,22 @@ pub const Move = enum(u8) {
2831
2850
  /// The number of Pokémon moves in this generation.
2832
2851
  pub const size = 251;
2833
2852
 
2853
+ /// Pokémon moves that can be called by Metronome in this generation.
2854
+ pub const METRONOME = init: {
2855
+ var num = 0;
2856
+ var moves: [239]Move = undefined;
2857
+ for (1..Move.size + 1) |i| {
2858
+ if (Move.get(@enumFromInt(i)).extra.metronome) {
2859
+ moves[num] = @enumFromInt(i);
2860
+ num += 1;
2861
+ }
2862
+ }
2863
+ assert(num == moves.len);
2864
+ break :init moves;
2865
+ };
2866
+
2834
2867
  /// Returns the `Data` corresponding to the move.
2835
- pub inline fn get(id: Move) Data {
2868
+ pub fn get(id: Move) Data {
2836
2869
  assert(id != .None);
2837
2870
  return DATA[@intFromEnum(id) - 1];
2838
2871
  }
@@ -1,4 +1,4 @@
1
- //! Code generated by `tools/generate` - manual edits will be overwritten
1
+ //! Code generated by `tools/generate` - manual edits will be overwritten.
2
2
 
3
3
  const std = @import("std");
4
4