CalcMonAbility::
; species in [wCurSpecies]
; dvs pointer in hl

; If we're in a link battle with a non-Prism game, disable abilities.
	push bc
	call GetBaseData ; preserves hl
	; Determine the parity of the DVs
	; Use the DVs to determine which of the two abilities to use.
	ld b, 2
	call CountSetBits

CalcMonAbility_Done:
	rra
	ld hl, wBaseAbilities ; First 2 bytes of the 4-byte padding
	jr nc, .load
	inc hl
.load
	ld a, [hl]
.single_ability
	pop bc
	ret

CalcTrainerMonAbility::
; Trainer 'mon's ability is also depends on class, ID and party position
	push bc
	call GetBaseData ; preserves hl
	ld a, [hli]
	ld b, a
	ld a, [OtherTrainerClass]
	add b
	ld b, a
	ld a, [hl]
	ld c, a
	ld a, [OtherTrainerID]
	add c
	xor b
	ld b, a
	bit 6, b
	jr z, .noswap
	swap a
.noswap
	bit 7, b
	jr z, .nocpl
	cpl
.nocpl
	ld c, a
	ld a, [CurOTMon]
	and a
	jr z, .skiprrc
	ld b, a
.rrcloop
	rrc c
	dec b
	jr nz, .rrcloop
.skiprrc
	ld a, c
	jr CalcMonAbility_Done
	

INCLUDE "battle/ability_names.asm"
INCLUDE "battle/pickup.asm"
