More splitting of main.asm; remove unneeded rept 2

This commit is contained in:
pikalaxalt
2016-05-04 11:46:23 -04:00
parent 82f1534925
commit 3713b71d9e
107 changed files with 1222 additions and 1610 deletions

View File

@@ -216,9 +216,8 @@ endr
pop de
pop hl
rept 2
inc hl
endr
inc hl
jr c, .loop
.used_item

View File

@@ -107,9 +107,8 @@ endr
ld hl, AIScoringPointers
dec c
ld b, 0
rept 2
add hl, bc
endr
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a

View File

@@ -133,18 +133,16 @@ AI_Setup: ; 385e0
call AI_50_50
jr c, .checkmove
rept 2
dec [hl]
endr
dec [hl]
jr .checkmove
.discourage
call Random
cp 30
jr c, .checkmove
rept 2
inc [hl]
endr
inc [hl]
jr .checkmove
; 38635
@@ -264,9 +262,8 @@ AI_Offensive: ; 386a2
and a
jr nz, .checkmove
rept 2
inc [hl]
endr
inc [hl]
jr .checkmove
; 386be
@@ -420,9 +417,8 @@ AI_Smart_Sleep: ; 387e3
.asm_387f0
call AI_50_50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 387f7
@@ -533,9 +529,8 @@ AI_Smart_LockOn: ; 3881d
call AI_50_50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_38882
@@ -560,9 +555,8 @@ endr
cp 180
jr nc, .asm_3888b
rept 2
dec [hl]
endr
dec [hl]
jr .asm_3888b
.asm_388a2
@@ -645,9 +639,8 @@ AI_Smart_EvasionUp: ; 388d4
jr nc, .asm_38911
.asm_388ef
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_388f2
@@ -676,9 +669,8 @@ endr
jr c, .asm_38911
.asm_3890f
rept 2
inc [hl]
endr
inc [hl]
; 30% chance to end up here if enemy's HP is full and player is not badly poisoned.
; 77% chance to end up here if enemy's HP is above 50% but not full.
@@ -722,9 +714,8 @@ endr
call Random
cp $50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; Player is seeded.
@@ -756,9 +747,8 @@ AI_Smart_AlwaysHit: ; 38947
call AI_80_20
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 3895b
@@ -828,9 +818,8 @@ AI_Smart_AccuracyDown: ; 38985
jr nc, .asm_389bf
.asm_3899d
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_389a0
@@ -859,9 +848,8 @@ endr
jr c, .asm_389bf
.asm_389bd
rept 2
inc [hl]
endr
inc [hl]
; We only end up here if the move has not been already encouraged.
.asm_389bf
@@ -900,9 +888,8 @@ endr
call Random
cp $50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; Player is seeded.
@@ -1010,9 +997,8 @@ AI_Smart_Moonlight: ; 38a3a
call Random
cp $19
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 38a4e
@@ -1093,9 +1079,8 @@ AI_Smart_Bind: ; 38a71
ret nc
call AI_50_50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 38a9c
@@ -1200,9 +1185,8 @@ AI_Smart_SpDefenseUp2: ; 38aed
.asm_38b09
call AI_80_20
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_38b10
@@ -1255,9 +1239,8 @@ AI_Smart_Paralyze: ; 38b26
ret nc
call AI_80_20
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_38b3a
@@ -1289,9 +1272,8 @@ AI_Smart_SpeedDownHit: ; 38b40
call Random
cp 30
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 38b5c
@@ -1528,9 +1510,8 @@ AI_Smart_Encore: ; 38c3b
call Random
cp $46
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_38c81
@@ -1685,9 +1666,8 @@ AI_Smart_Spite: ; 38cd5
call Random
cp $64
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 38d16
@@ -1755,9 +1735,8 @@ endr
ret z
call AI_50_50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
.no_status
@@ -2007,15 +1986,13 @@ AI_Smart_Curse: ; 38e5c
ret nc
call AI_80_20
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_38e90
rept 2
inc [hl]
endr
inc [hl]
.asm_38e92
inc [hl]
.asm_38e93
@@ -2065,9 +2042,8 @@ endr
call AI_50_50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 38ed2
@@ -2119,9 +2095,8 @@ AI_Smart_Protect: ; 38ed2
call Random
cp 20
ret c
rept 2
inc [hl]
endr
inc [hl]
ret
; 38f1d
@@ -2151,9 +2126,8 @@ AI_Smart_Foresight: ; 38f1d
call Random
cp 100
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 38f4a
@@ -2272,9 +2246,8 @@ endr
call AI_50_50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_38fd8
@@ -2296,9 +2269,8 @@ AI_Smart_FuryCutter: ; 38fdb
cp 2
jr c, .end
rept 2
dec [hl]
endr
dec [hl]
cp 3
jr c, .end
@@ -2344,9 +2316,8 @@ AI_Smart_Rollout: ; 38fef
call Random
cp 200
ret nc
rept 2
dec [hl]
endr
dec [hl]
ret
.asm_39020
@@ -2406,9 +2377,8 @@ AI_Smart_Earthquake: ; 39044
call AICompareSpeed
ret nc
rept 2
dec [hl]
endr
dec [hl]
ret
.could_dig
@@ -2455,9 +2425,8 @@ AI_Smart_Pursuit: ; 39072
.asm_3907d
call AI_50_50
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 39084
@@ -2482,9 +2451,8 @@ AI_Smart_RapidSpin: ; 39084
call AI_80_20
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 3909e
@@ -2636,9 +2604,8 @@ AIGoodWeatherType: ; 39122
ret nz
.good
rept 2
dec [hl]
endr
dec [hl]
ret
; 39134
@@ -2733,9 +2700,8 @@ AI_Smart_PsychUp: ; 39152
ret
.asm_39188
rept 2
inc [hl]
endr
inc [hl]
ret
; 3918b
@@ -2820,9 +2786,8 @@ AI_Smart_Gust: ; 391d5
call AICompareSpeed
ret nc
rept 2
dec [hl]
endr
dec [hl]
ret
; Try to predict if the player will use Fly this turn.
@@ -2849,9 +2814,8 @@ AI_Smart_FutureSight: ; 391f3
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret z
rept 2
dec [hl]
endr
dec [hl]
ret
; 39200
@@ -2886,18 +2850,16 @@ AI_Smart_Solarbeam: ; 3920b
cp 25 ; 1/10
ret c
rept 2
inc [hl]
endr
inc [hl]
ret
.asm_3921e
call AI_80_20
ret c
rept 2
dec [hl]
endr
dec [hl]
ret
; 39225
@@ -2991,9 +2953,8 @@ AICheckPlayerHalfHP: ; 3926e
ld c, [hl]
sla c
rl b
rept 2
inc hl
endr
inc hl
ld a, [hld]
cp c
ld a, [hl]
@@ -3013,9 +2974,8 @@ AICheckEnemyHalfHP: ; 39281
ld c, [hl]
sla c
rl b
rept 2
inc hl
endr
inc hl
ld a, [hld]
cp c
ld a, [hl]
@@ -3039,9 +2999,8 @@ AICheckEnemyQuarterHP: ; 39298
rl b
sla c
rl b
rept 2
inc hl
endr
inc hl
ld a, [hld]
cp c
ld a, [hl]
@@ -3063,9 +3022,8 @@ AICheckPlayerQuarterHP: ; 392b3
rl b
sla c
rl b
rept 2
inc hl
endr
inc hl
ld a, [hld]
cp c
ld a, [hl]

View File

@@ -626,9 +626,8 @@ FindEnemyMonsWithEnoughHP: ; 34b77
ld b, [hl]
inc hl
ld c, [hl]
rept 2
inc hl
endr
inc hl
; hl = MaxHP + 1
; b = (4 * b) % $100 + (c & 3)
; c = c / 4

View File

@@ -45,9 +45,8 @@ HiddenPowerDamage: ; fbced
; Multiply by 5
ld b, a
rept 2
add a
endr
add a
add b
; Add Special & 3
@@ -75,9 +74,8 @@ endr
ld a, [hl]
and 3 << 4
swap a
rept 2
add a
endr
add a
or b
; Skip Normal

162
battle/link_result.asm Executable file
View File

@@ -0,0 +1,162 @@
DetermineLinkBattleResult: ; 2b930
callba UpdateEnemyMonInParty
ld hl, PartyMon1HP
call .CountMonsRemaining
push bc
ld hl, OTPartyMon1HP
call .CountMonsRemaining
ld a, c
pop bc
cp c
jr z, .even_number_of_mons_remaining
jr c, .defeat
jr .victory
.even_number_of_mons_remaining
call .BothSides_CheckNumberMonsAtFullHealth
jr z, .drawn
ld a, e
cp $1
jr z, .victory
cp $2
jr z, .defeat
ld hl, PartyMon1HP
call .CalcPercentHPRemaining
push de
ld hl, OTPartyMon1HP
call .CalcPercentHPRemaining
pop hl
ld a, d
cp h
jr c, .victory
jr z, .compare_lo
jr .defeat
.compare_lo
ld a, e
cp l
jr z, .drawn
jr nc, .defeat
.victory
ld a, [wBattleResult]
and $f0
ld [wBattleResult], a
ret
.defeat
ld a, [wBattleResult]
and $f0
add $1
ld [wBattleResult], a
ret
.drawn
ld a, [wBattleResult]
and $f0
add $2
ld [wBattleResult], a
ret
.CountMonsRemaining: ; 2b995
ld c, 0
ld b, 3
ld de, PARTYMON_STRUCT_LENGTH - 1
.loop
ld a, [hli]
or [hl]
jr nz, .not_fainted
inc c
.not_fainted
add hl, de
dec b
jr nz, .loop
ret
.CalcPercentHPRemaining: ; 2b9a6
ld de, 0
ld c, $3
.loop2
ld a, [hli]
or [hl]
jr z, .next
dec hl
xor a
ld [hDividend + 0], a
ld a, [hli]
ld [hDividend + 1], a
ld a, [hli]
ld [hDividend + 2], a
xor a
ld [hDividend + 3], a
ld a, [hli]
ld b, a
ld a, [hld]
srl b
rr a
srl b
rr a
ld [hDivisor], a
ld b, $4
call Divide
ld a, [hQuotient + 2]
add e
ld e, a
ld a, [hQuotient + 1]
adc d
ld d, a
dec hl
.next
push de
ld de, $2f
add hl, de
pop de
dec c
jr nz, .loop2
ret
.BothSides_CheckNumberMonsAtFullHealth: ; 2b9e1
ld hl, PartyMon1HP
call .CheckFaintedOrFullHealth
jr nz, .finish ; we have a pokemon that's neither fainted nor at full health
ld hl, OTPartyMon1HP
call .CheckFaintedOrFullHealth
ld e, $1
ret
.finish
ld hl, OTPartyMon1HP
call .CheckFaintedOrFullHealth
ld e, $0
ret nz ; we both have pokemon that are neither fainted nor at full health
ld e, $2
ld a, $1
and a
ret
.CheckFaintedOrFullHealth: ; 2ba01
ld d, 3
.loop3
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
or b
jr z, .fainted_or_full_health
ld a, [hli]
cp b
ret nz
ld a, [hld]
cp c
ret nz
.fainted_or_full_health
push de
ld de, PARTYMON_STRUCT_LENGTH - 2
add hl, de
pop de
dec d
jr nz, .loop3
ret

View File

@@ -141,9 +141,8 @@ CalcMagikarpLength: ; fbbfc
; hl = de * 10
ld h, d
ld l, e
rept 2
add hl, hl
endr
add hl, hl
add hl, de
add hl, hl

View File

@@ -72,9 +72,8 @@ DoWeatherModifiers: ; fbda4
jr z, .ApplyModifier
.NextWeatherType:
rept 2
inc de
endr
inc de
jr .CheckWeatherType
@@ -99,9 +98,8 @@ endr
jr z, .ApplyModifier
.NextWeatherMove:
rept 2
inc de
endr
inc de
jr .CheckWeatherMove
.ApplyModifier:

View File

@@ -39,12 +39,10 @@ BattleIntroSlidingPics: ; 4e980
ld a, d
ld [hSCX], a
call .subfunction5
rept 2
inc e
endr
rept 2
inc e
dec d
dec d
endr
pop af
push af
cp $1
@@ -66,9 +64,8 @@ endr
ld c, $12 ; 18
ld de, $4
.loop3
rept 2
dec [hl]
endr
dec [hl]
add hl, de
dec c
jr nz, .loop3