diff --git a/constants/player_ai_constants.asm b/constants/player_ai_constants.asm new file mode 100755 index 000000000..de2def5bc --- /dev/null +++ b/constants/player_ai_constants.asm @@ -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 diff --git a/constants/player_constants.asm b/constants/player_constants.asm index 046236879..7c53c93c0 100755 --- a/constants/player_constants.asm +++ b/constants/player_constants.asm @@ -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 diff --git a/engine/board/ai.asm b/engine/board/ai.asm new file mode 100755 index 000000000..c98215e0a --- /dev/null +++ b/engine/board/ai.asm @@ -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 diff --git a/engine/board/menu.asm b/engine/board/menu.asm index c8683a61a..6efd9dc50 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -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 diff --git a/engine/board/spaces.asm b/engine/board/spaces.asm index 5195ff6a7..e77c7faf1 100755 --- a/engine/board/spaces.asm +++ b/engine/board/spaces.asm @@ -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 diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 17d762f6c..59466cdff 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -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 diff --git a/engine/overworld/overworld.asm b/engine/overworld/overworld.asm index 5384755c1..5a4cf7536 100644 --- a/engine/overworld/overworld.asm +++ b/engine/overworld/overworld.asm @@ -60,6 +60,8 @@ GetPlayerSprite: ld [wPlayerObjectSprite], a ; from wMapObjects ret +INCLUDE "data/sprites/player_sprites.asm" + AddMapSprites: ld a, [wMapGroup] dec a diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm index ef8942d7b..e655503d5 100644 --- a/engine/overworld/player_object.asm +++ b/engine/overworld/player_object.asm @@ -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 diff --git a/includes.asm b/includes.asm index ba6cfc92f..dd448777e 100644 --- a/includes.asm +++ b/includes.asm @@ -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" diff --git a/main.asm b/main.asm index c7ec62c2c..db73e340e 100644 --- a/main.asm +++ b/main.asm @@ -251,6 +251,7 @@ INCLUDE "engine/board/menu.asm" INCLUDE "engine/board/next_player_turn.asm" INCLUDE "engine/board/spaces.asm" INCLUDE "engine/board/movement.asm" +INCLUDE "engine/board/ai.asm" SECTION "bank20", ROMX