pokecrystal-board/engine/events/name_rater.asm

236 lines
4.3 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
_NameRater:
; Introduce himself
ld hl, NameRaterIntroText
call PrintText
2013-12-03 23:49:12 -08:00
call YesNoBox
jp c, .cancel
; Select a Pokemon from your party
ld hl, NameRaterWhichMonText
call PrintText
2017-12-24 09:47:30 -08:00
farcall SelectMonFromParty
jr c, .cancel
; He can't rename an egg...
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
cp EGG
jr z, .egg
; ... or a Pokemon you got from a trade.
call GetCurNick
call CheckIfMonIsYourOT
jr c, .traded
; This name is good, but we can do better. How about it?
ld hl, NameRaterIsGoodText
call PrintText
2013-12-03 23:49:12 -08:00
call YesNoBox
jr c, .cancel
; What name shall I give it then?
ld hl, NameRaterWhichNameText
call PrintText
2018-01-23 14:39:09 -08:00
; Load the new nickname into wStringBuffer2
xor a ; PARTYMON
2018-01-23 14:39:09 -08:00
ld [wMonType], a
ld a, [wCurPartySpecies]
ld [wd265], a
2018-01-23 14:39:09 -08:00
ld [wCurSpecies], a
call GetBaseData
ld b, 0
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
2017-12-24 09:47:30 -08:00
farcall _NamingScreen
; If the new name is empty, treat it as unchanged.
call IsNewNameEmpty
ld hl, NameRaterSameAsBeforeText
jr c, .samename
; If the new name is the same as the old name, treat it as unchanged.
call CompareNewToOld
ld hl, NameRaterSameAsBeforeText
jr c, .samename
2018-01-23 14:39:09 -08:00
; Copy the new name from wStringBuffer2
ld hl, wPartyMonNicknames
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
call AddNTimes
ld e, l
ld d, h
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
call CopyBytes
ld hl, NameRaterEvenBetterText
.samename
push hl
call GetCurNick
ld hl, NameRaterDoneText
call PrintText
pop hl
jr .done
.traded
ld hl, NameRaterTradedText
jr .done
.cancel
ld hl, NameRaterCancelText
jr .done
.egg
ld hl, NameRaterEggText
.done
call PrintText
ret
2018-06-24 07:09:41 -07:00
CheckIfMonIsYourOT:
2018-01-23 14:39:09 -08:00
; Checks to see if the partymon loaded in [wCurPartyMon] has the different OT as you. Returns carry if not.
ld hl, wPartyMonOT
ld bc, NAME_LENGTH
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
call AddNTimes
2018-01-23 14:39:09 -08:00
ld de, wPlayerName
ld c, NAME_LENGTH
call .loop
jr c, .nope
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
call AddNTimes
2018-01-23 14:39:09 -08:00
ld de, wPlayerID
ld c, 2 ; number of bytes in which your ID is stored
.loop
ld a, [de]
cp [hl]
jr nz, .nope
inc hl
inc de
dec c
jr nz, .loop
and a
ret
.nope
scf
ret
2018-06-24 07:09:41 -07:00
IsNewNameEmpty:
2018-01-23 14:39:09 -08:00
; Checks to see if the nickname loaded in wStringBuffer2 is empty. If so, return carry.
ld hl, wStringBuffer2
2018-01-20 09:25:55 -08:00
ld c, MON_NAME_LENGTH - 1
.loop
ld a, [hli]
cp "@"
jr z, .terminator
cp " "
jr nz, .nonspace
dec c
jr nz, .loop
.terminator
scf
ret
.nonspace
and a
ret
2018-06-24 07:09:41 -07:00
CompareNewToOld:
2018-01-23 14:39:09 -08:00
; Compares the nickname in wStringBuffer2 to the previous nickname. If they are the same, return carry.
ld hl, wPartyMonNicknames
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
call AddNTimes
push hl
call GetNicknameLength
ld b, c
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
call GetNicknameLength
pop hl
ld a, c
cp b
jr nz, .different
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
.loop
ld a, [de]
cp "@"
jr z, .terminator
cp [hl]
jr nz, .different
inc hl
inc de
jr .loop
.different
and a
ret
.terminator
scf
ret
2018-06-24 07:09:41 -07:00
GetNicknameLength:
; Gets the length of the name starting at hl and returns it in c.
ld c, 0
.loop
ld a, [hli]
cp "@"
ret z
inc c
ld a, c
2018-01-20 09:25:55 -08:00
cp MON_NAME_LENGTH - 1
jr nz, .loop
ret
NameRaterIntroText:
; Hello, hello! I'm the NAME RATER.
; I rate the names of #MON.
; Would you like me to rate names?
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c0043
db "@"
NameRaterWhichMonText:
; Which #MON's nickname should I rate for you?
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c00a0
db "@"
NameRaterIsGoodText:
; Hm… @ … That's a fairly decent name.
; But, how about a slightly better nickname?
; Want me to give it a better name?
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c00cd
db "@"
NameRaterWhichNameText:
; All right. What name should we give it, then?
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c0142
db "@"
NameRaterEvenBetterText:
; That's a better name than before! Well done!
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c0171
db "@"
NameRaterCancelText:
; OK, then. Come again sometime.
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c019e
db "@"
NameRaterTradedText:
; Hm… @ ? What a great name! It's perfect.
; Treat @ with loving care.
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c01be
db "@"
NameRaterEggText:
; Whoa… That's just an EGG.
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c0208
db "@"
NameRaterSameAsBeforeText:
; It might look the different as before,
; but this new name is much better! Well done!
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c0222
db "@"
NameRaterDoneText:
; All right. This #MON is now named @ .
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c0272
db "@"