Move events/ to engine/events/

This commit is contained in:
Remy Oukaour
2017-12-27 00:09:12 -05:00
parent 47e4f21e62
commit 86fd37af16
64 changed files with 65 additions and 65 deletions

34
engine/events/basement_key.asm Executable file
View File

@@ -0,0 +1,34 @@
_BasementKey: ; 507b4
; Are we even in the right map to use this?
ld a, [MapGroup]
cp GROUP_GOLDENROD_UNDERGROUND
jr nz, .nope
ld a, [MapNumber]
cp MAP_GOLDENROD_UNDERGROUND
jr nz, .nope
; Are we on the tile in front of the door?
call GetFacingTileCoord
ld a, d
cp 22
jr nz, .nope
ld a, e
cp 10
jr nz, .nope
; Let's use the Basement Key
ld hl, .BasementKeyScript
call QueueScript
ld a, TRUE
ld [wItemEffectSucceeded], a
ret
.nope
ld a, FALSE
ld [wItemEffectSucceeded], a
ret
; 507e1
.BasementKeyScript: ; 0x507e1
closetext
farjump BasementDoorScript
; 0x507e6

View File

@@ -0,0 +1,210 @@
Function_LoadOpponentTrainerAndPokemons: ; 1f8000
ld a, [rSVBK]
push af
ld a, BANK(BT_OTTrainer)
ld [rSVBK], a
; Fill BT_OTTrainer with zeros
xor a
ld hl, BT_OTTrainer
ld bc, BT_OTTrainerEnd - BT_OTTrainer
call ByteFill
; Write $ff into the Item-Slots
ld a, $ff
ld [BT_OTPkmn1Item], a
ld [BT_OTPkmn2Item], a
ld [BT_OTPkmn3Item], a
; Set BT_OTTrainer as start address to write the following data to
ld de, BT_OTTrainer
ld a, [hRandomAdd]
ld b, a
.resample ; loop to find a random trainer
call Random
ld a, [hRandomAdd]
add b
ld b, a ; b contains the nr of the trainer
IF DEF(CRYSTAL11)
and (1 << 7) - 1
cp 70
ELSE
and (1 << 5) - 1
cp 21
ENDC
jr nc, .resample
ld b, a
ld a, BANK(sBTTrainers)
call GetSRAMBank
ld c, BATTLETOWER_NROFTRAINERS
ld hl, sBTTrainers
.next_trainer
ld a, [hli]
cp b
jr z, .resample
dec c
jr nz, .next_trainer ; c <= 7 initialise all 7 trainers?
ld hl, sBTTrainers
ld a, [sNrOfBeatenBattleTowerTrainers]
ld c, a
ld a, b
ld b, 0
add hl, bc
ld [hl], a
call CloseSRAM
push af
; Copy name (10 bytes) and class (1 byte) of trainer
ld hl, BattleTowerTrainers
ld bc, NAME_LENGTH
call AddNTimes
ld bc, NAME_LENGTH
call CopyBytes
call Function_LoadRandomBattleTowerPkmn
pop af
ld hl, BattleTowerTrainerData
ld bc, BATTLETOWER_TRAINERDATALENGTH
call AddNTimes
ld bc, BATTLETOWER_TRAINERDATALENGTH
.copy_bt_trainer_data_loop
ld a, BANK(BattleTowerTrainerData)
call GetFarByte
ld [de], a
inc hl
inc de
dec bc
ld a, b
or c
jr nz, .copy_bt_trainer_data_loop
pop af
ld [rSVBK], a
ret
Function_LoadRandomBattleTowerPkmn: ; 1f8081
ld c, BATTLETOWER_NROFPKMNS
.loop
push bc
ld a, BANK(sBTPkmnPrevTrainer1)
call GetSRAMBank
.FindARandomBattleTowerPkmn:
; From Which LevelGroup are the Pkmn loaded
; a = 1..10
ld a, [wBTChoiceOfLvlGroup] ; [$d800]
dec a
ld hl, BattleTowerMons
ld bc, BattleTowerMons2 - BattleTowerMons1
call AddNTimes
ld a, [hRandomAdd]
ld b, a
.resample
call Random
ld a, [hRandomAdd]
add b
ld b, a
and $1f
cp BATTLETOWER_NRMONSPERLEVELBRACKET
jr nc, .resample
; in register 'a' is the chosen Pkmn of the LevelGroup
; Check if Pkmn was already loaded before
; Check current and the 2 previous teams
; includes check if item is double at the current team
ld bc, PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH
call AddNTimes
ld a, [hli]
ld b, a
ld a, [hld]
ld c, a
ld a, [BT_OTPkmn1]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [BT_OTPkmn1Item]
cp c
jr z, .FindARandomBattleTowerPkmn
ld a, [BT_OTPkmn2]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [BT_OTPkmn2Item]
cp c
jr z, .FindARandomBattleTowerPkmn
ld a, [BT_OTPkmn3]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [BT_OTPkmn3Item]
cp c
jr z, .FindARandomBattleTowerPkmn
ld a, [sBTPkmnPrevTrainer1]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [sBTPkmnPrevTrainer2]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [sBTPkmnPrevTrainer3]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [sBTPkmnPrevPrevTrainer1]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [sBTPkmnPrevPrevTrainer2]
cp b
jr z, .FindARandomBattleTowerPkmn
ld a, [sBTPkmnPrevPrevTrainer3]
cp b
jr z, .FindARandomBattleTowerPkmn
ld bc, PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH
call CopyBytes
ld a, [wNamedObjectIndexBuffer]
push af
push de
ld hl, - (PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH)
add hl, de
ld a, [hl]
ld [wNamedObjectIndexBuffer], a
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
push hl
call GetPokemonName
ld h, d
ld l, e
pop de
ld bc, PKMN_NAME_LENGTH
call CopyBytes
pop de
pop af
ld [wNamedObjectIndexBuffer], a
pop bc
dec c
jp nz, .loop
ld a, [sBTPkmnPrevTrainer1]
ld [sBTPkmnPrevPrevTrainer1], a
ld a, [sBTPkmnPrevTrainer2]
ld [sBTPkmnPrevPrevTrainer2], a
ld a, [sBTPkmnPrevTrainer3]
ld [sBTPkmnPrevPrevTrainer3], a
ld a, [BT_OTPkmn1]
ld [sBTPkmnPrevTrainer1], a
ld a, [BT_OTPkmn2]
ld [sBTPkmnPrevTrainer2], a
ld a, [BT_OTPkmn3]
ld [sBTPkmnPrevTrainer3], a
call CloseSRAM
ret
; 1f814e
INCLUDE "data/battle_tower.asm"

View File

@@ -0,0 +1,342 @@
CheckForMobileBattleRules: ; 8b1e1
ld de, .PointerTables
call BattleTower_ExecuteJumptable
ret z
call BattleTower_PleaseReturnWhenReady
scf
ret
; 8b1ed
.PointerTables: ; 8b1ed
db 2
dw .Functions
dw .TextPointers
.Functions: ; 8b1f2
dw BattleTower_CheckPartyLengthIs3
dw BattleTower_CheckPartyHasThreeMonsThatAreNotEggs
; 8b1f6
.TextPointers: ; 8b1f6
dw .ExcuseMeText
dw JumpText_NeedAtLeastThreeMon
dw JumpText_EggDoesNotQualify
; 8b1fc
.ExcuseMeText: ; 0x8b1fc
; Excuse me!
text_jump UnknownText_0x1c5937
db "@"
; 0x8b201
CheckForBattleTowerRules: ; 8b201
ld hl, StringBuffer2
ld [hl], "3"
inc hl
ld [hl], "@"
ld de, .PointerTables
call BattleTower_ExecuteJumptable
ret z
call BattleTower_PleaseReturnWhenReady
scf
ret
; 8b215
.PointerTables: ; 8b215
db 4
dw .Functions
dw .TextPointers
.Functions: ; 8b21a
dw Function_PartyCountEq3
dw Function_PartySpeciesAreUnique
dw Function_PartyItemsAreUnique
dw Function_HasPartyAnEgg
; 8b222
.TextPointers: ; 8b222
dw JumpText_ExcuseMeYoureNotReady
dw JumpText_OnlyThreePkmnMayBeEntered
dw JumpText_ThePkmnMustAllBeDifferentKinds
dw JumpText_ThePkmnMustNotHoldTheSameItems
dw JumpText_YouCantTakeAnEgg
; 8b22c
JumpText_ExcuseMeYoureNotReady: ; 0x8b22c
; Excuse me. You're not ready.
text_jump Text_ExcuseMeYoureNotReady
db "@"
; 0x8b231
BattleTower_PleaseReturnWhenReady: ; 8b231
ld hl, .PleaseReturnWhenReady
call PrintText
ret
; 8b238
.PleaseReturnWhenReady: ; 0x8b238
; Please return when you're ready.
text_jump UnknownText_0x1c5962
db "@"
; 0x8b23d
JumpText_NeedAtLeastThreeMon: ; 0x8b23d
; You need at least three #MON.
text_jump UnknownText_0x1c5983
db "@"
; 0x8b242
JumpText_EggDoesNotQualify: ; 0x8b242
; Sorry, an EGG doesn't qualify.
text_jump UnknownText_0x1c59a3
db "@"
; 0x8b247
JumpText_OnlyThreePkmnMayBeEntered: ; 0x8b247
; Only three #MON may be entered.
text_jump Text_OnlyThreePkmnMayBeEntered
db "@"
; 0x8b24c
JumpText_ThePkmnMustAllBeDifferentKinds: ; 0x8b24c
; The @ #MON must all be different kinds.
text_jump Text_ThePkmnMustAllBeDifferentKinds
db "@"
; 0x8b251
JumpText_ThePkmnMustNotHoldTheSameItems: ; 0x8b251
; The @ #MON must not hold the same items.
text_jump Text_ThePkmnMustNotHoldTheSameItems
db "@"
; 0x8b256
JumpText_YouCantTakeAnEgg: ; 0x8b256
; You can't take an EGG!
text_jump Text_YouCantTakeAnEgg
db "@"
; 0x8b25b
BattleTower_ExecuteJumptable: ; 8b25b
ld bc, 0
.loop
call .DoJumptableFunction
call c, .PrintFailureText
call .Next_CheckReachedEnd
jr nz, .loop
ld a, b
and a
ret
; 8b26c
.DoJumptableFunction: ; 8b26c
push de
push bc
call .GetFunctionPointer
ld a, c
rst JumpTable
pop bc
pop de
ret
; 8b276
.Next_CheckReachedEnd: ; 8b276
inc c
ld a, [de]
cp c
ret
; 8b27a
.GetFunctionPointer: ; 8b27a
inc de
ld a, [de]
ld l, a
inc de
ld a, [de]
ld h, a
ret
; 8b281
.GetTextPointers: ; 8b281
inc de
inc de
inc de
ld a, [de]
ld l, a
inc de
ld a, [de]
ld h, a
ret
; 8b28a
.LoadTextPointer: ; 8b28a
ld a, [hli]
ld h, [hl]
ld l, a
ret
; 8b28e
.PrintFailureText: ; 8b28e
push de
push bc
ld a, b
and a
call z, .PrintFirstText
pop bc
call .PrintNthText
ld b, $1
pop de
ret
; 8b29d
.PrintFirstText: ; 8b29d
push de
call .GetTextPointers
call .LoadTextPointer
call PrintText
pop de
ret
; 8b2a9
.PrintNthText: ; 8b2a9
push bc
call .GetTextPointers
inc hl
inc hl
ld b, $0
add hl, bc
add hl, bc
call .LoadTextPointer
call PrintText
pop bc
ret
; 8b2bb
BattleTower_CheckPartyLengthIs3: ; 8b2bb
ld a, [PartyCount]
cp 3
ret
; 8b2c1
BattleTower_CheckPartyHasThreeMonsThatAreNotEggs: ; 8b2c1
ld hl, PartyCount
ld a, [hli]
ld b, $0
ld c, a
.loop
ld a, [hli]
cp EGG
jr z, .egg
inc b
.egg
dec c
jr nz, .loop
ld a, [PartyCount]
cp b
ret z
ld a, b
cp 3
ret
; 8b2da
Function_PartyCountEq3: ; 8b2da
ld a, [PartyCount]
cp 3
ret z
scf
ret
; 8b2e2
Function_PartySpeciesAreUnique: ; 8b2e2
ld hl, PartyMon1Species
call VerifyUniqueness
ret
; 8b2e9
VerifyUniqueness: ; 8b2e9
ld de, PartyCount
ld a, [de]
inc de
dec a
jr z, .done
ld b, a
.loop
push hl
push de
ld c, b
call .isegg
jr z, .next
ld a, [hl]
and a
jr z, .next
.loop2
call .nextmon
call .isegg
jr z, .next2
cp [hl]
jr z, .gotcha
.next2
dec c
jr nz, .loop2
.next
pop de
pop hl
call .nextmon
dec b
jr nz, .loop
.done
and a
ret
.gotcha
pop de
pop hl
scf
ret
; 8b31a
.nextmon ; 8b31a
push bc
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
inc de
pop bc
ret
; 8b322
.isegg ; 8b322
push bc
ld b, a
ld a, [de]
cp EGG
ld a, b
pop bc
ret
; 8b32a
Function_PartyItemsAreUnique: ; 8b32a
ld hl, PartyMon1Item
call VerifyUniqueness
ret
; 8b331
Function_HasPartyAnEgg: ; 8b331
ld hl, PartyCount
ld a, [hli]
ld c, a
.loop
ld a, [hli]
cp EGG
jr z, .found
dec c
jr nz, .loop
and a
ret
.found
scf
ret
; 8b342

336
engine/events/buena.asm Normal file
View File

@@ -0,0 +1,336 @@
SpecialBuenasPassword: ; 8af6b
xor a
ld [wWhichIndexSet], a
ld hl, .MenuDataHeader
call CopyMenuDataHeader
ld a, [wBuenasPassword]
ld c, a
farcall GetBuenasPassword
ld a, [wMenuBorderLeftCoord]
add c
add $2
ld [wMenuBorderRightCoord], a
call PushWindow
call DoNthMenu ; menu
farcall Buena_ExitMenu
ld b, $0
ld a, [MenuSelection]
ld c, a
ld a, [wBuenasPassword]
and $3
cp c
jr nz, .wrong
ld b, $1
.wrong
ld a, b
ld [ScriptVar], a
ret
; 8afa9
.MenuDataHeader: ; 0x8afa9
db $40 ; flags
db 00, 00 ; start coords
db 07, 10 ; end coords
dw .MenuData2
db 1 ; default option
; 0x8afb1
db 0
.MenuData2: ; 0x8afb2
db $81 ; flags
db 0 ; items
dw .PasswordIndices
dw .PlacePasswordChoices
; 0x8afb4
.PasswordIndices: ; 8afb8
db 3
db 0, 1, 2
db -1
.PlacePasswordChoices: ; 8afbd
push de
ld a, [wBuenasPassword]
and $f0
ld c, a
ld a, [MenuSelection]
add c
ld c, a
farcall GetBuenasPassword
pop hl
call PlaceString
ret
; 8afd4
SpecialBuenaPrize: ; 8afd4
xor a
ld [wMenuScrollPosition], a
ld a, $1
ld [MenuSelection], a
call Buena_PlacePrizeMenuBox
call Buena_DisplayBlueCardBalance
ld hl, .Text_AskWhichPrize
call PrintText
jr .okay
.loop
ld hl, .Text_AskWhichPrize
call BuenaPrintText
.okay
call DelayFrame
call UpdateSprites
call PrintBlueCardBalance
call Buena_PrizeMenu
jr z, .done
ld [MenuSelectionQuantity], a
call Buena_getprize
ld a, [hl]
ld [wNamedObjectIndexBuffer], a
call GetItemName
ld hl, .Text_IsThatRight
call BuenaPrintText
call YesNoBox
jr c, .loop
ld a, [MenuSelectionQuantity]
call Buena_getprize
inc hl
ld a, [hld]
ld c, a
ld a, [wBlueCardBalance]
cp c
jr c, .InsufficientBalance
ld a, [hli]
push hl
ld [CurItem], a
ld a, $1
ld [wItemQuantityChangeBuffer], a
ld hl, NumItems
call ReceiveItem
pop hl
jr nc, .BagFull
ld a, [hl]
ld c, a
ld a, [wBlueCardBalance]
sub c
ld [wBlueCardBalance], a
call PrintBlueCardBalance
jr .Purchase
.InsufficientBalance:
ld hl, .Text_NotEnoughPoints
jr .print
.BagFull:
ld hl, .Text_NoRoom
jr .print
.Purchase:
ld de, SFX_TRANSACTION
call PlaySFX
ld hl, .Text_HereYouGo
.print
call BuenaPrintText
jr .loop
.done
call CloseWindow
call CloseWindow
ld hl, .Text_PleaseComeBackAgain
call PrintText
call JoyWaitAorB
call PlayClickSFX
ret
; 8b072
.Text_AskWhichPrize: ; 0x8b072
; Which prize would you like?
text_jump UnknownText_0x1c589f
db "@"
; 0x8b077
.Text_IsThatRight: ; 0x8b077
; ? Is that right?
text_jump UnknownText_0x1c58bc
db "@"
; 0x8b07c
.Text_HereYouGo: ; Here you go!
text_jump UnknownText_0x1c58d1
db "@"
; 0x8b081
.Text_NotEnoughPoints: ; 0x8b081
; You don't have enough points.
text_jump UnknownText_0x1c58e0
db "@"
; 0x8b086
.Text_NoRoom: ; 0x8b086
; You have no room for it.
text_jump UnknownText_0x1c58ff
db "@"
; 0x8b08b
.Text_PleaseComeBackAgain: ; 0x8b08b
; Oh. Please come back again!
text_jump UnknownText_0x1c591a
db "@"
; 0x8b090
Buena_DisplayBlueCardBalance: ; 8b090
ld hl, BlueCardBalanceMenuDataHeader
call LoadMenuDataHeader
ret
; 8b097
PrintBlueCardBalance: ; 8b097
ld de, wBlueCardBalance
call .DrawBox
ret
; 8b09e
.DrawBox: ; 8b09e
push de
xor a
ld [hBGMapMode], a
ld hl, BlueCardBalanceMenuDataHeader
call CopyMenuDataHeader
call MenuBox
call UpdateSprites
call MenuBoxCoord2Tile
ld bc, SCREEN_WIDTH + 1
add hl, bc
ld de, .Points_string
call PlaceString
ld h, b
ld l, c
inc hl
ld a, " "
ld [hli], a
ld [hld], a
pop de
lb bc, 1, 2
call PrintNum
ret
; 8b0ca
.Points_string:
db "Points@"
; 8b0d1
BlueCardBalanceMenuDataHeader: ; 0x8b0d1
db $40 ; flags
db 11, 00 ; start coords
db 13, 11 ; end coords
; 8b0d6
Buena_PlacePrizeMenuBox: ; 8b0d6
ld hl, .menudataheader
call LoadMenuDataHeader
ret
; 8b0dd
.menudataheader ; 0x8b0dd
db $40 ; flags
db 00, 00 ; start coords
db 11, 17 ; end coords
; 8b0e2
Buena_PrizeMenu: ; 8b0e2
ld hl, .MenuDataHeader
call CopyMenuDataHeader
ld a, [MenuSelection]
ld [wMenuCursorBuffer], a
xor a
ld [wWhichIndexSet], a
ld [hBGMapMode], a
call InitScrollingMenu
call UpdateSprites
call ScrollingMenu
ld a, [MenuSelection]
ld c, a
ld a, [wMenuCursorY]
ld [MenuSelection], a
ld a, [wMenuJoypad]
cp $2
jr z, .cancel
ld a, c
and a
ret nz
.cancel
xor a
ret
; 8b113
.MenuDataHeader: ; 0x8b113
db $40 ; flags
db 01, 01 ; start coords
db 09, 16 ; end coords
dw .MenuData2
db 1 ; default option
; 0x8b11b
db 0
.MenuData2: ; 0x8b11c
db $10 ; flags
db 4, 13 ; rows, columns
db 1 ; spacing
dba .indices
dba .prizeitem
dba .prizepoints
; 8b129
NUM_BUENA_PRIZES EQU 9 ; ((BuenaPrizeItemsEnd - BuenaPrizeItems) / 2)
.indices ; 8b129
db NUM_BUENA_PRIZES
x = 1
rept NUM_BUENA_PRIZES
db x
x = x + 1
endr
db -1
; 8b134
.prizeitem ; 8b134
ld a, [MenuSelection]
call Buena_getprize
ld a, [hl]
push de
ld [wNamedObjectIndexBuffer], a
call GetItemName
pop hl
call PlaceString
ret
; 8b147
.prizepoints ; 8b147
ld a, [MenuSelection]
call Buena_getprize
inc hl
ld a, [hl]
ld c, "0"
add c
ld [de], a
ret
; 8b154
Buena_getprize: ; 8b154
dec a
ld hl, BuenaPrizeItems
ld b, 0
ld c, a
add hl, bc
add hl, bc
ret
; 8b15e
INCLUDE "data/items/buena_prizes.asm"

View File

@@ -0,0 +1,58 @@
AskRememberPassword: ; 4ae12
call .DoMenu
ld a, $0
jr c, .okay
ld a, $1
.okay
ld [ScriptVar], a
ret
.DoMenu: ; 4ae1f
lb bc, 14, 7
push bc
ld hl, YesNoMenuDataHeader
call CopyMenuDataHeader
pop bc
ld a, b
ld [wMenuBorderLeftCoord], a
add $5
ld [wMenuBorderRightCoord], a
ld a, c
ld [wMenuBorderTopCoord], a
add $4
ld [wMenuBorderBottomCoord], a
call PushWindow
call VerticalMenu
push af
ld c, 15
call DelayFrames
call Buena_ExitMenu
pop af
jr c, .refused
ld a, [wMenuCursorY]
cp $2
jr z, .refused
and a
ret
.refused
ld a, $2
ld [wMenuCursorY], a
scf
ret
Buena_ExitMenu: ; 4ae5e
ld a, [hOAMUpdate]
push af
call ExitMenu
call UpdateSprites
xor a
ld [hOAMUpdate], a
call DelayFrame
ld a, $1
ld [hOAMUpdate], a
call ApplyTilemap
pop af
ld [hOAMUpdate], a
ret

View File

@@ -0,0 +1,38 @@
BugContest_SetCaughtContestMon: ; e6ce
ld a, [wContestMon]
and a
jr z, .firstcatch
ld [wd265], a
farcall DisplayAlreadyCaughtText
farcall DisplayCaughtContestMonStats
lb bc, 14, 7
call PlaceYesNoBox
ret c
.firstcatch
call .generatestats
ld a, [TempEnemyMonSpecies]
ld [wd265], a
call GetPokemonName
ld hl, .caughttext
call PrintText
ret
.generatestats ; e6fd
ld a, [TempEnemyMonSpecies]
ld [CurSpecies], a
ld [CurPartySpecies], a
call GetBaseData
xor a
ld bc, PARTYMON_STRUCT_LENGTH
ld hl, wContestMon
call ByteFill
xor a
ld [MonType], a
ld hl, wContestMon
jp GeneratePartyMonStats
.caughttext ; 0xe71d
; Caught @ !
text_jump UnknownText_0x1c10c0
db "@"

View File

@@ -0,0 +1,43 @@
Special_GiveParkBalls: ; 135db
xor a
ld [wContestMon], a
ld a, 20
ld [wParkBallsRemaining], a
farcall StartBugContestTimer
ret
BugCatchingContestBattleScript:: ; 0x135eb
writecode VAR_BATTLETYPE, BATTLETYPE_CONTEST
randomwildmon
startbattle
reloadmapafterbattle
copybytetovar wParkBallsRemaining
iffalse BugCatchingContestOutOfBallsScript
end
BugCatchingContestOverScript:: ; 0x135f8
playsound SFX_ELEVATOR_END
opentext
writetext BugCatchingContestText_BeeepTimesUp
waitbutton
jump BugCatchingContestReturnToGateScript
BugCatchingContestOutOfBallsScript: ; 0x13603
playsound SFX_ELEVATOR_END
opentext
writetext BugCatchingContestText_ContestIsOver
waitbutton
BugCatchingContestReturnToGateScript: ; 0x1360b
closetext
jumpstd bugcontestresultswarp
BugCatchingContestText_BeeepTimesUp: ; 0x1360f
; ANNOUNCER: BEEEP! Time's up!
text_jump UnknownText_0x1bd2ca
db "@"
BugCatchingContestText_ContestIsOver: ; 0x13614
; ANNOUNCER: The Contest is over!
text_jump UnknownText_0x1bd2e7
db "@"

View File

@@ -0,0 +1,133 @@
Special_SelectRandomBugContestContestants: ; 139a8
; Select five random people to participate in the current contest.
; First we have to make sure that any old data is cleared away.
ld c, 10 ; Number of people to choose from.
ld hl, BugCatchingContestantEventFlagTable
.loop1
push bc
push hl
ld e, [hl]
inc hl
ld d, [hl]
ld b, RESET_FLAG
call EventFlagAction
pop hl
inc hl
inc hl
pop bc
dec c
jr nz, .loop1
; Now that that's out of the way, we can get on to the good stuff.
ld c, 5
.loop2
push bc
.next
; Choose a flag at uniform random to be set.
call Random
cp 250
jr nc, .next
ld c, 25
call SimpleDivide
ld e, b
ld d, 0
ld hl, BugCatchingContestantEventFlagTable
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
push de
; If we've already set it, it doesn't count.
ld b, CHECK_FLAG
call EventFlagAction
pop de
ld a, c
and a
jr nz, .next
; Set the flag. This will cause that sprite to not be visible in the contest.
ld b, SET_FLAG
call EventFlagAction
pop bc
; Check if we're done. If so, return. Otherwise, choose the next victim.
dec c
jr nz, .loop2
ret
; 139ed
Special_CheckBugContestContestantFlag: ; 139ed
; Checks the flag of the Bug Catching Contestant whose index is loaded in a.
; Bug: If a >= 10 when this is called, it will read beyond the table.
ld hl, BugCatchingContestantEventFlagTable
ld e, a
ld d, 0
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ld b, CHECK_FLAG
call EventFlagAction
ret
; 139fe
BugCatchingContestantEventFlagTable: ; 139fe
dw EVENT_BUG_CATCHING_CONTESTANT_1A
dw EVENT_BUG_CATCHING_CONTESTANT_2A
dw EVENT_BUG_CATCHING_CONTESTANT_3A
dw EVENT_BUG_CATCHING_CONTESTANT_4A
dw EVENT_BUG_CATCHING_CONTESTANT_5A
dw EVENT_BUG_CATCHING_CONTESTANT_6A
dw EVENT_BUG_CATCHING_CONTESTANT_7A
dw EVENT_BUG_CATCHING_CONTESTANT_8A
dw EVENT_BUG_CATCHING_CONTESTANT_9A
dw EVENT_BUG_CATCHING_CONTESTANT_10A
; 13a12
ContestDropOffMons: ; 13a12
ld hl, PartyMon1HP
ld a, [hli]
or [hl]
jr z, .fainted
; Mask the rest of your party by setting the count to 1...
ld hl, PartyCount
ld a, 1
ld [hli], a
inc hl
; ... backing up the second mon index somewhere...
ld a, [hl]
ld [wBugContestSecondPartySpecies], a
; ... and replacing it with the terminator byte
ld [hl], $ff
xor a
ld [ScriptVar], a
ret
.fainted
ld a, $1
ld [ScriptVar], a
ret
; 13a31
ContestReturnMons: ; 13a31
; Restore the species of the second mon.
ld hl, PartySpecies + 1
ld a, [wBugContestSecondPartySpecies]
ld [hl], a
; Restore the party count, which must be recomputed.
ld b, $1
.loop
ld a, [hli]
cp -1
jr z, .done
inc b
jr .loop
.done
ld a, b
ld [PartyCount], a
ret
; 13a47

View File

@@ -0,0 +1,107 @@
DisplayCaughtContestMonStats: ; cc000
call ClearBGPalettes
call ClearTileMap
call ClearSprites
call LoadFontsBattleExtra
ld hl, Options
ld a, [hl]
push af
set 4, [hl]
hlcoord 0, 0
ld b, 4
ld c, 13
call TextBox
hlcoord 0, 6
ld b, 4
ld c, 13
call TextBox
hlcoord 2, 0
ld de, .Stock
call PlaceString
hlcoord 2, 6
ld de, .This
call PlaceString
hlcoord 5, 4
ld de, .Health
call PlaceString
hlcoord 5, 10
ld de, .Health
call PlaceString
ld a, [wContestMon]
ld [wd265], a
call GetPokemonName
ld de, StringBuffer1
hlcoord 1, 2
call PlaceString
ld h, b
ld l, c
ld a, [wContestMonLevel]
ld [TempMonLevel], a
call PrintLevel
ld de, EnemyMonNick
hlcoord 1, 8
call PlaceString
ld h, b
ld l, c
ld a, [EnemyMonLevel]
ld [TempMonLevel], a
call PrintLevel
hlcoord 11, 4
ld de, wContestMonMaxHP
lb bc, 2, 3
call PrintNum
hlcoord 11, 10
ld de, EnemyMonMaxHP
call PrintNum
ld hl, SwitchMonText
call PrintText
pop af
ld [Options], a
call WaitBGMap
ld b, SCGB_DIPLOMA
call GetSGBLayout
call SetPalettes
ret
.Health:
db "HEALTH@"
.Stock:
db " STOCK ", $4a, " @"
.This:
db " THIS ", $4a, " @"
SwitchMonText: ; cc0c2
; Switch #MON?
text_jump UnknownText_0x1c10cf
db "@"
DisplayAlreadyCaughtText: ; cc0c7
call GetPokemonName
ld hl, .AlreadyCaughtText
jp PrintText
.AlreadyCaughtText: ; 0xcc0d0
; You already caught a @ .
text_jump UnknownText_0x1c10dd
db "@"
Predef2F:
Predef38:
Predef39: ; cc0d5
ret

View File

@@ -0,0 +1,395 @@
_BugContestJudging: ; 1369d
call ContestScore
farcall TrainerRankings_BugContestScore
call BugContest_JudgeContestants
ld a, [wBugContestThirdPlaceWinnerID]
call LoadContestantName
ld a, [wBugContestThirdPlaceMon]
ld [wNamedObjectIndexBuffer], a
call GetPokemonName
ld hl, BugContest_ThirdPlaceText
call PrintText
ld a, [wBugContestSecondPlaceWinnerID]
call LoadContestantName
ld a, [wBugContestSecondPlaceMon]
ld [wNamedObjectIndexBuffer], a
call GetPokemonName
ld hl, BugContest_SecondPlaceText
call PrintText
ld a, [wBugContestFirstPlaceWinnerID]
call LoadContestantName
ld a, [wBugContestFirstPlaceMon]
ld [wNamedObjectIndexBuffer], a
call GetPokemonName
ld hl, BugContest_FirstPlaceText
call PrintText
jp BugContest_GetPlayersResult
; 136eb
BugContest_FirstPlaceText: ; 0x136eb
text_jump ContestJudging_FirstPlaceText
start_asm
ld de, SFX_1ST_PLACE
call PlaySFX
call WaitSFX
ld hl, BugContest_FirstPlaceScoreText
ret
; 136fd
BugContest_FirstPlaceScoreText: ; 0x136fd
; The winning score was @ points!
text_jump ContestJudging_FirstPlaceScoreText
db "@"
; 0x13702
BugContest_SecondPlaceText: ; 0x13702
; Placing second was @ , who caught a @ !@ @
text_jump ContestJudging_SecondPlaceText
start_asm
ld de, SFX_2ND_PLACE
call PlaySFX
call WaitSFX
ld hl, BugContest_SecondPlaceScoreText
ret
; 13714
BugContest_SecondPlaceScoreText: ; 0x13714
; The score was @ points!
text_jump ContestJudging_SecondPlaceScoreText
db "@"
; 0x13719
BugContest_ThirdPlaceText: ; 0x13719
; Placing third was @ , who caught a @ !@ @
text_jump ContestJudging_ThirdPlaceText
start_asm
ld de, SFX_3RD_PLACE
call PlaySFX
call WaitSFX
ld hl, BugContest_ThirdPlaceScoreText
ret
; 1372b
BugContest_ThirdPlaceScoreText: ; 0x1372b
; The score was @ points!
text_jump ContestJudging_ThirdPlaceScoreText
db "@"
; 0x13730
LoadContestantName: ; 13730
; If a = 0, get your name.
dec a
jr z, .player
; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a.
ld c, a
ld b, 0
ld hl, BugContestantPointers
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
; Copy the Trainer Class to c.
ld a, [hli]
ld c, a
; Save hl and bc for later.
push hl
push bc
; Get the Trainer Class name and copy it into wBugContestWinnerName.
callfar GetTrainerClassName
ld hl, StringBuffer1
ld de, wBugContestWinnerName
ld bc, TRAINER_CLASS_NAME_LENGTH
call CopyBytes
ld hl, wBugContestWinnerName
; Delete the trailing terminator and replace it with a space.
.next
ld a, [hli]
cp "@"
jr nz, .next
dec hl
ld [hl], " "
inc hl
ld d, h
ld e, l
; Restore the Trainer Class ID and Trainer ID pointer. Save de for later.
pop bc
pop hl
push de
; Get the name of the trainer with class c and ID b.
ld a, [hl]
ld b, a
callfar GetTrainerName
; Append the name to wBugContestWinnerName.
ld hl, StringBuffer1
pop de
ld bc, NAME_LENGTH - 1
jp CopyBytes
.player
ld hl, PlayerName
ld de, wBugContestWinnerName
ld bc, NAME_LENGTH
jp CopyBytes
; 13783
INCLUDE "data/bug_contest_winners.asm"
; 13807
BugContest_GetPlayersResult: ; 13807
ld hl, wBugContestThirdPlaceWinnerID
ld de, -4
ld b, 3
.loop
ld a, [hl]
cp 1 ; Player
jr z, .done
add hl, de
dec b
jr nz, .loop
.done
ret
; 13819
BugContest_JudgeContestants: ; 13819
call ClearContestResults
call ComputeAIContestantScores
ld hl, wBugContestTempWinnerID
ld a, 1 ; Player
ld [hli], a
ld a, [wContestMon]
ld [hli], a
ld a, [hProduct]
ld [hli], a
ld a, [hProduct + 1]
ld [hl], a
call DetermineContestWinners
ret
; 13833
ClearContestResults: ; 13833
ld hl, wBugContestResults
ld b, wBugContestWinnersEnd - wBugContestResults
xor a
.loop
ld [hli], a
dec b
jr nz, .loop
ret
; 1383e
DetermineContestWinners: ; 1383e
ld de, wBugContestTempScore
ld hl, wBugContestFirstPlaceScore
ld c, 2
call StringCmp
jr c, .not_first_place
ld hl, wBugContestSecondPlaceWinnerID
ld de, wBugContestThirdPlaceWinnerID
ld bc, 4
call CopyBytes
ld hl, wBugContestFirstPlaceWinnerID
ld de, wBugContestSecondPlaceWinnerID
ld bc, 4
call CopyBytes
ld hl, wBugContestFirstPlaceWinnerID
call CopyTempContestant
jr .done
.not_first_place
ld de, wBugContestTempScore
ld hl, wBugContestSecondPlaceScore
ld c, 2
call StringCmp
jr c, .not_second_place
ld hl, wBugContestSecondPlaceWinnerID
ld de, wBugContestThirdPlaceWinnerID
ld bc, 4
call CopyBytes
ld hl, wBugContestSecondPlaceWinnerID
call CopyTempContestant
jr .done
.not_second_place
ld de, wBugContestTempScore
ld hl, wBugContestThirdPlaceScore
ld c, 2
call StringCmp
jr c, .done
ld hl, wBugContestThirdPlaceWinnerID
call CopyTempContestant
.done
ret
; 138a0
CopyTempContestant: ; 138a0
; Could've just called CopyBytes.
ld de, wBugContestTempWinnerID
rept 3
ld a, [de]
inc de
ld [hli], a
endr
ld a, [de]
inc de
ld [hl], a
ret
; 138b0
ComputeAIContestantScores: ; 138b0
ld e, 0
.loop
push de
call Special_CheckBugContestContestantFlag
pop de
jr nz, .done
ld a, e
inc a
inc a
ld [wBugContestTempWinnerID], a
dec a
ld c, a
ld b, 0
ld hl, BugContestantPointers
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
inc hl
.loop2
call Random
and 3
cp 3
jr z, .loop2
ld c, a
ld b, 0
add hl, bc
add hl, bc
add hl, bc
ld a, [hli]
ld [wBugContestTempMon], a
ld a, [hli]
ld h, [hl]
ld l, a
call Random
and 7
ld c, a
ld b, 0
add hl, bc
ld a, h
ld [wBugContestTempScore], a
ld a, l
ld [wBugContestTempScore + 1], a
push de
call DetermineContestWinners
pop de
.done
inc e
ld a, e
cp 10
jr nz, .loop
ret
; 13900
ContestScore: ; 13900
; Determine the player's score in the Bug Catching Contest.
xor a
ld [hProduct], a
ld [hMultiplicand], a
ld a, [wContestMonSpecies] ; Species
and a
jr z, .done
; Tally the following:
; Max HP * 4
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
ld a, [wContestMonMaxHP + 1]
call .AddContestStat
; Stats
ld a, [wContestMonAttack + 1]
call .AddContestStat
ld a, [wContestMonDefense + 1]
call .AddContestStat
ld a, [wContestMonSpeed + 1]
call .AddContestStat
ld a, [wContestMonSpclAtk + 1]
call .AddContestStat
ld a, [wContestMonSpclDef + 1]
call .AddContestStat
; DVs
ld a, [wContestMonDVs + 0]
ld b, a
and 2
add a
add a
ld c, a
swap b
ld a, b
and 2
add a
add c
ld d, a
ld a, [wContestMonDVs + 1]
ld b, a
and 2
ld c, a
swap b
ld a, b
and 2
srl a
add c
add c
add d
add d
call .AddContestStat
; Remaining HP / 8
ld a, [wContestMonHP + 1]
srl a
srl a
srl a
call .AddContestStat
; Whether it's holding an item
ld a, [wContestMonItem]
and a
jr z, .done
ld a, 1
call .AddContestStat
.done
ret
; 1397f
.AddContestStat: ; 1397f
ld hl, hMultiplicand
add [hl]
ld [hl], a
ret nc
dec hl
inc [hl]
ret
; 13988

39
engine/events/card_key.asm Executable file
View File

@@ -0,0 +1,39 @@
_CardKey: ; 50779
; Are we even in the right map to use this?
ld a, [MapGroup]
cp GROUP_RADIO_TOWER_3F
jr nz, .nope
ld a, [MapNumber]
cp MAP_RADIO_TOWER_3F
jr nz, .nope
; Are we facing the slot?
ld a, [PlayerDirection]
and %1100
cp OW_UP
jr nz, .nope
call GetFacingTileCoord
ld a, d
cp 18
jr nz, .nope
ld a, e
cp 6
jr nz, .nope
; Let's use the Card Key.
ld hl, .CardKeyScript
call QueueScript
ld a, TRUE
ld [wItemEffectSucceeded], a
ret
.nope
ld a, FALSE
ld [wItemEffectSucceeded], a
ret
; 507af
.CardKeyScript: ; 0x507af
closetext
farjump MapRadioTower3FSignpost2Script
; 0x507b4

View File

@@ -0,0 +1,81 @@
CatchTutorial:: ; 4e554
ld a, [BattleType]
dec a
ld c, a
ld hl, .dw
ld b, 0
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw ; 4e564 (13:6564)
dw .DudeTutorial
dw .DudeTutorial
dw .DudeTutorial
.DudeTutorial: ; 4e56a (13:656a)
; Back up your name to your Mom's name.
ld hl, PlayerName
ld de, MomsName
ld bc, NAME_LENGTH
call CopyBytes
; Copy Dude's name to your name
ld hl, .Dude
ld de, PlayerName
ld bc, NAME_LENGTH
call CopyBytes
call .LoadDudeData
xor a
ld [hJoyDown], a
ld [hJoyPressed], a
ld a, [Options]
push af
and $f8
add $3
ld [Options], a
ld hl, .AutoInput
ld a, BANK(.AutoInput)
call StartAutoInput
callfar StartBattle
call StopAutoInput
pop af
ld [Options], a
ld hl, MomsName
ld de, PlayerName
ld bc, NAME_LENGTH
call CopyBytes
ret
.LoadDudeData: ; 4e5b7 (13:65b7)
ld hl, wDudeNumItems
ld [hl], 1
inc hl
ld [hl], POTION
inc hl
ld [hl], 1
inc hl
ld [hl], -1
ld hl, wDudeNumKeyItems
ld [hl], 0
inc hl
ld [hl], -1
ld hl, wDudeNumBalls
ld a, 1
ld [hli], a
ld a, POKE_BALL ; 5
ld [hli], a
ld [hli], a
ld [hl], -1
ret
.Dude: ; 4e5da
db "DUDE@"
.AutoInput: ; 4e5df
db NO_INPUT, $ff ; end

View File

@@ -0,0 +1,43 @@
_DudeAutoInput_A:: ; 1de28a
ld hl, DudeAutoInput_A
jr _DudeAutoInput
_DudeAutoInput_RightA: ; 1de28f
ld hl, DudeAutoInput_RightA
jr _DudeAutoInput
_DudeAutoInput_DownA: ; 1de294
ld hl, DudeAutoInput_DownA
jr _DudeAutoInput
_DudeAutoInput: ; 1de299
ld a, BANK(DudeAutoInputs)
call StartAutoInput
ret
DudeAutoInputs:
DudeAutoInput_A: ; 1de29f
db NO_INPUT, $50
db A_BUTTON, $00
db NO_INPUT, $ff ; end
DudeAutoInput_RightA: ; 1de2a5
db NO_INPUT, $08
db D_RIGHT, $00
db NO_INPUT, $08
db A_BUTTON, $00
db NO_INPUT, $ff ; end
DudeAutoInput_DownA: ; 1de2af
db NO_INPUT, $fe
db NO_INPUT, $fe
db NO_INPUT, $fe
db NO_INPUT, $fe
db D_DOWN, $00
db NO_INPUT, $fe
db NO_INPUT, $fe
db NO_INPUT, $fe
db NO_INPUT, $fe
db A_BUTTON, $00
db NO_INPUT, $ff ; end

380
engine/events/celebi.asm Executable file
View File

@@ -0,0 +1,380 @@
Special_CelebiShrineEvent: ; 4989a
call DelayFrame
ld a, [VramState]
push af
xor a
ld [VramState], a
call LoadCelebiGFX
depixel 0, 10, 7, 0
ld a, SPRITE_ANIM_INDEX_CELEBI
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $84
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
ld [hl], SPRITE_ANIM_SEQ_CELEBI
ld hl, SPRITEANIMSTRUCT_0F
add hl, bc
ld a, $80
ld [hl], a
ld a, 160 ; frame count
ld [wcf64], a
ld d, $0
.loop
ld a, [wJumptableIndex]
bit 7, a
jr nz, .done
push bc
call GetCelebiSpriteTile
inc d
push de
ld a, $90
ld [wCurrSpriteOAMAddr], a
farcall DoNextFrameForAllSprites
call CelebiEvent_CountDown
ld c, 2
call DelayFrames
pop de
pop bc
jr .loop
.done
pop af
ld [VramState], a
call .RefreshPlayerSprite_ClearAllOthers
call CelebiEvent_SetBattleType
ret
; 498f9
.RefreshPlayerSprite_ClearAllOthers: ; 498f9
ld hl, Sprites + 2
xor a
ld c, $4
.OAMloop:
ld [hli], a
inc hl
inc hl
inc hl
inc a
dec c
jr nz, .OAMloop
ld hl, Sprites + 4 * 4
ld bc, 36 * 4
xor a
call ByteFill
ret
; 49912
LoadCelebiGFX: ; 49912
farcall ClearSpriteAnims
ld de, SpecialCelebiLeafGFX
ld hl, VTiles1
lb bc, BANK(SpecialCelebiLeafGFX), 4
call Request2bpp
ld de, SpecialCelebiGFX
ld hl, VTiles0 tile $84
lb bc, BANK(SpecialCelebiGFX), $10
call Request2bpp
xor a
ld [wJumptableIndex], a
ret
; 49935
CelebiEvent_CountDown: ; 49935
ld hl, wcf64
ld a, [hl]
and a
jr z, .done
dec [hl]
ret
.done
ld hl, wJumptableIndex
set 7, [hl]
ret
; 49944
CelebiEvent_SpawnLeaf: ; 49944
; unused
ld hl, wcf65
ld a, [hl]
inc [hl]
and $7
ret nz
ld a, [hl]
and $18
sla a
add $40
ld d, a
ld e, $0
ld a, SPRITE_ANIM_INDEX_FLY_LEAF ; fly land
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $80
ret
; 49962
SpecialCelebiLeafGFX: ; 49962
INCBIN "gfx/overworld/cut_grass.2bpp"
SpecialCelebiGFX: ; 499a2
INCBIN "gfx/overworld/celebi/1.2bpp"
INCBIN "gfx/overworld/celebi/2.2bpp"
INCBIN "gfx/overworld/celebi/3.2bpp"
INCBIN "gfx/overworld/celebi/4.2bpp"
UpdateCelebiPosition: ; 49aa2 (12:5aa2)
ld hl, SPRITEANIMSTRUCT_XOFFSET
add hl, bc
ld a, [hl]
push af
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, [hl]
cp 8 * 10 + 2
jp nc, .FreezeCelebiPosition
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
inc [hl]
ld hl, SPRITEANIMSTRUCT_0F
add hl, bc
ld a, [hl]
ld d, a
cp $3a
jr c, .skip
jr z, .skip
sub $3
ld [hl], a
.skip
ld hl, SPRITEANIMSTRUCT_0E
add hl, bc
ld a, [hl]
inc [hl]
call CelebiEvent_Cosine
ld hl, SPRITEANIMSTRUCT_XOFFSET
add hl, bc
ld [hl], a
ld d, a
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
add [hl]
cp 8 * 11 + 4
jr nc, .ShiftY
cp 8 * 8 + 4
jr nc, .ReinitSpriteAnimFrame
.ShiftY:
pop af
push af
cp d
jr nc, .moving_left
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
add [hl]
cp 8 * 10
jr c, .float_up
jr .float_down
.moving_left
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
add [hl]
cp 8 * 10
jr nc, .float_up
.float_down
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, [hl]
sub $2
ld [hl], a
jr .ReinitSpriteAnimFrame
.float_up
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld a, [hl]
add $1
ld [hl], a
.ReinitSpriteAnimFrame:
pop af
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
add [hl]
cp 8 * 10
jr c, .left
cp -(8 * 3 + 2)
jr nc, .left
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
add hl, bc
ld a, SPRITE_ANIM_FRAMESET_CELEBI_RIGHT
call ReinitSpriteAnimFrame
jr .done
.left
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
add hl, bc
ld a, SPRITE_ANIM_FRAMESET_CELEBI_LEFT
call ReinitSpriteAnimFrame
.done
ret
.FreezeCelebiPosition: ; 49b30 (12:5b30)
pop af
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
add hl, bc
ld a, SPRITE_ANIM_FRAMESET_CELEBI_LEFT
call ReinitSpriteAnimFrame
ret
CelebiEvent_Cosine: ; 49b3b (12:5b3b)
add $10
and $3f
cp $20
jr nc, .negative
call .SineFunction
ld a, h
ret
.negative
and $1f
call .SineFunction
ld a, h
xor $ff
inc a
ret
.SineFunction: ; 49b52 (12:5b52)
ld e, a
ld a, d
ld d, $0
ld hl, .sinewave
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ld hl, 0
.multiply
srl a
jr nc, .even
add hl, de
.even
sla e
rl d
and a
jr nz, .multiply
ret
; 49b6e (12:5b6e)
.sinewave ; 49b6e
sine_wave $100
; 49bae
GetCelebiSpriteTile: ; 49bae
push hl
push bc
push de
ld a, d
ld d, $3
ld e, d
cp $0
jr z, .Frame1
cp d
jr z, .Frame2
call .AddE
cp d
jr z, .Frame3
call .AddE
cp d
jr z, .Frame4
call .AddE
cp d
jr c, .done
jr .restart
.Frame1:
ld a, $84
jr .load_tile
.Frame2:
ld a, $88
jr .load_tile
.Frame3:
ld a, $8c
jr .load_tile
.Frame4:
ld a, $90
.load_tile
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], a
jr .done
.restart
pop de
ld d, $ff
push de
.done
pop de
pop bc
pop hl
ret
; 49bed
.AddE: ; 49bed
push af
ld a, d
add e
ld d, a
pop af
ret
; 49bf3
CelebiEvent_SetBattleType: ; 49bf3
ld a, BATTLETYPE_CELEBI
ld [BattleType], a
ret
; 49bf9
CheckCaughtCelebi: ; 49bf9
ld a, [wBattleResult]
bit 6, a
jr z, .false
ld a, $1
ld [ScriptVar], a
jr .done
.false
xor a
ld [ScriptVar], a
.done
ret
; 49c0c

View File

@@ -0,0 +1,327 @@
SpecialHoOhChamber: ; 0x8addb
ld hl, PartySpecies
ld a, [hl]
cp HO_OH ; is Ho-oh the first Pokémon in the party?
jr nz, .done ; if not, we're done
call GetSecondaryMapHeaderPointer
ld de, EVENT_WALL_OPENED_IN_HO_OH_CHAMBER
ld b, SET_FLAG
call EventFlagAction
.done
ret
; 0x8adef
SpecialOmanyteChamber: ; 8adef
call GetSecondaryMapHeaderPointer
ld de, EVENT_WALL_OPENED_IN_OMANYTE_CHAMBER
ld b, CHECK_FLAG
call EventFlagAction
ld a, c
and a
jr nz, .nope
ld a, WATER_STONE
ld [CurItem], a
ld hl, NumItems
call CheckItem
jr c, .open
ld a, [PartyCount]
ld b, a
inc b
.loop
dec b
jr z, .nope
ld a, b
dec a
ld [CurPartyMon], a
push bc
ld a, MON_ITEM
call GetPartyParamLocation
pop bc
ld a, [hl]
cp WATER_STONE
jr nz, .loop
.open
call GetSecondaryMapHeaderPointer
ld de, EVENT_WALL_OPENED_IN_OMANYTE_CHAMBER
ld b, SET_FLAG
call EventFlagAction
.nope
ret
; 8ae30
SpecialAerodactylChamber: ; 8ae30
push de
push bc
call GetSecondaryMapHeaderPointer
ld a, h
cp HIGH(RuinsOfAlphAerodactylChamber_SecondMapHeader)
jr nz, .nope
ld a, l
cp LOW(RuinsOfAlphAerodactylChamber_SecondMapHeader)
jr nz, .nope
ld de, EVENT_WALL_OPENED_IN_AERODACTYL_CHAMBER
ld b, SET_FLAG
call EventFlagAction
scf
jr .done
.nope
and a
.done
pop bc
pop de
ret
; 8ae4e
SpecialKabutoChamber: ; 8ae4e
push hl
push de
call GetSecondaryMapHeaderPointer
ld a, h
cp HIGH(RuinsOfAlphKabutoChamber_SecondMapHeader)
jr nz, .done
ld a, l
cp LOW(RuinsOfAlphKabutoChamber_SecondMapHeader)
jr nz, .done
ld de, EVENT_WALL_OPENED_IN_KABUTO_CHAMBER
ld b, SET_FLAG
call EventFlagAction
.done
pop de
pop hl
ret
; 8ae68
Special_DisplayUnownWords: ; 8ae68
ld a, [ScriptVar]
ld hl, .MenuDataHeader_Escape
and a
jr z, .load
ld d, $0
ld e, $5
.loop
add hl, de
dec a
jr nz, .loop
.load
call LoadMenuDataHeader
xor a
ld [hBGMapMode], a
call MenuBox
call UpdateSprites
call ApplyTilemap
call MenuBoxCoord2Tile
inc hl
ld d, 0
ld e, SCREEN_WIDTH
add hl, de
add hl, de
ld a, [ScriptVar]
ld c, a
ld de, .UnownText
and a
jr z, .copy
.loop2
ld a, [de]
inc de
cp $ff
jr nz, .loop2
dec c
jr nz, .loop2
.copy
call .CopyWord
ld bc, AttrMap - TileMap
add hl, bc
call .FillAttr
call WaitBGMap2
call JoyWaitAorB
call PlayClickSFX
call CloseWindow
ret
; 8aebc
.UnownText: ; 8aebc
unownwall: MACRO
rept _NARG
if \1 == "-"
x = $64
else
if \1 >= "Y"
x = 2 * (\1 - "Y") + $60
else
if \1 >= "Q"
x = 2 * (\1 - "Q") + $40
else
if \1 >= "I"
x = 2 * (\1 - "I") + $20
else
x = 2 * (\1 - "A")
endc
endc
endc
endc
db x
shift
endr
db $ff
endm
.UnownText_Escape:
; db $08, $44, $04, $00, $2e, $08, $ff
unownwall "E", "S", "C", "A", "P", "E"
.UnownText_Light:
; db $26, $20, $0c, $0e, $46, $ff
unownwall "L", "I", "G", "H", "T"
.UnownText_Water:
; db $4c, $00, $46, $08, $42, $ff
unownwall "W", "A", "T", "E", "R"
.UnownText_Ho_Oh:
; db $0e, $2c, $64, $2c, $0e, $ff
unownwall "H", "O", "-", "O", "H"
; 8aed5
.MenuDataHeader_Escape: ; 0x8aed5
db $40 ; flags
db 04, 03 ; start coords
db 09, 16 ; end coords
.MenuDataHeader_Light: ; 0x8aeda
db $40 ; flags
db 04, 04 ; start coords
db 09, 15 ; end coords
.MenuDataHeader_Water: ; 0x8aedf
db $40 ; flags
db 04, 04 ; start coords
db 09, 15 ; end coords
.MenuDataHeader_Ho_Oh: ; 0x8aee4
db $40 ; flags
db 04, 04 ; start coords
db 09, 15 ; end coords
; 8aee9
.FillAttr: ; 8aee9
ld a, [de]
cp $ff
ret z
cp $60
ld a, VRAM_BANK_1 | PAL_BG_BROWN
jr c, .got_pal
ld a, PAL_BG_BROWN
.got_pal
call .PlaceSquare
inc hl
inc hl
inc de
jr .FillAttr
; 8aefd
.PlaceSquare: ; 8aefd
push hl
ld [hli], a
ld [hld], a
ld b, 0
ld c, SCREEN_WIDTH
add hl, bc
ld [hli], a
ld [hl], a
pop hl
ret
; 8af09
.CopyWord: ; 8af09
push hl
push de
.word_loop
ld a, [de]
cp $ff
jr z, .word_done
ld c, a
call .ConvertChar
inc hl
inc hl
inc de
jr .word_loop
.word_done
pop de
pop hl
ret
; 8af1c
.ConvertChar: ; 8af1c
push hl
ld a, c
cp $60
jr z, .Tile60
cp $62
jr z, .Tile62
cp $64
jr z, .Tile64
ld [hli], a
inc a
ld [hld], a
dec a
ld b, 0
ld c, SCREEN_WIDTH
add hl, bc
ld c, $10
add c
ld [hli], a
inc a
ld [hl], a
pop hl
ret
.Tile60:
ld [hl], $5b
inc hl
ld [hl], $5c
ld bc, SCREEN_WIDTH - 1
add hl, bc
ld [hl], $4d
inc hl
ld [hl], $5d
pop hl
ret
.Tile62:
ld [hl], $4e
inc hl
ld [hl], $4f
ld bc, SCREEN_WIDTH - 1
add hl, bc
ld [hl], $5e
inc hl
ld [hl], $5f
pop hl
ret
.Tile64:
ld [hl], $2
inc hl
ld [hl], $3
ld bc, SCREEN_WIDTH - 1
add hl, bc
ld [hl], $3
inc hl
ld [hl], $2
pop hl
ret
; 8af6b

792
engine/events/daycare.asm Executable file

File diff suppressed because it is too large Load Diff

112
engine/events/dratini.asm Normal file
View File

@@ -0,0 +1,112 @@
SpecialDratini: ; 0x8b170
; if ScriptVar is 0 or 1, change the moveset of the last Dratini in the party.
; 0: give it a special moveset with Extremespeed.
; 1: give it the normal moveset of a level 15 Dratini.
ld a, [ScriptVar]
cp $2
ret nc
ld bc, PartyCount
ld a, [bc]
ld hl, MON_SPECIES
call .GetNthPartyMon
ld a, [bc]
ld c, a
ld de, PARTYMON_STRUCT_LENGTH
.CheckForDratini:
; start at the end of the party and search backwards for a Dratini
ld a, [hl]
cp DRATINI
jr z, .GiveMoveset
ld a, l
sub e
ld l, a
ld a, h
sbc d
ld h, a
dec c
jr nz, .CheckForDratini
ret
.GiveMoveset:
push hl
ld a, [ScriptVar]
ld hl, .Movesets
ld bc, .Moveset1 - .Moveset0
call AddNTimes
; get address of mon's first move
pop de
inc de
inc de
.GiveMoves:
ld a, [hl]
and a ; is the move 00?
ret z ; if so, we're done here
push hl
push de
ld [de], a ; give the Pokémon the new move
; get the PP of the new move
dec a
ld hl, Moves + MOVE_PP
ld bc, MOVE_LENGTH
call AddNTimes
ld a, BANK(Moves)
call GetFarByte
; get the address of the move's PP and update the PP
ld hl, MON_PP - MON_MOVES
add hl, de
ld [hl], a
pop de
pop hl
inc de
inc hl
jr .GiveMoves
.Movesets:
.Moveset0:
; Dratini does not normally learn Extremespeed. This is a special gift.
db WRAP
db THUNDER_WAVE
db TWISTER
db EXTREMESPEED
db 0
.Moveset1:
; This is the normal moveset of a level 15 Dratini
db WRAP
db LEER
db THUNDER_WAVE
db TWISTER
db 0
.GetNthPartyMon: ; 0x8b1ce
; inputs:
; hl must be set to 0 before calling this function.
; a must be set to the number of Pokémon in the party.
; outputs:
; returns the address of the last Pokémon in the party in hl.
; sets carry if a is 0.
ld de, PartyMon1
add hl, de
and a
jr z, .EmptyParty
dec a
ret z
ld de, PARTYMON_STRUCT_LENGTH
.loop
add hl, de
dec a
jr nz, .loop
ret
.EmptyParty:
scf
ret
; 8b1e1

283
engine/events/elevator.asm Executable file
View File

@@ -0,0 +1,283 @@
Elevator:: ; 1342d
call .LoadPointer
call .FindCurrentFloor
jr c, .quit
ld [wElevatorOriginFloor], a
call Elevator_AskWhichFloor
jr c, .quit
ld hl, wElevatorOriginFloor
cp [hl]
jr z, .quit
call Elevator_GoToFloor
and a
ret
.quit
scf
ret
; 1344a
.LoadPointer: ; 1344a
ld a, b
ld [wElevatorPointerBank], a
ld a, e
ld [wElevatorPointer], a
ld a, d
ld [wElevatorPointer + 1], a
call .LoadFloors
ret
; 1345a
.LoadFloors: ; 1345a
ld de, CurElevator
ld bc, 4
ld hl, wElevatorPointer
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wElevatorPointerBank]
call GetFarByte
inc hl
ld [de], a
inc de
.loop
ld a, [wElevatorPointerBank]
call GetFarByte
ld [de], a
inc de
add hl, bc
cp -1
jr nz, .loop
ret
; 1347d
.FindCurrentFloor: ; 1347d
ld hl, wElevatorPointer
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wElevatorPointerBank]
call GetFarByte
ld c, a
inc hl
ld a, [BackupMapGroup]
ld d, a
ld a, [BackupMapNumber]
ld e, a
ld b, 0
.loop2
ld a, [wElevatorPointerBank]
call GetFarByte
cp -1
jr z, .fail
inc hl
inc hl
ld a, [wElevatorPointerBank]
call GetFarByte
inc hl
cp d
jr nz, .next1
ld a, [wElevatorPointerBank]
call GetFarByte
inc hl
cp e
jr nz, .next2
jr .done
.next1
inc hl
.next2
inc b
jr .loop2
.done
xor a
ld a, b
ret
.fail
scf
ret
; 134c0
Elevator_GoToFloor: ; 134c0
push af
ld hl, wElevatorPointer
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
pop af
ld bc, 4
call AddNTimes
inc hl
ld de, BackupWarpNumber
ld a, [wElevatorPointerBank]
ld bc, 3
call FarCopyBytes
ret
; 134dd
Elevator_AskWhichFloor: ; 134dd
call LoadStandardMenuDataHeader
ld hl, Elevator_WhichFloorText
call PrintText
call Elevator_GetCurrentFloorText
ld hl, Elevator_MenuDataHeader
call CopyMenuDataHeader
call InitScrollingMenu
call UpdateSprites
xor a
ld [wMenuScrollPosition], a
call ScrollingMenu
call CloseWindow
ld a, [wMenuJoypad]
cp B_BUTTON
jr z, .cancel
xor a
ld a, [wScrollingMenuCursorPosition]
ret
.cancel
scf
ret
; 1350d
Elevator_WhichFloorText: ; 0x1350d
; Which floor?
text_jump UnknownText_0x1bd2bc
db "@"
; 0x13512
Elevator_GetCurrentFloorText: ; 13512
ld hl, Options
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
hlcoord 0, 0
ld b, 4
ld c, 8
call TextBox
hlcoord 1, 2
ld de, Elevator_CurrentFloorText
call PlaceString
hlcoord 4, 4
call Elevator_GetCurrentFloorString
pop af
ld [Options], a
ret
; 13537
Elevator_CurrentFloorText: ; 13537
db "Now on:@"
; 1353f
Elevator_GetCurrentFloorString: ; 1353f
push hl
ld a, [wElevatorOriginFloor]
ld e, a
ld d, 0
ld hl, CurElevatorFloors
add hl, de
ld a, [hl]
pop de
call GetFloorString
ret
; 13550
Elevator_MenuDataHeader: ; 0x13550
db $40 ; flags
db 01, 12 ; start coords
db 09, 18 ; end coords
dw Elevator_MenuData2
db 1 ; default option
; 0x13558
Elevator_MenuData2: ; 0x13558
db $10 ; flags
db 4, 0 ; rows, columns
db 1 ; horizontal spacing
dbw 0, CurElevator
dba GetElevatorFlorStrings
dba NULL
dba NULL
; 13568
GetElevatorFlorStrings: ; 13568
ld a, [MenuSelection]
GetFloorString: ; 1356b
push de
call FloorToString
ld d, h
ld e, l
pop hl
jp PlaceString
; 13575
FloorToString: ; 13575
push de
ld e, a
ld d, 0
ld hl, .floors
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
pop de
ret
; 13583
.floors
dw .b4f
dw .b3f
dw .b2f
dw .b1f
dw ._1f
dw ._2f
dw ._3f
dw ._4f
dw ._5f
dw ._6f
dw ._7f
dw ._8f
dw ._9f
dw ._10f
dw ._11f
dw .roof
.b4f
db "B4F@"
.b3f
db "B3F@"
.b2f
db "B2F@"
.b1f
db "B1F@"
._1f
db "1F@"
._2f
db "2F@"
._3f
db "3F@"
._4f
db "4F@"
._5f
db "5F@"
._6f
db "6F@"
._7f
db "7F@"
._8f
db "8F@"
._9f
db "9F@"
._10f
db "10F@"
._11f
db "11F@"
.roof
db "ROOF@"
; 135db

469
engine/events/field_moves.asm Executable file
View File

@@ -0,0 +1,469 @@
PlayWhirlpoolSound: ; 8c7d4
call WaitSFX
ld de, SFX_SURF
call PlaySFX
call WaitSFX
ret
; 8c7e1
BlindingFlash: ; 8c7e1
farcall FadeOutPalettes
ld hl, StatusFlags
set 2, [hl] ; Flash
farcall ReplaceTimeOfDayPals
farcall UpdateTimeOfDayPal
ld b, SCGB_MAPPALS
call GetSGBLayout
farcall LoadOW_BGPal7
farcall FadeInPalettes
ret
; 8c80a
ShakeHeadbuttTree: ; 8c80a
farcall ClearSpriteAnims
ld de, CutGrassGFX
ld hl, VTiles1
lb bc, BANK(CutGrassGFX), 4
call Request2bpp
ld de, HeadbuttTreeGFX
ld hl, VTiles1 tile $04
lb bc, BANK(HeadbuttTreeGFX), 8
call Request2bpp
call Cut_Headbutt_GetPixelFacing
ld a, SPRITE_ANIM_INDEX_HEADBUTT
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $84
ld a, 36 * 4
ld [wCurrSpriteOAMAddr], a
farcall DoNextFrameForAllSprites
call HideHeadbuttTree
ld a, $20
ld [wcf64], a
call WaitSFX
ld de, SFX_SANDSTORM
call PlaySFX
.loop
ld hl, wcf64
ld a, [hl]
and a
jr z, .done
dec [hl]
ld a, 36 * 4
ld [wCurrSpriteOAMAddr], a
farcall DoNextFrameForAllSprites
call DelayFrame
jr .loop
.done
call OverworldTextModeSwitch
call WaitBGMap
xor a
ld [hBGMapMode], a
farcall ClearSpriteAnims
ld hl, Sprites + 36 * 4
ld bc, SpritesEnd - (Sprites + 36 * 4)
xor a
call ByteFill
ld de, Font
ld hl, VTiles1
lb bc, BANK(Font), 12
call Get1bpp
call ReplaceKrisSprite
ret
; 8c893
HeadbuttTreeGFX: ; 8c893
INCBIN "gfx/overworld/headbutt_tree.2bpp"
; 8c913
HideHeadbuttTree: ; 8c913
xor a
ld [hBGMapMode], a
ld a, [PlayerDirection]
and %00001100
srl a
ld e, a
ld d, 0
ld hl, TreeRelativeLocationTable
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld a, $5
ld [hli], a
ld [hld], a
ld bc, SCREEN_WIDTH
add hl, bc
ld [hli], a
ld [hld], a
call WaitBGMap
xor a
ld [hBGMapMode], a
ret
; 8c938
TreeRelativeLocationTable: ; 8c938
dwcoord 8, 8 + 2 ; RIGHT
dwcoord 8, 8 - 2 ; LEFT
dwcoord 8 - 2, 8 ; DOWN
dwcoord 8 + 2, 8 ; UP
; 8c940
OWCutAnimation: ; 8c940
; Animation index in e
; 0: Split tree in half
; 1: Mow the lawn
ld a, e
and $1
ld [wJumptableIndex], a
call .LoadCutGFX
call WaitSFX
ld de, SFX_PLACE_PUZZLE_PIECE_DOWN
call PlaySFX
.loop
ld a, [wJumptableIndex]
bit 7, a
jr nz, .finish
ld a, 36 * 4
ld [wCurrSpriteOAMAddr], a
callfar DoNextFrameForAllSprites
call OWCutJumptable
call DelayFrame
jr .loop
.finish
ret
; 8c96d
.LoadCutGFX: ; 8c96d
callfar ClearSpriteAnims ; pointless to farcall
ld de, CutGrassGFX
ld hl, VTiles1
lb bc, BANK(CutGrassGFX), 4
call Request2bpp
ld de, CutTreeGFX
ld hl, VTiles1 tile $4
lb bc, BANK(CutTreeGFX), 4
call Request2bpp
ret
; 8c98c
CutTreeGFX: ; c898c
INCBIN "gfx/overworld/cut_tree.2bpp"
; c89cc
CutGrassGFX: ; 8c9cc
INCBIN "gfx/overworld/cut_grass.2bpp"
; 8ca0c
OWCutJumptable: ; 8ca0c
ld a, [wJumptableIndex]
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
; 8ca1b
.dw ; 8ca1b (23:4a1b)
dw Cut_SpawnAnimateTree
dw Cut_SpawnAnimateLeaves
dw Cut_StartWaiting
dw Cut_WaitAnimSFX
Cut_SpawnAnimateTree: ; 8ca23 (23:4a23)
call Cut_Headbutt_GetPixelFacing
ld a, SPRITE_ANIM_INDEX_CUT_TREE ; cut tree
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $84
ld a, 32
ld [wcf64], a
; Cut_StartWaiting
ld hl, wJumptableIndex
inc [hl]
inc [hl]
ret
Cut_SpawnAnimateLeaves: ; 8ca3c (23:4a3c)
call Cut_GetLeafSpawnCoords
xor a
call Cut_SpawnLeaf
ld a, $10
call Cut_SpawnLeaf
ld a, $20
call Cut_SpawnLeaf
ld a, $30
call Cut_SpawnLeaf
ld a, 32 ; frames
ld [wcf64], a
; Cut_StartWaiting
ld hl, wJumptableIndex
inc [hl]
ret
Cut_StartWaiting: ; 8ca5c (23:4a5c)
ld a, $1
ld [hBGMapMode], a
; Cut_WaitAnimSFX
ld hl, wJumptableIndex
inc [hl]
Cut_WaitAnimSFX: ; 8ca64 (23:4a64)
ld hl, wcf64
ld a, [hl]
and a
jr z, .finished
dec [hl]
ret
.finished
ld hl, wJumptableIndex
set 7, [hl]
ret
Cut_SpawnLeaf: ; 8ca73 (23:4a73)
push de
push af
ld a, SPRITE_ANIM_INDEX_LEAF ; leaf
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $80
ld hl, SPRITEANIMSTRUCT_0E
add hl, bc
ld [hl], $4
pop af
ld hl, SPRITEANIMSTRUCT_0C
add hl, bc
ld [hl], a
pop de
ret
Cut_GetLeafSpawnCoords: ; 8ca8e (23:4a8e)
ld de, 0
ld a, [wMetatileStandingX]
bit 0, a
jr z, .left_side
set 0, e
.left_side
ld a, [wMetatileStandingY]
bit 0, a
jr z, .top_side
set 1, e
.top_side
ld a, [PlayerDirection]
and %00001100
add e
ld e, a
ld hl, .Coords
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ret
; 8cab3 (23:4ab3)
.Coords: ; 8cab3
dbpixel 11, 12 ; facing down, top left
dbpixel 9, 12 ; facing down, top right
dbpixel 11, 14 ; facing down, bottom left
dbpixel 9, 14 ; facing down, bottom right
dbpixel 11, 8 ; facing up, top left
dbpixel 9, 8 ; facing up, top right
dbpixel 11, 10 ; facing up, bottom left
dbpixel 9, 10 ; facing up, bottom right
dbpixel 7, 12 ; facing left, top left
dbpixel 9, 12 ; facing left, top right
dbpixel 7, 10 ; facing left, bottom left
dbpixel 9, 10 ; facing left, bottom right
dbpixel 11, 12 ; facing right, top left
dbpixel 13, 12 ; facing right, top right
dbpixel 11, 10 ; facing right, bottom left
dbpixel 13, 10 ; facing right, bottom right
; 8cad3
Cut_Headbutt_GetPixelFacing: ; 8cad3 (23:4ad3)
ld a, [PlayerDirection]
and %00001100
srl a
ld e, a
ld d, 0
ld hl, .Coords
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ret
; 8cae5 (23:4ae5)
.Coords: ; 8cae5
dbpixel 10, 13
dbpixel 10, 9
dbpixel 8, 11
dbpixel 12, 11
; 8caed
FlyFromAnim: ; 8caed
call DelayFrame
ld a, [VramState]
push af
xor a
ld [VramState], a
call FlyFunction_InitGFX
depixel 10, 10, 4, 0
ld a, SPRITE_ANIM_INDEX_RED_WALK
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $84
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
ld [hl], SPRITE_ANIM_SEQ_FLY_FROM
ld a, 128
ld [wcf64], a
.loop
ld a, [wJumptableIndex]
bit 7, a
jr nz, .exit
ld a, 0 * 4
ld [wCurrSpriteOAMAddr], a
callfar DoNextFrameForAllSprites
call FlyFunction_FrameTimer
call DelayFrame
jr .loop
.exit
pop af
ld [VramState], a
ret
; 8cb33
FlyToAnim: ; 8cb33
call DelayFrame
ld a, [VramState]
push af
xor a
ld [VramState], a
call FlyFunction_InitGFX
depixel 31, 10, 4, 0
ld a, SPRITE_ANIM_INDEX_RED_WALK
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $84
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
ld [hl], SPRITE_ANIM_SEQ_FLY_TO
ld hl, SPRITEANIMSTRUCT_0F
add hl, bc
ld [hl], 11 * 8
ld a, 64
ld [wcf64], a
.loop
ld a, [wJumptableIndex]
bit 7, a
jr nz, .exit
ld a, 0 * 4
ld [wCurrSpriteOAMAddr], a
callfar DoNextFrameForAllSprites
call FlyFunction_FrameTimer
call DelayFrame
jr .loop
.exit
pop af
ld [VramState], a
call .RestorePlayerSprite_DespawnLeaves
ret
.RestorePlayerSprite_DespawnLeaves: ; 8cb82 (23:4b82)
ld hl, Sprites + 2 ; Tile ID
xor a
ld c, $4
.loop2
ld [hli], a
inc hl
inc hl
inc hl
inc a
dec c
jr nz, .loop2
ld hl, Sprites + 4 * 4
ld bc, SpritesEnd - (Sprites + 4 * 4)
xor a
call ByteFill
ret
FlyFunction_InitGFX: ; 8cb9b (23:4b9b)
callfar ClearSpriteAnims
ld de, CutGrassGFX
ld hl, VTiles1 tile $00
lb bc, BANK(CutGrassGFX), 4
call Request2bpp
ld a, [CurPartyMon]
ld hl, PartySpecies
ld e, a
ld d, 0
add hl, de
ld a, [hl]
ld [wd265], a
ld e, $84
farcall FlyFunction_GetMonIcon
xor a
ld [wJumptableIndex], a
ret
FlyFunction_FrameTimer: ; 8cbc8 (23:4bc8)
call .SpawnLeaf
ld hl, wcf64
ld a, [hl]
and a
jr z, .exit
dec [hl]
cp $40
ret c
and $7
ret nz
ld de, SFX_FLY
call PlaySFX
ret
.exit
ld hl, wJumptableIndex
set 7, [hl]
ret
.SpawnLeaf: ; 8cbe6 (23:4be6)
ld hl, wcf65
ld a, [hl]
inc [hl]
and $7
ret nz
ld a, [hl]
and (6 * 8) >> 1
sla a
add 8 * 8 ; gives a number in [$40, $50, $60, $70]
ld d, a
ld e, $0
ld a, SPRITE_ANIM_INDEX_FLY_LEAF ; fly land
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $80
ret

133
engine/events/fish.asm Normal file
View File

@@ -0,0 +1,133 @@
Fish: ; 92402
; Using a fishing rod.
; Fish for monsters with rod e in encounter group d.
; Return monster e at level d.
push af
push bc
push hl
ld b, e
call GetFishGroupIndex
ld hl, FishGroups
rept 7
add hl, de
endr
call .Fish
pop hl
pop bc
pop af
ret
; 9241a
.Fish: ; 9241a
; Fish for monsters with rod b from encounter data in FishGroup at hl.
; Return monster e at level d.
call Random
cp [hl]
jr nc, .no_bite
; Get encounter data by rod:
; 0: Old
; 1: Good
; 2: Super
inc hl
ld e, b
ld d, 0
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
; Compare the encounter chance to select a Pokemon.
call Random
.loop
cp [hl]
jr z, .ok
jr c, .ok
inc hl
inc hl
inc hl
jr .loop
.ok
inc hl
; Species 0 reads from a time-based encounter table.
ld a, [hli]
ld d, a
and a
call z, .TimeEncounter
ld e, [hl]
ret
.no_bite
ld de, 0
ret
.TimeEncounter:
; The level byte is repurposed as the index for the new table.
ld e, [hl]
ld d, 0
ld hl, TimeFishGroups
rept 4
add hl, de
endr
ld a, [TimeOfDay]
and 3
cp NITE_F
jr c, .time_species
inc hl
inc hl
.time_species
ld d, [hl]
inc hl
ret
; 9245b
GetFishGroupIndex: ; 9245b
; Return the index of fishgroup d in de.
push hl
ld hl, DailyFlags
bit 2, [hl]
pop hl
jr z, .done
ld a, d
cp FISHGROUP_QWILFISH
jr z, .qwilfish
cp FISHGROUP_REMORAID
jr z, .remoraid
.done
dec d
ld e, d
ld d, 0
ret
.qwilfish
ld a, [wFishingSwarmFlag]
cp FISHSWARM_QWILFISH
jr nz, .done
ld d, FISHGROUP_QWILFISH_SWARM
jr .done
.remoraid
ld a, [wFishingSwarmFlag]
cp FISHSWARM_REMORAID
jr nz, .done
ld d, FISHGROUP_REMORAID_SWARM
jr .done
; 92488
INCLUDE "data/wild/fish.asm"

Some files were not shown because too many files have changed in this diff Show More