Create level scoped event flags for trainers and talkers, and integrate trainer battles in the board engine (#30)

This commit is contained in:
xCrystal 2023-11-28 09:44:10 +01:00
parent 2596e3c93e
commit 34d9877a1f
7 changed files with 106 additions and 8 deletions

View File

@ -1,7 +1,8 @@
; wEventFlags bit flags
const_def
; The first eight flags are reset upon reloading the map
;; The first eight flags are reset upon reloading the map
const EVENT_TEMPORARY_UNTIL_MAP_RELOAD_1
const EVENT_TEMPORARY_UNTIL_MAP_RELOAD_2
const EVENT_TEMPORARY_UNTIL_MAP_RELOAD_3
@ -11,6 +12,43 @@
const EVENT_TEMPORARY_UNTIL_MAP_RELOAD_7
const EVENT_TEMPORARY_UNTIL_MAP_RELOAD_8
if (const_value % 8) != 0
const_value = const_value + 8 - (const_value % 8)
endc
EVENT_TEMPORARY_UNTIL_MAP_RELOAD_FLAGS_END EQU const_value
;; The next flags are reset upon entering a new level (for e.g. trainers)
EVENT_LEVEL_SCOPED_FLAGS_START EQU EVENT_TEMPORARY_UNTIL_MAP_RELOAD_FLAGS_END
const EVENT_LEVEL_SCOPED_1
const EVENT_LEVEL_SCOPED_2
const EVENT_LEVEL_SCOPED_3
const EVENT_LEVEL_SCOPED_4
const EVENT_LEVEL_SCOPED_5
const EVENT_LEVEL_SCOPED_6
const EVENT_LEVEL_SCOPED_7
const EVENT_LEVEL_SCOPED_8
const EVENT_LEVEL_SCOPED_9
const EVENT_LEVEL_SCOPED_10
const EVENT_LEVEL_SCOPED_11
const EVENT_LEVEL_SCOPED_12
const EVENT_LEVEL_SCOPED_13
const EVENT_LEVEL_SCOPED_14
const EVENT_LEVEL_SCOPED_15
const EVENT_LEVEL_SCOPED_16
const EVENT_LEVEL_SCOPED_17
const EVENT_LEVEL_SCOPED_18
const EVENT_LEVEL_SCOPED_19
const EVENT_LEVEL_SCOPED_20
if (const_value % 8) != 0
const_value = const_value + 8 - (const_value % 8)
endc
EVENT_LEVEL_SCOPED_FLAGS_END EQU const_value
;; The remaining flags are only reset explicitly
EVENT_REGULAR_FLAGS_START EQU EVENT_LEVEL_SCOPED_FLAGS_END
const EVENT_INITIALIZED_EVENTS
; Decorations

View File

@ -52,3 +52,4 @@ MapSetupCommands:
add_mapsetup ConstructAndEnableOverworldHUD ; 2d
add_mapsetup EnableOverworldHUD ; 2e
add_mapsetup SpawnInCustomFacing ; 2f
add_mapsetup ResetLevelScopedEventFlags ; 30

View File

@ -23,12 +23,13 @@ MACRO mapsetup
ENDM
MapSetupScript_EnterLevel:
; same as MapSetupScript_Warp, but includes ConstructAndEnableOverworldHUD
; same as MapSetupScript_Warp, but includes ResetLevelScopedEventFlags and ConstructAndEnableOverworldHUD
mapsetup DisableLCD
mapsetup InitSound
mapsetup EnterMapSpawnPoint
mapsetup LoadMapAttributes
mapsetup HandleNewMap
mapsetup ResetLevelScopedEventFlags
mapsetup SpawnPlayer
mapsetup RefreshPlayerCoords
mapsetup GetMapScreenCoords

View File

@ -8,6 +8,7 @@ TalkToTrainerScript::
SeenByTrainerScript::
loadtemptrainer
waitsfx ; wait for any pending space-related sfx
encountermusic
showemote EMOTE_SHOCK, LAST_TALKED, 30
callasm TrainerWalkToPlayer

View File

@ -82,9 +82,6 @@ LoadMapObjects:
farcall InitializeVisibleSprites
ret
MapSetup_DummyFunction: ; unreferenced
ret
ResetPlayerObjectAction:
ld hl, wPlayerSpriteSetupFlags
set PLAYERSPRITESETUP_RESET_ACTION_F, [hl]
@ -194,3 +191,14 @@ ForceMapMusic:
.notbiking
call TryRestartMapMusic
ret
ResetLevelScopedEventFlags:
ld hl, wEventFlags + EVENT_LEVEL_SCOPED_FLAGS_START / 8
ld c, (EVENT_LEVEL_SCOPED_FLAGS_END / 8) - (EVENT_LEVEL_SCOPED_FLAGS_START / 8)
xor a
.loop
ld [hli], a
dec c
jr nz, .loop
ret

View File

@ -1160,6 +1160,8 @@ Script_startbattle:
call DisableOverworldHUD
ld a, FALSE
ld [wText2bpp], a
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_SPACES_LEFT_F, [hl]
call BufferScreen
predef StartBattle
ld a, [wBattleResult]
@ -1192,15 +1194,23 @@ Script_reloadmapafterbattle:
bit 0, d
jr z, .was_wild
farcall MomTriesToBuySomething
jr .done
jr .next
.was_wild
ld a, [wBattleResult]
bit BATTLERESULT_BOX_FULL, a
jr z, .done
jr z, .next
ld b, BANK(Script_SpecialBillCall)
ld de, Script_SpecialBillCall
farcall LoadMemScript
.next
ld a, [wSpacesLeft]
and a
jr z, .done
farcall LoadBoardMenuDieNumbersGFX
ld hl, wDisplaySecondarySprites
set SECONDARYSPRITES_SPACES_LEFT_F, [hl]
.done
jp Script_reloadmap

View File

@ -19,6 +19,45 @@ DebugLevel5_Map1_MapEvents:
def_bg_events
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
.DebugLevel5_Map1TrainerYoungsterMikey1:
trainer YOUNGSTER, MIKEY, EVENT_LEVEL_SCOPED_1, .YoungsterMikeySeenText, .YoungsterMikeyBeatenText, 0, .Script
.DebugLevel5_Map1TrainerYoungsterMikey2:
trainer YOUNGSTER, MIKEY, EVENT_LEVEL_SCOPED_2, .YoungsterMikeySeenText, .YoungsterMikeyBeatenText, 0, .Script
.Script:
endifjustbattled
opentext
writetext .YoungsterMikeyAfterText
waitbutton
closetext
end
.YoungsterMikeySeenText:
text "You're a #MON"
line "trainer, right?"
para "Then you have to"
line "battle!"
done
.YoungsterMikeyBeatenText:
text "That's strange."
line "I won before."
done
.YoungsterMikeyAfterText:
text "Becoming a good"
line "trainer is really"
cont "tough."
para "I'm going to bat-"
line "tle other people"
cont "to get better."
done
DebugLevel5_Map1_MapSpaces:
space 2, 4, $0, 1 ; 0
@ -70,6 +109,6 @@ DebugLevel5_Map1_MapSpaces:
space 16, 4, $0, 8 ; 43
.BS2:
branchdir RIGHT, 3, TECHNIQUE_SURF
branchdir RIGHT, 3, 0
branchdir UP, 35, 0
endbranch