@pkmn/engine 0.1.0-dev.d716e940 → 0.1.0-dev.d97c6e03
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 +18 -18
- package/build/pkg/addon.d.ts +1 -1
- package/build/pkg/addon.js +4 -4
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/layout.json +1 -1
- package/build/pkg/gen1.d.ts +4 -5
- package/build/pkg/gen1.js +23 -42
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +12 -15
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +2 -4
- package/build/pkg/protocol.js +2 -4
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +12 -29
- package/build/test/display.js.map +1 -1
- package/build.zig +7 -7
- package/package.json +9 -10
- package/src/bin/install-pkmn-engine +3 -3
- package/src/lib/binding/node.zig +1 -1
- package/src/lib/binding/wasm.zig +1 -1
- package/src/lib/common/debug.zig +0 -1
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +69 -90
- package/src/lib/gen1/data.zig +12 -14
- package/src/lib/gen1/helpers.zig +14 -3
- package/src/lib/gen1/mechanics.zig +78 -156
- package/src/lib/pkmn.zig +4 -4
|
@@ -7,7 +7,7 @@ const options = @import("./options.zig");
|
|
|
7
7
|
const assert = std.debug.assert;
|
|
8
8
|
const print = std.debug.print;
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const trace = options.trace;
|
|
11
11
|
|
|
12
12
|
const Player = data.Player;
|
|
13
13
|
const ID = data.ID;
|
|
@@ -230,7 +230,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
230
230
|
pub const Error = Writer.Error;
|
|
231
231
|
|
|
232
232
|
pub fn move(self: Self, source: ID, m: anytype, target: ID, from: anytype) Error!void {
|
|
233
|
-
if (!
|
|
233
|
+
if (!trace) return;
|
|
234
234
|
assert(m != .None);
|
|
235
235
|
try self.writer.writeAll(&.{
|
|
236
236
|
@enumToInt(ArgType.Move),
|
|
@@ -253,7 +253,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
pub fn switched(self: Self, ident: ID, pokemon: anytype) Error!void {
|
|
256
|
-
if (!
|
|
256
|
+
if (!trace) return;
|
|
257
257
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Switch), @bitCast(u8, ident) });
|
|
258
258
|
try self.writer.writeAll(&.{ @enumToInt(pokemon.species), pokemon.level });
|
|
259
259
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -262,7 +262,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
pub fn cant(self: Self, ident: ID, reason: Cant) Error!void {
|
|
265
|
-
if (!
|
|
265
|
+
if (!trace) return;
|
|
266
266
|
assert(reason != .Disable);
|
|
267
267
|
try self.writer.writeAll(&.{
|
|
268
268
|
@enumToInt(ArgType.Cant),
|
|
@@ -272,7 +272,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
pub fn disabled(self: Self, ident: ID, m: anytype) Error!void {
|
|
275
|
-
if (!
|
|
275
|
+
if (!trace) return;
|
|
276
276
|
try self.writer.writeAll(&.{
|
|
277
277
|
@enumToInt(ArgType.Cant),
|
|
278
278
|
@bitCast(u8, ident),
|
|
@@ -282,20 +282,20 @@ pub fn Log(comptime Writer: type) type {
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
pub fn faint(self: Self, ident: ID, done: bool) Error!void {
|
|
285
|
-
if (!
|
|
285
|
+
if (!trace) return;
|
|
286
286
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Faint), @bitCast(u8, ident) });
|
|
287
287
|
if (done) try self.writer.writeByte(@enumToInt(ArgType.None));
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
pub fn turn(self: Self, num: u16) Error!void {
|
|
291
|
-
if (!
|
|
291
|
+
if (!trace) return;
|
|
292
292
|
try self.writer.writeByte(@enumToInt(ArgType.Turn));
|
|
293
293
|
try self.writer.writeIntNative(u16, num);
|
|
294
294
|
try self.writer.writeByte(@enumToInt(ArgType.None));
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
pub fn win(self: Self, player: Player) Error!void {
|
|
298
|
-
if (!
|
|
298
|
+
if (!trace) return;
|
|
299
299
|
try self.writer.writeAll(&.{
|
|
300
300
|
@enumToInt(ArgType.Win),
|
|
301
301
|
@enumToInt(player),
|
|
@@ -304,12 +304,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
pub fn tie(self: Self) Error!void {
|
|
307
|
-
if (!
|
|
307
|
+
if (!trace) return;
|
|
308
308
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Tie), @enumToInt(ArgType.None) });
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
pub fn damage(self: Self, ident: ID, pokemon: anytype, reason: Damage) Error!void {
|
|
312
|
-
if (!
|
|
312
|
+
if (!trace) return;
|
|
313
313
|
assert(@enumToInt(reason) <= @enumToInt(Damage.LeechSeed));
|
|
314
314
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Damage), @bitCast(u8, ident) });
|
|
315
315
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -324,7 +324,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
324
324
|
reason: Damage,
|
|
325
325
|
source: ID,
|
|
326
326
|
) Error!void {
|
|
327
|
-
if (!
|
|
327
|
+
if (!trace) return;
|
|
328
328
|
assert(@enumToInt(reason) == @enumToInt(Damage.RecoilOf));
|
|
329
329
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Damage), @bitCast(u8, ident) });
|
|
330
330
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -337,7 +337,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
pub fn heal(self: Self, ident: ID, pokemon: anytype, reason: Heal) Error!void {
|
|
340
|
-
if (!
|
|
340
|
+
if (!trace) return;
|
|
341
341
|
assert(reason != .Drain);
|
|
342
342
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Heal), @bitCast(u8, ident) });
|
|
343
343
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
@@ -346,7 +346,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
pub fn drain(self: Self, source: ID, pokemon: anytype, target: ID) Error!void {
|
|
349
|
-
if (!
|
|
349
|
+
if (!trace) return;
|
|
350
350
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Heal), @bitCast(u8, source) });
|
|
351
351
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
352
352
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
@@ -358,7 +358,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
pub fn status(self: Self, ident: ID, value: u8, reason: Status) Error!void {
|
|
361
|
-
if (!
|
|
361
|
+
if (!trace) return;
|
|
362
362
|
assert(reason != .From);
|
|
363
363
|
try self.writer.writeAll(&.{
|
|
364
364
|
@enumToInt(ArgType.Status),
|
|
@@ -369,7 +369,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
pub fn statusFrom(self: Self, ident: ID, value: u8, m: anytype) Error!void {
|
|
372
|
-
if (!
|
|
372
|
+
if (!trace) return;
|
|
373
373
|
try self.writer.writeAll(&.{
|
|
374
374
|
@enumToInt(ArgType.Status),
|
|
375
375
|
@bitCast(u8, ident),
|
|
@@ -380,7 +380,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
pub fn curestatus(self: Self, ident: ID, value: u8, reason: CureStatus) Error!void {
|
|
383
|
-
if (!
|
|
383
|
+
if (!trace) return;
|
|
384
384
|
try self.writer.writeAll(&.{
|
|
385
385
|
@enumToInt(ArgType.CureStatus),
|
|
386
386
|
@bitCast(u8, ident),
|
|
@@ -390,7 +390,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
pub fn boost(self: Self, ident: ID, reason: Boost, num: i8) Error!void {
|
|
393
|
-
if (!
|
|
393
|
+
if (!trace) return;
|
|
394
394
|
assert(num != 0 and (reason != .Rage or num > 0));
|
|
395
395
|
try self.writer.writeAll(&.{
|
|
396
396
|
@enumToInt(ArgType.Boost),
|
|
@@ -401,12 +401,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
pub fn clearallboost(self: Self) Error!void {
|
|
404
|
-
if (!
|
|
404
|
+
if (!trace) return;
|
|
405
405
|
try self.writer.writeAll(&.{@enumToInt(ArgType.ClearAllBoost)});
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
pub fn fail(self: Self, ident: ID, reason: Fail) Error!void {
|
|
409
|
-
if (!
|
|
409
|
+
if (!trace) return;
|
|
410
410
|
try self.writer.writeAll(&.{
|
|
411
411
|
@enumToInt(ArgType.Fail),
|
|
412
412
|
@bitCast(u8, ident),
|
|
@@ -415,17 +415,17 @@ pub fn Log(comptime Writer: type) type {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
pub fn miss(self: Self, source: ID) Error!void {
|
|
418
|
-
if (!
|
|
418
|
+
if (!trace) return;
|
|
419
419
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Miss), @bitCast(u8, source) });
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
pub fn hitcount(self: Self, ident: ID, num: u8) Error!void {
|
|
423
|
-
if (!
|
|
423
|
+
if (!trace) return;
|
|
424
424
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.HitCount), @bitCast(u8, ident), num });
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
pub fn prepare(self: Self, source: ID, m: anytype) Error!void {
|
|
428
|
-
if (!
|
|
428
|
+
if (!trace) return;
|
|
429
429
|
try self.writer.writeAll(&.{
|
|
430
430
|
@enumToInt(ArgType.Prepare),
|
|
431
431
|
@bitCast(u8, source),
|
|
@@ -434,12 +434,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
pub fn mustrecharge(self: Self, ident: ID) Error!void {
|
|
437
|
-
if (!
|
|
437
|
+
if (!trace) return;
|
|
438
438
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.MustRecharge), @bitCast(u8, ident) });
|
|
439
439
|
}
|
|
440
440
|
|
|
441
441
|
pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
|
|
442
|
-
if (!
|
|
442
|
+
if (!trace) return;
|
|
443
443
|
try self.writer.writeAll(&.{
|
|
444
444
|
@enumToInt(ArgType.Activate),
|
|
445
445
|
@bitCast(u8, ident),
|
|
@@ -448,12 +448,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
pub fn fieldactivate(self: Self) Error!void {
|
|
451
|
-
if (!
|
|
451
|
+
if (!trace) return;
|
|
452
452
|
try self.writer.writeAll(&.{@enumToInt(ArgType.FieldActivate)});
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
pub fn start(self: Self, ident: ID, reason: Start) Error!void {
|
|
456
|
-
if (!
|
|
456
|
+
if (!trace) return;
|
|
457
457
|
assert(@enumToInt(reason) < @enumToInt(Start.TypeChange));
|
|
458
458
|
try self.writer.writeAll(&.{
|
|
459
459
|
@enumToInt(ArgType.Start),
|
|
@@ -463,7 +463,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
|
|
466
|
-
if (!
|
|
466
|
+
if (!trace) return;
|
|
467
467
|
try self.writer.writeAll(&.{
|
|
468
468
|
@enumToInt(ArgType.Start),
|
|
469
469
|
@bitCast(u8, source),
|
|
@@ -474,7 +474,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
|
|
477
|
-
if (!
|
|
477
|
+
if (!trace) return;
|
|
478
478
|
assert(@enumToInt(reason) > @enumToInt(Start.TypeChange));
|
|
479
479
|
try self.writer.writeAll(&.{
|
|
480
480
|
@enumToInt(ArgType.Start),
|
|
@@ -485,7 +485,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
485
485
|
}
|
|
486
486
|
|
|
487
487
|
pub fn end(self: Self, ident: ID, reason: End) Error!void {
|
|
488
|
-
if (!
|
|
488
|
+
if (!trace) return;
|
|
489
489
|
try self.writer.writeAll(&.{
|
|
490
490
|
@enumToInt(ArgType.End),
|
|
491
491
|
@bitCast(u8, ident),
|
|
@@ -494,27 +494,27 @@ pub fn Log(comptime Writer: type) type {
|
|
|
494
494
|
}
|
|
495
495
|
|
|
496
496
|
pub fn ohko(self: Self) Error!void {
|
|
497
|
-
if (!
|
|
497
|
+
if (!trace) return;
|
|
498
498
|
try self.writer.writeAll(&.{@enumToInt(ArgType.OHKO)});
|
|
499
499
|
}
|
|
500
500
|
|
|
501
501
|
pub fn crit(self: Self, ident: ID) Error!void {
|
|
502
|
-
if (!
|
|
502
|
+
if (!trace) return;
|
|
503
503
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Crit), @bitCast(u8, ident) });
|
|
504
504
|
}
|
|
505
505
|
|
|
506
506
|
pub fn supereffective(self: Self, ident: ID) Error!void {
|
|
507
|
-
if (!
|
|
507
|
+
if (!trace) return;
|
|
508
508
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.SuperEffective), @bitCast(u8, ident) });
|
|
509
509
|
}
|
|
510
510
|
|
|
511
511
|
pub fn resisted(self: Self, ident: ID) Error!void {
|
|
512
|
-
if (!
|
|
512
|
+
if (!trace) return;
|
|
513
513
|
try self.writer.writeAll(&.{ @enumToInt(ArgType.Resisted), @bitCast(u8, ident) });
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
pub fn immune(self: Self, ident: ID, reason: Immune) Error!void {
|
|
517
|
-
if (!
|
|
517
|
+
if (!trace) return;
|
|
518
518
|
try self.writer.writeAll(&.{
|
|
519
519
|
@enumToInt(ArgType.Immune),
|
|
520
520
|
@bitCast(u8, ident),
|
|
@@ -523,7 +523,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
pub fn transform(self: Self, source: ID, target: ID) Error!void {
|
|
526
|
-
if (!
|
|
526
|
+
if (!trace) return;
|
|
527
527
|
try self.writer.writeAll(&.{
|
|
528
528
|
@enumToInt(ArgType.Transform),
|
|
529
529
|
@bitCast(u8, source),
|
|
@@ -532,12 +532,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
pub fn laststill(self: Self) Error!void {
|
|
535
|
-
if (!
|
|
535
|
+
if (!trace) return;
|
|
536
536
|
try self.writer.writeAll(&.{@enumToInt(ArgType.LastStill)});
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
pub fn lastmiss(self: Self) Error!void {
|
|
540
|
-
if (!
|
|
540
|
+
if (!trace) return;
|
|
541
541
|
try self.writer.writeAll(&.{@enumToInt(ArgType.LastMiss)});
|
|
542
542
|
}
|
|
543
543
|
};
|
|
@@ -838,7 +838,7 @@ pub fn expectLog(
|
|
|
838
838
|
actual: []const u8,
|
|
839
839
|
offset: usize,
|
|
840
840
|
) !void {
|
|
841
|
-
if (!
|
|
841
|
+
if (!trace) return;
|
|
842
842
|
const color = color: {
|
|
843
843
|
if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
|
|
844
844
|
break :color true;
|
package/src/lib/gen1/README.md
CHANGED
|
@@ -28,36 +28,35 @@ 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
|
-
| `
|
|
44
|
-
| `pokemon.
|
|
45
|
-
| `{pokemon,active}.
|
|
46
|
-
| `
|
|
47
|
-
| `pokemon.
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `active.
|
|
52
|
-
| `
|
|
53
|
-
| `active.
|
|
54
|
-
| `
|
|
55
|
-
| `volatiles.
|
|
56
|
-
| `volatiles.
|
|
57
|
-
| `volatiles.
|
|
58
|
-
| `volatiles.
|
|
59
|
-
| `volatiles.
|
|
60
|
-
| `volatiles.disabled_{move,duration}` | `PlayerDisabledMove{,Number}` | `volatiles.disable.{move,time}` |
|
|
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_selected_indexes` | `PlayerMoveListIndex` | `side.lastMove` |
|
|
41
|
+
| `side.order` | - | `pokemon.position` |
|
|
42
|
+
| `{pokemon,active}.moves` | `{party,battle}_struct.{Moves,PP}` | `pokemon.{baseMoveSlots,moveSlots}` |
|
|
43
|
+
| `pokemon.hp` | `{party,battle}_struct.HP` | `pokemon.hp` |
|
|
44
|
+
| `{pokemon,active}.status` | `{party,battle}_struct.Status` | `pokemon.status` |
|
|
45
|
+
| `{pokemon,active}.level` | `PlayerMonUnmodifiedLevel` | `pokemon.level` |
|
|
46
|
+
| `pokemon.species` | `party_struct.Species` | `pokemon.baseSpecies` |
|
|
47
|
+
| `pokemon.stats` | `box_struct.Stats` | `pokemon.baseStoredStats` |
|
|
48
|
+
| `active.stats` | `battle_struct.Stats` | `pokemon.modifiedStats` |
|
|
49
|
+
| `volatiles.transform` | `PlayerMonUnmodified*` | `pokemon.storedStats` |
|
|
50
|
+
| `active.species` | `battle_struct.Species` | `pokemon.species` |
|
|
51
|
+
| `{pokemon,active}.types` | `{party,battle}_struct.Type` | `pokemon.types` |
|
|
52
|
+
| `active.boosts` | `PlayerMon*Mod` | `pokemon.boosts` |
|
|
53
|
+
| `active.volatiles` | `PlayerBattleStatus{1,2,3}` | `pokemon.volatiles` |
|
|
54
|
+
| `volatiles.state` | `PlayerBideAccumulatedDamage` | `volatiles.bide.totalDamage` |
|
|
55
|
+
| `volatiles.attacks` | `PlayerNumAttacksLeft` | `volatiles.{bide,lockedmove}.duration` |
|
|
56
|
+
| `volatiles.confusion` | `PlayerConfusedCounter` | `volatiles.confusion.duration` |
|
|
57
|
+
| `volatiles.toxic` | `PlayerToxicCounter` | `volatiles.residualdmg.counter` |
|
|
58
|
+
| `volatiles.substitute` | `PlayerSubstituteHP` | `volatiles.substitute.hp` |
|
|
59
|
+
| `volatiles.disabled_{move,duration}` | `PlayerDisabledMove{,Number}` | `volatiles.disable.{move,time}` |
|
|
61
60
|
|
|
62
61
|
- Pokémon Showdown [does not implement the correct Generation I RNG](#rng) and as such its `seed` is
|
|
63
62
|
different
|
|
@@ -69,9 +68,6 @@ The following information is required to simulate a Generation I Pokémon battle
|
|
|
69
68
|
Counter and is not set and cleared in the correct locations. `Pokemon.lastMove` matches
|
|
70
69
|
`PlayerUsedMove` more often so is what the engine attempts to model, despite the implications for
|
|
71
70
|
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.
|
|
75
71
|
- Pokémon Showdown does not implement the [partial-trapping move Mirror Move
|
|
76
72
|
glitch](https://glitchcity.wiki/Partial_trapping_move_Mirror_Move_link_battle_glitch) and as such
|
|
77
73
|
does not need to keep track of a player's last selected move index (`PlayerMoveListIndex`)
|
|
@@ -102,8 +98,8 @@ The following information is required to simulate a Generation I Pokémon battle
|
|
|
102
98
|
store general information about the battle. Unlike in Pokémon Showdown there is a distinction
|
|
103
99
|
between the data structure for the "active" Pokémon and its party members (see below).
|
|
104
100
|
|
|
105
|
-
Due to layout constraints,
|
|
106
|
-
otherwise be the padding bytes of`Battle` (the `
|
|
101
|
+
Due to layout constraints, the index of the last selected move for a side is stored in what would
|
|
102
|
+
otherwise be the padding bytes of`Battle` (the `last_selected_indexes` field) instead of in `Side`.
|
|
107
103
|
|
|
108
104
|
### `Pokemon` / `ActivePokemon`
|
|
109
105
|
|
|
@@ -202,7 +198,7 @@ above, PP information isn't strictly necessary in Generation I so is dropped. `M
|
|
|
202
198
|
a special sentinel value to indicate `null`. Move PP data is only included for testing and is not
|
|
203
199
|
necessary for the actual engine implementation.
|
|
204
200
|
|
|
205
|
-
In order to workaround various [Pokémon Showdown bugs](#bugs) and to support its protocol in
|
|
201
|
+
In order to workaround various [Pokémon Showdown bugs](#bugs) and to support its protocol in traces,
|
|
206
202
|
additional information is stored in `Move.Data` (`targets`) about what Pokémon Showdown believes the
|
|
207
203
|
`Move.Target` to be (despite the concept of targeting not existing until Generation III when Double
|
|
208
204
|
battles were introduced). More specifically, a move's "targeting" status is required in various
|
|
@@ -335,33 +331,30 @@ does not produce an equivalent to Pokémon Showdown's `|request|` protocol messa
|
|
|
335
331
|
must be gleaned through the `Battle` state). Useful size and offset information can be found in
|
|
336
332
|
the [`layout.json`](../../data/layout.json) which exists to simplify writing driver code.
|
|
337
333
|
|
|
338
|
-
Documentation of the wire protocol used for
|
|
339
|
-
|
|
334
|
+
Documentation of the wire protocol used for logging traces when `-Dtrace` is enabled can be found in
|
|
335
|
+
[PROTOCOL.md](../../../docs/PROTOCOL.md). Note that the
|
|
340
336
|
[`pkmn-debug`](../../../README.md#pkmn-debug) tool exists to display the binary protocol and battle
|
|
341
337
|
data in the browser for ease of debugging.
|
|
342
338
|
|
|
343
339
|
### `Battle`
|
|
344
340
|
|
|
345
|
-
| Start | End | Data
|
|
346
|
-
| ------- | ------- |
|
|
347
|
-
| 0 | 184 | [`sides[0]`](#side)
|
|
348
|
-
| 184 | 368 | [`sides[1]`](#side)
|
|
349
|
-
| 368 | 370 | `turn`
|
|
350
|
-
| 370 | 372 | `last_damage`
|
|
351
|
-
| 372 | 373-376 | `
|
|
352
|
-
| 373-376 | 384 | `rng`
|
|
341
|
+
| Start | End | Data | Description |
|
|
342
|
+
| ------- | ------- | ----------------------- | ------------------------------------------------------- |
|
|
343
|
+
| 0 | 184 | [`sides[0]`](#side) | Player 1's side |
|
|
344
|
+
| 184 | 368 | [`sides[1]`](#side) | Player 2's side |
|
|
345
|
+
| 368 | 370 | `turn` | The current turn number |
|
|
346
|
+
| 370 | 372 | `last_damage` | The last damage dealt by either side |
|
|
347
|
+
| 372 | 373-376 | `last_selected_indexes` | The slot index of the last selected moves for each side |
|
|
348
|
+
| 373-376 | 384 | `rng` | The RNG state |
|
|
353
349
|
|
|
354
350
|
- the current `turn` is 2 bytes, written in native-endianness
|
|
355
|
-
- `
|
|
356
|
-
(`-Dshowdown`). In either case it stores
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
|
351
|
+
- `last_selected_indexes` layout depends on whether or not Pokémon Showdown compatibility mode is
|
|
352
|
+
enabled (`-Dshowdown`). In either case it stores a move "slot", where 0 is used as an empty value and
|
|
353
|
+
1-4 represent actual moves:
|
|
354
|
+
- if `showdown` is enabled bytes 372 and 373 are used to store the last selected move index of
|
|
355
|
+
`side[0]` and bytes 374 and 375 store the last selected move index of `side[1]`
|
|
356
|
+
- otherwise byte 372 stores the last selected move index of `side[0]` in its first 4 bits and
|
|
357
|
+
`side[1]`'s in its second 4 bits
|
|
365
358
|
- the `rng` depends on whether or not Pokémon Showdown compatibility mode is enabled (`-Dshowdown`):
|
|
366
359
|
- if `showdown` is enabled, the RNG state begins on byte 376 and consists of a 64-bit seed,
|
|
367
360
|
written in native-endianness
|
|
@@ -492,14 +485,12 @@ Beyond the general bugs listed above, several move effects are implemented incor
|
|
|
492
485
|
Showdown. Some of these moves are [too fundamentally broken to be implemented](#unimplementable) by
|
|
493
486
|
the pkmn engine, but the following moves have their broken behavior preserved in `-Dshowdown` mode:
|
|
494
487
|
|
|
495
|
-
- **Bide**:
|
|
496
|
-
|
|
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.
|
|
488
|
+
- **Bide**: If the opponent faints after Bide inflicts damage on Pokémon Showdown residual damage
|
|
489
|
+
incorrectly still gets applied to Bide's user.
|
|
501
490
|
- **Leech Seed**: Leech Seed fails to heal its source side if a seeded target faints due to
|
|
502
|
-
recoil/crash damage on Pokémon Showdown.
|
|
491
|
+
recoil/crash damage on Pokémon Showdown. Pokémon Showdown also updates the battle's last damage
|
|
492
|
+
field with the uncapped Leech Seed damage if the residual damage is applied which has consequences
|
|
493
|
+
for Bide and Counter.
|
|
503
494
|
- **Pay Day**: Pay Day should still scatter coins if it hits (but doesn't break) and opponent's
|
|
504
495
|
Substitute but doesn't on Pokémon Showdown.
|
|
505
496
|
- **Flinch**: Flinching does not get cleared during move selection on Pokémon Showdown and is
|
|
@@ -540,13 +531,9 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
540
531
|
glitch](https://glitchcity.wiki/Substitute_%C2%BC_HP_glitch) also fails in many cases due to
|
|
541
532
|
Pokémon Showdown implementing the health check based on floating point division instead of integer
|
|
542
533
|
divison like on the cartridge (meaning the Substitute 1/4 glitch will only occur if the Pokémon's
|
|
543
|
-
maximum HP is evenly divisible by 4). Substitute also incorrectly blocks Dream Eater on
|
|
534
|
+
maximum HP is evenly divisible by 4). Finally, Substitute also incorrectly blocks Dream Eater on
|
|
544
535
|
Pokémon Showdown and will incorrectly still heal 1 HP for any draining moves if the attack does 0
|
|
545
|
-
damage.
|
|
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.
|
|
536
|
+
damage.
|
|
550
537
|
|
|
551
538
|
In addition to numerous cases where Pokémon Showdown uses the wrong type of message (e.g. `|-fail`
|
|
552
539
|
vs. `|-miss|` vs. `|-immune|`, e.g. in the case of Leech Seed) which are not documented here, Pokémon
|
|
@@ -616,9 +603,9 @@ the correct control flow):
|
|
|
616
603
|
still gets a turn under the [trapping sleep
|
|
617
604
|
glitch](https://glitchcity.wiki/Trapping_move_and_sleep_glitch), Wrap does 0 damage against
|
|
618
605
|
Ghost-type Pokémon instead of properly respecting immunity, and binding effects are handled in the
|
|
619
|
-
wrong order in the code
|
|
620
|
-
|
|
621
|
-
|
|
606
|
+
wrong order in the code.
|
|
607
|
+
- **Counter**: On Pokémon Showdown choices made while sleeping (which should not have been
|
|
608
|
+
registered) can erroneously cause Counter to trigger Desync Clause Mod behavior.
|
|
622
609
|
- **Mimic**: Pokémon Showdown checks that the user of Mimic has Mimic in one of their move slots,
|
|
623
610
|
which means Mimic legally called via Metronome or Mirror Move will only work if the user also has
|
|
624
611
|
Mimic (and the moved mimicked by Mimic called via Metronome / Mirror Move will erroneously
|
|
@@ -626,27 +613,19 @@ the correct control flow):
|
|
|
626
613
|
because Pokémon Showdown deducts PP based on a move's name instead of slot, if Mimic copies a move
|
|
627
614
|
the Pokémon already knows, PP deduction for using either the original move of the mimicked move
|
|
628
615
|
will instead deduct PP for whichever appears at the lower move slot index and the PP will be
|
|
629
|
-
allowed to go negative (effectively allowing for infinite PP use).
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
Mirror Move (though Pokémon Showdown has its own weird behavior and does not implement the
|
|
633
|
-
[partial trapping move Mirror Move
|
|
616
|
+
allowed to go negative (effectively allowing for infinite PP use).
|
|
617
|
+
- **Mirror Move**: Binding moves misbehave when used via Mirror Move (though Pokémon Showdown has
|
|
618
|
+
its own weird behavior and does not implement the [partial trapping move Mirror Move
|
|
634
619
|
glitch](https://glitchcity.wiki/Partial_trapping_move_Mirror_Move_link_battle_glitch) that exists
|
|
635
|
-
on the cartridge).
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
- **
|
|
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
|
|
620
|
+
on the cartridge).
|
|
621
|
+
- **Metronome**: In addition to the issues with binding moves, Metronome and Mirror Move cannot
|
|
622
|
+
mutually call each other more than 3 times in a row without causing the Pokémon Showdown simulator
|
|
623
|
+
to crash due to defensive safety checks that do not exist on the cartridge.
|
|
624
|
+
- **Transform**: Transform screws up the effect of Disable, because on Pokémon Showdown, Disable
|
|
643
625
|
prevents moves of a given *name* from being used (e.g. "Water Gun") as opposed to moves in a
|
|
644
626
|
specific *slot* (e.g. the 2nd move slot), and a Pokémon's moves can change after Transform (this
|
|
645
|
-
is not an issue with Disable + Mimic because Mimic happens to replace the same slot).
|
|
646
|
-
|
|
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
|
|
627
|
+
is not an issue with Disable + Mimic because Mimic happens to replace the same slot). Furthermore,
|
|
628
|
+
transforming and then using Mirror Move / Metronome can result in [glitchy behavior and
|
|
650
629
|
softlocks](https://pkmn.cc/bulba/Transform_glitches#Transform_.2B_Mirror_Move.2FMetronome_PP_error)
|
|
651
630
|
which Pokémon Showdown does not implement.
|
|
652
631
|
|
package/src/lib/gen1/data.zig
CHANGED
|
@@ -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
|
+
/// The slot index of the last selected moves for each side
|
|
59
|
+
last_selected_indexes: MoveIndexes = .{},
|
|
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
|
|
79
|
+
/// battle, optionally writing protocol logs to `log` if `options.trace` 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,19 +201,17 @@ pub const MoveSlot = extern struct {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
///
|
|
209
|
-
|
|
210
|
-
///
|
|
211
|
-
|
|
212
|
-
/// Whether the last move executed by Player 2 was counterable.
|
|
213
|
-
p2_counterable: if (showdown) u8 else u1 = 0,
|
|
204
|
+
const uindex = if (showdown) u16 else u4;
|
|
205
|
+
|
|
206
|
+
/// Representation of the move slot indexes for each side in a Generation I Pokémon battle.
|
|
207
|
+
pub const MoveIndexes = packed struct {
|
|
208
|
+
/// Player 1's move index.
|
|
209
|
+
p1: uindex = 0,
|
|
210
|
+
/// Player 1's move index.
|
|
211
|
+
p2: uindex = 0,
|
|
214
212
|
|
|
215
213
|
comptime {
|
|
216
|
-
assert(@sizeOf(
|
|
214
|
+
assert(@sizeOf(MoveIndexes) == if (showdown) 4 else 1);
|
|
217
215
|
}
|
|
218
216
|
};
|
|
219
217
|
|
package/src/lib/gen1/helpers.zig
CHANGED
|
@@ -55,12 +55,17 @@ pub const Battle = struct {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
pub fn random(rand: *PSRNG, opt: Options) data.Battle(data.PRNG) {
|
|
58
|
-
|
|
58
|
+
var p1: u4 = 0;
|
|
59
|
+
var p2: u4 = 0;
|
|
60
|
+
var battle: data.Battle(data.PRNG) = .{
|
|
59
61
|
.rng = prng(rand),
|
|
60
62
|
.turn = 0,
|
|
61
63
|
.last_damage = 0,
|
|
62
64
|
.sides = .{ Side.random(rand, opt), Side.random(rand, opt) },
|
|
63
65
|
};
|
|
66
|
+
battle.last_selected_indexes.p1 = p1;
|
|
67
|
+
battle.last_selected_indexes.p2 = p2;
|
|
68
|
+
return battle;
|
|
64
69
|
}
|
|
65
70
|
};
|
|
66
71
|
|
|
@@ -206,10 +211,16 @@ pub const Pokemon = struct {
|
|
|
206
211
|
}
|
|
207
212
|
};
|
|
208
213
|
|
|
214
|
+
// cat src/test/showdown/blocklist.json | jq '."1".moves'
|
|
209
215
|
fn blocked(m: Move) bool {
|
|
210
|
-
|
|
216
|
+
if (Move.get(m).effect == .Binding) return true;
|
|
211
217
|
return switch (m) {
|
|
212
|
-
.
|
|
218
|
+
.Counter,
|
|
219
|
+
.Mimic,
|
|
220
|
+
.Metronome,
|
|
221
|
+
.MirrorMove,
|
|
222
|
+
.Transform,
|
|
223
|
+
=> true,
|
|
213
224
|
else => false,
|
|
214
225
|
};
|
|
215
226
|
}
|