@pkmn/engine 0.1.0-dev.eaae4aa6 → 0.1.0-dev.f34af416
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 +0 -2
- package/README.md +15 -11
- package/build/pkg/addon.js +6 -7
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +2 -3
- package/build/pkg/index.d.ts +1 -1
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.js +4 -4
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +8 -3
- package/build/test/display.js.map +1 -1
- package/build/tools/debug.js +2 -3
- package/build/tools/debug.js.map +1 -1
- package/build.zig +189 -72
- package/package.json +17 -16
- package/src/bin/install-pkmn-engine +17 -7
- package/src/lib/common/data.zig +8 -8
- package/src/lib/common/debug.zig +2 -2
- package/src/lib/common/js.zig +4 -2
- package/src/lib/common/optional.zig +13 -9
- package/src/lib/common/options.zig +2 -0
- package/src/lib/common/protocol.zig +51 -44
- package/src/lib/common/rational.zig +114 -24
- package/src/lib/common/rng.zig +10 -10
- package/src/lib/common/util.zig +50 -1
- package/src/lib/gen1/calc.zig +508 -128
- package/src/lib/gen1/chance.zig +383 -276
- package/src/lib/gen1/data/species.zig +1 -1
- package/src/lib/gen1/data.zig +29 -28
- package/src/lib/gen1/helpers.zig +96 -536
- package/src/lib/gen1/mechanics.zig +266 -160
- package/src/lib/gen2/calc.zig +34 -16
- package/src/lib/gen2/chance.zig +91 -500
- package/src/lib/gen2/data.zig +15 -14
- package/src/lib/gen2/helpers.zig +41 -9
- package/src/lib/gen2/mechanics.zig +158 -97
- package/src/lib/pkmn.zig +10 -16
- package/src/test/display/pkmn.html.tmpl +5 -5
- package/src/lib/gen1/README.md +0 -894
- package/src/lib/gen2/README.md +0 -329
|
@@ -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
|
|
|
@@ -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];
|
|
@@ -316,12 +317,12 @@ test Status {
|
|
|
316
317
|
try expect(Status.is(Status.slp(5), .SLP));
|
|
317
318
|
try expect(!Status.is(Status.slp(5), .EXT));
|
|
318
319
|
try expect(!Status.is(Status.slp(7), .PSN));
|
|
319
|
-
try expectEqual(5, Status.duration(Status.slp(5)));
|
|
320
|
+
try expectEqual(@as(u3, 5), Status.duration(Status.slp(5)));
|
|
320
321
|
try expect(Status.is(Status.slf(2), .SLP));
|
|
321
322
|
try expect(Status.is(Status.slf(2), .EXT));
|
|
322
323
|
try expect(Status.is(Status.TOX, .PSN));
|
|
323
324
|
try expect(Status.is(Status.TOX, .EXT));
|
|
324
|
-
try expectEqual(1, Status.duration(Status.slp(1)));
|
|
325
|
+
try expectEqual(@as(u3, 1), Status.duration(Status.slp(1)));
|
|
325
326
|
}
|
|
326
327
|
|
|
327
328
|
/// Bitfield representation of volatile statuses and associated data in Generation I.
|
|
@@ -405,16 +406,16 @@ test Volatiles {
|
|
|
405
406
|
try expect(!volatiles.Transform);
|
|
406
407
|
try expect(!volatiles.MultiHit);
|
|
407
408
|
|
|
408
|
-
try expectEqual(235, volatiles.state);
|
|
409
|
-
try expectEqual(42, volatiles.substitute);
|
|
410
|
-
try expectEqual(2, volatiles.disable_move);
|
|
411
|
-
try expectEqual(4, volatiles.disable_duration);
|
|
412
|
-
try expectEqual(2, volatiles.confusion);
|
|
413
|
-
try expectEqual(4, volatiles.toxic);
|
|
414
|
-
try expectEqual(3, volatiles.attacks);
|
|
409
|
+
try expectEqual(@as(u16, 235), volatiles.state);
|
|
410
|
+
try expectEqual(@as(u8, 42), volatiles.substitute);
|
|
411
|
+
try expectEqual(@as(u4, 2), volatiles.disable_move);
|
|
412
|
+
try expectEqual(@as(u4, 4), volatiles.disable_duration);
|
|
413
|
+
try expectEqual(@as(u3, 2), volatiles.confusion);
|
|
414
|
+
try expectEqual(@as(u5, 4), volatiles.toxic);
|
|
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,
|
|
@@ -442,9 +443,9 @@ test Stats {
|
|
|
442
443
|
try expectEqual(0, stats.def);
|
|
443
444
|
|
|
444
445
|
var base = Species.get(.Gyarados).stats;
|
|
445
|
-
try expectEqual(127, Stats(u16).calc("hp", base.hp, 0, 5120, 38));
|
|
446
|
+
try expectEqual(@as(u16, 127), Stats(u16).calc("hp", base.hp, 0, 5120, 38));
|
|
446
447
|
base = Species.get(.Pidgeot).stats;
|
|
447
|
-
try expectEqual(279, Stats(u16).calc("spe", base.spe, 15, 63001, 100));
|
|
448
|
+
try expectEqual(@as(u16, 279), Stats(u16).calc("spe", base.spe, 15, 63001, 100));
|
|
448
449
|
}
|
|
449
450
|
|
|
450
451
|
/// Representation of a Pokémon's boosts in Generation I.
|
|
@@ -537,7 +538,7 @@ pub const Species = species.Species;
|
|
|
537
538
|
|
|
538
539
|
test Species {
|
|
539
540
|
try expectEqual(2, @intFromEnum(Species.Ivysaur));
|
|
540
|
-
try expectEqual(100, Species.get(.Mew).stats.def);
|
|
541
|
+
try expectEqual(@as(u8, 100), Species.get(.Mew).stats.def);
|
|
541
542
|
}
|
|
542
543
|
|
|
543
544
|
/// Representation of a Generation I type in Pokémon.
|
|
@@ -576,8 +577,8 @@ test Types {
|
|
|
576
577
|
try expectEqual(Effectiveness.Resisted, Type.effectiveness(.Fire, .Water));
|
|
577
578
|
try expectEqual(Effectiveness.Neutral, Type.effectiveness(.Normal, .Grass));
|
|
578
579
|
|
|
579
|
-
try expectEqual(3, Type.precedence(.Water, .Water));
|
|
580
|
-
try expectEqual(26, Type.precedence(.Bug, .Ghost));
|
|
580
|
+
try expectEqual(@as(u8, 3), Type.precedence(.Water, .Water));
|
|
581
|
+
try expectEqual(@as(u8, 26), Type.precedence(.Bug, .Ghost));
|
|
581
582
|
try expect(Type.precedence(.Poison, .Bug) > Type.precedence(.Poison, .Poison));
|
|
582
583
|
|
|
583
584
|
const t: Types = .{ .type1 = .Rock, .type2 = .Ground };
|
|
@@ -617,18 +618,18 @@ pub const DVs = struct {
|
|
|
617
618
|
|
|
618
619
|
test DVs {
|
|
619
620
|
var dvs: DVs = .{ .spc = 15, .spe = 15 };
|
|
620
|
-
try expectEqual(15, dvs.hp());
|
|
621
|
+
try expectEqual(@as(u4, 15), dvs.hp());
|
|
621
622
|
dvs = .{
|
|
622
623
|
.atk = 5,
|
|
623
624
|
.def = 15,
|
|
624
625
|
.spe = 13,
|
|
625
626
|
.spc = 13,
|
|
626
627
|
};
|
|
627
|
-
try expectEqual(15, dvs.hp());
|
|
628
|
+
try expectEqual(@as(u4, 15), dvs.hp());
|
|
628
629
|
dvs = .{
|
|
629
630
|
.def = 3,
|
|
630
631
|
.spe = 10,
|
|
631
632
|
.spc = 11,
|
|
632
633
|
};
|
|
633
|
-
try expectEqual(13, dvs.hp());
|
|
634
|
+
try expectEqual(@as(u4, 13), dvs.hp());
|
|
634
635
|
}
|