@pkmn/engine 0.1.0-dev.d97c6e03 → 0.1.0-dev.dc33f678
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 +67 -56
- package/build/pkg/addon.d.ts +1 -1
- package/build/pkg/addon.js +7 -6
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +27 -5
- package/build/pkg/data/protocol.json +69 -12
- package/build/pkg/data.d.ts +2 -2
- package/build/pkg/gen1.d.ts +5 -4
- package/build/pkg/gen1.js +48 -32
- 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 +60 -39
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +29 -12
- package/build/test/display.js.map +1 -1
- package/build.zig +92 -68
- package/package.json +40 -21
- package/src/bin/install-pkmn-engine +11 -6
- package/src/lib/binding/node.zig +46 -141
- package/src/lib/binding/wasm.zig +5 -3
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +15 -27
- package/src/lib/common/debug.zig +21 -11
- package/src/lib/common/js.zig +118 -0
- package/src/lib/common/optional.zig +67 -0
- package/src/lib/common/options.zig +12 -3
- package/src/lib/common/protocol.zig +771 -245
- package/src/lib/common/rational.zig +353 -0
- package/src/lib/common/rng.zig +15 -15
- package/src/lib/common/util.zig +12 -0
- package/src/lib/gen1/README.md +285 -182
- package/src/lib/gen1/calc.zig +426 -0
- package/src/lib/gen1/chance.zig +1060 -0
- package/src/lib/gen1/data/moves.zig +192 -180
- package/src/lib/gen1/data/species.zig +2 -2
- package/src/lib/gen1/data/types.zig +5 -5
- package/src/lib/gen1/data.zig +79 -65
- package/src/lib/gen1/helpers.zig +577 -32
- package/src/lib/gen1/mechanics.zig +940 -614
- package/src/lib/gen2/README.md +106 -85
- package/src/lib/gen2/data/items.zig +12 -18
- package/src/lib/gen2/data/moves.zig +660 -566
- package/src/lib/gen2/data/species.zig +1 -1
- package/src/lib/gen2/data/types.zig +131 -28
- package/src/lib/gen2/data.zig +132 -84
- package/src/lib/gen2/helpers.zig +16 -22
- package/src/lib/gen2/mechanics.zig +2426 -12
- package/src/lib/pkmn.zig +65 -6
package/src/lib/gen2/README.md
CHANGED
|
@@ -32,35 +32,36 @@ The following information is required to simulate a Generation II Pokémon battl
|
|
|
32
32
|
| `pokemon.species` | `party_struct.Species` | `pokemon.baseSpecies` |
|
|
33
33
|
| `active.species` | `battle_struct.Species` | `pokemon.species` |
|
|
34
34
|
| `active.stats` | `TODO modified` | `pokemon.storedStats` |
|
|
35
|
-
| `active.trapped FIXME` | `PlayerTrappingMove` | `pokemon.trapped` |
|
|
36
|
-
| `active.switching` | `PlayerIsSwitching` | `pokemon.switchFlag` |
|
|
37
35
|
| `active.boosts` | `PlayerStatLevels` | `pokemon.boosts` |
|
|
38
36
|
| `active.volatiles` | `PlayerBattleStatus{1,2,3}` | `pokemon.volatiles` |
|
|
39
|
-
| `volatiles.
|
|
40
|
-
| `volatiles.
|
|
41
|
-
| `volatiles.
|
|
42
|
-
| `volatiles.
|
|
43
|
-
| `volatiles.
|
|
44
|
-
| `volatiles.
|
|
45
|
-
| `volatiles.
|
|
46
|
-
| `volatiles.
|
|
47
|
-
| `volatiles.
|
|
48
|
-
| `volatiles.
|
|
49
|
-
| `volatiles.
|
|
50
|
-
| `volatiles.
|
|
51
|
-
| `volatiles.
|
|
37
|
+
| `volatiles.bide` | `PlayerDamageTaken` | `volatiles.bide.totalDamage` |
|
|
38
|
+
| `volatiles.substitute` | `PlayerSubstituteHP` | `volatiles.substitute.hp` |
|
|
39
|
+
| `volatiles.rollout` | `PlayerRolloutCount` | `volatiles.rollout.hitCount` |
|
|
40
|
+
| `volatiles.confusion` | `PlayerConfuseCount` | `volatiles.confusion.duration` |
|
|
41
|
+
| `volatiles.toxic` | `PlayerToxicCount` | `volatiles.residualdmg.counter` |
|
|
42
|
+
| `volatiles.disable` | `PlayerDisableCount` | `moveSlots.disabled` |
|
|
43
|
+
| `volatiles.encore` | `PlayerEncoreCount` | `volatiles.encore.duration` |
|
|
44
|
+
| `volatiles.perish_song` | `PlayerPerishCount` | `volatiles.perishsong.duration` |
|
|
45
|
+
| `volatiles.fury_cutter` | `PlayerFuryCutterCount` | `volatiles.furycutter.multiplier` |
|
|
46
|
+
| `volatiles.protect` | `PlayerProtectCount` | `volatiles.stall.counter` |
|
|
47
|
+
| `volatiles.future_sight` | `PlayerFutureSight{Damage,Count}` | `slotConditions[i].futuremove` |
|
|
48
|
+
| `volatiles.rage` | `PlayerRageCounter` | **BUG** |
|
|
49
|
+
| `volatiles.bind` | `PlayerWrapCount` | `volatiles.partiallytrapped.duration` |
|
|
50
|
+
| `volatiles.bind_reason` | `PlayerTrappingMove` | `volatiles.effectState.sourceEffect` |
|
|
52
51
|
| | `PlayerCharging` | |
|
|
53
|
-
|
|
|
52
|
+
| `volatiles.trapped FIXME` | `FIXME` | `pokemon.trapped` |
|
|
53
|
+
| `volatiles.switched` | `TODO` | `pokemon.switchFlag` |
|
|
54
|
+
| `volatiles.switching` | `PlayerIsSwitching` | `pokemon.switchFlag` |
|
|
55
|
+
| `volatiles.frozen` | `PlayerJustGotFrozen` | `volatiles.frozen` |
|
|
54
56
|
| | | |
|
|
55
57
|
| `active.last_used_move` | `PlayerUsedMove` | `side.lastMove` |
|
|
56
58
|
|
|
57
|
-
- Pokémon Showdown
|
|
59
|
+
- Pokémon Showdown doesn't implement the correct Generation II RNG and as such its `seed` is
|
|
58
60
|
different
|
|
59
|
-
- `battle.turn` only needs to be tracked
|
|
60
|
-
protocol
|
|
61
|
+
- `battle.turn` only needs to be tracked to be compatible with the Pokémon Showdown protocol
|
|
61
62
|
- Battle results (win, lose, draw) or request states are communicated via the return code of
|
|
62
63
|
`Battle.update`
|
|
63
|
-
- Nicknames (`BattleMonNick`/`pokemon.name`)
|
|
64
|
+
- Nicknames (`BattleMonNick`/`pokemon.name`) aren't handled by the pkmn engine as they're expected
|
|
64
65
|
to be handled by driver code if required
|
|
65
66
|
|
|
66
67
|
==**TODO**==
|
|
@@ -77,9 +78,9 @@ between the data structure for the "active" Pokémon and its party members (see
|
|
|
77
78
|
|
|
78
79
|
### `Pokemon` / `ActivePokemon`
|
|
79
80
|
|
|
80
|
-
Similar to the cartridge,
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
Similar to the cartridge, to save space different information is stored depending on whether a
|
|
82
|
+
[Pokémon](https://pkmn.cc/bulba/Pok%c3%a9mon_data_structure_%28Generation_II%29) is actively
|
|
83
|
+
participating in battle vs. is switched out (pret's [`battle_struct` vs.
|
|
83
84
|
`party_struct`](https://pkmn.cc/pokecrystal/macros/ram.asm)). In Pokémon Showdown, all the Pokemon
|
|
84
85
|
are represented by the same
|
|
85
86
|
[`Pokemon`](https://github.com/smogon/pokemon-showdown/blob/master/sim/pokemon.ts) class, and static
|
|
@@ -93,14 +94,14 @@ A `MoveSlot` is a data-type for a `(move, current pp)` pair. A pared down versio
|
|
|
93
94
|
Showdown's `Pokemon#moveSlot`, it also stores data from the cartridge's `battle_struct::Move` macro
|
|
94
95
|
and can be used to replace the `PlayerMove*` data. Move PP is stored as a full byte instead of how
|
|
95
96
|
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
|
|
97
|
+
to store the number of applied PP Ups). PP Up bits don't actually need to be stored on move slot
|
|
97
98
|
as max PP is never relevant in Generation II (the Mystery Berry always increases PP from 0 -> 5).
|
|
98
99
|
|
|
99
100
|
#### `Status`
|
|
100
101
|
|
|
101
102
|
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
|
|
103
|
+
condition](https://pkmn.cc/bulba/Status_condition), mirroring how it's stored on the cartridge. A
|
|
104
|
+
value of `0x00` means that the Pokémon isn't affected by any major status, otherwise the lower 3
|
|
104
105
|
bits represent the remaining duration for Sleep. Other status are denoted by the presence of
|
|
105
106
|
individual bits - at most one status should be set at any given time.
|
|
106
107
|
|
|
@@ -161,7 +162,7 @@ boosts should always range from `-6`...`6` instead of `1`...`13` as on the cartr
|
|
|
161
162
|
|
|
162
163
|
`Moves` serves as an identifier for a unique [Pokémon move](https://pkmn.cc/bulba/Move) that can be
|
|
163
164
|
used to retrieve a `Move` with information regarding base power, accuracy and type. As covered
|
|
164
|
-
|
|
165
|
+
earlier, PP information isn't strictly necessary in Generation I, but fits neatly into the 4 bits of
|
|
165
166
|
padding after noticing that all PP values are multiples of 5. `Moves.None` exists as a special
|
|
166
167
|
sentinel value to indicate `null`.
|
|
167
168
|
|
|
@@ -215,11 +216,86 @@ entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory))) is as foll
|
|
|
215
216
|
| **wrap** | 0...5 | 3 | | **perish song** | 0...4 | 3 |
|
|
216
217
|
| **item** | TODO | 5? | | **gender** | 0..1 | 1 |
|
|
217
218
|
|
|
218
|
-
From this
|
|
219
|
-
much overhead the representations
|
|
219
|
+
From this one can determine the minimum bits required to store each data structure to determine how
|
|
220
|
+
much overhead the preceding representations have after taking into consideration [alignment &
|
|
220
221
|
padding](https://en.wikipedia.org/wiki/Data_structure_alignment) and
|
|
221
222
|
[denormalization](https://en.wikipedia.org/wiki/Denormalization):
|
|
222
223
|
|
|
224
|
+
## Details
|
|
225
|
+
|
|
226
|
+
| pkmn | Pokémon Crystal (pret) |
|
|
227
|
+
| ------------------------- | ------------------------------------------------- |
|
|
228
|
+
| `start` | `DoBattle` |
|
|
229
|
+
| `update` | `BattleTurn` |
|
|
230
|
+
| `selectMove` / `saveMove` | `CheckPlayerLockedIn` / `ParsePlayerAction` |
|
|
231
|
+
| `switchIn` | `SwitchPlayerMon` / `SendOutPlayerMon` |
|
|
232
|
+
| `turnOrder` | `DetermineMoveOrder` |
|
|
233
|
+
| `doTurn` | `DoTurn` |
|
|
234
|
+
| `executeMove` | `DoMove` |
|
|
235
|
+
| `beforeMove` | `CheckTurn` |
|
|
236
|
+
| `canMove` | |
|
|
237
|
+
| `decrementPP` | |
|
|
238
|
+
| `doMove` | |
|
|
239
|
+
| `checkCriticalHit` | `BattleCommand_Critical` |
|
|
240
|
+
| `calcDamage` | `BattleCommand_DamageCalc` / `PlayerAttackDamage` |
|
|
241
|
+
| `adjustDamage` | `BattleCommand_Stab` |
|
|
242
|
+
| `randomizeDamage` | `BattleCommand_DamageVariation` |
|
|
243
|
+
| `specialDamage` | `BattleCommand_ConstantDamage` |
|
|
244
|
+
| `applyDamage` | `BattleCommand_ApplyDamage` |
|
|
245
|
+
| `checkHit` | `BattleCommand_CheckHit` |
|
|
246
|
+
| `checkFaint` | `CheckFaint` |
|
|
247
|
+
| `handleResidual` | `ResidualDamage` |
|
|
248
|
+
| `endTurn` | `EndTurn` |
|
|
249
|
+
|
|
250
|
+
DoBattle
|
|
251
|
+
BattleTurn
|
|
252
|
+
- HandleBerserkGene
|
|
253
|
+
- CheckPlayerLockedIn
|
|
254
|
+
- BattleMenu
|
|
255
|
+
- ParsePlayerAction
|
|
256
|
+
- DetermineMoveOrder
|
|
257
|
+
- CompareMovePriority
|
|
258
|
+
- GetMovePriority
|
|
259
|
+
- Battle_*
|
|
260
|
+
- Handle*Switch
|
|
261
|
+
- SwitchPlayerMon
|
|
262
|
+
- BreakAttraction
|
|
263
|
+
- SendOutPlayerMon
|
|
264
|
+
- SpikesDamage
|
|
265
|
+
- *Turn_EndOpponentProtectEndureDestinyBond
|
|
266
|
+
- EndUserDestinyBond
|
|
267
|
+
- Do*Turn
|
|
268
|
+
- EndOpponentProtectEndureDestinyBond
|
|
269
|
+
- ResidualDamage
|
|
270
|
+
- CheckFaint_*
|
|
271
|
+
- HandleBetweenTurnEffects
|
|
272
|
+
- HandleFutureSight
|
|
273
|
+
- HandleWeather
|
|
274
|
+
- HandleWrap
|
|
275
|
+
- HandlePerishSong
|
|
276
|
+
- HandleLeftovers
|
|
277
|
+
- HandleMysteryBerry
|
|
278
|
+
- HandleDefrost
|
|
279
|
+
- HandleSafeguard
|
|
280
|
+
- HandleScreens
|
|
281
|
+
- HandleStatBoostingHeldItems
|
|
282
|
+
- HandleHealingItems
|
|
283
|
+
- HandleEncore
|
|
284
|
+
|
|
285
|
+
DoTurn
|
|
286
|
+
DoMove = executeMove
|
|
287
|
+
CheckTurn = beforeMove
|
|
288
|
+
BattleCommand_Critical = checkCriticalHit
|
|
289
|
+
BattleCommand_Stab = adjustDamage
|
|
290
|
+
BattleCommand_DamageVariation = randomizeDamage
|
|
291
|
+
BattleCommand_CheckHit = checkHit
|
|
292
|
+
BattleCommand_ApplyDamage = applyDamage
|
|
293
|
+
BattleCommand_CheckFaint
|
|
294
|
+
BattleCommand_BuildOpponentRage = buildRage
|
|
295
|
+
BattleCommand_DamageCalc (PlayerAttackDamage / EnemyAttackDamage) = calcDamage
|
|
296
|
+
BattleCommand_ConstantDamage = specialDamage
|
|
297
|
+
DoEnemyDamage / DoPlayerDamage / DoSubstituteDamage
|
|
298
|
+
|
|
223
299
|
==**TODO**==
|
|
224
300
|
|
|
225
301
|
## Protocol
|
|
@@ -227,62 +303,7 @@ padding](https://en.wikipedia.org/wiki/Data_structure_alignment) and
|
|
|
227
303
|
TODO
|
|
228
304
|
|
|
229
305
|
```txt
|
|
230
|
-
-activate: _,
|
|
231
|
-
-anim: _
|
|
232
|
-
-block: _
|
|
233
|
-
-boost: _, from, silent
|
|
234
|
-
-clearallboost: _
|
|
235
|
-
-copyboost: from
|
|
236
|
-
-crit: _
|
|
237
|
-
-curestatus: msg
|
|
238
|
-
-cureteam: from
|
|
239
|
-
-damage: _, from, of, partiallytrapped
|
|
240
|
-
-end: _, from, of, partiallytrapped, silent
|
|
241
|
-
-enditem: _, eat
|
|
242
|
-
-fail: _, block, weak
|
|
243
|
-
-fieldactivate: _
|
|
244
|
-
-heal: _, from, of, silent
|
|
245
|
-
-hint: _
|
|
246
|
-
-hitcount: _
|
|
247
|
-
-immune: _, ohko
|
|
248
|
-
-item: from, of
|
|
249
|
-
-miss: _
|
|
250
|
-
-mustrecharge: _
|
|
251
|
-
-ohko: _
|
|
252
|
-
-prepare: _
|
|
253
|
-
-resisted: _
|
|
254
|
-
-setboost: from
|
|
255
|
-
-sethp: from, silent
|
|
256
|
-
-sideend: _, from, of
|
|
257
|
-
-sidestart: _
|
|
258
|
-
-singlemove: _
|
|
259
|
-
-singleturn: _
|
|
260
|
-
-start: _, of, silent
|
|
261
|
-
-status: _, from, silent
|
|
262
|
-
-supereffective: _
|
|
263
|
-
-transform: _
|
|
264
|
-
-unboost: _
|
|
265
|
-
-weather: _, upkeep
|
|
266
|
-
cant: _
|
|
267
|
-
debug: _
|
|
268
|
-
done: _
|
|
269
|
-
drag: _
|
|
270
|
-
faint: _
|
|
271
|
-
gametype: _
|
|
272
|
-
gen: _
|
|
273
|
-
move: _, from, miss, still
|
|
274
|
-
player: _
|
|
275
|
-
request: _
|
|
276
|
-
rule: _
|
|
277
|
-
start: _
|
|
278
|
-
switch: _, from
|
|
279
|
-
t:: _
|
|
280
|
-
teamsize: _
|
|
281
|
-
tie: _
|
|
282
|
-
tier: _
|
|
283
|
-
turn: _
|
|
284
|
-
upkeep: _
|
|
285
|
-
win: _
|
|
306
|
+
-activate: _, move, name, number
|
|
286
307
|
```
|
|
287
308
|
|
|
288
309
|
## Bugs
|
|
@@ -11,15 +11,15 @@ const Type = data.Type;
|
|
|
11
11
|
/// Representation of a held item in Generation II Pokémon.
|
|
12
12
|
pub const Item = enum(u8) {
|
|
13
13
|
None,
|
|
14
|
+
SoftSand, // Ground
|
|
15
|
+
HardStone, // Rock
|
|
16
|
+
MetalCoat, // Steel
|
|
14
17
|
PinkBow, // Normal
|
|
15
18
|
BlackBelt, // Fighting
|
|
16
19
|
SharpBeak, // Flying
|
|
17
20
|
PoisonBarb, // Poison
|
|
18
|
-
SoftSand, // Ground
|
|
19
|
-
HardStone, // Rock
|
|
20
21
|
SilverPowder, // Bug
|
|
21
22
|
SpellTag, // Ghost
|
|
22
|
-
MetalCoat, // Steel
|
|
23
23
|
PolkadotBow, // ??? (Normal)
|
|
24
24
|
Charcoal, // Fire
|
|
25
25
|
MysticWater, // Water
|
|
@@ -36,21 +36,21 @@ pub const Item = enum(u8) {
|
|
|
36
36
|
Stick,
|
|
37
37
|
ThickClub,
|
|
38
38
|
FocusBand, // FocusBand
|
|
39
|
-
BerryJuice, // Berry
|
|
40
39
|
ScopeLens, // CriticalUp
|
|
41
40
|
Leftovers, // Leftovers
|
|
42
41
|
BerserkGene,
|
|
43
42
|
LightBall,
|
|
43
|
+
Berry, // Berry
|
|
44
|
+
BerryJuice, // Berry
|
|
45
|
+
GoldBerry, // Berry
|
|
46
|
+
MintBerry, // HealSleep
|
|
44
47
|
PSNCureBerry, // HealPoison
|
|
45
48
|
PRZCureBerry, // HealParalyze
|
|
46
|
-
BurntBerry, // HealFreeze
|
|
47
49
|
IceBerry, // HealBurn
|
|
48
|
-
|
|
49
|
-
MintBerry, // HealSleep
|
|
50
|
+
BurntBerry, // HealFreeze
|
|
50
51
|
MiracleBerry, // HealStatus
|
|
52
|
+
BitterBerry, // HealConfusion
|
|
51
53
|
MysteryBerry, // RestorePP
|
|
52
|
-
Berry, // Berry
|
|
53
|
-
GoldBerry, // Berry
|
|
54
54
|
MasterBall,
|
|
55
55
|
UltraBall,
|
|
56
56
|
GreatBall,
|
|
@@ -219,18 +219,12 @@ 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 (@
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/// Whether or not this item is a Berry.
|
|
226
|
-
pub inline fn berry(item: Item) bool {
|
|
227
|
-
assert(item != .None);
|
|
228
|
-
return @enumToInt(item) > 30 and @enumToInt(item) <= 40;
|
|
222
|
+
return if (@intFromEnum(item) <= 18) @enumFromInt(@intFromEnum(item) - 1) else null;
|
|
229
223
|
}
|
|
230
224
|
|
|
231
225
|
/// Whether or not this item is Mail.
|
|
232
|
-
pub inline fn
|
|
226
|
+
pub inline fn isMail(item: Item) bool {
|
|
233
227
|
assert(item != .None);
|
|
234
|
-
return @
|
|
228
|
+
return @intFromEnum(item) > 60 and @intFromEnum(item) <= 70;
|
|
235
229
|
}
|
|
236
230
|
};
|