@pkmn/engine 0.1.0-dev.83de29ee → 0.1.0-dev.8b83af6b
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 +3 -3
- package/build/pkg/gen1.js +11 -3
- package/build/pkg/gen1.js.map +1 -1
- 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 +0 -1
- package/build/test/display.js.map +1 -1
- package/build.zig +7 -8
- package/package.json +14 -14
- package/src/bin/install-pkmn-engine +1 -1
- package/src/lib/binding/node.zig +17 -20
- package/src/lib/binding/wasm.zig +2 -2
- package/src/lib/common/data.zig +11 -11
- package/src/lib/common/protocol.zig +156 -140
- package/src/lib/common/rng.zig +5 -5
- package/src/lib/gen1/README.md +20 -14
- package/src/lib/gen1/data/moves.zig +10 -10
- package/src/lib/gen1/data/species.zig +2 -2
- package/src/lib/gen1/data/types.zig +3 -3
- package/src/lib/gen1/data.zig +19 -16
- package/src/lib/gen1/helpers.zig +10 -19
- package/src/lib/gen1/mechanics.zig +119 -101
- package/src/lib/gen2/data/items.zig +3 -3
- package/src/lib/gen2/data/moves.zig +1 -1
- package/src/lib/gen2/data/species.zig +1 -1
- package/src/lib/gen2/data/types.zig +3 -3
- package/src/lib/gen2/data.zig +12 -11
- package/src/lib/gen2/helpers.zig +6 -6
|
@@ -233,29 +233,29 @@ pub fn Log(comptime Writer: type) type {
|
|
|
233
233
|
if (!enabled) return;
|
|
234
234
|
assert(m != .None);
|
|
235
235
|
try self.writer.writeAll(&.{
|
|
236
|
-
@
|
|
237
|
-
@
|
|
238
|
-
@
|
|
239
|
-
@
|
|
236
|
+
@intFromEnum(ArgType.Move),
|
|
237
|
+
@as(u8, @bitCast(source)),
|
|
238
|
+
@intFromEnum(m),
|
|
239
|
+
@as(u8, @bitCast(target)),
|
|
240
240
|
});
|
|
241
|
-
const none = &[_]u8{@
|
|
241
|
+
const none = &[_]u8{@intFromEnum(Move.None)};
|
|
242
242
|
try self.writer.writeAll(switch (@typeInfo(@TypeOf(from))) {
|
|
243
243
|
.Null => none,
|
|
244
244
|
.Optional => if (from) |f| blk: {
|
|
245
|
-
assert(@
|
|
246
|
-
break :blk &[_]u8{ @
|
|
245
|
+
assert(@intFromEnum(f) != 0);
|
|
246
|
+
break :blk &[_]u8{ @intFromEnum(Move.From), @intFromEnum(f) };
|
|
247
247
|
} else none,
|
|
248
248
|
else => blk: {
|
|
249
|
-
assert(@
|
|
250
|
-
break :blk &[_]u8{ @
|
|
249
|
+
assert(@intFromEnum(from) != 0);
|
|
250
|
+
break :blk &[_]u8{ @intFromEnum(Move.From), @intFromEnum(from) };
|
|
251
251
|
},
|
|
252
252
|
});
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
pub fn switched(self: Self, ident: ID, pokemon: anytype) Error!void {
|
|
256
256
|
if (!enabled) return;
|
|
257
|
-
try self.writer.writeAll(&.{ @
|
|
258
|
-
try self.writer.writeAll(&.{ @
|
|
257
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Switch), @as(u8, @bitCast(ident)) });
|
|
258
|
+
try self.writer.writeAll(&.{ @intFromEnum(pokemon.species), pokemon.level });
|
|
259
259
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
260
260
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
261
261
|
try self.writer.writeAll(&.{pokemon.status});
|
|
@@ -265,56 +265,56 @@ pub fn Log(comptime Writer: type) type {
|
|
|
265
265
|
if (!enabled) return;
|
|
266
266
|
assert(reason != .Disable);
|
|
267
267
|
try self.writer.writeAll(&.{
|
|
268
|
-
@
|
|
269
|
-
@
|
|
270
|
-
@
|
|
268
|
+
@intFromEnum(ArgType.Cant),
|
|
269
|
+
@as(u8, @bitCast(ident)),
|
|
270
|
+
@intFromEnum(reason),
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
pub fn disabled(self: Self, ident: ID, m: anytype) Error!void {
|
|
275
275
|
if (!enabled) return;
|
|
276
276
|
try self.writer.writeAll(&.{
|
|
277
|
-
@
|
|
278
|
-
@
|
|
279
|
-
@
|
|
280
|
-
@
|
|
277
|
+
@intFromEnum(ArgType.Cant),
|
|
278
|
+
@as(u8, @bitCast(ident)),
|
|
279
|
+
@intFromEnum(Cant.Disable),
|
|
280
|
+
@intFromEnum(m),
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
pub fn faint(self: Self, ident: ID, done: bool) Error!void {
|
|
285
285
|
if (!enabled) return;
|
|
286
|
-
try self.writer.writeAll(&.{ @
|
|
287
|
-
if (done) try self.writer.writeByte(@
|
|
286
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Faint), @as(u8, @bitCast(ident)) });
|
|
287
|
+
if (done) try self.writer.writeByte(@intFromEnum(ArgType.None));
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
pub fn turn(self: Self, num: u16) Error!void {
|
|
291
291
|
if (!enabled) return;
|
|
292
|
-
try self.writer.writeByte(@
|
|
292
|
+
try self.writer.writeByte(@intFromEnum(ArgType.Turn));
|
|
293
293
|
try self.writer.writeIntNative(u16, num);
|
|
294
|
-
try self.writer.writeByte(@
|
|
294
|
+
try self.writer.writeByte(@intFromEnum(ArgType.None));
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
pub fn win(self: Self, player: Player) Error!void {
|
|
298
298
|
if (!enabled) return;
|
|
299
299
|
try self.writer.writeAll(&.{
|
|
300
|
-
@
|
|
301
|
-
@
|
|
302
|
-
@
|
|
300
|
+
@intFromEnum(ArgType.Win),
|
|
301
|
+
@intFromEnum(player),
|
|
302
|
+
@intFromEnum(ArgType.None),
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
pub fn tie(self: Self) Error!void {
|
|
307
307
|
if (!enabled) return;
|
|
308
|
-
try self.writer.writeAll(&.{ @
|
|
308
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Tie), @intFromEnum(ArgType.None) });
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
pub fn damage(self: Self, ident: ID, pokemon: anytype, reason: Damage) Error!void {
|
|
312
312
|
if (!enabled) return;
|
|
313
|
-
assert(@
|
|
314
|
-
try self.writer.writeAll(&.{ @
|
|
313
|
+
assert(@intFromEnum(reason) <= @intFromEnum(Damage.LeechSeed));
|
|
314
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @as(u8, @bitCast(ident)) });
|
|
315
315
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
316
316
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
317
|
-
try self.writer.writeAll(&.{ pokemon.status, @
|
|
317
|
+
try self.writer.writeAll(&.{ pokemon.status, @intFromEnum(reason) });
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
pub fn damageOf(
|
|
@@ -325,35 +325,35 @@ pub fn Log(comptime Writer: type) type {
|
|
|
325
325
|
source: ID,
|
|
326
326
|
) Error!void {
|
|
327
327
|
if (!enabled) return;
|
|
328
|
-
assert(@
|
|
329
|
-
try self.writer.writeAll(&.{ @
|
|
328
|
+
assert(@intFromEnum(reason) == @intFromEnum(Damage.RecoilOf));
|
|
329
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Damage), @as(u8, @bitCast(ident)) });
|
|
330
330
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
331
331
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
332
332
|
try self.writer.writeAll(&.{
|
|
333
333
|
pokemon.status,
|
|
334
|
-
@
|
|
335
|
-
@
|
|
334
|
+
@intFromEnum(reason),
|
|
335
|
+
@as(u8, @bitCast(source)),
|
|
336
336
|
});
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
pub fn heal(self: Self, ident: ID, pokemon: anytype, reason: Heal) Error!void {
|
|
340
340
|
if (!enabled) return;
|
|
341
341
|
assert(reason != .Drain);
|
|
342
|
-
try self.writer.writeAll(&.{ @
|
|
342
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(ident)) });
|
|
343
343
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
344
344
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
345
|
-
try self.writer.writeAll(&.{ pokemon.status, @
|
|
345
|
+
try self.writer.writeAll(&.{ pokemon.status, @intFromEnum(reason) });
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
pub fn drain(self: Self, source: ID, pokemon: anytype, target: ID) Error!void {
|
|
349
349
|
if (!enabled) return;
|
|
350
|
-
try self.writer.writeAll(&.{ @
|
|
350
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Heal), @as(u8, @bitCast(source)) });
|
|
351
351
|
try self.writer.writeIntNative(u16, pokemon.hp);
|
|
352
352
|
try self.writer.writeIntNative(u16, pokemon.stats.hp);
|
|
353
353
|
try self.writer.writeAll(&.{
|
|
354
354
|
pokemon.status,
|
|
355
|
-
@
|
|
356
|
-
@
|
|
355
|
+
@intFromEnum(Heal.Drain),
|
|
356
|
+
@as(u8, @bitCast(target)),
|
|
357
357
|
});
|
|
358
358
|
}
|
|
359
359
|
|
|
@@ -361,31 +361,31 @@ pub fn Log(comptime Writer: type) type {
|
|
|
361
361
|
if (!enabled) return;
|
|
362
362
|
assert(reason != .From);
|
|
363
363
|
try self.writer.writeAll(&.{
|
|
364
|
-
@
|
|
365
|
-
@
|
|
364
|
+
@intFromEnum(ArgType.Status),
|
|
365
|
+
@as(u8, @bitCast(ident)),
|
|
366
366
|
value,
|
|
367
|
-
@
|
|
367
|
+
@intFromEnum(reason),
|
|
368
368
|
});
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
pub fn statusFrom(self: Self, ident: ID, value: u8, m: anytype) Error!void {
|
|
372
372
|
if (!enabled) return;
|
|
373
373
|
try self.writer.writeAll(&.{
|
|
374
|
-
@
|
|
375
|
-
@
|
|
374
|
+
@intFromEnum(ArgType.Status),
|
|
375
|
+
@as(u8, @bitCast(ident)),
|
|
376
376
|
value,
|
|
377
|
-
@
|
|
378
|
-
@
|
|
377
|
+
@intFromEnum(Status.From),
|
|
378
|
+
@intFromEnum(m),
|
|
379
379
|
});
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
pub fn curestatus(self: Self, ident: ID, value: u8, reason: CureStatus) Error!void {
|
|
383
383
|
if (!enabled) return;
|
|
384
384
|
try self.writer.writeAll(&.{
|
|
385
|
-
@
|
|
386
|
-
@
|
|
385
|
+
@intFromEnum(ArgType.CureStatus),
|
|
386
|
+
@as(u8, @bitCast(ident)),
|
|
387
387
|
value,
|
|
388
|
-
@
|
|
388
|
+
@intFromEnum(reason),
|
|
389
389
|
});
|
|
390
390
|
}
|
|
391
391
|
|
|
@@ -393,152 +393,165 @@ pub fn Log(comptime Writer: type) type {
|
|
|
393
393
|
if (!enabled) return;
|
|
394
394
|
assert(num != 0 and (reason != .Rage or num > 0));
|
|
395
395
|
try self.writer.writeAll(&.{
|
|
396
|
-
@
|
|
397
|
-
@
|
|
398
|
-
@
|
|
399
|
-
@
|
|
396
|
+
@intFromEnum(ArgType.Boost),
|
|
397
|
+
@as(u8, @bitCast(ident)),
|
|
398
|
+
@intFromEnum(reason),
|
|
399
|
+
@as(u8, @intCast(num + 6)),
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
pub fn clearallboost(self: Self) Error!void {
|
|
404
404
|
if (!enabled) return;
|
|
405
|
-
try self.writer.writeAll(&.{@
|
|
405
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.ClearAllBoost)});
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
pub fn fail(self: Self, ident: ID, reason: Fail) Error!void {
|
|
409
409
|
if (!enabled) return;
|
|
410
410
|
try self.writer.writeAll(&.{
|
|
411
|
-
@
|
|
412
|
-
@
|
|
413
|
-
@
|
|
411
|
+
@intFromEnum(ArgType.Fail),
|
|
412
|
+
@as(u8, @bitCast(ident)),
|
|
413
|
+
@intFromEnum(reason),
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
pub fn miss(self: Self, source: ID) Error!void {
|
|
418
418
|
if (!enabled) return;
|
|
419
|
-
try self.writer.writeAll(&.{ @
|
|
419
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Miss), @as(u8, @bitCast(source)) });
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
pub fn hitcount(self: Self, ident: ID, num: u8) Error!void {
|
|
423
423
|
if (!enabled) return;
|
|
424
|
-
try self.writer.writeAll(&.{
|
|
424
|
+
try self.writer.writeAll(&.{
|
|
425
|
+
@intFromEnum(ArgType.HitCount),
|
|
426
|
+
@as(u8, @bitCast(ident)),
|
|
427
|
+
num,
|
|
428
|
+
});
|
|
425
429
|
}
|
|
426
430
|
|
|
427
431
|
pub fn prepare(self: Self, source: ID, m: anytype) Error!void {
|
|
428
432
|
if (!enabled) return;
|
|
429
433
|
try self.writer.writeAll(&.{
|
|
430
|
-
@
|
|
431
|
-
@
|
|
432
|
-
@
|
|
434
|
+
@intFromEnum(ArgType.Prepare),
|
|
435
|
+
@as(u8, @bitCast(source)),
|
|
436
|
+
@intFromEnum(m),
|
|
433
437
|
});
|
|
434
438
|
}
|
|
435
439
|
|
|
436
440
|
pub fn mustrecharge(self: Self, ident: ID) Error!void {
|
|
437
441
|
if (!enabled) return;
|
|
438
|
-
try self.writer.writeAll(&.{
|
|
442
|
+
try self.writer.writeAll(&.{
|
|
443
|
+
@intFromEnum(ArgType.MustRecharge),
|
|
444
|
+
@as(u8, @bitCast(ident)),
|
|
445
|
+
});
|
|
439
446
|
}
|
|
440
447
|
|
|
441
448
|
pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
|
|
442
449
|
if (!enabled) return;
|
|
443
450
|
try self.writer.writeAll(&.{
|
|
444
|
-
@
|
|
445
|
-
@
|
|
446
|
-
@
|
|
451
|
+
@intFromEnum(ArgType.Activate),
|
|
452
|
+
@as(u8, @bitCast(ident)),
|
|
453
|
+
@intFromEnum(reason),
|
|
447
454
|
});
|
|
448
455
|
}
|
|
449
456
|
|
|
450
457
|
pub fn fieldactivate(self: Self) Error!void {
|
|
451
458
|
if (!enabled) return;
|
|
452
|
-
try self.writer.writeAll(&.{@
|
|
459
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.FieldActivate)});
|
|
453
460
|
}
|
|
454
461
|
|
|
455
462
|
pub fn start(self: Self, ident: ID, reason: Start) Error!void {
|
|
456
463
|
if (!enabled) return;
|
|
457
|
-
assert(@
|
|
464
|
+
assert(@intFromEnum(reason) < @intFromEnum(Start.TypeChange));
|
|
458
465
|
try self.writer.writeAll(&.{
|
|
459
|
-
@
|
|
460
|
-
@
|
|
461
|
-
@
|
|
466
|
+
@intFromEnum(ArgType.Start),
|
|
467
|
+
@as(u8, @bitCast(ident)),
|
|
468
|
+
@intFromEnum(reason),
|
|
462
469
|
});
|
|
463
470
|
}
|
|
464
471
|
|
|
465
472
|
pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
|
|
466
473
|
if (!enabled) return;
|
|
467
474
|
try self.writer.writeAll(&.{
|
|
468
|
-
@
|
|
469
|
-
@
|
|
470
|
-
@
|
|
471
|
-
@
|
|
472
|
-
@
|
|
475
|
+
@intFromEnum(ArgType.Start),
|
|
476
|
+
@as(u8, @bitCast(source)),
|
|
477
|
+
@intFromEnum(Start.TypeChange),
|
|
478
|
+
@as(u8, @bitCast(types)),
|
|
479
|
+
@as(u8, @bitCast(target)),
|
|
473
480
|
});
|
|
474
481
|
}
|
|
475
482
|
|
|
476
483
|
pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
|
|
477
484
|
if (!enabled) return;
|
|
478
|
-
assert(@
|
|
485
|
+
assert(@intFromEnum(reason) > @intFromEnum(Start.TypeChange));
|
|
479
486
|
try self.writer.writeAll(&.{
|
|
480
|
-
@
|
|
481
|
-
@
|
|
482
|
-
@
|
|
483
|
-
@
|
|
487
|
+
@intFromEnum(ArgType.Start),
|
|
488
|
+
@as(u8, @bitCast(ident)),
|
|
489
|
+
@intFromEnum(reason),
|
|
490
|
+
@intFromEnum(m),
|
|
484
491
|
});
|
|
485
492
|
}
|
|
486
493
|
|
|
487
494
|
pub fn end(self: Self, ident: ID, reason: End) Error!void {
|
|
488
495
|
if (!enabled) return;
|
|
489
496
|
try self.writer.writeAll(&.{
|
|
490
|
-
@
|
|
491
|
-
@
|
|
492
|
-
@
|
|
497
|
+
@intFromEnum(ArgType.End),
|
|
498
|
+
@as(u8, @bitCast(ident)),
|
|
499
|
+
@intFromEnum(reason),
|
|
493
500
|
});
|
|
494
501
|
}
|
|
495
502
|
|
|
496
503
|
pub fn ohko(self: Self) Error!void {
|
|
497
504
|
if (!enabled) return;
|
|
498
|
-
try self.writer.writeAll(&.{@
|
|
505
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.OHKO)});
|
|
499
506
|
}
|
|
500
507
|
|
|
501
508
|
pub fn crit(self: Self, ident: ID) Error!void {
|
|
502
509
|
if (!enabled) return;
|
|
503
|
-
try self.writer.writeAll(&.{ @
|
|
510
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Crit), @as(u8, @bitCast(ident)) });
|
|
504
511
|
}
|
|
505
512
|
|
|
506
513
|
pub fn supereffective(self: Self, ident: ID) Error!void {
|
|
507
514
|
if (!enabled) return;
|
|
508
|
-
try self.writer.writeAll(&.{
|
|
515
|
+
try self.writer.writeAll(&.{
|
|
516
|
+
@intFromEnum(ArgType.SuperEffective),
|
|
517
|
+
@as(u8, @bitCast(ident)),
|
|
518
|
+
});
|
|
509
519
|
}
|
|
510
520
|
|
|
511
521
|
pub fn resisted(self: Self, ident: ID) Error!void {
|
|
512
522
|
if (!enabled) return;
|
|
513
|
-
try self.writer.writeAll(&.{
|
|
523
|
+
try self.writer.writeAll(&.{
|
|
524
|
+
@intFromEnum(ArgType.Resisted),
|
|
525
|
+
@as(u8, @bitCast(ident)),
|
|
526
|
+
});
|
|
514
527
|
}
|
|
515
528
|
|
|
516
529
|
pub fn immune(self: Self, ident: ID, reason: Immune) Error!void {
|
|
517
530
|
if (!enabled) return;
|
|
518
531
|
try self.writer.writeAll(&.{
|
|
519
|
-
@
|
|
520
|
-
@
|
|
521
|
-
@
|
|
532
|
+
@intFromEnum(ArgType.Immune),
|
|
533
|
+
@as(u8, @bitCast(ident)),
|
|
534
|
+
@intFromEnum(reason),
|
|
522
535
|
});
|
|
523
536
|
}
|
|
524
537
|
|
|
525
538
|
pub fn transform(self: Self, source: ID, target: ID) Error!void {
|
|
526
539
|
if (!enabled) return;
|
|
527
540
|
try self.writer.writeAll(&.{
|
|
528
|
-
@
|
|
529
|
-
@
|
|
530
|
-
@
|
|
541
|
+
@intFromEnum(ArgType.Transform),
|
|
542
|
+
@as(u8, @bitCast(source)),
|
|
543
|
+
@as(u8, @bitCast(target)),
|
|
531
544
|
});
|
|
532
545
|
}
|
|
533
546
|
|
|
534
547
|
pub fn laststill(self: Self) Error!void {
|
|
535
548
|
if (!enabled) return;
|
|
536
|
-
try self.writer.writeAll(&.{@
|
|
549
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastStill)});
|
|
537
550
|
}
|
|
538
551
|
|
|
539
552
|
pub fn lastmiss(self: Self) Error!void {
|
|
540
553
|
if (!enabled) return;
|
|
541
|
-
try self.writer.writeAll(&.{@
|
|
554
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastMiss)});
|
|
542
555
|
}
|
|
543
556
|
};
|
|
544
557
|
}
|
|
@@ -593,7 +606,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
593
606
|
|
|
594
607
|
var i: usize = 0;
|
|
595
608
|
while (i < a.len) {
|
|
596
|
-
const arg = @
|
|
609
|
+
const arg: ArgType = @enumFromInt(a[i]);
|
|
597
610
|
const name = switch (arg) {
|
|
598
611
|
.None => if (color) "\x1b[2m-\x1b[0m" else "-",
|
|
599
612
|
.LastStill => "|[still]",
|
|
@@ -639,17 +652,17 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
639
652
|
.OHKO,
|
|
640
653
|
=> {},
|
|
641
654
|
.Move => {
|
|
642
|
-
const source = ID.from(@intCast(
|
|
655
|
+
const source = ID.from(@intCast(a[i]));
|
|
643
656
|
printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
|
|
644
657
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
645
|
-
const target = ID.from(@intCast(
|
|
658
|
+
const target = ID.from(@intCast(a[i]));
|
|
646
659
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
647
|
-
const reason = @
|
|
660
|
+
const reason: Move = @enumFromInt(a[i]);
|
|
648
661
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
649
662
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
650
663
|
},
|
|
651
664
|
.Switch => {
|
|
652
|
-
const id = ID.from(@intCast(
|
|
665
|
+
const id = ID.from(@intCast(a[i]));
|
|
653
666
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
654
667
|
printc(" {s}", .{formatter(.Species, a[i])}, a, b, &i, 1, color);
|
|
655
668
|
printc(" L{d}", .{a[i]}, a, b, &i, 1, color);
|
|
@@ -670,9 +683,9 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
670
683
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
671
684
|
},
|
|
672
685
|
.Cant => {
|
|
673
|
-
const id = ID.from(@intCast(
|
|
686
|
+
const id = ID.from(@intCast(a[i]));
|
|
674
687
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
675
|
-
const reason = @
|
|
688
|
+
const reason: Cant = @enumFromInt(a[i]);
|
|
676
689
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
677
690
|
if (reason == .Disable) {
|
|
678
691
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
@@ -685,7 +698,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
685
698
|
.SuperEffective,
|
|
686
699
|
.Resisted,
|
|
687
700
|
=> {
|
|
688
|
-
const id = ID.from(@intCast(
|
|
701
|
+
const id = ID.from(@intCast(a[i]));
|
|
689
702
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
690
703
|
},
|
|
691
704
|
.Turn => {
|
|
@@ -695,9 +708,11 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
695
708
|
};
|
|
696
709
|
printc(" {d}", .{turn}, a, b, &i, 2, color);
|
|
697
710
|
},
|
|
698
|
-
.Win =>
|
|
711
|
+
.Win => {
|
|
712
|
+
printc(" {s}", .{@tagName(@as(Player, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
713
|
+
},
|
|
699
714
|
.Damage, .Heal => {
|
|
700
|
-
var id = ID.from(@intCast(
|
|
715
|
+
var id = ID.from(@intCast(a[i]));
|
|
701
716
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
702
717
|
switch (endian) {
|
|
703
718
|
.Big => {
|
|
@@ -715,91 +730,92 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
715
730
|
}
|
|
716
731
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
717
732
|
if (arg == .Damage) {
|
|
718
|
-
const reason = a[i];
|
|
719
|
-
printc(" {s}", .{@tagName(
|
|
720
|
-
if (reason ==
|
|
721
|
-
id = ID.from(@intCast(
|
|
733
|
+
const reason: Damage = @enumFromInt(a[i]);
|
|
734
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
735
|
+
if (reason == .RecoilOf) {
|
|
736
|
+
id = ID.from(@intCast(a[i]));
|
|
722
737
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
723
738
|
}
|
|
724
739
|
} else {
|
|
725
|
-
const reason = @
|
|
740
|
+
const reason: Heal = @enumFromInt(a[i]);
|
|
726
741
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
727
742
|
if (reason == .Drain) {
|
|
728
|
-
id = ID.from(@intCast(
|
|
743
|
+
id = ID.from(@intCast(a[i]));
|
|
729
744
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
730
745
|
}
|
|
731
746
|
}
|
|
732
747
|
},
|
|
733
748
|
.Status => {
|
|
734
|
-
const id = ID.from(@intCast(
|
|
749
|
+
const id = ID.from(@intCast(a[i]));
|
|
735
750
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
736
751
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
737
|
-
const reason = @
|
|
752
|
+
const reason: Status = @enumFromInt(a[i]);
|
|
738
753
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
739
754
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
740
755
|
},
|
|
741
756
|
.CureStatus => {
|
|
742
|
-
const id = ID.from(@intCast(
|
|
757
|
+
const id = ID.from(@intCast(a[i]));
|
|
743
758
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
744
759
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
745
|
-
|
|
760
|
+
const reason: CureStatus = @enumFromInt(a[i]);
|
|
761
|
+
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
746
762
|
},
|
|
747
763
|
.Boost => {
|
|
748
|
-
const id = ID.from(@intCast(
|
|
764
|
+
const id = ID.from(@intCast(a[i]));
|
|
749
765
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
750
|
-
printc(" {s}", .{@tagName(@
|
|
766
|
+
printc(" {s}", .{@tagName(@as(Boost, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
751
767
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
752
768
|
},
|
|
753
769
|
.Fail => {
|
|
754
|
-
const id = ID.from(@intCast(
|
|
770
|
+
const id = ID.from(@intCast(a[i]));
|
|
755
771
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
756
|
-
printc(" {s}", .{@tagName(@
|
|
772
|
+
printc(" {s}", .{@tagName(@as(Fail, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
757
773
|
},
|
|
758
774
|
.HitCount => {
|
|
759
|
-
const id = ID.from(@intCast(
|
|
775
|
+
const id = ID.from(@intCast(a[i]));
|
|
760
776
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
761
777
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
762
778
|
},
|
|
763
779
|
.Prepare => {
|
|
764
|
-
const id = ID.from(@intCast(
|
|
780
|
+
const id = ID.from(@intCast(a[i]));
|
|
765
781
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
766
782
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
767
783
|
},
|
|
768
784
|
.Activate => {
|
|
769
|
-
const id = ID.from(@intCast(
|
|
785
|
+
const id = ID.from(@intCast(a[i]));
|
|
770
786
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
771
|
-
printc(" {s}", .{@tagName(@
|
|
787
|
+
printc(" {s}", .{@tagName(@as(Activate, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
772
788
|
},
|
|
773
789
|
.Start => {
|
|
774
|
-
const id = ID.from(@intCast(
|
|
790
|
+
const id = ID.from(@intCast(a[i]));
|
|
775
791
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
776
792
|
const reason = a[i];
|
|
777
|
-
printc(" {s}", .{@tagName(@
|
|
778
|
-
if (@
|
|
779
|
-
const types = @
|
|
793
|
+
printc(" {s}", .{@tagName(@as(Start, @enumFromInt(reason)))}, a, b, &i, 1, color);
|
|
794
|
+
if (@as(Start, @enumFromInt(reason)) == .TypeChange) {
|
|
795
|
+
const types = @as(gen1.Types, @bitCast(a[i]));
|
|
780
796
|
const args = .{
|
|
781
|
-
formatter(.Type, @
|
|
782
|
-
formatter(.Type, @
|
|
797
|
+
formatter(.Type, @intFromEnum(types.type1)),
|
|
798
|
+
formatter(.Type, @intFromEnum(types.type2)),
|
|
783
799
|
};
|
|
784
800
|
printc(" {s}/{s}", args, a, b, &i, 1, color);
|
|
785
|
-
} else if (reason >= @
|
|
801
|
+
} else if (reason >= @intFromEnum(Start.Disable)) {
|
|
786
802
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
787
803
|
}
|
|
788
804
|
},
|
|
789
805
|
.End => {
|
|
790
|
-
const id = ID.from(@intCast(
|
|
806
|
+
const id = ID.from(@intCast(a[i]));
|
|
791
807
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
792
|
-
printc(" {s}", .{@tagName(@
|
|
808
|
+
printc(" {s}", .{@tagName(@as(End, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
793
809
|
},
|
|
794
810
|
.Immune => {
|
|
795
|
-
const id = ID.from(@intCast(
|
|
811
|
+
const id = ID.from(@intCast(a[i]));
|
|
796
812
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
797
|
-
printc(" {s}", .{@tagName(@
|
|
813
|
+
printc(" {s}", .{@tagName(@as(Immune, @enumFromInt(a[i])))}, a, b, &i, 1, color);
|
|
798
814
|
},
|
|
799
815
|
.Transform => {
|
|
800
|
-
const source = ID.from(@intCast(
|
|
816
|
+
const source = ID.from(@intCast(a[i]));
|
|
801
817
|
printc(" {s}({d})", .{ @tagName(source.player), source.id }, a, b, &i, 1, color);
|
|
802
|
-
const target = ID.from(@intCast(
|
|
818
|
+
const target = ID.from(@intCast(a[i]));
|
|
803
819
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
804
820
|
},
|
|
805
821
|
else => unreachable,
|
|
@@ -881,7 +897,7 @@ fn expectEqualBytes(expected: []const u8, actual: []const u8, offset: usize) !vo
|
|
|
881
897
|
const endian = builtin.target.cpu.arch.endian();
|
|
882
898
|
|
|
883
899
|
fn N(e: anytype) u8 {
|
|
884
|
-
return @
|
|
900
|
+
return @intFromEnum(e);
|
|
885
901
|
}
|
|
886
902
|
|
|
887
903
|
const p1 = Player.P1;
|
|
@@ -905,9 +921,9 @@ fn expectLog1(expected: []const u8, actual: []const u8) !void {
|
|
|
905
921
|
|
|
906
922
|
fn gen1Formatter(kind: Kind, byte: u8) []const u8 {
|
|
907
923
|
return switch (kind) {
|
|
908
|
-
.Move => @tagName(@
|
|
909
|
-
.Species => @tagName(@
|
|
910
|
-
.Type => @tagName(@
|
|
924
|
+
.Move => @tagName(@as(M, @enumFromInt(byte))),
|
|
925
|
+
.Species => @tagName(@as(S, @enumFromInt(byte))),
|
|
926
|
+
.Type => @tagName(@as(gen1.Type, @enumFromInt(byte))),
|
|
911
927
|
.Status => gen1.Status.name(byte),
|
|
912
928
|
};
|
|
913
929
|
}
|