Files
pokecrystal-board/engine/board/ai.asm

94 lines
1.5 KiB
NASM
Executable File

BoardAIAction:
; if current player is AI player, executes the PLAYERAIACTION_* at c and returns carry
ld a, [wCurTurnPlayer]
and a ; PLAYER_1?
ret z
ld b, 0
ld hl, .Jumptable
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable:
dw PlayerAIAction_BoardMenu
dw PlayerAIAction_RollDie
dw PlayerAIAction_ChooseBranchDir
PlayerAIAction_BoardMenu:
ld c, 30
call DelayFrames
ld a, A_BUTTON
scf
ret
PlayerAIAction_RollDie:
ld a, [wFrameCounter2]
dec a
ld [wFrameCounter2], a
scf
jr nz, .not_yet
ld a, A_BUTTON
ret
.not_yet
ld a, 0
ret
PlayerAIAction_ChooseBranchDir:
; choose a valid and available direction at random
ld c, 30
call DelayFrames
.random
call Random
and %11
ld hl, wTempSpaceBranchStruct
; right
; cp %00
jr nz, .next1
ld a, [hl]
inc a ; cp BRANCH_DIRECTION_INVALID
jr z, .random
inc a ; cp BRANCH_DIRECTION_UNAVAILABLE
jr z, .random
ld a, D_RIGHT
jr .done
.next1
; left
inc hl
cp %01
jr nz, .next2
ld a, [hl]
inc a ; cp BRANCH_DIRECTION_INVALID
jr z, .random
inc a ; cp BRANCH_DIRECTION_UNAVAILABLE
jr z, .random
ld a, D_LEFT
jr .done
.next2
; up
inc hl
cp %10
jr nz, .next3
ld a, [hl]
inc a ; cp BRANCH_DIRECTION_INVALID
jr z, .random
inc a ; cp BRANCH_DIRECTION_UNAVAILABLE
jr z, .random
ld a, D_UP
jr .done
.next3
; down
inc hl
ld a, [hl]
inc a ; cp BRANCH_DIRECTION_INVALID
jr z, .random
inc a ; cp BRANCH_DIRECTION_UNAVAILABLE
jr z, .random
ld a, D_DOWN
.done
scf
ret