@pkmn/engine 0.1.0-dev.a0447192 → 0.1.0-dev.a23f64f3
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/README.md +5 -4
- package/build/pkg/addon/browser.d.ts +1 -1
- package/build/pkg/addon/browser.js +2 -1
- package/build/pkg/addon/browser.js.map +1 -1
- package/build/pkg/addon/node.js +2 -1
- package/build/pkg/addon/node.js.map +1 -1
- package/build/pkg/addon/wasm.d.ts +2 -0
- package/build/pkg/addon/wasm.js +44 -0
- package/build/pkg/addon/wasm.js.map +1 -0
- package/build/pkg/addon.d.ts +23 -3
- package/build/pkg/addon.js +8 -17
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/layout.json +15 -2
- package/build/pkg/data/protocol.json +23 -9
- package/build/pkg/gen1.d.ts +13 -17
- package/build/pkg/gen1.js +6 -10
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +35 -100
- package/build/pkg/index.js +6 -68
- package/build/pkg/index.js.map +1 -1
- package/build/tools/debug.js +1 -2
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/index.js +17 -8
- package/build/tools/display/index.js.map +1 -1
- package/build/tools/display/ui.jsx.map +1 -1
- package/build.zig +112 -68
- package/package.json +20 -121
- package/src/bin/install-pkmn-engine +2 -2
- package/src/lib/common/options.zig +2 -0
- package/src/lib/common/protocol.zig +4 -8
- package/src/lib/common/rng.zig +1 -3
- package/src/lib/gen1/calc.zig +22 -48
- package/src/lib/gen1/chance.zig +34 -18
- package/src/lib/gen1/data/moves.zig +2 -4
- package/src/lib/gen1/data/species.zig +1 -3
- package/src/lib/gen1/data/types.zig +1 -2
- package/src/lib/gen1/data.zig +7 -11
- package/src/lib/gen1/helpers.zig +4 -10
- package/src/lib/gen1/mechanics.zig +65 -42
- package/src/lib/gen2/calc.zig +9 -17
- package/src/lib/gen2/data/items.zig +1 -3
- package/src/lib/gen2/data/moves.zig +2 -4
- package/src/lib/gen2/data/species.zig +1 -3
- package/src/lib/gen2/data/types.zig +1 -2
- package/src/lib/gen2/data.zig +11 -15
- package/src/lib/gen2/generated.zig +18 -23
- package/src/lib/gen2/helpers.zig +5 -12
- package/src/lib/gen2/mechanics.zig +41 -38
- package/src/lib/node.zig +2 -4
- package/src/lib/pkmn.zig +4 -0
- package/src/lib/wasm.zig +36 -1
- package/src/tools/display/ui.css +0 -5
|
@@ -1,44 +1,37 @@
|
|
|
1
|
-
const std = @import("std");
|
|
2
|
-
|
|
3
|
-
const pkmn = @import("../pkmn.zig");
|
|
4
|
-
|
|
5
|
-
const common = @import("../common/data.zig");
|
|
6
1
|
const DEBUG = @import("../common/debug.zig").print;
|
|
7
|
-
const protocol = @import("../common/protocol.zig");
|
|
8
|
-
const rng = @import("../common/rng.zig");
|
|
9
2
|
|
|
3
|
+
const builtin = @import("builtin");
|
|
4
|
+
const common = @import("../common/data.zig");
|
|
10
5
|
const data = @import("data.zig");
|
|
11
6
|
const generated = @import("generated.zig");
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const expectEqualSlices = std.testing.expectEqualSlices;
|
|
17
|
-
const expectEqualStrings = std.testing.expectEqualStrings;
|
|
18
|
-
|
|
19
|
-
const showdown = pkmn.options.showdown;
|
|
20
|
-
|
|
21
|
-
const Choice = common.Choice;
|
|
22
|
-
const ID = common.ID;
|
|
23
|
-
const Player = common.Player;
|
|
24
|
-
const Result = common.Result;
|
|
7
|
+
const pkmn = @import("../pkmn.zig");
|
|
8
|
+
const protocol = @import("../common/protocol.zig");
|
|
9
|
+
const rng = @import("../common/rng.zig");
|
|
10
|
+
const std = @import("std");
|
|
25
11
|
|
|
26
12
|
const Activate = protocol.Activate;
|
|
13
|
+
const ActivePokemon = data.ActivePokemon;
|
|
14
|
+
const assert = std.debug.assert;
|
|
27
15
|
const Boost = protocol.Boost;
|
|
16
|
+
const Boosts = data.Boosts;
|
|
17
|
+
const Choice = common.Choice;
|
|
28
18
|
const Damage = protocol.Damage;
|
|
19
|
+
const Effectiveness = data.Effectiveness;
|
|
29
20
|
const End = protocol.End;
|
|
21
|
+
const expectEqual = std.testing.expectEqual;
|
|
22
|
+
const expectEqualSlices = std.testing.expectEqualSlices;
|
|
23
|
+
const expectEqualStrings = std.testing.expectEqualStrings;
|
|
30
24
|
const Fail = protocol.Fail;
|
|
31
|
-
const Heal = protocol.Heal;
|
|
32
|
-
const Start = protocol.Start;
|
|
33
|
-
|
|
34
25
|
const Gen12 = rng.Gen12;
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const Boosts = data.Boosts;
|
|
38
|
-
const Effectiveness = data.Effectiveness;
|
|
26
|
+
const Heal = protocol.Heal;
|
|
27
|
+
const ID = common.ID;
|
|
39
28
|
const Item = data.Item;
|
|
40
29
|
const Move = data.Move;
|
|
30
|
+
const Player = common.Player;
|
|
31
|
+
const Result = common.Result;
|
|
32
|
+
const showdown = pkmn.options.showdown;
|
|
41
33
|
const Side = data.Side;
|
|
34
|
+
const Start = protocol.Start;
|
|
42
35
|
const Stats = data.Stats;
|
|
43
36
|
const Status = data.Status;
|
|
44
37
|
const TriAttack = data.TriAttack;
|
|
@@ -1200,7 +1193,7 @@ fn updateSideCondition(
|
|
|
1200
1193
|
fn endTurn(battle: anytype, options: anytype) @TypeOf(options.log).Error!Result {
|
|
1201
1194
|
battle.turn += 1;
|
|
1202
1195
|
|
|
1203
|
-
if (
|
|
1196
|
+
if (pkmn.options.mod and battle.turn >= 1000) {
|
|
1204
1197
|
try options.log.tie(.{});
|
|
1205
1198
|
return Result.Tie;
|
|
1206
1199
|
} else if (battle.turn >= 65535) {
|
|
@@ -1434,7 +1427,8 @@ pub const Effects = struct {
|
|
|
1434
1427
|
if (move.type.special() != (last == .MirrorCoat)) return;
|
|
1435
1428
|
if (state.damage == 0) return;
|
|
1436
1429
|
|
|
1437
|
-
|
|
1430
|
+
// NOTE: llvm/llvm-project#58557
|
|
1431
|
+
state.damage = smul(state.damage, 2);
|
|
1438
1432
|
state.miss = false;
|
|
1439
1433
|
}
|
|
1440
1434
|
|
|
@@ -1529,15 +1523,18 @@ pub const Effects = struct {
|
|
|
1529
1523
|
|
|
1530
1524
|
pub const double = struct {
|
|
1531
1525
|
pub fn flying(battle: anytype, player: Player, state: *State, _: anytype) !void {
|
|
1532
|
-
if (battle.foe(player).active.volatiles.Flying)
|
|
1526
|
+
if (!battle.foe(player).active.volatiles.Flying) return;
|
|
1527
|
+
state.damage = smul(state.damage, 2);
|
|
1533
1528
|
}
|
|
1534
1529
|
|
|
1535
1530
|
pub fn underground(battle: anytype, player: Player, state: *State, _: anytype) !void {
|
|
1536
|
-
if (battle.foe(player).active.volatiles.Underground)
|
|
1531
|
+
if (!battle.foe(player).active.volatiles.Underground) return;
|
|
1532
|
+
state.damage = smul(state.damage, 2);
|
|
1537
1533
|
}
|
|
1538
1534
|
|
|
1539
1535
|
pub fn minimize(battle: anytype, player: Player, state: *State, _: anytype) !void {
|
|
1540
|
-
if (battle.foe(player).active.volatiles.minimized)
|
|
1536
|
+
if (!battle.foe(player).active.volatiles.minimized) return;
|
|
1537
|
+
state.damage = smul(state.damage, 2);
|
|
1541
1538
|
}
|
|
1542
1539
|
};
|
|
1543
1540
|
|
|
@@ -1706,7 +1703,7 @@ pub const Effects = struct {
|
|
|
1706
1703
|
if (!state.proc) return;
|
|
1707
1704
|
if (foe.conditions.Safeguard) return;
|
|
1708
1705
|
// Freeze Clause Mod
|
|
1709
|
-
if (
|
|
1706
|
+
if (pkmn.options.mod) for (foe.pokemon) |p| if (Status.is(p.status, .FRZ)) return;
|
|
1710
1707
|
|
|
1711
1708
|
foe_stored.status = Status.init(.FRZ);
|
|
1712
1709
|
try options.log.status(.{ foe_ident, foe_stored.status, .None });
|
|
@@ -1735,7 +1732,7 @@ pub const Effects = struct {
|
|
|
1735
1732
|
state.bp *= 2;
|
|
1736
1733
|
assert(state.bp <= 160);
|
|
1737
1734
|
} else {
|
|
1738
|
-
state.damage
|
|
1735
|
+
state.damage = smul(state.damage, 2);
|
|
1739
1736
|
}
|
|
1740
1737
|
}
|
|
1741
1738
|
|
|
@@ -2206,7 +2203,7 @@ pub const Effects = struct {
|
|
|
2206
2203
|
|
|
2207
2204
|
pub fn pursuit(battle: anytype, player: Player, state: *State, _: anytype) !void {
|
|
2208
2205
|
// TODO: remove switching variable and just look at Choice saved in Battle struct?
|
|
2209
|
-
if (battle.foe(player).active.volatiles.switching) state.damage
|
|
2206
|
+
if (battle.foe(player).active.volatiles.switching) state.damage = smul(state.damage, 2);
|
|
2210
2207
|
}
|
|
2211
2208
|
|
|
2212
2209
|
pub const rage = struct {
|
|
@@ -2219,7 +2216,7 @@ pub const Effects = struct {
|
|
|
2219
2216
|
const side = battle.side(player);
|
|
2220
2217
|
|
|
2221
2218
|
assert(side.active.volatiles.Rage);
|
|
2222
|
-
state.damage
|
|
2219
|
+
state.damage = smul(state.damage, (side.active.volatiles.rage +| 1)); // TODO: |+
|
|
2223
2220
|
}
|
|
2224
2221
|
};
|
|
2225
2222
|
|
|
@@ -2314,7 +2311,7 @@ pub const Effects = struct {
|
|
|
2314
2311
|
side.active.volatiles.attacks += 1;
|
|
2315
2312
|
side.active.volatiles.Rollout = side.active.volatiles.attacks != 5;
|
|
2316
2313
|
|
|
2317
|
-
if (side.active.volatiles.DefenseCurl) state.damage
|
|
2314
|
+
if (side.active.volatiles.DefenseCurl) state.damage = smul(state.damage, 2);
|
|
2318
2315
|
}
|
|
2319
2316
|
};
|
|
2320
2317
|
|
|
@@ -2384,7 +2381,7 @@ pub const Effects = struct {
|
|
|
2384
2381
|
}
|
|
2385
2382
|
|
|
2386
2383
|
// Sleep Clause Mod
|
|
2387
|
-
if (
|
|
2384
|
+
if (pkmn.options.mod) {
|
|
2388
2385
|
for (foe.pokemon) |p| {
|
|
2389
2386
|
if (Status.is(p.status, .SLP) and !Status.is(p.status, .EXT)) return;
|
|
2390
2387
|
}
|
|
@@ -2842,6 +2839,12 @@ fn convertible(active: ActivePokemon, m: Move) bool {
|
|
|
2842
2839
|
return t != .@"???" and !active.types.includes(t);
|
|
2843
2840
|
}
|
|
2844
2841
|
|
|
2842
|
+
// NOTE: llvm/llvm-project#58557
|
|
2843
|
+
fn smul(a: anytype, b: @TypeOf(a)) @TypeOf(a) {
|
|
2844
|
+
if (!comptime builtin.target.isWasm()) return a *| b;
|
|
2845
|
+
return @max(a *% b, std.math.maxInt(@TypeOf(a)));
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2845
2848
|
pub const Rolls = struct {
|
|
2846
2849
|
fn speedTie(battle: anytype, options: anytype) !bool {
|
|
2847
2850
|
const p1 = if (options.calc.overridden(.P1, 0, .speed_tie)) |player|
|
package/src/lib/node.zig
CHANGED
package/src/lib/pkmn.zig
CHANGED
|
@@ -96,6 +96,10 @@ pub const gen1 = struct {
|
|
|
96
96
|
/// though damage calculator support should additionally be turned off
|
|
97
97
|
/// entirely via `options.calc`.
|
|
98
98
|
pub const NULL = @import("gen1/calc.zig").NULL;
|
|
99
|
+
/// TODO
|
|
100
|
+
pub const MAX_FRONTIER = @import("gen1/calc.zig").MAX_FRONTIER;
|
|
101
|
+
/// TODO
|
|
102
|
+
pub const Rolls = @import("gen1/calc.zig").Rolls;
|
|
99
103
|
};
|
|
100
104
|
/// Provides helpers for initializing Generation I Pokémon battles.
|
|
101
105
|
pub const helpers = @import("gen1/helpers.zig");
|
package/src/lib/wasm.zig
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
const pkmn = @import("pkmn.zig");
|
|
1
2
|
const std = @import("std");
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
+
const assert = std.debug.assert;
|
|
5
|
+
|
|
6
|
+
const Enum = if (@hasField(std.builtin.Type, "enum")) .@"enum" else .Enum;
|
|
4
7
|
|
|
5
8
|
export const SHOWDOWN = pkmn.options.showdown;
|
|
6
9
|
export const LOG = pkmn.options.log;
|
|
@@ -11,3 +14,35 @@ export const GEN1_CHOICES_SIZE =
|
|
|
11
14
|
std.math.ceilPowerOfTwo(u32, @as(u32, @intCast(pkmn.gen1.CHOICES_SIZE))) catch unreachable;
|
|
12
15
|
export const GEN1_LOGS_SIZE =
|
|
13
16
|
std.math.ceilPowerOfTwo(u32, @as(u32, @intCast(pkmn.gen1.LOGS_SIZE))) catch unreachable;
|
|
17
|
+
|
|
18
|
+
export fn GEN1_update(
|
|
19
|
+
battle: *pkmn.gen1.Battle(pkmn.gen1.PRNG),
|
|
20
|
+
c1: pkmn.Choice,
|
|
21
|
+
c2: pkmn.Choice,
|
|
22
|
+
options: ?[*]u8,
|
|
23
|
+
) pkmn.Result {
|
|
24
|
+
return (if (options) |o| result: {
|
|
25
|
+
const buf = @as([*]u8, @ptrCast(o))[0..pkmn.gen1.LOGS_SIZE];
|
|
26
|
+
var stream: pkmn.protocol.ByteStream = .{ .buffer = buf };
|
|
27
|
+
// TODO: extract out
|
|
28
|
+
var opts = pkmn.battle.options(
|
|
29
|
+
pkmn.protocol.FixedLog{ .writer = stream.writer() },
|
|
30
|
+
pkmn.gen1.chance.NULL,
|
|
31
|
+
pkmn.gen1.calc.NULL,
|
|
32
|
+
);
|
|
33
|
+
break :result battle.update(c1, c2, &opts);
|
|
34
|
+
} else battle.update(c1, c2, &pkmn.gen1.NULL)) catch unreachable;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export fn GEN1_choices(
|
|
38
|
+
battle: *pkmn.gen1.Battle(pkmn.gen1.PRNG),
|
|
39
|
+
player: u8,
|
|
40
|
+
request: u8,
|
|
41
|
+
buf: [*]u8,
|
|
42
|
+
) u8 {
|
|
43
|
+
assert(player <= @field(@typeInfo(pkmn.Player), @tagName(Enum)).fields.len);
|
|
44
|
+
assert(request <= @field(@typeInfo(pkmn.Choice.Type), @tagName(Enum)).fields.len);
|
|
45
|
+
|
|
46
|
+
const len = GEN1_CHOICES_SIZE;
|
|
47
|
+
return battle.choices(@enumFromInt(player), @enumFromInt(request), @ptrCast(buf[0..len]));
|
|
48
|
+
}
|