Implement talker events [commit 1] (#30)

This commit is contained in:
xCrystal 2023-11-28 13:59:36 +01:00
parent 93dad5959f
commit 88b6810a18
13 changed files with 134 additions and 29 deletions

View File

@ -89,6 +89,7 @@ DEF RETVAR_EXECUTE EQU 2 << 6
const PLAYEREVENT_WHITEOUT const PLAYEREVENT_WHITEOUT
const PLAYEREVENT_HATCH const PLAYEREVENT_HATCH
const PLAYEREVENT_JOYCHANGEFACING const PLAYEREVENT_JOYCHANGEFACING
const PLAYEREVENT_SEENBYTALKER
DEF NUM_PLAYER_EVENTS EQU const_value DEF NUM_PLAYER_EVENTS EQU const_value
; PlayerMovementPointers indexes (see engine/overworld/events.asm) ; PlayerMovementPointers indexes (see engine/overworld/events.asm)
@ -137,7 +138,7 @@ DEF NUM_BGEVENTS EQU const_value
const OBJECTTYPE_SCRIPT const OBJECTTYPE_SCRIPT
const OBJECTTYPE_ITEMBALL const OBJECTTYPE_ITEMBALL
const OBJECTTYPE_TRAINER const OBJECTTYPE_TRAINER
const OBJECTTYPE_3 const OBJECTTYPE_TALKER
const OBJECTTYPE_4 const OBJECTTYPE_4
const OBJECTTYPE_5 const OBJECTTYPE_5
const OBJECTTYPE_6 const OBJECTTYPE_6
@ -188,6 +189,7 @@ DEF NUM_FLOORS EQU const_value
; Emotes indexes (see data/sprites/emotes.asm) ; Emotes indexes (see data/sprites/emotes.asm)
const_def const_def
const EMOTE_SHOCK const EMOTE_SHOCK
const EMOTE_TALK
const EMOTE_QUESTION const EMOTE_QUESTION
const EMOTE_HAPPY const EMOTE_HAPPY
const EMOTE_SAD const EMOTE_SAD

View File

@ -45,3 +45,13 @@ DEF CONTEXT_USE EQU 1 << CONTEXT_USE_F
const TRAINERTYPE_MOVES const TRAINERTYPE_MOVES
const TRAINERTYPE_ITEM const TRAINERTYPE_ITEM
const TRAINERTYPE_ITEM_MOVES const TRAINERTYPE_ITEM_MOVES
; talker events (from talker macro and high bit of wTempTalkerType)
DEF TALKER_OPTIONAL EQU %0
DEF TALKER_MANDATORY EQU %1
; talker types (from talker macro and low seven bits of wTempTalkerType)
const_def
const TALKERTYPE_TEXT
const TALKERTYPE_MODAL_TEXT
const TALKERTYPE_SCRIPT

View File

@ -9,6 +9,7 @@ Emotes:
; entries correspond to EMOTE_* constants ; entries correspond to EMOTE_* constants
table_width EMOTE_LENGTH, Emotes table_width EMOTE_LENGTH, Emotes
emote ShockEmote, 4, $f8 emote ShockEmote, 4, $f8
emote TalkEmote, 4, $f8
emote QuestionEmote, 4, $f8 emote QuestionEmote, 4, $f8
emote HappyEmote, 4, $f8 emote HappyEmote, 4, $f8
emote SadEmote, 4, $f8 emote SadEmote, 4, $f8

View File

@ -11,7 +11,7 @@ SeenByTrainerScript::
waitsfx ; wait for any pending space-related sfx waitsfx ; wait for any pending space-related sfx
encountermusic encountermusic
showemote EMOTE_SHOCK, LAST_TALKED, 30 showemote EMOTE_SHOCK, LAST_TALKED, 30
callasm TrainerWalkToPlayer callasm TrainerOrTalkerWalkToPlayer
applymovementlasttalked wMovementBuffer applymovementlasttalked wMovementBuffer
writeobjectxy LAST_TALKED writeobjectxy LAST_TALKED
faceobject PLAYER, LAST_TALKED faceobject PLAYER, LAST_TALKED
@ -30,3 +30,12 @@ StartBattleWithMapTrainerScript:
AlreadyBeatenTrainerScript: AlreadyBeatenTrainerScript:
scripttalkafter scripttalkafter
SeenByTalkerScript::
waitsfx ; wait for any pending space-related sfx
showemote EMOTE_TALK, LAST_TALKED, 20
callasm TrainerOrTalkerWalkToPlayer
applymovementlasttalked wMovementBuffer
writeobjectxy LAST_TALKED
faceobject PLAYER, LAST_TALKED
end

View File

@ -285,7 +285,7 @@ PlayerEvents:
call DisableSpaceEffects ; doesn't alter f call DisableSpaceEffects ; doesn't alter f
jr c, .ok jr c, .ok
call CheckTrainerEvent call CheckTrainerOrTalkerEvent
jr c, .ok jr c, .ok
call CheckTileEvent call CheckTileEvent
@ -451,15 +451,20 @@ CheckBoardEvent:
dw UnionSpaceScript ; COLL_UNION_SPACE dw UnionSpaceScript ; COLL_UNION_SPACE
assert_table_length NUM_COLL_SPACES assert_table_length NUM_COLL_SPACES
CheckTrainerEvent: CheckTrainerOrTalkerEvent:
ldh a, [hCurBoardEvent] ldh a, [hCurBoardEvent]
cp BOARDEVENT_VIEW_MAP_MODE cp BOARDEVENT_VIEW_MAP_MODE
ret z ret z
call CheckTrainerBattle call CheckTrainerBattleOrTalkerPrompt
jr nc, .nope jr nc, .nope
ld a, [wTrainerOrTalkerIsTalker]
and a ; cp FALSE
ld a, PLAYEREVENT_SEENBYTRAINER ld a, PLAYEREVENT_SEENBYTRAINER
jr z, .done
ld a, PLAYEREVENT_SEENBYTALKER
.done
scf scf
ret ret
@ -748,7 +753,7 @@ ObjectEventTypeArray:
dbw OBJECTTYPE_ITEMBALL, .itemball dbw OBJECTTYPE_ITEMBALL, .itemball
dbw OBJECTTYPE_TRAINER, .trainer dbw OBJECTTYPE_TRAINER, .trainer
; the remaining four are dummy events ; the remaining four are dummy events
dbw OBJECTTYPE_3, .three dbw OBJECTTYPE_TALKER, .three
dbw OBJECTTYPE_4, .four dbw OBJECTTYPE_4, .four
dbw OBJECTTYPE_5, .five dbw OBJECTTYPE_5, .five
dbw OBJECTTYPE_6, .six dbw OBJECTTYPE_6, .six
@ -1158,6 +1163,7 @@ PlayerEventScriptPointers:
dba OverworldWhiteoutScript ; PLAYEREVENT_WHITEOUT dba OverworldWhiteoutScript ; PLAYEREVENT_WHITEOUT
dba HatchEggScript ; PLAYEREVENT_HATCH dba HatchEggScript ; PLAYEREVENT_HATCH
dba ChangeDirectionScript ; PLAYEREVENT_JOYCHANGEFACING dba ChangeDirectionScript ; PLAYEREVENT_JOYCHANGEFACING
dba SeenByTalkerScript ; PLAYEREVENT_SEENBYTALKER
dba InvalidEventScript ; (NUM_PLAYER_EVENTS) dba InvalidEventScript ; (NUM_PLAYER_EVENTS)
assert_table_length NUM_PLAYER_EVENTS + 1 assert_table_length NUM_PLAYER_EVENTS + 1

View File

@ -514,12 +514,12 @@ CopyTempObjectToObjectStruct:
ld [hl], a ld [hl], a
ret ret
TrainerWalkToPlayer: TrainerOrTalkerWalkToPlayer:
ldh a, [hLastTalked] ldh a, [hLastTalked]
call InitMovementBuffer call InitMovementBuffer
ld a, movement_step_sleep ld a, movement_step_sleep
call AppendToMovementBuffer call AppendToMovementBuffer
ld a, [wSeenTrainerDistance] ld a, [wSeenTrainerOrTalkerDistance]
dec a dec a
jr z, .TerminateStep jr z, .TerminateStep
ldh a, [hLastTalked] ldh a, [hLastTalked]

View File

@ -671,7 +671,7 @@ Script_trainertext:
ld a, [hli] ld a, [hli]
ld h, [hl] ld h, [hl]
ld l, a ld l, a
ld a, [wSeenTrainerBank] ld a, [wSeenTrainerOrTalkerBank]
ld b, a ld b, a
call MapTextbox call MapTextbox
ret ret
@ -681,7 +681,7 @@ Script_scripttalkafter:
ld a, [hli] ld a, [hli]
ld h, [hl] ld h, [hl]
ld l, a ld l, a
ld a, [wSeenTrainerBank] ld a, [wSeenTrainerOrTalkerBank]
ld b, a ld b, a
jp ScriptJump jp ScriptJump

View File

@ -1,4 +1,5 @@
ShockEmote: INCBIN "gfx/emotes/shock.2bpp" ShockEmote: INCBIN "gfx/emotes/shock.2bpp"
TalkEmote: INCBIN "gfx/emotes/talk.2bpp"
QuestionEmote: INCBIN "gfx/emotes/question.2bpp" QuestionEmote: INCBIN "gfx/emotes/question.2bpp"
HappyEmote: INCBIN "gfx/emotes/happy.2bpp" HappyEmote: INCBIN "gfx/emotes/happy.2bpp"
SadEmote: INCBIN "gfx/emotes/sad.2bpp" SadEmote: INCBIN "gfx/emotes/sad.2bpp"

BIN
gfx/emotes/talk.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

View File

@ -1,17 +1,17 @@
CheckTrainerBattle:: CheckTrainerBattleOrTalkerPrompt::
ldh a, [hROMBank] ldh a, [hROMBank]
push af push af
call SwitchToMapScriptsBank call SwitchToMapScriptsBank
call _CheckTrainerBattle call _CheckTrainerBattleOrTalkerPrompt
pop bc pop bc
ld a, b ld a, b
rst Bankswitch rst Bankswitch
ret ret
_CheckTrainerBattle:: _CheckTrainerBattleOrTalkerPrompt::
; Check if any trainer on the map sees the player and wants to battle. ; Check if any trainer or talker on the map sees the player and wants to battle or talk.
; Skip the player object. ; Skip the player object.
ld a, 1 ld a, 1
@ -30,14 +30,25 @@ _CheckTrainerBattle::
and a and a
jr z, .next jr z, .next
; Is a trainer ; Is a trainer or a talker
ld hl, MAPOBJECT_TYPE ld hl, MAPOBJECT_TYPE
add hl, de add hl, de
ld a, [hl] ld a, [hl]
and MAPOBJECT_TYPE_MASK and MAPOBJECT_TYPE_MASK
cp OBJECTTYPE_TRAINER cp OBJECTTYPE_TRAINER
jr z, .is_trainer
cp OBJECTTYPE_TALKER
jr nz, .next jr nz, .next
; also set wTrainerOrTalkerIsTalker accordingly (flag is only relevant if there's actually an event)
;.is_talker
ld a, TRUE
ld [wTrainerOrTalkerIsTalker], a
jr .go
.is_trainer
xor a ; FALSE
ld [wTrainerOrTalkerIsTalker], a
.go
; Is visible on the map ; Is visible on the map
ld hl, MAPOBJECT_OBJECT_STRUCT_ID ld hl, MAPOBJECT_OBJECT_STRUCT_ID
add hl, de add hl, de
@ -57,7 +68,38 @@ _CheckTrainerBattle::
cp b cp b
jr c, .next jr c, .next
; And hasn't already been beaten ld a, [wTrainerOrTalkerIsTalker]
and a ; TRUE?
jr z, .trainer_battle
;.talker_prompt
pop de
pop af
ldh [hLastTalked], a
ld a, b
ld [wSeenTrainerOrTalkerDistance], a
ld a, c
ld [wSeenTrainerOrTalkerDirection], a
call GetMapScriptsBank
ld [wSeenTrainerOrTalkerBank], a
ldh a, [hLastTalked]
call GetMapObject
ld hl, MAPOBJECT_SCRIPT_POINTER
add hl, bc
ld a, [wSeenTrainerOrTalkerBank]
call GetFarWord
ld de, wTempTalker
ld bc, wTempTalkerEnd - wTempTalker
ld a, [wSeenTrainerOrTalkerBank]
call FarCopyBytes
scf
ret
.trainer_battle
; And hasn't already been beaten if it's a trainer
push bc push bc
push de push de
ld hl, MAPOBJECT_SCRIPT_POINTER ld hl, MAPOBJECT_SCRIPT_POINTER
@ -86,7 +128,7 @@ _CheckTrainerBattle::
pop af pop af
inc a inc a
cp NUM_OBJECTS cp NUM_OBJECTS
jr nz, .loop jp nz, .loop
xor a xor a
ret ret
@ -95,31 +137,31 @@ _CheckTrainerBattle::
pop af pop af
ldh [hLastTalked], a ldh [hLastTalked], a
ld a, b ld a, b
ld [wSeenTrainerDistance], a ld [wSeenTrainerOrTalkerDistance], a
ld a, c ld a, c
ld [wSeenTrainerDirection], a ld [wSeenTrainerOrTalkerDirection], a
jr LoadTrainer_continue jr LoadTrainer_continue
TalkToTrainer:: TalkToTrainer::
ld a, 1 ld a, 1
ld [wSeenTrainerDistance], a ld [wSeenTrainerOrTalkerDistance], a
ld a, -1 ld a, -1
ld [wSeenTrainerDirection], a ld [wSeenTrainerOrTalkerDirection], a
LoadTrainer_continue:: LoadTrainer_continue::
call GetMapScriptsBank call GetMapScriptsBank
ld [wSeenTrainerBank], a ld [wSeenTrainerOrTalkerBank], a
ldh a, [hLastTalked] ldh a, [hLastTalked]
call GetMapObject call GetMapObject
ld hl, MAPOBJECT_SCRIPT_POINTER ld hl, MAPOBJECT_SCRIPT_POINTER
add hl, bc add hl, bc
ld a, [wSeenTrainerBank] ld a, [wSeenTrainerOrTalkerBank]
call GetFarWord call GetFarWord
ld de, wTempTrainer ld de, wTempTrainer
ld bc, wTempTrainerEnd - wTempTrainer ld bc, wTempTrainerEnd - wTempTrainer
ld a, [wSeenTrainerBank] ld a, [wSeenTrainerOrTalkerBank]
call FarCopyBytes call FarCopyBytes
xor a xor a
ld [wRunningTrainerBattleScript], a ld [wRunningTrainerBattleScript], a

View File

@ -232,7 +232,7 @@ ENDM
MACRO trainer MACRO trainer
;\1: trainer group ;\1: trainer group
;\2: trainer id ;\2: trainer id
;\3: flag: an EVENT_BEAT_* constant ;\3: flag: an EVENT_* constant
;\4: seen text ;\4: seen text
;\5: win text ;\5: win text
;\6: loss text ;\6: loss text
@ -242,6 +242,16 @@ MACRO trainer
dw \4, \5, \6, \7 dw \4, \5, \6, \7
ENDM ENDM
MACRO talker
;\1: flag: an EVENT_* constant
;\2: OPTIONAL or MANDATORY
;\3: talker type: TEXT, MODAL_TEXT, SCRIPT
;\4: pointer to talker data
dw \1
db \2 | \3
dw \4
ENDM
MACRO itemball MACRO itemball
;\1: item: from constants/item_constants.asm ;\1: item: from constants/item_constants.asm
;\2: quantity: default 1 ;\2: quantity: default 1

View File

@ -28,6 +28,16 @@ DebugLevel5_Map1_MapEvents:
.DebugLevel5_Map1TrainerYoungsterMikey2: .DebugLevel5_Map1TrainerYoungsterMikey2:
trainer YOUNGSTER, MIKEY, EVENT_LEVEL_SCOPED_2, .YoungsterMikeySeenText, .YoungsterMikeyBeatenText, 0, .Script trainer YOUNGSTER, MIKEY, EVENT_LEVEL_SCOPED_2, .YoungsterMikeySeenText, .YoungsterMikeyBeatenText, 0, .Script
; talker EVENT_STEP_SCOPED_*, OPTIONAL/MANDATORY | TEXT/MODAL_TEXT/SCRIPT, .Data
; .Data: ; Text
; db .Text
; .Data: ; Modal text
; dw EVENT_*, .Text1
; dw EVENT_*, .Text2
; dw DEFAULT_TEXT, .DefaultText
; .Data: ; Script
; end
.Script: .Script:
endifjustbattled endifjustbattled
opentext opentext

View File

@ -1550,10 +1550,15 @@ SECTION UNION "Miscellaneous WRAM 1", WRAMX
ds 60 ds 60
UNION UNION
; trainer and talker data
wTrainerOrTalkerIsTalker:: db ; TRUE means talker; FALSE means trainer
wSeenTrainerOrTalkerBank:: db
wSeenTrainerOrTalkerDistance:: db
wSeenTrainerOrTalkerDirection:: db
NEXTU
; trainer data ; trainer data
wSeenTrainerBank:: db ds 4
wSeenTrainerDistance:: db
wSeenTrainerDirection:: db
wTempTrainer:: wTempTrainer::
wTempTrainerEventFlag:: dw wTempTrainerEventFlag:: dw
wTempTrainerClass:: db wTempTrainerClass:: db
@ -1565,6 +1570,15 @@ wScriptAfterPointer:: dw
wRunningTrainerBattleScript:: db wRunningTrainerBattleScript:: db
wTempTrainerEnd:: wTempTrainerEnd::
NEXTU
; talker data
ds 4
wTempTalker::
wTempTalkerEventFlag:: dw
wTempTalkerType:: db
wTempTalkerDataPointer:: dw
wTempTalkerEnd::
NEXTU NEXTU
; menu items list ; menu items list
wMenuItemsList:: ds 16 wMenuItemsList:: ds 16
@ -1642,7 +1656,7 @@ wFacingDirection:: db
wWalkingX:: db wWalkingX:: db
wWalkingY:: db wWalkingY:: db
wWalkingTile:: db wWalkingTile:: db
ds 6 ds 7
wPlayerTurningDirection:: db wPlayerTurningDirection:: db
NEXTU NEXTU