You've already forked pokecrystal-board
mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-12-11 05:02:16 -08:00
Multiplayer engine: automate player AI actions in board menu and branch space [Commit 13] (#40)
This commit is contained in:
5
constants/player_ai_constants.asm
Executable file
5
constants/player_ai_constants.asm
Executable file
@@ -0,0 +1,5 @@
|
||||
const_def
|
||||
const PLAYERAIACTION_BOARD_MENU ; 0
|
||||
const PLAYERAIACTION_ROLL_DIE ; 1
|
||||
const PLAYERAIACTION_CHOOSE_BRANCH_DIR ; 2
|
||||
DEF NUM_PLAYER_AI_ACTIONS EQU const_value
|
||||
@@ -5,6 +5,15 @@
|
||||
const PLAYER_CHRIS
|
||||
const PLAYER_KRIS
|
||||
const PLAYER_GREEN
|
||||
|
||||
; player character types (see data/players/objects.asm)
|
||||
const_def
|
||||
const PLAYER_DEFAULT_MALE ; 0
|
||||
const PLAYER_DEFAULT_FEMALE ; 1
|
||||
const PLAYER_YOUNGSTER_1 ; 2
|
||||
const PLAYER_YOUNGSTER_2 ; 3
|
||||
const PLAYER_YOUNGSTER_3 ; 4
|
||||
const PLAYER_BUG_CATCHER_1 ; 5
|
||||
DEF NUM_PLAYER_CHARACTERS EQU const_value
|
||||
|
||||
; field ids in the Players table
|
||||
@@ -26,13 +35,3 @@ DEF PLAYERDATA_LENGTH EQU _RS
|
||||
const PLAYER_4 ; 3
|
||||
; maximum number of participants in a level (1 is the human player and MAX_PLAYERS-1 are AI players)
|
||||
DEF MAX_PLAYERS EQU const_value
|
||||
|
||||
; player character types (see data/players/objects.asm)
|
||||
const_def
|
||||
const PLAYER_DEFAULT_MALE ; 0
|
||||
const PLAYER_DEFAULT_FEMALE ; 1
|
||||
const PLAYER_YOUNGSTER_1 ; 2
|
||||
const PLAYER_YOUNGSTER_2 ; 3
|
||||
const PLAYER_YOUNGSTER_3 ; 4
|
||||
const PLAYER_BUG_CATCHER_1 ; 5
|
||||
DEF NUM_PLAYER_CHARACTERS EQU const_value
|
||||
|
||||
93
engine/board/ai.asm
Executable file
93
engine/board/ai.asm
Executable file
@@ -0,0 +1,93 @@
|
||||
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
|
||||
@@ -157,9 +157,13 @@ BoardMenuScript::
|
||||
|
||||
BoardMenu::
|
||||
; returns the selected menu item (BOARDMENUITEM_*) in hScriptVar upon exit
|
||||
ld a, [wCurTurnPlayer]
|
||||
and a ; PLAYER_1?
|
||||
jr nz, .die
|
||||
ld a, [wBoardMenuLastCursorPosition]
|
||||
cp NUM_BOARD_MENU_ITEMS
|
||||
jr c, .ok
|
||||
.die
|
||||
ld a, BOARDMENUITEM_DIE
|
||||
.ok
|
||||
ld [wBoardMenuCursorPosition], a
|
||||
@@ -223,8 +227,12 @@ ApplyBoardMenuSpritePalette:
|
||||
|
||||
GetBoardMenuSelection:
|
||||
call DelayFrame
|
||||
ld c, PLAYERAIACTION_BOARD_MENU
|
||||
call BoardAIAction
|
||||
jr c, .ai_action
|
||||
call JoyTextDelay
|
||||
call GetMenuJoypad
|
||||
.ai_action
|
||||
bit A_BUTTON_F, a
|
||||
jr nz, .a_button
|
||||
bit SELECT_F, a
|
||||
@@ -280,8 +288,10 @@ DEF DIE_MAX_NUMBER EQU 6
|
||||
set SECONDARYSPRITES_DIE_ROLL_F, [hl]
|
||||
ld a, 1
|
||||
ld [wDieRoll], a
|
||||
call HDMATransferTilemapAndAttrmap_Menu ;
|
||||
call CloseText ; closetext
|
||||
ld a, 30
|
||||
ld [wFrameCounter2], a
|
||||
call HDMATransferTilemapAndAttrmap_Menu
|
||||
call CloseText
|
||||
|
||||
.rotate_die_loop
|
||||
call IsSFXPlaying
|
||||
@@ -295,8 +305,12 @@ DEF DIE_MAX_NUMBER EQU 6
|
||||
add $1
|
||||
ld [wDieRoll], a
|
||||
call UpdateSecondarySprites
|
||||
ld c, PLAYERAIACTION_ROLL_DIE
|
||||
call BoardAIAction
|
||||
jr c, .ai_action
|
||||
call GetJoypad
|
||||
ldh a, [hJoyPressed]
|
||||
.ai_action
|
||||
bit B_BUTTON_F, a
|
||||
jr nz, .back_to_menu
|
||||
bit A_BUTTON_F, a
|
||||
|
||||
@@ -217,11 +217,16 @@ endr
|
||||
ret
|
||||
|
||||
PromptPlayerToChooseBranchDirection:
|
||||
ld c, PLAYERAIACTION_CHOOSE_BRANCH_DIR
|
||||
call BoardAIAction
|
||||
jr c, .ai_action
|
||||
|
||||
; sample a dpad press or SELECT button
|
||||
call DelayFrame
|
||||
ld hl, wTempSpaceBranchStruct
|
||||
call GetJoypad
|
||||
ldh a, [hJoyPressed]
|
||||
.ai_action
|
||||
ld hl, wTempSpaceBranchStruct
|
||||
and D_PAD | SELECT
|
||||
jr z, PromptPlayerToChooseBranchDirection
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ StartMap:
|
||||
xor a ; PLAYER_1
|
||||
ld [wCurTurnPlayer], a
|
||||
ld hl, wPlayer1Character
|
||||
ld a, [wPlayerGender] ; PLAYER_DEFAULT_MALE or PLAYER_DEFAULT_FEMALE
|
||||
ld a, [wPlayerCharacter]
|
||||
ld [hli], a ; wPlayer1Character
|
||||
ld a, PLAYER_BUG_CATCHER_1
|
||||
ld [hli], a ; wPlayer2Character
|
||||
|
||||
@@ -60,6 +60,8 @@ GetPlayerSprite:
|
||||
ld [wPlayerObjectSprite], a ; from wMapObjects
|
||||
ret
|
||||
|
||||
INCLUDE "data/sprites/player_sprites.asm"
|
||||
|
||||
AddMapSprites:
|
||||
ld a, [wMapGroup]
|
||||
dec a
|
||||
|
||||
@@ -1060,11 +1060,7 @@ MockPlayerObject:
|
||||
cp -1
|
||||
jr nz, .loop
|
||||
|
||||
; adjust sprite id
|
||||
farcall DeterminePlayerSprite
|
||||
ld a, c
|
||||
ld [wMapObject{d:LAST_OBJECT}Sprite], a
|
||||
|
||||
.copy_player_coords
|
||||
; copy player's coordinates
|
||||
ld a, [wMockingWhichPlayer]
|
||||
ld hl, wPlayer1MockYCoord
|
||||
|
||||
@@ -54,6 +54,7 @@ INCLUDE "constants/item_data_constants.asm"
|
||||
INCLUDE "constants/music_constants.asm"
|
||||
INCLUDE "constants/npc_trade_constants.asm"
|
||||
INCLUDE "constants/phone_constants.asm"
|
||||
INCLUDE "constants/player_ai_constants.asm"
|
||||
INCLUDE "constants/player_constants.asm"
|
||||
INCLUDE "constants/pokemon_constants.asm"
|
||||
INCLUDE "constants/pokemon_data_constants.asm"
|
||||
|
||||
Reference in New Issue
Block a user