@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
package/src/lib/gen2/calc.zig
CHANGED
|
@@ -5,6 +5,8 @@ const pkmn = @import("../pkmn.zig");
|
|
|
5
5
|
const common = @import("../common/data.zig");
|
|
6
6
|
const util = @import("../common/util.zig");
|
|
7
7
|
|
|
8
|
+
const Optional = @import("../common/optional.zig").Optional;
|
|
9
|
+
|
|
8
10
|
const chance = @import("chance.zig");
|
|
9
11
|
|
|
10
12
|
const assert = std.debug.assert;
|
|
@@ -14,9 +16,15 @@ const enabled = pkmn.options.calc;
|
|
|
14
16
|
const Player = common.Player;
|
|
15
17
|
|
|
16
18
|
const PointerType = util.PointerType;
|
|
19
|
+
const isPointerTo = util.isPointerTo;
|
|
17
20
|
|
|
18
21
|
const Actions = chance.Actions;
|
|
19
22
|
const Action = chance.Action;
|
|
23
|
+
const Criticals = chance.Criticals;
|
|
24
|
+
const Damages = chance.Damages;
|
|
25
|
+
|
|
26
|
+
const Int = if (@hasField(std.builtin.Type, "int")) .int else .Int;
|
|
27
|
+
const Enum = if (@hasField(std.builtin.Type, "enum")) .@"enum" else .Enum;
|
|
20
28
|
|
|
21
29
|
/// Information relevant to damage calculation that occured during a Generation II battle `update`.
|
|
22
30
|
pub const Summaries = extern struct {
|
|
@@ -31,7 +39,7 @@ pub const Summaries = extern struct {
|
|
|
31
39
|
|
|
32
40
|
/// Returns the `Summary` for the given `player`.
|
|
33
41
|
pub fn get(self: anytype, player: Player) PointerType(@TypeOf(self), Summary) {
|
|
34
|
-
assert(
|
|
42
|
+
assert(isPointerTo(self, Summaries));
|
|
35
43
|
return if (player == .P1) &self.p1 else &self.p2;
|
|
36
44
|
}
|
|
37
45
|
};
|
|
@@ -65,33 +73,34 @@ pub const Summary = extern struct {
|
|
|
65
73
|
}
|
|
66
74
|
};
|
|
67
75
|
|
|
68
|
-
/// TODO
|
|
69
|
-
pub const Overrides = extern struct {
|
|
70
|
-
/// TODO
|
|
71
|
-
actions: Actions = .{},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
76
|
/// Allows for forcing the value of specific RNG events during a Generation II battle `update` via
|
|
75
77
|
/// `overrides` and tracks `summaries` of information relevant to damage calculation.
|
|
76
78
|
pub const Calc = struct {
|
|
77
79
|
/// Overrides the normal behavior of the RNG during an `update` to force specific outcomes.
|
|
78
|
-
overrides:
|
|
80
|
+
overrides: Actions = .{},
|
|
79
81
|
/// Information relevant to damage calculation.
|
|
80
82
|
summaries: Summaries = .{},
|
|
81
83
|
|
|
82
84
|
pub fn overridden(
|
|
83
85
|
self: Calc,
|
|
84
86
|
player: Player,
|
|
87
|
+
hit: u3,
|
|
85
88
|
comptime field: Action.Field,
|
|
86
|
-
)
|
|
89
|
+
) ReturnType(field) {
|
|
87
90
|
if (!enabled) return null;
|
|
88
91
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
const val = switch (field) {
|
|
93
|
+
.damages => Damages.get(self.overrides.get(player).damages, hit),
|
|
94
|
+
.critical_hits => Criticals.get(self.overrides.get(player).critical_hits, hit),
|
|
95
|
+
else => val: {
|
|
96
|
+
assert(hit == 0);
|
|
97
|
+
break :val @field(self.overrides.get(player), @tagName(field));
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
92
101
|
return if (switch (@typeInfo(@TypeOf(val))) {
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
Enum => val != .None,
|
|
103
|
+
Int => val != 0,
|
|
95
104
|
else => unreachable,
|
|
96
105
|
}) val else null;
|
|
97
106
|
}
|
|
@@ -123,9 +132,10 @@ const Null = struct {
|
|
|
123
132
|
pub fn overridden(
|
|
124
133
|
self: Null,
|
|
125
134
|
player: Player,
|
|
135
|
+
hit: u3,
|
|
126
136
|
comptime field: Action.Field,
|
|
127
|
-
)
|
|
128
|
-
_ = .{ self, player };
|
|
137
|
+
) ReturnType(field) {
|
|
138
|
+
_ = .{ self, player, hit };
|
|
129
139
|
return null;
|
|
130
140
|
}
|
|
131
141
|
|
|
@@ -141,3 +151,11 @@ const Null = struct {
|
|
|
141
151
|
_ = .{ self, player };
|
|
142
152
|
}
|
|
143
153
|
};
|
|
154
|
+
|
|
155
|
+
fn ReturnType(comptime field: Action.Field) type {
|
|
156
|
+
return ?(switch (field) {
|
|
157
|
+
.damages => u8,
|
|
158
|
+
.critical_hits => Optional(bool),
|
|
159
|
+
else => std.meta.FieldType(Action, field),
|
|
160
|
+
});
|
|
161
|
+
}
|