2018-06-24 14:09:41 +00:00
|
|
|
CheckPlayerMoveTypeMatchups:
|
2015-11-07 13:05:57 +00:00
|
|
|
; Check how well the moves you've already used
|
|
|
|
; fare against the enemy's Pokemon. Used to
|
|
|
|
; score a potential switch.
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld a, 10
|
2016-01-12 17:46:18 +00:00
|
|
|
ld [wEnemyAISwitchScore], a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wPlayerUsedMoves
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .unknown_moves
|
|
|
|
|
|
|
|
ld d, NUM_MOVES
|
|
|
|
ld e, 0
|
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
|
|
|
and a
|
|
|
|
jr z, .exit
|
|
|
|
push hl
|
|
|
|
dec a
|
|
|
|
ld hl, Moves + MOVE_POWER
|
|
|
|
call GetMoveAttr
|
|
|
|
and a
|
|
|
|
jr z, .next
|
|
|
|
|
|
|
|
inc hl
|
|
|
|
call GetMoveByte
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wEnemyMonType
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckTypeMatchup
|
|
|
|
ld a, [wTypeMatchup]
|
|
|
|
cp 10 + 1 ; 1.0 + 0.1
|
|
|
|
jr nc, .super_effective
|
|
|
|
and a
|
|
|
|
jr z, .next
|
|
|
|
cp 10 ; 1.0
|
|
|
|
jr nc, .neutral
|
|
|
|
|
|
|
|
.not_very_effective
|
|
|
|
ld a, e
|
|
|
|
cp 1 ; 0.1
|
|
|
|
jr nc, .next
|
|
|
|
ld e, 1
|
|
|
|
jr .next
|
|
|
|
|
|
|
|
.neutral
|
|
|
|
ld e, 2
|
|
|
|
jr .next
|
|
|
|
|
|
|
|
.super_effective
|
|
|
|
call .DecreaseScore
|
|
|
|
pop hl
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.next
|
|
|
|
pop hl
|
|
|
|
dec d
|
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
.exit
|
|
|
|
ld a, e
|
|
|
|
cp 2
|
|
|
|
jr z, .done
|
|
|
|
call .IncreaseScore
|
|
|
|
ld a, e
|
|
|
|
and a
|
|
|
|
jr nz, .done
|
|
|
|
call .IncreaseScore
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.unknown_moves
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wBattleMonType1]
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wEnemyMonType1
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckTypeMatchup
|
|
|
|
ld a, [wTypeMatchup]
|
|
|
|
cp 10 + 1 ; 1.0 + 0.1
|
|
|
|
jr c, .ok
|
|
|
|
call .DecreaseScore
|
|
|
|
.ok
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wBattleMonType2]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp b
|
|
|
|
jr z, .ok2
|
|
|
|
call CheckTypeMatchup
|
|
|
|
ld a, [wTypeMatchup]
|
|
|
|
cp 10 + 1 ; 1.0 + 0.1
|
|
|
|
jr c, .ok2
|
|
|
|
call .DecreaseScore
|
|
|
|
.ok2
|
|
|
|
|
|
|
|
.done
|
|
|
|
call .CheckEnemyMoveMatchups
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.CheckEnemyMoveMatchups:
|
2018-01-23 22:39:09 +00:00
|
|
|
ld de, wEnemyMonMoves
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, NUM_MOVES + 1
|
|
|
|
ld c, 0
|
|
|
|
|
|
|
|
ld a, [wTypeMatchup]
|
|
|
|
push af
|
|
|
|
.loop2
|
|
|
|
dec b
|
|
|
|
jr z, .exit2
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
and a
|
|
|
|
jr z, .exit2
|
|
|
|
|
|
|
|
inc de
|
|
|
|
dec a
|
|
|
|
ld hl, Moves + MOVE_POWER
|
|
|
|
call GetMoveAttr
|
|
|
|
and a
|
|
|
|
jr z, .loop2
|
|
|
|
|
|
|
|
inc hl
|
|
|
|
call GetMoveByte
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wBattleMonType1
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckTypeMatchup
|
|
|
|
|
|
|
|
ld a, [wTypeMatchup]
|
|
|
|
; immune
|
|
|
|
and a
|
|
|
|
jr z, .loop2
|
|
|
|
|
|
|
|
; not very effective
|
|
|
|
inc c
|
|
|
|
cp 10
|
|
|
|
jr c, .loop2
|
|
|
|
|
|
|
|
; neutral
|
|
|
|
inc c
|
2016-05-16 13:36:24 +00:00
|
|
|
inc c
|
|
|
|
inc c
|
|
|
|
inc c
|
|
|
|
inc c
|
2015-11-07 13:05:57 +00:00
|
|
|
cp 10
|
|
|
|
jr z, .loop2
|
|
|
|
|
|
|
|
; super effective
|
|
|
|
ld c, 100
|
|
|
|
jr .loop2
|
|
|
|
|
|
|
|
.exit2
|
|
|
|
pop af
|
|
|
|
ld [wTypeMatchup], a
|
|
|
|
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
jr z, .doubledown ; double down
|
|
|
|
cp 5
|
|
|
|
jr c, .DecreaseScore ; down
|
|
|
|
cp 100
|
|
|
|
ret c
|
|
|
|
jr .IncreaseScore ; up
|
|
|
|
|
|
|
|
.doubledown
|
|
|
|
call .DecreaseScore
|
2018-06-24 14:09:41 +00:00
|
|
|
.DecreaseScore:
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
dec a
|
2016-01-12 17:46:18 +00:00
|
|
|
ld [wEnemyAISwitchScore], a
|
2015-11-07 13:05:57 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.IncreaseScore:
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
inc a
|
2016-01-12 17:46:18 +00:00
|
|
|
ld [wEnemyAISwitchScore], a
|
2015-11-07 13:05:57 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckAbleToSwitch:
|
2015-11-07 13:05:57 +00:00
|
|
|
xor a
|
2015-11-09 00:09:36 +00:00
|
|
|
ld [wEnemySwitchMonParam], a
|
|
|
|
call FindAliveEnemyMons
|
2015-11-07 13:05:57 +00:00
|
|
|
ret c
|
|
|
|
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wEnemySubStatus1]
|
2015-11-07 13:05:57 +00:00
|
|
|
bit SUBSTATUS_PERISH, a
|
|
|
|
jr z, .no_perish
|
|
|
|
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wEnemyPerishCount]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp 1
|
|
|
|
jr nz, .no_perish
|
|
|
|
|
|
|
|
; Perish count is 1
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
call FindAliveEnemyMons
|
2016-05-16 13:36:24 +00:00
|
|
|
call FindEnemyMonsWithAtLeastQuarterMaxHP
|
2015-11-09 00:09:36 +00:00
|
|
|
call FindEnemyMonsThatResistPlayer
|
2016-05-16 13:36:24 +00:00
|
|
|
call FindAliveEnemyMonsWithASuperEffectiveMove
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld a, e
|
|
|
|
cp 2
|
|
|
|
jr nz, .not_2
|
|
|
|
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2016-05-16 13:36:24 +00:00
|
|
|
add $30 ; maximum chance
|
2015-11-09 00:09:36 +00:00
|
|
|
ld [wEnemySwitchMonParam], a
|
2015-11-07 13:05:57 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
.not_2
|
2015-11-09 00:09:36 +00:00
|
|
|
call FindAliveEnemyMons
|
2015-11-07 13:05:57 +00:00
|
|
|
sla c
|
|
|
|
sla c
|
|
|
|
ld b, $ff
|
|
|
|
|
|
|
|
.loop1
|
|
|
|
inc b
|
|
|
|
sla c
|
|
|
|
jr nc, .loop1
|
|
|
|
|
|
|
|
ld a, b
|
2016-05-16 13:36:24 +00:00
|
|
|
add $30 ; maximum chance
|
2015-11-09 00:09:36 +00:00
|
|
|
ld [wEnemySwitchMonParam], a
|
2015-11-07 13:05:57 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
.no_perish
|
|
|
|
call CheckPlayerMoveTypeMatchups
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp 11
|
|
|
|
ret nc
|
|
|
|
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wLastPlayerCounterMove]
|
2015-11-07 13:05:57 +00:00
|
|
|
and a
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .no_last_counter_move
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
call FindEnemyMonsImmuneToLastCounterMove
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
and a
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .no_last_counter_move
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld c, a
|
2016-05-16 13:36:24 +00:00
|
|
|
call FindEnemyMonsWithASuperEffectiveMove
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp $ff
|
|
|
|
ret z
|
|
|
|
|
|
|
|
ld b, a
|
|
|
|
ld a, e
|
|
|
|
cp 2
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .not_2_again
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
call CheckPlayerMoveTypeMatchups
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp 10
|
|
|
|
ret nc
|
|
|
|
|
|
|
|
ld a, b
|
|
|
|
add $10
|
2015-11-09 00:09:36 +00:00
|
|
|
ld [wEnemySwitchMonParam], a
|
2015-11-07 13:05:57 +00:00
|
|
|
ret
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.not_2_again
|
2015-11-07 13:05:57 +00:00
|
|
|
ld c, $10
|
|
|
|
call CheckPlayerMoveTypeMatchups
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp 10
|
2015-11-09 00:09:36 +00:00
|
|
|
jr nc, .okay
|
2015-11-07 13:05:57 +00:00
|
|
|
ld c, $20
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.okay
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, b
|
|
|
|
add c
|
2015-11-09 00:09:36 +00:00
|
|
|
ld [wEnemySwitchMonParam], a
|
2015-11-07 13:05:57 +00:00
|
|
|
ret
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.no_last_counter_move
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckPlayerMoveTypeMatchups
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp 10
|
|
|
|
ret nc
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
call FindAliveEnemyMons
|
2016-05-16 13:36:24 +00:00
|
|
|
call FindEnemyMonsWithAtLeastQuarterMaxHP
|
2015-11-09 00:09:36 +00:00
|
|
|
call FindEnemyMonsThatResistPlayer
|
2016-05-16 13:36:24 +00:00
|
|
|
call FindAliveEnemyMonsWithASuperEffectiveMove
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld a, e
|
|
|
|
cp $2
|
|
|
|
ret nz
|
|
|
|
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
add $10
|
2015-11-09 00:09:36 +00:00
|
|
|
ld [wEnemySwitchMonParam], a
|
2015-11-07 13:05:57 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FindAliveEnemyMons:
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wOTPartyCount]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp 2
|
|
|
|
jr c, .only_one
|
|
|
|
|
|
|
|
ld d, a
|
|
|
|
ld e, 0
|
|
|
|
ld b, 1 << (PARTY_LENGTH - 1)
|
|
|
|
ld c, 0
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1HP
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
.loop
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wCurOTMon]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp e
|
|
|
|
jr z, .next
|
|
|
|
|
|
|
|
push bc
|
|
|
|
ld b, [hl]
|
|
|
|
inc hl
|
|
|
|
ld a, [hld]
|
|
|
|
or b
|
|
|
|
pop bc
|
|
|
|
jr z, .next
|
|
|
|
|
|
|
|
ld a, c
|
|
|
|
or b
|
|
|
|
ld c, a
|
|
|
|
|
|
|
|
.next
|
|
|
|
srl b
|
|
|
|
push bc
|
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
inc e
|
|
|
|
dec d
|
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
jr nz, .more_than_one
|
|
|
|
|
|
|
|
.only_one
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
.more_than_one
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FindEnemyMonsImmuneToLastCounterMove:
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1
|
|
|
|
ld a, [wOTPartyCount]
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, a
|
|
|
|
ld c, 1 << (PARTY_LENGTH - 1)
|
|
|
|
ld d, 0
|
|
|
|
xor a
|
2016-01-12 17:46:18 +00:00
|
|
|
ld [wEnemyAISwitchScore], a
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
.loop
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wCurOTMon]
|
2015-11-07 13:05:57 +00:00
|
|
|
cp d
|
|
|
|
push hl
|
2016-05-16 13:36:24 +00:00
|
|
|
jr z, .next
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
push hl
|
|
|
|
push bc
|
2016-05-16 13:36:24 +00:00
|
|
|
|
|
|
|
; If the Pokemon has at least 1 HP...
|
2015-11-07 13:05:57 +00:00
|
|
|
ld bc, MON_HP
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
ld a, [hli]
|
|
|
|
or [hl]
|
|
|
|
pop hl
|
2016-05-16 13:36:24 +00:00
|
|
|
jr z, .next
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld a, [hl]
|
2018-01-23 22:39:09 +00:00
|
|
|
ld [wCurSpecies], a
|
2015-11-07 13:05:57 +00:00
|
|
|
call GetBaseData
|
2016-05-16 13:36:24 +00:00
|
|
|
|
2017-01-08 00:26:48 +00:00
|
|
|
; the player's last move is damaging...
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wLastPlayerCounterMove]
|
2015-11-07 13:05:57 +00:00
|
|
|
dec a
|
|
|
|
ld hl, Moves + MOVE_POWER
|
|
|
|
call GetMoveAttr
|
|
|
|
and a
|
2016-05-16 13:36:24 +00:00
|
|
|
jr z, .next
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; and the Pokemon is immune to it...
|
2015-11-07 13:05:57 +00:00
|
|
|
inc hl
|
|
|
|
call GetMoveByte
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wBaseType
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckTypeMatchup
|
|
|
|
ld a, [wTypeMatchup]
|
|
|
|
and a
|
2016-05-16 13:36:24 +00:00
|
|
|
jr nz, .next
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; ... encourage that Pokemon.
|
2016-01-12 17:46:18 +00:00
|
|
|
ld a, [wEnemyAISwitchScore]
|
2015-11-07 13:05:57 +00:00
|
|
|
or c
|
2016-01-12 17:46:18 +00:00
|
|
|
ld [wEnemyAISwitchScore], a
|
2016-05-16 13:36:24 +00:00
|
|
|
.next
|
2015-11-07 13:05:57 +00:00
|
|
|
pop hl
|
|
|
|
dec b
|
|
|
|
ret z
|
|
|
|
|
|
|
|
push bc
|
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
inc d
|
|
|
|
srl c
|
2016-05-16 13:36:24 +00:00
|
|
|
jr .loop
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FindAliveEnemyMonsWithASuperEffectiveMove:
|
2015-11-07 13:05:57 +00:00
|
|
|
push bc
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wOTPartyCount]
|
2015-11-07 13:05:57 +00:00
|
|
|
ld e, a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1HP
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, 1 << (PARTY_LENGTH - 1)
|
|
|
|
ld c, 0
|
2015-11-09 00:09:36 +00:00
|
|
|
.loop
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, [hli]
|
|
|
|
or [hl]
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .next
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld a, b
|
|
|
|
or c
|
|
|
|
ld c, a
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.next
|
2015-11-07 13:05:57 +00:00
|
|
|
srl b
|
|
|
|
push bc
|
2018-01-23 22:39:09 +00:00
|
|
|
ld bc, wPartyMon2HP - (wPartyMon1HP + 1)
|
2015-11-07 13:05:57 +00:00
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec e
|
2015-11-09 00:09:36 +00:00
|
|
|
jr nz, .loop
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld a, c
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
and c
|
|
|
|
ld c, a
|
2018-06-25 16:24:18 +00:00
|
|
|
; fallthrough
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2018-06-25 16:24:18 +00:00
|
|
|
FindEnemyMonsWithASuperEffectiveMove:
|
2016-05-16 13:36:24 +00:00
|
|
|
ld a, -1
|
2016-01-12 17:46:18 +00:00
|
|
|
ld [wEnemyAISwitchScore], a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1Moves
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, 1 << (PARTY_LENGTH - 1)
|
|
|
|
ld d, 0
|
|
|
|
ld e, 0
|
2015-11-09 00:09:36 +00:00
|
|
|
.loop
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, b
|
|
|
|
and c
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .next
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
push hl
|
|
|
|
push bc
|
2016-05-16 13:36:24 +00:00
|
|
|
; for move on mon:
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, NUM_MOVES
|
|
|
|
ld c, 0
|
2015-11-09 00:09:36 +00:00
|
|
|
.loop3
|
2016-05-16 13:36:24 +00:00
|
|
|
; if move is None: break
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, [hli]
|
|
|
|
and a
|
|
|
|
push hl
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .break3
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; if move has no power: continue
|
2015-11-07 13:05:57 +00:00
|
|
|
dec a
|
|
|
|
ld hl, Moves + MOVE_POWER
|
|
|
|
call GetMoveAttr
|
|
|
|
and a
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .nope
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; check type matchups
|
2015-11-07 13:05:57 +00:00
|
|
|
inc hl
|
|
|
|
call GetMoveByte
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wBattleMonType1
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckTypeMatchup
|
2016-05-16 13:36:24 +00:00
|
|
|
|
|
|
|
; if immune or not very effective: continue
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, [wTypeMatchup]
|
|
|
|
cp 10
|
2015-11-09 00:09:36 +00:00
|
|
|
jr c, .nope
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; if neutral: load 1 and continue
|
2015-11-07 13:05:57 +00:00
|
|
|
ld e, 1
|
2015-11-09 00:09:36 +00:00
|
|
|
cp 10 + 1
|
|
|
|
jr c, .nope
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; if super-effective: load 2 and break
|
2015-11-07 13:05:57 +00:00
|
|
|
ld e, 2
|
2015-11-09 00:09:36 +00:00
|
|
|
jr .break3
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.nope
|
2015-11-07 13:05:57 +00:00
|
|
|
pop hl
|
|
|
|
dec b
|
2015-11-09 00:09:36 +00:00
|
|
|
jr nz, .loop3
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
jr .done
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.break3
|
2015-11-07 13:05:57 +00:00
|
|
|
pop hl
|
2015-11-09 00:09:36 +00:00
|
|
|
.done
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, e
|
|
|
|
pop bc
|
|
|
|
pop hl
|
2016-05-16 13:36:24 +00:00
|
|
|
cp 2
|
|
|
|
jr z, .done2 ; at least one move is super-effective
|
|
|
|
cp 1
|
|
|
|
jr nz, .next ; no move does more than half damage
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; encourage this pokemon
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, d
|
|
|
|
or b
|
|
|
|
ld d, a
|
2016-05-16 13:36:24 +00:00
|
|
|
jr .next ; such a long jump
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.next
|
2016-05-16 13:36:24 +00:00
|
|
|
; next pokemon?
|
2015-11-07 13:05:57 +00:00
|
|
|
push bc
|
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
srl b
|
2015-11-09 00:09:36 +00:00
|
|
|
jr nc, .loop
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2016-05-16 13:36:24 +00:00
|
|
|
; if no pokemon has a super-effective move: return
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, d
|
|
|
|
ld b, a
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.done2
|
2016-05-16 13:36:24 +00:00
|
|
|
; convert the bit flag to an int and return
|
2015-11-07 13:05:57 +00:00
|
|
|
push bc
|
|
|
|
sla b
|
|
|
|
sla b
|
|
|
|
ld c, $ff
|
2015-11-09 00:09:36 +00:00
|
|
|
.loop2
|
2015-11-07 13:05:57 +00:00
|
|
|
inc c
|
|
|
|
sla b
|
2015-11-09 00:09:36 +00:00
|
|
|
jr nc, .loop2
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld a, c
|
2016-01-12 17:46:18 +00:00
|
|
|
ld [wEnemyAISwitchScore], a
|
2015-11-07 13:05:57 +00:00
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FindEnemyMonsThatResistPlayer:
|
2015-11-07 13:05:57 +00:00
|
|
|
push bc
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartySpecies
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, 1 << (PARTY_LENGTH - 1)
|
|
|
|
ld c, 0
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.loop
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, [hli]
|
|
|
|
cp $ff
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .done
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
push hl
|
2018-01-23 22:39:09 +00:00
|
|
|
ld [wCurSpecies], a
|
2015-11-07 13:05:57 +00:00
|
|
|
call GetBaseData
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wLastPlayerCounterMove]
|
2015-11-07 13:05:57 +00:00
|
|
|
and a
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .skip_move
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
dec a
|
|
|
|
ld hl, Moves + MOVE_POWER
|
|
|
|
call GetMoveAttr
|
|
|
|
and a
|
2015-11-09 00:09:36 +00:00
|
|
|
jr z, .skip_move
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
inc hl
|
|
|
|
call GetMoveByte
|
2015-11-09 00:09:36 +00:00
|
|
|
jr .check_type
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.skip_move
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wBattleMonType1]
|
|
|
|
ld hl, wBaseType
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckTypeMatchup
|
|
|
|
ld a, [wTypeMatchup]
|
2015-11-09 00:09:36 +00:00
|
|
|
cp 10 + 1
|
|
|
|
jr nc, .dont_choose_mon
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wBattleMonType2]
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.check_type
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wBaseType
|
2015-11-07 13:05:57 +00:00
|
|
|
call CheckTypeMatchup
|
|
|
|
ld a, [wTypeMatchup]
|
2015-11-09 00:09:36 +00:00
|
|
|
cp 10 + 1
|
|
|
|
jr nc, .dont_choose_mon
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
ld a, b
|
|
|
|
or c
|
|
|
|
ld c, a
|
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.dont_choose_mon
|
2015-11-07 13:05:57 +00:00
|
|
|
srl b
|
|
|
|
pop hl
|
2015-11-09 00:09:36 +00:00
|
|
|
jr .loop
|
2015-11-07 13:05:57 +00:00
|
|
|
|
2015-11-09 00:09:36 +00:00
|
|
|
.done
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, c
|
|
|
|
pop bc
|
|
|
|
and c
|
|
|
|
ld c, a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FindEnemyMonsWithAtLeastQuarterMaxHP:
|
2015-11-07 13:05:57 +00:00
|
|
|
push bc
|
2018-01-23 22:39:09 +00:00
|
|
|
ld de, wOTPartySpecies
|
2015-11-07 13:05:57 +00:00
|
|
|
ld b, 1 << (PARTY_LENGTH - 1)
|
|
|
|
ld c, 0
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wOTPartyMon1HP
|
2015-11-07 13:05:57 +00:00
|
|
|
|
|
|
|
.loop
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
cp $ff
|
|
|
|
jr z, .done
|
|
|
|
|
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
ld b, [hl]
|
|
|
|
inc hl
|
|
|
|
ld c, [hl]
|
|
|
|
inc hl
|
2016-05-04 15:46:23 +00:00
|
|
|
inc hl
|
2015-11-09 00:09:36 +00:00
|
|
|
; hl = MaxHP + 1
|
2016-05-16 13:36:24 +00:00
|
|
|
; bc = [CurHP] * 4
|
2015-11-07 13:05:57 +00:00
|
|
|
srl c
|
|
|
|
rl b
|
|
|
|
srl c
|
|
|
|
rl b
|
2016-05-16 13:36:24 +00:00
|
|
|
; if bc >= [hl], encourage
|
2015-11-07 13:05:57 +00:00
|
|
|
ld a, [hld]
|
|
|
|
cp c
|
|
|
|
ld a, [hl]
|
|
|
|
sbc b
|
|
|
|
pop bc
|
|
|
|
jr nc, .next
|
|
|
|
|
|
|
|
ld a, b
|
|
|
|
or c
|
|
|
|
ld c, a
|
|
|
|
|
|
|
|
.next
|
|
|
|
srl b
|
|
|
|
pop hl
|
|
|
|
push bc
|
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.done
|
|
|
|
ld a, c
|
|
|
|
pop bc
|
|
|
|
and c
|
|
|
|
ld c, a
|
|
|
|
ret
|