@pkmn/engine 0.1.0-dev.fb5bf955 → 0.1.0-dev.fc150752
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 +71 -60
- package/build/pkg/addon.d.ts +2 -2
- package/build/pkg/addon.js +8 -7
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/layout.json +25 -3
- package/build/pkg/gen1.d.ts +5 -4
- package/build/pkg/gen1.js +47 -31
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +15 -12
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +4 -2
- package/build/pkg/protocol.js +4 -2
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +31 -13
- package/build/test/display.js.map +1 -1
- package/build.zig +95 -76
- package/package.json +26 -16
- package/src/bin/install-pkmn-engine +11 -6
- package/src/bin/pkmn-debug +29 -6
- package/src/lib/binding/node.zig +46 -141
- package/src/lib/binding/wasm.zig +6 -4
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +14 -26
- package/src/lib/common/debug.zig +21 -11
- package/src/lib/common/js.zig +118 -0
- package/src/lib/common/optional.zig +60 -0
- package/src/lib/common/options.zig +12 -3
- package/src/lib/common/protocol.zig +315 -197
- package/src/lib/common/rational.zig +353 -0
- package/src/lib/common/rng.zig +11 -11
- package/src/lib/common/util.zig +12 -0
- package/src/lib/gen1/README.md +265 -155
- package/src/lib/gen1/calc.zig +426 -0
- package/src/lib/gen1/chance.zig +1036 -0
- package/src/lib/gen1/data/moves.zig +178 -180
- package/src/lib/gen1/data/species.zig +2 -2
- package/src/lib/gen1/data/types.zig +3 -3
- package/src/lib/gen1/data.zig +73 -59
- package/src/lib/gen1/helpers.zig +592 -32
- package/src/lib/gen1/mechanics.zig +994 -641
- package/src/lib/gen2/README.md +87 -13
- package/src/lib/gen2/data/items.zig +3 -3
- package/src/lib/gen2/data/moves.zig +635 -563
- package/src/lib/gen2/data/species.zig +1 -1
- package/src/lib/gen2/data/types.zig +3 -3
- package/src/lib/gen2/data.zig +104 -74
- package/src/lib/gen2/helpers.zig +16 -22
- package/src/lib/gen2/mechanics.zig +916 -11
- package/src/lib/pkmn.zig +68 -9
package/src/lib/gen2/README.md
CHANGED
|
@@ -54,13 +54,12 @@ The following information is required to simulate a Generation II Pokémon battl
|
|
|
54
54
|
| | | |
|
|
55
55
|
| `active.last_used_move` | `PlayerUsedMove` | `side.lastMove` |
|
|
56
56
|
|
|
57
|
-
- Pokémon Showdown
|
|
57
|
+
- Pokémon Showdown doesn't implement the correct Generation II RNG and as such its `seed` is
|
|
58
58
|
different
|
|
59
|
-
- `battle.turn` only needs to be tracked
|
|
60
|
-
protocol
|
|
59
|
+
- `battle.turn` only needs to be tracked to be compatible with the Pokémon Showdown protocol
|
|
61
60
|
- Battle results (win, lose, draw) or request states are communicated via the return code of
|
|
62
61
|
`Battle.update`
|
|
63
|
-
- Nicknames (`BattleMonNick`/`pokemon.name`)
|
|
62
|
+
- Nicknames (`BattleMonNick`/`pokemon.name`) aren't handled by the pkmn engine as they're expected
|
|
64
63
|
to be handled by driver code if required
|
|
65
64
|
|
|
66
65
|
==**TODO**==
|
|
@@ -77,9 +76,9 @@ between the data structure for the "active" Pokémon and its party members (see
|
|
|
77
76
|
|
|
78
77
|
### `Pokemon` / `ActivePokemon`
|
|
79
78
|
|
|
80
|
-
Similar to the cartridge,
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
Similar to the cartridge, to save space different information is stored depending on whether a
|
|
80
|
+
[Pokémon](https://pkmn.cc/bulba/Pok%c3%a9mon_data_structure_%28Generation_II%29) is actively
|
|
81
|
+
participating in battle vs. is switched out (pret's [`battle_struct` vs.
|
|
83
82
|
`party_struct`](https://pkmn.cc/pokecrystal/macros/ram.asm)). In Pokémon Showdown, all the Pokemon
|
|
84
83
|
are represented by the same
|
|
85
84
|
[`Pokemon`](https://github.com/smogon/pokemon-showdown/blob/master/sim/pokemon.ts) class, and static
|
|
@@ -93,14 +92,14 @@ A `MoveSlot` is a data-type for a `(move, current pp)` pair. A pared down versio
|
|
|
93
92
|
Showdown's `Pokemon#moveSlot`, it also stores data from the cartridge's `battle_struct::Move` macro
|
|
94
93
|
and can be used to replace the `PlayerMove*` data. Move PP is stored as a full byte instead of how
|
|
95
94
|
the cartridge (`battle_struct::PP`) stores it (6 bits for current PP and the remaining 2 bits used
|
|
96
|
-
to store the number of applied PP Ups). PP Up bits
|
|
95
|
+
to store the number of applied PP Ups). PP Up bits don't actually need to be stored on move slot
|
|
97
96
|
as max PP is never relevant in Generation II (the Mystery Berry always increases PP from 0 -> 5).
|
|
98
97
|
|
|
99
98
|
#### `Status`
|
|
100
99
|
|
|
101
100
|
Bitfield representation of a Pokémon's major [status
|
|
102
|
-
condition](https://pkmn.cc/bulba/Status_condition), mirroring how it
|
|
103
|
-
value of `0x00` means that the Pokémon
|
|
101
|
+
condition](https://pkmn.cc/bulba/Status_condition), mirroring how it's stored on the cartridge. A
|
|
102
|
+
value of `0x00` means that the Pokémon isn't affected by any major status, otherwise the lower 3
|
|
104
103
|
bits represent the remaining duration for Sleep. Other status are denoted by the presence of
|
|
105
104
|
individual bits - at most one status should be set at any given time.
|
|
106
105
|
|
|
@@ -161,7 +160,7 @@ boosts should always range from `-6`...`6` instead of `1`...`13` as on the cartr
|
|
|
161
160
|
|
|
162
161
|
`Moves` serves as an identifier for a unique [Pokémon move](https://pkmn.cc/bulba/Move) that can be
|
|
163
162
|
used to retrieve a `Move` with information regarding base power, accuracy and type. As covered
|
|
164
|
-
|
|
163
|
+
earlier, PP information isn't strictly necessary in Generation I, but fits neatly into the 4 bits of
|
|
165
164
|
padding after noticing that all PP values are multiples of 5. `Moves.None` exists as a special
|
|
166
165
|
sentinel value to indicate `null`.
|
|
167
166
|
|
|
@@ -215,11 +214,86 @@ entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory))) is as foll
|
|
|
215
214
|
| **wrap** | 0...5 | 3 | | **perish song** | 0...4 | 3 |
|
|
216
215
|
| **item** | TODO | 5? | | **gender** | 0..1 | 1 |
|
|
217
216
|
|
|
218
|
-
From this
|
|
219
|
-
much overhead the representations
|
|
217
|
+
From this one can determine the minimum bits required to store each data structure to determine how
|
|
218
|
+
much overhead the preceding representations have after taking into consideration [alignment &
|
|
220
219
|
padding](https://en.wikipedia.org/wiki/Data_structure_alignment) and
|
|
221
220
|
[denormalization](https://en.wikipedia.org/wiki/Denormalization):
|
|
222
221
|
|
|
222
|
+
## Details
|
|
223
|
+
|
|
224
|
+
| pkmn | Pokémon Crystal (pret) |
|
|
225
|
+
| ------------------------- | ------------------------------------------------- |
|
|
226
|
+
| `start` | `DoBattle` |
|
|
227
|
+
| `update` | `BattleTurn` |
|
|
228
|
+
| `selectMove` / `saveMove` | `CheckPlayerLockedIn` / `ParsePlayerAction` |
|
|
229
|
+
| `switchIn` | `SwitchPlayerMon` / `SendOutPlayerMon` |
|
|
230
|
+
| `turnOrder` | `DetermineMoveOrder` |
|
|
231
|
+
| `doTurn` | `DoTurn` |
|
|
232
|
+
| `executeMove` | `DoMove` |
|
|
233
|
+
| `beforeMove` | `CheckTurn` |
|
|
234
|
+
| `canMove` | |
|
|
235
|
+
| `decrementPP` | |
|
|
236
|
+
| `doMove` | |
|
|
237
|
+
| `checkCriticalHit` | `BattleCommand_Critical` |
|
|
238
|
+
| `calcDamage` | `BattleCommand_DamageCalc` / `PlayerAttackDamage` |
|
|
239
|
+
| `adjustDamage` | `BattleCommand_Stab` |
|
|
240
|
+
| `randomizeDamage` | `BattleCommand_DamageVariation` |
|
|
241
|
+
| `specialDamage` | `BattleCommand_ConstantDamage` |
|
|
242
|
+
| `applyDamage` | `BattleCommand_ApplyDamage` |
|
|
243
|
+
| `checkHit` | `BattleCommand_CheckHit` |
|
|
244
|
+
| `checkFaint` | `CheckFaint` |
|
|
245
|
+
| `handleResidual` | `ResidualDamage` |
|
|
246
|
+
| `endTurn` | `EndTurn` |
|
|
247
|
+
|
|
248
|
+
DoBattle
|
|
249
|
+
BattleTurn
|
|
250
|
+
- HandleBerserkGene
|
|
251
|
+
- CheckPlayerLockedIn
|
|
252
|
+
- BattleMenu
|
|
253
|
+
- ParsePlayerAction
|
|
254
|
+
- DetermineMoveOrder
|
|
255
|
+
- CompareMovePriority
|
|
256
|
+
- GetMovePriority
|
|
257
|
+
- Battle_*
|
|
258
|
+
- Handle*Switch
|
|
259
|
+
- SwitchPlayerMon
|
|
260
|
+
- BreakAttraction
|
|
261
|
+
- SendOutPlayerMon
|
|
262
|
+
- SpikesDamage
|
|
263
|
+
- *Turn_EndOpponentProtectEndureDestinyBond
|
|
264
|
+
- EndUserDestinyBond
|
|
265
|
+
- Do*Turn
|
|
266
|
+
- EndOpponentProtectEndureDestinyBond
|
|
267
|
+
- ResidualDamage
|
|
268
|
+
- CheckFaint_*
|
|
269
|
+
- HandleBetweenTurnEffects
|
|
270
|
+
- HandleFutureSight
|
|
271
|
+
- HandleWeather
|
|
272
|
+
- HandleWrap
|
|
273
|
+
- HandlePerishSong
|
|
274
|
+
- HandleLeftovers
|
|
275
|
+
- HandleMysteryBerry
|
|
276
|
+
- HandleDefrost
|
|
277
|
+
- HandleSafeguard
|
|
278
|
+
- HandleScreens
|
|
279
|
+
- HandleStatBoostingHeldItems
|
|
280
|
+
- HandleHealingItems
|
|
281
|
+
- HandleEncore
|
|
282
|
+
|
|
283
|
+
DoTurn
|
|
284
|
+
DoMove = executeMove
|
|
285
|
+
CheckTurn = beforeMove
|
|
286
|
+
BattleCommand_Critical = checkCriticalHit
|
|
287
|
+
BattleCommand_Stab = adjustDamage
|
|
288
|
+
BattleCommand_DamageVariation = randomizeDamage
|
|
289
|
+
BattleCommand_CheckHit = checkHit
|
|
290
|
+
BattleCommand_ApplyDamage = applyDamage
|
|
291
|
+
BattleCommand_CheckFaint
|
|
292
|
+
BattleCommand_BuildOpponentRage = buildRage
|
|
293
|
+
BattleCommand_DamageCalc (PlayerAttackDamage / EnemyAttackDamage) = calcDamage
|
|
294
|
+
BattleCommand_ConstantDamage = specialDamage
|
|
295
|
+
DoEnemyDamage / DoPlayerDamage / DoSubstituteDamage
|
|
296
|
+
|
|
223
297
|
==**TODO**==
|
|
224
298
|
|
|
225
299
|
## Protocol
|
|
@@ -219,18 +219,18 @@ pub const Item = enum(u8) {
|
|
|
219
219
|
pub inline fn boost(item: Item) ?Type {
|
|
220
220
|
assert(item != .None);
|
|
221
221
|
if (item == .PolkadotBow) return .Normal;
|
|
222
|
-
return if (@
|
|
222
|
+
return if (@intFromEnum(item) <= 18) @enumFromInt(@intFromEnum(item) - 1) else null;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
/// Whether or not this item is a Berry.
|
|
226
226
|
pub inline fn berry(item: Item) bool {
|
|
227
227
|
assert(item != .None);
|
|
228
|
-
return @
|
|
228
|
+
return @intFromEnum(item) > 30 and @intFromEnum(item) <= 40;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
/// Whether or not this item is Mail.
|
|
232
232
|
pub inline fn mail(item: Item) bool {
|
|
233
233
|
assert(item != .None);
|
|
234
|
-
return @
|
|
234
|
+
return @intFromEnum(item) > 60 and @intFromEnum(item) <= 70;
|
|
235
235
|
}
|
|
236
236
|
};
|