@pkmn/engine 0.1.0-dev.d56bdadd → 0.1.0-dev.d952b7c9
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 +1 -3
- package/README.md +46 -19
- package/build/pkg/addon/browser.d.ts +3 -0
- package/build/pkg/addon/browser.js +43 -0
- package/build/pkg/addon/browser.js.map +1 -0
- package/build/pkg/addon/node.d.ts +3 -0
- package/build/pkg/addon/node.js +96 -0
- package/build/pkg/addon/node.js.map +1 -0
- package/build/pkg/addon.d.ts +2 -0
- package/build/pkg/addon.js +35 -58
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +27 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +1 -1
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +24 -10
- package/build/pkg/index.js +15 -10
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +20 -1
- package/build/pkg/protocol.js +109 -107
- package/build/pkg/protocol.js.map +1 -1
- package/build/tools/debug.js +36 -68
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/debug.jsx +128 -0
- package/build/tools/display/debug.jsx.map +1 -0
- package/build/tools/display/index.js +132 -0
- package/build/tools/display/index.js.map +1 -0
- package/build/tools/display/ui.jsx +349 -0
- package/build/tools/display/ui.jsx.map +1 -0
- package/build/tools/display/util.js +18 -0
- package/build/tools/display/util.js.map +1 -0
- package/build.zig +206 -81
- package/package.json +51 -30
- package/src/bin/install-pkmn-engine +29 -19
- package/src/bin/pkmn-debug +1 -1
- package/src/lib/common/array.zig +77 -0
- package/src/lib/common/data.zig +4 -4
- package/src/lib/common/debug.zig +11 -6
- package/src/lib/common/js.zig +4 -2
- package/src/lib/common/optional.zig +14 -10
- package/src/lib/common/options.zig +4 -0
- package/src/lib/common/protocol.zig +389 -407
- package/src/lib/common/rational.zig +121 -27
- package/src/lib/common/rng.zig +7 -7
- package/src/lib/common/util.zig +50 -1
- package/src/lib/gen1/calc.zig +657 -133
- package/src/lib/gen1/chance.zig +376 -267
- package/src/lib/gen1/data/species.zig +1 -1
- package/src/lib/gen1/data.zig +17 -16
- package/src/lib/gen1/helpers.zig +95 -538
- package/src/lib/gen1/mechanics.zig +492 -389
- package/src/lib/gen2/calc.zig +34 -16
- package/src/lib/gen2/chance.zig +84 -496
- package/src/lib/gen2/data.zig +8 -7
- package/src/lib/gen2/generated.zig +4 -6
- package/src/lib/gen2/helpers.zig +41 -13
- package/src/lib/gen2/mechanics.zig +448 -377
- package/src/lib/{binding/node.zig → node.zig} +9 -12
- package/src/lib/pkmn.zig +32 -15
- package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
- package/src/tools/display/dom.ts +96 -0
- package/src/tools/display/ui.css +351 -0
- package/build/test/display.js +0 -400
- package/build/test/display.js.map +0 -1
- package/src/lib/gen1/README.md +0 -894
- package/src/lib/gen2/README.md +0 -329
- package/src/test/display/pkmn.html.tmpl +0 -368
|
@@ -1091,7 +1091,7 @@ pub const Species = enum(u8) {
|
|
|
1091
1091
|
/// The number of Pokémon species in this generation.
|
|
1092
1092
|
pub const size = 151;
|
|
1093
1093
|
|
|
1094
|
-
/// The Pokémon's critical hit
|
|
1094
|
+
/// The Pokémon's critical hit ratio out of 256.
|
|
1095
1095
|
pub fn chance(id: Species) u8 {
|
|
1096
1096
|
assert(id != .None);
|
|
1097
1097
|
return CHANCES[@intFromEnum(id) - 1];
|
package/src/lib/gen1/data.zig
CHANGED
|
@@ -22,11 +22,11 @@ const expect = std.testing.expect;
|
|
|
22
22
|
|
|
23
23
|
/// The minimum size in bytes required to hold all Generation I choice options.
|
|
24
24
|
pub const MAX_CHOICES: usize = 9; // move 1..4, switch 2..6
|
|
25
|
-
/// The
|
|
26
|
-
/// At least as large as MAX_CHOICES.
|
|
25
|
+
/// The maximum number of bytes possibly logged by a single Generation I update.
|
|
27
26
|
pub const MAX_LOGS: usize = 180;
|
|
28
27
|
|
|
29
|
-
/// The
|
|
28
|
+
/// The optimal size in bytes required to hold all Generation I choice options.
|
|
29
|
+
/// At least as large as MAX_CHOICES.
|
|
30
30
|
pub const CHOICES_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
31
31
|
MAX_CHOICES
|
|
32
32
|
else
|
|
@@ -47,6 +47,7 @@ const Player = data.Player;
|
|
|
47
47
|
const Result = data.Result;
|
|
48
48
|
|
|
49
49
|
const PointerType = util.PointerType;
|
|
50
|
+
const isPointerTo = util.isPointerTo;
|
|
50
51
|
|
|
51
52
|
const showdown = pkmn.options.showdown;
|
|
52
53
|
|
|
@@ -71,13 +72,13 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
71
72
|
|
|
72
73
|
/// Returns the `Side` for the given `player`.
|
|
73
74
|
pub fn side(self: anytype, player: Player) PointerType(@TypeOf(self), Side) {
|
|
74
|
-
assert(
|
|
75
|
+
assert(isPointerTo(self, Self));
|
|
75
76
|
return &self.sides[@intFromEnum(player)];
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/// Returns the `Side` of the opponent for the given `player`
|
|
79
80
|
pub fn foe(self: anytype, player: Player) PointerType(@TypeOf(self), Side) {
|
|
80
|
-
assert(
|
|
81
|
+
assert(isPointerTo(self, Self));
|
|
81
82
|
return &self.sides[@intFromEnum(player.foe())];
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -91,7 +92,7 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
91
92
|
self: anytype,
|
|
92
93
|
player: Player,
|
|
93
94
|
) PointerType(@TypeOf(self), MoveDetails) {
|
|
94
|
-
assert(
|
|
95
|
+
assert(isPointerTo(self, Self));
|
|
95
96
|
return &self.last_moves[@intFromEnum(player)];
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -112,7 +113,7 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
112
113
|
/// make (i.e. on the cartridge a soft-lock occurs).
|
|
113
114
|
///
|
|
114
115
|
/// This function will always return choices > 0 if `pkmn.options.showdown` is true.
|
|
115
|
-
pub fn choices(self: *Self, player: Player, request: Choice.Type, out: []Choice) u8 {
|
|
116
|
+
pub fn choices(self: *const Self, player: Player, request: Choice.Type, out: []Choice) u8 {
|
|
116
117
|
return mechanics.choices(self, player, request, out);
|
|
117
118
|
}
|
|
118
119
|
};
|
|
@@ -142,7 +143,7 @@ pub const Side = extern struct {
|
|
|
142
143
|
|
|
143
144
|
/// Returns the stored `Pokemon` corresponding to the one-indexed party `slot`.
|
|
144
145
|
pub fn get(self: anytype, slot: u8) PointerType(@TypeOf(self), Pokemon) {
|
|
145
|
-
assert(
|
|
146
|
+
assert(isPointerTo(self, Side));
|
|
146
147
|
assert(slot > 0 and slot <= 6);
|
|
147
148
|
const id = self.order[slot - 1];
|
|
148
149
|
assert(id > 0 and id <= 6);
|
|
@@ -151,7 +152,7 @@ pub const Side = extern struct {
|
|
|
151
152
|
|
|
152
153
|
/// Returns the stored `Pokemon` corresponding to the `active` Pokémon (slot 1).
|
|
153
154
|
pub fn stored(self: anytype) PointerType(@TypeOf(self), Pokemon) {
|
|
154
|
-
assert(
|
|
155
|
+
assert(isPointerTo(self, Side));
|
|
155
156
|
return self.get(1);
|
|
156
157
|
}
|
|
157
158
|
};
|
|
@@ -177,7 +178,7 @@ pub const ActivePokemon = extern struct {
|
|
|
177
178
|
|
|
178
179
|
/// Returns the active Pokémon's current move slot located at the one-indexed `mslot`.
|
|
179
180
|
pub fn move(self: anytype, mslot: u8) PointerType(@TypeOf(self), MoveSlot) {
|
|
180
|
-
assert(
|
|
181
|
+
assert(isPointerTo(self, ActivePokemon));
|
|
181
182
|
assert(mslot > 0 and mslot <= 4);
|
|
182
183
|
assert(self.moves[mslot - 1].id != .None);
|
|
183
184
|
return &self.moves[mslot - 1];
|
|
@@ -207,7 +208,7 @@ pub const Pokemon = extern struct {
|
|
|
207
208
|
|
|
208
209
|
/// Returns the Pokémon's original move slot located at the one-indexed `mslot`.
|
|
209
210
|
pub fn move(self: anytype, mslot: u8) PointerType(@TypeOf(self), MoveSlot) {
|
|
210
|
-
assert(
|
|
211
|
+
assert(isPointerTo(self, Pokemon));
|
|
211
212
|
assert(mslot > 0 and mslot <= 4);
|
|
212
213
|
assert(self.moves[mslot - 1].id != .None);
|
|
213
214
|
return &self.moves[mslot - 1];
|
|
@@ -255,7 +256,7 @@ pub const Status = enum(u8) {
|
|
|
255
256
|
|
|
256
257
|
pub const TOX = 0b10001000;
|
|
257
258
|
|
|
258
|
-
const
|
|
259
|
+
const SLEEP = 0b111;
|
|
259
260
|
|
|
260
261
|
/// Whether or not the status `num` is the same as `status`.
|
|
261
262
|
pub fn is(num: u8, status: Status) bool {
|
|
@@ -283,7 +284,7 @@ pub const Status = enum(u8) {
|
|
|
283
284
|
|
|
284
285
|
/// Returns the duration of a sleep status.
|
|
285
286
|
pub fn duration(num: u8) u3 {
|
|
286
|
-
return @intCast(num &
|
|
287
|
+
return @intCast(num & SLEEP);
|
|
287
288
|
}
|
|
288
289
|
|
|
289
290
|
/// Returns whether `num` reflects any status.
|
|
@@ -409,12 +410,12 @@ test Volatiles {
|
|
|
409
410
|
try expectEqual(@as(u8, 42), volatiles.substitute);
|
|
410
411
|
try expectEqual(@as(u4, 2), volatiles.disable_move);
|
|
411
412
|
try expectEqual(@as(u4, 4), volatiles.disable_duration);
|
|
412
|
-
try expectEqual(@as(
|
|
413
|
+
try expectEqual(@as(u3, 2), volatiles.confusion);
|
|
413
414
|
try expectEqual(@as(u5, 4), volatiles.toxic);
|
|
414
|
-
try expectEqual(@as(
|
|
415
|
+
try expectEqual(@as(u3, 3), volatiles.attacks);
|
|
415
416
|
}
|
|
416
417
|
|
|
417
|
-
///
|
|
418
|
+
/// Representation of a Pokémon's stats in Generation I.
|
|
418
419
|
pub fn Stats(comptime T: type) type {
|
|
419
420
|
return extern struct {
|
|
420
421
|
hp: T = 0,
|