Path: blob/master/engine/events/hidden_objects/vermilion_gym_trash.asm
1271 views
PrintTrashText:1call EnableAutoTextBoxDrawing2tx_pre_jump VermilionGymTrashText34VermilionGymTrashText::5text_far _VermilionGymTrashText6text_end78GymTrashScript:9call EnableAutoTextBoxDrawing10ld a, [wHiddenObjectFunctionArgument]11ld [wGymTrashCanIndex], a1213; Don't do the trash can puzzle if it's already been done.14CheckEvent EVENT_2ND_LOCK_OPENED15jr z, .ok1617tx_pre_jump VermilionGymTrashText1819.ok20CheckEventReuseA EVENT_1ST_LOCK_OPENED21jr nz, .trySecondLock2223ld a, [wFirstLockTrashCanIndex]24ld b, a25ld a, [wGymTrashCanIndex]26cp b27jr z, .openFirstLock2829tx_pre_id VermilionGymTrashText30jr .done3132.openFirstLock33; Next can is trying for the second switch.34SetEvent EVENT_1ST_LOCK_OPENED3536ld hl, GymTrashCans37ld a, [wGymTrashCanIndex]38; * 539ld b, a40add a41add a42add b4344ld d, 045ld e, a46add hl, de47ld a, [hli]4849; Bug: This code should calculate a value in the range [0, 3],50; but if the mask and random number don't have any 1 bits in common, then51; the result of the AND will be 0. When 1 is subtracted from that, the value52; will become $ff. This will result in 255 being added to hl, which will cause53; hl to point to one of the zero bytes that pad the end of the ROM bank.54; Trash can 0 was intended to be able to have the second lock only when the55; first lock was in trash can 1 or 3. However, due to this bug, trash can 0 can56; have the second lock regardless of which trash can had the first lock.5758ldh [hGymTrashCanRandNumMask], a59push hl60call Random61swap a62ld b, a63ldh a, [hGymTrashCanRandNumMask]64and b65dec a66pop hl6768ld d, 069ld e, a70add hl, de71ld a, [hl]72and $f73ld [wSecondLockTrashCanIndex], a7475tx_pre_id VermilionGymTrashSuccessText176jr .done7778.trySecondLock79ld a, [wSecondLockTrashCanIndex]80ld b, a81ld a, [wGymTrashCanIndex]82cp b83jr z, .openSecondLock8485; Reset the cans.86ResetEvent EVENT_1ST_LOCK_OPENED87call Random8889and $e90ld [wFirstLockTrashCanIndex], a9192tx_pre_id VermilionGymTrashFailText93jr .done9495.openSecondLock96; Completed the trash can puzzle.97SetEvent EVENT_2ND_LOCK_OPENED98ld hl, wCurrentMapScriptFlags99set BIT_CUR_MAP_LOADED_2, [hl]100101tx_pre_id VermilionGymTrashSuccessText3102103.done104jp PrintPredefTextID105106GymTrashCans:107; byte 0: mask for random number108; bytes 1-4: indices of the trash cans that can have the second lock109; (but see the comment above explaining a bug regarding this)110; Note that the mask is simply the number of valid trash can indices that111; follow. The remaining bytes are filled with 0 to pad the length of each entry112; to 5 bytes.113db 2, 1, 3, 0, 0 ; 0114db 3, 0, 2, 4, 0 ; 1115db 2, 1, 5, 0, 0 ; 2116db 3, 0, 4, 6, 0 ; 3117db 4, 1, 3, 5, 7 ; 4118db 3, 2, 4, 8, 0 ; 5119db 3, 3, 7, 9, 0 ; 6120db 4, 4, 6, 8, 10 ; 7121db 3, 5, 7, 11, 0 ; 8122db 3, 6, 10, 12, 0 ; 9123db 4, 7, 9, 11, 13 ; 10124db 3, 8, 10, 14, 0 ; 11125db 2, 9, 13, 0, 0 ; 12126db 3, 10, 12, 14, 0 ; 13127db 2, 11, 13, 0, 0 ; 14128129VermilionGymTrashSuccessText1::130text_far _VermilionGymTrashSuccessText1131text_asm132call WaitForSoundToFinish133ld a, SFX_SWITCH134call PlaySound135call WaitForSoundToFinish136jp TextScriptEnd137138; unused139VermilionGymTrashSuccessText2::140text_far _VermilionGymTrashSuccessText2141text_end142143; unused144VermilionGymTrashSuccessPlaySfx:145text_asm146call WaitForSoundToFinish147ld a, SFX_SWITCH148call PlaySound149call WaitForSoundToFinish150jp TextScriptEnd151152VermilionGymTrashSuccessText3::153text_far _VermilionGymTrashSuccessText3154text_asm155call WaitForSoundToFinish156ld a, SFX_GO_INSIDE157call PlaySound158call WaitForSoundToFinish159jp TextScriptEnd160161VermilionGymTrashFailText::162text_far _VermilionGymTrashFailText163text_asm164call WaitForSoundToFinish165ld a, SFX_DENIED166call PlaySound167call WaitForSoundToFinish168jp TextScriptEnd169170171