mirror of
https://github.com/pret/pokered.git
synced 2026-08-27 03:45:18 -05:00
Add constants for trainer macro struct fields (#598)
--------- Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>
This commit is contained in:
10
constants/trainer_data_constants.asm
Normal file
10
constants/trainer_data_constants.asm
Normal file
@@ -0,0 +1,10 @@
|
||||
; trainer data structure fields (see macros/scripts/maps.asm)
|
||||
rsreset
|
||||
DEF TRAINER_EVENT_FLAG_BIT rb ; 0
|
||||
DEF TRAINER_VIEW_RANGE rb ; 1
|
||||
DEF TRAINER_EVENT_FLAG_POINTER rw ; 2
|
||||
DEF TRAINER_BEFORE_BATTLE_TEXT rw ; 4
|
||||
DEF TRAINER_AFTER_BATTLE_TEXT rw ; 6
|
||||
DEF TRAINER_WON_BATTLE_TEXT rw ; 8
|
||||
DEF TRAINER_LOST_BATTLE_TEXT rw ; 10
|
||||
DEF TRAINER_STRUCT_SIZE EQU _RS ; 12
|
||||
@@ -1,4 +1,3 @@
|
||||
; stores hl in [wTrainerHeaderPtr]
|
||||
StoreTrainerHeaderPointer::
|
||||
ld a, h
|
||||
ld [wTrainerHeaderPtr], a
|
||||
@@ -19,7 +18,7 @@ ExecuteCurMapScriptInTable::
|
||||
ld hl, wStatusFlags7
|
||||
bit BIT_USE_CUR_MAP_SCRIPT, [hl]
|
||||
res BIT_USE_CUR_MAP_SCRIPT, [hl]
|
||||
jr z, .useProvidedIndex ; test if map script index was overridden manually
|
||||
jr z, .useProvidedIndex
|
||||
ld a, [wCurMapScript]
|
||||
.useProvidedIndex
|
||||
pop hl
|
||||
@@ -32,23 +31,18 @@ LoadGymLeaderAndCityName::
|
||||
push de
|
||||
ld de, wGymCityName
|
||||
ld bc, GYM_CITY_LENGTH
|
||||
call CopyData ; load city name
|
||||
call CopyData
|
||||
pop hl
|
||||
ld de, wGymLeaderName
|
||||
ld bc, NAME_LENGTH
|
||||
jp CopyData ; load gym leader name
|
||||
jp CopyData
|
||||
|
||||
; reads specific information from trainer header (pointed to at wTrainerHeaderPtr)
|
||||
; a: offset in header data
|
||||
; 0 -> flag's bit (into wTrainerHeaderFlagBit)
|
||||
; 2 -> flag's byte ptr (into hl)
|
||||
; 4 -> before battle text (into hl)
|
||||
; 6 -> after battle text (into hl)
|
||||
; 8 -> end battle text (into hl)
|
||||
ReadTrainerHeaderInfo::
|
||||
push de
|
||||
push af
|
||||
ld d, $0
|
||||
ld d, 0
|
||||
ld e, a
|
||||
ld hl, wTrainerHeaderPtr
|
||||
ld a, [hli]
|
||||
@@ -59,20 +53,20 @@ ReadTrainerHeaderInfo::
|
||||
and a
|
||||
jr nz, .nonZeroOffset
|
||||
ld a, [hl]
|
||||
ld [wTrainerHeaderFlagBit], a ; store flag's bit
|
||||
ld [wTrainerHeaderFlagBit], a
|
||||
jr .done
|
||||
.nonZeroOffset
|
||||
cp $2
|
||||
jr z, .readPointer ; read flag's byte ptr
|
||||
cp $4
|
||||
jr z, .readPointer ; read before battle text
|
||||
cp $6
|
||||
jr z, .readPointer ; read after battle text
|
||||
cp $8
|
||||
jr z, .readPointer ; read end battle text
|
||||
cp $a
|
||||
cp TRAINER_EVENT_FLAG_POINTER
|
||||
jr z, .readPointer
|
||||
cp TRAINER_BEFORE_BATTLE_TEXT
|
||||
jr z, .readPointer
|
||||
cp TRAINER_AFTER_BATTLE_TEXT
|
||||
jr z, .readPointer
|
||||
cp TRAINER_WON_BATTLE_TEXT
|
||||
jr z, .readPointer
|
||||
cp TRAINER_LOST_BATTLE_TEXT
|
||||
jr nz, .done
|
||||
ld a, [hli] ; read end battle text (2) but override the result afterwards (XXX why, bug?)
|
||||
ld a, [hli] ; TRAINER_LOST_BATTLE_TEXT pointer is overwritten afterwards (XXX why, bug?)
|
||||
ld d, [hl]
|
||||
ld e, a
|
||||
jr .done
|
||||
@@ -89,40 +83,40 @@ TrainerFlagAction::
|
||||
|
||||
TalkToTrainer::
|
||||
call StoreTrainerHeaderPointer
|
||||
xor a
|
||||
call ReadTrainerHeaderInfo ; read flag's bit
|
||||
ld a, $2
|
||||
call ReadTrainerHeaderInfo ; read flag's byte ptr
|
||||
xor a ; TRAINER_EVENT_FLAG_BIT
|
||||
call ReadTrainerHeaderInfo
|
||||
ld a, TRAINER_EVENT_FLAG_POINTER
|
||||
call ReadTrainerHeaderInfo
|
||||
ld a, [wTrainerHeaderFlagBit]
|
||||
ld c, a
|
||||
ld b, FLAG_TEST
|
||||
call TrainerFlagAction ; read trainer's flag
|
||||
call TrainerFlagAction
|
||||
ld a, c
|
||||
and a
|
||||
jr z, .trainerNotYetFought ; test trainer's flag
|
||||
ld a, $6
|
||||
call ReadTrainerHeaderInfo ; print after battle text
|
||||
jr z, .trainerNotYetFought
|
||||
ld a, TRAINER_AFTER_BATTLE_TEXT
|
||||
call ReadTrainerHeaderInfo
|
||||
jp PrintText
|
||||
.trainerNotYetFought
|
||||
ld a, $4
|
||||
call ReadTrainerHeaderInfo ; print before battle text
|
||||
ld a, TRAINER_BEFORE_BATTLE_TEXT
|
||||
call ReadTrainerHeaderInfo
|
||||
call PrintText
|
||||
ld a, $a
|
||||
call ReadTrainerHeaderInfo ; (?) does nothing apparently (maybe bug in ReadTrainerHeaderInfo)
|
||||
ld a, TRAINER_LOST_BATTLE_TEXT
|
||||
call ReadTrainerHeaderInfo
|
||||
push de
|
||||
ld a, $8
|
||||
call ReadTrainerHeaderInfo ; read end battle text
|
||||
ld a, TRAINER_WON_BATTLE_TEXT
|
||||
call ReadTrainerHeaderInfo
|
||||
pop de
|
||||
call SaveEndBattleTextPointers
|
||||
ld hl, wStatusFlags7
|
||||
set BIT_USE_CUR_MAP_SCRIPT, [hl] ; activate map script index override (index is set below)
|
||||
ld hl, wMiscFlags
|
||||
bit BIT_SEEN_BY_TRAINER, [hl] ; test if player is already engaging the trainer (because the trainer saw the player)
|
||||
bit BIT_SEEN_BY_TRAINER, [hl]
|
||||
ret nz
|
||||
; if the player talked to the trainer of his own volition
|
||||
; if the player talked to the trainer of their own volition
|
||||
call EngageMapTrainer
|
||||
ld hl, wCurMapScript
|
||||
inc [hl] ; increment map script index before StartTrainerBattle increments it again (next script function is usually EndTrainerBattle)
|
||||
inc [hl] ; increment map script index before StartTrainerBattle increments it again (next script function is usually EndTrainerBattle)
|
||||
jp StartTrainerBattle
|
||||
|
||||
; checks if any trainers are seeing the player and wanting to fight
|
||||
@@ -189,26 +183,26 @@ EndTrainerBattle::
|
||||
ld hl, wStatusFlags3
|
||||
res BIT_PRINT_END_BATTLE_TEXT, [hl]
|
||||
ld hl, wMiscFlags
|
||||
res BIT_SEEN_BY_TRAINER, [hl] ; player is no longer engaged by any trainer
|
||||
res BIT_SEEN_BY_TRAINER, [hl]
|
||||
ld a, [wIsInBattle]
|
||||
cp $ff
|
||||
jp z, ResetButtonPressedAndMapScript
|
||||
ld a, $2
|
||||
ld a, TRAINER_EVENT_FLAG_POINTER
|
||||
call ReadTrainerHeaderInfo
|
||||
ld a, [wTrainerHeaderFlagBit]
|
||||
ld c, a
|
||||
ld b, FLAG_SET
|
||||
call TrainerFlagAction ; flag trainer as fought
|
||||
call TrainerFlagAction ; flag trainer as fought
|
||||
ld a, [wEnemyMonOrTrainerClass]
|
||||
cp OPP_ID_OFFSET
|
||||
jr nc, .skipRemoveSprite ; test if trainer was fought (in that case skip removing the corresponding sprite)
|
||||
jr nc, .skipRemoveSprite
|
||||
ld hl, wToggleableObjectList
|
||||
ld de, $2
|
||||
ld a, [wSpriteIndex]
|
||||
call IsInArray ; search for sprite ID
|
||||
inc hl
|
||||
ld a, [hl]
|
||||
ld [wToggleableObjectIndex], a ; load corresponding toggleable object index and remove it
|
||||
ld [wToggleableObjectIndex], a
|
||||
predef HideObject
|
||||
.skipRemoveSprite
|
||||
ld hl, wStatusFlags5
|
||||
@@ -222,14 +216,13 @@ ResetButtonPressedAndMapScript::
|
||||
ldh [hJoyHeld], a
|
||||
ldh [hJoyPressed], a
|
||||
ldh [hJoyReleased], a
|
||||
ld [wCurMapScript], a ; reset battle status
|
||||
ld [wCurMapScript], a
|
||||
ret
|
||||
|
||||
; calls TrainerWalkUpToPlayer
|
||||
TrainerWalkUpToPlayer_Bank0::
|
||||
farjp TrainerWalkUpToPlayer
|
||||
|
||||
; sets opponent type and mon set/lvl based on the engaging trainer data
|
||||
; sets opponent trainer class and party level based on the engaging trainer data
|
||||
InitBattleEnemyParameters::
|
||||
ld a, [wEngagedTrainerClass]
|
||||
ld [wCurOpponent], a
|
||||
@@ -262,33 +255,33 @@ SpritePositionBankswitch::
|
||||
jp Bankswitch ; indirect jump to one of the four functions
|
||||
|
||||
CheckForEngagingTrainers::
|
||||
xor a
|
||||
call ReadTrainerHeaderInfo ; read trainer flag's bit (unused)
|
||||
ld d, h ; store trainer header address in de
|
||||
xor a ; TRAINER_EVENT_FLAG_BIT
|
||||
call ReadTrainerHeaderInfo
|
||||
ld d, h
|
||||
ld e, l
|
||||
.trainerLoop
|
||||
call StoreTrainerHeaderPointer ; set trainer header pointer to current trainer
|
||||
call StoreTrainerHeaderPointer
|
||||
ld a, [de]
|
||||
ld [wSpriteIndex], a ; store trainer flag's bit
|
||||
ld [wSpriteIndex], a
|
||||
ld [wTrainerHeaderFlagBit], a
|
||||
cp -1
|
||||
ret z
|
||||
ld a, $2
|
||||
call ReadTrainerHeaderInfo ; read trainer flag's byte ptr
|
||||
ld a, TRAINER_EVENT_FLAG_POINTER
|
||||
call ReadTrainerHeaderInfo
|
||||
ld b, FLAG_TEST
|
||||
ld a, [wTrainerHeaderFlagBit]
|
||||
ld c, a
|
||||
call TrainerFlagAction ; read trainer flag
|
||||
call TrainerFlagAction
|
||||
ld a, c
|
||||
and a ; has the trainer already been defeated?
|
||||
jr nz, .continue
|
||||
push hl
|
||||
push de
|
||||
push hl
|
||||
xor a
|
||||
call ReadTrainerHeaderInfo ; get trainer header pointer
|
||||
xor a ; TRAINER_EVENT_FLAG_BIT
|
||||
call ReadTrainerHeaderInfo
|
||||
inc hl
|
||||
ld a, [hl] ; read trainer engage distance
|
||||
ld a, [hl]
|
||||
pop hl
|
||||
ld [wTrainerEngageDistance], a
|
||||
ld a, [wSpriteIndex]
|
||||
@@ -301,7 +294,7 @@ CheckForEngagingTrainers::
|
||||
and a
|
||||
ret nz ; break if the trainer is engaging
|
||||
.continue
|
||||
ld hl, $c
|
||||
ld hl, TRAINER_STRUCT_SIZE
|
||||
add hl, de
|
||||
ld d, h
|
||||
ld e, l
|
||||
@@ -326,15 +319,15 @@ SaveEndBattleTextPointers::
|
||||
; [wSpriteIndex]: sprite ID of trainer who is engaged
|
||||
EngageMapTrainer::
|
||||
ld hl, wMapSpriteExtraData
|
||||
ld d, $0
|
||||
ld d, 0
|
||||
ld a, [wSpriteIndex]
|
||||
dec a
|
||||
add a
|
||||
ld e, a
|
||||
add hl, de ; seek to engaged trainer data
|
||||
ld a, [hli] ; load trainer class
|
||||
add hl, de
|
||||
ld a, [hli]
|
||||
ld [wEngagedTrainerClass], a
|
||||
ld a, [hl] ; load trainer mon set
|
||||
ld a, [hl]
|
||||
ld [wEngagedTrainerSet], a
|
||||
jp PlayTrainerMusic
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ INCLUDE "constants/pokedex_constants.asm"
|
||||
INCLUDE "constants/pokemon_data_constants.asm"
|
||||
INCLUDE "constants/player_constants.asm"
|
||||
INCLUDE "constants/trainer_constants.asm"
|
||||
INCLUDE "constants/trainer_data_constants.asm"
|
||||
INCLUDE "constants/icon_constants.asm"
|
||||
INCLUDE "constants/sprite_constants.asm"
|
||||
INCLUDE "constants/sprite_data_constants.asm"
|
||||
|
||||
Reference in New Issue
Block a user