@pkmn/engine 0.1.0-dev.93b7cb0d → 0.1.0-dev.942dbfa4
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.map +1 -1
- package/build/pkg/index.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 +2 -2
- package/src/lib/common/data.zig +1 -1
- package/src/lib/common/protocol.zig +102 -95
- package/src/lib/gen1/README.md +3 -1
- 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 +2 -2
- package/src/lib/gen1/data.zig +13 -11
- package/src/lib/gen1/helpers.zig +2 -2
- package/src/lib/gen1/mechanics.zig +27 -27
- 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 +8 -8
- package/src/lib/gen2/helpers.zig +3 -3
|
@@ -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
|
-
@
|
|
236
|
+
@intFromEnum(ArgType.Move),
|
|
237
237
|
@bitCast(u8, source),
|
|
238
|
-
@
|
|
238
|
+
@intFromEnum(m),
|
|
239
239
|
@bitCast(u8, 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), @bitCast(u8, 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
|
-
@
|
|
268
|
+
@intFromEnum(ArgType.Cant),
|
|
269
269
|
@bitCast(u8, ident),
|
|
270
|
-
@
|
|
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
|
-
@
|
|
277
|
+
@intFromEnum(ArgType.Cant),
|
|
278
278
|
@bitCast(u8, ident),
|
|
279
|
-
@
|
|
280
|
-
@
|
|
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), @bitCast(u8, 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), @bitCast(u8, 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,13 +325,13 @@ 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), @bitCast(u8, 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
|
-
@
|
|
334
|
+
@intFromEnum(reason),
|
|
335
335
|
@bitCast(u8, source),
|
|
336
336
|
});
|
|
337
337
|
}
|
|
@@ -339,20 +339,20 @@ pub fn Log(comptime Writer: type) type {
|
|
|
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), @bitCast(u8, 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), @bitCast(u8, 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
|
-
@
|
|
355
|
+
@intFromEnum(Heal.Drain),
|
|
356
356
|
@bitCast(u8, target),
|
|
357
357
|
});
|
|
358
358
|
}
|
|
@@ -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
|
-
@
|
|
364
|
+
@intFromEnum(ArgType.Status),
|
|
365
365
|
@bitCast(u8, 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
|
-
@
|
|
374
|
+
@intFromEnum(ArgType.Status),
|
|
375
375
|
@bitCast(u8, 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
|
-
@
|
|
385
|
+
@intFromEnum(ArgType.CureStatus),
|
|
386
386
|
@bitCast(u8, ident),
|
|
387
387
|
value,
|
|
388
|
-
@
|
|
388
|
+
@intFromEnum(reason),
|
|
389
389
|
});
|
|
390
390
|
}
|
|
391
391
|
|
|
@@ -393,81 +393,85 @@ 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
|
-
@
|
|
396
|
+
@intFromEnum(ArgType.Boost),
|
|
397
397
|
@bitCast(u8, ident),
|
|
398
|
-
@
|
|
398
|
+
@intFromEnum(reason),
|
|
399
399
|
@intCast(u8, 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
|
-
@
|
|
411
|
+
@intFromEnum(ArgType.Fail),
|
|
412
412
|
@bitCast(u8, ident),
|
|
413
|
-
@
|
|
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), @bitCast(u8, 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
|
+
@bitCast(u8, 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
|
-
@
|
|
434
|
+
@intFromEnum(ArgType.Prepare),
|
|
431
435
|
@bitCast(u8, source),
|
|
432
|
-
@
|
|
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(&.{ @intFromEnum(ArgType.MustRecharge), @bitCast(u8, ident) });
|
|
439
443
|
}
|
|
440
444
|
|
|
441
445
|
pub fn activate(self: Self, ident: ID, reason: Activate) Error!void {
|
|
442
446
|
if (!enabled) return;
|
|
443
447
|
try self.writer.writeAll(&.{
|
|
444
|
-
@
|
|
448
|
+
@intFromEnum(ArgType.Activate),
|
|
445
449
|
@bitCast(u8, ident),
|
|
446
|
-
@
|
|
450
|
+
@intFromEnum(reason),
|
|
447
451
|
});
|
|
448
452
|
}
|
|
449
453
|
|
|
450
454
|
pub fn fieldactivate(self: Self) Error!void {
|
|
451
455
|
if (!enabled) return;
|
|
452
|
-
try self.writer.writeAll(&.{@
|
|
456
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.FieldActivate)});
|
|
453
457
|
}
|
|
454
458
|
|
|
455
459
|
pub fn start(self: Self, ident: ID, reason: Start) Error!void {
|
|
456
460
|
if (!enabled) return;
|
|
457
|
-
assert(@
|
|
461
|
+
assert(@intFromEnum(reason) < @intFromEnum(Start.TypeChange));
|
|
458
462
|
try self.writer.writeAll(&.{
|
|
459
|
-
@
|
|
463
|
+
@intFromEnum(ArgType.Start),
|
|
460
464
|
@bitCast(u8, ident),
|
|
461
|
-
@
|
|
465
|
+
@intFromEnum(reason),
|
|
462
466
|
});
|
|
463
467
|
}
|
|
464
468
|
|
|
465
469
|
pub fn typechange(self: Self, source: ID, types: anytype, target: ID) Error!void {
|
|
466
470
|
if (!enabled) return;
|
|
467
471
|
try self.writer.writeAll(&.{
|
|
468
|
-
@
|
|
472
|
+
@intFromEnum(ArgType.Start),
|
|
469
473
|
@bitCast(u8, source),
|
|
470
|
-
@
|
|
474
|
+
@intFromEnum(Start.TypeChange),
|
|
471
475
|
@bitCast(u8, types),
|
|
472
476
|
@bitCast(u8, target),
|
|
473
477
|
});
|
|
@@ -475,57 +479,60 @@ pub fn Log(comptime Writer: type) type {
|
|
|
475
479
|
|
|
476
480
|
pub fn startEffect(self: Self, ident: ID, reason: Start, m: anytype) Error!void {
|
|
477
481
|
if (!enabled) return;
|
|
478
|
-
assert(@
|
|
482
|
+
assert(@intFromEnum(reason) > @intFromEnum(Start.TypeChange));
|
|
479
483
|
try self.writer.writeAll(&.{
|
|
480
|
-
@
|
|
484
|
+
@intFromEnum(ArgType.Start),
|
|
481
485
|
@bitCast(u8, ident),
|
|
482
|
-
@
|
|
483
|
-
@
|
|
486
|
+
@intFromEnum(reason),
|
|
487
|
+
@intFromEnum(m),
|
|
484
488
|
});
|
|
485
489
|
}
|
|
486
490
|
|
|
487
491
|
pub fn end(self: Self, ident: ID, reason: End) Error!void {
|
|
488
492
|
if (!enabled) return;
|
|
489
493
|
try self.writer.writeAll(&.{
|
|
490
|
-
@
|
|
494
|
+
@intFromEnum(ArgType.End),
|
|
491
495
|
@bitCast(u8, ident),
|
|
492
|
-
@
|
|
496
|
+
@intFromEnum(reason),
|
|
493
497
|
});
|
|
494
498
|
}
|
|
495
499
|
|
|
496
500
|
pub fn ohko(self: Self) Error!void {
|
|
497
501
|
if (!enabled) return;
|
|
498
|
-
try self.writer.writeAll(&.{@
|
|
502
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.OHKO)});
|
|
499
503
|
}
|
|
500
504
|
|
|
501
505
|
pub fn crit(self: Self, ident: ID) Error!void {
|
|
502
506
|
if (!enabled) return;
|
|
503
|
-
try self.writer.writeAll(&.{ @
|
|
507
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Crit), @bitCast(u8, ident) });
|
|
504
508
|
}
|
|
505
509
|
|
|
506
510
|
pub fn supereffective(self: Self, ident: ID) Error!void {
|
|
507
511
|
if (!enabled) return;
|
|
508
|
-
try self.writer.writeAll(&.{
|
|
512
|
+
try self.writer.writeAll(&.{
|
|
513
|
+
@intFromEnum(ArgType.SuperEffective),
|
|
514
|
+
@bitCast(u8, ident),
|
|
515
|
+
});
|
|
509
516
|
}
|
|
510
517
|
|
|
511
518
|
pub fn resisted(self: Self, ident: ID) Error!void {
|
|
512
519
|
if (!enabled) return;
|
|
513
|
-
try self.writer.writeAll(&.{ @
|
|
520
|
+
try self.writer.writeAll(&.{ @intFromEnum(ArgType.Resisted), @bitCast(u8, ident) });
|
|
514
521
|
}
|
|
515
522
|
|
|
516
523
|
pub fn immune(self: Self, ident: ID, reason: Immune) Error!void {
|
|
517
524
|
if (!enabled) return;
|
|
518
525
|
try self.writer.writeAll(&.{
|
|
519
|
-
@
|
|
526
|
+
@intFromEnum(ArgType.Immune),
|
|
520
527
|
@bitCast(u8, ident),
|
|
521
|
-
@
|
|
528
|
+
@intFromEnum(reason),
|
|
522
529
|
});
|
|
523
530
|
}
|
|
524
531
|
|
|
525
532
|
pub fn transform(self: Self, source: ID, target: ID) Error!void {
|
|
526
533
|
if (!enabled) return;
|
|
527
534
|
try self.writer.writeAll(&.{
|
|
528
|
-
@
|
|
535
|
+
@intFromEnum(ArgType.Transform),
|
|
529
536
|
@bitCast(u8, source),
|
|
530
537
|
@bitCast(u8, target),
|
|
531
538
|
});
|
|
@@ -533,12 +540,12 @@ pub fn Log(comptime Writer: type) type {
|
|
|
533
540
|
|
|
534
541
|
pub fn laststill(self: Self) Error!void {
|
|
535
542
|
if (!enabled) return;
|
|
536
|
-
try self.writer.writeAll(&.{@
|
|
543
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastStill)});
|
|
537
544
|
}
|
|
538
545
|
|
|
539
546
|
pub fn lastmiss(self: Self) Error!void {
|
|
540
547
|
if (!enabled) return;
|
|
541
|
-
try self.writer.writeAll(&.{@
|
|
548
|
+
try self.writer.writeAll(&.{@intFromEnum(ArgType.LastMiss)});
|
|
542
549
|
}
|
|
543
550
|
};
|
|
544
551
|
}
|
|
@@ -593,7 +600,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
593
600
|
|
|
594
601
|
var i: usize = 0;
|
|
595
602
|
while (i < a.len) {
|
|
596
|
-
const arg = @
|
|
603
|
+
const arg = @enumFromInt(ArgType, a[i]);
|
|
597
604
|
const name = switch (arg) {
|
|
598
605
|
.None => if (color) "\x1b[2m-\x1b[0m" else "-",
|
|
599
606
|
.LastStill => "|[still]",
|
|
@@ -644,7 +651,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
644
651
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
645
652
|
const target = ID.from(@intCast(u4, a[i]));
|
|
646
653
|
printc(" {s}({d})", .{ @tagName(target.player), target.id }, a, b, &i, 1, color);
|
|
647
|
-
const reason = @
|
|
654
|
+
const reason = @enumFromInt(Move, a[i]);
|
|
648
655
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
649
656
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
650
657
|
},
|
|
@@ -672,7 +679,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
672
679
|
.Cant => {
|
|
673
680
|
const id = ID.from(@intCast(u4, a[i]));
|
|
674
681
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
675
|
-
const reason = @
|
|
682
|
+
const reason = @enumFromInt(Cant, a[i]);
|
|
676
683
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
677
684
|
if (reason == .Disable) {
|
|
678
685
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
@@ -695,7 +702,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
695
702
|
};
|
|
696
703
|
printc(" {d}", .{turn}, a, b, &i, 2, color);
|
|
697
704
|
},
|
|
698
|
-
.Win => printc(" {s}", .{@tagName(@
|
|
705
|
+
.Win => printc(" {s}", .{@tagName(@enumFromInt(Player, a[i]))}, a, b, &i, 1, color),
|
|
699
706
|
.Damage, .Heal => {
|
|
700
707
|
var id = ID.from(@intCast(u4, a[i]));
|
|
701
708
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
@@ -716,13 +723,13 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
716
723
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
717
724
|
if (arg == .Damage) {
|
|
718
725
|
const reason = a[i];
|
|
719
|
-
printc(" {s}", .{@tagName(@
|
|
720
|
-
if (reason == @
|
|
726
|
+
printc(" {s}", .{@tagName(@enumFromInt(Damage, reason))}, a, b, &i, 1, color);
|
|
727
|
+
if (reason == @intFromEnum(Damage.RecoilOf)) {
|
|
721
728
|
id = ID.from(@intCast(u4, a[i]));
|
|
722
729
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
723
730
|
}
|
|
724
731
|
} else {
|
|
725
|
-
const reason = @
|
|
732
|
+
const reason = @enumFromInt(Heal, a[i]);
|
|
726
733
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
727
734
|
if (reason == .Drain) {
|
|
728
735
|
id = ID.from(@intCast(u4, a[i]));
|
|
@@ -734,7 +741,7 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
734
741
|
const id = ID.from(@intCast(u4, a[i]));
|
|
735
742
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
736
743
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
737
|
-
const reason = @
|
|
744
|
+
const reason = @enumFromInt(Status, a[i]);
|
|
738
745
|
printc(" {s}", .{@tagName(reason)}, a, b, &i, 1, color);
|
|
739
746
|
if (reason == .From) printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
740
747
|
},
|
|
@@ -742,18 +749,18 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
742
749
|
const id = ID.from(@intCast(u4, a[i]));
|
|
743
750
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
744
751
|
printc(" {s}", .{formatter(.Status, a[i])}, a, b, &i, 1, color);
|
|
745
|
-
printc(" {s}", .{@tagName(@
|
|
752
|
+
printc(" {s}", .{@tagName(@enumFromInt(CureStatus, a[i]))}, a, b, &i, 1, color);
|
|
746
753
|
},
|
|
747
754
|
.Boost => {
|
|
748
755
|
const id = ID.from(@intCast(u4, a[i]));
|
|
749
756
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
750
|
-
printc(" {s}", .{@tagName(@
|
|
757
|
+
printc(" {s}", .{@tagName(@enumFromInt(Boost, a[i]))}, a, b, &i, 1, color);
|
|
751
758
|
printc(" {d}", .{a[i]}, a, b, &i, 1, color);
|
|
752
759
|
},
|
|
753
760
|
.Fail => {
|
|
754
761
|
const id = ID.from(@intCast(u4, a[i]));
|
|
755
762
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
756
|
-
printc(" {s}", .{@tagName(@
|
|
763
|
+
printc(" {s}", .{@tagName(@enumFromInt(Fail, a[i]))}, a, b, &i, 1, color);
|
|
757
764
|
},
|
|
758
765
|
.HitCount => {
|
|
759
766
|
const id = ID.from(@intCast(u4, a[i]));
|
|
@@ -768,33 +775,33 @@ pub fn format(comptime formatter: Formatter, a: []const u8, b: ?[]const u8, colo
|
|
|
768
775
|
.Activate => {
|
|
769
776
|
const id = ID.from(@intCast(u4, a[i]));
|
|
770
777
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
771
|
-
printc(" {s}", .{@tagName(@
|
|
778
|
+
printc(" {s}", .{@tagName(@enumFromInt(Activate, a[i]))}, a, b, &i, 1, color);
|
|
772
779
|
},
|
|
773
780
|
.Start => {
|
|
774
781
|
const id = ID.from(@intCast(u4, a[i]));
|
|
775
782
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
776
783
|
const reason = a[i];
|
|
777
|
-
printc(" {s}", .{@tagName(@
|
|
778
|
-
if (@
|
|
784
|
+
printc(" {s}", .{@tagName(@enumFromInt(Start, reason))}, a, b, &i, 1, color);
|
|
785
|
+
if (@enumFromInt(Start, reason) == .TypeChange) {
|
|
779
786
|
const types = @bitCast(gen1.Types, a[i]);
|
|
780
787
|
const args = .{
|
|
781
|
-
formatter(.Type, @
|
|
782
|
-
formatter(.Type, @
|
|
788
|
+
formatter(.Type, @intFromEnum(types.type1)),
|
|
789
|
+
formatter(.Type, @intFromEnum(types.type2)),
|
|
783
790
|
};
|
|
784
791
|
printc(" {s}/{s}", args, a, b, &i, 1, color);
|
|
785
|
-
} else if (reason >= @
|
|
792
|
+
} else if (reason >= @intFromEnum(Start.Disable)) {
|
|
786
793
|
printc(" {s}", .{formatter(.Move, a[i])}, a, b, &i, 1, color);
|
|
787
794
|
}
|
|
788
795
|
},
|
|
789
796
|
.End => {
|
|
790
797
|
const id = ID.from(@intCast(u4, a[i]));
|
|
791
798
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
792
|
-
printc(" {s}", .{@tagName(@
|
|
799
|
+
printc(" {s}", .{@tagName(@enumFromInt(End, a[i]))}, a, b, &i, 1, color);
|
|
793
800
|
},
|
|
794
801
|
.Immune => {
|
|
795
802
|
const id = ID.from(@intCast(u4, a[i]));
|
|
796
803
|
printc(" {s}({d})", .{ @tagName(id.player), id.id }, a, b, &i, 1, color);
|
|
797
|
-
printc(" {s}", .{@tagName(@
|
|
804
|
+
printc(" {s}", .{@tagName(@enumFromInt(Immune, a[i]))}, a, b, &i, 1, color);
|
|
798
805
|
},
|
|
799
806
|
.Transform => {
|
|
800
807
|
const source = ID.from(@intCast(u4, a[i]));
|
|
@@ -881,7 +888,7 @@ fn expectEqualBytes(expected: []const u8, actual: []const u8, offset: usize) !vo
|
|
|
881
888
|
const endian = builtin.target.cpu.arch.endian();
|
|
882
889
|
|
|
883
890
|
fn N(e: anytype) u8 {
|
|
884
|
-
return @
|
|
891
|
+
return @intFromEnum(e);
|
|
885
892
|
}
|
|
886
893
|
|
|
887
894
|
const p1 = Player.P1;
|
|
@@ -905,9 +912,9 @@ fn expectLog1(expected: []const u8, actual: []const u8) !void {
|
|
|
905
912
|
|
|
906
913
|
fn gen1Formatter(kind: Kind, byte: u8) []const u8 {
|
|
907
914
|
return switch (kind) {
|
|
908
|
-
.Move => @tagName(@
|
|
909
|
-
.Species => @tagName(@
|
|
910
|
-
.Type => @tagName(@
|
|
915
|
+
.Move => @tagName(@enumFromInt(M, byte)),
|
|
916
|
+
.Species => @tagName(@enumFromInt(S, byte)),
|
|
917
|
+
.Type => @tagName(@enumFromInt(gen1.Type, byte)),
|
|
911
918
|
.Status => gen1.Status.name(byte),
|
|
912
919
|
};
|
|
913
920
|
}
|
package/src/lib/gen1/README.md
CHANGED
|
@@ -497,7 +497,9 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
497
497
|
damage grow unbounded. Additionally, if the opponent faints after Bide inflicts damage on Pokémon
|
|
498
498
|
Showdown residual damage incorrectly still gets applied to Bide's user.
|
|
499
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.
|
|
500
|
+
registered) can erroneously cause Counter to trigger Desync Clause Mod behavior. Additionally,
|
|
501
|
+
because Pokémon Showdown neglects to zero the last battle damage if a move misses due to immunity
|
|
502
|
+
or invulnerability Counter will occasionally work on Pokémon Showdown when it should fail.
|
|
501
503
|
- **Leech Seed**: Leech Seed fails to heal its source side if a seeded target faints due to
|
|
502
504
|
recoil/crash damage on Pokémon Showdown.
|
|
503
505
|
- **Pay Day**: Pay Day should still scatter coins if it hits (but doesn't break) and opponent's
|
|
@@ -1602,44 +1602,44 @@ pub const Move = enum(u8) {
|
|
|
1602
1602
|
|
|
1603
1603
|
/// Whether this effect activates during the "begin" step of move execution.
|
|
1604
1604
|
pub inline fn onBegin(effect: Effect) bool {
|
|
1605
|
-
return @
|
|
1605
|
+
return @intFromEnum(effect) > 0 and @intFromEnum(effect) <= 16;
|
|
1606
1606
|
}
|
|
1607
1607
|
|
|
1608
1608
|
/// Whether this effect lowers stats.
|
|
1609
1609
|
pub inline fn isStatDown(effect: Effect) bool {
|
|
1610
|
-
return @
|
|
1610
|
+
return @intFromEnum(effect) > 16 and @intFromEnum(effect) <= 21;
|
|
1611
1611
|
}
|
|
1612
1612
|
|
|
1613
1613
|
/// Whether this effect activates during the "end" step of move execution.
|
|
1614
1614
|
pub inline fn onEnd(effect: Effect) bool {
|
|
1615
|
-
return @
|
|
1615
|
+
return @intFromEnum(effect) > 16 and @intFromEnum(effect) <= 31;
|
|
1616
1616
|
}
|
|
1617
1617
|
|
|
1618
1618
|
/// Whether this effect is considered to "always happen".
|
|
1619
1619
|
pub inline fn alwaysHappens(effect: Effect) bool {
|
|
1620
|
-
return @
|
|
1620
|
+
return @intFromEnum(effect) > 31 and @intFromEnum(effect) <= 38;
|
|
1621
1621
|
}
|
|
1622
1622
|
|
|
1623
1623
|
/// Whether this effect is handled specially by the engine.
|
|
1624
1624
|
pub inline fn isSpecial(effect: Effect) bool {
|
|
1625
1625
|
// NB: isSpecial includes isMulti up to Twineedle
|
|
1626
|
-
return @
|
|
1626
|
+
return @intFromEnum(effect) > 31 and @intFromEnum(effect) <= 46;
|
|
1627
1627
|
}
|
|
1628
1628
|
|
|
1629
1629
|
/// Whether this effect is a multi-hit effect.
|
|
1630
1630
|
pub inline fn isMulti(effect: Effect) bool {
|
|
1631
|
-
return @
|
|
1631
|
+
return @intFromEnum(effect) > 44 and @intFromEnum(effect) <= 47;
|
|
1632
1632
|
}
|
|
1633
1633
|
|
|
1634
1634
|
/// Whether this effect is has chance of lowering stats.
|
|
1635
1635
|
pub inline fn isStatDownChance(effect: Effect) bool {
|
|
1636
|
-
return @
|
|
1636
|
+
return @intFromEnum(effect) > 47 and @intFromEnum(effect) <= 51;
|
|
1637
1637
|
}
|
|
1638
1638
|
|
|
1639
1639
|
/// Whether this effect has a secondary chance.
|
|
1640
1640
|
pub inline fn isSecondaryChance(effect: Effect) bool {
|
|
1641
1641
|
// NB: isSecondaryChance includes isStatDownChance as well as Twineedle
|
|
1642
|
-
return (@
|
|
1642
|
+
return (@intFromEnum(effect) > 46 and @intFromEnum(effect) <= 61);
|
|
1643
1643
|
}
|
|
1644
1644
|
};
|
|
1645
1645
|
|
|
@@ -1843,12 +1843,12 @@ pub const Move = enum(u8) {
|
|
|
1843
1843
|
/// Returns the `Data` corresponding to the move.
|
|
1844
1844
|
pub inline fn get(id: Move) Data {
|
|
1845
1845
|
assert(id != .None and id != .SKIP_TURN);
|
|
1846
|
-
return DATA[@
|
|
1846
|
+
return DATA[@intFromEnum(id) - 1];
|
|
1847
1847
|
}
|
|
1848
1848
|
|
|
1849
1849
|
/// Returns the base PP of the move.
|
|
1850
1850
|
pub fn pp(id: Move) u8 {
|
|
1851
1851
|
assert(id != .None);
|
|
1852
|
-
return PP[@
|
|
1852
|
+
return PP[@intFromEnum(id) - 1];
|
|
1853
1853
|
}
|
|
1854
1854
|
};
|
|
@@ -1094,12 +1094,12 @@ pub const Species = enum(u8) {
|
|
|
1094
1094
|
/// The Pokémon's critical hit rate=io out of 256.
|
|
1095
1095
|
pub inline fn chance(id: Species) u8 {
|
|
1096
1096
|
assert(id != .None);
|
|
1097
|
-
return CHANCES[@
|
|
1097
|
+
return CHANCES[@intFromEnum(id) - 1];
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
1100
|
/// Returns the `Data` corresponding to the species.
|
|
1101
1101
|
pub fn get(id: Species) Data {
|
|
1102
1102
|
assert(id != .None);
|
|
1103
|
-
return DATA[@
|
|
1103
|
+
return DATA[@intFromEnum(id) - 1];
|
|
1104
1104
|
}
|
|
1105
1105
|
};
|
|
@@ -91,12 +91,12 @@ pub const Type = enum(u4) {
|
|
|
91
91
|
|
|
92
92
|
/// Whether or not this type is considered to be special as opposed to physical.
|
|
93
93
|
pub inline fn special(self: Type) bool {
|
|
94
|
-
return @
|
|
94
|
+
return @intFromEnum(self) >= @intFromEnum(Type.Fire);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/// The `Effectiveness` of type `t2` vs. type `t1`.
|
|
98
98
|
pub inline fn effectiveness(t1: Type, t2: Type) Effectiveness {
|
|
99
|
-
return CHART[@
|
|
99
|
+
return CHART[@intFromEnum(t1)][@intFromEnum(t2)];
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/// The precedence order of type `t2` vs. type `t1`.
|