diff options
Diffstat (limited to 'battle')
-rw-r--r-- | battle/magikarp_length.asm | 215 | ||||
-rw-r--r-- | battle/misc.asm | 259 |
2 files changed, 259 insertions, 215 deletions
diff --git a/battle/magikarp_length.asm b/battle/magikarp_length.asm deleted file mode 100644 index 237450928..000000000 --- a/battle/magikarp_length.asm +++ /dev/null @@ -1,215 +0,0 @@ -CalcMagikarpLength: ; fbbfc -; Return Magikarp's length (in mm) at MagikarpLength (big endian). -; -; input: -; de: EnemyMonDVs -; bc: PlayerID - -; This function is poorly commented. - -; In short, it generates a value between 190 and 1786 using -; a Magikarp's DVs and its trainer ID. This value is further -; filtered in LoadEnemyMon to make longer Magikarp even rarer. - -; The value is generated from a lookup table. -; The index is determined by the dv xored with the player's trainer id. - -; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id) - -; if bc < 10: [MagikarpLength] = c + 190 -; if bc >= $ff00: [MagikarpLength] = c + 1370 -; else: [MagikarpLength] = z * 100 + (bc - x) / y - -; 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 - - - ; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id) - - ; id - ld h, b - ld l, c - ld a, [hli] - ld b, a - ld c, [hl] - rrc b - rrc c - - ; dv - ld a, [de] - inc de - rrca - rrca - xor b - ld b, a - - ld a, [de] - rrca - rrca - xor c - ld c, a - - ; if bc < 10: - ; de = bc + 190 - ; break - - ld a, b - and a - jr nz, .no - ld a, c - cp 10 - jr nc, .no - - ld hl, 190 - add hl, bc - ld d, h - ld e, l - jr .done - -.no - - ld hl, .Lengths - ld a, 2 - ld [wd265], a - -.read - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - call .BCLessThanDE - jr nc, .next - - ; c = (bc - de) / [hl] - call .BCMinusDE - ld a, b - ld [hDividend + 0], a - ld a, c - ld [hDividend + 1], a - ld a, [hl] - ld [hDivisor], a - ld b, 2 - call Divide - ld a, [hQuotient + 2] - ld c, a - - ; de = c + 100 * (2 + i) - xor a - ld [hMultiplicand + 0], a - ld [hMultiplicand + 1], a - ld a, 100 - ld [hMultiplicand + 2], a - ld a, [wd265] - ld [hMultiplier], a - call Multiply - ld b, 0 - ld a, [hProduct + 3] - add c - ld e, a - ld a, [hProduct + 2] - adc b - ld d, a - jr .done - -.next - inc hl ; align to next triplet - ld a, [wd265] - inc a - ld [wd265], a - cp 16 - jr c, .read - - call .BCMinusDE - ld hl, 1600 - add hl, bc - ld d, h - ld e, l - -.done - ; hl = de * 10 - ld h, d - ld l, e -rept 2 - add hl, hl -endr - add hl, de - add hl, hl - - ; hl = hl / 254 - ld de, -254 - ld a, -1 -.div_254 - inc a - 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 - inc d - jr .mod_12 -.ok - ld e, a - - ld hl, MagikarpLength - ld [hl], d - inc hl - ld [hl], e - ret -; fbc9a - -.BCLessThanDE: ; fbc9a -; Intention: Return bc < de. -; Reality: Return b < d. - ld a, b - cp d - ret c - ret nc ; whoops - ld a, c - cp e - ret -; fbca1 - -.BCMinusDE: ; fbca1 -; bc -= de - ld a, c - sub e - ld c, a - ld a, b - sbc d - ld b, a - ret -; fbca8 - -.Lengths: ; fbca8 -; ????, divisor - dwb 110, 1 - dwb 310, 2 - dwb 710, 4 - dwb 2710, 20 - dwb 7710, 50 - dwb 17710, 100 - dwb 32710, 150 - dwb 47710, 150 - dwb 57710, 100 - dwb 62710, 50 - dwb 64710, 20 - dwb 65210, 5 - dwb 65410, 2 - dwb 65510, 1 ; not used -; fbcd2 diff --git a/battle/misc.asm b/battle/misc.asm new file mode 100644 index 000000000..a8dccca84 --- /dev/null +++ b/battle/misc.asm @@ -0,0 +1,259 @@ +Functionfbd54: ; fbd54 + xor a + ld [hBGMapMode], a ; $ff00+$d4 + ld a, [hBattleTurn] ; $ff00+$e4 + and a + jr z, .asm_fbd61 + call Functionfbd96 + jr .asm_fbd64 +.asm_fbd61 + call Functionfbd9d +.asm_fbd64 + call ClearBox + jr Functionfbd91 + +Functionfbd69: ; fbd69 (3e:7d69) + callba BattleCommanda6 + jr Functionfbd77 + +Functionfbd71: ; fbd71 (3e:7d71) + callba BattleCommanda7 + +Functionfbd77: ; fbd77 (3e:7d77) + xor a + ld [hBGMapMode], a ; $ff00+$d4 + ld a, [hBattleTurn] ; $ff00+$e4 + and a + jr z, .asm_fbd85 + call Functionfbd96 + xor a + jr .asm_fbd8a +.asm_fbd85 + call Functionfbd9d + ld a, $31 +.asm_fbd8a + ld [$ffad], a + predef FillBox +Functionfbd91: ; fbd91 (3e:7d91) + ld a, $1 + ld [hBGMapMode], a ; $ff00+$d4 + ret + +Functionfbd96: ; fbd96 (3e:7d96) + hlcoord 12, 0 + lb bc, 7, 7 + ret + +Functionfbd9d: ; fbd9d (3e:7d9d) + hlcoord 2, 6 + lb bc, 6, 6 + ret + + +DoWeatherModifiers: ; fbda4 + + ld de, .WeatherTypeModifiers + ld a, [Weather] + ld b, a + ld a, [wd265] ; move type + ld c, a + +.CheckWeatherType + ld a, [de] + inc de + cp $ff + jr z, .asm_fbdc0 + + cp b + jr nz, .NextWeatherType + + ld a, [de] + cp c + jr z, .ApplyModifier + +.NextWeatherType +rept 2 + inc de +endr + jr .CheckWeatherType + + +.asm_fbdc0 + ld de, .WeatherMoveModifiers + + ld a, BATTLE_VARS_MOVE_EFFECT + call GetBattleVar + ld c, a + +.CheckWeatherMove + ld a, [de] + inc de + cp $ff + jr z, .done + + cp b + jr nz, .NextWeatherMove + + ld a, [de] + cp c + jr z, .ApplyModifier + +.NextWeatherMove +rept 2 + inc de +endr + jr .CheckWeatherMove + +.ApplyModifier + xor a + ld [hMultiplicand + 0], a + ld hl, CurDamage + ld a, [hli] + ld [hMultiplicand + 1], a + ld a, [hl] + ld [hMultiplicand + 2], a + + inc de + ld a, [de] + ld [hMultiplier], a + + call Multiply + + ld a, 10 + ld [hDivisor], a + ld b, $4 + call Divide + + ld a, [hQuotient + 0] + and a + ld bc, -1 + jr nz, .Update + + ld a, [hQuotient + 1] + ld b, a + ld a, [hQuotient + 2] + ld c, a + or b + jr nz, .Update + + ld bc, 1 + +.Update + ld a, b + ld [CurDamage], a + ld a, c + ld [CurDamage + 1], a + +.done + ret + +.WeatherTypeModifiers + db WEATHER_RAIN, WATER, 15 + db WEATHER_RAIN, FIRE, 05 + db WEATHER_SUN, FIRE, 15 + db WEATHER_SUN, WATER, 05 + db $ff + +.WeatherMoveModifiers + db WEATHER_RAIN, EFFECT_SOLARBEAM, 05 + db $ff +; fbe24 + + +DoBadgeTypeBoosts: ; fbe24 + ld a, [InLinkBattle] + and a + ret nz + + ld a, [InBattleTowerBattle] + and a + ret nz + + ld a, [hBattleTurn] + and a + ret nz + + push de + push bc + + ld hl, .BadgeTypes + + ld a, [KantoBadges] + ld b, a + ld a, [JohtoBadges] + ld c, a + +.CheckBadge + ld a, [hl] + cp $ff + jr z, .done + + srl b + rr c + jr nc, .NextBadge + + ld a, [wd265] ; move type + cp [hl] + jr z, .ApplyBoost + +.NextBadge + inc hl + jr .CheckBadge + +.ApplyBoost + ld a, [CurDamage] + ld h, a + ld d, a + ld a, [CurDamage + 1] + ld l, a + ld e, a + + srl d + rr e + srl d + rr e + srl d + rr e + + ld a, e + or d + jr nz, .asm_fbe6f + ld e, 1 + +.asm_fbe6f + add hl, de + jr nc, .Update + + ld hl, $ffff + +.Update + ld a, h + ld [CurDamage], a + ld a, l + ld [CurDamage + 1], a + +.done + pop bc + pop de + ret + +.BadgeTypes + db FLYING ; zephyrbadge + db BUG ; hivebadge + db NORMAL ; plainbadge + db GHOST ; fogbadge + db STEEL ; mineralbadge + db FIGHTING ; stormbadge + db ICE ; glacierbadge + db DRAGON ; risingbadge + + db ROCK ; boulderbadge + db WATER ; cascadebadge + db ELECTRIC ; thunderbadge + db GRASS ; rainbowbadge + db POISON ; soulbadge + db PSYCHIC ; marshbadge + db FIRE ; volcanobadge + db GROUND ; earthbadge + db $ff +; fbe91 |