@pkmn/engine 0.1.0-dev.9a0c07c3 → 0.1.0-dev.af1565df
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 +22 -22
- package/build/pkg/addon.d.ts +7 -0
- package/build/pkg/addon.js +111 -0
- package/build/pkg/addon.js.map +1 -0
- package/build/pkg/data/layout.json +1 -1
- package/build/pkg/gen1.d.ts +5 -4
- package/build/pkg/gen1.js +43 -24
- 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 +17 -22
- package/package.json +13 -9
- package/src/bin/install-pkmn-engine +3 -3
- package/src/bin/pkmn-debug +34 -7
- package/src/lib/binding/node.zig +5 -5
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/debug.zig +1 -0
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +99 -71
- package/src/lib/gen1/data.zig +19 -17
- package/src/lib/gen1/helpers.zig +4 -15
- package/src/lib/gen1/mechanics.zig +378 -304
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +7 -7
package/src/lib/gen1/README.md
CHANGED
|
@@ -28,35 +28,36 @@ list of additional reference [**resources**](#resources).
|
|
|
28
28
|
|
|
29
29
|
The following information is required to simulate a Generation I Pokémon battle:
|
|
30
30
|
|
|
31
|
-
| pkmn
|
|
32
|
-
|
|
|
33
|
-
| `battle.seed`
|
|
34
|
-
| `battle.turn`
|
|
35
|
-
| `battle.last_damage`
|
|
36
|
-
| `side.{active,pokemon}`
|
|
37
|
-
| `side.team`
|
|
38
|
-
| `side.last_used_move`
|
|
39
|
-
| `side.last_selected_move`
|
|
40
|
-
| `battle.
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `pokemon.
|
|
44
|
-
| `
|
|
45
|
-
| `{pokemon,active}.
|
|
46
|
-
| `pokemon.
|
|
47
|
-
| `pokemon.
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `active.
|
|
53
|
-
| `active.
|
|
54
|
-
| `volatiles
|
|
55
|
-
| `volatiles.
|
|
56
|
-
| `volatiles.
|
|
57
|
-
| `volatiles.
|
|
58
|
-
| `volatiles.
|
|
59
|
-
| `volatiles.
|
|
31
|
+
| pkmn | Pokémon Red (pret) | Pokémon Showdown |
|
|
32
|
+
| --------------------------------------- | ---------------------------------- | -------------------------------------- |
|
|
33
|
+
| `battle.seed` | `Random{Add,Sub}` | `battle.seed` |
|
|
34
|
+
| `battle.turn` | - | `battle.turn` |
|
|
35
|
+
| `battle.last_damage` | `Damage` | `battle.lastDamage` |
|
|
36
|
+
| `side.{active,pokemon}` | `PlayerMonNumber`/`BattleMon` | `side.active` |
|
|
37
|
+
| `side.team` | `PartyMons` | `side.pokemon` |
|
|
38
|
+
| `side.last_used_move` | `PlayerUsedMove` | `pokemon.lastMove` |
|
|
39
|
+
| `side.last_selected_move` | `PlayerSelectedMove` | `side.lastSelectedMove` |
|
|
40
|
+
| `battle.last_moves.{p1,p2}_index` | `PlayerMoveListIndex` | - |
|
|
41
|
+
| `battle.last_moves.{p1,p2}_counterable` | - | `side.lastMove` |
|
|
42
|
+
| `side.order` | - | `pokemon.position` |
|
|
43
|
+
| `{pokemon,active}.moves` | `{party,battle}_struct.{Moves,PP}` | `pokemon.{baseMoveSlots,moveSlots}` |
|
|
44
|
+
| `pokemon.hp` | `{party,battle}_struct.HP` | `pokemon.hp` |
|
|
45
|
+
| `{pokemon,active}.status` | `{party,battle}_struct.Status` | `pokemon.status` |
|
|
46
|
+
| `{pokemon,active}.level` | `PlayerMonUnmodifiedLevel` | `pokemon.level` |
|
|
47
|
+
| `pokemon.species` | `party_struct.Species` | `pokemon.baseSpecies` |
|
|
48
|
+
| `pokemon.stats` | `box_struct.Stats` | `pokemon.baseStoredStats` |
|
|
49
|
+
| `active.stats` | `battle_struct.Stats` | `pokemon.modifiedStats` |
|
|
50
|
+
| `volatiles.transform` | `PlayerMonUnmodified*` | `pokemon.storedStats` |
|
|
51
|
+
| `active.species` | `battle_struct.Species` | `pokemon.species` |
|
|
52
|
+
| `{pokemon,active}.types` | `{party,battle}_struct.Type` | `pokemon.types` |
|
|
53
|
+
| `active.boosts` | `PlayerMon*Mod` | `pokemon.boosts` |
|
|
54
|
+
| `active.volatiles` | `PlayerBattleStatus{1,2,3}` | `pokemon.volatiles` |
|
|
55
|
+
| `volatiles.state` | `PlayerBideAccumulatedDamage` | `volatiles.bide.totalDamage` |
|
|
56
|
+
| `volatiles.attacks` | `PlayerNumAttacksLeft` | `volatiles.{bide,lockedmove}.duration` |
|
|
57
|
+
| `volatiles.confusion` | `PlayerConfusedCounter` | `volatiles.confusion.duration` |
|
|
58
|
+
| `volatiles.toxic` | `PlayerToxicCounter` | `volatiles.residualdmg.counter` |
|
|
59
|
+
| `volatiles.substitute` | `PlayerSubstituteHP` | `volatiles.substitute.hp` |
|
|
60
|
+
| `volatiles.disabled_{move,duration}` | `PlayerDisabledMove{,Number}` | `volatiles.disable.{move,time}` |
|
|
60
61
|
|
|
61
62
|
- Pokémon Showdown [does not implement the correct Generation I RNG](#rng) and as such its `seed` is
|
|
62
63
|
different
|
|
@@ -68,6 +69,9 @@ The following information is required to simulate a Generation I Pokémon battle
|
|
|
68
69
|
Counter and is not set and cleared in the correct locations. `Pokemon.lastMove` matches
|
|
69
70
|
`PlayerUsedMove` more often so is what the engine attempts to model, despite the implications for
|
|
70
71
|
Counter)
|
|
72
|
+
- `battle.last_moves` doesn't map precisely to cartridge concepts because it is used to track desyncs
|
|
73
|
+
which instead are represented on the cartridge as discrepancies between the two separate battle states
|
|
74
|
+
that exist in the link battle.
|
|
71
75
|
- Pokémon Showdown does not implement the [partial-trapping move Mirror Move
|
|
72
76
|
glitch](https://glitchcity.wiki/Partial_trapping_move_Mirror_Move_link_battle_glitch) and as such
|
|
73
77
|
does not need to keep track of a player's last selected move index (`PlayerMoveListIndex`)
|
|
@@ -98,8 +102,8 @@ The following information is required to simulate a Generation I Pokémon battle
|
|
|
98
102
|
store general information about the battle. Unlike in Pokémon Showdown there is a distinction
|
|
99
103
|
between the data structure for the "active" Pokémon and its party members (see below).
|
|
100
104
|
|
|
101
|
-
Due to layout constraints,
|
|
102
|
-
otherwise be the padding bytes of`Battle` (the `
|
|
105
|
+
Due to layout constraints, details about the last moves for a side are stored in what would
|
|
106
|
+
otherwise be the padding bytes of`Battle` (the `last_moves` field) instead of in `Side`.
|
|
103
107
|
|
|
104
108
|
### `Pokemon` / `ActivePokemon`
|
|
105
109
|
|
|
@@ -198,7 +202,7 @@ above, PP information isn't strictly necessary in Generation I so is dropped. `M
|
|
|
198
202
|
a special sentinel value to indicate `null`. Move PP data is only included for testing and is not
|
|
199
203
|
necessary for the actual engine implementation.
|
|
200
204
|
|
|
201
|
-
In order to workaround various [Pokémon Showdown bugs](#bugs) and to support its protocol in
|
|
205
|
+
In order to workaround various [Pokémon Showdown bugs](#bugs) and to support its protocol in logs,
|
|
202
206
|
additional information is stored in `Move.Data` (`targets`) about what Pokémon Showdown believes the
|
|
203
207
|
`Move.Target` to be (despite the concept of targeting not existing until Generation III when Double
|
|
204
208
|
battles were introduced). More specifically, a move's "targeting" status is required in various
|
|
@@ -331,30 +335,33 @@ does not produce an equivalent to Pokémon Showdown's `|request|` protocol messa
|
|
|
331
335
|
must be gleaned through the `Battle` state). Useful size and offset information can be found in
|
|
332
336
|
the [`layout.json`](../../data/layout.json) which exists to simplify writing driver code.
|
|
333
337
|
|
|
334
|
-
Documentation of the wire protocol used for logging
|
|
335
|
-
[PROTOCOL.md](../../../docs/PROTOCOL.md). Note that the
|
|
338
|
+
Documentation of the wire protocol used for protocol message logging when `-Dlog` is enabled can be
|
|
339
|
+
found in [PROTOCOL.md](../../../docs/PROTOCOL.md). Note that the
|
|
336
340
|
[`pkmn-debug`](../../../README.md#pkmn-debug) tool exists to display the binary protocol and battle
|
|
337
341
|
data in the browser for ease of debugging.
|
|
338
342
|
|
|
339
343
|
### `Battle`
|
|
340
344
|
|
|
341
|
-
| Start | End | Data
|
|
342
|
-
| ------- | ------- |
|
|
343
|
-
| 0 | 184 | [`sides[0]`](#side)
|
|
344
|
-
| 184 | 368 | [`sides[1]`](#side)
|
|
345
|
-
| 368 | 370 | `turn`
|
|
346
|
-
| 370 | 372 | `last_damage`
|
|
347
|
-
| 372 | 373-376 | `
|
|
348
|
-
| 373-376 | 384 | `rng`
|
|
345
|
+
| Start | End | Data | Description |
|
|
346
|
+
| ------- | ------- | ------------------- | ------------------------------------------------------- |
|
|
347
|
+
| 0 | 184 | [`sides[0]`](#side) | Player 1's side |
|
|
348
|
+
| 184 | 368 | [`sides[1]`](#side) | Player 2's side |
|
|
349
|
+
| 368 | 370 | `turn` | The current turn number |
|
|
350
|
+
| 370 | 372 | `last_damage` | The last damage dealt by either side |
|
|
351
|
+
| 372 | 373-376 | `last_moves` | The slot index of the last selected moves for each side |
|
|
352
|
+
| 373-376 | 384 | `rng` | The RNG state |
|
|
349
353
|
|
|
350
354
|
- the current `turn` is 2 bytes, written in native-endianness
|
|
351
|
-
- `
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
`side[1]`
|
|
355
|
+
- `last_moves` layout depends on whether or not Pokémon Showdown compatibility mode is enabled
|
|
356
|
+
(`-Dshowdown`). In either case it stores the last selected move index and last executed move for
|
|
357
|
+
each player (required to detect desyncs). In the case of the move index, 0 is used as an empty
|
|
358
|
+
value and 1-4 represent actual moves:
|
|
359
|
+
- if `showdown` is enabled byte 372 is used to store the last selected move index of `side[0]` and
|
|
360
|
+
byte 373 is used to store whether or not the side's last executed move would have been considered
|
|
361
|
+
"counterable"; and bytes 374 and 375 store the same information for `side[1]`
|
|
362
|
+
- otherwise the first 3 bits of byte 372 stores the last selected move index of `side[0]` and the
|
|
363
|
+
next bit stores whether that side's last executed move would have been considered "counterable",
|
|
364
|
+
with the same information for `side[1]`'s being stored in the second 4 bits
|
|
358
365
|
- the `rng` depends on whether or not Pokémon Showdown compatibility mode is enabled (`-Dshowdown`):
|
|
359
366
|
- if `showdown` is enabled, the RNG state begins on byte 376 and consists of a 64-bit seed,
|
|
360
367
|
written in native-endianness
|
|
@@ -478,17 +485,21 @@ Smogon](https://www.smogon.com/forums/posts/5933177/show):
|
|
|
478
485
|
- Confusion self-hits use the wrong damage formula resulting in off-by-one errors (and also fail to
|
|
479
486
|
account for an opponent's Reflect). Furthermore, the confusion self-hit damage will erroneously be
|
|
480
487
|
inflicted to the confused user's substitute if the confused user had been attempting to use a
|
|
481
|
-
self-targeting move.
|
|
488
|
+
self-targeting move. Finally, Pokémon Showdown erroneously considers the *uncapped* self-hit
|
|
489
|
+
damage for the purposes of tracking the battle's last damage.
|
|
482
490
|
|
|
483
491
|
Beyond the general bugs listed above, several move effects are implemented incorrectly by Pokémon
|
|
484
492
|
Showdown. Some of these moves are [too fundamentally broken to be implemented](#unimplementable) by
|
|
485
493
|
the pkmn engine, but the following moves have their broken behavior preserved in `-Dshowdown` mode:
|
|
486
494
|
|
|
487
|
-
- **Bide**:
|
|
488
|
-
|
|
495
|
+
- **Bide**: Bide's damage can overflow if OHKO moves are involved because OHKO moves work by setting
|
|
496
|
+
the damage to 65535 - Pokémon Showdown doesn't implement this overflow and instead lets Bide's
|
|
497
|
+
damage grow unbounded. Additionally, if the opponent faints after Bide inflicts damage on Pokémon
|
|
498
|
+
Showdown residual damage incorrectly still gets applied to Bide's user.
|
|
499
|
+
- **Counter**: On Pokémon Showdown choices made while sleeping (which should not have been
|
|
500
|
+
registered) can erroneously cause Counter to trigger Desync Clause Mod behavior.
|
|
489
501
|
- **Leech Seed**: Leech Seed fails to heal its source side if a seeded target faints due to
|
|
490
|
-
recoil/crash damage on Pokémon Showdown.
|
|
491
|
-
field with the uncapped Leech Seed damage which has consequences for Bide and Counter.
|
|
502
|
+
recoil/crash damage on Pokémon Showdown.
|
|
492
503
|
- **Pay Day**: Pay Day should still scatter coins if it hits (but doesn't break) and opponent's
|
|
493
504
|
Substitute but doesn't on Pokémon Showdown.
|
|
494
505
|
- **Flinch**: Flinching does not get cleared during move selection on Pokémon Showdown and is
|
|
@@ -498,10 +509,14 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
498
509
|
- **Rage**: Rage boosts should still result in burn/paralysis [stat modification
|
|
499
510
|
errors](https://pkmn.cc/bulba-glitch-1#Stat_modification_errors) but don't on Pokémon Showdown.
|
|
500
511
|
Furthermore, Pokémon Showdown only builds Rage for Disable/Explosion (hit/miss) when attacking
|
|
501
|
-
into a Substitute instead of all moves.
|
|
512
|
+
into a Substitute instead of all moves. Pokémon Showdown also implements the [Rage and Thrash /
|
|
513
|
+
Petal Dance accuracy bug]( https://www.youtube.com/watch?v=NC5gbJeExbs) incorrectly, as the
|
|
514
|
+
accuracy only gets written when the volatile is present which can lead to incorrect accuracy
|
|
515
|
+
values on turns where Rage is used on the same turn as a move which modifies accuracy or evasion.
|
|
502
516
|
- **Thrash** / **Petal Dance**: once a Pokémon is locked into a thrashing move they will lose all
|
|
503
517
|
speed ties on Pokémon Showdown (due to the fact that if they win the speed tie their action will
|
|
504
|
-
then get "changed" and inserted back into the queue after their opponent's action).
|
|
518
|
+
then get "changed" and inserted back into the queue after their opponent's action). Pokémon
|
|
519
|
+
Showdown also implements accuracy incorrectly, as covered above.
|
|
505
520
|
- **Freeze** / **Sleep**: Pokémon Showdown requires a move to be selected when a Pokémon is frozen
|
|
506
521
|
or sleeping and uses that in the event that the status is removed while on the cartridge no
|
|
507
522
|
selection is possible and no turn exists for the thawed/woken Pokémon to act except in the case of
|
|
@@ -525,8 +540,13 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
525
540
|
glitch](https://glitchcity.wiki/Substitute_%C2%BC_HP_glitch) also fails in many cases due to
|
|
526
541
|
Pokémon Showdown implementing the health check based on floating point division instead of integer
|
|
527
542
|
divison like on the cartridge (meaning the Substitute 1/4 glitch will only occur if the Pokémon's
|
|
528
|
-
maximum HP is evenly divisible by 4).
|
|
529
|
-
Pokémon Showdown
|
|
543
|
+
maximum HP is evenly divisible by 4). Substitute also incorrectly blocks Dream Eater on
|
|
544
|
+
Pokémon Showdown and will incorrectly still heal 1 HP for any draining moves if the attack does 0
|
|
545
|
+
damage. Finally, Pokémon Showdown uses a `subFainted` field to track whether a Substitute was
|
|
546
|
+
broken in order to know when to nullify a move's effect, only it doesn't get cleared at the end of
|
|
547
|
+
the turn and can result in incorrect behavior on subsequent turns with the moves Mirror Move and
|
|
548
|
+
Metronome that invoke `runMove` (which is where `subFainted` gets cleared) on the user but skips
|
|
549
|
+
calling it for the eventual true target.
|
|
530
550
|
|
|
531
551
|
In addition to numerous cases where Pokémon Showdown uses the wrong type of message (e.g. `|-fail`
|
|
532
552
|
vs. `|-miss|` vs. `|-immune|`, e.g. in the case of Leech Seed) which are not documented here, Pokémon
|
|
@@ -596,9 +616,9 @@ the correct control flow):
|
|
|
596
616
|
still gets a turn under the [trapping sleep
|
|
597
617
|
glitch](https://glitchcity.wiki/Trapping_move_and_sleep_glitch), Wrap does 0 damage against
|
|
598
618
|
Ghost-type Pokémon instead of properly respecting immunity, and binding effects are handled in the
|
|
599
|
-
wrong order in the code
|
|
600
|
-
|
|
601
|
-
|
|
619
|
+
wrong order in the code which results in either out of order messaging or, more consequentially,
|
|
620
|
+
Pokémon using Rage/Bide or Thrashing/Charging moves being incorrectly forced to skip a turn when
|
|
621
|
+
the Pokémon using the Binding move switches.
|
|
602
622
|
- **Mimic**: Pokémon Showdown checks that the user of Mimic has Mimic in one of their move slots,
|
|
603
623
|
which means Mimic legally called via Metronome or Mirror Move will only work if the user also has
|
|
604
624
|
Mimic (and the moved mimicked by Mimic called via Metronome / Mirror Move will erroneously
|
|
@@ -606,19 +626,27 @@ the correct control flow):
|
|
|
606
626
|
because Pokémon Showdown deducts PP based on a move's name instead of slot, if Mimic copies a move
|
|
607
627
|
the Pokémon already knows, PP deduction for using either the original move of the mimicked move
|
|
608
628
|
will instead deduct PP for whichever appears at the lower move slot index and the PP will be
|
|
609
|
-
allowed to go negative (effectively allowing for infinite PP use).
|
|
610
|
-
|
|
611
|
-
|
|
629
|
+
allowed to go negative (effectively allowing for infinite PP use). Pokémon Showdown also doesn't
|
|
630
|
+
deduct PP from using Transform if it was copied by Mimic.
|
|
631
|
+
- **Mirror Move**: As covered above, both Substitute and Binding moves misbehave when used via
|
|
632
|
+
Mirror Move (though Pokémon Showdown has its own weird behavior and does not implement the
|
|
633
|
+
[partial trapping move Mirror Move
|
|
612
634
|
glitch](https://glitchcity.wiki/Partial_trapping_move_Mirror_Move_link_battle_glitch) that exists
|
|
613
|
-
on the cartridge).
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
- **
|
|
635
|
+
on the cartridge). Additionally, Pokémon Showdown sets the last used move every turn a Pokémon is
|
|
636
|
+
Thrashing instead of just on the turn it is actually selected meaning Mirror Move will sometimes
|
|
637
|
+
successfully mirror a Thrashing move when it should fail. Finally, if Mirror Move copies
|
|
638
|
+
Struggle it should not deduct PP but on Pokémon Showdown it does.
|
|
639
|
+
- **Metronome**: In addition to the issues with binding moves and Substitute, Metronome and Mirror
|
|
640
|
+
Move cannot mutually call each other more than 3 times in a row without causing the Pokémon
|
|
641
|
+
Showdown simulator to crash due to defensive safety checks that do not exist on the cartridge.
|
|
642
|
+
- **Transform**: Transform screws up the effect of Disable, because on Pokémon Showdown, Disable
|
|
618
643
|
prevents moves of a given *name* from being used (e.g. "Water Gun") as opposed to moves in a
|
|
619
644
|
specific *slot* (e.g. the 2nd move slot), and a Pokémon's moves can change after Transform (this
|
|
620
|
-
is not an issue with Disable + Mimic because Mimic happens to replace the same slot).
|
|
621
|
-
|
|
645
|
+
is not an issue with Disable + Mimic because Mimic happens to replace the same slot). Transform
|
|
646
|
+
also has a bad interaction with Pokémon Showdown's buggy Haze implementation, as Haze on Pokémon
|
|
647
|
+
Showdown does not copy unmodified stats, leaving the Transformed Pokémon with incorrect stats.
|
|
648
|
+
Furthermore, transforming and then using Mirror Move / Metronome can result in [glitchy behavior
|
|
649
|
+
and
|
|
622
650
|
softlocks](https://pkmn.cc/bulba/Transform_glitches#Transform_.2B_Mirror_Move.2FMetronome_PP_error)
|
|
623
651
|
which Pokémon Showdown does not implement.
|
|
624
652
|
|
package/src/lib/gen1/data.zig
CHANGED
|
@@ -17,16 +17,16 @@ const expectEqual = std.testing.expectEqual;
|
|
|
17
17
|
const expect = std.testing.expect;
|
|
18
18
|
|
|
19
19
|
/// The minimum size in bytes required to hold all Generation I choice options.
|
|
20
|
-
pub const
|
|
20
|
+
pub const MAX_CHOICES: usize = 9; // move 1..4, switch 2..6
|
|
21
21
|
/// The optimal size in bytes required to hold all Generation I choice options.
|
|
22
|
-
/// At least as large as
|
|
22
|
+
/// At least as large as MAX_CHOICES.
|
|
23
23
|
pub const MAX_LOGS: usize = 180;
|
|
24
24
|
|
|
25
25
|
/// The maximum number of bytes possibly logged by a single Generation I update.
|
|
26
|
-
pub const
|
|
27
|
-
|
|
26
|
+
pub const CHOICES_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
27
|
+
MAX_CHOICES
|
|
28
28
|
else
|
|
29
|
-
std.math.ceilPowerOfTwo(usize,
|
|
29
|
+
std.math.ceilPowerOfTwo(usize, MAX_CHOICES) catch unreachable;
|
|
30
30
|
/// The optimal size in bytes required to hold the largest amount of log data possible from a
|
|
31
31
|
/// single Generation I update. At least as large as MAX_LOGS.
|
|
32
32
|
pub const LOGS_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
@@ -55,8 +55,8 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
55
55
|
turn: u16 = 0,
|
|
56
56
|
/// The last damage dealt by either side.
|
|
57
57
|
last_damage: u16 = 0,
|
|
58
|
-
///
|
|
59
|
-
|
|
58
|
+
/// Details about the last move selected/used by each player required to detect desyncs.
|
|
59
|
+
last_moves: MoveDetails = .{},
|
|
60
60
|
/// The pseudo random number generator.
|
|
61
61
|
rng: RNG,
|
|
62
62
|
|
|
@@ -76,7 +76,7 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/// Returns the result of applying Player 1's choice `c1` and Player 2's choice `c2` to the
|
|
79
|
-
/// battle, optionally writing protocol logs to `log` if `options.
|
|
79
|
+
/// battle, optionally writing protocol message logs to `log` if `options.log` is enabled.
|
|
80
80
|
pub fn update(self: *Self, c1: Choice, c2: Choice, log: anytype) !Result {
|
|
81
81
|
return mechanics.update(self, c1, c2, log);
|
|
82
82
|
}
|
|
@@ -201,17 +201,19 @@ pub const MoveSlot = extern struct {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
///
|
|
207
|
-
|
|
208
|
-
/// Player 1
|
|
209
|
-
|
|
210
|
-
///
|
|
211
|
-
|
|
204
|
+
/// Details required to detect desyncs based on the move last selected/executed by players.
|
|
205
|
+
pub const MoveDetails = packed struct {
|
|
206
|
+
/// The move slot index of the last move selected in the battle menu by Player 1
|
|
207
|
+
p1_index: if (showdown) u8 else u3 = 0,
|
|
208
|
+
/// Whether the last move executed by Player 1 was counterable.
|
|
209
|
+
p1_counterable: if (showdown) u8 else u1 = 0,
|
|
210
|
+
/// The move slot index of the last move selected in the battle menu by Player 2
|
|
211
|
+
p2_index: if (showdown) u8 else u3 = 0,
|
|
212
|
+
/// Whether the last move executed by Player 2 was counterable.
|
|
213
|
+
p2_counterable: if (showdown) u8 else u1 = 0,
|
|
212
214
|
|
|
213
215
|
comptime {
|
|
214
|
-
assert(@sizeOf(
|
|
216
|
+
assert(@sizeOf(MoveDetails) == if (showdown) 4 else 1);
|
|
215
217
|
}
|
|
216
218
|
};
|
|
217
219
|
|
package/src/lib/gen1/helpers.zig
CHANGED
|
@@ -55,21 +55,16 @@ pub const Battle = struct {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
pub fn random(rand: *PSRNG, opt: Options) data.Battle(data.PRNG) {
|
|
58
|
-
|
|
59
|
-
var p2: u4 = 0;
|
|
60
|
-
var battle: data.Battle(data.PRNG) = .{
|
|
58
|
+
return .{
|
|
61
59
|
.rng = prng(rand),
|
|
62
60
|
.turn = 0,
|
|
63
61
|
.last_damage = 0,
|
|
64
62
|
.sides = .{ Side.random(rand, opt), Side.random(rand, opt) },
|
|
65
63
|
};
|
|
66
|
-
battle.last_selected_indexes.p1 = p1;
|
|
67
|
-
battle.last_selected_indexes.p2 = p2;
|
|
68
|
-
return battle;
|
|
69
64
|
}
|
|
70
65
|
};
|
|
71
66
|
|
|
72
|
-
|
|
67
|
+
fn prng(rand: *PSRNG) data.PRNG {
|
|
73
68
|
// GLITCH: initial bytes in seed can only range from 0-252, not 0-255
|
|
74
69
|
const max: u8 = 253;
|
|
75
70
|
return .{
|
|
@@ -211,16 +206,10 @@ pub const Pokemon = struct {
|
|
|
211
206
|
}
|
|
212
207
|
};
|
|
213
208
|
|
|
214
|
-
// cat src/test/showdown/blocklist.json | jq '."1".moves'
|
|
215
209
|
fn blocked(m: Move) bool {
|
|
216
|
-
|
|
210
|
+
// Binding moves are borked but only via Mirror Move / Metronome which are already blocked
|
|
217
211
|
return switch (m) {
|
|
218
|
-
.
|
|
219
|
-
.Mimic,
|
|
220
|
-
.Metronome,
|
|
221
|
-
.MirrorMove,
|
|
222
|
-
.Transform,
|
|
223
|
-
=> true,
|
|
212
|
+
.Mimic, .Metronome, .MirrorMove, .Transform => true,
|
|
224
213
|
else => false,
|
|
225
214
|
};
|
|
226
215
|
}
|