aboutsummaryrefslogtreecommitdiffstats
path: root/engine/pokemon/remove_mon.asm
blob: ee47f0c8d46acb667656b6b2dfbab5465d9633b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
_RemovePokemon::
	ld hl, wPartyCount
	ld a, [wRemoveMonFromBox]
	and a
	jr z, .gotCount
	ld hl, wBoxCount
.gotCount
	ld a, [hl]
	dec a
	ld [hli], a

	ld a, [wWhichPokemon]
	ld c, a
	ld b, 0
	add hl, bc
	ld e, l
	ld d, h
	inc de
.shiftMonSpeciesLoop
	ld a, [de]
	inc de
	ld [hli], a
	inc a ; reached terminator?
	jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species

	ld hl, wPartyMonOT
	ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift
	ld a, [wRemoveMonFromBox]
	and a
	jr z, .gotOTsPointer
	ld hl, wBoxMonOT
	ld d, MONS_PER_BOX - 1
.gotOTsPointer
	ld a, [wWhichPokemon]
	call SkipFixedLengthTextEntries
	ld a, [wWhichPokemon]
	cp d ; are we removing the last pokemon?
	jr nz, .notRemovingLastMon ; if not, shift the pokemon below

	; bug: to erase a string, this should be ld [hl], '@'
	; This is not needed, as wBoxSpecies/wPartySpecies determine if a slot is used.
	; Besides, existing mon nick is left untouched
	ld [hl], $ff
	ret

.notRemovingLastMon
	ld d, h
	ld e, l
	ld bc, NAME_LENGTH
	add hl, bc
	ld bc, wPartyMonNicks
	ld a, [wRemoveMonFromBox]
	and a
	jr z, .gotNicksPointer
	ld bc, wBoxMonNicks
.gotNicksPointer
	call CopyDataUntil

	ld hl, wPartyMons
	ld bc, PARTYMON_STRUCT_LENGTH
	ld a, [wRemoveMonFromBox]
	and a
	jr z, .gotMonStructs
	ld hl, wBoxMons
	ld bc, BOXMON_STRUCT_LENGTH
.gotMonStructs
	ld a, [wWhichPokemon]
	call AddNTimes ; get address of the pokemon removed

	ld d, h ; de = start address for CopyDataUntil
	ld e, l
	ld a, [wRemoveMonFromBox]
	and a
	jr z, .copyUntilPartyMonOT
; copy until wBoxMonOT
	ld bc, BOXMON_STRUCT_LENGTH
	add hl, bc ; get address of next slot
	ld bc, wBoxMonOT
	jr .shiftOTs
.copyUntilPartyMonOT
	ld bc, PARTYMON_STRUCT_LENGTH
	add hl, bc ; get address of next slot
	ld bc, wPartyMonOT
.shiftOTs
	call CopyDataUntil ; shift all pokemon data up one slot

	ld hl, wPartyMonNicks
	ld a, [wRemoveMonFromBox]
	and a
	jr z, .gotNicksPointer2
	ld hl, wBoxMonNicks
.gotNicksPointer2
	ld bc, NAME_LENGTH
	ld a, [wWhichPokemon]
	call AddNTimes

	ld d, h
	ld e, l
	ld bc, NAME_LENGTH
	add hl, bc
	ld bc, wPartyMonNicksEnd
	ld a, [wRemoveMonFromBox]
	and a
	jr z, .shiftMonNicks
	ld bc, wBoxMonNicksEnd
.shiftMonNicks
	jp CopyDataUntil ; shift all pokemon nicknames up one slot