@pkmn/engine 0.1.0-dev.028ab165

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 (62) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +343 -0
  3. package/build/pkg/addon.d.ts +7 -0
  4. package/build/pkg/addon.js +112 -0
  5. package/build/pkg/addon.js.map +1 -0
  6. package/build/pkg/data/ids.json +240 -0
  7. package/build/pkg/data/layout.json +108 -0
  8. package/build/pkg/data/protocol.json +230 -0
  9. package/build/pkg/data.d.ts +91 -0
  10. package/build/pkg/data.js +150 -0
  11. package/build/pkg/data.js.map +1 -0
  12. package/build/pkg/gen1.d.ts +110 -0
  13. package/build/pkg/gen1.js +684 -0
  14. package/build/pkg/gen1.js.map +1 -0
  15. package/build/pkg/index.d.ts +386 -0
  16. package/build/pkg/index.js +122 -0
  17. package/build/pkg/index.js.map +1 -0
  18. package/build/pkg/protocol.d.ts +73 -0
  19. package/build/pkg/protocol.js +473 -0
  20. package/build/pkg/protocol.js.map +1 -0
  21. package/build/test/display.js +400 -0
  22. package/build/test/display.js.map +1 -0
  23. package/build/tools/debug.js +135 -0
  24. package/build/tools/debug.js.map +1 -0
  25. package/build.zig +371 -0
  26. package/package.json +224 -0
  27. package/src/bin/install-pkmn-engine +396 -0
  28. package/src/bin/pkmn-debug +62 -0
  29. package/src/lib/binding/node.zig +134 -0
  30. package/src/lib/binding/wasm.zig +12 -0
  31. package/src/lib/common/battle.zig +17 -0
  32. package/src/lib/common/data.zig +117 -0
  33. package/src/lib/common/debug.zig +74 -0
  34. package/src/lib/common/js.zig +118 -0
  35. package/src/lib/common/optional.zig +67 -0
  36. package/src/lib/common/options.zig +49 -0
  37. package/src/lib/common/protocol.zig +1841 -0
  38. package/src/lib/common/rational.zig +353 -0
  39. package/src/lib/common/rng.zig +243 -0
  40. package/src/lib/common/util.zig +12 -0
  41. package/src/lib/gen1/README.md +894 -0
  42. package/src/lib/gen1/calc.zig +426 -0
  43. package/src/lib/gen1/chance.zig +1060 -0
  44. package/src/lib/gen1/data/moves.zig +1866 -0
  45. package/src/lib/gen1/data/species.zig +1105 -0
  46. package/src/lib/gen1/data/types.zig +131 -0
  47. package/src/lib/gen1/data.zig +634 -0
  48. package/src/lib/gen1/helpers.zig +779 -0
  49. package/src/lib/gen1/mechanics.zig +3128 -0
  50. package/src/lib/gen2/README.md +329 -0
  51. package/src/lib/gen2/calc.zig +143 -0
  52. package/src/lib/gen2/chance.zig +1314 -0
  53. package/src/lib/gen2/data/items.zig +230 -0
  54. package/src/lib/gen2/data/moves.zig +2878 -0
  55. package/src/lib/gen2/data/species.zig +1798 -0
  56. package/src/lib/gen2/data/types.zig +226 -0
  57. package/src/lib/gen2/data.zig +463 -0
  58. package/src/lib/gen2/generated.zig +808 -0
  59. package/src/lib/gen2/helpers.zig +219 -0
  60. package/src/lib/gen2/mechanics.zig +3551 -0
  61. package/src/lib/pkmn.zig +113 -0
  62. package/src/test/display/pkmn.html.tmpl +368 -0
@@ -0,0 +1,131 @@
1
+ //! Code generated by `tools/generate` - manual edits will be overwritten.
2
+
3
+ const std = @import("std");
4
+
5
+ const gen1 = @import("../../gen1/data.zig");
6
+
7
+ const assert = std.debug.assert;
8
+ const Effectiveness = gen1.Effectiveness;
9
+
10
+ const S = Effectiveness.Super;
11
+ const N = Effectiveness.Neutral;
12
+ const R = Effectiveness.Resisted;
13
+ const I = Effectiveness.Immune;
14
+
15
+ /// Representation of a Generation I type in Pokémon.
16
+ pub const Type = enum(u4) {
17
+ Normal,
18
+ Fighting,
19
+ Flying,
20
+ Poison,
21
+ Ground,
22
+ Rock,
23
+ Bug,
24
+ Ghost,
25
+ Fire,
26
+ Water,
27
+ Grass,
28
+ Electric,
29
+ Psychic,
30
+ Ice,
31
+ Dragon,
32
+
33
+ const CHART: [15][15]Effectiveness = .{
34
+ [_]Effectiveness{ N, N, N, N, N, R, N, I, N, N, N, N, N, N, N }, // Normal
35
+ [_]Effectiveness{ S, N, R, R, N, S, R, I, N, N, N, N, R, S, N }, // Fighting
36
+ [_]Effectiveness{ N, S, N, N, N, R, S, N, N, N, S, R, N, N, N }, // Flying
37
+ [_]Effectiveness{ N, N, N, R, R, R, S, R, N, N, S, N, N, N, N }, // Poison
38
+ [_]Effectiveness{ N, N, I, S, N, S, R, N, S, N, R, S, N, N, N }, // Ground
39
+ [_]Effectiveness{ N, R, S, N, R, N, S, N, S, N, N, N, N, S, N }, // Rock
40
+ [_]Effectiveness{ N, R, R, S, N, N, N, R, R, N, S, N, S, N, N }, // Bug
41
+ [_]Effectiveness{ I, N, N, N, N, N, N, S, N, N, N, N, I, N, N }, // Ghost
42
+ [_]Effectiveness{ N, N, N, N, N, R, S, N, R, R, S, N, N, S, R }, // Fire
43
+ [_]Effectiveness{ N, N, N, N, S, S, N, N, S, R, R, N, N, N, R }, // Water
44
+ [_]Effectiveness{ N, N, R, R, S, S, R, N, R, S, R, N, N, N, R }, // Grass
45
+ [_]Effectiveness{ N, N, S, N, I, N, N, N, N, S, R, R, N, N, R }, // Electric
46
+ [_]Effectiveness{ N, S, N, S, N, N, N, N, N, N, N, N, R, N, N }, // Psychic
47
+ [_]Effectiveness{ N, N, S, N, S, N, N, N, N, R, S, N, N, R, S }, // Ice
48
+ [_]Effectiveness{ N, N, N, N, N, N, N, N, N, N, N, N, N, N, S }, // Dragon
49
+ };
50
+
51
+ const PRECEDENCE = [_]Types{
52
+ .{ .type1 = .Fire, .type2 = .Ice },
53
+ .{ .type1 = .Grass, .type2 = .Water },
54
+ .{ .type1 = .Water, .type2 = .Rock },
55
+ .{ .type1 = .Water, .type2 = .Water },
56
+ .{ .type1 = .Electric, .type2 = .Electric },
57
+ .{ .type1 = .Ice, .type2 = .Ice },
58
+ .{ .type1 = .Fire, .type2 = .Water },
59
+ .{ .type1 = .Electric, .type2 = .Flying },
60
+ .{ .type1 = .Grass, .type2 = .Ground },
61
+ .{ .type1 = .Grass, .type2 = .Poison },
62
+ .{ .type1 = .Grass, .type2 = .Rock },
63
+ .{ .type1 = .Grass, .type2 = .Flying },
64
+ .{ .type1 = .Ice, .type2 = .Water },
65
+ .{ .type1 = .Ice, .type2 = .Flying },
66
+ .{ .type1 = .Fighting, .type2 = .Normal },
67
+ .{ .type1 = .Fighting, .type2 = .Flying },
68
+ .{ .type1 = .Fighting, .type2 = .Psychic },
69
+ .{ .type1 = .Fighting, .type2 = .Rock },
70
+ .{ .type1 = .Fighting, .type2 = .Ice },
71
+ .{ .type1 = .Poison, .type2 = .Grass },
72
+ .{ .type1 = .Poison, .type2 = .Poison },
73
+ .{ .type1 = .Poison, .type2 = .Bug },
74
+ .{ .type1 = .Ground, .type2 = .Grass },
75
+ .{ .type1 = .Ground, .type2 = .Bug },
76
+ .{ .type1 = .Ground, .type2 = .Poison },
77
+ .{ .type1 = .Bug, .type2 = .Flying },
78
+ .{ .type1 = .Bug, .type2 = .Ghost },
79
+ .{ .type1 = .Bug, .type2 = .Poison },
80
+ .{ .type1 = .Electric, .type2 = .Dragon },
81
+ };
82
+
83
+ comptime {
84
+ assert(@bitSizeOf(Type) == 4);
85
+ assert(@sizeOf(@TypeOf(CHART)) == 225);
86
+ assert(@sizeOf(@TypeOf(PRECEDENCE)) == 29);
87
+ }
88
+
89
+ /// The number of types in this generation.
90
+ pub const size = 15;
91
+
92
+ /// Whether or not this type is considered to be special as opposed to physical.
93
+ pub fn special(self: Type) bool {
94
+ return @intFromEnum(self) >= @intFromEnum(Type.Fire);
95
+ }
96
+
97
+ /// The `Effectiveness` of type `t2` vs. type `t1`.
98
+ pub fn effectiveness(t1: Type, t2: Type) Effectiveness {
99
+ return CHART[@intFromEnum(t1)][@intFromEnum(t2)];
100
+ }
101
+
102
+ /// The precedence order of Type `t2` vs. Type `t1`.
103
+ pub fn precedence(t1: Type, t2: Type) u8 {
104
+ for (PRECEDENCE, 0..) |matchup, i| {
105
+ if (matchup.type1 == t1 and matchup.type2 == t2) return @intCast(i);
106
+ }
107
+ unreachable;
108
+ }
109
+ };
110
+
111
+ /// Representation of a Pokémon's typing.
112
+ pub const Types = packed struct {
113
+ /// A Pokémon's primary type.
114
+ type1: Type = .Normal,
115
+ /// A Pokémon's secondary type (may be identical to its primary type).
116
+ type2: Type = .Normal,
117
+
118
+ comptime {
119
+ assert(@sizeOf(Types) == 1);
120
+ }
121
+
122
+ /// Whether this typing is immune to type `t`.
123
+ pub fn immune(self: Types, t: Type) bool {
124
+ return t.effectiveness(self.type1) == I or t.effectiveness(self.type2) == I;
125
+ }
126
+
127
+ /// Whether this typing includes type `t`.
128
+ pub fn includes(self: Types, t: Type) bool {
129
+ return self.type1 == t or self.type2 == t;
130
+ }
131
+ };