Player management [Commit 1] (#38)

This commit is contained in:
xCrystal 2024-03-08 18:56:26 +01:00
parent bb0240e279
commit dbb340515f
18 changed files with 120 additions and 200 deletions

18
constants/player_constants.asm Executable file
View File

@ -0,0 +1,18 @@
; see GetPlayerField (home/player.asm) and Players (data/players/players.asm)
; player characters
const_def
const PLAYER_CHRIS
const PLAYER_KRIS
const PLAYER_GREEN
DEF NUM_PLAYER_CHARACTERS EQU const_value
; field ids in the Players table
rsreset
DEF PLAYERDATA_STATE_SPRITES rw
DEF PLAYERDATA_NPC_PAL rb
DEF PLAYERDATA_FISHING_SPRITE rw
DEF PLAYERDATA_FRONTPIC rw
DEF PLAYERDATA_BACKPIC rw
DEF PLAYERDATA_PIC_PAL rw
DEF PLAYERDATA_LENGTH EQU _RS

0
data/player_names.asm → data/players/names.asm Normal file → Executable file
View File

13
data/players/players.asm Executable file
View File

@ -0,0 +1,13 @@
MACRO player
dw \1 ; ptr to ow state sprites
db \2 ; ow sprite palette
dw \3 ; ptr to ow fishing gfx
dw \4, \5 ; ptr to (uncompressed) frontpic, ptr to (compressed) backpic
dw \6 ; ptr to pic pallete
ENDM
Players::
player ChrisStateSprites, PAL_NPC_RED, FishingGFX, ChrisPic, ChrisBackpic, PlayerPalette ; PLAYER_CHRIS
player KrisStateSprites, PAL_NPC_BLUE, KrisFishingGFX, KrisPic, KrisBackpic, KrisPalette ; PLAYER_KRIS
player GreenStateSprites, PAL_NPC_GREEN, FishingGFX, ChrisPic, ChrisBackpic, PlayerPalette ; PLAYER_GREEN
db $ff

View File

@ -11,3 +11,10 @@ KrisStateSprites:
db PLAYER_SURF, SPRITE_SURF
db PLAYER_SURF_PIKA, SPRITE_SURFING_PIKACHU
db -1 ; end
GreenStateSprites:
db PLAYER_NORMAL, SPRITE_RIVAL
db PLAYER_BIKE, SPRITE_CHRIS_BIKE
db PLAYER_SURF, SPRITE_SURF
db PLAYER_SURF_PIKA, SPRITE_SURFING_PIKACHU
db -1 ; end

View File

@ -8755,7 +8755,6 @@ GetTrainerBackpic:
; Load the player character's backpic (6x6) into VRAM starting from vTiles2 tile $31.
; Special exception for Dude.
ld b, BANK(DudeBackpic)
ld hl, DudeBackpic
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
@ -8763,21 +8762,12 @@ GetTrainerBackpic:
; What gender are we?
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .Chris
; It's a girl.
farcall GetKrisBackpic
ret
.Chris:
; It's a boy.
ld b, BANK(ChrisBackpic)
ld hl, ChrisBackpic
.Decompress:
ld e, PLAYERDATA_BACKPIC
call GetPlayerField
.Decompress
ld de, vTiles2 tile $31
ld c, 7 * 7
ld b, BANK(ChrisBackpic)
predef DecompressGet2bpp
ret

View File

@ -4,12 +4,11 @@ LoadFishingGFX:
ld a, $1
ldh [rVBK], a
ld de, FishingGFX
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .got_gender
ld de, KrisFishingGFX
.got_gender
ld e, PLAYERDATA_FISHING_SPRITE
call GetPlayerField
ld d, h
ld e, l
ld hl, vTiles0 tile $02
call .LoadGFX

View File

@ -504,13 +504,8 @@ GetPlayerOrMonPalettePointer:
and a
jp nz, GetMonNormalOrShinyPalettePointer
ld a, [wPlayerGender]
and a
jr z, .male
ld hl, KrisPalette
ret
.male
ld hl, PlayerPalette
ld e, PLAYERDATA_PIC_PAL
call GetPlayerField
ret
GetFrontpicPalettePointer:

View File

@ -288,25 +288,6 @@ EXPORT PICS_FIX
db BANK("Pics 23") ; BANK("Pics 1") + 22
db BANK("Pics 24") ; BANK("Pics 1") + 23
GSIntro_GetMonFrontpic: ; unreferenced
ld a, c
push de
ld hl, PokemonPicPointers
dec a
ld bc, 6
call AddNTimes
ld a, BANK(PokemonPicPointers)
call GetFarByte
call FixPicBank
push af
inc hl
ld a, BANK(PokemonPicPointers)
call GetFarWord
pop af
pop de
call FarDecompress
ret
GetTrainerPic:
ld a, [wTrainerClass]
and a

View File

@ -58,7 +58,7 @@ ShowPlayerNamingChoices:
call CloseWindow
ret
INCLUDE "data/player_names.asm"
INCLUDE "data/players/names.asm"
GetPlayerIcon:
ld de, ChrisSpriteGFX
@ -100,16 +100,11 @@ INCBIN "gfx/trainer_card/trainer_card.2bpp"
GetPlayerBackpic:
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, GetChrisBackpic
call GetKrisBackpic
ret
GetChrisBackpic:
ld hl, ChrisBackpic
ld b, BANK(ChrisBackpic)
ld e, PLAYERDATA_BACKPIC
call GetPlayerField
ld de, vTiles2 tile $31
ld c, 7 * 7
ld b, BANK(ChrisBackpic)
predef DecompressGet2bpp
ret
@ -177,20 +172,3 @@ DrawIntroPlayerPic:
lb bc, 7, 7
predef PlaceGraphic
ret
ChrisPic:
INCBIN "gfx/player/chris.2bpp"
KrisPic:
INCBIN "gfx/player/kris.2bpp"
GetKrisBackpic:
; Kris's backpic is uncompressed.
ld de, KrisBackpic
ld hl, vTiles2 tile $31
lb bc, BANK(KrisBackpic), 7 * 7 ; dimensions
call Get2bpp
ret
KrisBackpic:
INCBIN "gfx/player/kris_back.2bpp"

View File

@ -52,15 +52,11 @@ RefreshSprites::
call LoadAndSortSprites
ret
GetPlayerSprite:
; Get Chris or Kris's sprite.
ld hl, ChrisStateSprites
DeterminePlayerSprite:
; Return player's sprite in c and a.
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .go
ld hl, KrisStateSprites
.go
ld e, PLAYERDATA_STATE_SPRITES
call GetPlayerField
ld a, [wPlayerState]
ld c, a
.loop
@ -75,12 +71,16 @@ GetPlayerSprite:
xor a ; ld a, PLAYER_NORMAL
ld [wPlayerState], a
ld a, SPRITE_CHRIS
jr .finish
ret
.good
ld a, [hl]
ld c, a
ret
.finish
GetPlayerSprite:
; Get player's sprite in a.
call DeterminePlayerSprite
ld [wUsedSprites + 0], a
ld [wPlayerSprite], a
ld [wPlayerObjectSprite], a

View File

@ -944,33 +944,19 @@ MockPlayerObject::
ld bc, OBJECT_EVENT_SIZE + 1
call CopyBytes
; adjust sprite id and palette number
ld hl, .PlayerObjectFields
.loop
; adjust palette number
ld a, [wPlayerGender]
cp [hl]
inc hl
jr nz, .next1
ld a, [wPlayerState]
cp [hl]
inc hl
jr nz, .next2
; found a match
ld a, [hli] ; sprite
ld [wMapObject{d:LAST_OBJECT}Sprite], a
ld a, [hl] ; palette | objecttype
ld e, PLAYERDATA_NPC_PAL
call GetPlayerField
swap a
or OBJECTTYPE_SCRIPT
ld [wMapObject{d:LAST_OBJECT}Palette], a ; also wMapObject{d:LAST_OBJECT}Type
jr .copy_player_coords
.next1
inc hl
.next2
inc hl
inc hl
ld a, [hl]
cp -1
jr nz, .loop
.copy_player_coords
; adjust sprite id
farcall DeterminePlayerSprite
ld a, c
ld [wMapObject{d:LAST_OBJECT}Sprite], a
; copy player's coordinates
ld hl, wPlayerMockYCoord
ld de, wMapObject{d:LAST_OBJECT}YCoord
@ -1001,16 +987,6 @@ MockPlayerObject::
db -1 ; MAPOBJECT_OBJECT_STRUCT_ID
object_event 0, 0, SPRITE_CHRIS, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, ObjectEvent, -1
.PlayerObjectFields:
; [wPlayerGender], [wPlayerState], sprite id, palette
db 0, PLAYER_NORMAL, SPRITE_CHRIS, PAL_NPC_RED << 4 | OBJECTTYPE_SCRIPT
db 1 << PLAYERGENDER_FEMALE_F, PLAYER_NORMAL, SPRITE_KRIS, PAL_NPC_BLUE << 4 | OBJECTTYPE_SCRIPT
db 0, PLAYER_SURF, SPRITE_SURF, PAL_NPC_RED << 4 | OBJECTTYPE_SCRIPT
db 1 << PLAYERGENDER_FEMALE_F, PLAYER_SURF, SPRITE_SURF, PAL_NPC_BLUE << 4 | OBJECTTYPE_SCRIPT
db 0, PLAYER_BIKE, SPRITE_CHRIS_BIKE, PAL_NPC_RED << 4 | OBJECTTYPE_SCRIPT
db 1 << PLAYERGENDER_FEMALE_F, PLAYER_BIKE, SPRITE_KRIS_BIKE, PAL_NPC_BLUE << 4 | OBJECTTYPE_SCRIPT
db -1
GetSouthConnectedSpriteCoords:
; ycoord / 2 <= 2
ld a, e

View File

@ -1,19 +1,3 @@
SECTION "Trainer Backpics", ROMX
ChrisBackpic::
INCBIN "gfx/player/chris_back.2bpp.lz"
DudeBackpic::
INCBIN "gfx/battle/dude.2bpp.lz"
SECTION "Shrink Pics", ROMX
Shrink1Pic::
INCBIN "gfx/new_game/shrink1.2bpp.lz"
Shrink2Pic::
INCBIN "gfx/new_game/shrink2.2bpp.lz"
SECTION "Unused Egg Pic", ROMX
UnusedEggPic::

View File

@ -17,6 +17,35 @@ SECTION "Trainer Pic Pointers", ROMX
INCLUDE "data/trainers/pic_pointers.asm"
SECTION "Player Frontpics", ROMX
ChrisPic::
INCBIN "gfx/player/chris.2bpp"
KrisPic::
INCBIN "gfx/player/kris.2bpp"
SECTION "Player Backpics", ROMX
ChrisBackpic::
INCBIN "gfx/player/chris_back.2bpp.lz"
KrisBackpic::
INCBIN "gfx/player/kris_back.2bpp.lz"
DudeBackpic::
INCBIN "gfx/battle/dude.2bpp.lz"
SECTION "Shrink Pics", ROMX
Shrink1Pic::
INCBIN "gfx/new_game/shrink1.2bpp.lz"
Shrink2Pic::
INCBIN "gfx/new_game/shrink2.2bpp.lz"
SECTION "Pics 1", ROMX
HoOhFrontpic: INCBIN "gfx/pokemon/ho_oh/front.animated.2bpp.lz"
@ -709,75 +738,11 @@ UnownIBackpic: INCBIN "gfx/pokemon/unown_i/back.2bpp.lz"
UnownRBackpic: INCBIN "gfx/pokemon/unown_r/back.2bpp.lz"
SECTION "Pics 19", ROMX
; Seems to be an accidental copy of the previous bank
INCBIN "gfx/pokemon/spinarak/back.2bpp.lz"
INCBIN "gfx/pokemon/raikou/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_k/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/houndour/back.2bpp.lz"
INCBIN "gfx/pokemon/poliwag/back.2bpp.lz"
INCBIN "gfx/pokemon/squirtle/back.2bpp.lz"
INCBIN "gfx/pokemon/shuckle/back.2bpp.lz"
INCBIN "gfx/pokemon/dewgong/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_b/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/slowpoke/back.2bpp.lz"
INCBIN "gfx/pokemon/dunsparce/back.2bpp.lz"
INCBIN "gfx/pokemon/donphan/back.2bpp.lz"
INCBIN "gfx/pokemon/wooper/back.2bpp.lz"
INCBIN "gfx/pokemon/tauros/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_x/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/unown_n/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/tangela/back.2bpp.lz"
INCBIN "gfx/pokemon/voltorb/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_j/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/mantine/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_l/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/piloswine/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_m/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/unown_f/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/natu/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_a/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/golem/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_u/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/diglett/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_q/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/unown_p/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/unown_c/back.2bpp.lz"
INCBIN "gfx/pokemon/jynx/back.2bpp.lz"
INCBIN "gfx/pokemon/golbat/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_y/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/unown_g/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_i/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/unown_v/back.2bpp.lz"
INCBIN "gfx/pokemon/forretress/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_s/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_r/front.animated.2bpp.lz"
INCBIN "gfx/pokemon/unown_e/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_j/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_b/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_o/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_z/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_w/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_n/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_a/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_m/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_k/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_t/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_x/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_l/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_u/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_q/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_y/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_p/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_i/back.2bpp.lz"
INCBIN "gfx/pokemon/unown_r/back.2bpp.lz"
; Sections "Pics 20" to "Pics 24" are not used for any graphics,
; Sections "Pics 19" to "Pics 24" are not used for any graphics,
; but entries for their banks exist in FixPicBank (see engine/gfx/load_pics.asm).
SECTION "Pics 19", ROMX
SECTION "Pics 20", ROMX
SECTION "Pics 21", ROMX

View File

@ -58,3 +58,4 @@ INCLUDE "home/print_bcd.asm"
INCLUDE "home/battle.asm"
INCLUDE "home/sprite_anims.asm"
INCLUDE "home/audio.asm"
INCLUDE "home/player.asm"

13
home/player.asm Executable file
View File

@ -0,0 +1,13 @@
; return field e in player a
; for one-byte field: in a
; for two-byte field: in hl
GetPlayerField::
ld hl, Players
ld bc, PLAYERDATA_LENGTH
call AddNTimes
ld d, 0
add hl, de
ld a, BANK(Players)
call GetFarWord
ld a, l
ret

View File

@ -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_constants.asm"
INCLUDE "constants/pokemon_constants.asm"
INCLUDE "constants/pokemon_data_constants.asm"
INCLUDE "constants/printer_constants.asm"

View File

@ -53,7 +53,6 @@ ROMX $09
"bank9"
ROMX $0a
"bankA"
"Trainer Backpics"
ROMX $0b
"bankB"
ROMX $0c
@ -73,7 +72,6 @@ ROMX $12
"Crystal Features 1"
ROMX $13
"bank13"
"Shrink Pics"
"bank13_2"
ROMX $14
"bank14"

View File

@ -24,6 +24,7 @@ INCLUDE "engine/overworld/player_object.asm"
INCLUDE "engine/math/sine.asm"
INCLUDE "engine/predef.asm"
INCLUDE "engine/gfx/color.asm"
INCLUDE "data/players/players.asm"
SECTION "bank3", ROMX