@pkmn/engine 0.1.0-dev.02b7f810
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/LICENSE +20 -0
- package/README.md +332 -0
- package/build/pkg/addon.d.ts +7 -0
- package/build/pkg/addon.js +111 -0
- package/build/pkg/addon.js.map +1 -0
- package/build/pkg/data/ids.json +240 -0
- package/build/pkg/data/layout.json +86 -0
- package/build/pkg/data/protocol.json +173 -0
- package/build/pkg/data.d.ts +91 -0
- package/build/pkg/data.js +150 -0
- package/build/pkg/data.js.map +1 -0
- package/build/pkg/gen1.d.ts +109 -0
- package/build/pkg/gen1.js +668 -0
- package/build/pkg/gen1.js.map +1 -0
- package/build/pkg/index.d.ts +383 -0
- package/build/pkg/index.js +122 -0
- package/build/pkg/index.js.map +1 -0
- package/build/pkg/protocol.d.ts +71 -0
- package/build/pkg/protocol.js +452 -0
- package/build/pkg/protocol.js.map +1 -0
- package/build/test/display.js +382 -0
- package/build/test/display.js.map +1 -0
- package/build/tools/debug.js +133 -0
- package/build/tools/debug.js.map +1 -0
- package/build.zig +346 -0
- package/package.json +202 -0
- package/src/bin/install-pkmn-engine +391 -0
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +229 -0
- package/src/lib/binding/wasm.zig +10 -0
- package/src/lib/common/data.zig +129 -0
- package/src/lib/common/debug.zig +64 -0
- package/src/lib/common/options.zig +40 -0
- package/src/lib/common/protocol.zig +1297 -0
- package/src/lib/common/rng.zig +234 -0
- package/src/lib/gen1/README.md +791 -0
- package/src/lib/gen1/data/moves.zig +1854 -0
- package/src/lib/gen1/data/species.zig +1105 -0
- package/src/lib/gen1/data/types.zig +131 -0
- package/src/lib/gen1/data.zig +620 -0
- package/src/lib/gen1/helpers.zig +234 -0
- package/src/lib/gen1/mechanics.zig +2819 -0
- package/src/lib/gen2/README.md +309 -0
- package/src/lib/gen2/data/items.zig +236 -0
- package/src/lib/gen2/data/moves.zig +2784 -0
- package/src/lib/gen2/data/species.zig +1798 -0
- package/src/lib/gen2/data/types.zig +123 -0
- package/src/lib/gen2/data.zig +425 -0
- package/src/lib/gen2/helpers.zig +225 -0
- package/src/lib/gen2/mechanics.zig +53 -0
- package/src/lib/pkmn.zig +54 -0
- 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 inline fn special(self: Type) bool {
|
|
94
|
+
return @enumToInt(self) >= @enumToInt(Type.Fire);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// The `Effectiveness` of type `t2` vs. type `t1`.
|
|
98
|
+
pub inline fn effectiveness(t1: Type, t2: Type) Effectiveness {
|
|
99
|
+
return CHART[@enumToInt(t1)][@enumToInt(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(u8, 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 inline 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 inline fn includes(self: Types, t: Type) bool {
|
|
129
|
+
return self.type1 == t or self.type2 == t;
|
|
130
|
+
}
|
|
131
|
+
};
|