2018-06-24 14:09:41 +00:00
|
|
|
|
CheckMagikarpLength:
|
2015-10-11 16:15:03 +00:00
|
|
|
|
; Returns 3 if you select a Magikarp that beats the previous record.
|
|
|
|
|
; Returns 2 if you select a Magikarp, but the current record is longer.
|
|
|
|
|
; Returns 1 if you press B in the Pokemon selection menu.
|
|
|
|
|
; Returns 0 if the Pokemon you select is not a Magikarp.
|
|
|
|
|
|
|
|
|
|
; Let's start by selecting a Magikarp.
|
2017-12-24 17:47:30 +00:00
|
|
|
|
farcall SelectMonFromParty
|
2015-10-11 16:15:03 +00:00
|
|
|
|
jr c, .declined
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld a, [wCurPartySpecies]
|
2015-10-11 16:15:03 +00:00
|
|
|
|
cp MAGIKARP
|
|
|
|
|
jr nz, .not_magikarp
|
2016-04-10 18:42:14 +00:00
|
|
|
|
|
2024-04-27 17:16:34 +00:00
|
|
|
|
; Now let's compute its length based on its DVs and Trainer ID.
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld a, [wCurPartyMon]
|
|
|
|
|
ld hl, wPartyMon1Species
|
2015-11-04 16:19:58 +00:00
|
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call AddNTimes
|
|
|
|
|
push hl
|
|
|
|
|
ld bc, MON_DVS
|
|
|
|
|
add hl, bc
|
|
|
|
|
ld d, h
|
|
|
|
|
ld e, l
|
|
|
|
|
pop hl
|
2024-04-27 17:16:34 +00:00
|
|
|
|
ld bc, MON_OT_ID
|
2015-10-11 16:15:03 +00:00
|
|
|
|
add hl, bc
|
|
|
|
|
ld b, h
|
|
|
|
|
ld c, l
|
|
|
|
|
call CalcMagikarpLength
|
|
|
|
|
call PrintMagikarpLength
|
2018-01-02 19:00:14 +00:00
|
|
|
|
farcall StubbedTrainerRankings_MagikarpLength
|
2019-10-20 22:24:17 +00:00
|
|
|
|
ld hl, .MagikarpGuruMeasureText
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call PrintText
|
2016-04-10 18:42:14 +00:00
|
|
|
|
|
2015-10-11 16:15:03 +00:00
|
|
|
|
; Did we beat the record?
|
2017-12-10 00:41:03 +00:00
|
|
|
|
ld hl, wMagikarpLength
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ld de, wBestMagikarpLengthFeet
|
|
|
|
|
ld c, 2
|
2018-07-23 04:25:53 +00:00
|
|
|
|
call CompareBytes
|
2015-10-11 16:15:03 +00:00
|
|
|
|
jr nc, .not_long_enough
|
2016-04-10 18:42:14 +00:00
|
|
|
|
|
2015-10-11 16:15:03 +00:00
|
|
|
|
; NEW RECORD!!! Let's save that.
|
2017-12-10 00:41:03 +00:00
|
|
|
|
ld hl, wMagikarpLength
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ld de, wBestMagikarpLengthFeet
|
|
|
|
|
ld a, [hli]
|
|
|
|
|
ld [de], a
|
|
|
|
|
inc de
|
|
|
|
|
ld a, [hl]
|
|
|
|
|
ld [de], a
|
|
|
|
|
inc de
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld a, [wCurPartyMon]
|
2021-03-17 20:16:02 +00:00
|
|
|
|
ld hl, wPartyMonOTs
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call SkipNames
|
|
|
|
|
call CopyBytes
|
2018-01-12 06:40:20 +00:00
|
|
|
|
ld a, MAGIKARPLENGTH_BEAT_RECORD
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld [wScriptVar], a
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.not_long_enough
|
2018-01-12 06:40:20 +00:00
|
|
|
|
ld a, MAGIKARPLENGTH_TOO_SHORT
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld [wScriptVar], a
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.declined
|
2018-01-12 06:40:20 +00:00
|
|
|
|
ld a, MAGIKARPLENGTH_REFUSED
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld [wScriptVar], a
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.not_magikarp
|
2018-01-12 06:40:20 +00:00
|
|
|
|
xor a ; MAGIKARPLENGTH_NOT_MAGIKARP
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld [wScriptVar], a
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ret
|
|
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
|
.MagikarpGuruMeasureText:
|
|
|
|
|
text_far _MagikarpGuruMeasureText
|
2018-11-17 18:33:03 +00:00
|
|
|
|
text_end
|
2015-10-11 16:15:03 +00:00
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
|
Magikarp_LoadFeetInchesChars:
|
2017-12-28 12:32:33 +00:00
|
|
|
|
ld hl, vTiles2 tile "′" ; $6e
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ld de, .feetinchchars
|
|
|
|
|
lb bc, BANK(.feetinchchars), 2
|
|
|
|
|
call Request2bpp
|
|
|
|
|
ret
|
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
|
.feetinchchars
|
2017-12-10 04:37:08 +00:00
|
|
|
|
INCBIN "gfx/font/feet_inches.2bpp"
|
2015-10-11 16:15:03 +00:00
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
|
PrintMagikarpLength:
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call Magikarp_LoadFeetInchesChars
|
2018-01-23 22:39:09 +00:00
|
|
|
|
ld hl, wStringBuffer1
|
2017-12-10 00:41:03 +00:00
|
|
|
|
ld de, wMagikarpLength
|
2019-11-04 01:17:04 +00:00
|
|
|
|
lb bc, PRINTNUM_LEFTALIGN | 1, 2
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call PrintNum
|
2015-10-13 23:50:58 +00:00
|
|
|
|
ld [hl], "′"
|
2015-10-11 16:15:03 +00:00
|
|
|
|
inc hl
|
2017-12-10 00:41:03 +00:00
|
|
|
|
ld de, wMagikarpLength + 1
|
2019-11-04 01:17:04 +00:00
|
|
|
|
lb bc, PRINTNUM_LEFTALIGN | 1, 2
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call PrintNum
|
2015-10-13 23:50:58 +00:00
|
|
|
|
ld [hl], "″"
|
2015-10-11 16:15:03 +00:00
|
|
|
|
inc hl
|
|
|
|
|
ld [hl], "@"
|
|
|
|
|
ret
|
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
|
CalcMagikarpLength:
|
2017-12-28 15:42:57 +00:00
|
|
|
|
; Return Magikarp's length (in feet and inches) at wMagikarpLength (big endian).
|
2013-02-18 09:40:01 +00:00
|
|
|
|
;
|
|
|
|
|
; input:
|
2018-01-23 22:39:09 +00:00
|
|
|
|
; de: wEnemyMonDVs
|
|
|
|
|
; bc: wPlayerID
|
2013-02-18 09:40:01 +00:00
|
|
|
|
|
2014-12-04 04:06:40 +00:00
|
|
|
|
; This function is poorly commented.
|
2013-02-18 09:40:01 +00:00
|
|
|
|
|
|
|
|
|
; In short, it generates a value between 190 and 1786 using
|
|
|
|
|
; a Magikarp's DVs and its trainer ID. This value is further
|
2014-12-04 04:06:40 +00:00
|
|
|
|
; filtered in LoadEnemyMon to make longer Magikarp even rarer.
|
2013-02-18 09:40:01 +00:00
|
|
|
|
|
2014-12-04 04:06:40 +00:00
|
|
|
|
; The value is generated from a lookup table.
|
|
|
|
|
; The index is determined by the dv xored with the player's trainer id.
|
2013-02-18 09:40:01 +00:00
|
|
|
|
|
2014-12-04 04:06:40 +00:00
|
|
|
|
; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id)
|
2013-02-18 09:40:01 +00:00
|
|
|
|
|
2017-12-10 00:41:03 +00:00
|
|
|
|
; if bc < 10: [wMagikarpLength] = c + 190
|
|
|
|
|
; if bc ≥ $ff00: [wMagikarpLength] = c + 1370
|
2017-12-25 18:40:10 +00:00
|
|
|
|
; else: [wMagikarpLength] = z * 100 + (bc - x) / y
|
2013-02-18 09:40:01 +00:00
|
|
|
|
|
|
|
|
|
; X, Y, and Z depend on the value of b as follows:
|
|
|
|
|
|
|
|
|
|
; if b = 0: x = 310, y = 2, z = 3
|
|
|
|
|
; if b = 1: x = 710, y = 4, z = 4
|
|
|
|
|
; if b = 2-9: x = 2710, y = 20, z = 5
|
|
|
|
|
; if b = 10-29: x = 7710, y = 50, z = 6
|
|
|
|
|
; if b = 30-68: x = 17710, y = 100, z = 7
|
|
|
|
|
; if b = 69-126: x = 32710, y = 150, z = 8
|
|
|
|
|
; if b = 127-185: x = 47710, y = 150, z = 9
|
|
|
|
|
; if b = 186-224: x = 57710, y = 100, z = 10
|
|
|
|
|
; if b = 225-243: x = 62710, y = 50, z = 11
|
|
|
|
|
; if b = 244-251: x = 64710, y = 20, z = 12
|
|
|
|
|
; if b = 252-253: x = 65210, y = 5, z = 13
|
|
|
|
|
; if b = 254: x = 65410, y = 2, z = 14
|
|
|
|
|
|
2014-12-04 04:06:40 +00:00
|
|
|
|
; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id)
|
2013-02-18 09:40:01 +00:00
|
|
|
|
|
2014-12-04 04:06:40 +00:00
|
|
|
|
; id
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld h, b
|
|
|
|
|
ld l, c
|
|
|
|
|
ld a, [hli]
|
|
|
|
|
ld b, a
|
|
|
|
|
ld c, [hl]
|
|
|
|
|
rrc b
|
|
|
|
|
rrc c
|
2014-12-04 04:06:40 +00:00
|
|
|
|
|
|
|
|
|
; dv
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, [de]
|
|
|
|
|
inc de
|
|
|
|
|
rrca
|
|
|
|
|
rrca
|
|
|
|
|
xor b
|
|
|
|
|
ld b, a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, [de]
|
|
|
|
|
rrca
|
|
|
|
|
rrca
|
|
|
|
|
xor c
|
|
|
|
|
ld c, a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
|
|
|
|
|
; if bc < 10:
|
|
|
|
|
; de = bc + 190
|
|
|
|
|
; break
|
|
|
|
|
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, b
|
|
|
|
|
and a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
jr nz, .no
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, c
|
2014-12-04 04:06:40 +00:00
|
|
|
|
cp 10
|
|
|
|
|
jr nc, .no
|
|
|
|
|
|
|
|
|
|
ld hl, 190
|
2013-02-18 09:40:01 +00:00
|
|
|
|
add hl, bc
|
|
|
|
|
ld d, h
|
|
|
|
|
ld e, l
|
2014-12-04 04:06:40 +00:00
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
|
|
.no
|
|
|
|
|
|
2018-01-26 03:19:24 +00:00
|
|
|
|
ld hl, MagikarpLengths
|
2014-12-04 04:06:40 +00:00
|
|
|
|
ld a, 2
|
2018-07-28 23:27:34 +00:00
|
|
|
|
ld [wTempByteValue], a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
|
|
|
|
|
.read
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, [hli]
|
|
|
|
|
ld e, a
|
|
|
|
|
ld a, [hli]
|
|
|
|
|
ld d, a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
call .BCLessThanDE
|
|
|
|
|
jr nc, .next
|
|
|
|
|
|
|
|
|
|
; c = (bc - de) / [hl]
|
2013-02-18 09:40:01 +00:00
|
|
|
|
call .BCMinusDE
|
|
|
|
|
ld a, b
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh [hDividend + 0], a
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, c
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh [hDividend + 1], a
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, [hl]
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh [hDivisor], a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
ld b, 2
|
2013-02-18 09:40:01 +00:00
|
|
|
|
call Divide
|
2018-08-26 17:49:38 +00:00
|
|
|
|
ldh a, [hQuotient + 3]
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld c, a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
|
2015-10-13 23:50:58 +00:00
|
|
|
|
; de = c + 100 × (2 + i)
|
2013-02-18 09:40:01 +00:00
|
|
|
|
xor a
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh [hMultiplicand + 0], a
|
|
|
|
|
ldh [hMultiplicand + 1], a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
ld a, 100
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh [hMultiplicand + 2], a
|
2018-07-28 23:27:34 +00:00
|
|
|
|
ld a, [wTempByteValue]
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh [hMultiplier], a
|
2013-02-18 09:40:01 +00:00
|
|
|
|
call Multiply
|
2014-12-04 04:06:40 +00:00
|
|
|
|
ld b, 0
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh a, [hProduct + 3]
|
2013-02-18 09:40:01 +00:00
|
|
|
|
add c
|
|
|
|
|
ld e, a
|
2018-08-25 18:28:22 +00:00
|
|
|
|
ldh a, [hProduct + 2]
|
2013-02-18 09:40:01 +00:00
|
|
|
|
adc b
|
|
|
|
|
ld d, a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
|
|
.next
|
2013-02-18 09:40:01 +00:00
|
|
|
|
inc hl ; align to next triplet
|
2018-07-28 23:27:34 +00:00
|
|
|
|
ld a, [wTempByteValue]
|
2013-02-18 09:40:01 +00:00
|
|
|
|
inc a
|
2018-07-28 23:27:34 +00:00
|
|
|
|
ld [wTempByteValue], a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
cp 16
|
|
|
|
|
jr c, .read
|
|
|
|
|
|
2013-02-18 09:40:01 +00:00
|
|
|
|
call .BCMinusDE
|
2014-12-04 04:06:40 +00:00
|
|
|
|
ld hl, 1600
|
2013-02-18 09:40:01 +00:00
|
|
|
|
add hl, bc
|
|
|
|
|
ld d, h
|
|
|
|
|
ld e, l
|
2014-12-04 04:06:40 +00:00
|
|
|
|
|
|
|
|
|
.done
|
2017-12-28 15:42:57 +00:00
|
|
|
|
; convert from mm to feet and inches
|
|
|
|
|
; in = mm / 25.4
|
|
|
|
|
; ft = in / 12
|
|
|
|
|
|
2015-10-13 23:50:58 +00:00
|
|
|
|
; hl = de × 10
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld h, d
|
|
|
|
|
ld l, e
|
|
|
|
|
add hl, hl
|
2016-05-04 15:46:23 +00:00
|
|
|
|
add hl, hl
|
2013-02-18 09:40:01 +00:00
|
|
|
|
add hl, de
|
2014-12-04 04:06:40 +00:00
|
|
|
|
add hl, hl
|
|
|
|
|
|
|
|
|
|
; hl = hl / 254
|
|
|
|
|
ld de, -254
|
|
|
|
|
ld a, -1
|
|
|
|
|
.div_254
|
2013-02-18 09:40:01 +00:00
|
|
|
|
inc a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
add hl, de
|
|
|
|
|
jr c, .div_254
|
|
|
|
|
|
|
|
|
|
; d, e = hl / 12, hl % 12
|
|
|
|
|
ld d, 0
|
|
|
|
|
.mod_12
|
|
|
|
|
cp 12
|
|
|
|
|
jr c, .ok
|
|
|
|
|
sub 12
|
2013-02-18 09:40:01 +00:00
|
|
|
|
inc d
|
2014-12-04 04:06:40 +00:00
|
|
|
|
jr .mod_12
|
|
|
|
|
.ok
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld e, a
|
2014-12-04 04:06:40 +00:00
|
|
|
|
|
2017-12-10 00:41:03 +00:00
|
|
|
|
ld hl, wMagikarpLength
|
2017-12-28 15:42:57 +00:00
|
|
|
|
ld [hl], d ; ft
|
2013-02-18 09:40:01 +00:00
|
|
|
|
inc hl
|
2017-12-28 15:42:57 +00:00
|
|
|
|
ld [hl], e ; in
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ret
|
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
|
.BCLessThanDE:
|
2022-07-09 21:12:02 +00:00
|
|
|
|
; BUG: Magikarp lengths can be miscalculated (see docs/bugs_and_glitches.md)
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, b
|
|
|
|
|
cp d
|
|
|
|
|
ret c
|
2022-07-09 21:12:02 +00:00
|
|
|
|
ret nc
|
2013-02-18 09:40:01 +00:00
|
|
|
|
ld a, c
|
|
|
|
|
cp e
|
|
|
|
|
ret
|
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
|
.BCMinusDE:
|
2013-02-18 09:40:01 +00:00
|
|
|
|
; bc -= de
|
|
|
|
|
ld a, c
|
|
|
|
|
sub e
|
|
|
|
|
ld c, a
|
|
|
|
|
ld a, b
|
|
|
|
|
sbc d
|
|
|
|
|
ld b, a
|
|
|
|
|
ret
|
|
|
|
|
|
2018-01-26 03:19:24 +00:00
|
|
|
|
INCLUDE "data/events/magikarp_lengths.asm"
|
2015-10-11 16:15:03 +00:00
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
|
MagikarpHouseSign:
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ld a, [wBestMagikarpLengthFeet]
|
2017-12-10 00:41:03 +00:00
|
|
|
|
ld [wMagikarpLength], a
|
2015-10-11 16:15:03 +00:00
|
|
|
|
ld a, [wBestMagikarpLengthInches]
|
2017-12-10 00:41:03 +00:00
|
|
|
|
ld [wMagikarpLength + 1], a
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call PrintMagikarpLength
|
2019-10-20 22:24:17 +00:00
|
|
|
|
ld hl, .KarpGuruRecordText
|
2015-10-11 16:15:03 +00:00
|
|
|
|
call PrintText
|
|
|
|
|
ret
|
|
|
|
|
|
2019-10-20 22:24:17 +00:00
|
|
|
|
.KarpGuruRecordText:
|
|
|
|
|
text_far _KarpGuruRecordText
|
2018-11-17 18:33:03 +00:00
|
|
|
|
text_end
|