- 56
- Posts
- 9
- Years
- Seen Nov 27, 2016
Basically the sla instruction causes a left shift leading to a multiplication by 2 while the srl instruction causes a right shift leading to a division by 2. By removing a srl b and a sla b for the non-focus energy case we leave it unaffected, while by replacing the two srl b affecting the focus energy used case with sla b, we make the crit rate four times higher instead of quartering it. jr c, .guaranteedCritical are there to make sure the value does not overflow.
I'm not sure I would have figured that out on my own. Thank's a heap!
When adding the label .gauranteedCritical some of my line numbers are different. Should I be more concerned with where they are in the code than with the line number they fall on? Is there a bit of code that should come before it? I see a lot of .variouslines that follow a "jr c" or "jr z".
Spoiler:
CriticalHitTest: ; 3e023 (f:6023)
xor a
ld [wCriticalHitOrOHKO], a
ld a, [H_WHOSETURN]
and a
ld a, [wEnemyMonSpecies]
jr nz, .asm_3e032
ld a, [wBattleMonSpecies]
.asm_3e032
ld [wd0b5], a
call GetMonHeader
ld a, [wMonHBaseSpeed]
ld b, a
ld a, [H_WHOSETURN]
and a
ld hl, wPlayerMovePower
ld de, wPlayerBattleStatus2
jr z, .calcCriticalHitProbability
ld hl, wEnemyMovePower
ld de, wEnemyBattleStatus2
.calcCriticalHitProbability
ld a, [hld] ; read base power from RAM
and a
ret z ; do nothing if zero
dec hl
ld c, [hl] ; read move id
ld a, [de]
bit GettingPumped, a ; test for focus energy
jr z, .nofocusEnergyUsed ; bug: using focus energy causes a shift to the right instead of left,
sla b
jr c, .guaranteedCritical
sla b
jr c, .guaranteedCritical
.Loop
ld a, [hli] ; read move from move table
cp c ; does it match the move about to be used?
jr z, .HighCritical ; if so, the move about to be used is a high critical hit ratio move
inc a ; move on to the next move, FF terminates loop
jr nz, .Loop ; check the next move in HighCriticalMoves
srl b ; /2 for regular move (effective (base speed / 2))
jr .SkipHighCritical ; continue as a normal move
.HighCritical
sla b ; *2 for high critical hit moves
jr nc, .noCarry
ld b, $ff ; cap at 255/256
.noCarry
sla b ; *4 for high critical move (effective (base speed/2)*8))
jr nc, .SkipHighCritical
ld b, $ff
.SkipHighCritical
call BattleRandom ; generates a random value, in "a"
rlc a
rlc a
rlc a
cp b ; check a against calculated crit rate
ret nc ; no critical hit if no borrow
jr nc, .guaranteedCritical
ld a, $1
ld [wCriticalHitOrOHKO], a ; set critical hit flag
ret
xor a
ld [wCriticalHitOrOHKO], a
ld a, [H_WHOSETURN]
and a
ld a, [wEnemyMonSpecies]
jr nz, .asm_3e032
ld a, [wBattleMonSpecies]
.asm_3e032
ld [wd0b5], a
call GetMonHeader
ld a, [wMonHBaseSpeed]
ld b, a
ld a, [H_WHOSETURN]
and a
ld hl, wPlayerMovePower
ld de, wPlayerBattleStatus2
jr z, .calcCriticalHitProbability
ld hl, wEnemyMovePower
ld de, wEnemyBattleStatus2
.calcCriticalHitProbability
ld a, [hld] ; read base power from RAM
and a
ret z ; do nothing if zero
dec hl
ld c, [hl] ; read move id
ld a, [de]
bit GettingPumped, a ; test for focus energy
jr z, .nofocusEnergyUsed ; bug: using focus energy causes a shift to the right instead of left,
sla b
jr c, .guaranteedCritical
sla b
jr c, .guaranteedCritical
.Loop
ld a, [hli] ; read move from move table
cp c ; does it match the move about to be used?
jr z, .HighCritical ; if so, the move about to be used is a high critical hit ratio move
inc a ; move on to the next move, FF terminates loop
jr nz, .Loop ; check the next move in HighCriticalMoves
srl b ; /2 for regular move (effective (base speed / 2))
jr .SkipHighCritical ; continue as a normal move
.HighCritical
sla b ; *2 for high critical hit moves
jr nc, .noCarry
ld b, $ff ; cap at 255/256
.noCarry
sla b ; *4 for high critical move (effective (base speed/2)*8))
jr nc, .SkipHighCritical
ld b, $ff
.SkipHighCritical
call BattleRandom ; generates a random value, in "a"
rlc a
rlc a
rlc a
cp b ; check a against calculated crit rate
ret nc ; no critical hit if no borrow
jr nc, .guaranteedCritical
ld a, $1
ld [wCriticalHitOrOHKO], a ; set critical hit flag
ret
That's what I have from line 4684 to line 4745 since editing, if it helps.
Last edited: