# Plan 6 Task 4: a catch in a joined link battle, the PARTNER's ball. The battle is made wild by hand (the two foes are the AI trainers'
# Pokémon with the TRAINER flag cleared on both cores once the battle runs: Task 3 does that in begin) and one foe is left: battler 1 is
# gone (absent, 0 HP), battler 3 sleeps with 1 HP. The partner throws a POKé BALL from its own bag (RIGHT to BAG, the bag's POKé BALLS
# pocket, USE): the ball leaves the PARTNER's bag only; the engine's own catch runs on the master; the caught foe is not put in the
# temporary link party (pk_coop_link_caught: caught by 2 and its 100 bytes) and both games end the battle with outcome 7 (caught)
# - the end reaches the partner's game too, neither core hangs.
# After the battle the partner's game gives it to ITSELF (pk_coop_give_mon through `coopgive`): it lands in the partner's real party with
# the partner's OT ID, OT name and gender, and the host's game gets nothing (its party count and slot 3 are as they were).
# Needs EMERALD_PARTNER_SAVE (`$PARTNER_SAVE`).
#
# want: PASS linkwait 2
# want: PASS linkwait 3
# want: PASS expectdelta b_ball -> b_ball2 = -1
# want: PASS expectdelta a_ball -> a_ball2 = 0
# want: link: caught by 2
# want: PASS expectnum a_out = 7
# want: PASS expectnum b_out = 7
# want: PASS expectnum b_count2 = 4
# want: PASS expectnum a_count2 = 3
# want: PASS expectnum a_slot3b = 0
# want: PASS expectmon 02024618
# want: PASS expectotname 02024618
pair $PARTNER_SAVE
on b
@boot
poke16 0x02024542 999
poke16 0x02024544 999
bagqty b_ball 4
on a
poke16 0x02024542 999
poke16 0x02024544 999
bagqty a_ball 4
coopbegin 1 2 333 318
on b
coopbegin 0 2 333 318
linkwait 2 1500
on a
waitmem32 0x03005D60 0x08057589 3000
poke32 0x02022FEC 0x800163
poke8 0x02024210 2
poke16 0x02024104 0
poke16 0x0202479A 0
poke32 0x020241D8 7
poke16 0x020241B4 1
on b
waitmem32 0x03005D68 0x08057589 3000
poke16 0x0202479A 0
poke32 0x02022FEC 0x800163
hold RIGHT 4
linkrun 30
hold A 4
linkrun 120
hold RIGHT 4
linkrun 30
hold A 4
linkrun 30
hold A 4
linkrun 100
hold A 4
linkrun 100
bagqty b_ball2 4
on a
bagqty a_ball2 4
hold A 4
linkrun 40
hold A 4
linkrun 40
hold A 4
linkrun 40
linkwait 3 4000
peeknum a_out 0x0202433A 1
expectnum a_out 7
linkcaught /work/caught_partner.bin
peeknum a_count 0x020244E9 1

on b
peeknum b_out 0x0202433A 1
expectnum b_out 7
peeknum b_count 0x020244E9 1
linkreset
on a
linkreset
waitmem32 0x030022C4 0x08085E5D 4000
on b
waitmem32 0x030022C4 0x08085E5D 4000
linkrun 200
coopgive /work/caught_partner.bin
linkrun 5
peeknum b_count2 0x020244E9 1
expectnum b_count2 4
monexp b_slot3 0x02024618
expectmon 0x02024618 own 286 own
expectotname 0x02024618
on a
linkrun 5
peeknum a_count2 0x020244E9 1
expectnum a_count2 3
monexp a_slot3b 0x02024618
expectnum a_slot3b 0
expectdelta b_ball b_ball2 -1
expectdelta a_ball a_ball2 0
