Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/events/hidden_objects/vermilion_gym_trash.asm
1271 views
1
PrintTrashText:
2
call EnableAutoTextBoxDrawing
3
tx_pre_jump VermilionGymTrashText
4
5
VermilionGymTrashText::
6
text_far _VermilionGymTrashText
7
text_end
8
9
GymTrashScript:
10
call EnableAutoTextBoxDrawing
11
ld a, [wHiddenObjectFunctionArgument]
12
ld [wGymTrashCanIndex], a
13
14
; Don't do the trash can puzzle if it's already been done.
15
CheckEvent EVENT_2ND_LOCK_OPENED
16
jr z, .ok
17
18
tx_pre_jump VermilionGymTrashText
19
20
.ok
21
CheckEventReuseA EVENT_1ST_LOCK_OPENED
22
jr nz, .trySecondLock
23
24
ld a, [wFirstLockTrashCanIndex]
25
ld b, a
26
ld a, [wGymTrashCanIndex]
27
cp b
28
jr z, .openFirstLock
29
30
tx_pre_id VermilionGymTrashText
31
jr .done
32
33
.openFirstLock
34
; Next can is trying for the second switch.
35
SetEvent EVENT_1ST_LOCK_OPENED
36
37
ld hl, GymTrashCans
38
ld a, [wGymTrashCanIndex]
39
; * 5
40
ld b, a
41
add a
42
add a
43
add b
44
45
ld d, 0
46
ld e, a
47
add hl, de
48
ld a, [hli]
49
50
; Bug: This code should calculate a value in the range [0, 3],
51
; but if the mask and random number don't have any 1 bits in common, then
52
; the result of the AND will be 0. When 1 is subtracted from that, the value
53
; will become $ff. This will result in 255 being added to hl, which will cause
54
; hl to point to one of the zero bytes that pad the end of the ROM bank.
55
; Trash can 0 was intended to be able to have the second lock only when the
56
; first lock was in trash can 1 or 3. However, due to this bug, trash can 0 can
57
; have the second lock regardless of which trash can had the first lock.
58
59
ldh [hGymTrashCanRandNumMask], a
60
push hl
61
call Random
62
swap a
63
ld b, a
64
ldh a, [hGymTrashCanRandNumMask]
65
and b
66
dec a
67
pop hl
68
69
ld d, 0
70
ld e, a
71
add hl, de
72
ld a, [hl]
73
and $f
74
ld [wSecondLockTrashCanIndex], a
75
76
tx_pre_id VermilionGymTrashSuccessText1
77
jr .done
78
79
.trySecondLock
80
ld a, [wSecondLockTrashCanIndex]
81
ld b, a
82
ld a, [wGymTrashCanIndex]
83
cp b
84
jr z, .openSecondLock
85
86
; Reset the cans.
87
ResetEvent EVENT_1ST_LOCK_OPENED
88
call Random
89
90
and $e
91
ld [wFirstLockTrashCanIndex], a
92
93
tx_pre_id VermilionGymTrashFailText
94
jr .done
95
96
.openSecondLock
97
; Completed the trash can puzzle.
98
SetEvent EVENT_2ND_LOCK_OPENED
99
ld hl, wCurrentMapScriptFlags
100
set BIT_CUR_MAP_LOADED_2, [hl]
101
102
tx_pre_id VermilionGymTrashSuccessText3
103
104
.done
105
jp PrintPredefTextID
106
107
GymTrashCans:
108
; byte 0: mask for random number
109
; bytes 1-4: indices of the trash cans that can have the second lock
110
; (but see the comment above explaining a bug regarding this)
111
; Note that the mask is simply the number of valid trash can indices that
112
; follow. The remaining bytes are filled with 0 to pad the length of each entry
113
; to 5 bytes.
114
db 2, 1, 3, 0, 0 ; 0
115
db 3, 0, 2, 4, 0 ; 1
116
db 2, 1, 5, 0, 0 ; 2
117
db 3, 0, 4, 6, 0 ; 3
118
db 4, 1, 3, 5, 7 ; 4
119
db 3, 2, 4, 8, 0 ; 5
120
db 3, 3, 7, 9, 0 ; 6
121
db 4, 4, 6, 8, 10 ; 7
122
db 3, 5, 7, 11, 0 ; 8
123
db 3, 6, 10, 12, 0 ; 9
124
db 4, 7, 9, 11, 13 ; 10
125
db 3, 8, 10, 14, 0 ; 11
126
db 2, 9, 13, 0, 0 ; 12
127
db 3, 10, 12, 14, 0 ; 13
128
db 2, 11, 13, 0, 0 ; 14
129
130
VermilionGymTrashSuccessText1::
131
text_far _VermilionGymTrashSuccessText1
132
text_asm
133
call WaitForSoundToFinish
134
ld a, SFX_SWITCH
135
call PlaySound
136
call WaitForSoundToFinish
137
jp TextScriptEnd
138
139
; unused
140
VermilionGymTrashSuccessText2::
141
text_far _VermilionGymTrashSuccessText2
142
text_end
143
144
; unused
145
VermilionGymTrashSuccessPlaySfx:
146
text_asm
147
call WaitForSoundToFinish
148
ld a, SFX_SWITCH
149
call PlaySound
150
call WaitForSoundToFinish
151
jp TextScriptEnd
152
153
VermilionGymTrashSuccessText3::
154
text_far _VermilionGymTrashSuccessText3
155
text_asm
156
call WaitForSoundToFinish
157
ld a, SFX_GO_INSIDE
158
call PlaySound
159
call WaitForSoundToFinish
160
jp TextScriptEnd
161
162
VermilionGymTrashFailText::
163
text_far _VermilionGymTrashFailText
164
text_asm
165
call WaitForSoundToFinish
166
ld a, SFX_DENIED
167
call PlaySound
168
call WaitForSoundToFinish
169
jp TextScriptEnd
170
171