Implement talker events [commit 3] (#30)

This commit is contained in:
xCrystal 2023-11-28 21:36:51 +01:00
parent 933fca3b4b
commit 6f4fcf580a
10 changed files with 56 additions and 32 deletions

View File

@ -36,11 +36,12 @@ DEF STRING_BUFFER_LENGTH EQU 19
const PHONE_CONTACTS_FULL ; 1
const PHONE_CONTACT_REFUSED ; 2
; trainertext arguments
; trainerortalkertext arguments
const_def
const TRAINERTEXT_SEEN
const TRAINERTEXT_WIN
const TRAINERTEXT_LOSS
const TRAINERORTALKERTEXT_TRAINER_SEEN
const TRAINERORTALKERTEXT_TRAINER_WIN
const TRAINERORTALKERTEXT_TRAINER_LOSS
DEF TRAINERORTALKERTEXT_TALKER EQU -1
; readvar/writevar/loadvar arguments
; _GetVarAction.VarActionTable indexes (see engine/overworld/variables.asm)

View File

@ -48,12 +48,11 @@ DEF CONTEXT_USE EQU 1 << CONTEXT_USE_F
; talker events (from talker macro and high bit of wTempTalkerType)
DEF TALKEREVENTTYPE_MASK EQU %10000000
DEF TALKEREVENTTYPE_OPTIONAL EQU %0
DEF TALKEREVENTTYPE_MANDATORY EQU %1
DEF TALKEREVENTTYPE_OPTIONAL EQU %00000000 ; masked
DEF TALKEREVENTTYPE_MANDATORY EQU %10000000 ; masked
; talker types (from talker macro and low seven bits of wTempTalkerType)
DEF TALKERTYPE_MASK EQU %01111111
const_def
const TALKERTYPE_TEXT
const TALKERTYPE_MODAL_TEXT
const TALKERTYPE_SCRIPT

View File

@ -339,7 +339,7 @@ If <code><i>item_id</i></code> = `USE_SCRIPT_VAR`, then it uses `[hScriptVar]` i
## `$61`: <code>catchtutorial <i>byte</i></code>
## `$62`: <code>trainertext <i>text_id</i></code>
## `$62`: <code>trainerortalkertext <i>text_id</i></code>
## `$63`: <code>trainerortalkerflagaction <i>action</i></code>

View File

@ -28,8 +28,8 @@ BoardMenuScript::
ld hl, wCurTurn
inc [hl]
; reset turn-scoped event flags
ld hl, wEventFlags + EVENT_LEVEL_SCOPED_FLAGS_START / 8
ld c, (EVENT_LEVEL_SCOPED_FLAGS_END / 8) - (EVENT_LEVEL_SCOPED_FLAGS_START / 8)
ld hl, wEventFlags + EVENT_TURN_SCOPED_FLAGS_START / 8
ld c, (EVENT_TURN_SCOPED_FLAGS_END / 8) - (EVENT_TURN_SCOPED_FLAGS_START / 8)
xor a
.loop
ld [hli], a

View File

@ -19,7 +19,7 @@ SeenByTrainerScript::
StartBattleWithMapTrainerScript:
opentext
trainertext TRAINERTEXT_SEEN
trainerortalkertext TRAINERORTALKERTEXT_TRAINER_SEEN
waitbutton
closetext
loadtemptrainer
@ -33,6 +33,7 @@ AlreadyBeatenTrainerScript:
SeenByTalkerScript::
waitsfx ; wait for any pending space-related sfx
; playsound SFX_
showemote EMOTE_TALK, LAST_TALKED, 20
callasm .TalkOrSkipTalker
iffalse .skipped
@ -40,15 +41,31 @@ SeenByTalkerScript::
applymovementlasttalked wMovementBuffer
writeobjectxy LAST_TALKED
faceobject PLAYER, LAST_TALKED
callasm .GetTalkerType
ifequal TALKERTYPE_TEXT, .Text
ifequal TALKERTYPE_SCRIPT, .Script
.skipped
trainerortalkerflagaction SET_FLAG
end
.Text
opentext
trainerortalkertext TRAINERORTALKERTEXT_TALKER
waitbutton
closetext
trainerortalkerflagaction SET_FLAG
end
.Script
trainerortalkerflagaction SET_FLAG
end
.TalkOrSkipTalker:
ld a, [wTempTalkerType]
and %1
and TALKEREVENTTYPE_MASK
cp TALKEREVENTTYPE_MANDATORY
jr z, .skip
call WaitButton
call JoyWaitAorB
call PlayClickSFX
call WaitSFX
ldh a, [hJoyPressed]
@ -61,3 +78,9 @@ SeenByTalkerScript::
.done
ld [hScriptVar], a
ret
.GetTalkerType:
ld a, [wTempTalkerType]
and TALKERTYPE_MASK
ld [hScriptVar], a
ret

View File

@ -162,7 +162,7 @@ ScriptCommandTable:
dw Script_startbattle ; 5f
dw Script_reloadmapafterbattle ; 60
dw Script_catchtutorial ; 61
dw Script_trainertext ; 62
dw Script_trainerortalkertext ; 62
dw Script_trainerortalkerflagaction ; 63
dw Script_winlosstext ; 64
dw Script_scripttalkafter ; 65
@ -661,13 +661,17 @@ Script_swarm:
farcall StoreSwarmMapIndices
ret
Script_trainertext:
Script_trainerortalkertext:
call GetScriptByte
cp TRAINERORTALKERTEXT_TALKER
ld hl, wTempTalkerTextOrScriptPointer
jr z, .next
ld c, a
ld b, 0
ld hl, wSeenTextPointer
add hl, bc
add hl, bc
.next
ld a, [hli]
ld h, [hl]
ld l, a

View File

@ -626,9 +626,9 @@ MACRO catchtutorial
db \1 ; byte
ENDM
const trainertext_command ; $62
MACRO trainertext
db trainertext_command
const trainerortalkertext_command ; $62
MACRO trainerortalkertext
db trainerortalkertext_command
db \1 ; text_id
ENDM

View File

@ -245,10 +245,10 @@ ENDM
MACRO talker
;\1: flag: an EVENT_* constant
;\2: OPTIONAL or MANDATORY
;\3: talker type: TEXT, MODAL_TEXT, SCRIPT
;\4: pointer to talker data
;\3: talker type: TEXT, SCRIPT
;\4: pointer to talker text or script
dw \1
db \2 | \3
db TALKEREVENTTYPE_\2 | TALKERTYPE_\3
dw \4
ENDM

View File

@ -20,7 +20,7 @@ DebugLevel5_Map1_MapEvents:
def_object_events
object_event 10, 2, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 2, .DebugLevel5_Map1TrainerYoungsterMikey1, -1
object_event 9, 2, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 2, .DebugLevel5_Map1TrainerYoungsterMikey2, -1
object_event 9, 2, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TALKER, 2, .DebugLevel5_Map1Talker1, -1
.DebugLevel5_Map1TrainerYoungsterMikey1:
trainer YOUNGSTER, MIKEY, EVENT_LEVEL_SCOPED_1, .YoungsterMikeySeenText, .YoungsterMikeyBeatenText, 0, .Script
@ -28,15 +28,12 @@ DebugLevel5_Map1_MapEvents:
.DebugLevel5_Map1TrainerYoungsterMikey2:
trainer YOUNGSTER, MIKEY, EVENT_LEVEL_SCOPED_2, .YoungsterMikeySeenText, .YoungsterMikeyBeatenText, 0, .Script
; talker EVENT_TURN_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
.DebugLevel5_Map1Talker1:
talker EVENT_TURN_SCOPED_1, OPTIONAL, TEXT, .Text
.Text:
text "I'm a talker!"
done
.Script:
endifjustbattled

View File

@ -1576,7 +1576,7 @@ NEXTU
wTempTalker::
wTempTalkerEventFlag:: dw
wTempTalkerType:: db
wTempTalkerDataPointer:: dw
wTempTalkerTextOrScriptPointer:: dw
wTempTalkerEnd::
NEXTU