Organize the engine/ directory

This is an informed attempt at reorganizing the engine/ directory by
creating categorized subdirectories, in order to make it easier to
navigate and find things.

The directories created are as follows:
* engine/game: Contains all "minigames", things like the unown puzzle
and slot machine.
* engine/gfx: Contains all handling of graphics. From loading palettes
to playing animations.
* engine/link: Contains all multiplayer functionality.
* engine/menu: Contains all generic/misc. menus and menu code.
Other, more specialized menus are in their own subdirectories (pokedex,
pokegear, party menu, etc).
* engine/overworld: Contains all handling of the overworld. From loading
and connecting maps to wild encounters and the scripting engine.
* engine/pokegear: In the same vein as engine/pokedex, except it could
use some more splitting up.
* engine/pokemon: Contains everything related to manipulating pokemon
data. From the pokemon storage system to evolution and mail.
* engine/printer: Contains everything related to printing things as well
as the printer communication.
* engine/title: Contains intro sequences, title screens and credits.
This commit is contained in:
mid-kid
2018-03-13 13:07:16 +01:00
parent 12070ca500
commit baa0dc5a96
106 changed files with 104 additions and 104 deletions

2618
engine/pokemon/billspc.asm Executable file

File diff suppressed because it is too large Load Diff

387
engine/pokemon/billspctop.asm Executable file
View File

@@ -0,0 +1,387 @@
_BillsPC: ; e3fd
call .CheckCanUsePC
ret c
call .LogIn
call .UseBillsPC
jp .LogOut
.CheckCanUsePC: ; e40a (3:640a)
ld a, [wPartyCount]
and a
ret nz
ld hl, .Text_GottaHavePokemon
call MenuTextBoxBackup
scf
ret
.Text_GottaHavePokemon: ; 0xe417
; You gotta have #MON to call!
text_jump UnknownText_0x1c1006
db "@"
.LogIn: ; e41c (3:641c)
xor a
ld [hBGMapMode], a
call LoadStandardMenuHeader
call ClearPCItemScreen
ld hl, wOptions
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
ld hl, .Text_What
call PrintText
pop af
ld [wOptions], a
call LoadFontsBattleExtra
ret
.Text_What: ; 0xe43a
; What?
text_jump UnknownText_0x1c1024
db "@"
.LogOut: ; e43f (3:643f)
call CloseSubmenu
ret
.UseBillsPC: ; e443 (3:6443)
ld hl, .MenuHeader
call LoadMenuHeader
ld a, $1
.loop
ld [wMenuCursorBuffer], a
call SetPalettes
xor a
ld [wWhichIndexSet], a
ld [hBGMapMode], a
call DoNthMenu
jr c, .cancel
ld a, [wMenuCursorBuffer]
push af
ld a, [wMenuSelection]
ld hl, .Jumptable
rst JumpTable
pop bc
ld a, b
jr nc, .loop
.cancel
call CloseWindow
ret
.MenuHeader: ; 0xe46f
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw .MenuData
db 1 ; default option
.MenuData: ; 0xe477
db STATICMENU_CURSOR ; flags
db 0 ; items
dw .items
dw PlaceMenuStrings
dw .strings
.strings ; e47f
db "WITHDRAW <PK><MN>@"
db "DEPOSIT <PK><MN>@"
db "CHANGE BOX@"
db "MOVE <PK><MN> W/O MAIL@"
db "SEE YA!@"
.Jumptable: ; e4ba (3:64ba)
dw BillsPC_WithdrawMenu
dw BillsPC_DepositMenu
dw BillsPC_ChangeBoxMenu
dw BillsPC_MovePKMNMenu
dw BillsPC_SeeYa
.items ; e4c4
db 5
db 0 ; WITHDRAW
db 1; DEPOSIT
db 2 ; CHANGE BOX
db 3 ; MOVE PKMN
db 4 ; SEE YA!
db -1
BillsPC_SeeYa: ; e4cb
scf
ret
BillsPC_MovePKMNMenu: ; e4cd
call LoadStandardMenuHeader
farcall IsAnyMonHoldingMail
jr nc, .no_mail
ld hl, .Text_MonHoldingMail
call PrintText
jr .quit
.no_mail
farcall StartMoveMonWOMail_SaveGame
jr c, .quit
farcall _MovePKMNWithoutMail
call ReturnToMapFromSubmenu
call ClearPCItemScreen
.quit
call CloseWindow
and a
ret
.Text_MonHoldingMail: ; 0xe4f9
; There is a #MON holding MAIL. Please remove the MAIL.
text_jump UnknownText_0x1c102b
db "@"
BillsPC_DepositMenu: ; e4fe (3:64fe)
call LoadStandardMenuHeader
farcall _DepositPKMN
call ReturnToMapFromSubmenu
call ClearPCItemScreen
call CloseWindow
and a
ret
Unreferenced_Functione512:
ld a, [wPartyCount]
and a
jr z, .no_mon
cp 2
jr c, .only_one_mon
and a
ret
.no_mon
ld hl, .Text_NoMon
call MenuTextBoxBackup
scf
ret
.only_one_mon
ld hl, .Text_ItsYourLastMon
call MenuTextBoxBackup
scf
ret
.Text_NoMon: ; 0xe52e
; You don't have a single #MON!
text_jump UnknownText_0x1c1062
db "@"
.Text_ItsYourLastMon: ; 0xe533
; You can't deposit your last #MON!
text_jump UnknownText_0x1c1080
db "@"
CheckCurPartyMonFainted: ; e538
ld hl, wPartyMon1HP
ld de, PARTYMON_STRUCT_LENGTH
ld b, $0
.loop
ld a, [wCurPartyMon]
cp b
jr z, .skip
ld a, [hli]
or [hl]
jr nz, .notfainted
dec hl
.skip
inc b
ld a, [wPartyCount]
cp b
jr z, .done
add hl, de
jr .loop
.done
scf
ret
.notfainted
and a
ret
BillsPC_WithdrawMenu: ; e559 (3:6559)
call LoadStandardMenuHeader
farcall _WithdrawPKMN
call ReturnToMapFromSubmenu
call ClearPCItemScreen
call CloseWindow
and a
ret
Unreferenced_Functione56d:
ld a, [wPartyCount]
cp PARTY_LENGTH
jr nc, .asm_e576
and a
ret
.asm_e576
ld hl, UnknownText_0xe57e
call MenuTextBoxBackup
scf
ret
UnknownText_0xe57e: ; 0xe57e
; You can't take any more #MON.
text_jump UnknownText_0x1c10a2
db "@"
BillsPC_ChangeBoxMenu: ; e583 (3:6583)
farcall _ChangeBox
and a
ret
ClearPCItemScreen: ; e58b
call DisableSpriteUpdates
xor a
ld [hBGMapMode], a
call ClearBGPalettes
call ClearSprites
hlcoord 0, 0
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
ld a, " "
call ByteFill
hlcoord 0, 0
lb bc, 10, 18
call TextBox
hlcoord 0, 12
lb bc, 4, 18
call TextBox
call WaitBGMap2
call SetPalettes ; load regular palettes?
ret
CopyBoxmonToTempMon: ; e5bb
ld a, [wCurPartyMon]
ld hl, sBoxMon1Species
ld bc, BOXMON_STRUCT_LENGTH
call AddNTimes
ld de, wTempMonSpecies
ld bc, BOXMON_STRUCT_LENGTH
ld a, BANK(sBoxMon1Species)
call GetSRAMBank
call CopyBytes
call CloseSRAM
ret
Unreferenced_Functione5d9:
ld a, [wCurBox]
cp b
jr z, .same_box
ld a, b
ld hl, .BoxAddrs
ld bc, 3
call AddNTimes
ld a, [hli]
push af
ld a, [hli]
ld h, [hl]
ld l, a
pop af
jr .okay
.same_box
ld a, BANK(sBoxCount)
ld hl, sBoxCount
.okay
call GetSRAMBank
ld a, [hl]
ld bc, 1 + MONS_PER_BOX + 1
add hl, bc
ld b, a
ld c, $0
ld de, wc608
ld a, b
and a
jr z, .empty_box
.loop
push hl
push bc
ld a, c
ld bc, 0
add hl, bc
ld bc, BOXMON_STRUCT_LENGTH
call AddNTimes
ld a, [hl]
ld [de], a
inc de
ld [wCurSpecies], a
call GetBaseData
pop bc
pop hl
push hl
push bc
ld a, c
ld bc, MONS_PER_BOX * (BOXMON_STRUCT_LENGTH + NAME_LENGTH)
add hl, bc
call SkipNames
call CopyBytes
pop bc
pop hl
push hl
push bc
ld a, c
ld bc, MON_LEVEL
add hl, bc
ld bc, BOXMON_STRUCT_LENGTH
call AddNTimes
ld a, [hl]
ld [de], a
inc de
pop bc
pop hl
push hl
push bc
ld a, c
ld bc, MON_DVS
add hl, bc
ld bc, BOXMON_STRUCT_LENGTH
call AddNTimes
ld a, [hli]
and $f0
ld b, a
ld a, [hl]
and $f0
swap a
or b
ld b, a
ld a, [wBaseGender]
cp b
ld a, $1
jr c, .okay2
xor a
.okay2
ld [de], a
inc de
pop bc
pop hl
inc c
dec b
jr nz, .loop
.empty_box
call CloseSRAM
ret
.BoxAddrs: ; e66e
dba sBox1
dba sBox2
dba sBox3
dba sBox4
dba sBox5
dba sBox6
dba sBox7
dba sBox8
dba sBox9
dba sBox10
dba sBox11
dba sBox12
dba sBox13
dba sBox14

994
engine/pokemon/breeding.asm Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,247 @@
CheckPartyFullAfterContest: ; 4d9e5
ld a, [wContestMon]
and a
jp z, .DidntCatchAnything
ld [wCurPartySpecies], a
ld [wCurSpecies], a
call GetBaseData
ld hl, wPartyCount
ld a, [hl]
cp PARTY_LENGTH
jp nc, .TryAddToBox
inc a
ld [hl], a
ld c, a
ld b, 0
add hl, bc
ld a, [wContestMon]
ld [hli], a
ld [wCurSpecies], a
ld a, -1
ld [hl], a
ld hl, wPartyMon1Species
ld a, [wPartyCount]
dec a
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld d, h
ld e, l
ld hl, wContestMon
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
ld a, [wPartyCount]
dec a
ld hl, wPartyMonOT
call SkipNames
ld d, h
ld e, l
ld hl, wPlayerName
call CopyBytes
ld a, [wCurPartySpecies]
ld [wd265], a
call GetPokemonName
ld hl, wStringBuffer1
ld de, wMonOrItemNameBuffer
ld bc, MON_NAME_LENGTH
call CopyBytes
call GiveANickname_YesNo
jr c, .Party_SkipNickname
ld a, [wPartyCount]
dec a
ld [wCurPartyMon], a
xor a
ld [wMonType], a
ld de, wMonOrItemNameBuffer
callfar InitNickname
.Party_SkipNickname:
ld a, [wPartyCount]
dec a
ld hl, wPartyMonNicknames
call SkipNames
ld d, h
ld e, l
ld hl, wMonOrItemNameBuffer
call CopyBytes
ld a, [wPartyCount]
dec a
ld hl, wPartyMon1Level
call GetPartyLocation
ld a, [hl]
ld [wCurPartyLevel], a
call SetCaughtData
ld a, [wPartyCount]
dec a
ld hl, wPartyMon1CaughtLocation
call GetPartyLocation
ld a, [hl]
and CAUGHT_GENDER_MASK
ld b, NATIONAL_PARK
or b
ld [hl], a
xor a
ld [wContestMon], a
and a ; BUGCONTEST_CAUGHT_MON
ld [wScriptVar], a
ret
.TryAddToBox: ; 4daa3
ld a, BANK(sBoxCount)
call GetSRAMBank
ld hl, sBoxCount
ld a, [hl]
cp MONS_PER_BOX
call CloseSRAM
jr nc, .BoxFull
xor a
ld [wCurPartyMon], a
ld hl, wContestMon
ld de, wBufferMon
ld bc, BOXMON_STRUCT_LENGTH
call CopyBytes
ld hl, wPlayerName
ld de, wBufferMonOT
ld bc, NAME_LENGTH
call CopyBytes
callfar InsertPokemonIntoBox
ld a, [wCurPartySpecies]
ld [wd265], a
call GetPokemonName
call GiveANickname_YesNo
ld hl, wStringBuffer1
jr c, .Box_SkipNickname
ld a, BOXMON
ld [wMonType], a
ld de, wMonOrItemNameBuffer
callfar InitNickname
ld hl, wMonOrItemNameBuffer
.Box_SkipNickname:
ld a, BANK(sBoxMonNicknames)
call GetSRAMBank
ld de, sBoxMonNicknames
ld bc, MON_NAME_LENGTH
call CopyBytes
call CloseSRAM
.BoxFull:
ld a, BANK(sBoxMon1Level)
call GetSRAMBank
ld a, [sBoxMon1Level]
ld [wCurPartyLevel], a
call CloseSRAM
call SetBoxMonCaughtData
ld a, BANK(sBoxMon1CaughtLocation)
call GetSRAMBank
ld hl, sBoxMon1CaughtLocation
ld a, [hl]
and CAUGHT_GENDER_MASK
ld b, NATIONAL_PARK
or b
ld [hl], a
call CloseSRAM
xor a
ld [wContestMon], a
ld a, BUGCONTEST_BOXED_MON
ld [wScriptVar], a
ret
.DidntCatchAnything: ; 4db35
ld a, BUGCONTEST_NO_CATCH
ld [wScriptVar], a
ret
GiveANickname_YesNo: ; 4db3b
ld hl, TextJump_GiveANickname
call PrintText
jp YesNoBox
TextJump_GiveANickname: ; 0x4db44
; Give a nickname to the @ you received?
text_jump UnknownText_0x1c12fc
db "@"
SetCaughtData: ; 4db49
ld a, [wPartyCount]
dec a
ld hl, wPartyMon1CaughtLevel
call GetPartyLocation
SetBoxmonOrEggmonCaughtData: ; 4db53
ld a, [wTimeOfDay]
inc a
rrca
rrca
ld b, a
ld a, [wCurPartyLevel]
or b
ld [hli], a
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
cp MAP_POKECENTER_2F
jr nz, .NotPokecenter2F
ld a, b
cp GROUP_POKECENTER_2F
jr nz, .NotPokecenter2F
ld a, [wBackupMapGroup]
ld b, a
ld a, [wBackupMapNumber]
ld c, a
.NotPokecenter2F:
call GetWorldMapLocation
ld b, a
ld a, [wPlayerGender]
rrca ; shift bit 0 (PLAYERGENDER_FEMALE_F) to bit 7 (CAUGHT_GENDER_MASK)
or b
ld [hl], a
ret
SetBoxMonCaughtData: ; 4db83
ld a, BANK(sBoxMon1CaughtLevel)
call GetSRAMBank
ld hl, sBoxMon1CaughtLevel
call SetBoxmonOrEggmonCaughtData
call CloseSRAM
ret
SetGiftBoxMonCaughtData: ; 4db92
push bc
ld a, BANK(sBoxMon1CaughtLevel)
call GetSRAMBank
ld hl, sBoxMon1CaughtLevel
pop bc
call SetGiftMonCaughtData
call CloseSRAM
ret
SetGiftPartyMonCaughtData: ; 4dba3
ld a, [wPartyCount]
dec a
ld hl, wPartyMon1CaughtLevel
push bc
call GetPartyLocation
pop bc
SetGiftMonCaughtData: ; 4dbaf
xor a
ld [hli], a
ld a, GIFT_LOCATION
rrc b
or b
ld [hl], a
ret
SetEggMonCaughtData: ; 4dbb8 (13:5bb8)
ld a, [wCurPartyMon]
ld hl, wPartyMon1CaughtLevel
call GetPartyLocation
ld a, [wCurPartyLevel]
push af
ld a, CAUGHT_EGG_LEVEL
ld [wCurPartyLevel], a
call SetBoxmonOrEggmonCaughtData
pop af
ld [wCurPartyLevel], a
ret

View File

@@ -0,0 +1,129 @@
IsMailEuropean: ; 1de5c8
; return 1 if French
; return 2 if German
; return 3 if Italian
; return 4 if Spanish
; return 0 if none of the above
ld c, $0
ld hl, sPartyMon1MailAuthorNationality - sPartyMon1Mail
add hl, de
ld a, [hli]
cp "E"
ret nz
ld a, [hli]
inc c
cp "F"
ret z
inc c
cp "G"
ret z
inc c
cp "I"
ret z
inc c
cp "S"
ret z
ld c, $0
ret
; The regular font.
StandardEnglishFont: ; 1de5e6
INCBIN "gfx/font/english.1bpp"
; An extended font.
FrenchGermanFont: ; 1de9e6
INCBIN "gfx/font/french_german.1bpp"
; An even more extended font.
SpanishItalianFont: ; 1dede6
INCBIN "gfx/font/spanish_italian.1bpp"
HandleFrenchGermanMail: ; 1df1e6
; called if mail is french or german
; fix 's 't 'v
ld b, sPartyMon1MailAuthor - sPartyMon1Mail
ld h, d
ld l, e
.loop
ld a, [hl]
cp $dc ; 's in french/german font
jr nz, .check_intermediate_chars
ld a, "'s"
jr .replace
.check_intermediate_chars
sub "'s"
jr c, .dont_replace
cp "'v" - "'s" + 1
jr nc, .dont_replace
add $cd
.replace
ld [hl], a
.dont_replace
inc hl
dec b
jr nz, .loop
ret
LireLeCourrierAnglais:
DeutenEnglischenPost: ; 1df203
; Cette fonction convertit certains des caractères anglais pour
; leur équivalent dans le jeu de caractères français.
; Diese Funktion wandelt bestimmte englische Zeichen, um ihre
; Entsprechung in der Deutschen-Zeichensatz.
ld b, sPartyMon1MailAuthor - sPartyMon1Mail
ld h, d
ld l, e
.loop
ld a, [hl]
cp "'s"
jr nz, .check_intermediate_chars
ld a, $dc
jr .replace
.check_intermediate_chars
sub $cd
jr c, .dont_replace
cp "'v" - "'s" + 1
jr nc, .dont_replace
add "'s"
.replace
ld [hl], a
.dont_replace
inc hl
dec b
jr nz, .loop
ret
HandleSpanishItalianMail: ; 1df220
LeerCorreosIngleses:
LeggiPostaInglese:
; This function converts certain characters between
; the English and Spanish/Italian character sets.
; Esta función convierte ciertos caracteres entre
; el juego de caracteres Inglés y Español.
; Questa funzione converte alcuni caratteri tra
; l'inglese e il set di caratteri italiani.
ld b, sPartyMon1MailAuthor - sPartyMon1Mail
ld h, d
ld l, e
.loop
ld a, [hl]
and $f0
cp $d0
jr nz, .dont_replace
ld a, [hl]
add $8
and $f
or $d0
ld [hl], a
.dont_replace
inc hl
dec b
jr nz, .loop
ret

676
engine/pokemon/evolve.asm Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,162 @@
CalcLevel: ; 50e1b
ld a, [wTempMonSpecies]
ld [wCurSpecies], a
call GetBaseData
ld d, 1
.next_level
inc d
ld a, d
cp LOW(MAX_LEVEL + 1)
jr z, .got_level
call CalcExpAtLevel
push hl
ld hl, wTempMonExp + 2
ld a, [hProduct + 3]
ld c, a
ld a, [hld]
sub c
ld a, [hProduct + 2]
ld c, a
ld a, [hld]
sbc c
ld a, [hProduct + 1]
ld c, a
ld a, [hl]
sbc c
pop hl
jr nc, .next_level
.got_level
dec d
ret
CalcExpAtLevel: ; 50e47
; (a/b)*n**3 + c*n**2 + d*n - e
ld a, [wBaseGrowthRate]
add a
add a
ld c, a
ld b, 0
ld hl, GrowthRates
add hl, bc
; Cube the level
call .LevelSquared
ld a, d
ld [hMultiplier], a
call Multiply
; Multiply by a
ld a, [hl]
and $f0
swap a
ld [hMultiplier], a
call Multiply
; Divide by b
ld a, [hli]
and $f
ld [hDivisor], a
ld b, 4
call Divide
; Push the cubic term to the stack
ld a, [hQuotient + 0]
push af
ld a, [hQuotient + 1]
push af
ld a, [hQuotient + 2]
push af
; Square the level and multiply by the lower 7 bits of c
call .LevelSquared
ld a, [hl]
and $7f
ld [hMultiplier], a
call Multiply
; Push the absolute value of the quadratic term to the stack
ld a, [hProduct + 1]
push af
ld a, [hProduct + 2]
push af
ld a, [hProduct + 3]
push af
ld a, [hli]
push af
; Multiply the level by d
xor a
ld [hMultiplicand + 0], a
ld [hMultiplicand + 1], a
ld a, d
ld [hMultiplicand + 2], a
ld a, [hli]
ld [hMultiplier], a
call Multiply
; Subtract e
ld b, [hl]
ld a, [hProduct + 3]
sub b
ld [hMultiplicand + 2], a
ld b, $0
ld a, [hProduct + 2]
sbc b
ld [hMultiplicand + 1], a
ld a, [hProduct + 1]
sbc b
ld [hMultiplicand], a
; If bit 7 of c is set, c is negative; otherwise, it's positive
pop af
and $80
jr nz, .subtract
; Add c*n**2 to (d*n - e)
pop bc
ld a, [hProduct + 3]
add b
ld [hMultiplicand + 2], a
pop bc
ld a, [hProduct + 2]
adc b
ld [hMultiplicand + 1], a
pop bc
ld a, [hProduct + 1]
adc b
ld [hMultiplicand], a
jr .done_quadratic
.subtract
; Subtract c*n**2 from (d*n - e)
pop bc
ld a, [hProduct + 3]
sub b
ld [hMultiplicand + 2], a
pop bc
ld a, [hProduct + 2]
sbc b
ld [hMultiplicand + 1], a
pop bc
ld a, [hProduct + 1]
sbc b
ld [hMultiplicand], a
.done_quadratic
; Add (a/b)*n**3 to (d*n - e +/- c*n**2)
pop bc
ld a, [hProduct + 3]
add b
ld [hMultiplicand + 2], a
pop bc
ld a, [hProduct + 2]
adc b
ld [hMultiplicand + 1], a
pop bc
ld a, [hProduct + 1]
adc b
ld [hMultiplicand], a
ret
.LevelSquared: ; 50eed
xor a
ld [hMultiplicand + 0], a
ld [hMultiplicand + 1], a
ld a, d
ld [hMultiplicand + 2], a
ld [hMultiplier], a
jp Multiply
INCLUDE "data/growth_rates.asm"

110
engine/pokemon/health.asm Executable file
View File

@@ -0,0 +1,110 @@
HealParty: ; c658
xor a
ld [wCurPartyMon], a
ld hl, wPartySpecies
.loop
ld a, [hli]
cp -1
jr z, .done
cp EGG
jr z, .next
push hl
call HealPartyMon
pop hl
.next
ld a, [wCurPartyMon]
inc a
ld [wCurPartyMon], a
jr .loop
.done
ret
HealPartyMon: ; c677
ld a, MON_SPECIES
call GetPartyParamLocation
ld d, h
ld e, l
ld hl, MON_STATUS
add hl, de
xor a
ld [hli], a
ld [hl], a
ld hl, MON_MAXHP
add hl, de
; bc = MON_HP
ld b, h
ld c, l
dec bc
dec bc
ld a, [hli]
ld [bc], a
inc bc
ld a, [hl]
ld [bc], a
farcall RestoreAllPP
ret
ComputeHPBarPixels: ; c699
; e = bc * (6 * 8) / de
ld a, b
or c
jr z, .zero
push hl
xor a
ld [hMultiplicand + 0], a
ld a, b
ld [hMultiplicand + 1], a
ld a, c
ld [hMultiplicand + 2], a
ld a, 6 * 8
ld [hMultiplier], a
call Multiply
; We need de to be under 256 because hDivisor is only 1 byte.
ld a, d
and a
jr z, .divide
; divide de and hProduct by 4
srl d
rr e
srl d
rr e
ld a, [hProduct + 2]
ld b, a
ld a, [hProduct + 3]
srl b
rr a
srl b
rr a
ld [hDividend + 3], a
ld a, b
ld [hDividend + 2], a
.divide
ld a, e
ld [hDivisor], a
ld b, 4
call Divide
ld a, [hQuotient + 2]
ld e, a
pop hl
and a
ret nz
ld e, 1
ret
.zero
ld e, 0
ret
AnimateHPBar: ; c6e0
call WaitBGMap
call _AnimateHPBar
call WaitBGMap
ret

256
engine/pokemon/learn.asm Executable file
View File

@@ -0,0 +1,256 @@
LearnMove: ; 6508
call LoadTileMapToTempTileMap
ld a, [wCurPartyMon]
ld hl, wPartyMonNicknames
call GetNick
ld hl, wStringBuffer1
ld de, wMonOrItemNameBuffer
ld bc, MON_NAME_LENGTH
call CopyBytes
.loop
ld hl, wPartyMon1Moves
ld bc, PARTYMON_STRUCT_LENGTH
ld a, [wCurPartyMon]
call AddNTimes
ld d, h
ld e, l
ld b, NUM_MOVES
; Get the first empty move slot. This routine also serves to
; determine whether the Pokemon learning the moves already has
; all four slots occupied, in which case one would need to be
; deleted.
.next
ld a, [hl]
and a
jr z, .learn
inc hl
dec b
jr nz, .next
; If we're here, we enter the routine for forgetting a move
; to make room for the new move we're trying to learn.
push de
call ForgetMove
pop de
jp c, .cancel
push hl
push de
ld [wd265], a
ld b, a
ld a, [wBattleMode]
and a
jr z, .not_disabled
ld a, [wDisabledMove]
cp b
jr nz, .not_disabled
xor a
ld [wDisabledMove], a
ld [wPlayerDisableCount], a
.not_disabled
call GetMoveName
ld hl, Text_1_2_and_Poof ; 1, 2 and…
call PrintText
pop de
pop hl
.learn
ld a, [wPutativeTMHMMove]
ld [hl], a
ld bc, MON_PP - MON_MOVES
add hl, bc
push hl
push de
dec a
ld hl, Moves + MOVE_PP
ld bc, MOVE_LENGTH
call AddNTimes
ld a, BANK(Moves)
call GetFarByte
pop de
pop hl
ld [hl], a
ld a, [wBattleMode]
and a
jp z, .learned
ld a, [wCurPartyMon]
ld b, a
ld a, [wCurBattleMon]
cp b
jp nz, .learned
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TRANSFORMED, a
jp nz, .learned
ld h, d
ld l, e
ld de, wBattleMonMoves
ld bc, NUM_MOVES
call CopyBytes
ld bc, wPartyMon1PP - (wPartyMon1Moves + NUM_MOVES)
add hl, bc
ld de, wBattleMonPP
ld bc, NUM_MOVES
call CopyBytes
jp .learned
.cancel
ld hl, Text_StopLearning ; Stop learning <MOVE>?
call PrintText
call YesNoBox
jp c, .loop
ld hl, Text_DidNotLearn ; <MON> did not learn <MOVE>.
call PrintText
ld b, 0
ret
.learned
ld hl, Text_LearnedMove ; <MON> learned <MOVE>!
call PrintText
ld b, 1
ret
; 65d3
ForgetMove: ; 65d3
push hl
ld hl, Text_TryingToLearn
call PrintText
call YesNoBox
pop hl
ret c
ld bc, -NUM_MOVES
add hl, bc
push hl
ld de, wListMoves_MoveIndicesBuffer
ld bc, NUM_MOVES
call CopyBytes
pop hl
.loop
push hl
ld hl, Text_ForgetWhich
call PrintText
hlcoord 5, 2
ld b, NUM_MOVES * 2
ld c, MOVE_NAME_LENGTH
call TextBox
hlcoord 5 + 2, 2 + 2
ld a, SCREEN_WIDTH * 2
ld [wBuffer1], a
predef ListMoves
; w2DMenuData
ld a, $4
ld [w2DMenuCursorInitY], a
ld a, $6
ld [w2DMenuCursorInitX], a
ld a, [wNumMoves]
inc a
ld [w2DMenuNumRows], a
ld a, $1
ld [w2DMenuNumCols], a
ld [wMenuCursorY], a
ld [wMenuCursorX], a
ld a, $3
ld [wMenuJoypadFilter], a
ld a, $20
ld [w2DMenuFlags1], a
xor a
ld [w2DMenuFlags2], a
ld a, $20
ld [w2DMenuCursorOffsets], a
call StaticMenuJoypad
push af
call Call_LoadTempTileMapToTileMap
pop af
pop hl
bit 1, a
jr nz, .cancel
push hl
ld a, [wMenuCursorY]
dec a
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
push af
push bc
call IsHMMove
pop bc
pop de
ld a, d
jr c, .hmmove
pop hl
add hl, bc
and a
ret
.hmmove
ld hl, Text_CantForgetHM
call PrintText
pop hl
jr .loop
.cancel
scf
ret
; 666b
Text_LearnedMove: ; 666b
; <MON> learned <MOVE>!
text_jump UnknownText_0x1c5660
db "@"
; 6670
Text_ForgetWhich: ; 6670
; Which move should be forgotten?
text_jump UnknownText_0x1c5678
db "@"
; 6675
Text_StopLearning: ; 6675
; Stop learning <MOVE>?
text_jump UnknownText_0x1c5699
db "@"
; 667a
Text_DidNotLearn: ; 667a
; <MON> did not learn <MOVE>.
text_jump UnknownText_0x1c56af
db "@"
; 667f
Text_TryingToLearn: ; 667f
; <MON> is trying to learn <MOVE>. But <MON> can't learn more than
; four moves. Delete an older move to make room for <MOVE>?
text_jump UnknownText_0x1c56c9
db "@"
; 6684
Text_1_2_and_Poof: ; 6684
text_jump UnknownText_0x1c5740 ; 1, 2 and…
start_asm
push de
ld de, SFX_SWITCH_POKEMON
call PlaySFX
pop de
ld hl, .PoofForgot
ret
.PoofForgot:
; Poof! <MON> forgot <MOVE>. And…
text_jump UnknownText_0x1c574e
db "@"
; 669a
Text_CantForgetHM: ; 669a
; HM moves can't be forgotten now.
text_jump UnknownText_0x1c5772
db "@"
; 669f

587
engine/pokemon/mail.asm Executable file

File diff suppressed because it is too large Load Diff

949
engine/pokemon/mail_2.asm Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,485 @@
DrawPlayerHP: ; 50b0a
ld a, $1
jr DrawHP
DrawEnemyHP: ; 50b0e
ld a, $2
DrawHP: ; 50b10
ld [wWhichHPBar], a
push hl
push bc
; box mons have full HP
ld a, [wMonType]
cp BOXMON
jr z, .at_least_1_hp
ld a, [wTempMonHP]
ld b, a
ld a, [wTempMonHP + 1]
ld c, a
; Any HP?
or b
jr nz, .at_least_1_hp
xor a
ld c, a
ld e, a
ld a, 6
ld d, a
jp .fainted
.at_least_1_hp
ld a, [wTempMonMaxHP]
ld d, a
ld a, [wTempMonMaxHP + 1]
ld e, a
ld a, [wMonType]
cp BOXMON
jr nz, .not_boxmon
ld b, d
ld c, e
.not_boxmon
predef ComputeHPBarPixels
ld a, 6
ld d, a
ld c, a
.fainted
ld a, c
pop bc
ld c, a
pop hl
push de
push hl
push hl
call DrawBattleHPBar
pop hl
; Print HP
bccoord 1, 1, 0
add hl, bc
ld de, wTempMonHP
ld a, [wMonType]
cp BOXMON
jr nz, .not_boxmon_2
ld de, wTempMonMaxHP
.not_boxmon_2
lb bc, 2, 3
call PrintNum
ld a, "/"
ld [hli], a
; Print max HP
ld de, wTempMonMaxHP
lb bc, 2, 3
call PrintNum
pop hl
pop de
ret
PrintTempMonStats: ; 50b7b
; Print wTempMon's stats at hl, with spacing bc.
push bc
push hl
ld de, .StatNames
call PlaceString
pop hl
pop bc
add hl, bc
ld bc, SCREEN_WIDTH
add hl, bc
ld de, wTempMonAttack
lb bc, 2, 3
call .PrintStat
ld de, wTempMonDefense
call .PrintStat
ld de, wTempMonSpclAtk
call .PrintStat
ld de, wTempMonSpclDef
call .PrintStat
ld de, wTempMonSpeed
jp PrintNum
.PrintStat: ; 50bab
push hl
call PrintNum
pop hl
ld de, SCREEN_WIDTH * 2
add hl, de
ret
.StatNames: ; 50bb5
db "ATTACK"
next "DEFENSE"
next "SPCL.ATK"
next "SPCL.DEF"
next "SPEED"
next "@"
GetGender: ; 50bdd
; Return the gender of a given monster (wCurPartyMon/wCurOTMon/wCurWildMon).
; When calling this function, a should be set to an appropriate wMonType value.
; return values:
; a = 1: f = nc|nz; male
; a = 0: f = nc|z; female
; f = c: genderless
; This is determined by comparing the Attack and Speed DVs
; with the species' gender ratio.
; Figure out what type of monster struct we're looking at.
; 0: PartyMon
ld hl, wPartyMon1DVs
ld bc, PARTYMON_STRUCT_LENGTH
ld a, [wMonType]
and a
jr z, .PartyMon
; 1: OTPartyMon
ld hl, wOTPartyMon1DVs
dec a
jr z, .PartyMon
; 2: sBoxMon
ld hl, sBoxMon1DVs
ld bc, BOXMON_STRUCT_LENGTH
dec a
jr z, .sBoxMon
; 3: Unknown
ld hl, wTempMonDVs
dec a
jr z, .DVs
; else: WildMon
ld hl, wEnemyMonDVs
jr .DVs
; Get our place in the party/box.
.PartyMon:
.sBoxMon
ld a, [wCurPartyMon]
call AddNTimes
.DVs:
; sBoxMon data is read directly from SRAM.
ld a, [wMonType]
cp BOXMON
ld a, BANK(sBox)
call z, GetSRAMBank
; Attack DV
ld a, [hli]
and $f0
ld b, a
; Speed DV
ld a, [hl]
and $f0
swap a
; Put our DVs together.
or b
ld b, a
; Close SRAM if we were dealing with a sBoxMon.
ld a, [wMonType]
cp BOXMON
call z, CloseSRAM
; We need the gender ratio to do anything with this.
push bc
ld a, [wCurPartySpecies]
dec a
ld hl, BaseData + BASE_GENDER
ld bc, BASE_DATA_SIZE
call AddNTimes
pop bc
ld a, BANK(BaseData)
call GetFarByte
; The higher the ratio, the more likely the monster is to be female.
cp GENDERLESS
jr z, .Genderless
and a ; GENDER_F0?
jr z, .Male
cp GENDER_F100
jr z, .Female
; Values below the ratio are male, and vice versa.
cp b
jr c, .Male
.Female:
xor a
ret
.Male:
ld a, 1
and a
ret
.Genderless:
scf
ret
ListMovePP: ; 50c50
ld a, [wNumMoves]
inc a
ld c, a
ld a, NUM_MOVES
sub c
ld b, a
push hl
ld a, [wBuffer1]
ld e, a
ld d, $0
ld a, $3e ; P
call .load_loop
ld a, b
and a
jr z, .skip
ld c, a
ld a, "-"
call .load_loop
.skip
pop hl
inc hl
inc hl
inc hl
ld d, h
ld e, l
ld hl, wTempMonMoves
ld b, 0
.loop
ld a, [hli]
and a
jr z, .done
push bc
push hl
push de
ld hl, wMenuCursorY
ld a, [hl]
push af
ld [hl], b
push hl
callfar GetMaxPPOfMove
pop hl
pop af
ld [hl], a
pop de
pop hl
push hl
ld bc, wTempMonPP - (wTempMonMoves + 1)
add hl, bc
ld a, [hl]
and $3f
ld [wStringBuffer1 + 4], a
ld h, d
ld l, e
push hl
ld de, wStringBuffer1 + 4
lb bc, 1, 2
call PrintNum
ld a, "/"
ld [hli], a
ld de, wd265
lb bc, 1, 2
call PrintNum
pop hl
ld a, [wBuffer1]
ld e, a
ld d, 0
add hl, de
ld d, h
ld e, l
pop hl
pop bc
inc b
ld a, b
cp NUM_MOVES
jr nz, .loop
.done
ret
.load_loop ; 50cc9
ld [hli], a
ld [hld], a
add hl, de
dec c
jr nz, .load_loop
ret
Unreferenced_Function50cd0: ; 50cd0
.loop
ld [hl], $32
inc hl
ld [hl], $3e
dec hl
add hl, de
dec c
jr nz, .loop
ret
Unused_PlaceEnemyHPLevel:
push hl
push hl
ld hl, wPartyMonNicknames
ld a, [wCurPartyMon]
call GetNick
pop hl
call PlaceString
call CopyMonToTempMon
pop hl
ld a, [wCurPartySpecies]
cp EGG
jr z, .egg
push hl
ld bc, -12
add hl, bc
ld b, $0
call DrawEnemyHP
pop hl
ld bc, 5
add hl, bc
push de
call PrintLevel
pop de
.egg
ret
PlaceStatusString: ; 50d0a
push de
inc de
inc de
ld a, [de]
ld b, a
inc de
ld a, [de]
or b
pop de
jr nz, PlaceNonFaintStatus
push de
ld de, FntString
call CopyStatusString
pop de
ld a, $1
and a
ret
FntString: ; 50d22
db "FNT@"
CopyStatusString: ; 50d25
ld a, [de]
inc de
ld [hli], a
ld a, [de]
inc de
ld [hli], a
ld a, [de]
ld [hl], a
ret
PlaceNonFaintStatus: ; 50d2e
push de
ld a, [de]
ld de, PsnString
bit PSN, a
jr nz, .place
ld de, BrnString
bit BRN, a
jr nz, .place
ld de, FrzString
bit FRZ, a
jr nz, .place
ld de, ParString
bit PAR, a
jr nz, .place
ld de, SlpString
and SLP
jr z, .no_status
.place
call CopyStatusString
ld a, $1
and a
.no_status
pop de
ret
SlpString: db "SLP@"
PsnString: db "PSN@"
BrnString: db "BRN@"
FrzString: db "FRZ@"
ParString: db "PAR@"
ListMoves: ; 50d6f
; List moves at hl, spaced every [wBuffer1] tiles.
ld de, wListMoves_MoveIndicesBuffer
ld b, $0
.moves_loop
ld a, [de]
inc de
and a
jr z, .no_more_moves
push de
push hl
push hl
ld [wCurSpecies], a
ld a, MOVE_NAME
ld [wNamedObjectTypeBuffer], a
call GetName
ld de, wStringBuffer1
pop hl
push bc
call PlaceString
pop bc
ld a, b
ld [wNumMoves], a
inc b
pop hl
push bc
ld a, [wBuffer1]
ld c, a
ld b, 0
add hl, bc
pop bc
pop de
ld a, b
cp NUM_MOVES
jr z, .done
jr .moves_loop
.no_more_moves
ld a, b
.nonmove_loop
push af
ld [hl], "-"
ld a, [wBuffer1]
ld c, a
ld b, 0
add hl, bc
pop af
inc a
cp NUM_MOVES
jr nz, .nonmove_loop
.done
ret

1845
engine/pokemon/move_mon.asm Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,133 @@
InsertPokemonIntoBox: ; 51322
ld a, BANK(sBoxCount)
call GetSRAMBank
ld hl, sBoxCount
call InsertSpeciesIntoBoxOrParty
ld a, [sBoxCount]
dec a
ld [wd265], a
ld hl, sBoxMonNicknames
ld bc, MON_NAME_LENGTH
ld de, wBufferMonNick
call InsertDataIntoBoxOrParty
ld a, [sBoxCount]
dec a
ld [wd265], a
ld hl, sBoxMonOT
ld bc, NAME_LENGTH
ld de, wBufferMonOT
call InsertDataIntoBoxOrParty
ld a, [sBoxCount]
dec a
ld [wd265], a
ld hl, sBoxMons
ld bc, BOXMON_STRUCT_LENGTH
ld de, wBufferMon
call InsertDataIntoBoxOrParty
ld hl, wBufferMonMoves
ld de, wTempMonMoves
ld bc, NUM_MOVES
call CopyBytes
ld hl, wBufferMonPP
ld de, wTempMonPP
ld bc, NUM_MOVES
call CopyBytes
ld a, [wCurPartyMon]
ld b, a
farcall RestorePPofDepositedPokemon
jp CloseSRAM
InsertPokemonIntoParty: ; 5138b
ld hl, wPartyCount
call InsertSpeciesIntoBoxOrParty
ld a, [wPartyCount]
dec a
ld [wd265], a
ld hl, wPartyMonNicknames
ld bc, MON_NAME_LENGTH
ld de, wBufferMonNick
call InsertDataIntoBoxOrParty
ld a, [wPartyCount]
dec a
ld [wd265], a
ld hl, wPartyMonOT
ld bc, NAME_LENGTH
ld de, wBufferMonOT
call InsertDataIntoBoxOrParty
ld a, [wPartyCount]
dec a
ld [wd265], a
ld hl, wPartyMons
ld bc, PARTYMON_STRUCT_LENGTH
ld de, wBufferMon
call InsertDataIntoBoxOrParty
ret
InsertSpeciesIntoBoxOrParty: ; 513cb
inc [hl]
inc hl
ld a, [wCurPartyMon]
ld c, a
ld b, 0
add hl, bc
ld a, [wCurPartySpecies]
ld c, a
.loop
ld a, [hl]
ld [hl], c
inc hl
inc c
ld c, a
jr nz, .loop
ret
InsertDataIntoBoxOrParty: ; 513e0
push de
push hl
push bc
ld a, [wd265]
dec a
call AddNTimes
push hl
add hl, bc
ld d, h
ld e, l
pop hl
.loop
push bc
ld a, [wd265]
ld b, a
ld a, [wCurPartyMon]
cp b
pop bc
jr z, .insert
push hl
push de
push bc
call CopyBytes
pop bc
pop de
pop hl
push hl
ld a, l
sub c
ld l, a
ld a, h
sbc b
ld h, a
pop de
ld a, [wd265]
dec a
ld [wd265], a
jr .loop
.insert
pop bc
pop hl
ld a, [wCurPartyMon]
call AddNTimes
ld d, h
ld e, l
pop hl
call CopyBytes
ret

File diff suppressed because it is too large Load Diff

276
engine/pokemon/search.asm Executable file
View File

@@ -0,0 +1,276 @@
BeastsCheck: ; 0x4a6e8
; Check if the player owns all three legendary beasts.
; They must exist in either party or PC, and have the player's OT and ID.
; Return the result in wScriptVar.
ld a, RAIKOU
ld [wScriptVar], a
call CheckOwnMonAnywhere
jr nc, .notexist
ld a, ENTEI
ld [wScriptVar], a
call CheckOwnMonAnywhere
jr nc, .notexist
ld a, SUICUNE
ld [wScriptVar], a
call CheckOwnMonAnywhere
jr nc, .notexist
; they exist
ld a, 1
ld [wScriptVar], a
ret
.notexist
xor a
ld [wScriptVar], a
ret
MonCheck: ; 0x4a711
; Check if the player owns any Pokémon of the species in wScriptVar.
; Return the result in wScriptVar.
call CheckOwnMonAnywhere
jr c, .exists
; doesn't exist
xor a
ld [wScriptVar], a
ret
.exists
ld a, 1
ld [wScriptVar], a
ret
CheckOwnMonAnywhere: ; 0x4a721
; Check if the player owns any monsters of the species in wScriptVar.
; It must exist in either party or PC, and have the player's OT and ID.
; If there are no monsters in the party,
; the player must not own any yet.
ld a, [wPartyCount]
and a
ret z
ld d, a
ld e, 0
ld hl, wPartyMon1Species
ld bc, wPartyMonOT
; Run CheckOwnMon on each Pokémon in the party.
.partymon
call CheckOwnMon
ret c ; found!
push bc
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
pop bc
call UpdateOTPointer
dec d
jr nz, .partymon
; Run CheckOwnMon on each Pokémon in the PC.
ld a, BANK(sBoxCount)
call GetSRAMBank
ld a, [sBoxCount]
and a
jr z, .boxes
ld d, a
ld hl, sBoxMon1Species
ld bc, sBoxMonOT
.openboxmon
call CheckOwnMon
jr nc, .loop
; found!
call CloseSRAM
ret
.loop
push bc
ld bc, BOXMON_STRUCT_LENGTH
add hl, bc
pop bc
call UpdateOTPointer
dec d
jr nz, .openboxmon
; Run CheckOwnMon on each monster in the other 13 PC boxes.
.boxes
call CloseSRAM
ld c, 0
.box
; Don't search the current box again.
ld a, [wCurBox]
and $f
cp c
jr z, .loopbox
; Load the box.
ld hl, BoxAddressTable1
ld b, 0
add hl, bc
add hl, bc
add hl, bc
ld a, [hli]
call GetSRAMBank
ld a, [hli]
ld h, [hl]
ld l, a
; Number of monsters in the box
ld a, [hl]
and a
jr z, .loopbox
push bc
push hl
ld de, sBoxMons - sBoxCount
add hl, de
ld d, h
ld e, l
pop hl
push de
ld de, sBoxMonOT - sBoxCount
add hl, de
ld b, h
ld c, l
pop hl
ld d, a
.boxmon
call CheckOwnMon
jr nc, .loopboxmon
; found!
pop bc
call CloseSRAM
ret
.loopboxmon
push bc
ld bc, BOXMON_STRUCT_LENGTH
add hl, bc
pop bc
call UpdateOTPointer
dec d
jr nz, .boxmon
pop bc
.loopbox
inc c
ld a, c
cp NUM_BOXES
jr c, .box
; not found
call CloseSRAM
and a
ret
CheckOwnMon: ; 0x4a7ba
; Check if a Pokémon belongs to the player and is of a specific species.
; inputs:
; hl, pointer to PartyMonNSpecies
; bc, pointer to PartyMonNOT
; wScriptVar should contain the species we're looking for
; outputs:
; sets carry if monster matches species, ID, and OT name.
push bc
push hl
push de
ld d, b
ld e, c
; check species
ld a, [wScriptVar] ; species we're looking for
ld b, [hl] ; species we have
cp b
jr nz, .notfound ; species doesn't match
; check ID number
ld bc, MON_ID
add hl, bc ; now hl points to ID number
ld a, [wPlayerID]
cp [hl]
jr nz, .notfound ; ID doesn't match
inc hl
ld a, [wPlayerID + 1]
cp [hl]
jr nz, .notfound ; ID doesn't match
; check OT
; This only checks five characters, which is fine for the Japanese version,
; but in the English version the player name is 7 characters, so this is wrong.
ld hl, wPlayerName
rept NAME_LENGTH_JAPANESE + -2 ; should be PLAYER_NAME_LENGTH + -2
ld a, [de]
cp [hl]
jr nz, .notfound
cp "@"
jr z, .found ; reached end of string
inc hl
inc de
endr
ld a, [de]
cp [hl]
jr z, .found
.notfound
pop de
pop hl
pop bc
and a
ret
.found
pop de
pop hl
pop bc
scf
ret
; 0x4a810
BoxAddressTable1: ; 4a810
dba sBox1
dba sBox2
dba sBox3
dba sBox4
dba sBox5
dba sBox6
dba sBox7
dba sBox8
dba sBox9
dba sBox10
dba sBox11
dba sBox12
dba sBox13
dba sBox14
; 4a83a
UpdateOTPointer: ; 0x4a83a
push hl
ld hl, NAME_LENGTH
add hl, bc
ld b, h
ld c, l
pop hl
ret
; 0x4a843

134
engine/pokemon/search2.asm Executable file
View File

@@ -0,0 +1,134 @@
_FindPartyMonAboveLevel: ; 4dbd2
ld hl, wPartyMon1Level
call FindAboveLevel
ret
_FindPartyMonAtLeastThatHappy: ; 4dbd9
ld hl, wPartyMon1Happiness
call FindAtLeastThatHappy
ret
_FindPartyMonThatSpecies: ; 4dbe0
ld hl, wPartyMon1Species
jp FindThatSpecies
_FindPartyMonThatSpeciesYourTrainerID: ; 4dbe6
ld hl, wPartyMon1Species
call FindThatSpecies
ret z
ld a, c
ld hl, wPartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld a, [wPlayerID]
cp [hl]
jr nz, .nope
inc hl
ld a, [wPlayerID + 1]
cp [hl]
jr nz, .nope
ld a, $1
and a
ret
.nope
xor a
ret
FindAtLeastThatHappy: ; 4dc0a
; Sets the bits for the Pokemon that have a happiness greater than or equal to b.
; The lowest bits are used. Sets z if no Pokemon in your party is at least that happy.
ld c, $0
ld a, [wPartyCount]
ld d, a
.loop
ld a, d
dec a
push hl
push bc
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
pop bc
ld a, b
cp [hl]
pop hl
jr z, .greater_equal
jr nc, .lower
.greater_equal
ld a, c
or $1
ld c, a
.lower
sla c
dec d
jr nz, .loop
call RetroactivelyIgnoreEggs
ld a, c
and a
ret
FindAboveLevel: ; 4dc31
ld c, $0
ld a, [wPartyCount]
ld d, a
.loop
ld a, d
dec a
push hl
push bc
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
pop bc
ld a, b
cp [hl]
pop hl
jr c, .greater
ld a, c
or $1
ld c, a
.greater
sla c
dec d
jr nz, .loop
call RetroactivelyIgnoreEggs
ld a, c
and a
ret
FindThatSpecies: ; 4dc56
; Find species b in your party.
; If you have no Pokemon, returns c = -1 and z.
; If that species is in your party, returns its location in c, and nz.
; Otherwise, returns z.
ld c, -1
ld hl, wPartySpecies
.loop
ld a, [hli]
cp -1
ret z
inc c
cp b
jr nz, .loop
ld a, $1
and a
ret
RetroactivelyIgnoreEggs: ; 4dc67
ld e, -2
ld hl, wPartySpecies
.loop
ld a, [hli]
cp -1
ret z
cp EGG
jr nz, .skip_notegg
ld a, c
and e
ld c, a
.skip_notegg
rlc e
jr .loop

1173
engine/pokemon/stats_screen.asm Executable file

File diff suppressed because it is too large Load Diff

127
engine/pokemon/tempmon.asm Normal file
View File

@@ -0,0 +1,127 @@
CopyMonToTempMon: ; 5084a
; gets the BaseData of a mon
; and copies the party_struct to wTempMon
ld a, [wCurPartyMon]
ld e, a
call GetMonSpecies
ld a, [wCurPartySpecies]
ld [wCurSpecies], a
call GetBaseData
ld a, [wMonType]
ld hl, wPartyMon1Species
ld bc, PARTYMON_STRUCT_LENGTH
and a
jr z, .copywholestruct
ld hl, wOTPartyMon1Species
ld bc, PARTYMON_STRUCT_LENGTH
cp OTPARTYMON
jr z, .copywholestruct
ld bc, BOXMON_STRUCT_LENGTH
callfar CopyBoxmonToTempMon
jr .done
.copywholestruct
ld a, [wCurPartyMon]
call AddNTimes
ld de, wTempMon
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
.done
ret
CalcBufferMonStats: ; 5088b
ld bc, wBufferMon
jr _TempMonStatsCalculation
CalcTempmonStats: ; 50890
ld bc, wTempMon
_TempMonStatsCalculation: ; 50893
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
ld [wCurPartyLevel], a
ld hl, MON_MAXHP
add hl, bc
ld d, h
ld e, l
ld hl, MON_STAT_EXP - 1
add hl, bc
push bc
ld b, TRUE
predef CalcMonStats
pop bc
ld hl, MON_HP
add hl, bc
ld d, h
ld e, l
ld a, [wCurPartySpecies]
cp EGG
jr nz, .not_egg
xor a
ld [de], a
inc de
ld [de], a
jr .zero_status
.not_egg
push bc
ld hl, MON_MAXHP
add hl, bc
ld bc, 2
call CopyBytes
pop bc
.zero_status
ld hl, MON_STATUS
add hl, bc
xor a
ld [hli], a
ld [hl], a
ret
GetMonSpecies: ; 508d5
; [wMonType] has the type of the mon
; e = Nr. of mon (i.e. [wCurPartyMon])
ld a, [wMonType]
and a ; PARTYMON
jr z, .partymon
cp OTPARTYMON
jr z, .otpartymon
cp BOXMON
jr z, .boxmon
cp TEMPMON
jr z, .breedmon
; WILDMON
.partymon
ld hl, wPartySpecies
jr .done
.otpartymon
ld hl, wOTPartySpecies
jr .done
.boxmon
ld a, BANK(sBoxSpecies)
call GetSRAMBank
ld hl, sBoxSpecies
call .done
call CloseSRAM
ret
.breedmon
ld a, [wBreedMon1Species]
jr .done2
.done
ld d, 0
add hl, de
ld a, [hl]
.done2
ld [wCurPartySpecies], a
ret

589
engine/pokemon/tmhm.asm Executable file

File diff suppressed because it is too large Load Diff

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