This commit is contained in:
dannye 2019-04-13 16:30:36 -05:00
commit e2c81e10f1
575 changed files with 12380 additions and 11198 deletions

File diff suppressed because it is too large Load diff

View file

@ -62,7 +62,7 @@ BattleTransition:
ld a, [hli]
ld h, [hl]
ld l, a
jp [hl]
jp hl
; the three GetBattleTransitionID functions set the first
; three bits of c, which determines what transition animation

File diff suppressed because it is too large Load diff

View file

@ -1,15 +1,15 @@
DecrementPP:
; after using a move, decrement pp in battle and (if not transformed?) in party
ld a, [de]
cp a, STRUGGLE
cp STRUGGLE
ret z ; if the pokemon is using "struggle", there's nothing to do
; we don't decrement PP for "struggle"
ld hl, wPlayerBattleStatus1
ld a, [hli] ; load the wPlayerBattleStatus1 pokemon status flags and increment hl to load the
; wPlayerBattleStatus2 status flags later
and a, (1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << AttackingMultipleTimes)
and (1 << STORING_ENERGY) | (1 << THRASHING_ABOUT) | (1 << ATTACKING_MULTIPLE_TIMES)
ret nz ; if any of these statuses are true, don't decrement PP
bit UsingRage, [hl]
bit USING_RAGE, [hl]
ret nz ; don't decrement PP either if Pokemon is using Rage
ld hl, wBattleMonPP ; PP of first move (in battle)
@ -18,7 +18,7 @@ DecrementPP:
; decrement PP in the party struct
ld a, [wPlayerBattleStatus3]
bit Transformed, a
bit TRANSFORMED, a
ret nz ; Return if transformed. Pokemon Red stores the "current pokemon's" PP
; separately from the "Pokemon in your party's" PP. This is
; duplication -- in all cases *other* than Pokemon with Transform.

View file

@ -1,7 +1,7 @@
DisplayEffectiveness:
ld a, [wDamageMultipliers]
and a, $7F
cp a, $0A
and $7F
cp $0A
ret z
ld hl, SuperEffectiveText
jr nc, .done

View file

@ -186,7 +186,7 @@ SetupPlayerAndEnemyPokeballs:
ld hl, wOAMBuffer + $18
jp WritePokeballOAMData
; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (faited) and pokeball slot (no mon)
; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (fainted) and pokeball slot (no mon)
PokeballTileGraphics::
INCBIN "gfx/pokeball.2bpp"
PokeballTileGraphicsEnd:

View file

@ -11,7 +11,7 @@ ConversionEffect_:
pop de
ld a, [wPlayerBattleStatus1]
.conversionEffect
bit Invulnerable, a ; is mon immune to typical attacks (dig/fly)
bit INVULNERABLE, a ; is mon immune to typical attacks (dig/fly)
jr nz, PrintButItFailedText
; copy target's types to user
ld a, [hli]

View file

@ -5,9 +5,9 @@ FocusEnergyEffect_:
jr z, .notEnemy
ld hl, wEnemyBattleStatus2
.notEnemy
bit GettingPumped, [hl] ; is mon already using focus energy?
bit GETTING_PUMPED, [hl] ; is mon already using focus energy?
jr nz, .alreadyUsing
set GettingPumped, [hl] ; mon is now using focus energy
set GETTING_PUMPED, [hl] ; mon is now using focus energy
callab PlayCurrentMoveAnimation
ld hl, GettingPumpedText
jp PrintText

View file

@ -47,14 +47,14 @@ HazeEffect_:
jp PrintText
CureVolatileStatuses:
res Confused, [hl]
res CONFUSED, [hl]
inc hl ; BATTSTATUS2
ld a, [hl]
; clear UsingXAccuracy, ProtectedByMist, GettingPumped, and Seeded statuses
and $ff ^((1 << UsingXAccuracy) | (1 << ProtectedByMist) | (1 << GettingPumped) | (1 << Seeded))
; clear USING_X_ACCURACY, PROTECTED_BY_MIST, GETTING_PUMPED, and SEEDED statuses
and $ff ^((1 << USING_X_ACCURACY) | (1 << PROTECTED_BY_MIST) | (1 << GETTING_PUMPED) | (1 << SEEDED))
ld [hli], a ; BATTSTATUS3
ld a, [hl]
and %11110000 | (1 << Transformed) ; clear Bad Poison, Reflect and Light Screen statuses
and %11110000 | (1 << TRANSFORMED) ; clear Bad Poison, Reflect and Light Screen statuses
ld [hl], a
ret

View file

@ -76,7 +76,7 @@ HealEffect_:
ld a, [de]
sbc [hl]
jr c, .playAnim
; copy max HP to current HP if an overflow ocurred
; copy max HP to current HP if an overflow occurred
ld a, [hli]
ld [de], a
ld [wHPBarNewHP+1], a

View file

@ -19,9 +19,9 @@ LeechSeedEffect_:
ld a, [de]
cp GRASS
jr z, .moveMissed
bit Seeded, [hl]
bit SEEDED, [hl]
jr nz, .moveMissed
set Seeded, [hl]
set SEEDED, [hl]
callab PlayCurrentMoveAnimation
ld hl, WasSeededText
jp PrintText

View file

@ -5,9 +5,9 @@ MistEffect_:
jr z, .mistEffect
ld hl, wEnemyBattleStatus2
.mistEffect
bit ProtectedByMist, [hl] ; is mon protected by mist?
bit PROTECTED_BY_MIST, [hl] ; is mon protected by mist?
jr nz, .mistAlreadyInUse
set ProtectedByMist, [hl] ; mon is now protected by mist
set PROTECTED_BY_MIST, [hl] ; mon is now protected by mist
callab PlayCurrentMoveAnimation
ld hl, ShroudedInMistText
jp PrintText

View file

@ -25,7 +25,7 @@ RecoilEffect_:
jr nz, .updateHP
inc c ; minimum recoil damage is 1
.updateHP
; substract HP from user due to the recoil damage
; subtract HP from user due to the recoil damage
ld a, [hli]
ld [wHPBarMaxHP+1], a
ld a, [hl]

View file

@ -10,15 +10,15 @@ ReflectLightScreenEffect_:
ld a, [de]
cp LIGHT_SCREEN_EFFECT
jr nz, .reflect
bit HasLightScreenUp, [hl] ; is mon already protected by light screen?
bit HAS_LIGHT_SCREEN_UP, [hl] ; is mon already protected by light screen?
jr nz, .moveFailed
set HasLightScreenUp, [hl] ; mon is now protected by light screen
set HAS_LIGHT_SCREEN_UP, [hl] ; mon is now protected by light screen
ld hl, LightScreenProtectedText
jr .playAnim
.reflect
bit HasReflectUp, [hl] ; is mon already protected by reflect?
bit HAS_REFLECT_UP, [hl] ; is mon already protected by reflect?
jr nz, .moveFailed
set HasReflectUp, [hl] ; mon is now protected by reflect
set HAS_REFLECT_UP, [hl] ; mon is now protected by reflect
ld hl, ReflectGainedArmorText
.playAnim
push hl

View file

@ -12,7 +12,7 @@ SubstituteEffect_:
ld bc, wEnemyBattleStatus2
.notEnemy
ld a, [bc]
bit HasSubstituteUp, a ; user already has substitute?
bit HAS_SUBSTITUTE_UP, a ; user already has substitute?
jr nz, .alreadyHasSubstitute
; quarter health to remove from user
; assumes max HP is 1023 or lower
@ -37,13 +37,13 @@ SubstituteEffect_:
sbc 0
pop bc
jr c, .notEnoughHP ; underflow means user would be left with negative health
; bug: since it only brances on carry, it will possibly leave user with 0 HP
; bug: since it only branches on carry, it will possibly leave user with 0 HP
.userHasZeroOrMoreHP
ldi [hl], a ; save resulting HP after substraction into current HP
ldi [hl], a ; save resulting HP after subtraction into current HP
ld [hl], d
ld h, b
ld l, c
set HasSubstituteUp, [hl]
set HAS_SUBSTITUTE_UP, [hl]
ld a, [wOptions]
bit 7, a ; battle animation is enabled?
ld hl, PlayCurrentMoveAnimation

View file

@ -12,7 +12,7 @@ TransformEffect_:
ld [wPlayerMoveListIndex], a
ld a, [wPlayerBattleStatus1]
.hitTest
bit Invulnerable, a ; is mon invulnerable to typical attacks? (fly/dig)
bit INVULNERABLE, a ; is mon invulnerable to typical attacks? (fly/dig)
jp nz, .failed
push hl
push de
@ -24,7 +24,7 @@ TransformEffect_:
ld hl, wEnemyBattleStatus2
.transformEffect
; animation(s) played are different if target has Substitute up
bit HasSubstituteUp, [hl]
bit HAS_SUBSTITUTE_UP, [hl]
push af
ld hl, HideSubstituteShowMonAnim
ld b, BANK(HideSubstituteShowMonAnim)
@ -44,7 +44,7 @@ TransformEffect_:
call nz, Bankswitch
pop bc
ld a, [bc]
set Transformed, a ; mon is now Transformed
set TRANSFORMED, a ; mon is now transformed
ld [bc], a
pop de
pop hl

View file

@ -1,43 +1,43 @@
ReadTrainer:
; don't change any moves in a link battle
ld a,[wLinkState]
ld a, [wLinkState]
and a
ret nz
; set [wEnemyPartyCount] to 0, [wEnemyPartyMons] to FF
; XXX first is total enemy pokemon?
; XXX second is species of first pokemon?
ld hl,wEnemyPartyCount
ld hl, wEnemyPartyCount
xor a
ld [hli],a
ld [hli], a
dec a
ld [hl],a
ld [hl], a
; get the pointer to trainer data for this class
ld a,[wCurOpponent]
ld a, [wCurOpponent]
sub $C9 ; convert value from pokemon to trainer
add a,a
ld hl,TrainerDataPointers
ld c,a
ld b,0
add hl,bc ; hl points to trainer class
ld a,[hli]
ld h,[hl]
ld l,a
ld a,[wTrainerNo]
ld b,a
add a
ld hl, TrainerDataPointers
ld c, a
ld b, 0
add hl, bc ; hl points to trainer class
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wTrainerNo]
ld b, a
; At this point b contains the trainer number,
; and hl points to the trainer class.
; Our next task is to iterate through the trainers,
; decrementing b each time, until we get to the right one.
.outer
dec b
jr z,.IterateTrainer
jr z, .IterateTrainer
.inner
ld a,[hli]
ld a, [hli]
and a
jr nz,.inner
jr nz, .inner
jr .outer
; if the first byte of trainer data is FF,
@ -46,17 +46,17 @@ ReadTrainer:
; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
; else the first byte is the level of every pokemon on the team
.IterateTrainer
ld a,[hli]
ld a, [hli]
cp $FF ; is the trainer special?
jr z,.SpecialTrainer ; if so, check for special moves
ld [wCurEnemyLVL],a
jr z, .SpecialTrainer ; if so, check for special moves
ld [wCurEnemyLVL], a
.LoopTrainerData
ld a,[hli]
ld a, [hli]
and a ; have we reached the end of the trainer data?
jr z,.FinishUp
ld [wcf91],a ; write species somewhere (XXX why?)
ld a,ENEMY_PARTY_DATA
ld [wMonDataLocation],a
jr z, .FinishUp
ld [wcf91], a ; write species somewhere (XXX why?)
ld a, ENEMY_PARTY_DATA
ld [wMonDataLocation], a
push hl
call AddPartyMon
pop hl
@ -66,101 +66,101 @@ ReadTrainer:
; - each pokemon has a specific level
; (as opposed to the whole team being of the same level)
; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
ld a,[hli]
ld a, [hli]
and a ; have we reached the end of the trainer data?
jr z,.AddLoneMove
ld [wCurEnemyLVL],a
ld a,[hli]
ld [wcf91],a
ld a,ENEMY_PARTY_DATA
ld [wMonDataLocation],a
jr z, .AddLoneMove
ld [wCurEnemyLVL], a
ld a, [hli]
ld [wcf91], a
ld a, ENEMY_PARTY_DATA
ld [wMonDataLocation], a
push hl
call AddPartyMon
pop hl
jr .SpecialTrainer
.AddLoneMove
; does the trainer have a single monster with a different move
ld a,[wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc
ld a, [wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc
and a
jr z,.AddTeamMove
jr z, .AddTeamMove
dec a
add a,a
ld c,a
ld b,0
ld hl,LoneMoves
add hl,bc
ld a,[hli]
ld d,[hl]
ld hl,wEnemyMon1Moves + 2
ld bc,wEnemyMon2 - wEnemyMon1
add a
ld c, a
ld b, 0
ld hl, LoneMoves
add hl, bc
ld a, [hli]
ld d, [hl]
ld hl, wEnemyMon1Moves + 2
ld bc, wEnemyMon2 - wEnemyMon1
call AddNTimes
ld [hl],d
ld [hl], d
jr .FinishUp
.AddTeamMove
; check if our trainer's team has special moves
; get trainer class number
ld a,[wCurOpponent]
ld a, [wCurOpponent]
sub 200
ld b,a
ld hl,TeamMoves
ld b, a
ld hl, TeamMoves
; iterate through entries in TeamMoves, checking each for our trainer class
.IterateTeamMoves
ld a,[hli]
ld a, [hli]
cp b
jr z,.GiveTeamMoves ; is there a match?
jr z, .GiveTeamMoves ; is there a match?
inc hl ; if not, go to the next entry
inc a
jr nz,.IterateTeamMoves
jr nz, .IterateTeamMoves
; no matches found. is this trainer champion rival?
ld a,b
ld a, b
cp SONY3
jr z,.ChampionRival
jr z, .ChampionRival
jr .FinishUp ; nope
.GiveTeamMoves
ld a,[hl]
ld [wEnemyMon5Moves + 2],a
ld a, [hl]
ld [wEnemyMon5Moves + 2], a
jr .FinishUp
.ChampionRival ; give moves to his team
; pidgeot
ld a,SKY_ATTACK
ld [wEnemyMon1Moves + 2],a
ld a, SKY_ATTACK
ld [wEnemyMon1Moves + 2], a
; starter
ld a,[wRivalStarter]
ld a, [wRivalStarter]
cp STARTER3
ld b,MEGA_DRAIN
jr z,.GiveStarterMove
ld b, MEGA_DRAIN
jr z, .GiveStarterMove
cp STARTER1
ld b,FIRE_BLAST
jr z,.GiveStarterMove
ld b,BLIZZARD ; must be squirtle
ld b, FIRE_BLAST
jr z, .GiveStarterMove
ld b, BLIZZARD ; must be squirtle
.GiveStarterMove
ld a,b
ld [wEnemyMon6Moves + 2],a
ld a, b
ld [wEnemyMon6Moves + 2], a
.FinishUp
; clear wAmountMoneyWon addresses
xor a
ld de,wAmountMoneyWon
ld [de],a
ld de, wAmountMoneyWon
ld [de], a
inc de
ld [de],a
ld [de], a
inc de
ld [de],a
ld a,[wCurEnemyLVL]
ld b,a
ld [de], a
ld a, [wCurEnemyLVL]
ld b, a
.LastLoop
; update wAmountMoneyWon addresses (money to win) based on enemy's level
ld hl,wTrainerBaseMoney + 1
ld c,2 ; wAmountMoneyWon is a 3-byte number
ld hl, wTrainerBaseMoney + 1
ld c, 2 ; wAmountMoneyWon is a 3-byte number
push bc
predef AddBCDPredef
pop bc
inc de
inc de
dec b
jr nz,.LastLoop ; repeat wCurEnemyLVL times
jr nz, .LastLoop ; repeat wCurEnemyLVL times
ret

View file

@ -1,21 +1,21 @@
SaveTrainerName:
ld hl,TrainerNamePointers
ld a,[wTrainerClass]
ld hl, TrainerNamePointers
ld a, [wTrainerClass]
dec a
ld c,a
ld b,0
add hl,bc
add hl,bc
ld a,[hli]
ld h,[hl]
ld l,a
ld de,wcd6d
ld c, a
ld b, 0
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
ld de, wcd6d
.CopyCharacter
ld a,[hli]
ld [de],a
ld a, [hli]
ld [de], a
inc de
cp "@"
jr nz,.CopyCharacter
jr nz, .CopyCharacter
ret
TrainerNamePointers:

View file

@ -51,7 +51,7 @@ AIEnemyTrainerChooseMoves:
ld l, a
ld de, .nextMoveChoiceModification ; set return address
push de
jp [hl] ; execute modification function
jp hl ; execute modification function
.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero
ld hl, wBuffer ; temp move selection array
ld de, wEnemyMonMoves ; enemy moves
@ -114,7 +114,7 @@ AIMoveChoiceModification1:
ld a, [wBattleMonStatus]
and a
ret z ; return if no status ailment on player's mon
ld hl, wBuffer - 1 ; temp move selection array (-1 byte offest)
ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset)
ld de, wEnemyMonMoves ; enemy moves
ld b, NUM_MOVES + 1
.nextMove
@ -154,7 +154,7 @@ StatusAilmentMoveEffects:
; slightly encourage moves with specific effects.
; in particular, stat-modifying moves and other move effects
; that fall in-bewteen
; that fall in-between
AIMoveChoiceModification2:
ld a, [wAILayer2Encouragement]
cp $1
@ -212,7 +212,7 @@ AIMoveChoiceModification3:
cp $10
jr z, .nextMove
jr c, .notEffectiveMove
dec [hl] ; sligthly encourage this move
dec [hl] ; slightly encourage this move
jr .nextMove
.notEffectiveMove ; discourages non-effective moves if better moves are available
push hl
@ -253,7 +253,7 @@ AIMoveChoiceModification3:
pop hl
and a
jr z, .nextMove
inc [hl] ; sligthly discourage this move
inc [hl] ; slightly discourage this move
jr .nextMove
AIMoveChoiceModification4:
ret
@ -263,10 +263,10 @@ ReadMove:
push de
push bc
dec a
ld hl,Moves
ld bc,MoveEnd - Moves
ld hl, Moves
ld bc, MoveEnd - Moves
call AddNTimes
ld de,wEnemyMoveNum
ld de, wEnemyMoveNum
call CopyData
pop bc
pop de
@ -338,35 +338,35 @@ INCLUDE "data/trainer_parties.asm"
TrainerAI:
and a
ld a,[wIsInBattle]
ld a, [wIsInBattle]
dec a
ret z ; if not a trainer, we're done here
ld a,[wLinkState]
ld a, [wLinkState]
cp LINK_STATE_BATTLING
ret z
ld a,[wTrainerClass] ; what trainer class is this?
ld a, [wTrainerClass] ; what trainer class is this?
dec a
ld c,a
ld b,0
ld hl,TrainerAIPointers
add hl,bc
add hl,bc
add hl,bc
ld a,[wAICount]
ld c, a
ld b, 0
ld hl, TrainerAIPointers
add hl, bc
add hl, bc
add hl, bc
ld a, [wAICount]
and a
ret z ; if no AI uses left, we're done here
inc hl
inc a
jr nz,.getpointer
jr nz, .getpointer
dec hl
ld a,[hli]
ld [wAICount],a
ld a, [hli]
ld [wAICount], a
.getpointer
ld a,[hli]
ld h,[hl]
ld l,a
ld a, [hli]
ld h, [hl]
ld l, a
call Random
jp [hl]
jp hl
TrainerAIPointers:
; one entry per trainer class
@ -442,17 +442,17 @@ CooltrainerMAI:
CooltrainerFAI:
cp $40
ld a,$A
ld a, $A
call AICheckIfHPBelowFraction
jp c,AIUseHyperPotion
ld a,5
jp c, AIUseHyperPotion
ld a, 5
call AICheckIfHPBelowFraction
ret nc
jp AISwitchIfEnoughMons
BrockAI:
; if his active monster has a status condition, use a full heal
ld a,[wEnemyMonStatus]
ld a, [wEnemyMonStatus]
and a
ret z
jp AIUseFullHeal
@ -470,7 +470,7 @@ LtSurgeAI:
ErikaAI:
cp $80
ret nc
ld a,$A
ld a, $A
call AICheckIfHPBelowFraction
ret nc
jp AIUseSuperPotion
@ -488,7 +488,7 @@ BlaineAI:
SabrinaAI:
cp $40
ret nc
ld a,$A
ld a, $A
call AICheckIfHPBelowFraction
ret nc
jp AIUseHyperPotion
@ -496,7 +496,7 @@ SabrinaAI:
Sony2AI:
cp $20
ret nc
ld a,5
ld a, 5
call AICheckIfHPBelowFraction
ret nc
jp AIUsePotion
@ -504,7 +504,7 @@ Sony2AI:
Sony3AI:
cp $20
ret nc
ld a,5
ld a, 5
call AICheckIfHPBelowFraction
ret nc
jp AIUseFullRestore
@ -512,7 +512,7 @@ Sony3AI:
LoreleiAI:
cp $80
ret nc
ld a,5
ld a, 5
call AICheckIfHPBelowFraction
ret nc
jp AIUseSuperPotion
@ -524,10 +524,10 @@ BrunoAI:
AgathaAI:
cp $14
jp c,AISwitchIfEnoughMons
jp c, AISwitchIfEnoughMons
cp $80
ret nc
ld a,4
ld a, 4
call AICheckIfHPBelowFraction
ret nc
jp AIUseSuperPotion
@ -535,7 +535,7 @@ AgathaAI:
LanceAI:
cp $80
ret nc
ld a,5
ld a, 5
call AICheckIfHPBelowFraction
ret nc
jp AIUseHyperPotion
@ -547,133 +547,133 @@ GenericAI:
; end of individual trainer AI routines
DecrementAICount:
ld hl,wAICount
ld hl, wAICount
dec [hl]
scf
ret
AIPlayRestoringSFX:
ld a,SFX_HEAL_AILMENT
ld a, SFX_HEAL_AILMENT
jp PlaySoundWaitForCurrent
AIUseFullRestore:
call AICureStatus
ld a,FULL_RESTORE
ld [wAIItem],a
ld de,wHPBarOldHP
ld hl,wEnemyMonHP + 1
ld a,[hld]
ld [de],a
ld a, FULL_RESTORE
ld [wAIItem], a
ld de, wHPBarOldHP
ld hl, wEnemyMonHP + 1
ld a, [hld]
ld [de], a
inc de
ld a,[hl]
ld [de],a
ld a, [hl]
ld [de], a
inc de
ld hl,wEnemyMonMaxHP + 1
ld a,[hld]
ld [de],a
ld hl, wEnemyMonMaxHP + 1
ld a, [hld]
ld [de], a
inc de
ld [wHPBarMaxHP],a
ld [wEnemyMonHP + 1],a
ld a,[hl]
ld [de],a
ld [wHPBarMaxHP+1],a
ld [wEnemyMonHP],a
ld [wHPBarMaxHP], a
ld [wEnemyMonHP + 1], a
ld a, [hl]
ld [de], a
ld [wHPBarMaxHP+1], a
ld [wEnemyMonHP], a
jr AIPrintItemUseAndUpdateHPBar
AIUsePotion:
; enemy trainer heals his monster with a potion
ld a,POTION
ld b,20
ld a, POTION
ld b, 20
jr AIRecoverHP
AIUseSuperPotion:
; enemy trainer heals his monster with a super potion
ld a,SUPER_POTION
ld b,50
ld a, SUPER_POTION
ld b, 50
jr AIRecoverHP
AIUseHyperPotion:
; enemy trainer heals his monster with a hyper potion
ld a,HYPER_POTION
ld b,200
ld a, HYPER_POTION
ld b, 200
; fallthrough
AIRecoverHP:
; heal b HP and print "trainer used $(a) on pokemon!"
ld [wAIItem],a
ld hl,wEnemyMonHP + 1
ld a,[hl]
ld [wHPBarOldHP],a
ld [wAIItem], a
ld hl, wEnemyMonHP + 1
ld a, [hl]
ld [wHPBarOldHP], a
add b
ld [hld],a
ld [wHPBarNewHP],a
ld a,[hl]
ld [wHPBarOldHP+1],a
ld [wHPBarNewHP+1],a
jr nc,.next
ld [hld], a
ld [wHPBarNewHP], a
ld a, [hl]
ld [wHPBarOldHP+1], a
ld [wHPBarNewHP+1], a
jr nc, .next
inc a
ld [hl],a
ld [wHPBarNewHP+1],a
ld [hl], a
ld [wHPBarNewHP+1], a
.next
inc hl
ld a,[hld]
ld b,a
ld de,wEnemyMonMaxHP + 1
ld a,[de]
ld a, [hld]
ld b, a
ld de, wEnemyMonMaxHP + 1
ld a, [de]
dec de
ld [wHPBarMaxHP],a
ld [wHPBarMaxHP], a
sub b
ld a,[hli]
ld b,a
ld a,[de]
ld [wHPBarMaxHP+1],a
ld a, [hli]
ld b, a
ld a, [de]
ld [wHPBarMaxHP+1], a
sbc b
jr nc,AIPrintItemUseAndUpdateHPBar
jr nc, AIPrintItemUseAndUpdateHPBar
inc de
ld a,[de]
ld a, [de]
dec de
ld [hld],a
ld [wHPBarNewHP],a
ld a,[de]
ld [hl],a
ld [wHPBarNewHP+1],a
ld [hld], a
ld [wHPBarNewHP], a
ld a, [de]
ld [hl], a
ld [wHPBarNewHP+1], a
; fallthrough
AIPrintItemUseAndUpdateHPBar:
call AIPrintItemUse_
coord hl, 2, 2
xor a
ld [wHPBarType],a
ld [wHPBarType], a
predef UpdateHPBar2
jp DecrementAICount
AISwitchIfEnoughMons:
; enemy trainer switches if there are 3 or more unfainted mons in party
ld a,[wEnemyPartyCount]
ld c,a
ld hl,wEnemyMon1HP
ld a, [wEnemyPartyCount]
ld c, a
ld hl, wEnemyMon1HP
ld d,0 ; keep count of unfainted monsters
ld d, 0 ; keep count of unfainted monsters
; count how many monsters haven't fainted yet
.loop
ld a,[hli]
ld b,a
ld a,[hld]
ld a, [hli]
ld b, a
ld a, [hld]
or b
jr z,.Fainted ; has monster fainted?
jr z, .Fainted ; has monster fainted?
inc d
.Fainted
push bc
ld bc, wEnemyMon2 - wEnemyMon1
add hl,bc
add hl, bc
pop bc
dec c
jr nz,.loop
jr nz, .loop
ld a,d ; how many available monsters are there?
ld a, d ; how many available monsters are there?
cp 2 ; don't bother if only 1 or 2
jp nc,SwitchEnemyMon
jp nc, SwitchEnemyMon
and a
ret
@ -681,14 +681,14 @@ SwitchEnemyMon:
; prepare to withdraw the active monster: copy hp, number, and status to roster
ld a,[wEnemyMonPartyPos]
ld hl,wEnemyMon1HP
ld bc,wEnemyMon2 - wEnemyMon1
ld a, [wEnemyMonPartyPos]
ld hl, wEnemyMon1HP
ld bc, wEnemyMon2 - wEnemyMon1
call AddNTimes
ld d,h
ld e,l
ld hl,wEnemyMonHP
ld bc,4
ld d, h
ld e, l
ld hl, wEnemyMonHP
ld bc, 4
call CopyData
ld hl, AIBattleWithdrawText
@ -696,13 +696,13 @@ SwitchEnemyMon:
; This wFirstMonsNotOutYet variable is abused to prevent the player from
; switching in a new mon in response to this switch.
ld a,1
ld [wFirstMonsNotOutYet],a
ld a, 1
ld [wFirstMonsNotOutYet], a
callab EnemySendOut
xor a
ld [wFirstMonsNotOutYet],a
ld [wFirstMonsNotOutYet], a
ld a,[wLinkState]
ld a, [wLinkState]
cp LINK_STATE_BATTLING
ret z
scf
@ -715,120 +715,120 @@ AIBattleWithdrawText:
AIUseFullHeal:
call AIPlayRestoringSFX
call AICureStatus
ld a,FULL_HEAL
ld a, FULL_HEAL
jp AIPrintItemUse
AICureStatus:
; cures the status of enemy's active pokemon
ld a,[wEnemyMonPartyPos]
ld hl,wEnemyMon1Status
ld bc,wEnemyMon2 - wEnemyMon1
ld a, [wEnemyMonPartyPos]
ld hl, wEnemyMon1Status
ld bc, wEnemyMon2 - wEnemyMon1
call AddNTimes
xor a
ld [hl],a ; clear status in enemy team roster
ld [wEnemyMonStatus],a ; clear status of active enemy
ld hl,wEnemyBattleStatus3
res 0,[hl]
ld [hl], a ; clear status in enemy team roster
ld [wEnemyMonStatus], a ; clear status of active enemy
ld hl, wEnemyBattleStatus3
res 0, [hl]
ret
AIUseXAccuracy: ; unused
call AIPlayRestoringSFX
ld hl,wEnemyBattleStatus2
set 0,[hl]
ld a,X_ACCURACY
ld hl, wEnemyBattleStatus2
set 0, [hl]
ld a, X_ACCURACY
jp AIPrintItemUse
AIUseGuardSpec:
call AIPlayRestoringSFX
ld hl,wEnemyBattleStatus2
set 1,[hl]
ld a,GUARD_SPEC
ld hl, wEnemyBattleStatus2
set 1, [hl]
ld a, GUARD_SPEC
jp AIPrintItemUse
AIUseDireHit: ; unused
call AIPlayRestoringSFX
ld hl,wEnemyBattleStatus2
set 2,[hl]
ld a,DIRE_HIT
ld hl, wEnemyBattleStatus2
set 2, [hl]
ld a, DIRE_HIT
jp AIPrintItemUse
AICheckIfHPBelowFraction:
; return carry if enemy trainer's current HP is below 1 / a of the maximum
ld [H_DIVISOR],a
ld hl,wEnemyMonMaxHP
ld a,[hli]
ld [H_DIVIDEND],a
ld a,[hl]
ld [H_DIVIDEND + 1],a
ld b,2
ld [H_DIVISOR], a
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld [H_DIVIDEND], a
ld a, [hl]
ld [H_DIVIDEND + 1], a
ld b, 2
call Divide
ld a,[H_QUOTIENT + 3]
ld c,a
ld a,[H_QUOTIENT + 2]
ld b,a
ld hl,wEnemyMonHP + 1
ld a,[hld]
ld e,a
ld a,[hl]
ld d,a
ld a,d
ld a, [H_QUOTIENT + 3]
ld c, a
ld a, [H_QUOTIENT + 2]
ld b, a
ld hl, wEnemyMonHP + 1
ld a, [hld]
ld e, a
ld a, [hl]
ld d, a
ld a, d
sub b
ret nz
ld a,e
ld a, e
sub c
ret
AIUseXAttack:
ld b,$A
ld a,X_ATTACK
ld b, $A
ld a, X_ATTACK
jr AIIncreaseStat
AIUseXDefend:
ld b,$B
ld a,X_DEFEND
ld b, $B
ld a, X_DEFEND
jr AIIncreaseStat
AIUseXSpeed:
ld b,$C
ld a,X_SPEED
ld b, $C
ld a, X_SPEED
jr AIIncreaseStat
AIUseXSpecial:
ld b,$D
ld a,X_SPECIAL
ld b, $D
ld a, X_SPECIAL
; fallthrough
AIIncreaseStat:
ld [wAIItem],a
ld [wAIItem], a
push bc
call AIPrintItemUse_
pop bc
ld hl,wEnemyMoveEffect
ld a,[hld]
ld hl, wEnemyMoveEffect
ld a, [hld]
push af
ld a,[hl]
ld a, [hl]
push af
push hl
ld a,ANIM_AF
ld [hli],a
ld [hl],b
ld a, ANIM_AF
ld [hli], a
ld [hl], b
callab StatModifierUpEffect
pop hl
pop af
ld [hli],a
ld [hli], a
pop af
ld [hl],a
ld [hl], a
jp DecrementAICount
AIPrintItemUse:
ld [wAIItem],a
ld [wAIItem], a
call AIPrintItemUse_
jp DecrementAICount
AIPrintItemUse_:
; print "x used [wAIItem] on z!"
ld a,[wAIItem]
ld [wd11e],a
ld a, [wAIItem]
ld [wd11e], a
call GetItemName
ld hl, AIBattleUseItemText
jp PrintText