diff options
author | entrpntr <entrpntr@gmail.com> | 2020-04-26 20:45:59 -0400 |
---|---|---|
committer | entrpntr <entrpntr@gmail.com> | 2020-04-26 22:15:31 -0400 |
commit | d53f3afe500ad9e92f18a7e6de77982928a6061f (patch) | |
tree | 9fd2697a741c82a98104b1c23437907f061be034 | |
parent | 0b33dabae2d43591a964774154f8bec5bf7194b1 (diff) |
Clean up some overworld code.
-rw-r--r-- | constants/map_object_constants.asm | 5 | ||||
-rw-r--r-- | constants/map_setup_constants.asm | 1 | ||||
-rw-r--r-- | data/events/field_move_blocks.asm | 52 | ||||
-rw-r--r-- | data/events/happiness_changes.asm | 21 | ||||
-rwxr-xr-x | data/text/common_1.asm | 12 | ||||
-rw-r--r-- | data/text/common_2.asm | 62 | ||||
-rwxr-xr-x | engine/events/happiness_egg.asm | 159 | ||||
-rwxr-xr-x | engine/events/overworld.asm | 1274 | ||||
-rwxr-xr-x | engine/items/item_effects.asm | 4 | ||||
-rwxr-xr-x | engine/movement_pattern.asm | 651 | ||||
-rwxr-xr-x | engine/overworld/map_object_action.asm | 274 | ||||
-rwxr-xr-x | engine/overworld/map_objects.asm | 2632 | ||||
-rwxr-xr-x | engine/overworld/movement.asm | 1081 | ||||
-rwxr-xr-x | engine/overworld/npc_movement.asm | 2 | ||||
-rwxr-xr-x | engine/overworld/player_movement.asm | 4 | ||||
-rwxr-xr-x | engine/overworld/player_object.asm | 16 | ||||
-rwxr-xr-x | engine/overworld/player_step.asm | 8 | ||||
-rwxr-xr-x | engine/step_types.asm | 719 | ||||
-rwxr-xr-x | hram.asm | 13 | ||||
-rw-r--r-- | macros/scripts/movement.asm | 5 | ||||
-rw-r--r-- | main.asm | 12 | ||||
-rw-r--r-- | wram.asm | 32 |
22 files changed, 3624 insertions, 3415 deletions
diff --git a/constants/map_object_constants.asm b/constants/map_object_constants.asm index 6a6cec59..51480453 100644 --- a/constants/map_object_constants.asm +++ b/constants/map_object_constants.asm @@ -70,6 +70,9 @@ EMOTE_OBJECT EQU 1 << EMOTE_OBJECT_F const OBJ_FLAGS2_2 ; 2 const OVERHEAD_F ; 3 const USE_OBP1_F ; 4 + const OBJ_FLAGS2_5 ; 5 + const OBJ_FLAGS2_6 ; 6 + const OBJ_FLAGS2_7 ; 7 LOW_PRIORITY EQU 1 << LOW_PRIORITY_F HIGH_PRIORITY EQU 1 << HIGH_PRIORITY_F @@ -225,7 +228,6 @@ NUM_SPRITEMOVEDATA EQU const_value const STEP_TYPE_16 ; 16 const STEP_TYPE_17 ; 17 const STEP_TYPE_18 ; 18 - const STEP_TYPE_SKYFALL_TOP ; 19 ; ObjectActionPairPointers indexes (see engine/overworld/map_object_action.asm) const_def @@ -245,7 +247,6 @@ NUM_SPRITEMOVEDATA EQU const_value const OBJECT_ACTION_BIG_DOLL ; 0d const OBJECT_ACTION_BOULDER_DUST ; 0e const OBJECT_ACTION_GRASS_SHAKE ; 0f - const OBJECT_ACTION_SKYFALL ; 10 ; Facings indexes (see data/sprites/facings.asm) const_def diff --git a/constants/map_setup_constants.asm b/constants/map_setup_constants.asm index fb88997b..b38a3c52 100644 --- a/constants/map_setup_constants.asm +++ b/constants/map_setup_constants.asm @@ -12,7 +12,6 @@ const MAPSETUP_TRAIN ; f9 const MAPSETUP_SUBMENU ; fa const MAPSETUP_BADWARP ; fb - const MAPSETUP_FLY ; fc ; MapSetupCommands indexes (see engine/overworld/map_setup.asm) const_def diff --git a/data/events/field_move_blocks.asm b/data/events/field_move_blocks.asm new file mode 100644 index 00000000..fea80f53 --- /dev/null +++ b/data/events/field_move_blocks.asm @@ -0,0 +1,52 @@ +CutTreeBlockPointers: +; tileset, block list pointer + dbw TILESET_JOHTO, .johto + dbw TILESET_JOHTO_MODERN, .johto_modern + dbw TILESET_KANTO, .kanto + dbw TILESET_PARK, .park + dbw TILESET_FOREST, .forest + db -1 ; end + +.johto: +; facing block, replacement block, animation + db $03, $02, 1 ; grass + db $5b, $3c, 0 ; tree + db $5f, $3d, 0 ; tree + db $63, $3f, 0 ; tree + db $67, $3e, 0 ; tree + db -1 ; end + +.johto_modern: +; facing block, replacement block, animation + db $03, $02, $01 ; grass + db -1 ; end + +.kanto: +; facing block, replacement block, animation + db $0b, $0a, 1 ; grass + db $32, $6d, 0 ; tree + db $33, $6c, 0 ; tree + db $34, $6f, 0 ; tree + db $35, $4c, 0 ; tree + db $60, $6e, 0 ; tree + db -1 ; end + +.park: +; facing block, replacement block, animation + db $13, $03, 1 ; grass + db $03, $04, 1 ; grass + db -1 ; end + +.forest: +; facing block, replacement block, animation + db $0f, $17, 0 + db -1 ; end + +WhirlpoolBlockPointers: + dbw TILESET_JOHTO, .johto + db -1 ; end + +.johto: +; facing block, replacement block, animation + db $07, $36, 0 + db -1 ; end diff --git a/data/events/happiness_changes.asm b/data/events/happiness_changes.asm new file mode 100644 index 00000000..aa154e4c --- /dev/null +++ b/data/events/happiness_changes.asm @@ -0,0 +1,21 @@ +HappinessChanges: +; entries correspond to HAPPINESS_* constants +; change if happiness < 100, change if happiness < 200, change otherwise + db +5, +3, +2 ; Gained a level + db +5, +3, +2 ; Vitamin + db +1, +1, +0 ; X Item + db +3, +2, +1 ; Battled a Gym Leader + db +1, +1, +0 ; Learned a move + db -1, -1, -1 ; Lost to an enemy + db -5, -5, -10 ; Fainted due to poison + db -5, -5, -10 ; Lost to a much stronger enemy + db +1, +1, +1 ; Haircut (older brother) 1 + db +3, +3, +1 ; Haircut (older brother) 2 + db +5, +5, +2 ; Haircut (older brother) 3 + db +1, +1, +1 ; Haircut (younger brother) 1 + db +3, +3, +1 ; Haircut (younger brother) 2 + db +10, +10, +4 ; Haircut (younger brother) 3 + db -5, -5, -10 ; Used Heal Powder or Energypowder (bitter) + db -10, -10, -15 ; Used Energy Root (bitter) + db -15, -15, -20 ; Used Revival Herb (bitter) + db +3, +3, +1 ; Grooming diff --git a/data/text/common_1.asm b/data/text/common_1.asm index ca1a8e9a..8745b9ee 100755 --- a/data/text/common_1.asm +++ b/data/text/common_1.asm @@ -1803,34 +1803,34 @@ UnknownText_0x1c04fa:: text "'s home." prompt -BadgeRequiredText_:: +_BadgeRequiredText:: text "Sorry! A new BADGE" line "is required." prompt -CantUseFieldMoveHereText_:: +_CantUseItemText:: text "Can't use that" line "here." prompt -Text_UsedCut_:: +_UseCutText:: text_ram wStringBuffer2 text " used" line "CUT!" prompt -Text_NothingToCut_:: +_CutNothingText:: text "There's nothing to" line "CUT here." prompt -Text_UsedFlash_:: +_BlindingFlashText:: text "A blinding FLASH" line "lights the area!@" text_promptbutton db "@@" -UsedSurfText_:: +_UsedSurfText:: text_ram wStringBuffer2 text " used" line "SURF!" diff --git a/data/text/common_2.asm b/data/text/common_2.asm index 78c3d703..05ee596f 100644 --- a/data/text/common_2.asm +++ b/data/text/common_2.asm @@ -1,80 +1,80 @@ -CantSurfText_:: +_CantSurfText:: text "You can't SURF" line "here." prompt -AlreadySurfingText_:: +_AlreadySurfingText:: text "You're already" line "SURFING." prompt -AskSurfText_:: +_AskSurfText:: text "The water is calm." line "Want to SURF?" done -Text_UsedWaterfall_:: +_UseWaterfallText:: text_ram wStringBuffer2 text " used" line "WATERFALL!" done -Text_CantDoWaterfall_:: +_HugeWaterfallText:: text "Wow, it's a huge" line "waterfall." done -Text_AskUseWaterfall_:: +_AskWaterfallText:: text "Do you want to use" line "WATERFALL?" done -Text_UsedDig_:: +_UseDigText:: text_ram wStringBuffer2 text " used" line "DIG!" done -Text_UsedEscapeRope_:: +_UseEscapeRopeText:: text "<PLAYER> used an" line "ESCAPE ROPE." done -Text_CantUseDigEscapeRopeHere_:: +_CantUseDigText:: text "Can't use that" line "here." done -Text_ReturnToLastMonCenter_:: +_TeleportReturnText:: text "Return to the last" line "#MON CENTER." done -Text_CantUseTeleportHere_:: +_CantUseTeleportText:: text "Can't use that" line "here." para "" done -Text_AlreadyUsingStrength_:: +_AlreadyUsingStrengthText:: text "A #MON is using" line "STRENGTH already." prompt -Text_UsedStrength_:: +_UseStrengthText:: text_ram wStringBuffer2 text " used" line "STRENGTH!" done -Text_AllowedToMoveBoulders_:: +_MoveBoulderText:: text_ram wStringBuffer1 text " can" line "move boulders." prompt -Text_AskStrength_:: +_AskStrengthText:: text "A #MON may be" line "able to move this." @@ -82,23 +82,23 @@ Text_AskStrength_:: line "STRENGTH?" done -Text_BouldersMayNowBeMoved_:: +_BouldersMoveText:: text "Boulders may now" line "be moved!" done -Text_MonMayBeAbleToMove_:: +_BouldersMayMoveText:: text "A #MON may be" line "able to move this." done -Text_UsedWhirlpool_:: +_UseWhirlpoolText:: text_ram wStringBuffer2 text " used" line "WHIRLPOOL!" prompt -Text_MightyWhirlpool_:: +_MayPassWhirlpoolText:: text "It's a vicious" line "whirlpool!" @@ -106,7 +106,7 @@ Text_MightyWhirlpool_:: line "able to pass it." done -Text_AskWhirlpool_:: +_AskWhirlpoolText:: text "A whirlpool is in" line "the way." @@ -114,17 +114,17 @@ Text_AskWhirlpool_:: line "WHIRLPOOL?" done -Text_DidAHeadbutt_:: +_UseHeadbuttText:: text_ram wStringBuffer2 text " did a" line "HEADBUTT!" prompt -Text_NothingFromHeadbutt_:: +_HeadbuttNothingText:: text "Nope. Nothing…" done -Text_AskHeadbutt_:: +_AskHeadbuttText:: text "A #MON could be" line "in this tree." @@ -132,18 +132,18 @@ Text_AskHeadbutt_:: line "it?" done -Text_UsedRockSmash_:: +_UseRockSmashText:: text_ram wStringBuffer2 text " used" line "ROCK SMASH!" prompt -Text_MayBeBreakable_:: +_MaySmashText:: text "A #MON may be" line "able to break it." done -Text_AskRockSmash_:: +_AskRockSmashText:: text "This rock looks" line "breakable." @@ -151,16 +151,16 @@ Text_AskRockSmash_:: line "SMASH?" done -Text_OhABite_:: +_RodBiteText:: text "Oh!" line "A bite!" prompt -Text_NotEvenANibble_:: +_RodNothingText:: text "Not even a nibble!" prompt -Text_NothingHereToFish_:: +_UnusedNothingHereText:: text "Looks like there's" line "nothing here." prompt @@ -184,14 +184,14 @@ _GotOffBikeText:: text "." done -Text_AskCut_:: +_AskCutText:: text "This tree can be" line "CUT!" para "Want to use CUT?" done -Text_MonCanCutThis_:: +_CanCutText:: text "This tree can be" line "CUT!" done diff --git a/engine/events/happiness_egg.asm b/engine/events/happiness_egg.asm index 6563c878..9e6bffb4 100755 --- a/engine/events/happiness_egg.asm +++ b/engine/events/happiness_egg.asm @@ -1,17 +1,17 @@ GetFirstPokemonHappiness: ld hl, wPartyMon1Happiness - ld bc, $30 + ld bc, PARTYMON_STRUCT_LENGTH ld de, wPartySpecies -.asm_7275 +.loop ld a, [de] cp EGG - jr nz, .asm_727e + jr nz, .done inc de add hl, bc - jr .asm_7275 + jr .loop -.asm_727e - ld [wd151], a +.done + ld [wNamedObjectIndexBuffer], a ld a, [hl] ld [wScriptVar], a call GetPokemonName @@ -19,67 +19,76 @@ GetFirstPokemonHappiness: CheckFirstMonIsEgg: ld a, [wPartySpecies] - ld [wd151], a + ld [wNamedObjectIndexBuffer], a cp EGG - ld a, $1 - jr z, .asm_7298 + ld a, TRUE + jr z, .egg xor a -.asm_7298 + +.egg ld [wScriptVar], a call GetPokemonName jp CopyPokemonName_Buffer1_Buffer3 -ChangeHappiness: ; 72a1 (1:72a1) +ChangeHappiness: +; Perform happiness action c on wCurPartyMon + ld a, [wCurPartyMon] inc a ld e, a - ld d, $0 - ld hl, wPartyCount + ld d, 0 + ld hl, wPartySpecies - 1 add hl, de ld a, [hl] - cp $fd + cp EGG ret z + push bc ld hl, wPartyMon1Happiness - ld bc, $30 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wCurPartyMon] call AddNTimes pop bc + ld d, h ld e, l + push de ld a, [de] - cp $64 - ld e, $0 - jr c, .asm_72ce + cp HAPPINESS_THRESHOLD_1 + ld e, 0 + jr c, .ok inc e - cp $c8 - jr c, .asm_72ce + cp HAPPINESS_THRESHOLD_2 + jr c, .ok inc e -.asm_72ce + +.ok dec c - ld b, $0 - ld hl, .Actions + ld b, 0 + ld hl, HappinessChanges add hl, bc add hl, bc add hl, bc - ld d, $0 + ld d, 0 add hl, de ld a, [hl] - cp $64 + cp $64 ; why not $80? pop de + ld a, [de] - jr nc, .asm_72e8 + jr nc, .negative add [hl] - jr nc, .asm_72ec - ld a, $ff - jr .asm_72ec + jr nc, .done + ld a, -1 + jr .done -.asm_72e8 +.negative add [hl] - jr c, .asm_72ec + jr c, .done xor a -.asm_72ec + +.done ld [de], a ld a, [wBattleMode] and a @@ -93,84 +102,72 @@ ChangeHappiness: ; 72a1 (1:72a1) ld [wBattleMonHappiness], a ret -.Actions: - db +5, +3, +2 ; Gained a level - db +5, +3, +2 ; Vitamin - db +1, +1, +0 ; X Item - db +3, +2, +1 ; Battled a Gym Leader - db +1, +1, +0 ; Learned a move - db -1, -1, -1 ; Lost to an enemy - db -5, -5, -10 ; Fainted due to poison - db -5, -5, -10 ; Lost to a much stronger enemy - db +1, +1, +1 ; Haircut (Y1) - db +3, +3, +1 ; Haircut (Y2) - db +5, +5, +2 ; Haircut (Y3) - db +1, +1, +1 ; Haircut (O1) - db +3, +3, +1 ; Haircut (O2) - db +10, +10, +4 ; Haircut (O3) - db -5, -5, -10 ; Used Heal Powder or Energypowder (bitter) - db -10, -10, -15 ; Used Energy Root (bitter) - db -15, -15, -20 ; Used Revival Herb (bitter) - db +3, +3, +1 ; Grooming +INCLUDE "data/events/happiness_changes.asm" StepHappiness:: - ld hl, wd9c1 +; Raise the party's happiness by 1 point every other step cycle. + + ld hl, wHappinessStepCount ld a, [hl] inc a - and $1 + and 1 ld [hl], a ret nz + ld de, wPartyCount ld a, [de] and a ret z + ld c, a ld hl, wPartyMon1Happiness -.asm_7349 +.loop inc de ld a, [de] cp EGG - jr z, .asm_7354 + jr z, .next inc [hl] - jr nz, .asm_7354 + jr nz, .next ld [hl], $ff -.asm_7354 + +.next push de - ld de, $30 + ld de, PARTYMON_STRUCT_LENGTH add hl, de pop de dec c - jr nz, .asm_7349 + jr nz, .loop ret -MAX_EXP EQU 5242880 - DayCareStep:: CheckFlag ENGINE_DAY_CARE_MAN_HAS_MON - jr z, .daycare_lady + jr z, .day_care_lady + ld a, [wBreedMon1Level] cp MAX_LEVEL - jr nc, .daycare_lady - ld hl, wBreedMon1Exp + 2 + jr nc, .day_care_lady + ld hl, wBreedMon1Exp + 2 ; exp inc [hl] - jr nz, .daycare_lady + jr nz, .day_care_lady dec hl inc [hl] - jr nz, .daycare_lady + jr nz, .day_care_lady dec hl inc [hl] ld a, [hl] - cp MAX_EXP / $10000 - jr c, .daycare_lady - ld a, MAX_EXP / $10000 + cp HIGH(MAX_DAY_CARE_EXP >> 8) + jr c, .day_care_lady + ld a, HIGH(MAX_DAY_CARE_EXP >> 8) ld [hl], a -.daycare_lady + +.day_care_lady CheckFlag ENGINE_DAY_CARE_LADY_HAS_MON jr z, .check_egg - ld a, [wBreedMon2Level] + + ld a, [wBreedMon2Level] ; level cp MAX_LEVEL jr nc, .check_egg - ld hl, wBreedMon2Exp + 2 + ld hl, wBreedMon2Exp + 2 ; exp inc [hl] jr nz, .check_egg dec hl @@ -179,13 +176,14 @@ DayCareStep:: dec hl inc [hl] ld a, [hl] - cp MAX_EXP / $10000 + cp HIGH(MAX_DAY_CARE_EXP >> 8) jr c, .check_egg - ld a, MAX_EXP / $10000 + ld a, HIGH(MAX_DAY_CARE_EXP >> 8) ld [hl], a + .check_egg ld hl, wDayCareMan - bit 5, [hl] + bit DAYCAREMAN_MONS_COMPATIBLE_F, [hl] ret z ld hl, wStepsToEgg dec [hl] @@ -194,24 +192,25 @@ DayCareStep:: call Random ld [hl], a callfar CheckBreedmonCompatibility - ld a, [wd151] + ld a, [wBreedingCompatibility] cp 230 - ld b, -1 + 32 percent + ld b, 32 percent - 1 jr nc, .okay - ld a, [wd151] + ld a, [wBreedingCompatibility] cp 170 ld b, 16 percent jr nc, .okay - ld a, [wd151] + ld a, [wBreedingCompatibility] cp 110 ld b, 12 percent jr nc, .okay ld b, 4 percent + .okay call Random cp b ret nc ld hl, wDayCareMan - res 5, [hl] + res DAYCAREMAN_MONS_COMPATIBLE_F, [hl] SetFlagForceReuseHL ENGINE_DAY_CARE_MAN_HAS_EGG ret diff --git a/engine/events/overworld.asm b/engine/events/overworld.asm index 28b7c895..ca8116c4 100755 --- a/engine/events/overworld.asm +++ b/engine/events/overworld.asm @@ -1,407 +1,390 @@ -FieldMoveBufferReset: ; c72f (3:472f) +FieldMoveJumptableReset: xor a ld hl, wBuffer1 - ld bc, $7 + ld bc, 7 call ByteFill ret -DoFieldMoveAction: ; c73a (3:473a) +FieldMoveJumptable: ld a, [wBuffer1] rst JumpTable ld [wBuffer1], a bit 7, a - jr nz, .asm_c747 + jr nz, .okay and a ret -.asm_c747 +.okay and $7f scf ret -FieldMoveGetPartyNick: ; c74b (3:474b) - ld hl, wPartyMon1Nickname - ld a, $2 +GetPartyNick: +; write wCurPartyMon nickname to wStringBuffer1-3 + ld hl, wPartyMonNicknames + ld a, BOXMON ld [wMonType], a ld a, [wCurPartyMon] call GetNick call CopyName1 +; copy text from wStringBuffer2 to wStringBuffer3 ld de, wStringBuffer2 ld hl, wStringBuffer3 call CopyName2 ret -FieldMoveEngineFlagCheck: ; c766 (3:4766) +CheckEngineFlag: +; Check engine flag de +; Return carry if flag is not set ld b, CHECK_FLAG - farcall EngineFlagAction ; same bank + farcall EngineFlagAction ld a, c and a - jr nz, .asm_c774 + jr nz, .isset scf ret - -.asm_c774 +.isset xor a ret -FieldMoveBadgeCheck: ; c776 (3:4776) - call FieldMoveEngineFlagCheck +CheckBadge: +; Check engine flag a (ENGINE_ZEPHYRBADGE thru ENGINE_EARTHBADGE) +; Display "Badge required" text and return carry if the badge is not owned + call CheckEngineFlag ret nc ld hl, .BadgeRequiredText - call MenuTextboxBackup + call MenuTextboxBackup ; push text to queue scf ret .BadgeRequiredText: - text_far BadgeRequiredText_ - db "@" + text_far _BadgeRequiredText + text_end + +CheckPartyMove: +; Check if a monster in your party has move d. -FieldMovePartyCheck: ; c787 (3:4787) - ld e, $0 + ld e, 0 xor a ld [wCurPartyMon], a -.asm_c78d +.loop ld c, e - ld b, $0 + ld b, 0 ld hl, wPartySpecies add hl, bc ld a, [hl] and a - jr z, .asm_c7bc + jr z, .no cp -1 - jr z, .asm_c7bc + jr z, .no cp EGG - jr z, .asm_c7b3 + jr z, .next + ld bc, PARTYMON_STRUCT_LENGTH ld hl, wPartyMon1Moves ld a, e call AddNTimes ld b, NUM_MOVES -.asm_c7ac +.check ld a, [hli] cp d - jr z, .asm_c7b6 + jr z, .yes dec b - jr nz, .asm_c7ac -.asm_c7b3 + jr nz, .check + +.next inc e - jr .asm_c78d + jr .loop -.asm_c7b6 +.yes ld a, e - ld [wCurPartyMon], a + ld [wCurPartyMon], a ; which mon has the move xor a ret - -.asm_c7bc +.no scf ret -FieldMoveFailed: ; c7be (3:47be) - ld hl, .CantUseHereText +FieldMoveFailed: + ld hl, .CantUseItemText call MenuTextboxBackup ret -.CantUseHereText: - text_far CantUseFieldMoveHereText_ - db "@" +.CantUseItemText: + text_far _CantUseItemText + text_end -CutFunction:: - call FieldMoveBufferReset -.asm_c7cd +CutFunction: + call FieldMoveJumptableReset +.loop ld hl, .Jumptable - call DoFieldMoveAction - jr nc, .asm_c7cd + call FieldMoveJumptable + jr nc, .loop and $7f ld [wFieldMoveSucceeded], a ret .Jumptable: - dw CheckAbleToCut - dw CutTreeOrGrass - dw FailToCut + dw .CheckAble + dw .DoCut + dw .FailCut -CheckAbleToCut: +.CheckAble: ld de, ENGINE_HIVEBADGE - call FieldMoveBadgeCheck - jr c, .asm_c7f1 + call CheckBadge + jr c, .nohivebadge call CheckMapForSomethingToCut - jr c, .asm_c7f4 + jr c, .nothingtocut ld a, $1 ret -.asm_c7f1 +.nohivebadge ld a, $80 ret -.asm_c7f4 +.nothingtocut ld a, $2 ret -CutTreeOrGrass: +.DoCut: ld hl, Script_CutFromMenu call QueueScript ld a, $81 ret -FailToCut: - ld hl, Text_NothingToCut +.FailCut: + ld hl, CutNothingText call MenuTextboxBackup ld a, $80 ret -Text_UsedCut: - text_far Text_UsedCut_ - db "@" +UseCutText: + text_far _UseCutText + text_end -Text_NothingToCut: - text_far Text_NothingToCut_ - db "@" +CutNothingText: + text_far _CutNothingText + text_end -CheckMapForSomethingToCut: ; c813 (3:4813) +CheckMapForSomethingToCut: + ; Does the collision data of the facing tile permit cutting? call GetFacingTileCoord ld c, a push de farcall CheckCutCollision pop de - jr nc, .asm_c841 + jr nc, .fail + ; Get the location of the current block in wOverworldMapBlocks. call GetBlockLocation ld c, [hl] + ; See if that block contains something that can be cut. push hl ld hl, CutTreeBlockPointers call CheckOverworldTileArrays pop hl - jr nc, .asm_c841 + jr nc, .fail + ; Back up the wOverworldMapBlocks address to wBuffer3 ld a, l ld [wBuffer3], a ld a, h ld [wBuffer4], a + ; Back up the replacement tile to wBuffer5 ld a, b ld [wBuffer5], a + ; Back up the animation index to wBuffer6 ld a, c ld [wBuffer6], a xor a ret -.asm_c841 +.fail scf ret Script_CutFromMenu: reloadmappart special UpdateTimePals + Script_Cut: - callasm FieldMoveGetPartyNick - writetext Text_UsedCut + callasm GetPartyNick + writetext UseCutText reloadmappart callasm CutDownTreeOrGrass closetext end CutDownTreeOrGrass: - ld hl, wBuffer3 + ld hl, wBuffer3 ; OverworldMapTile ld a, [hli] ld h, [hl] ld l, a - ld a, [wBuffer5] + ld a, [wBuffer5] ; ReplacementTile ld [hl], a xor a ldh [hBGMapMode], a call OverworldTextModeSwitch call UpdateSprites call DelayFrame - ld a, [wBuffer6] + ld a, [wBuffer6] ; Animation type ld e, a farcall OWCutAnimation call BufferScreen call GetMovementPermissions ret -CheckOverworldTileArrays: ; c87c (3:487c) +CheckOverworldTileArrays: + ; Input: c contains the tile you're facing + ; Output: Replacement tile in b and effect on wild encounters in c, plus carry set. + ; Carry is not set if the facing tile cannot be replaced, or if the tileset + ; does not contain a tile you can replace. + + ; Dictionary lookup for pointer to tile replacement table push bc ld a, [wMapTileset] - ld de, $3 + ld de, 3 call IsInArray pop bc - jr nc, .asm_c89c + jr nc, .nope + ; Load the pointer inc hl ld a, [hli] ld h, [hl] ld l, a - ld de, $3 + ; Look up the tile you're facing + ld de, 3 ld a, c call IsInArray - jr nc, .asm_c89c + jr nc, .nope + ; Load the replacement to b inc hl ld b, [hl] + ; Load the animation type parameter to c inc hl ld c, [hl] scf ret -.asm_c89c +.nope xor a ret -CutTreeBlockPointers: - dbw TILESET_JOHTO, .johto1 - dbw TILESET_JOHTO_MODERN, .johto2 - dbw TILESET_KANTO, .kanto - dbw TILESET_PARK, .park - dbw TILESET_FOREST, .ilex - db -1 - -.johto1 - db $03, $02, $01 ; grass - db $5b, $3c, $00 ; tree - db $5f, $3d, $00 ; tree - db $63, $3f, $00 ; tree - db $67, $3e, $00 ; tree - db -1 - -.johto2 - db $03, $02, $01 ; grass - db -1 - -.kanto - db $0b, $0a, $01 ; grass - db $32, $6d, $00 ; tree - db $33, $6c, $00 ; tree - db $34, $6f, $00 ; tree - db $35, $4c, $00 ; tree - db $60, $6e, $00 ; tree - db -1 - -.park - db $13, $03, $01 ; grass - db $03, $04, $01 ; grass - db -1 - -.ilex - db $0f, $17, $00 - db -1 - -WhirlpoolBlockPointers: - dbw TILESET_JOHTO, .johto - db -1 - -.johto - db $07, $36, $00 - db -1 +INCLUDE "data/events/field_move_blocks.asm" FlashFunction: - call CheckUseFlash + call .CheckUseFlash and $7f ld [wFieldMoveSucceeded], a ret -CheckUseFlash: ; c8f1 (3:48f1) +.CheckUseFlash: +; Flash ld de, ENGINE_ZEPHYRBADGE - farcall FieldMoveBadgeCheck ; same bank - jr c, .asm_c90f - ld a, [wd56e] - cp $ff - jr nz, .asm_c909 + farcall CheckBadge + jr c, .nozephyrbadge + ld a, [wTimeOfDayPalset] + cp %11111111 ; 3, 3, 3, 3 + jr nz, .notadarkcave +.useflash call UseFlash ld a, $81 ret -.asm_c909 +.notadarkcave call FieldMoveFailed ld a, $80 ret -.asm_c90f +.nozephyrbadge ld a, $80 ret -UseFlash: ; c912 (3:4912) +UseFlash: ld hl, Script_UseFlash jp QueueScript Script_UseFlash: reloadmappart special UpdateTimePals - writetext Text_UsedFlash + writetext UseFlashTextScript callasm BlindingFlash closetext end -Text_UsedFlash: - text_far Text_UsedFlash_ +UseFlashTextScript: + text_far _BlindingFlashText text_asm call WaitSFX ld de, SFX_FLASH call PlaySFX call WaitSFX - ld hl, .end + ld hl, .BlankText ret -.end db "@" + +.BlankText: + text_end SurfFunction: - call FieldMoveBufferReset -.asm_c93e + call FieldMoveJumptableReset +.loop ld hl, .Jumptable - call DoFieldMoveAction - jr nc, .asm_c93e + call FieldMoveJumptable + jr nc, .loop and $7f ld [wFieldMoveSucceeded], a ret .Jumptable: - dw CheckAbleToSurf - dw StartSurfing - dw CantSurf - dw AlreadySurfing + dw .TrySurf + dw .DoSurf + dw .FailSurf + dw .AlreadySurfing -CheckAbleToSurf: +.TrySurf: ld de, ENGINE_FOGBADGE - call FieldMoveBadgeCheck + call CheckBadge jr c, .asm_c980 - CheckFlagHL ENGINE_ALWAYS_ON_BIKE - jr nz, .asm_c986 + ld hl, wBikeFlags + bit BIKEFLAGS_ALWAYS_ON_BIKE_F, [hl] + jr nz, .cannotsurf ld a, [wPlayerState] cp PLAYER_SURF - jr z, .asm_c983 + jr z, .alreadyfail cp PLAYER_SURF_PIKA - jr z, .asm_c983 + jr z, .alreadyfail call GetFacingTileCoord call GetTileCollision - cp $1 - jr nz, .asm_c986 - call GetSurfDirection - jr c, .asm_c986 + cp WATER_TILE + jr nz, .cannotsurf + call CheckDirection + jr c, .cannotsurf ld a, $1 ret - .asm_c980 ld a, $80 ret - -.asm_c983 +.alreadyfail ld a, $3 ret - -.asm_c986 +.cannotsurf ld a, $2 ret -StartSurfing: +.DoSurf: call GetSurfType ld [wBuffer2], a - call FieldMoveGetPartyNick + call GetPartyNick ld hl, SurfFromMenuScript call QueueScript ld a, $81 ret -CantSurf: +.FailSurf: ld hl, CantSurfText call MenuTextboxBackup ld a, $80 ret -AlreadySurfing: +.AlreadySurfing: ld hl, AlreadySurfingText call MenuTextboxBackup ld a, $80 @@ -414,8 +397,10 @@ UsedSurfScript: writetext UsedSurfText ; "used SURF!" waitbutton closetext + readmem wBuffer2 writevar VAR_MOVEMENT + special ReplaceChrisSprite special PlayMapMusic ; step into the water (slow_step DIR, step_end) @@ -424,23 +409,27 @@ UsedSurfScript: end UsedSurfText: - text_far UsedSurfText_ - db "@" + text_far _UsedSurfText + text_end CantSurfText: - text_far CantSurfText_ - db "@" + text_far _CantSurfText + text_end AlreadySurfingText: - text_far AlreadySurfingText_ - db "@" + text_far _AlreadySurfingText + text_end + +GetSurfType: +; Surfing on Pikachu uses an alternate sprite. +; This is done by using a separate movement type. -GetSurfType: ; c9d7 (3:49d7) ld a, [wCurPartyMon] ld e, a - ld d, $0 + ld d, 0 ld hl, wPartySpecies add hl, de + ld a, [hl] cp PIKACHU ld a, PLAYER_SURF_PIKA @@ -448,22 +437,28 @@ GetSurfType: ; c9d7 (3:49d7) ld a, PLAYER_SURF ret -GetSurfDirection: ; c9ea (3:49ea) +CheckDirection: +; Return carry if a tile permission prevents you +; from moving in the direction you're facing. + +; Get player direction ld a, [wPlayerDirection] - and $c + and %00001100 ; bits 2 and 3 contain direction rrca rrca ld e, a - ld d, $0 + ld d, 0 ld hl, .Directions add hl, de + +; Can you walk in this direction? ld a, [wTilePermissions] and [hl] - jr nz, .asm_ca00 + jr nz, .quit xor a ret -.asm_ca00 +.quit scf ret @@ -474,31 +469,46 @@ GetSurfDirection: ; c9ea (3:49ea) db FACE_RIGHT TrySurfOW:: +; Checking a tile in the overworld. +; Return carry if fail is allowed. + +; Don't ask to surf if already fail. ld a, [wPlayerState] cp PLAYER_SURF_PIKA jr z, .quit cp PLAYER_SURF jr z, .quit + +; Must be facing water. ld a, [wFacingTileID] call GetTileCollision - cp $1 + cp WATER_TILE jr nz, .quit - call GetSurfDirection + +; Check tile permissions. + call CheckDirection jr c, .quit + ld de, ENGINE_FOGBADGE - call FieldMoveEngineFlagCheck + call CheckEngineFlag jr c, .quit + ld d, SURF - call FieldMovePartyCheck + call CheckPartyMove jr c, .quit - CheckFlagHL ENGINE_ALWAYS_ON_BIKE + + ld hl, wBikeFlags + bit BIKEFLAGS_ALWAYS_ON_BIKE_F, [hl] jr nz, .quit + call GetSurfType ld [wBuffer2], a - call FieldMoveGetPartyNick + call GetPartyNick + ld a, BANK(AskSurfScript) ld hl, AskSurfScript call CallScript + scf ret @@ -515,150 +525,152 @@ AskSurfScript: end AskSurfText: - text_far AskSurfText_ - db "@" + text_far _AskSurfText + text_end FlyFunction: - call FieldMoveBufferReset -.asm_ca5d + call FieldMoveJumptableReset +.loop ld hl, .Jumptable - call DoFieldMoveAction - jr nc, .asm_ca5d + call FieldMoveJumptable + jr nc, .loop and $7f ld [wFieldMoveSucceeded], a ret -.Jumptable - dw TryToFly - dw RunFlyScript - dw FailToFly +.Jumptable: + dw .TryFly + dw .DoFly + dw .FailFly -TryToFly: +.TryFly: +; Fly ld de, ENGINE_STORMBADGE - call FieldMoveBadgeCheck - jr c, .asm_caa4 + call CheckBadge + jr c, .nostormbadge call GetMapEnvironment call CheckOutdoorMap - jr z, .asm_ca83 - jr .asm_caa7 + jr z, .outdoors + jr .indoors -.asm_ca83 +.outdoors xor a ldh [hMapAnims], a call LoadStandardMenuHeader call ClearSprites - ld a, $24 - ld hl, $5a61 - rst FarCall + farcall _FlyMap ld a, e - cp $ff - jr z, .asm_caaa - cp $1c - jr nc, .asm_caaa + cp -1 + jr z, .illegal + cp NUM_SPAWNS + jr nc, .illegal + ld [wDefaultSpawnpoint], a call CloseWindow ld a, $1 ret -.asm_caa4 +.nostormbadge ld a, $82 ret -.asm_caa7 +.indoors ld a, $2 ret -.asm_caaa +.illegal call CloseWindow call WaitBGMap ld a, $80 ret -RunFlyScript: - ld hl, FlyScript +.DoFly: + ld hl, .FlyScript call QueueScript ld a, $81 ret -FailToFly: +.FailFly: call FieldMoveFailed ld a, $82 ret -FlyScript: +.FlyScript: reloadmappart callasm HideSprites special UpdateTimePals - callasm FlyFromAnimation + callasm FlyFromAnim farscall Script_AbortBugContest special WarpToSpawnPoint callasm SkipUpdateMapSprites loadvar VAR_MOVEMENT, PLAYER_NORMAL newloadmap MAPSETUP_TELEPORT - callasm FlyToAnimation + callasm FlyToAnim special WaitSFX special ReplaceChrisSprite callasm _RefreshSprites end -WaterfallFunction: ; caed - call TryWaterfall +WaterfallFunction: + call .TryWaterfall and $7f ld [wFieldMoveSucceeded], a ret -TryWaterfall: ; caf6 (3:4af6) +.TryWaterfall: +; Waterfall ld de, ENGINE_RISINGBADGE - farcall FieldMoveBadgeCheck ; same bank + farcall CheckBadge ld a, $80 ret c call CheckMapCanWaterfall - jr c, .asm_cb10 + jr c, .failed ld hl, Script_WaterfallFromMenu call QueueScript ld a, $81 ret -.asm_cb10 +.failed call FieldMoveFailed ld a, $80 ret -CheckMapCanWaterfall: ; cb16 (3:4b16) +CheckMapCanWaterfall: ld a, [wPlayerDirection] and $c cp FACE_UP - jr nz, .asm_cb29 + jr nz, .failed ld a, [wTileUp] call CheckWaterfallTile - jr nz, .asm_cb29 + jr nz, .failed xor a ret -.asm_cb29 +.failed scf ret -Script_WaterfallFromMenu: ;cb2b +Script_WaterfallFromMenu: reloadmappart special UpdateTimePals + Script_UsedWaterfall: - callasm FieldMoveGetPartyNick - writetext Text_UsedWaterfall + callasm GetPartyNick + writetext .UseWaterfallText waitbutton closetext playsound SFX_BUBBLEBEAM .loop - applymovement 0, WaterfallStep - callasm CheckContinueWaterfall + applymovement PLAYER, .WaterfallStep + callasm .CheckContinueWaterfall iffalse .loop end -WaterfallStep: +.WaterfallStep: turn_waterfall UP step_end -CheckContinueWaterfall: ;cb49 +.CheckContinueWaterfall: xor a ld [wScriptVar], a ld a, [wPlayerStandingTile] @@ -668,441 +680,450 @@ CheckContinueWaterfall: ;cb49 ld [wScriptVar], a ret -Text_UsedWaterfall: - text_far Text_UsedWaterfall_ - db "@" +.UseWaterfallText: + text_far _UseWaterfallText + text_end TryWaterfallOW:: ld d, WATERFALL - call FieldMovePartyCheck - jr c, .asm_cb7d + call CheckPartyMove + jr c, .failed ld de, ENGINE_RISINGBADGE - call FieldMoveEngineFlagCheck - jr c, .asm_cb7d + call CheckEngineFlag + jr c, .failed call CheckMapCanWaterfall - jr c, .asm_cb7d + jr c, .failed ld a, BANK(Script_AskWaterfall) ld hl, Script_AskWaterfall call CallScript scf ret -.asm_cb7d +.failed ld a, BANK(Script_CantDoWaterfall) ld hl, Script_CantDoWaterfall call CallScript scf ret -Script_CantDoWaterfall:;cb87 - jumptext Text_CantDoWaterfall +Script_CantDoWaterfall: + jumptext .HugeWaterfallText -Text_CantDoWaterfall: - text_far Text_CantDoWaterfall_ - db "@" +.HugeWaterfallText: + text_far _HugeWaterfallText + text_end Script_AskWaterfall: opentext - writetext Text_AskUseWaterfall + writetext .AskWaterfallText yesorno iftrue Script_UsedWaterfall closetext end -Text_AskUseWaterfall: - text_far Text_AskUseWaterfall_ - db "@" +.AskWaterfallText: + text_far _AskWaterfallText + text_end EscapeRopeFunction: - call FieldMoveBufferReset + call FieldMoveJumptableReset ld a, $1 - jr asm_cbaa + jr EscapeRopeOrDig DigFunction: - call FieldMoveBufferReset + call FieldMoveJumptableReset ld a, $2 -asm_cbaa: + +EscapeRopeOrDig: ld [wBuffer2], a -.asm_cbad - ld hl, .Jumptable - call DoFieldMoveAction - jr nc, .asm_cbad +.loop + ld hl, .DigTable + call FieldMoveJumptable + jr nc, .loop and $7f ld [wFieldMoveSucceeded], a ret -.Jumptable: - dw TryEscapeFromDungeon - dw EscapeFromDungeon - dw FailToEscapeFromDungeon +.DigTable: + dw .CheckCanDig + dw .DoDig + dw .FailDig -TryEscapeFromDungeon: +.CheckCanDig: call GetMapEnvironment cp CAVE - jr z, .asm_cbcf + jr z, .incave cp DUNGEON - jr z, .asm_cbcf -.asm_cbcc + jr z, .incave +.fail ld a, $2 ret -.asm_cbcf +.incave ld hl, wDigWarpNumber ld a, [hli] and a - jr z, .asm_cbcc + jr z, .fail ld a, [hli] and a - jr z, .asm_cbcc + jr z, .fail ld a, [hl] and a - jr z, .asm_cbcc + jr z, .fail ld a, $1 ret -EscapeFromDungeon: +.DoDig: ld hl, wDigWarpNumber ld de, wNextWarp - ld bc, $3 + ld bc, 3 call CopyBytes - call FieldMoveGetPartyNick + call GetPartyNick ld a, [wBuffer2] cp $2 - jr nz, .asm_cc00 - ld hl, UsedDigScript + jr nz, .escaperope + ld hl, .UsedDigScript call QueueScript ld a, $81 ret -.asm_cc00 - ld hl, UsedEscapeRopeScript +.escaperope + ld hl, .UsedEscapeRopeScript call QueueScript ld a, $81 ret -FailToEscapeFromDungeon: +.FailDig: ld a, [wBuffer2] cp $2 - jr nz, .asm_cc1c - ld hl, Text_CantUseDigEscapeRopeHere ; $4c29 + jr nz, .failescaperope + ld hl, .CantUseDigText call MenuTextbox call WaitPressAorB_BlinkCursor call CloseWindow -.asm_cc1c + +.failescaperope ld a, $80 ret -Text_UsedDig: ; cc1f - text_far Text_UsedDig_ - db "@" +.UseDigText: + text_far _UseDigText + text_end -Text_UsedEscapeRope: - text_far Text_UsedEscapeRope_ - db "@" +.UseEscapeRopeText: + text_far _UseEscapeRopeText + text_end -Text_CantUseDigEscapeRopeHere: - text_far Text_CantUseDigEscapeRopeHere_ - db "@" +.CantUseDigText: + text_far _CantUseDigText + text_end -UsedEscapeRopeScript: ; cc2e reloadmappart +.UsedEscapeRopeScript: reloadmappart special UpdateTimePals - writetext Text_UsedEscapeRope ; cc24 - sjump ContinueDigEscapeRopeScript + writetext .UseEscapeRopeText + sjump .UsedDigOrEscapeRopeScript -UsedDigScript: +.UsedDigScript: reloadmappart special UpdateTimePals - writetext Text_UsedDig -ContinueDigEscapeRopeScript: + writetext .UseDigText + +.UsedDigOrEscapeRopeScript: waitbutton closetext playsound SFX_WARP_TO - applymovement PLAYER, DigOutMovementData + applymovement PLAYER, .DigOut farscall Script_AbortBugContest special WarpToSpawnPoint loadvar VAR_MOVEMENT, PLAYER_NORMAL newloadmap MAPSETUP_DOOR playsound SFX_WARP_FROM - applymovement PLAYER, DigReturnMovementData + applymovement PLAYER, .DigReturn end -DigOutMovementData: +.DigOut: step_dig 32 - hide_person + hide_object step_end -DigReturnMovementData: - show_person +.DigReturn: + show_object return_dig 32 step_end TeleportFunction: - call FieldMoveBufferReset -.asm_cc67 + call FieldMoveJumptableReset +.loop ld hl, .Jumptable - call DoFieldMoveAction - jr nc, .asm_cc67 + call FieldMoveJumptable + jr nc, .loop and $7f ld [wFieldMoveSucceeded], a ret .Jumptable: - dw TryTeleport - dw DoTeleport - dw FailTeleport + dw .TryTeleport + dw .DoTeleport + dw .FailTeleport -TryTeleport: +.TryTeleport: call GetMapEnvironment call CheckOutdoorMap - jr z, .asm_cc85 - jr .asm_cc9c + jr z, .CheckIfSpawnPoint + jr .nope -.asm_cc85 +.CheckIfSpawnPoint: ld a, [wLastSpawnMapGroup] ld d, a ld a, [wLastSpawnMapNumber] ld e, a - ld a, $5 - ld hl, $5465 - rst FarCall - jr nc, .asm_cc9c + farcall IsSpawnPoint + jr nc, .nope ld a, c ld [wDefaultSpawnpoint], a ld a, $1 ret -.asm_cc9c +.nope ld a, $2 ret -DoTeleport: - call FieldMoveGetPartyNick - ld hl, TeleportScript +.DoTeleport: + call GetPartyNick + ld hl, .TeleportScript call QueueScript ld a, $81 ret -FailTeleport: - ld hl, Text_CantUseTeleportHere +.FailTeleport: + ld hl, .CantUseTeleportText call MenuTextboxBackup ld a, $80 ret -Text_ReturnToLastMonCenter: - text_far Text_ReturnToLastMonCenter_ - db "@" +.TeleportReturnText: + text_far _TeleportReturnText + text_end -Text_CantUseTeleportHere: - text_far Text_CantUseTeleportHere_ - db "@" +.CantUseTeleportText: + text_far _CantUseTeleportText + text_end -TeleportScript: ; ccbe +.TeleportScript: reloadmappart special UpdateTimePals - writetext Text_ReturnToLastMonCenter + writetext .TeleportReturnText pause 60 reloadmappart closetext playsound SFX_WARP_TO - applymovement PLAYER, TeleportFromMovementData + applymovement PLAYER, .TeleportFrom farscall Script_AbortBugContest special WarpToSpawnPoint loadvar VAR_MOVEMENT, PLAYER_NORMAL newloadmap MAPSETUP_TELEPORT playsound SFX_WARP_FROM - applymovement PLAYER, TeleportToMovementData + applymovement PLAYER, .TeleportTo end -TeleportFromMovementData: ; cce4 +.TeleportFrom: teleport_from step_end -TeleportToMovementData: +.TeleportTo: teleport_to step_end StrengthFunction: - call Functionccf1 + call .TryStrength and $7f ld [wFieldMoveSucceeded], a ret -Functionccf1: ; ccf1 (3:4cf1) +.TryStrength: +; Strength ld de, ENGINE_PLAINBADGE - call FieldMoveBadgeCheck - jr c, asm_cd09 - jr asm_cd0c + call CheckBadge + jr c, .Failed + jr .UseStrength - ld hl, Text_AlreadyUsingStrength +.Unreferenced_AlreadyUsing: + ld hl, .AlreadyUsingStrengthText call MenuTextboxBackup ld a, $80 ret -Text_AlreadyUsingStrength: - text_far Text_AlreadyUsingStrength_ - db "@" +.AlreadyUsingStrengthText: + text_far _AlreadyUsingStrengthText + text_end -asm_cd09: +.Failed: ld a, $80 ret -asm_cd0c: +.UseStrength: ld hl, Script_StrengthFromMenu call QueueScript ld a, $81 ret -GetStrengthUserSpeciesAndSetFlag: - SetFlag ENGINE_STRENGTH_ACTIVE +SetStrengthFlag: + ld hl, wBikeFlags + set BIKEFLAGS_STRENGTH_ACTIVE_F, [hl] ld a, [wCurPartyMon] ld e, a - ld d, $0 + ld d, 0 ld hl, wPartySpecies add hl, de ld a, [hl] ld [wBuffer6], a - call FieldMoveGetPartyNick + call GetPartyNick ret -Script_StrengthFromMenu: ; cd2c +Script_StrengthFromMenu: reloadmappart special UpdateTimePals + Script_UsedStrength: - callasm GetStrengthUserSpeciesAndSetFlag - writetext Text_UsedStrength + callasm SetStrengthFlag + writetext .UseStrengthText readmem wBuffer6 cry 0 pause 3 - writetext Text_AllowedToMoveBoulders + writetext .MoveBoulderText closetext end -Text_UsedStrength: ; cd44 - text_far Text_UsedStrength_ - db "@" +.UseStrengthText: + text_far _UseStrengthText + text_end -Text_AllowedToMoveBoulders: - text_far Text_AllowedToMoveBoulders_ - db "@" +.MoveBoulderText: + text_far _MoveBoulderText + text_end -AskStrengthScript: ; cd4e +AskStrengthScript: callasm TryStrengthOW - iffalse .ask - ifequal 1, .not_able - sjump .already_active + iffalse .AskStrength + ifequal $1, .DontMeetRequirements + sjump .AlreadyUsedStrength -.not_able - jumptext Text_MonMayBeAbleToMove +.DontMeetRequirements: + jumptext BouldersMayMoveText -.already_active - jumptext Text_BouldersMayNowBeMoved +.AlreadyUsedStrength: + jumptext BouldersMoveText -.ask +.AskStrength: opentext - writetext Text_AskStrength + writetext AskStrengthText yesorno iftrue Script_UsedStrength closetext end -Text_AskStrength: - text_far Text_AskStrength_ - db "@" +AskStrengthText: + text_far _AskStrengthText + text_end -Text_BouldersMayNowBeMoved: - text_far Text_BouldersMayNowBeMoved_ - db "@" +BouldersMoveText: + text_far _BouldersMoveText + text_end -Text_MonMayBeAbleToMove: - text_far Text_MonMayBeAbleToMove_ - db "@" +BouldersMayMoveText: + text_far _BouldersMayMoveText + text_end TryStrengthOW: ld d, STRENGTH - call FieldMovePartyCheck - jr c, .asm_cd95 + call CheckPartyMove + jr c, .nope + ld de, ENGINE_PLAINBADGE - call FieldMoveEngineFlagCheck - jr c, .asm_cd95 - CheckFlagHL ENGINE_STRENGTH_ACTIVE - jr z, .asm_cd99 - ld a, $2 - jr .asm_cd9c + call CheckEngineFlag + jr c, .nope -.asm_cd95 - ld a, $1 - jr .asm_cd9c + ld hl, wBikeFlags + bit BIKEFLAGS_STRENGTH_ACTIVE_F, [hl] + jr z, .already_using -.asm_cd99 + ld a, 2 + jr .done + +.nope + ld a, 1 + jr .done + +.already_using xor a - jr .asm_cd9c + jr .done -.asm_cd9c +.done ld [wScriptVar], a ret WhirlpoolFunction: - call FieldMoveBufferReset -.asm_cda3 - ld hl, .Jumptable - call DoFieldMoveAction - jr nc, .asm_cda3 + call FieldMoveJumptableReset +.loop + ld hl, Jumptable_cdae + call FieldMoveJumptable + jr nc, .loop and $7f ld [wFieldMoveSucceeded], a ret -.Jumptable - dw TryWhirlpool - dw DoWhirlpool - dw FailWhirlpool +Jumptable_cdae: + dw .TryWhirlpool + dw .DoWhirlpool + dw .FailWhirlpool -TryWhirlpool: +.TryWhirlpool: ld de, ENGINE_GLACIERBADGE - call FieldMoveBadgeCheck - jr c, .asm_cdca + call CheckBadge + jr c, .noglacierbadge call TryWhirlpoolMenu - jr c, .asm_cdc7 + jr c, .failed ld a, $1 ret -.asm_cdc7 +.failed ld a, $2 ret -.asm_cdca +.noglacierbadge ld a, $80 ret -DoWhirlpool: +.DoWhirlpool: ld hl, Script_WhirlpoolFromMenu call QueueScript ld a, $81 ret -FailWhirlpool: +.FailWhirlpool: call FieldMoveFailed ld a, $80 ret -Text_UsedWhirlpool: - text_far Text_UsedWhirlpool_ - db "@" +UseWhirlpoolText: + text_far _UseWhirlpoolText + text_end -TryWhirlpoolMenu: ; cde1 (3:4de1) +TryWhirlpoolMenu: call GetFacingTileCoord ld c, a push de call CheckWhirlpoolTile pop de - jr c, .asm_ce0c + jr c, .failed call GetBlockLocation ld c, [hl] push hl ld hl, WhirlpoolBlockPointers call CheckOverworldTileArrays pop hl - jr nc, .asm_ce0c + jr nc, .failed ld a, l ld [wBuffer3], a ld a, h @@ -1114,22 +1135,23 @@ TryWhirlpoolMenu: ; cde1 (3:4de1) xor a ret -.asm_ce0c +.failed scf ret -Script_WhirlpoolFromMenu: ; 4e0e +Script_WhirlpoolFromMenu: reloadmappart special UpdateTimePals + Script_UsedWhirlpool: - callasm FieldMoveGetPartyNick - writetext Text_UsedWhirlpool + callasm GetPartyNick + writetext UseWhirlpoolText reloadmappart callasm DisappearWhirlpool closetext end -DisappearWhirlpool: ; 4e20 +DisappearWhirlpool: ld hl, wBuffer3 ld a, [hli] ld h, [hl] @@ -1148,44 +1170,44 @@ DisappearWhirlpool: ; 4e20 TryWhirlpoolOW:: ld d, WHIRLPOOL - call FieldMovePartyCheck - jr c, .asm_ce5f + call CheckPartyMove + jr c, .failed ld de, ENGINE_GLACIERBADGE - call FieldMoveEngineFlagCheck - jr c, .asm_ce5f + call CheckEngineFlag + jr c, .failed call TryWhirlpoolMenu - jr c, .asm_ce5f + jr c, .failed ld a, BANK(Script_AskWhirlpoolOW) - ld hl, Script_AskWhirlpoolOW ; $4e71 + ld hl, Script_AskWhirlpoolOW call CallScript scf ret -.asm_ce5f +.failed ld a, BANK(Script_MightyWhirlpool) - ld hl, Script_MightyWhirlpool ; $4e69 + ld hl, Script_MightyWhirlpool call CallScript scf ret Script_MightyWhirlpool: - jumptext Text_MightyWhirlpool + jumptext .MayPassWhirlpoolText -Text_MightyWhirlpool: - text_far Text_MightyWhirlpool_ - db "@" +.MayPassWhirlpoolText: + text_far _MayPassWhirlpoolText + text_end -Script_AskWhirlpoolOW: ; ce71 +Script_AskWhirlpoolOW: opentext - writetext Text_AskWhirlpool + writetext AskWhirlpoolText yesorno iftrue Script_UsedWhirlpool closetext end -Text_AskWhirlpool: ; ce7b - text_far Text_AskWhirlpool_ - db "@" +AskWhirlpoolText: + text_far _AskWhirlpoolText + text_end HeadbuttFunction: call TryHeadbuttFromMenu @@ -1193,76 +1215,80 @@ HeadbuttFunction: ld [wFieldMoveSucceeded], a ret -TryHeadbuttFromMenu: ; ce89 (3:4e89) +TryHeadbuttFromMenu: call GetFacingTileCoord call CheckHeadbuttTreeTile - jr nz, .asm_ce9a - ld hl, HeadbuttFromMenuScript ; $4eaa + jr nz, .no_tree + + ld hl, HeadbuttFromMenuScript call QueueScript ld a, $81 ret -.asm_ce9a +.no_tree call FieldMoveFailed ld a, $80 ret -; ceaa -Text_DidAHeadbutt: - text_far Text_DidAHeadbutt_ - db "@" +UseHeadbuttText: + text_far _UseHeadbuttText + text_end -Text_NothingFromHeadbutt: - text_far Text_NothingFromHeadbutt_ - db "@" +HeadbuttNothingText: + text_far _HeadbuttNothingText + text_end HeadbuttFromMenuScript: reloadmappart special UpdateTimePals + HeadbuttScript: - callasm FieldMoveGetPartyNick - writetext Text_DidAHeadbutt + callasm GetPartyNick + writetext UseHeadbuttText + reloadmappart callasm ShakeHeadbuttTree + callasm TreeMonEncounter - iffalse .nope_nothing + iffalse .no_battle closetext randomwildmon startbattle reloadmapafterbattle end -.nope_nothing: - writetext Text_NothingFromHeadbutt +.no_battle + writetext HeadbuttNothingText waitbutton closetext end TryHeadbuttOW:: ld d, HEADBUTT - call FieldMovePartyCheck - jr c, .asm_cedd + call CheckPartyMove + jr c, .no + ld a, BANK(AskHeadbuttScript) - ld hl, AskHeadbuttScript ; $4edf + ld hl, AskHeadbuttScript call CallScript scf ret -.asm_cedd +.no xor a ret AskHeadbuttScript: opentext - writetext Text_AskHeadbutt + writetext AskHeadbuttText yesorno iftrue HeadbuttScript closetext end -Text_AskHeadbutt: ; cee9 - text_far Text_AskHeadbutt_ - db "@" +AskHeadbuttText: + text_far _AskHeadbuttText + text_end RockSmashFunction: call TryRockSmashFromMenu @@ -1270,177 +1296,178 @@ RockSmashFunction: ld [wFieldMoveSucceeded], a ret -TryRockSmashFromMenu: ; cef7 (3:4ef7) +TryRockSmashFromMenu: call GetFacingObject - jr c, .asm_cf0a + jr c, .no_rock ld a, d cp $18 - jr nz, .asm_cf0a - ld hl, RockSmashFromMenuScript ; $4f31 + jr nz, .no_rock + + ld hl, RockSmashFromMenuScript call QueueScript ld a, $81 ret -.asm_cf0a +.no_rock call FieldMoveFailed ld a, $80 ret -GetFacingObject: ; cf10 (3:4f10) +GetFacingObject: farcall CheckFacingObject - jr nc, .asm_cf2f + jr nc, .fail + ldh a, [hObjectStructIndexBuffer] call GetObjectStruct - ld hl, $1 + ld hl, OBJECT_MAP_OBJECT_INDEX add hl, bc ld a, [hl] ldh [hLastTalked], a call GetMapObject - ld hl, $4 + ld hl, MAPOBJECT_MOVEMENT add hl, bc ld a, [hl] ld d, a and a ret -.asm_cf2f +.fail scf ret -RockSmashFromMenuScript: ; cf31 +RockSmashFromMenuScript: reloadmappart special UpdateTimePals + RockSmashScript: - callasm FieldMoveGetPartyNick - writetext Text_UsedRockSmash + callasm GetPartyNick + writetext UseRockSmashText closetext special WaitSFX playsound SFX_STRENGTH earthquake 84 - applymovementlasttalked RockSmashMovementData + applymovementlasttalked MovementData_RockSmash disappear -2 callasm RockMonEncounter readmem wTempWildMonSpecies - iffalse .skip_battle + iffalse .done randomwildmon startbattle reloadmapafterbattle -.skip_battle +.done end -RockSmashMovementData: +MovementData_RockSmash: rock_smash 10 step_end -Text_UsedRockSmash: - text_far Text_UsedRockSmash_ - db "@" -; cf60 +UseRockSmashText: + text_far _UseRockSmashText + text_end + AskRockSmashScript: - callasm TryRockSmashOW - ifequal 1, .fail + callasm HasRockSmash + ifequal 1, .no + opentext - writetext Text_AskRockSmash + writetext AskRockSmashText yesorno iftrue RockSmashScript closetext end -.fail - jumptext Text_MayBeBreakable +.no + jumptext MaySmashText -Text_MayBeBreakable: - text_far Text_MayBeBreakable_ - db "@" +MaySmashText: + text_far _MaySmashText + text_end -Text_AskRockSmash: - text_far Text_AskRockSmash_ - db "@" +AskRockSmashText: + text_far _AskRockSmashText + text_end -TryRockSmashOW: ; cf7f +HasRockSmash: ld d, ROCK_SMASH - call FieldMovePartyCheck - jr nc, .asm_cf8a - ld a, $1 - jr .asm_cf8d - -.asm_cf8a + call CheckPartyMove + jr nc, .yes +.no + ld a, 1 + jr .done +.yes xor a - jr .asm_cf8d - -.asm_cf8d + jr .done +.done ld [wScriptVar], a ret -FishingRodFunction: ; cf91 +FishFunction: ld a, e push af - call FieldMoveBufferReset + call FieldMoveJumptableReset pop af ld [wBuffer2], a -.asm_cf9a - ld hl, .Jumptable ; $4fa8 - call DoFieldMoveAction - jr nc, .asm_cf9a +.loop + ld hl, .FishTable + call FieldMoveJumptable + jr nc, .loop and $7f ld [wFieldMoveSucceeded], a ret -.Jumptable - dw Fish_CheckMap ; 3:4fb2 - dw Fish_NoBite ; 3:5005 - dw Fish_GotSomething ; 3:4ff7 - dw Fish_Failed ; 3:4ff4 - dw Fish_NoFish ; 3:5013 +.FishTable: + dw .TryFish + dw .FishNoBite + dw .FishGotSomething + dw .FailFish + dw .FishNoFish -Fish_CheckMap: +.TryFish: ld a, [wPlayerState] cp PLAYER_SURF - jr z, .asm_cfc7 + jr z, .fail cp PLAYER_SURF_PIKA - jr z, .asm_cfc7 + jr z, .fail call GetFacingTileCoord call GetTileCollision - cp $1 - jr z, .asm_cfca -.asm_cfc7 + cp WATER_TILE + jr z, .facingwater +.fail ld a, $3 ret -.asm_cfca +.facingwater call GetFishingGroup and a - jr nz, .asm_cfd3 + jr nz, .goodtofish ld a, $4 ret -.asm_cfd3 +.goodtofish ld d, a ld a, [wBuffer2] ld e, a - ld a, $24 - ld hl, $697a - rst FarCall + farcall Fish ld a, d and a - jr z, .asm_cff1 + jr z, .nonibble ld [wTempWildMonSpecies], a ld a, e ld [wCurPartyLevel], a - ld a, $4 + ld a, BATTLETYPE_FISH ld [wBattleType], a ld a, $2 ret -.asm_cff1 +.nonibble ld a, $1 ret -Fish_Failed: +.FailFish: ld a, $80 ret -Fish_GotSomething: +.FishGotSomething: ld a, $1 ld [wBuffer6], a ld hl, Script_GotABite @@ -1448,7 +1475,7 @@ Fish_GotSomething: ld a, $81 ret -Fish_NoBite: +.FishNoBite: ld a, $2 ld [wBuffer6], a ld hl, Script_NotEvenANibble @@ -1456,7 +1483,7 @@ Fish_NoBite: ld a, $81 ret -Fish_NoFish: +.FishNoFish: ld a, $0 ld [wBuffer6], a ld hl, Script_NotEvenANibble2 @@ -1464,32 +1491,34 @@ Fish_NoFish: ld a, $81 ret -Script_NotEvenANibble: ; d021 +Script_NotEvenANibble: scall Script_FishCastRod - writetext Text_NotEvenANibble - sjump Script_NotEvenANibble_Continue + writetext RodNothingText + sjump Script_NotEvenANibble_FallThrough Script_NotEvenANibble2: scall Script_FishCastRod - writetext Text_NotEvenANibble -Script_NotEvenANibble_Continue: + writetext RodNothingText + +Script_NotEvenANibble_FallThrough: callasm PutTheRodAway closetext end Script_GotABite: scall Script_FishCastRod - callasm Fish_CheckFacingUp - iffalse .not_facing_up - applymovement 0, Movement_Fishing_BiteFacingUp - sjump .continue - -.not_facing_up - applymovement 0, Movement_Fishing_BiteNotFacingUp -.continue + callasm Fishing_CheckFacingUp + iffalse .NotFacingUp + applymovement PLAYER, .Movement_FacingUp + sjump .FightTheHookedPokemon + +.NotFacingUp: + applymovement PLAYER, .Movement_NotFacingUp + +.FightTheHookedPokemon: pause 40 - applymovement 0, Movement_Fishing_RestoreRod - writetext Text_OhABite + applymovement PLAYER, .Movement_RestoreRod + writetext RodBiteText callasm PutTheRodAway closetext randomwildmon @@ -1497,8 +1526,7 @@ Script_GotABite: reloadmapafterbattle end - -Movement_Fishing_BiteNotFacingUp: +.Movement_NotFacingUp: fish_got_bite fish_got_bite fish_got_bite @@ -1506,7 +1534,7 @@ Movement_Fishing_BiteNotFacingUp: show_emote step_end -Movement_Fishing_BiteFacingUp: +.Movement_FacingUp: fish_got_bite fish_got_bite fish_got_bite @@ -1515,38 +1543,39 @@ Movement_Fishing_BiteFacingUp: show_emote step_end -Movement_Fishing_RestoreRod: +.Movement_RestoreRod: hide_emote fish_cast_rod step_end -Fish_CheckFacingUp: ; d06d +Fishing_CheckFacingUp: ld a, [wPlayerDirection] and $c cp OW_UP ld a, $1 - jr z, .asm_d079 + jr z, .up xor a -.asm_d079 + +.up ld [wScriptVar], a ret -Script_FishCastRod: ; d07d +Script_FishCastRod: reloadmappart loadmem hBGMapMode, $0 special UpdateTimePals loademote EMOTE_ROD callasm LoadFishingGFX loademote EMOTE_SHOCK - applymovement PLAYER, Movement_CastRod + applymovement PLAYER, MovementData_CastRod pause 40 end -Movement_CastRod: +MovementData_CastRod: fish_cast_rod step_end -PutTheRodAway: ; d096 +PutTheRodAway: hlcoord 1, 14 lb bc, $3, $12 call ClearBox @@ -1559,38 +1588,38 @@ PutTheRodAway: ; d096 call ReplaceChrisSprite ret -Text_OhABite: - text_far Text_OhABite_ - db "@" +RodBiteText: + text_far _RodBiteText + text_end -Text_NotEvenANibble: - text_far Text_NotEvenANibble_ - db "@" +RodNothingText: + text_far _RodNothingText + text_end -Text_NothingHereToFish: - text_far Text_NothingHereToFish_ - db "@" +UnusedNothingHereText: ; unused + text_far _UnusedNothingHereText + text_end -BicycleFunction: - call Functiond0c9 +BikeFunction: + call .TryBike and $7f ld [wFieldMoveSucceeded], a ret -Functiond0c9: ; d0c9 (3:50c9) - call CheckBikePermission - jr c, .cant_bike +.TryBike: + call .CheckEnvironment + jr c, .CannotUseBike ld a, [wPlayerState] cp PLAYER_NORMAL - jr z, .get_on_bike + jr z, .GetOnBike cp PLAYER_BIKE - jr z, .get_off_bike - jr .cant_bike + jr z, .GetOffBike + jr .CannotUseBike -.get_on_bike +.GetOnBike: ld hl, Script_GetOnBike ld de, Script_GetOnBike_Register - call ChooseScriptBasedOnWhetherBikeIsRegistered + call .CheckIfRegistered call QueueScript xor a ld [wMusicFade], a @@ -1605,30 +1634,30 @@ Functiond0c9: ; d0c9 (3:50c9) ld a, $1 ret -.get_off_bike +.GetOffBike: ld hl, wBikeFlags - bit 1, [hl] - jr nz, .asm_d118 + bit BIKEFLAGS_ALWAYS_ON_BIKE_F, [hl] + jr nz, .CantGetOffBike ld hl, Script_GetOffBike ld de, Script_GetOffBike_Register - call ChooseScriptBasedOnWhetherBikeIsRegistered - ld a, $3 - jr .queue_off + call .CheckIfRegistered + ld a, BANK(Script_GetOffBike) + jr .done -.asm_d118 +.CantGetOffBike: ld hl, Script_CantGetOffBike - jr .queue_off + jr .done -.cant_bike +.CannotUseBike: ld a, $0 ret -.queue_off +.done call QueueScript ld a, $1 ret -ChooseScriptBasedOnWhetherBikeIsRegistered: ; d126 (3:5126) +.CheckIfRegistered: ld a, [wUsingItemWithSelect] and a ret z @@ -1636,28 +1665,28 @@ ChooseScriptBasedOnWhetherBikeIsRegistered: ; d126 (3:5126) ld l, e ret -CheckBikePermission: ; d12e (3:512e) +.CheckEnvironment: call GetMapEnvironment call CheckOutdoorMap - jr z, .asm_d140 + jr z, .ok cp CAVE - jr z, .asm_d140 + jr z, .ok cp GATE - jr z, .asm_d140 - jr .asm_d149 + jr z, .ok + jr .nope -.asm_d140 +.ok call GetPlayerStandingTile - and $f - jr nz, .asm_d149 + and $f ; lo nybble only + jr nz, .nope ; not FLOOR_TILE xor a ret -.asm_d149 +.nope scf ret -Script_GetOnBike: ; d14b +Script_GetOnBike: reloadmappart special UpdateTimePals loadvar VAR_MOVEMENT, PLAYER_BIKE @@ -1673,6 +1702,7 @@ Script_GetOnBike_Register: special ReplaceChrisSprite end +; unused nop ret @@ -1682,6 +1712,7 @@ Script_GetOffBike: loadvar VAR_MOVEMENT, PLAYER_NORMAL writetext GotOffBikeText waitbutton + FinishGettingOffBike: closetext special ReplaceChrisSprite @@ -1710,54 +1741,55 @@ GotOffBikeText: text_far _GotOffBikeText text_end - TryCutOW:: ld d, CUT - call FieldMovePartyCheck - jr c, .asm_d1ac + call CheckPartyMove + jr c, .cant_cut + ld de, ENGINE_HIVEBADGE - call FieldMoveEngineFlagCheck - jr c, .asm_d1ac + call CheckEngineFlag + jr c, .cant_cut + ld a, BANK(AskCutScript) ld hl, AskCutScript call CallScript scf ret -.asm_d1ac +.cant_cut ld a, BANK(CantCutScript) ld hl, CantCutScript call CallScript scf ret -AskCutScript: ; d1b6 +AskCutScript: opentext - writetext Text_AskCut + writetext AskCutText yesorno iffalse .declined - callasm CheckMapForSomethingToCut_ + callasm .CheckMap iftrue Script_Cut -.declined: +.declined closetext end -CheckMapForSomethingToCut_: ; d1c7 +.CheckMap: xor a ld [wScriptVar], a call CheckMapForSomethingToCut ret c - ld a, $1 + ld a, TRUE ld [wScriptVar], a ret -Text_AskCut: - text_far Text_AskCut_ - db "@" +AskCutText: + text_far _AskCutText + text_end -CantCutScript: ; d1da - jumptext Text_MonCanCutThis +CantCutScript: + jumptext CanCutText -Text_MonCanCutThis: - text_far Text_MonCanCutThis_ - db "@" +CanCutText: + text_far _CanCutText + text_end diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index dccbd51b..e5a0960b 100755 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -1005,7 +1005,7 @@ TownMap: ; ee55 (3:6e55) ret Bicycle: ; ee5c - farcall BicycleFunction ; same bank + farcall BikeFunction ; same bank ret FireStone: ; ee63 @@ -2146,7 +2146,7 @@ SuperRod: ; f5f4 (3:75f4) jr UseRod UseRod: - farcall FishingRodFunction ; same bank + farcall FishFunction ret ItemfinderEffect: ; f5ff (3:75ff) diff --git a/engine/movement_pattern.asm b/engine/movement_pattern.asm deleted file mode 100755 index 29d09229..00000000 --- a/engine/movement_pattern.asm +++ /dev/null @@ -1,651 +0,0 @@ -RestoreDefaultMovement: - ld hl, $1 - add hl, bc - ld a, [hl] - cp $ff - jr z, .asm_4756 - push bc - call GetMapObject - ld hl, $4 - add hl, bc - ld a, [hl] - pop bc - ret - -.asm_4756 - ld a, $6 - ret - -ClearObjectMovementByteIndex: - ld hl, $1b - add hl, bc - ld [hl], $0 - ret - -IncrementObjectMovementByteIndex: - ld hl, $1b - add hl, bc - inc [hl] - ret - -DecrementObjectMovementByteIndex: - ld hl, $1b - add hl, bc - dec [hl] - ret - -MovementAnonymousJumptable: - ld hl, $1b - add hl, bc - ld a, [hl] - pop hl - rst JumpTable - ret - -ClearObjectStructField28: - ld hl, $1c - add hl, bc - ld [hl], $0 - ret - -IncrementObjectStructField28: - ld hl, $1c - add hl, bc - inc [hl] - ret - -Object28AnonymousJumptable: - ld hl, $1c - add hl, bc - ld a, [hl] - pop hl - rst JumpTable - ret - -GetValueObjectStructField28: - ld hl, $1c - add hl, bc - ld a, [hl] - ret - -SetValueObjectStructField28: - ld hl, $1c - add hl, bc - ld [hl], a - ret - -ObjectMovementReset: ; 4795 (1:4795) - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - push bc - call GetCoordTile - pop bc - ld hl, $e - add hl, bc - ld [hl], a - call CopyNextCoordsTileToStandingCoordsTile - call EndSpriteMovement - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -MapObjectMovementPattern: ; 47b6 (1:47b6) - call ClearObjectStructField28 - call GetSpriteMovementFunction - ld a, [hl] - ld hl, .Pointers - rst JumpTable - ret - -.Pointers: - dw Function47fa - dw Function47fb - dw Function4805 - dw Function4811 - dw Function481b - dw Function482a - dw Function4842 - dw Function4855 - dw Function485b - dw Function4861 - dw Function4867 - dw Function486a - dw Function486d - dw Function4870 - dw Function4876 - dw Function4879 - dw Function487f - dw Function4885 - dw Function48d8 - dw Function49be - dw Function49fa - dw Function4931 - dw Function4947 - dw Function4a95 - dw Function4966 - dw Function495d - dw Function4a1f - dw Function4a62 - -Function47fa: - ret - -Function47fb: ; 47fb (1:47fb) - call Random - ldh a, [hRandom] - and $1 - jp Function4ac9 - -Function4805: ; 4805 (1:4805) - call Random - ldh a, [hRandom] - and $1 - or $2 - jp Function4ac9 - -Function4811: ; 4811 (1:4811) - call Random - ldh a, [hRandom] - and $3 - jp Function4ac9 - -Function481b: ; 481b (1:481b) - call Random - ldh a, [hRandom] - and $c - ld hl, $8 - add hl, bc - ld [hl], a - jp Function4af6 - -Function482a: ; 482a (1:482a) - ld hl, $8 - add hl, bc - ld a, [hl] - and $c - ld d, a - call Random - ldh a, [hRandom] - and $c - cp d - jr nz, .asm_483e - xor $c -.asm_483e - ld [hl], a - jp Function4aff - -Function4842: ; 4842 (1:4842) - call Function4603 - call EndSpriteMovement - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, $9 - add hl, bc - ld [hl], $5 - ret - -Function4855: ; 4855 (1:4855) - ld hl, $4fa8 - jp Function4fe9 - -Function485b: ; 485b (1:485b) - ld hl, $4fbd - jp Function4fe9 - -Function4861: ; 4861 (1:4861) - ld hl, $4fce - jp Function4fe9 - -Function4867: ; 4867 (1:4867) - jp Function4fdf - -Function486a: ; 486a (1:486a) - jp Function4fdf - -Function486d: ; 486d (1:486d) - jp Function4fdf - -Function4870: ; 4870 (1:4870) - ld hl, $4fa8 - jp Function4fe9 - -Function4876: ; 4876 (1:4876) - jp Function4fdf - -Function4879: ; 4879 (1:4879) - ld hl, $5485 - jp Function4fe9 - -Function487f: ; 487f (1:487f) - ld hl, $4fb6 - jp Function4fe9 - -Function4885: ; 4885 (1:4885) - call MovementAnonymousJumptable - dw .asm_488c - dw .asm_48d1 - -.asm_488c - ld hl, $e - add hl, bc - ld a, [hl] - call CheckPitTile - jr z, .asm_48ce - ld hl, $5 - add hl, bc - bit 2, [hl] - res 2, [hl] - jr z, .asm_48c7 - ld hl, $20 - add hl, bc - ld a, [hl] - and $3 - or $0 - call InitStep - call CheckNPCMovementPermissions - jr c, .asm_48c4 - ld de, $1b - call PlaySFX - call Function54d7 - call UpdateGrassPriority - ld hl, $9 - add hl, bc - ld [hl], $f - ret - -.asm_48c4 - call Function4603 -.asm_48c7 - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -.asm_48ce - call IncrementObjectMovementByteIndex -.asm_48d1 - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -Function48d8: ; 48d8 (1:48d8) - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - ld hl, $20 - add hl, bc - ld a, [hl] - push bc - call GetObjectStruct - ld hl, $7 - add hl, bc - ld a, [hl] - cp $ff - jr z, .asm_4923 - ld hl, $12 - add hl, bc - ld a, [hl] - cp d - jr z, .asm_4906 - jr c, .asm_4902 - ld a, $3 - jr .asm_4916 - -.asm_4902 - ld a, $2 - jr .asm_4916 - -.asm_4906 - ld hl, $13 - add hl, bc - ld a, [hl] - cp e - jr z, .asm_4923 - jr c, .asm_4914 - ld a, $0 - jr .asm_4916 - -.asm_4914 - ld a, $1 -.asm_4916 - ld d, a - ld hl, $7 - add hl, bc - ld a, [hl] - and $c - or d - pop bc - jp Function53b1 - -.asm_4923 - pop bc - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $b - add hl, bc - ld [hl], $1 - ret - -Function4931: ; 4931 (1:4931) - call EndSpriteMovement - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $b - add hl, bc - ld [hl], $9 - ld hl, $9 - add hl, bc - ld [hl], $4 - ret - -Function4947: ; 4947 (1:4947) - call EndSpriteMovement - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $b - add hl, bc - ld [hl], $a - ld hl, $9 - add hl, bc - ld [hl], $4 - ret - -Function495d: ; 495d (1:495d) - call MovementAnonymousJumptable - dw Function496f - dw Function4975 - dw Function4991 - -Function4966: ; 4966 (1:4966) - call MovementAnonymousJumptable - dw Function496f - dw Function4975 - dw Function499d - -Function496f: - call EndSpriteMovement - call IncrementObjectMovementByteIndex -Function4975: - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, $20 - add hl, bc - ld a, [hl] - ld a, $10 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $3 - call IncrementObjectMovementByteIndex - ret - -Function4991: - ld de, .data - call Function49a9 - jr Function495d - -.data - db OW_RIGHT, OW_LEFT, OW_DOWN, OW_UP - -Function499d: - ld de, .data - call Function49a9 - jr Function4966 - -.data - db OW_LEFT, OW_RIGHT, OW_UP, OW_DOWN - -Function49a9: ; 49a9 (1:49a9) - ld hl, $8 - add hl, bc - ld a, [hl] - and $c - rrca - rrca - push hl - ld l, a - ld h, $0 - add hl, de - ld a, [hl] - pop hl - ld [hl], a - call DecrementObjectMovementByteIndex - ret - -Function49be: ; 49be (1:49be) - call Function4a81 - ld hl, $b - add hl, bc - ld [hl], $7 - ld hl, $a - add hl, de - ld a, [hl] - inc a - add a - add $0 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $7 - add hl, de - ld a, [hl] - and $3 - ld d, $e - cp $0 - jr z, .asm_49e8 - cp $1 - jr z, .asm_49e8 - ld d, $c -.asm_49e8 - ld hl, $1a - add hl, bc - ld [hl], d - ld hl, $19 - add hl, bc - ld [hl], $0 - ld hl, $9 - add hl, bc - ld [hl], $13 - ret - -Function49fa: ; 49fa (1:49fa) - call EndSpriteMovement - call Function4a81 - ld hl, $b - add hl, bc - ld [hl], $8 - ld hl, $a - add hl, bc - ld [hl], $0 - ld hl, $1a - add hl, bc - ld [hl], $f0 - ld hl, $19 - add hl, bc - ld [hl], $0 - ld hl, $9 - add hl, bc - ld [hl], $13 - ret - -Function4a1f: ; 4a1f (1:4a1f) - call EndSpriteMovement - call Function4a81 - ld hl, $b - add hl, bc - ld [hl], $e - ld hl, $a - add hl, de - ld a, [hl] - inc a - add a - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $7 - add hl, de - ld a, [hl] - and $3 - ld e, a - ld d, $0 - ld hl, .data - add hl, de - add hl, de - ld d, [hl] - inc hl - ld e, [hl] - ld hl, $19 - add hl, bc - ld [hl], d - ld hl, $1a - add hl, bc - ld [hl], e - ld hl, $9 - add hl, bc - ld [hl], $13 - ret - -.data - ; x, y - db 0, -4 - db 0, 8 - db 6, 2 - db -6, 2 - -Function4a62: ; 4a62 (1:4a62) - call EndSpriteMovement - call Function4a81 - ld hl, $b - add hl, bc - ld [hl], $f - ld hl, $a - add hl, de - ld a, [hl] - add $ff - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $13 - ret - -Function4a81: ; 4a81 (1:4a81) - ld hl, $20 - add hl, bc - ld a, [hl] - push bc - call GetObjectStruct - ld d, b - ld e, c - pop bc - ld hl, $1d - add hl, bc - ld [hl], e - inc hl - ld [hl], d - ret - -Function4a95: ; 4a95 (1:4a95) - call EndSpriteMovement - ld hl, $b - add hl, bc - ld [hl], $0 - ld hl, $20 - add hl, bc - ld a, [hl] - call Function4ab7 - ld hl, $a - add hl, bc - ld [hl], e - ld hl, $1e - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $15 - ret - -Function4ab7: ; 4ab7 (1:4ab7) - ld d, a - and $3f - ld e, a - ld a, d - rlca - rlca - and $3 - ld d, a - inc d - ld a, $1 -.asm_4ac4 - dec d - ret z - add a - jr .asm_4ac4 - -Function4ac9: ; 4ac9 (1:4ac9) - call InitStep - call CheckNPCMovementPermissions - jr c, .asm_4af0 - call UpdateGrassPriority - ld hl, $b - add hl, bc - ld [hl], $2 - ld hl, wCenteredObject - ldh a, [hConnectionStripLength] - cp [hl] - jr z, .asm_4ae9 - ld hl, $9 - add hl, bc - ld [hl], $7 - ret - -.asm_4ae9 - ld hl, $9 - add hl, bc - ld [hl], $6 - ret - -.asm_4af0 - call EndSpriteMovement - call Function4603 -Function4af6: ; 4af6 (1:4af6) - call Random - ldh a, [hRandom] - and $7f - jr asm_4b06 - -Function4aff: ; 4aff (1:4aff) - call Random - ldh a, [hRandomAdd] - and $1f -asm_4b06: - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, $9 - add hl, bc - ld [hl], $3 - ret diff --git a/engine/overworld/map_object_action.asm b/engine/overworld/map_object_action.asm index 7701ec4f..8f749f84 100755 --- a/engine/overworld/map_object_action.asm +++ b/engine/overworld/map_object_action.asm @@ -1,260 +1,264 @@ - ld hl, $b - add hl, bc - ld a, [hl] - ld l, a - ld h, $0 - add hl, hl - add hl, hl - add hl, de - ld a, [hli] - ld h, [hl] - ld l, a - call _hl_ - ret +ObjectActionPairPointers: +; entries correspond to OBJECT_ACTION_* constants + dw SetFacingStanding, SetFacingStanding + dw SetFacingStandAction, SetFacingCurrent + dw SetFacingStepAction, SetFacingCurrent + dw SetFacingBumpAction, SetFacingCurrent + dw SetFacingCounterclockwiseSpin, SetFacingCurrent + dw SetFacingCounterclockwiseSpin2, SetFacingStanding + dw SetFacingFish, SetFacingFish + dw SetFacingShadow, SetFacingStanding + dw SetFacingEmote, SetFacingEmote + dw SetFacingBigDollSym, SetFacingBigDollSym + dw SetFacingBounce, SetFacingFreezeBounce + dw SetFacingWeirdTree, SetFacingCurrent + dw SetFacingBigDollAsym, SetFacingBigDollAsym + dw SetFacingBigDoll, SetFacingBigDoll + dw SetFacingBoulderDust, SetFacingStanding + dw SetFacingGrassShake, SetFacingStanding -Pointers4460: - dw Function44a0, Function44a0 - dw Function44b2, Function44a7 - dw Function44be, Function44a7 - dw Function44e1, Function44a7 - dw Function4502, Function44a7 - dw Function4512, Function44a0 - dw Function4547, Function4547 - dw Function4554, Function44a0 - dw Function455b, Function455b - dw Function4562, Function4562 - dw Function4569, Function457d - dw Function4584, Function44a7 - dw Function4597, Function4597 - dw Function459e, Function459e - dw Function45b3, Function44a0 - dw Function45c6, Function44a0 - -Function44a0: - ld hl, $d +SetFacingStanding: + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $ff + ld [hl], STANDING ret -Function44a7: ; 44a7 (1:44a7) +SetFacingCurrent: call GetSpriteDirection - or $0 - ld hl, $d + or FACING_STEP_DOWN_0 ; useless + ld hl, OBJECT_FACING_STEP add hl, bc ld [hl], a ret -Function44b2: - ld hl, $d +SetFacingStandAction: + ld hl, OBJECT_FACING_STEP add hl, bc ld a, [hl] - and $1 - jr nz, Function44be - jp Function44a7 + and 1 + jr nz, SetFacingStepAction + jp SetFacingCurrent -Function44be: - ld hl, $4 +SetFacingStepAction: + ld hl, OBJECT_FLAGS1 add hl, bc - bit 3, [hl] - jp nz, Function44a7 - ld hl, $c + bit SLIDING_F, [hl] + jp nz, SetFacingCurrent + + ld hl, OBJECT_STEP_FRAME add hl, bc ld a, [hl] inc a - and $f + and %00001111 ld [hl], a + rrca rrca - and $3 + maskbits NUM_DIRECTIONS ld d, a + call GetSpriteDirection - or $0 + or FACING_STEP_DOWN_0 ; useless or d - ld hl, $d + ld hl, OBJECT_FACING_STEP add hl, bc ld [hl], a ret -Function44e1: - ld hl, $4 +SetFacingBumpAction: + ld hl, OBJECT_FLAGS1 add hl, bc - bit 3, [hl] - jp nz, Function44a7 - ld hl, $c + bit SLIDING_F, [hl] + jp nz, SetFacingCurrent + + ld hl, OBJECT_STEP_FRAME add hl, bc inc [hl] + ld a, [hl] rrca rrca rrca - and $3 + maskbits NUM_DIRECTIONS ld d, a + call GetSpriteDirection - or $0 + or FACING_STEP_DOWN_0 ; useless or d - ld hl, $d + ld hl, OBJECT_FACING_STEP add hl, bc ld [hl], a ret -Function4502: - call Function4518 - ld hl, $8 +SetFacingCounterclockwiseSpin: + call CounterclockwiseSpinAction + ld hl, OBJECT_FACING add hl, bc ld a, [hl] - or $0 - ld hl, $d + or FACING_STEP_DOWN_0 ; useless + ld hl, OBJECT_FACING_STEP add hl, bc ld [hl], a ret -Function4512: - call Function4518 - jp Function44a0 +SetFacingCounterclockwiseSpin2: + call CounterclockwiseSpinAction + jp SetFacingStanding -Function4518: ; 4518 (1:4518) - ld hl, $c +CounterclockwiseSpinAction: +; Here, OBJECT_STEP_FRAME consists of two 2-bit components, +; using only bits 0,1 and 4,5. +; bits 0,1 is a timer (4 overworld frames) +; bits 4,5 determines the facing - the direction is counterclockwise. + ld hl, OBJECT_STEP_FRAME add hl, bc ld a, [hl] - and $f0 + and %11110000 ld e, a + ld a, [hl] inc a - and $f + and %00001111 ld d, a - cp $4 - jr c, .asm_4531 - ld d, $0 + cp 4 + jr c, .ok + + ld d, 0 ld a, e add $10 - and $30 + and %00110000 ld e, a -.asm_4531 + +.ok ld a, d or e ld [hl], a + swap e - ld d, $0 - ld hl, .directions + ld d, 0 + ld hl, .Directions add hl, de ld a, [hl] - ld hl, $8 + ld hl, OBJECT_FACING add hl, bc ld [hl], a ret -.directions +.Directions: db OW_DOWN, OW_RIGHT, OW_UP, OW_LEFT -Function4547: +SetFacingFish: call GetSpriteDirection rrca rrca - add $10 - ld hl, $d + add FACING_FISH_DOWN + ld hl, OBJECT_FACING_STEP add hl, bc ld [hl], a ret -Function4554: - ld hl, $d +SetFacingShadow: + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $15 + ld [hl], FACING_SHADOW ret -Function455b: - ld hl, $d +SetFacingEmote: + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $14 + ld [hl], FACING_EMOTE ret -Function4562: - ld hl, $d +SetFacingBigDollSym: + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $17 + ld [hl], FACING_BIG_DOLL_SYM ret -Function4569: - ld hl, $c +SetFacingBounce: + ld hl, OBJECT_STEP_FRAME add hl, bc ld a, [hl] inc a - and $f + and %00001111 ld [hl], a - and $8 - jr z, Function457d - ld hl, $d + and %00001000 + jr z, SetFacingFreezeBounce + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $4 + ld [hl], FACING_STEP_UP_0 ret -Function457d: - ld hl, $d +SetFacingFreezeBounce: + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $0 + ld [hl], FACING_STEP_DOWN_0 ret -Function4584: - ld hl, $c +SetFacingWeirdTree: + ld hl, OBJECT_STEP_FRAME add hl, bc ld a, [hl] inc a ld [hl], a - and $c + maskbits NUM_DIRECTIONS, 2 rrca rrca - add $18 - ld hl, $d + add FACING_WEIRD_TREE_0 + ld hl, OBJECT_FACING_STEP add hl, bc ld [hl], a ret -Function4597: - ld hl, $d +SetFacingBigDollAsym: + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $16 + ld [hl], FACING_BIG_DOLL_ASYM ret -Function459e: +SetFacingBigDoll: ld a, [wVariableSprites + SPRITE_BIG_DOLL - SPRITE_VARS] - ld d, $17 - cp $33 - jr z, .asm_45ad - cp $47 - jr z, .asm_45ad - ld d, $16 -.asm_45ad - ld hl, $d + ld d, FACING_BIG_DOLL_SYM ; symmetric + cp SPRITE_BIG_SNORLAX + jr z, .ok + cp SPRITE_BIG_LAPRAS + jr z, .ok + ld d, FACING_BIG_DOLL_ASYM ; asymmetric + +.ok + ld hl, OBJECT_FACING_STEP add hl, bc ld [hl], d ret -Function45b3: - ld hl, $c +SetFacingBoulderDust: + ld hl, OBJECT_STEP_FRAME add hl, bc inc [hl] ld a, [hl] - ld hl, $d + + ld hl, OBJECT_FACING_STEP add hl, bc - and $2 - ld a, $1c - jr z, .asm_45c4 - inc a -.asm_45c4 + and 2 + ld a, FACING_BOULDER_DUST_1 + jr z, .ok + inc a ; FACING_BOULDER_DUST_2 +.ok ld [hl], a ret -Function45c6: - ld hl, $c +SetFacingGrassShake: + ld hl, OBJECT_STEP_FRAME add hl, bc inc [hl] ld a, [hl] - ld hl, $d + ld hl, OBJECT_FACING_STEP add hl, bc - and $4 - ld a, $1e - jr z, .asm_45d7 - inc a -.asm_45d7 + and 4 + ld a, FACING_GRASS_1 + jr z, .ok + inc a ; FACING_GRASS_2 + +.ok ld [hl], a ret diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index a59be34f..25f3720f 100755 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -2,27 +2,27 @@ INCLUDE "data/sprites/facings.asm" INCLUDE "data/sprites/map_objects.asm" -DeleteMapObject:: ; 4358 (1:4358) +DeleteMapObject:: push bc - ld hl, $1 + ld hl, OBJECT_MAP_OBJECT_INDEX add hl, bc ld a, [hl] push af ld h, b ld l, c - ld bc, $28 + ld bc, OBJECT_LENGTH xor a call ByteFill pop af - cp $ff - jr z, .asm_437a + cp -1 + jr z, .ok bit 7, a - jr nz, .asm_437a + jr nz, .ok call GetMapObject - ld hl, $0 + ld hl, OBJECT_SPRITE add hl, bc - ld [hl], $ff -.asm_437a + ld [hl], -1 +.ok pop bc ret @@ -33,306 +33,322 @@ Function437c: call .HandleObjectAction ret -.CheckObjectStillVisible: ; 4387 (1:4387) - ld hl, $5 +.CheckObjectStillVisible: + ld hl, OBJECT_FLAGS2 add hl, bc - res 6, [hl] + res OBJ_FLAGS2_6, [hl] ld a, [wXCoord] ld e, a - ld hl, $10 + ld hl, OBJECT_NEXT_MAP_X add hl, bc ld a, [hl] - add $1 + add 1 sub e - jr c, .asm_43b3 - cp $c - jr nc, .asm_43b3 + jr c, .ok + cp MAPOBJECT_SCREEN_WIDTH + jr nc, .ok ld a, [wYCoord] ld e, a - ld hl, $11 + ld hl, OBJECT_NEXT_MAP_Y add hl, bc ld a, [hl] - add $1 + add 1 sub e - jr c, .asm_43b3 - cp $b - jr nc, .asm_43b3 - jr .asm_43dd + jr c, .ok + cp MAPOBJECT_SCREEN_HEIGHT + jr nc, .ok + jr .yes -.asm_43b3 - ld hl, $5 +.ok + ld hl, OBJECT_FLAGS2 add hl, bc - set 6, [hl] + set OBJ_FLAGS2_6, [hl] ld a, [wXCoord] ld e, a - ld hl, $14 + ld hl, OBJECT_INIT_X add hl, bc ld a, [hl] - add $1 + add 1 sub e - jr c, .asm_43df - cp $c - jr nc, .asm_43df + jr c, .ok2 + cp MAPOBJECT_SCREEN_WIDTH + jr nc, .ok2 ld a, [wYCoord] ld e, a - ld hl, $15 + ld hl, OBJECT_INIT_Y add hl, bc ld a, [hl] - add $1 + add 1 sub e - jr c, .asm_43df - cp $b - jr nc, .asm_43df -.asm_43dd + jr c, .ok2 + cp MAPOBJECT_SCREEN_HEIGHT + jr nc, .ok2 +.yes and a ret -.asm_43df - ld hl, $4 +.ok2 + ld hl, OBJECT_FLAGS1 add hl, bc - bit 1, [hl] - jr nz, .asm_43ec + bit WONT_DELETE_F, [hl] + jr nz, .yes2 call DeleteMapObject scf ret -.asm_43ec - ld hl, $5 +.yes2 + ld hl, OBJECT_FLAGS2 add hl, bc - set 6, [hl] + set OBJ_FLAGS2_6, [hl] and a ret -.HandleStepType: ; 43f4 (1:43f4) - ld hl, $9 +.HandleStepType: + ld hl, OBJECT_STEP_TYPE add hl, bc ld a, [hl] and a - jr z, .asm_440a - ld hl, $5 + jr z, .zero + ld hl, OBJECT_FLAGS2 add hl, bc - bit 5, [hl] - jr nz, .asm_4427 - cp $1 - jr z, .asm_4415 - jr .asm_4422 + bit OBJ_FLAGS2_5, [hl] + jr nz, .bit5 + cp STEP_TYPE_SLEEP + jr z, .one + jr .ok3 -.asm_440a +.zero call ObjectMovementReset - ld hl, $5 + ld hl, OBJECT_FLAGS2 add hl, bc - bit 5, [hl] - jr nz, .asm_4427 -.asm_4415 + bit OBJ_FLAGS2_5, [hl] + jr nz, .bit5 +.one call MapObjectMovementPattern - ld hl, $9 + ld hl, OBJECT_STEP_TYPE add hl, bc ld a, [hl] and a ret z - cp $1 + cp STEP_TYPE_SLEEP ret z -.asm_4422 +.ok3 ld hl, StepTypesJumptable rst JumpTable ret -.asm_4427 +.bit5 ret -.HandleObjectAction: ; 4428 (1:4428) - ld hl, $4 +.HandleObjectAction: + ld hl, OBJECT_FLAGS1 add hl, bc - bit 0, [hl] - jr nz, Function44a0 - ld hl, $5 + bit INVISIBLE_F, [hl] + jr nz, SetFacingStanding + ld hl, OBJECT_FLAGS2 add hl, bc - bit 6, [hl] - jr nz, Function44a0 - bit 5, [hl] + bit OBJ_FLAGS2_6, [hl] + jr nz, SetFacingStanding + bit OBJ_FLAGS2_5, [hl] jr nz, asm_4449 - ld de, Pointers4460 + ld de, ObjectActionPairPointers ; use first column jr _HandleObjectAction Function4441: - ld hl, $4 + ld hl, OBJECT_FLAGS1 add hl, bc - bit 0, [hl] - jr nz, Function44a0 + bit INVISIBLE_F, [hl] + jr nz, SetFacingStanding asm_4449: - ld de, Pointers4460 + 2 + ld de, ObjectActionPairPointers + 2 ; use second column jr _HandleObjectAction _HandleObjectAction: +; call [4 * wObjectStructs[ObjInd, OBJECT_ACTION] + de] + ld hl, OBJECT_ACTION + add hl, bc + ld a, [hl] + ld l, a + ld h, 0 + add hl, hl + add hl, hl + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + call _hl_ + ret + INCLUDE "engine/overworld/map_object_action.asm" -CopyNextCoordsTileToStandingCoordsTile: ; 45d9 (1:45d9) - ld hl, $10 +CopyNextCoordsTileToStandingCoordsTile: + ld hl, OBJECT_NEXT_MAP_X add hl, bc ld a, [hl] - ld hl, $12 + ld hl, OBJECT_MAP_X add hl, bc ld [hl], a - ld hl, $11 + ld hl, OBJECT_NEXT_MAP_Y add hl, bc ld a, [hl] - ld hl, $13 + ld hl, OBJECT_MAP_Y add hl, bc ld [hl], a - ld hl, $e + ld hl, OBJECT_NEXT_TILE add hl, bc ld a, [hl] - ld hl, $f + ld hl, OBJECT_STANDING_TILE add hl, bc ld [hl], a - call SetGrassPriority - ld hl, $e + call SetTallGrassFlags + ld hl, OBJECT_NEXT_TILE add hl, bc ld a, [hl] call UselessAndA ret Function4603: - ld hl, $12 + ld hl, OBJECT_MAP_X add hl, bc ld a, [hl] - ld hl, $10 + ld hl, OBJECT_NEXT_MAP_X add hl, bc ld [hl], a - ld hl, $13 + ld hl, OBJECT_MAP_Y add hl, bc ld a, [hl] - ld hl, $11 + ld hl, OBJECT_NEXT_MAP_Y add hl, bc ld [hl], a ret -UpdateGrassPriority: - ld hl, $5 +UpdateTallGrassFlags: + ld hl, OBJECT_FLAGS2 add hl, bc - bit 3, [hl] - jr z, .asm_4628 - ld hl, $e + bit OVERHEAD_F, [hl] + jr z, .ok + ld hl, OBJECT_NEXT_TILE add hl, bc ld a, [hl] - call SetGrassPriority -.asm_4628 - ld hl, $e + call SetTallGrassFlags +.ok + ld hl, OBJECT_NEXT_TILE add hl, bc ld a, [hl] call UselessAndA - ret c - ld hl, $f + ret c ; never happens + ld hl, OBJECT_STANDING_TILE add hl, bc ld a, [hl] call UselessAndA ret -SetGrassPriority: ; 463a (1:463a) +SetTallGrassFlags: call CheckSuperTallGrassTile - jr z, .asm_4644 + jr z, .set call CheckGrassTile - jr c, .asm_464b -.asm_4644 - ld hl, $5 + jr c, .reset +.set + ld hl, OBJECT_FLAGS2 add hl, bc - set 3, [hl] + set OVERHEAD_F, [hl] ret -.asm_464b - ld hl, $5 +.reset + ld hl, OBJECT_FLAGS2 add hl, bc - res 3, [hl] + res OVERHEAD_F, [hl] ret -UselessAndA: ; 4652 (1:4652) +UselessAndA: and a ret EndSpriteMovement: xor a - ld hl, $c + ld hl, OBJECT_STEP_FRAME add hl, bc ld [hl], a - ld hl, $1b + ld hl, OBJECT_MOVEMENT_BYTE_INDEX add hl, bc ld [hli], a ld [hli], a ld [hli], a - ld [hl], a - ld hl, $7 + ld [hl], a ; OBJECT_1E + ld hl, OBJECT_DIRECTION_WALKING add hl, bc - ld [hl], $ff + ld [hl], STANDING ret InitStep: - ld hl, $7 + ld hl, OBJECT_DIRECTION_WALKING add hl, bc ld [hl], a - ld hl, $4 + ld hl, OBJECT_FLAGS1 add hl, bc - bit 2, [hl] + bit FIXED_FACING_F, [hl] jr nz, GetNextTile add a add a - and $c - ld hl, $8 + and %00001100 + ld hl, OBJECT_FACING add hl, bc ld [hl], a GetNextTile: call GetStepVector - ld hl, $a + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a ld a, d call GetStepVectorSign - ld hl, $12 + ld hl, OBJECT_MAP_X add hl, bc add [hl] - ld hl, $10 + ld hl, OBJECT_NEXT_MAP_X add hl, bc ld [hl], a ld d, a ld a, e call GetStepVectorSign - ld hl, $13 + ld hl, OBJECT_MAP_Y add hl, bc add [hl] - ld hl, $11 + ld hl, OBJECT_NEXT_MAP_Y add hl, bc ld [hl], a ld e, a push bc call GetCoordTile pop bc - ld hl, $e + ld hl, OBJECT_NEXT_TILE add hl, bc ld [hl], a ret -AddStepVector: ; 46b0 (1:46b0) +AddStepVector: call GetStepVector - ld hl, $17 + ld hl, OBJECT_SPRITE_X add hl, bc ld a, [hl] add d ld [hl], a - ld hl, $18 + ld hl, OBJECT_SPRITE_Y add hl, bc ld a, [hl] add e ld [hl], a ret -GetStepVector: ; 46c2 (1:46c2) - ld hl, $7 +GetStepVector: +; Return (x, y, duration, speed) in (d, e, a, h). + ld hl, OBJECT_DIRECTION_WALKING add hl, bc ld a, [hl] - and $f + and %00001111 add a add a ld l, a - ld h, $0 + ld h, 0 ld de, StepVectors add hl, de ld d, [hl] @@ -343,7 +359,7 @@ GetStepVector: ; 46c2 (1:46c2) ld h, [hl] ret -StepVectors: ; 46d9 +StepVectors: ; x, y, duration, speed ; slow db 0, 1, 16, 1 @@ -361,19 +377,19 @@ StepVectors: ; 46d9 db -4, 0, 4, 4 db 4, 0, 4, 4 -GetStepVectorSign: ; 4709 (1:4709) +GetStepVectorSign: add a - ret z - ld a, $1 - ret nc - ld a, $ff - ret + ret z ; 0 or 128 + ld a, 1 + ret nc ; 1 - 127 + ld a, -1 + ret ; 129 - 255 UpdatePlayerStep: - ld hl, $7 + ld hl, OBJECT_DIRECTION_WALKING add hl, bc ld a, [hl] - and $3 + and %00000011 ld [wPlayerStepDirection], a call AddStepVector ld a, [wPlayerStepVectorX] @@ -383,14 +399,14 @@ UpdatePlayerStep: add e ld [wPlayerStepVectorY], a ld hl, wPlayerStepFlags - set 5, [hl] + set PLAYERSTEP_CONTINUE_F, [hl] ret Function4732: push bc ld e, a - ld d, $0 - ld hl, $1 + ld d, 0 + ld hl, OBJECT_MAP_OBJECT_INDEX add hl, bc ld a, [hl] call GetMapObject @@ -399,40 +415,1480 @@ Function4732: pop bc ret -INCLUDE "engine/movement_pattern.asm" -INCLUDE "engine/step_types.asm" -INCLUDE "engine/overworld/movement.asm" +RestoreDefaultMovement: + ld hl, OBJECT_MAP_OBJECT_INDEX + add hl, bc + ld a, [hl] + cp -1 + jr z, .ok + push bc + call GetMapObject + ld hl, MAPOBJECT_MOVEMENT + add hl, bc + ld a, [hl] + pop bc + ret + +.ok + ld a, SPRITEMOVEDATA_STANDING_DOWN + ret -Function5429: ; 5429 (1:5429) +ClearObjectMovementByteIndex: + ld hl, OBJECT_MOVEMENT_BYTE_INDEX + add hl, bc + ld [hl], 0 + ret + +IncrementObjectMovementByteIndex: + ld hl, OBJECT_MOVEMENT_BYTE_INDEX + add hl, bc + inc [hl] + ret + +DecrementObjectMovementByteIndex: + ld hl, OBJECT_MOVEMENT_BYTE_INDEX + add hl, bc + dec [hl] + ret + +MovementAnonymousJumptable: + ld hl, OBJECT_MOVEMENT_BYTE_INDEX + add hl, bc + ld a, [hl] + pop hl + rst JumpTable + ret + +ClearObjectStructField1c: + ld hl, OBJECT_1C + add hl, bc + ld [hl], 0 + ret + +IncrementObjectStructField1c: + ld hl, OBJECT_1C + add hl, bc + inc [hl] + ret + +Field1cAnonymousJumptable: + ld hl, OBJECT_1C + add hl, bc + ld a, [hl] + pop hl + rst JumpTable + ret + +GetValueObjectStructField1c: + ld hl, OBJECT_1C + add hl, bc + ld a, [hl] + ret + +SetValueObjectStructField1c: + ld hl, OBJECT_1C + add hl, bc + ld [hl], a + ret + +ObjectMovementReset: + ld hl, OBJECT_NEXT_MAP_X + add hl, bc + ld d, [hl] + ld hl, OBJECT_NEXT_MAP_Y + add hl, bc + ld e, [hl] + push bc + call GetCoordTile + pop bc + ld hl, OBJECT_NEXT_TILE + add hl, bc + ld [hl], a + call CopyNextCoordsTileToStandingCoordsTile + call EndSpriteMovement + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +MapObjectMovementPattern: + call ClearObjectStructField1c + call GetSpriteMovementFunction + ld a, [hl] + ld hl, .Pointers + rst JumpTable + ret + +.Pointers: +; entries correspond to SPRITEMOVEFN_* constants + dw .Null_00 ; 00 + dw .RandomWalkY ; 01 + dw .RandomWalkX ; 02 + dw .RandomWalkXY ; 03 + dw .RandomSpin1 ; 04 + dw .RandomSpin2 ; 05 + dw .Standing ; 06 + dw .ObeyDPad ; 07 + dw .Movement08 ; 08 + dw .Movement09 ; 09 + dw .Movement0a ; 0a + dw .Movement0b ; 0b + dw .Movement0c ; 0c + dw .Movement0d ; 0d + dw .Movement0e ; 0e + dw .Follow ; 0f + dw .Script ; 10 + dw .Strength ; 11 + dw .FollowNotExact ; 12 + dw .MovementShadow ; 13 + dw .MovementEmote ; 14 + dw .MovementBigStanding ; 15 + dw .MovementBouncing ; 16 + dw .MovementScreenShake ; 17 + dw .MovementSpinClockwise ; 18 + dw .MovementSpinCounterclockwise ; 19 + dw .MovementBoulderDust ; 1a + dw .MovementShakingGrass ; 1b + +.Null_00: + ret + +.RandomWalkY: + call Random + ldh a, [hRandomAdd] + and %00000001 + jp .RandomWalkContinue + +.RandomWalkX: + call Random + ldh a, [hRandomAdd] + and %00000001 + or %00000010 + jp .RandomWalkContinue + +.RandomWalkXY: + call Random + ldh a, [hRandomAdd] + and %00000011 + jp .RandomWalkContinue + +.RandomSpin1: + call Random + ldh a, [hRandomAdd] + and %00001100 + ld hl, OBJECT_FACING + add hl, bc + ld [hl], a + jp RandomStepDuration_Slow + +.RandomSpin2: + ld hl, OBJECT_FACING + add hl, bc + ld a, [hl] + and %00001100 + ld d, a + call Random + ldh a, [hRandomAdd] + and %00001100 + cp d + jr nz, .keep + xor %00001100 +.keep + ld [hl], a + jp RandomStepDuration_Fast + +.Standing: + call Function4603 + call EndSpriteMovement + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_STAND + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_05 + ret + +.ObeyDPad: + ld hl, Function4fa8 + jp HandleMovementData + +.Movement08: + ld hl, Function4fbd + jp HandleMovementData + +.Movement09: + ld hl, Function4fce + jp HandleMovementData + +.Movement0a: + jp _GetMovementObject + +.Movement0b: + jp _GetMovementObject + +.Movement0c: + jp _GetMovementObject + +.Movement0d: + ld hl, Function4fa8 + jp HandleMovementData + +.Movement0e: + jp _GetMovementObject + +.Follow: + ld hl, GetFollowerNextMovementByte + jp HandleMovementData + +.Script: + ld hl, GetMovementByte + jp HandleMovementData + +.Strength: + call MovementAnonymousJumptable + dw .Strength_Start + dw .Strength_Stop + +.Strength_Start: + ld hl, OBJECT_NEXT_TILE + add hl, bc + ld a, [hl] + call CheckPitTile + jr z, .on_pit + ld hl, OBJECT_FLAGS2 + add hl, bc + bit OBJ_FLAGS2_2, [hl] + res OBJ_FLAGS2_2, [hl] + jr z, .ok + ld hl, OBJECT_RANGE + add hl, bc + ld a, [hl] + and %00000011 + or 0 call InitStep - ld hl, $1f + call CanObjectMoveInDirection + jr c, .ok2 + ld de, SFX_STRENGTH + call PlaySFX + call SpawnStrengthBoulderDust + call UpdateTallGrassFlags + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_0F + ret + +.ok2 + call Function4603 +.ok + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ret + +.on_pit + call IncrementObjectMovementByteIndex +.Strength_Stop: + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ret + +.FollowNotExact: + ld hl, OBJECT_NEXT_MAP_X + add hl, bc + ld d, [hl] + ld hl, OBJECT_NEXT_MAP_Y + add hl, bc + ld e, [hl] + ld hl, OBJECT_RANGE + add hl, bc + ld a, [hl] + push bc + call GetObjectStruct + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld a, [hl] + cp STANDING + jr z, .standing + ld hl, OBJECT_MAP_X + add hl, bc + ld a, [hl] + cp d + jr z, .equal + jr c, .less + ld a, 3 + jr .done + +.less + ld a, 2 + jr .done + +.equal + ld hl, OBJECT_MAP_Y + add hl, bc + ld a, [hl] + cp e + jr z, .standing + jr c, .less2 + ld a, 0 + jr .done + +.less2 + ld a, 1 +.done + ld d, a + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld a, [hl] + and %00001100 + or d + pop bc + jp NormalStep + +.standing + pop bc + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_STAND + ret + +.MovementBigStanding: + call EndSpriteMovement + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_BIG_DOLL_SYM + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_04 + ret + +.MovementBouncing: + call EndSpriteMovement + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_BOUNCE + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_04 + ret + +.MovementSpinCounterclockwise: + call MovementAnonymousJumptable + dw .MovementSpinInit + dw .MovementSpinRepeat + dw .MovementSpinTurnLeft + +.MovementSpinClockwise: + call MovementAnonymousJumptable + dw .MovementSpinInit + dw .MovementSpinRepeat + dw .MovementSpinTurnRight + +.MovementSpinInit: + call EndSpriteMovement + call IncrementObjectMovementByteIndex +.MovementSpinRepeat: + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_STAND + ld hl, OBJECT_RANGE + add hl, bc + ld a, [hl] + ld a, $10 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_03 + call IncrementObjectMovementByteIndex + ret + +.MovementSpinTurnLeft: + ld de, .DirectionData_Counterclockwise + call .MovementSpinNextFacing + jr .MovementSpinCounterclockwise + +.DirectionData_Counterclockwise: + db OW_RIGHT, OW_LEFT, OW_DOWN, OW_UP + +.MovementSpinTurnRight: + ld de, .DirectionData_Clockwise + call .MovementSpinNextFacing + jr .MovementSpinClockwise + +.DirectionData_Clockwise: + db OW_LEFT, OW_RIGHT, OW_UP, OW_DOWN + +.MovementSpinNextFacing: + ld hl, OBJECT_FACING + add hl, bc + ld a, [hl] + and %00001100 + rrca + rrca + push hl + ld l, a + ld h, 0 + add hl, de + ld a, [hl] + pop hl + ld [hl], a + call DecrementObjectMovementByteIndex + ret + +.MovementShadow: + call ._MovementShadow_Grass_Emote_BoulderDust + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_SHADOW + ld hl, OBJECT_STEP_DURATION + add hl, de + ld a, [hl] + inc a + add a + add 0 + ld hl, OBJECT_STEP_DURATION add hl, bc - ld [hl], $0 - ld hl, $5 + ld [hl], a + ld hl, OBJECT_DIRECTION_WALKING + add hl, de + ld a, [hl] + maskbits NUM_DIRECTIONS + ld d, 1 * 8 + 6 + cp DOWN + jr z, .ok_13 + cp UP + jr z, .ok_13 + ld d, 1 * 8 + 4 +.ok_13 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], d + ld hl, OBJECT_SPRITE_X_OFFSET add hl, bc - res 3, [hl] - ld hl, $b + ld [hl], 0 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_TRACKING_OBJECT + ret + +.MovementEmote: + call EndSpriteMovement + call ._MovementShadow_Grass_Emote_BoulderDust + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_EMOTE + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 0 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], -2 * 8 + ld hl, OBJECT_SPRITE_X_OFFSET + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_TRACKING_OBJECT + ret + +.MovementBoulderDust: + call EndSpriteMovement + call ._MovementShadow_Grass_Emote_BoulderDust + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $2 - call Function54c8 + ld [hl], OBJECT_ACTION_BOULDER_DUST + ld hl, OBJECT_STEP_DURATION + add hl, de + ld a, [hl] + inc a + add a + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], a + ld hl, OBJECT_DIRECTION_WALKING + add hl, de + ld a, [hl] + and %00000011 + ld e, a + ld d, 0 + ld hl, .data_4a81 + add hl, de + add hl, de + ld d, [hl] + inc hl + ld e, [hl] + ld hl, OBJECT_SPRITE_X_OFFSET + add hl, bc + ld [hl], d + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], e + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_TRACKING_OBJECT + ret + +.data_4a81 + ; x, y + db 0, -4 + db 0, 8 + db 6, 2 + db -6, 2 + +.MovementShakingGrass: + call EndSpriteMovement + call ._MovementShadow_Grass_Emote_BoulderDust + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_GRASS_SHAKE + ld hl, OBJECT_STEP_DURATION + add hl, de + ld a, [hl] + add -1 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_TRACKING_OBJECT + ret + +._MovementShadow_Grass_Emote_BoulderDust: + ld hl, OBJECT_RANGE + add hl, bc + ld a, [hl] + push bc + call GetObjectStruct + ld d, b + ld e, c + pop bc + ld hl, OBJECT_1D + add hl, bc + ld [hl], e + inc hl + ld [hl], d + ret + +.MovementScreenShake: + call EndSpriteMovement + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_00 + ld hl, OBJECT_RANGE + add hl, bc + ld a, [hl] + call ._MovementScreenShake + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], e + ld hl, OBJECT_1E + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_15 + ret + +._MovementScreenShake: + ld d, a + and %00111111 + ld e, a + ld a, d + rlca + rlca + and %00000011 + ld d, a + inc d + ld a, 1 +.loop + dec d + ret z + add a + jr .loop + +.RandomWalkContinue: + call InitStep + call CanObjectMoveInDirection ; check whether the object can move in that direction + jr c, .NewDuration + call UpdateTallGrassFlags + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_STEP ld hl, wCenteredObject ldh a, [hMapObjectIndexBuffer] cp [hl] - jr z, .asm_5450 - ld hl, $9 + jr z, .load_6 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_07 + ret + +.load_6 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_PLAYER_WALK + ret + +.NewDuration: + call EndSpriteMovement + call Function4603 +RandomStepDuration_Slow: + call Random + ldh a, [hRandomAdd] + and %01111111 + jr SetRandomStepDuration + +RandomStepDuration_Fast: + call Random + ldh a, [hRandomAdd] + and %00011111 +SetRandomStepDuration: + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], a + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_STAND + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_03 + ret + +StepTypesJumptable: +; entries correspond to STEP_TYPE_* constants + dw ObjectMovementReset ; 00 + dw MapObjectMovementPattern ; 01 + dw NPCStep ; 02 + dw StepType03 ; 03 + dw StepType04 ; 04 + dw StepType05 ; 05 + dw PlayerStep ; 06 + dw StepType07 ; 07 + dw NPCJump ; 08 + dw PlayerJump ; 09 + dw PlayerOrNPCTurnStep ; 0a + dw StepTypeBump ; 0b + dw TeleportFrom ; 0c + dw TeleportTo ; 0d + dw Skyfall ; 0e + dw StepType0f ; 0f + dw GotBiteStep ; 10 + dw RockSmashStep ; 11 + dw ReturnDigStep ; 12 + dw StepTypeTrackingObject ; 13 + dw StepType14 ; 14 + dw StepType15 ; 15 + dw StepType16 ; 16 + dw StepType17 ; 17 + dw StepType18 ; 18 + +WaitStep_InPlace: + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +NPCJump: + call Field1cAnonymousJumptable +; anonymous dw + dw .Jump + dw .Land + +.Jump: + call AddStepVector + call UpdateJumpPosition + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call CopyNextCoordsTileToStandingCoordsTile + call GetNextTile + ld hl, OBJECT_FLAGS2 add hl, bc - ld [hl], $8 + res OVERHEAD_F, [hl] + call IncrementObjectStructField1c ret -.asm_5450 - ld hl, $9 +.Land: + call AddStepVector + call UpdateJumpPosition + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call CopyNextCoordsTileToStandingCoordsTile + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +PlayerJump: + call Field1cAnonymousJumptable +; anonymous dw + dw .initjump + dw .stepjump + dw .initland + dw .stepland + +.initjump + ld hl, wPlayerStepFlags + set PLAYERSTEP_START_F, [hl] + call IncrementObjectStructField1c +.stepjump + call UpdateJumpPosition + call UpdatePlayerStep + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call CopyNextCoordsTileToStandingCoordsTile + ld hl, OBJECT_FLAGS2 + add hl, bc + res OVERHEAD_F, [hl] + ld hl, wPlayerStepFlags + set PLAYERSTEP_STOP_F, [hl] + set PLAYERSTEP_MIDAIR_F, [hl] + call IncrementObjectStructField1c + ret + +.initland + call GetNextTile + ld hl, wPlayerStepFlags + set PLAYERSTEP_START_F, [hl] + call IncrementObjectStructField1c +.stepland + call UpdateJumpPosition + call UpdatePlayerStep + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, wPlayerStepFlags + set PLAYERSTEP_STOP_F, [hl] + call CopyNextCoordsTileToStandingCoordsTile + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $9 + ld [hl], STEP_TYPE_SLEEP ret -Function5457: ; 5457 (1:5457) + +TeleportFrom: + call Field1cAnonymousJumptable +; anonymous dw + dw .InitSpin + dw .DoSpin + dw .InitSpinRise + dw .DoSpinRise + +.InitSpin: + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 16 + call IncrementObjectStructField1c +.DoSpin: + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_SPIN + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call IncrementObjectStructField1c + ret + +.InitSpinRise: + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld [hl], 0 + ld hl, OBJECT_1F + add hl, bc + ld [hl], $10 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 16 + ld hl, OBJECT_FLAGS2 + add hl, bc + res OVERHEAD_F, [hl] + call IncrementObjectStructField1c +.DoSpinRise: + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_SPIN + ld hl, OBJECT_1F + add hl, bc + inc [hl] + ld a, [hl] + ld d, $60 + call Sine + ld a, h + sub $60 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +TeleportTo: + call Field1cAnonymousJumptable +; anonymous dw + dw .InitWait + dw .DoWait + dw .InitDescent + dw .DoDescent + dw .InitFinalSpin + dw .DoFinalSpin + dw .FinishStep + +.InitWait: + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_00 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 16 + call IncrementObjectStructField1c + ret + +.DoWait: + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call IncrementObjectStructField1c +.InitDescent: + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld [hl], 0 + ld hl, OBJECT_1F + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 16 + call IncrementObjectStructField1c + ret + +.DoDescent: + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_SPIN + ld hl, OBJECT_1F + add hl, bc + inc [hl] + ld a, [hl] + ld d, $60 + call Sine + ld a, h + sub $60 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call IncrementObjectStructField1c +.InitFinalSpin: + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 16 + call IncrementObjectStructField1c + ret + +.DoFinalSpin: + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_SPIN + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz +.FinishStep: + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld [hl], 0 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +Skyfall: + call Field1cAnonymousJumptable +; anonymous dw + dw .Init + dw .Step + dw .Fall + dw .Finish + +.Init: + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_00 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 16 + call IncrementObjectStructField1c +.Step: + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_STEP + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld [hl], 0 + ld hl, OBJECT_1F + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 16 + call IncrementObjectStructField1c +.Fall: + ld hl, OBJECT_1F + add hl, bc + inc [hl] + ld a, [hl] + ld d, $60 + call Sine + ld a, h + sub $60 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call IncrementObjectStructField1c +.Finish: + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld [hl], 0 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +GotBiteStep: + call Field1cAnonymousJumptable +; anonymous dw + dw .Init + dw .Run + +.Init: + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 8 + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], 0 + call IncrementObjectStructField1c +.Run: + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld a, [hl] + xor 1 + ld [hl], a + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], 0 + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +RockSmashStep: + call .Step + jp WaitStep_InPlace + +.Step: + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld a, [hl] + and %00000001 + ld a, OBJECT_ACTION_STAND + jr z, .yes + ld a, OBJECT_ACTION_00 +.yes + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], a + ret + +ReturnDigStep: + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld a, [hl] + and %00000001 + ld a, OBJECT_ACTION_SPIN + jr z, .yes + ld a, OBJECT_ACTION_SPIN_FLICKER +.yes + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], a + jp WaitStep_InPlace + +StepType03: + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +StepType18: + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + jp DeleteMapObject + +StepTypeBump: + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +StepType05: + call Field1cAnonymousJumptable +; anonymous dw + dw .Reset + dw StepType04 + +.Reset: + call RestoreDefaultMovement + call GetInitialFacing + ld hl, OBJECT_FACING + add hl, bc + ld [hl], a + call IncrementObjectStructField1c +StepType04: + call Stubbed_Function4fb2 + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ret + +NPCStep: + call Stubbed_Function4fb2 + call AddStepVector + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call CopyNextCoordsTileToStandingCoordsTile + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +StepType07: + call AddStepVector + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call CopyNextCoordsTileToStandingCoordsTile + jp RandomStepDuration_Slow + +PlayerStep: +; AnimateStep? + call Field1cAnonymousJumptable +; anonymous dw + dw .init + dw .step + +.init + ld hl, wPlayerStepFlags + set PLAYERSTEP_START_F, [hl] + call IncrementObjectStructField1c +.step + call UpdatePlayerStep + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, wPlayerStepFlags + set PLAYERSTEP_STOP_F, [hl] + call CopyNextCoordsTileToStandingCoordsTile + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +PlayerOrNPCTurnStep: + call Field1cAnonymousJumptable +; anonymous dw + dw .init1 + dw .step1 + dw .init2 + dw .step2 + +.init1 + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_STEP_FRAME + add hl, bc + ld a, [hl] + ld [hl], 2 + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 2 + call IncrementObjectStructField1c +.step1 + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + call IncrementObjectStructField1c +.init2 + ld hl, OBJECT_1D ; new facing + add hl, bc + ld a, [hl] + ld hl, OBJECT_FACING + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld [hl], 2 + call IncrementObjectStructField1c +.step2 + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +StepType0f: + call AddStepVector + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + ret nz + push bc + ld hl, OBJECT_NEXT_MAP_X + add hl, bc + ld d, [hl] + ld hl, OBJECT_NEXT_MAP_Y + add hl, bc + ld e, [hl] + ld hl, OBJECT_MAP_OBJECT_INDEX + add hl, bc + ld a, [hl] + ld b, a + farcall CopyDECoordsToMapObject + pop bc + ld hl, OBJECT_FLAGS2 + add hl, bc + res OBJ_FLAGS2_2, [hl] + call CopyNextCoordsTileToStandingCoordsTile + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], STANDING + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_SLEEP + ret + +StepTypeTrackingObject: + ld hl, OBJECT_1D + add hl, bc + ld e, [hl] + inc hl + ld d, [hl] + ld hl, OBJECT_SPRITE + add hl, de + ld a, [hl] + and a + jr z, .nope + ld hl, OBJECT_SPRITE_X + add hl, de + ld a, [hl] + ld hl, OBJECT_SPRITE_X + add hl, bc + ld [hl], a + ld hl, OBJECT_SPRITE_Y + add hl, de + ld a, [hl] + ld hl, OBJECT_SPRITE_Y + add hl, bc + ld [hl], a + ld hl, OBJECT_STEP_DURATION + add hl, bc + ld a, [hl] + and a + ret z + dec [hl] + ret nz +.nope + jp DeleteMapObject + +StepType14: +StepType15: + call Field1cAnonymousJumptable +; anonymous dw + dw .Init + dw .Run + +.Init: + xor a + ld hl, OBJECT_1D + add hl, bc + ld [hl], a + call IncrementObjectStructField1c +.Run: + ld hl, OBJECT_1D + add hl, bc + ld d, [hl] + ld a, [wPlayerStepVectorY] + sub d + ld [wPlayerStepVectorY], a + ld hl, OBJECT_STEP_DURATION + add hl, bc + dec [hl] + jr z, .ok + ld a, [hl] + call .GetSign + ld hl, OBJECT_1D + add hl, bc + ld [hl], a + ld d, a + ld a, [wPlayerStepVectorY] + add d + ld [wPlayerStepVectorY], a + ret + +.ok + call DeleteMapObject + ret + +.GetSign: + ld hl, OBJECT_1E + add hl, bc + and 1 + ld a, [hl] + ret z + cpl + inc a + ret + +StepType16: + call Field1cAnonymousJumptable ; ???? +StepType17: + call Field1cAnonymousJumptable +; anonymous dw + dw .null + dw .null + dw .null +.null + +Stubbed_Function4fb2: + ret + ld hl, OBJECT_1D + add hl, bc + inc [hl] + ld a, [hl] + srl a + srl a + and %00000111 + ld l, a + ld h, 0 + ld de, .y + add hl, de + ld a, [hl] + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], a + ret + +.y + db 0, -1, -2, -3, -4, -3, -2, -1 +UpdateJumpPosition: + call GetStepVector + ld a, h + ld hl, OBJECT_1F + add hl, bc + ld e, [hl] + add e + ld [hl], a + nop + srl e + ld d, 0 + ld hl, .y + add hl, de + ld a, [hl] + ld hl, OBJECT_SPRITE_Y_OFFSET + add hl, bc + ld [hl], a + ret + +.y + db -4, -6, -8, -10, -11, -12, -12, -12 + db -11, -10, -9, -8, -6, -4, 0, 0 + +Function4fa8: ; unscripted? +; copy [wPlayerNextMovement] to [wPlayerMovement] + ld a, [wPlayerNextMovement] + ld hl, wPlayerMovement + ld [hl], a +; load [wPlayerNextMovement] with movement_step_sleep + ld a, movement_step_sleep + ld [wPlayerNextMovement], a +; recover the previous value of [wPlayerNextMovement] + ld a, [hl] + ret + +GetMovementByte: + ld hl, wMovementDataBank + call _GetMovementByte + ret + +Function4fbd: + ld hl, OBJECT_MOVEMENT_BYTE_INDEX + add hl, bc + ld e, [hl] + inc [hl] + ld d, 0 + ld hl, wMovementObject + ld a, [hli] + ld h, [hl] + ld l, a + add hl, de + ld a, [hl] + ret + +Function4fce: + ld hl, OBJECT_MOVEMENT_BYTE_INDEX + add hl, bc + ld e, [hl] + inc [hl] + ld d, 0 + ld hl, wce8f + ld a, [hli] + ld h, [hl] + ld l, a + add hl, de + ld a, [hl] + ret + +_GetMovementObject: + ld hl, GetMovementObject + jp HandleMovementData + +GetMovementObject: + ld a, [wMovementObject] + ret + +HandleMovementData: + call .StorePointer +.loop + xor a + ld [wMovementByteWasControlSwitch], a + call JumpMovementPointer + call DoMovementFunction + ld a, [wMovementByteWasControlSwitch] + and a + jr nz, .loop + ret + +.StorePointer: + ld a, l + ld [wMovementPointer], a + ld a, h + ld [wMovementPointer + 1], a + ret + +JumpMovementPointer: + ld hl, wMovementPointer + ld a, [hli] + ld h, [hl] + ld l, a + jp hl + +ContinueReadingMovement: + ld a, 1 + ld [wMovementByteWasControlSwitch], a + ret + +DoMovementFunction: + push af + call ApplyMovementToFollower + pop af + ld hl, MovementPointers + rst JumpTable + ret + +INCLUDE "engine/overworld/movement.asm" + +ApplyMovementToFollower: ld e, a ld a, [wObjectFollow_Follower] - cp $ff + cp -1 ret z ld a, [wObjectFollow_Leader] ld d, a @@ -440,21 +1896,21 @@ Function5457: ; 5457 (1:5457) cp d ret nz ld a, e - cp $3e + cp movement_step_sleep ret z - cp $47 + cp movement_step_end ret z - cp $4b + cp movement_step_4b ret z - cp $50 + cp movement_step_bump ret z - cp $8 + cp movement_slow_step ret c push af ld hl, wFollowerMovementQueueLength inc [hl] ld e, [hl] - ld d, $0 + ld d, 0 ld hl, wFollowMovementQueue add hl, de pop af @@ -465,143 +1921,149 @@ GetFollowerNextMovementByte: ld hl, wFollowerMovementQueueLength ld a, [hl] and a - jr z, .asm_54a2 - cp $ff - jr z, .asm_54a2 + jr z, .done + cp -1 + jr z, .done dec [hl] ld e, a - ld d, $0 + ld d, 0 ld hl, wFollowMovementQueue add hl, de inc e - ld a, $ff -.asm_549b + ld a, -1 +.loop ld d, [hl] ld [hld], a ld a, d dec e - jr nz, .asm_549b + jr nz, .loop ret -.asm_54a2 - call Function54a9 +.done + call .CancelFollowIfLeaderMissing ret c - ld a, $3e + ld a, movement_step_sleep ret -Function54a9: ; 54a9 (1:54a9) +.CancelFollowIfLeaderMissing: ld a, [wObjectFollow_Leader] - cp $ff - jr z, .asm_54bf + cp -1 + jr z, .nope push bc call GetObjectStruct - ld hl, $0 + ld hl, OBJECT_SPRITE add hl, bc ld a, [hl] pop bc and a - jr z, .asm_54bf + jr z, .nope and a ret -.asm_54bf - ld a, $ff +.nope + ld a, -1 ld [wObjectFollow_Follower], a - ld a, $47 + ld a, movement_step_end scf ret -Function54c8: ; 54c8 (1:54c8) +SpawnShadow: push bc - ld de, .data - call Function5558 - call Function554b + ld de, .ShadowObject + call CopyTempObjectData + call InitTempObject pop bc ret -.data db $fc, PAL_OW_SILVER, SPRITEMOVEDATA_SHADOW +.ShadowObject: + ; vtile, palette, movement + db $fc, PAL_OW_SILVER, SPRITEMOVEDATA_SHADOW -Function54d7: ; 54d7 (1:54d7) +SpawnStrengthBoulderDust: push bc - ld de, .data - call Function5558 - call Function554b + ld de, .BoulderDustObject + call CopyTempObjectData + call InitTempObject pop bc ret -.data db $fe, PAL_OW_SILVER, SPRITEMOVEDATA_BOULDERDUST +.BoulderDustObject: + db $fe, PAL_OW_SILVER, SPRITEMOVEDATA_BOULDERDUST -Function54e6: ; 54e6 (1:54e6) +SpawnEmote: push bc - ld de, .data - call Function5558 - call Function554b + ld de, .EmoteObject + call CopyTempObjectData + call InitTempObject pop bc ret -.data db $f8, PAL_OW_SILVER, SPRITEMOVEDATA_EMOTE +.EmoteObject: + db $f8, PAL_OW_SILVER, SPRITEMOVEDATA_EMOTE -Function54f5: ; 54f5 (1:54f5) +ShakeGrass: push bc - ld de, .data - call Function5558 - call Function554b + ld de, .GrassObject + call CopyTempObjectData + call InitTempObject pop bc ret -.data db $fe, PAL_OW_TREE, SPRITEMOVEDATA_GRASS +.GrassObject + db $fe, PAL_OW_TREE, SPRITEMOVEDATA_GRASS -Function5504: ; 5504 (1:5504) +ShakeScreen: push bc push af - ld de, .data - call Function5558 + ld de, .ScreenShakeObject + call CopyTempObjectData pop af - ld [wce9e], a - call Function554b + ld [wTempObjectCopyRange], a + call InitTempObject pop bc ret -.data db $00, PAL_OW_SILVER, SPRITEMOVEDATA_SCREENSHAKE +.ScreenShakeObject: + db $00, PAL_OW_SILVER, SPRITEMOVEDATA_SCREENSHAKE -Function5518: ; 5518 (1:5518) +DespawnEmote: push bc ldh a, [hMapObjectIndexBuffer] ld c, a - call Function5521 + call .DeleteEmote pop bc ret -Function5521: ; 5521 (1:5521) - ld de, wPlayerStruct - ld a, $d -.asm_5526 +.DeleteEmote: + ld de, wObjectStructs + ld a, NUM_OBJECT_STRUCTS +.loop push af - ld hl, $4 + ld hl, OBJECT_FLAGS1 add hl, de - bit 7, [hl] - jr z, .asm_5540 - ld hl, $0 + bit EMOTE_OBJECT_F, [hl] + jr z, .next + ld hl, OBJECT_SPRITE add hl, de ld a, [hl] and a - jr z, .asm_5540 + jr z, .next push bc xor a - ld bc, $28 + ld bc, OBJECT_LENGTH call ByteFill pop bc -.asm_5540 - ld hl, $28 +.next + ld hl, OBJECT_LENGTH add hl, de ld d, h ld e, l pop af dec a - jr nz, .asm_5526 + jr nz, .loop ret -Function554b: ; 554b (1:554b) +InitTempObject: call FindFirstEmptyObjectStruct ret nc ld d, h @@ -609,11 +2071,14 @@ Function554b: ; 554b (1:554b) farcall CopyTempObjectToObjectStruct ret -Function5558: ; 5558 (1:5558) - ld hl, wce99 - ld [hl], $ff +CopyTempObjectData: +; load into wTempObjectCopy: +; -1, -1, [de], [de + 1], [de + 2], [hMapObjectIndexBuffer], [NextMapX], [NextMapY], -1 +; This spawns the object at the same place as whichever object is loaded into bc. + ld hl, wTempObjectCopyMapObjectIndex + ld [hl], -1 inc hl - ld [hl], $ff + ld [hl], -1 inc hl ld a, [de] inc de @@ -626,10 +2091,10 @@ Function5558: ; 5558 (1:5558) ldh a, [hMapObjectIndexBuffer] ld [hli], a push hl - ld hl, $10 + ld hl, OBJECT_NEXT_MAP_X add hl, bc ld d, [hl] - ld hl, $11 + ld hl, OBJECT_NEXT_MAP_Y add hl, bc ld e, [hl] pop hl @@ -637,56 +2102,57 @@ Function5558: ; 5558 (1:5558) inc hl ld [hl], e inc hl - ld [hl], $ff + ld [hl], -1 ret -Function557f:: ; 557f (1:557f) +Function557f:: ld a, [wVramState] bit 0, a ret z - ld bc, wPlayerStruct + ld bc, wObjectStructs xor a -.asm_5589 - ldh [hConnectionStripLength], a +.loop + ldh [hMapObjectIndexBuffer], a call DoesObjectHaveASprite - jr z, .asm_5593 + jr z, .ok call Function55ef -.asm_5593 - ld hl, $28 +.ok + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l ldh a, [hMapObjectIndexBuffer] inc a - cp $d - jr nz, .asm_5589 + cp NUM_OBJECT_STRUCTS + jr nz, .loop ret Function55a1: - call Function55d8 - ld a, $0 - call Function55bc +; called at battle start + call Function55d8 ; clear sprites + ld a, PLAYER + call Function55bc ; respawn player ld a, [wBattleScriptFlags] bit 7, a - jr z, .asm_55b8 + jr z, .ok ldh a, [hLastTalked] and a - jr z, .asm_55b8 - call Function55bc -.asm_55b8 + jr z, .ok + call Function55bc ; respawn opponent +.ok call _UpdateSprites ret -Function55bc: ; 55bc (1:55bc) - cp $10 +Function55bc: + cp NUM_OBJECTS ret nc call GetMapObject - ld hl, $0 + ld hl, MAPOBJECT_OBJECT_STRUCT_ID add hl, bc ld a, [hl] - cp $ff + cp -1 ret z - cp $d + cp NUM_OBJECT_STRUCTS ret nc call GetObjectStruct call DoesObjectHaveASprite @@ -694,209 +2160,211 @@ Function55bc: ; 55bc (1:55bc) call Function5606 ret -Function55d8: ; 55d8 (1:55d8) +Function55d8: xor a - ld bc, wPlayerStruct -.asm_55dc + ld bc, wObjectStructs +.loop ldh [hMapObjectIndexBuffer], a - call Function5613 - ld hl, $28 + call SetFacing_Standing + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l - ldh a, [hConnectionStripLength] + ldh a, [hMapObjectIndexBuffer] inc a - cp $d - jr nz, .asm_55dc + cp NUM_OBJECT_STRUCTS + jr nz, .loop ret -Function55ef: ; 55ef (1:55ef) +Function55ef: push bc call Function5660 pop bc - jr c, Function5613 + jr c, SetFacing_Standing call Function5636 - jr c, Function5613 + jr c, SetFacing_Standing call Function561b - farcall Function4441 ; same bank + farcall Function4441 xor a ret -Function5606: ; 5606 (1:5606) +Function5606: call Function5636 - jr c, Function5613 - farcall Function4441 ; same bank + jr c, SetFacing_Standing + farcall Function4441 xor a ret -Function5613: ; 5613 (1:5613) - ld hl, $d +SetFacing_Standing: + ld hl, OBJECT_FACING_STEP add hl, bc - ld [hl], $ff + ld [hl], STANDING scf ret -Function561b: ; 561b (1:561b) +Function561b: push bc - ld hl, $10 + ld hl, OBJECT_NEXT_MAP_X add hl, bc ld d, [hl] - ld hl, $11 + ld hl, OBJECT_NEXT_MAP_Y add hl, bc ld e, [hl] call GetCoordTile pop bc - ld hl, $e + ld hl, OBJECT_NEXT_TILE add hl, bc ld [hl], a - farcall UpdateGrassPriority ; same bank + farcall UpdateTallGrassFlags ; no need to farcall ret -Function5636: ; 5636 (1:5636) - ld hl, $10 +Function5636: + ld hl, OBJECT_NEXT_MAP_X add hl, bc ld d, [hl] - ld hl, $11 + ld hl, OBJECT_NEXT_MAP_Y add hl, bc ld e, [hl] inc d inc e ld a, [wXCoord] cp d - jr z, .asm_564f - jr nc, .asm_565e - add $b + jr z, .equal_x + jr nc, .nope + add MAPOBJECT_SCREEN_WIDTH - 1 cp d - jr c, .asm_565e -.asm_564f + jr c, .nope +.equal_x ld a, [wYCoord] cp e - jr z, .asm_565c - jr nc, .asm_565e - add $a + jr z, .equal_y + jr nc, .nope + add MAPOBJECT_SCREEN_HEIGHT - 1 cp e - jr c, .asm_565e -.asm_565c + jr c, .nope +.equal_y xor a ret -.asm_565e +.nope scf ret -Function5660: ; 5660 (1:5660) - ld a, [wce81] +Function5660: + ld a, [wPlayerBGMapOffsetX] ld d, a - ld hl, $19 + ld hl, OBJECT_SPRITE_X_OFFSET add hl, bc ld a, [hl] - ld hl, $17 + ld hl, OBJECT_SPRITE_X add hl, bc add [hl] add d cp $f0 - jr nc, .asm_5678 + jr nc, .ok1 cp $a0 - jp nc, Function56fb -.asm_5678 - and $7 - ld d, $2 - cp $4 - jr c, .asm_5682 - ld d, $3 -.asm_5682 + jp nc, .nope +.ok1 + and %00000111 + ld d, 2 + cp 4 + jr c, .ok2 + ld d, 3 +.ok2 ld a, [hl] srl a srl a srl a - cp $14 - jr c, .asm_568f - sub $20 -.asm_568f - ldh [hUsedSpriteIndex], a - ld a, [wce82] + cp SCREEN_WIDTH + jr c, .ok3 + sub BG_MAP_WIDTH +.ok3 + ldh [hCurSpriteXCoord], a + ld a, [wPlayerBGMapOffsetY] ld e, a - ld hl, $1a + ld hl, OBJECT_SPRITE_Y_OFFSET add hl, bc ld a, [hl] - ld hl, $18 + ld hl, OBJECT_SPRITE_Y add hl, bc add [hl] add e cp $f0 - jr nc, .asm_56a8 + jr nc, .ok4 cp $90 - jr nc, Function56fb -.asm_56a8 - and $7 - ld e, $2 - cp $4 - jr c, .asm_56b2 - ld e, $3 -.asm_56b2 + jr nc, .nope +.ok4 + and %00000111 + ld e, 2 + cp 4 + jr c, .ok5 + ld e, 3 +.ok5 ld a, [hl] srl a srl a srl a - cp $12 - jr c, .asm_56bf - sub $20 -.asm_56bf - ldh [hUsedSpriteTile], a - ld hl, $6 - add hl, bc - bit 7, [hl] - jr z, .asm_56d1 + cp SCREEN_HEIGHT + jr c, .ok6 + sub BG_MAP_HEIGHT +.ok6 + ldh [hCurSpriteYCoord], a + ld hl, OBJECT_PALETTE + add hl, bc + bit BIG_OBJECT_F, [hl] + jr z, .ok7 ld a, d - add $2 + add 2 ld d, a ld a, e - add $2 + add 2 ld e, a -.asm_56d1 +.ok7 ld a, d - ldh [hFFC1], a -.asm_56d4 - ldh a, [hFFC1] + ldh [hCurSpriteXPixel], a +.loop + ldh a, [hCurSpriteXPixel] ld d, a - ldh a, [hUsedSpriteTile] + ldh a, [hCurSpriteYCoord] add e dec a - cp $12 - jr nc, .asm_56f6 + cp SCREEN_HEIGHT + jr nc, .ok9 ld b, a -.asm_56e0 - ldh a, [hUsedSpriteIndex] +.next + ldh a, [hCurSpriteXCoord] add d dec a - cp $14 - jr nc, .asm_56f3 + cp SCREEN_WIDTH + jr nc, .ok8 ld c, a push bc call Coord2Tile pop bc +; NPCs disappear if standing on tile $60-$7f (or $e0-$ff), +; since those IDs are for text characters and textbox frames. ld a, [hl] - cp $60 - jr nc, Function56fb -.asm_56f3 + cp FIRST_REGULAR_TEXT_CHAR + jr nc, .nope +.ok8 dec d - jr nz, .asm_56e0 -.asm_56f6 + jr nz, .next +.ok9 dec e - jr nz, .asm_56d4 + jr nz, .loop and a ret -Function56fb: ; 56fb (1:56fb) +.nope scf ret HandleNPCStep:: - call Function5704 - call Function5714 + call .ResetStepVector + call .DoStepsForAllObjects ret -Function5704: ; 5704 (1:5704) +.ResetStepVector: xor a ld [wPlayerStepVectorX], a ld [wPlayerStepVectorY], a @@ -905,119 +2373,119 @@ Function5704: ; 5704 (1:5704) ld [wPlayerStepDirection], a ret -Function5714: ; 5714 (1:5714) - ld bc, wPlayerSprite +.DoStepsForAllObjects: + ld bc, wObjectStructs xor a -.asm_5718 +.loop ldh [hMapObjectIndexBuffer], a call DoesObjectHaveASprite - jr z, .asm_5722 + jr z, .next call Function437c -.asm_5722 - ld hl, $28 +.next + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l - ldh a, [hConnectionStripLength] + ldh a, [hMapObjectIndexBuffer] inc a - cp $d - jr nz, .asm_5718 + cp NUM_OBJECT_STRUCTS + jr nz, .loop ret -RefreshPlayerSprite:: ; 5730 (1:5730) - ld a, $3e - ld [wce87], a - ld [wce88], a +RefreshPlayerSprite:: + ld a, movement_step_sleep + ld [wPlayerNextMovement], a + ld [wPlayerMovement], a xor a ld [wPlayerTurningDirection], a ld [wPlayerObjectStepFrame], a - call Function574f + call .TryResetPlayerAction farcall CheckWarpFacingDown call c, SpawnInFacingDown - call Function5761 + call .SpawnInCustomFacing ret -Function574f: ; 574f (1:574f) +.TryResetPlayerAction: ld hl, wPlayerSpriteSetupFlags bit 7, [hl] - jr nz, .asm_575b + jr nz, .ok bit 6, [hl] - jr nz, .asm_575b + jr nz, .ok ret -.asm_575b - ld a, $0 +.ok + ld a, OBJECT_ACTION_00 ld [wPlayerAction], a ret -Function5761: ; 5761 (1:5761) +.SpawnInCustomFacing: ld hl, wPlayerSpriteSetupFlags - bit 5, [hl] + bit PLAYERSPRITESETUP_CUSTOM_FACING_F, [hl] ret z ld a, [wPlayerSpriteSetupFlags] - and $3 + and PLAYERSPRITESETUP_FACING_MASK add a add a - jr asm_5772 + jr ContinueSpawnFacing SpawnInFacingDown: - ld a, $0 -asm_5772: - ld bc, wObjectStructs + ld a, DOWN +ContinueSpawnFacing: + ld bc, wPlayerStruct call SetSpriteDirection ret StartFollow:: push bc ld a, b - call Function578b + call SetLeaderIfVisible pop bc ret c ld a, c - call Function57a2 + call SetFollowerIfVisible farcall QueueFollowerFirstStep ret -Function578b: ; 578b (1:578b) +SetLeaderIfVisible: call CheckObjectVisibility ret c ldh a, [hObjectStructIndexBuffer] ld [wObjectFollow_Leader], a ret -StopFollow:: ; 5795 (1:5795) - call Function579c - call Function57bd +StopFollow:: + call ResetLeader + call ResetFollower ret -Function579c: ; 579c (1:579c) - ld a, $ff +ResetLeader: + ld a, -1 ld [wObjectFollow_Leader], a ret -Function57a2: ; 57a2 (1:57a2) +SetFollowerIfVisible: push af - call Function57bd + call ResetFollower pop af call CheckObjectVisibility ret c - ld hl, $3 + ld hl, OBJECT_MOVEMENTTYPE add hl, bc - ld [hl], $13 - ld hl, $9 + ld [hl], SPRITEMOVEDATA_FOLLOWING + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $0 - ldh a, [hConnectedMapWidth] + ld [hl], STEP_TYPE_00 + ldh a, [hObjectStructIndexBuffer] ld [wObjectFollow_Follower], a ret -Function57bd: ; 57bd (1:57bd) +ResetFollower: ld a, [wObjectFollow_Follower] - cp $ff + cp -1 ret z call GetObjectStruct - farcall Function5859 ; same bank - ld a, $ff + farcall Function5859 ; no need to bankswitch + ld a, -1 ld [wObjectFollow_Follower], a ret @@ -1028,134 +2496,138 @@ SetFlagsForMovement_1:: push bc call Function57f0 pop bc - ld hl, $5 + ld hl, OBJECT_FLAGS2 add hl, bc - res 5, [hl] + res OBJ_FLAGS2_5, [hl] xor a ret Function57e4: call CheckObjectVisibility ret c - ld hl, $5 + ld hl, OBJECT_FLAGS2 add hl, bc - set 5, [hl] + set OBJ_FLAGS2_5, [hl] xor a ret -Function57f0: ; 57f0 (1:57f0) - ld bc, wPlayerStruct +Function57f0: + ld bc, wObjectStructs xor a -.asm_57f4 +.loop push af call DoesObjectHaveASprite - jr z, .asm_5800 - ld hl, $5 + jr z, .next + ld hl, OBJECT_FLAGS2 add hl, bc - set 5, [hl] -.asm_5800 - ld hl, $28 + set OBJ_FLAGS2_5, [hl] +.next + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l pop af inc a - cp $d - jr nz, .asm_57f4 + cp NUM_OBJECT_STRUCTS + jr nz, .loop ret _SetFlagsForMovement_2:: ld a, [wObjectFollow_Leader] - cp $ff + cp -1 ret z push bc call GetObjectStruct - ld hl, $1 + ld hl, OBJECT_MAP_OBJECT_INDEX add hl, bc ld a, [hl] pop bc cp c ret nz ld a, [wObjectFollow_Follower] - cp $ff + cp -1 ret z call GetObjectStruct - ld hl, $5 + ld hl, OBJECT_FLAGS2 add hl, bc - res 5, [hl] + res OBJ_FLAGS2_5, [hl] ret Function582f:: push bc - ld bc, wPlayerSprite + ld bc, wObjectStructs xor a -.asm_5834 +.loop push af call DoesObjectHaveASprite - jr z, .asm_5840 - ld hl, $5 + jr z, .next + ld hl, OBJECT_FLAGS2 add hl, bc - res 5, [hl] -.asm_5840 - ld hl, $28 + res OBJ_FLAGS2_5, [hl] +.next + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l pop af inc a - cp $d - jr nz, .asm_5834 + cp NUM_OBJECT_STRUCTS + jr nz, .loop pop bc ret Function584e: call CheckObjectVisibility ret c - ld hl, $5 + ld hl, OBJECT_FLAGS2 add hl, bc - res 5, [hl] + res OBJ_FLAGS2_5, [hl] ret -Function5859: - ld hl, $1 +Function5859:: + ld hl, OBJECT_MAP_OBJECT_INDEX add hl, bc ld a, [hl] - cp $ff - jp z, Function5879 + cp -1 + jp z, Function5879 ; a jr would have been appropriate here push bc call GetMapObject - ld hl, $4 + ld hl, MAPOBJECT_MOVEMENT add hl, bc ld a, [hl] pop bc - ld hl, $3 + ld hl, OBJECT_MOVEMENTTYPE add hl, bc ld [hl], a - ld hl, $9 + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $0 + ld [hl], STEP_TYPE_00 ret -Function5879: ; 5879 (1:5879) +Function5879: call GetSpriteDirection rrca rrca ld e, a - ld d, $0 - ld hl, .data + ld d, 0 + ld hl, .standing_movefns add hl, de ld a, [hl] - ld hl, $3 + ld hl, OBJECT_MOVEMENTTYPE add hl, bc ld [hl], a - ld hl, $9 + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $0 + ld [hl], STEP_TYPE_00 ret -.data db 6,7,8,9 +.standing_movefns + db SPRITEMOVEDATA_STANDING_DOWN + db SPRITEMOVEDATA_STANDING_UP + db SPRITEMOVEDATA_STANDING_LEFT + db SPRITEMOVEDATA_STANDING_RIGHT -_UpdateSprites:: ; 5896 (1:5896) +_UpdateSprites:: ld a, [wVramState] bit 0, a ret z @@ -1163,119 +2635,124 @@ _UpdateSprites:: ; 5896 (1:5896) ldh [hUsedSpriteIndex], a ldh a, [hOAMUpdate] push af - ld a, $1 + ld a, 1 ldh [hOAMUpdate], a - call Function58fe - call Function58b0 + call InitSprites + call .fill pop af ldh [hOAMUpdate], a ret -Function58b0: ; 58b0 (1:58b0) - ld b, $a0 +.fill + ld b, OBJECT_LENGTH * SPRITEOAMSTRUCT_LENGTH ldh a, [hUsedSpriteIndex] cp b ret nc ld l, a - ld h, wVirtualOAM / $100 - ld de, $4 + ld h, HIGH(wVirtualOAM) + ld de, SPRITEOAMSTRUCT_LENGTH ld a, b - ld c, $a0 -.asm_58bf - ld [hl], c + ld c, SCREEN_HEIGHT_PX + 2 * TILE_WIDTH +.loop + ld [hl], c ; y add hl, de cp l - jr nz, .asm_58bf + jr nz, .loop ret -ApplyBGMapAnchorToObjects:: ; 58c5 (1:58c5) +ApplyBGMapAnchorToObjects:: push hl push de push bc - ld a, [wce81] + ld a, [wPlayerBGMapOffsetX] ld d, a - ld a, [wce82] + ld a, [wPlayerBGMapOffsetY] ld e, a - ld bc, wPlayerStruct - ld a, $d -.asm_58d5 + ld bc, wObjectStructs + ld a, NUM_OBJECT_STRUCTS +.loop push af call DoesObjectHaveASprite - jr z, .asm_58e9 - ld hl, $17 + jr z, .skip + ld hl, OBJECT_SPRITE_X add hl, bc ld a, [hl] add d ld [hl], a - ld hl, $18 + ld hl, OBJECT_SPRITE_Y add hl, bc ld a, [hl] add e ld [hl], a -.asm_58e9 - ld hl, $28 +.skip + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l pop af dec a - jr nz, .asm_58d5 + jr nz, .loop xor a - ld [wce81], a - ld [wce82], a + ld [wPlayerBGMapOffsetX], a + ld [wPlayerBGMapOffsetY], a pop bc pop de pop hl ret -Function58fe: ; 58fe (1:58fe) - call Function5911 - ld c, $30 - call Function5960 - ld c, $20 - call Function5960 - ld c, $10 - call Function5960 +PRIORITY_LOW EQU $10 +PRIORITY_NORM EQU $20 +PRIORITY_HIGH EQU $30 + +InitSprites: + call .DeterminePriorities + ld c, PRIORITY_HIGH + call .InitSpritesByPriority + ld c, PRIORITY_NORM + call .InitSpritesByPriority + ld c, PRIORITY_LOW + call .InitSpritesByPriority ret -Function5911: ; 5911 (1:5911) +.DeterminePriorities: xor a - ld hl, wce94 - ld bc, $d + ld hl, wMovementPointer + ld bc, NUM_OBJECT_STRUCTS call ByteFill - ld d, $0 + ld d, 0 ld bc, wObjectStructs - ld hl, wce94 -.asm_5923 + ld hl, wMovementPointer +.loop push hl call DoesObjectHaveASprite - jr z, .asm_5946 - ld hl, $d + jr z, .skip + ld hl, OBJECT_FACING_STEP add hl, bc ld a, [hl] - cp $ff - jr z, .asm_5946 - ld e, $10 - ld hl, $5 - add hl, bc - bit 0, [hl] - jr nz, .asm_594f - ld e, $20 - bit 1, [hl] - jr z, .asm_594f - ld e, $30 - jr .asm_594f - -.asm_5946 - ld hl, $28 + cp STANDING + jr z, .skip +; Define the sprite priority. + ld e, PRIORITY_LOW + ld hl, OBJECT_FLAGS2 + add hl, bc + bit LOW_PRIORITY_F, [hl] + jr nz, .add + ld e, PRIORITY_NORM + bit HIGH_PRIORITY_F, [hl] + jr z, .add + ld e, PRIORITY_HIGH + jr .add + +.skip + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l pop hl - jr .asm_5959 + jr .next -.asm_594f - ld hl, $28 +.add + ld hl, OBJECT_LENGTH add hl, bc ld b, h ld c, l @@ -1283,93 +2760,94 @@ Function5911: ; 5911 (1:5911) ld a, d or e ld [hli], a -.asm_5959 +.next inc d ld a, d - cp $d - jr nz, .asm_5923 + cp NUM_OBJECT_STRUCTS + jr nz, .loop ret -Function5960: ; 5960 (1:5960) - ld hl, wce94 -.asm_5963 +.InitSpritesByPriority: + ld hl, wMovementPointer +.next_sprite ld a, [hli] ld d, a and $f0 ret z cp c - jr nz, .asm_5963 + jr nz, .next_sprite push bc push hl ld a, d and $f - call Function5a27 - call Function597a + call .GetObjectStructPointer + call .InitSprite pop hl pop bc - jr .asm_5963 + jr .next_sprite -Function597a: ; 597a (1:597a) +.InitSprite: xor a - ld hl, $5 +.skip1 + ld hl, OBJECT_FLAGS2 add hl, bc ld e, [hl] - bit 7, e - jr z, .asm_5986 - or $80 -.asm_5986 - bit 4, e - jr z, .asm_598c - or $10 -.asm_598c - ld hl, $6 + bit OBJ_FLAGS2_7, e + jr z, .skip2 + or PRIORITY +.skip2 + bit USE_OBP1_F, e + jr z, .skip3 + or OBP_NUM +.skip3 + ld hl, OBJECT_PALETTE add hl, bc ld d, a ld a, [hl] - and $7 + and PALETTE_MASK or d ld d, a xor a - bit 3, e - jr z, .asm_599d - or $80 -.asm_599d - ldh [hFFC4], a - ld hl, $2 + bit OVERHEAD_F, e + jr z, .skip4 + or PRIORITY +.skip4 + ldh [hCurSpriteOAMFlags], a + ld hl, OBJECT_SPRITE_TILE add hl, bc ld a, [hl] - ldh [hFFC3], a - ld hl, $17 + ldh [hCurSpriteTile], a + ld hl, OBJECT_SPRITE_X add hl, bc ld a, [hl] - ld hl, $19 + ld hl, OBJECT_SPRITE_X_OFFSET add hl, bc add [hl] - add $8 + add 8 ld e, a - ld a, [wce81] + ld a, [wPlayerBGMapOffsetX] add e - ldh [hFFC1], a - ld hl, $18 + ldh [hCurSpriteXPixel], a + ld hl, OBJECT_SPRITE_Y add hl, bc ld a, [hl] - ld hl, $1a + ld hl, OBJECT_SPRITE_Y_OFFSET add hl, bc add [hl] - add $c + add 12 ld e, a - ld a, [wce82] + ld a, [wPlayerBGMapOffsetY] add e - ldh [hFFC2], a - ld hl, $d + ldh [hCurSpriteYPixel], a + ld hl, OBJECT_FACING_STEP add hl, bc ld a, [hl] - cp $ff - jp z, .asm_5a23 - cp $20 - jp nc, .asm_5a23 + cp STANDING + jp z, .done + cp NUM_FACINGS + jp nc, .done ld l, a - ld h, $0 + ld h, 0 add hl, hl ld bc, Facings add hl, bc @@ -1378,62 +2856,62 @@ Function597a: ; 597a (1:597a) ld l, a ldh a, [hUsedSpriteIndex] ld c, a - ld b, $c3 + ld b, HIGH(wVirtualOAM) ld a, [hli] ldh [hUsedSpriteTile], a add c - cp $a0 - jr nc, .asm_5a25 -.asm_59f3 - ldh a, [hFFC2] + cp LOW(wVirtualOAMEnd) + jr nc, .full +.addsprite + ldh a, [hCurSpriteYPixel] add [hl] inc hl - ld [bc], a + ld [bc], a ; y inc c - ldh a, [hFFC1] + ldh a, [hCurSpriteXPixel] add [hl] inc hl - ld [bc], a + ld [bc], a ; x inc c ld e, [hl] inc hl - ldh a, [hFFC3] - bit 2, e - jr z, .asm_5a08 + ldh a, [hCurSpriteTile] + bit ABSOLUTE_TILE_ID_F, e + jr z, .nope1 xor a -.asm_5a08 +.nope1 add [hl] inc hl - ld [bc], a + ld [bc], a ; tile id inc c ld a, e - bit 1, a - jr z, .asm_5a14 - ldh a, [hFFC4] + bit RELATIVE_ATTRIBUTES_F, a + jr z, .nope2 + ldh a, [hCurSpriteOAMFlags] or e -.asm_5a14 - and $f0 +.nope2 + and OBP_NUM | X_FLIP | Y_FLIP | PRIORITY or d - ld [bc], a + ld [bc], a ; attributes inc c ldh a, [hUsedSpriteTile] dec a ldh [hUsedSpriteTile], a - jr nz, .asm_59f3 + jr nz, .addsprite ld a, c ldh [hUsedSpriteIndex], a -.asm_5a23 +.done xor a ret -.asm_5a25 +.full scf ret -Function5a27: ; 5a27 (1:5a27) +.GetObjectStructPointer: ld c, a - ld b, $0 - ld hl, ObjectStructPointers + ld b, 0 + ld hl, .Addresses add hl, bc add hl, bc ld c, [hl] @@ -1441,7 +2919,7 @@ Function5a27: ; 5a27 (1:5a27) ld b, [hl] ret -ObjectStructPointers: +.Addresses: dw wPlayerStruct dw wObject1Struct dw wObject2Struct diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm index 39f99480..1a819acb 100755 --- a/engine/overworld/movement.asm +++ b/engine/overworld/movement.asm @@ -1,776 +1,767 @@ -GetMovementByte: - ld hl, wMovementDataBank - call _GetMovementByte +MovementPointers: +; entries correspond to macros/scripts/movement.asm enumeration + dw Movement_turn_head_down ; 00 + dw Movement_turn_head_up ; 01 + dw Movement_turn_head_left ; 02 + dw Movement_turn_head_right ; 03 + dw Movement_turn_step_down ; 04 + dw Movement_turn_step_up ; 05 + dw Movement_turn_step_left ; 06 + dw Movement_turn_step_right ; 07 + dw Movement_slow_step_down ; 08 + dw Movement_slow_step_up ; 09 + dw Movement_slow_step_left ; 0a + dw Movement_slow_step_right ; 0b + dw Movement_step_down ; 0c + dw Movement_step_up ; 0d + dw Movement_step_left ; 0e + dw Movement_step_right ; 0f + dw Movement_big_step_down ; 10 + dw Movement_big_step_up ; 11 + dw Movement_big_step_left ; 12 + dw Movement_big_step_right ; 13 + dw Movement_slow_slide_step_down ; 14 + dw Movement_slow_slide_step_up ; 15 + dw Movement_slow_slide_step_left ; 16 + dw Movement_slow_slide_step_right ; 17 + dw Movement_slide_step_down ; 18 + dw Movement_slide_step_up ; 19 + dw Movement_slide_step_left ; 1a + dw Movement_slide_step_right ; 1b + dw Movement_fast_slide_step_down ; 1c + dw Movement_fast_slide_step_up ; 1d + dw Movement_fast_slide_step_left ; 1e + dw Movement_fast_slide_step_right ; 1f + dw Movement_turn_away_down ; 20 + dw Movement_turn_away_up ; 21 + dw Movement_turn_away_left ; 22 + dw Movement_turn_away_right ; 23 + dw Movement_turn_in_down ; 24 + dw Movement_turn_in_up ; 25 + dw Movement_turn_in_left ; 26 + dw Movement_turn_in_right ; 27 + dw Movement_turn_waterfall_down ; 28 + dw Movement_turn_waterfall_up ; 29 + dw Movement_turn_waterfall_left ; 2a + dw Movement_turn_waterfall_right ; 2b + dw Movement_slow_jump_step_down ; 2c + dw Movement_slow_jump_step_up ; 2d + dw Movement_slow_jump_step_left ; 2e + dw Movement_slow_jump_step_right ; 2f + dw Movement_jump_step_down ; 30 + dw Movement_jump_step_up ; 31 + dw Movement_jump_step_left ; 32 + dw Movement_jump_step_right ; 33 + dw Movement_fast_jump_step_down ; 34 + dw Movement_fast_jump_step_up ; 35 + dw Movement_fast_jump_step_left ; 36 + dw Movement_fast_jump_step_right ; 37 + dw Movement_remove_sliding ; 38 + dw Movement_set_sliding ; 39 + dw Movement_remove_fixed_facing ; 3a + dw Movement_fix_facing ; 3b + dw Movement_show_object ; 3c + dw Movement_hide_object ; 3d + dw Movement_step_sleep_1 ; 3e + dw Movement_step_sleep_2 ; 3f + dw Movement_step_sleep_3 ; 40 + dw Movement_step_sleep_4 ; 41 + dw Movement_step_sleep_5 ; 42 + dw Movement_step_sleep_6 ; 43 + dw Movement_step_sleep_7 ; 44 + dw Movement_step_sleep_8 ; 45 + dw Movement_step_sleep ; 46 + dw Movement_step_end ; 47 + dw Movement_48 ; 48 + dw Movement_remove_object ; 49 + dw Movement_step_loop ; 4a + dw Movement_4b ; 4b + dw Movement_teleport_from ; 4c + dw Movement_teleport_to ; 4d + dw Movement_skyfall ; 4e + dw Movement_step_dig ; 4f + dw Movement_step_bump ; 50 + dw Movement_fish_got_bite ; 51 + dw Movement_fish_cast_rod ; 52 + dw Movement_hide_emote ; 53 + dw Movement_show_emote ; 54 + dw Movement_step_shake ; 55 + dw Movement_tree_shake ; 56 + dw Movement_rock_smash ; 57 + dw Movement_return_dig ; 58 + +Movement_teleport_from: + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_TELEPORT_FROM ret -Function4fbd: - ld hl, $1b - add hl, bc - ld e, [hl] - inc [hl] - ld d, $0 - ld hl, wMovementObject - ld a, [hli] - ld h, [hl] - ld l, a - add hl, de - ld a, [hl] - ret - -Function4fce: - ld hl, $1b - add hl, bc - ld e, [hl] - inc [hl] - ld d, $0 - ld hl, wce8f - ld a, [hli] - ld h, [hl] - ld l, a - add hl, de - ld a, [hl] - ret - -Function4fdf: ; 4fdf (1:4fdf) - ld hl, GetMovementPerson - jp Function4fe9 - -GetMovementPerson: - ld a, [wMovementObject] - ret - -Function4fe9: ; 4fe9 (1:4fe9) - call Function4ffd -.asm_4fec - xor a - ld [wce93], a - call Function5006 - call Function5013 - ld a, [wce93] - and a - jr nz, .asm_4fec - ret - -Function4ffd: ; 4ffd (1:4ffd) - ld a, l - ld [wce94], a - ld a, h - ld [wce95], a - ret - -Function5006: ; 5006 (1:5006) - ld hl, wce94 - ld a, [hli] - ld h, [hl] - ld l, a - jp hl - -Function500d: ; 500d (1:500d) - ld a, $1 - ld [wce93], a - ret - -Function5013: ; 5013 (1:5013) - push af - call Function5457 - pop af - ld hl, MovementPointers - rst JumpTable - ret - -MovementPointers: ; 501d - dw Function527d - dw Function5281 - dw Function5285 - dw Function5289 - dw Function538f - dw Function5393 - dw Function5397 - dw Function539b - dw Function529f - dw Function52a4 - dw Function52a9 - dw Function52ae - dw Function52b3 - dw Function52b8 - dw Function52bd - dw Function52c2 - dw Function52c7 - dw Function52cc - dw Function52d1 - dw Function52d6 - dw Function5317 - dw Function531c - dw Function5321 - dw Function5326 - dw Function532b - dw Function5330 - dw Function5335 - dw Function533a - dw Function533f - dw Function5344 - dw Function5349 - dw Function534e - dw Function52db - dw Function52e0 - dw Function52e5 - dw Function52ea - dw Function52ef - dw Function52f4 - dw Function52f9 - dw Function52fe - dw Function5303 - dw Function5308 - dw Function530d - dw Function5312 - dw Function5353 - dw Function5358 - dw Function535d - dw Function5362 - dw Function5367 - dw Function536c - dw Function5371 - dw Function5376 - dw Function537b - dw Function5380 - dw Function5385 - dw Function538a - dw Function5232 - dw Function523b - dw Function5244 - dw Function524d - dw Function5256 - dw Function525f - dw Function51c1 - dw Function51c5 - dw Function51c9 - dw Function51cd - dw Function51d1 - dw Function51d5 - dw Function51d9 - dw Function51dd - dw Function51e1 - dw Function5160 - dw Function517a - dw Function519c - dw Function5157 - dw Function51af - dw Function50cf - dw Function50d6 - dw Function50dd - dw Function50e4 - dw Function51fe - dw Function5128 - dw Function514a - dw Function5268 - dw Function526e - dw Function5274 - dw Function5218 - dw Function5135 - dw Function5109 - -Function50cf: ; 50cf (1:50cf) - ld hl, $9 - add hl, bc - ld [hl], $c - ret - -Function50d6: ; 50d6 (1:50d6) - ld hl, $9 +Movement_teleport_to: + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $d + ld [hl], STEP_TYPE_TELEPORT_TO ret -Function50dd: ; 50dd (1:50dd) - ld hl, $9 +Movement_skyfall: + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $e + ld [hl], STEP_TYPE_SKYFALL ret -Function50e4: ; 50e4 (1:50e4) +Movement_step_dig: call GetSpriteDirection rlca rlca - ld hl, $c + ld hl, OBJECT_STEP_FRAME add hl, bc ld [hl], a - ld hl, $b + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $4 - call Function5006 - ld hl, $a + ld [hl], OBJECT_ACTION_SPIN + call JumpMovementPointer + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a - ld hl, $9 + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $3 - ld hl, $7 + ld [hl], STEP_TYPE_03 + ld hl, OBJECT_DIRECTION_WALKING add hl, bc - ld [hl], $ff + ld [hl], STANDING ret -Function5109: ; 5109 (1:5109) +Movement_return_dig: call GetSpriteDirection rlca rlca - ld hl, $c + ld hl, OBJECT_STEP_FRAME add hl, bc ld [hl], a - call Function5006 - ld hl, $a + call JumpMovementPointer + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a - ld hl, $7 + ld hl, OBJECT_DIRECTION_WALKING add hl, bc - ld [hl], $ff - ld hl, $9 + ld [hl], STANDING + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $12 + ld [hl], STEP_TYPE_RETURN_DIG ret -Function5128: ; 5128 (1:5128) - ld hl, $b +Movement_fish_got_bite: + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $6 - ld hl, $9 + ld [hl], OBJECT_ACTION_FISHING + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $10 + ld [hl], STEP_TYPE_GOT_BITE ret -Function5135: ; 5135 (1:5135) - call Function5006 - ld hl, $a +Movement_rock_smash: + call JumpMovementPointer + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a - ld hl, $b + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $1 - ld hl, $9 + ld [hl], OBJECT_ACTION_STAND + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $11 + ld [hl], STEP_TYPE_ROCK_SMASH ret -Function514a: ; 514a (1:514a) - ld hl, $b +Movement_fish_cast_rod: + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $6 - ld hl, $9 + ld [hl], OBJECT_ACTION_FISHING + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $1 + ld [hl], STEP_TYPE_SLEEP ret -Function5157: ; 5157 (1:5157) - ld hl, $1b +Movement_step_loop: + ld hl, OBJECT_MOVEMENT_BYTE_INDEX add hl, bc ld [hl], $0 - jp Function500d + jp ContinueReadingMovement -Function5160: ; 5160 (1:5160) +Movement_step_end: call RestoreDefaultMovement - ld hl, $3 + ld hl, OBJECT_MOVEMENTTYPE add hl, bc ld [hl], a - ld hl, $1b + + ld hl, OBJECT_MOVEMENT_BYTE_INDEX add hl, bc ld [hl], $0 + ld hl, wVramState res 7, [hl] - ld hl, $9 + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $1 + ld [hl], STEP_TYPE_SLEEP ret -Function517a: ; 517a (1:517a) +Movement_48: call RestoreDefaultMovement - ld hl, $3 + ld hl, OBJECT_MOVEMENTTYPE add hl, bc ld [hl], a - ld hl, $1b + + ld hl, OBJECT_MOVEMENT_BYTE_INDEX add hl, bc ld [hl], $0 - call Function5006 - ld hl, $a + + call JumpMovementPointer + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a - ld hl, $9 + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $3 + ld [hl], STEP_TYPE_03 + ld hl, wVramState res 7, [hl] ret -Function519c: ; 519c (1:519c) +Movement_remove_object: call DeleteMapObject ld hl, wObjectFollow_Leader ldh a, [hMapObjectIndexBuffer] cp [hl] - jr nz, .asm_51a9 - ld [hl], $ff -.asm_51a9 + jr nz, .not_leading + ld [hl], -1 + +.not_leading ld hl, wVramState res 7, [hl] ret -Function51af: ; 51af (1:51af) - ld hl, $b +Movement_4b: + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $1 - ld hl, $9 + ld [hl], OBJECT_ACTION_STAND + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $4 + ld [hl], STEP_TYPE_04 + ld hl, wVramState res 7, [hl] ret -Function51c1: ; 51c1 (1:51c1) - ld a, $1 - jr asm_51e6 +Movement_step_sleep_1: + ld a, 1 + jr Movement_step_sleep_common + +Movement_step_sleep_2: + ld a, 2 + jr Movement_step_sleep_common -Function51c5: ; 51c5 (1:51c5) - ld a, $2 - jr asm_51e6 +Movement_step_sleep_3: + ld a, 3 + jr Movement_step_sleep_common -Function51c9: ; 51c9 (1:51c9) - ld a, $3 - jr asm_51e6 +Movement_step_sleep_4: + ld a, 4 + jr Movement_step_sleep_common -Function51cd: ; 51cd (1:51cd) - ld a, $4 - jr asm_51e6 +Movement_step_sleep_5: + ld a, 5 + jr Movement_step_sleep_common -Function51d1: ; 51d1 (1:51d1) - ld a, $5 - jr asm_51e6 +Movement_step_sleep_6: + ld a, 6 + jr Movement_step_sleep_common -Function51d5: ; 51d5 (1:51d5) - ld a, $6 - jr asm_51e6 +Movement_step_sleep_7: + ld a, 7 + jr Movement_step_sleep_common -Function51d9: ; 51d9 (1:51d9) - ld a, $7 - jr asm_51e6 +Movement_step_sleep_8: + ld a, 8 + jr Movement_step_sleep_common -Function51dd: ; 51dd (1:51dd) - ld a, $8 - jr asm_51e6 +Movement_step_sleep: +; parameters: +; duration (DecimalParam) -Function51e1: ; 51e1 (1:51e1) - call Function5006 - jr asm_51e6 + call JumpMovementPointer + jr Movement_step_sleep_common -asm_51e6: - ld hl, $a +Movement_step_sleep_common: + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a - ld hl, $9 + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $3 - ld hl, $b + ld [hl], STEP_TYPE_03 + + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $1 - ld hl, $7 + ld [hl], OBJECT_ACTION_STAND + + ld hl, OBJECT_DIRECTION_WALKING add hl, bc - ld [hl], $ff + ld [hl], STANDING ret -Function51fe: ; 51fe (1:51fe) - ld a, $1 - ld hl, $a +Movement_step_bump: + ld a, 1 + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a - ld hl, $9 + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $b - ld hl, $b + ld [hl], STEP_TYPE_BUMP + + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $3 - ld hl, $7 + ld [hl], OBJECT_ACTION_BUMP + + ld hl, OBJECT_DIRECTION_WALKING add hl, bc - ld [hl], $ff + ld [hl], STANDING ret -Function5218: ; 5218 (1:5218) - ld a, $18 - ld hl, $a +Movement_tree_shake: + ld a, 24 + ld hl, OBJECT_STEP_DURATION add hl, bc ld [hl], a - ld hl, $9 + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $3 - ld hl, $b + ld [hl], STEP_TYPE_03 + + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $b - ld hl, $7 + ld [hl], OBJECT_ACTION_WEIRD_TREE + + ld hl, OBJECT_DIRECTION_WALKING add hl, bc - ld [hl], $ff + ld [hl], STANDING ret -Function5232: ; 5232 (1:5232) - ld hl, $4 +Movement_remove_sliding: + ld hl, OBJECT_FLAGS1 add hl, bc - res 3, [hl] - jp Function500d + res SLIDING_F, [hl] + jp ContinueReadingMovement -Function523b: ; 523b (1:523b) - ld hl, $4 +Movement_set_sliding: + ld hl, OBJECT_FLAGS1 add hl, bc - set 3, [hl] - jp Function500d + set SLIDING_F, [hl] + jp ContinueReadingMovement -Function5244: ; 5244 (1:5244) - ld hl, $4 +Movement_remove_fixed_facing: + ld hl, OBJECT_FLAGS1 add hl, bc - res 2, [hl] - jp Function500d + res FIXED_FACING_F, [hl] + jp ContinueReadingMovement -Function524d: ; 524d (1:524d) - ld hl, $4 +Movement_fix_facing: + ld hl, OBJECT_FLAGS1 add hl, bc - set 2, [hl] - jp Function500d + set FIXED_FACING_F, [hl] + jp ContinueReadingMovement -Function5256: ; 5256 (1:5256) - ld hl, $4 +Movement_show_object: + ld hl, OBJECT_FLAGS1 add hl, bc - res 0, [hl] - jp Function500d + res INVISIBLE_F, [hl] + jp ContinueReadingMovement -Function525f: ; 525f (1:525f) - ld hl, $4 +Movement_hide_object: + ld hl, OBJECT_FLAGS1 add hl, bc - set 0, [hl] - jp Function500d + set INVISIBLE_F, [hl] + jp ContinueReadingMovement + +Movement_hide_emote: + call DespawnEmote + jp ContinueReadingMovement -Function5268: ; 5268 (1:5268) - call Function5518 - jp Function500d +Movement_show_emote: + call SpawnEmote + jp ContinueReadingMovement -Function526e: ; 526e (1:526e) - call Function54e6 - jp Function500d +Movement_step_shake: +; parameters: +; displacement (DecimalParam) -Function5274: ; 5274 (1:5274) - call Function5006 - call Function5504 - jp Function500d + call JumpMovementPointer + call ShakeScreen + jp ContinueReadingMovement -Function527d: ; 527d (1:527d) - ld a, $0 - jr asm_528d +Movement_turn_head_down: + ld a, OW_DOWN + jr TurnHead -Function5281: ; 5281 (1:5281) - ld a, $4 - jr asm_528d +Movement_turn_head_up: + ld a, OW_UP + jr TurnHead -Function5285: ; 5285 (1:5285) - ld a, $8 - jr asm_528d +Movement_turn_head_left: + ld a, OW_LEFT + jr TurnHead -Function5289: ; 5289 (1:5289) - ld a, $c - jr asm_528d +Movement_turn_head_right: + ld a, OW_RIGHT + jr TurnHead -asm_528d: - ld hl, $8 +TurnHead: + ld hl, OBJECT_FACING add hl, bc ld [hl], a - ld hl, $b + + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $1 - ld hl, $7 + ld [hl], OBJECT_ACTION_STAND + + ld hl, OBJECT_DIRECTION_WALKING add hl, bc - ld [hl], $ff + ld [hl], STANDING ret -Function529f: ; 529f (1:529f) - ld a, $0 - jp Function53b1 +Movement_slow_step_down: + ld a, STEP_SLOW << 2 | DOWN + jp NormalStep -Function52a4: ; 52a4 (1:52a4) - ld a, $1 - jp Function53b1 +Movement_slow_step_up: + ld a, STEP_SLOW << 2 | UP + jp NormalStep -Function52a9: ; 52a9 (1:52a9) - ld a, $2 - jp Function53b1 +Movement_slow_step_left: + ld a, STEP_SLOW << 2 | LEFT + jp NormalStep -Function52ae: ; 52ae (1:52ae) - ld a, $3 - jp Function53b1 +Movement_slow_step_right: + ld a, STEP_SLOW << 2 | RIGHT + jp NormalStep -Function52b3: ; 52b3 (1:52b3) - ld a, $4 - jp Function53b1 +Movement_step_down: + ld a, STEP_WALK << 2 | DOWN + jp NormalStep -Function52b8: ; 52b8 (1:52b8) - ld a, $5 - jp Function53b1 +Movement_step_up: + ld a, STEP_WALK << 2 | UP + jp NormalStep -Function52bd: ; 52bd (1:52bd) - ld a, $6 - jp Function53b1 +Movement_step_left: + ld a, STEP_WALK << 2 | LEFT + jp NormalStep -Function52c2: ; 52c2 (1:52c2) - ld a, $7 - jp Function53b1 +Movement_step_right: + ld a, STEP_WALK << 2 | RIGHT + jp NormalStep -Function52c7: ; 52c7 (1:52c7) - ld a, $8 - jp Function53b1 +Movement_big_step_down: + ld a, STEP_BIKE << 2 | DOWN + jp NormalStep -Function52cc: ; 52cc (1:52cc) - ld a, $9 - jp Function53b1 +Movement_big_step_up: + ld a, STEP_BIKE << 2 | UP + jp NormalStep -Function52d1: ; 52d1 (1:52d1) - ld a, $a - jp Function53b1 +Movement_big_step_left: + ld a, STEP_BIKE << 2 | LEFT + jp NormalStep -Function52d6: ; 52d6 (1:52d6) - ld a, $b - jp Function53b1 +Movement_big_step_right: + ld a, STEP_BIKE << 2 | RIGHT + jp NormalStep -Function52db: ; 52db (1:52db) - ld a, $0 - jp Function53e5 +Movement_turn_away_down: + ld a, STEP_SLOW << 2 | DOWN + jp TurningStep -Function52e0: ; 52e0 (1:52e0) - ld a, $1 - jp Function53e5 +Movement_turn_away_up: + ld a, STEP_SLOW << 2 | UP + jp TurningStep -Function52e5: ; 52e5 (1:52e5) - ld a, $2 - jp Function53e5 +Movement_turn_away_left: + ld a, STEP_SLOW << 2 | LEFT + jp TurningStep -Function52ea: ; 52ea (1:52ea) - ld a, $3 - jp Function53e5 +Movement_turn_away_right: + ld a, STEP_SLOW << 2 | RIGHT + jp TurningStep -Function52ef: ; 52ef (1:52ef) - ld a, $4 - jp Function53e5 +Movement_turn_in_down: + ld a, STEP_WALK << 2 | DOWN + jp TurningStep -Function52f4: ; 52f4 (1:52f4) - ld a, $5 - jp Function53e5 +Movement_turn_in_up: + ld a, STEP_WALK << 2 | UP + jp TurningStep -Function52f9: ; 52f9 (1:52f9) - ld a, $6 - jp Function53e5 +Movement_turn_in_left: + ld a, STEP_WALK << 2 | LEFT + jp TurningStep -Function52fe: ; 52fe (1:52fe) - ld a, $7 - jp Function53e5 +Movement_turn_in_right: + ld a, STEP_WALK << 2 | RIGHT + jp TurningStep -Function5303: ; 5303 (1:5303) - ld a, $8 - jp Function53e5 +Movement_turn_waterfall_down: + ld a, STEP_BIKE << 2 | DOWN + jp TurningStep -Function5308: ; 5308 (1:5308) - ld a, $9 - jp Function53e5 +Movement_turn_waterfall_up: + ld a, STEP_BIKE << 2 | UP + jp TurningStep -Function530d: ; 530d (1:530d) - ld a, $a - jp Function53e5 +Movement_turn_waterfall_left: + ld a, STEP_BIKE << 2 | LEFT + jp TurningStep -Function5312: ; 5312 (1:5312) - ld a, $b - jp Function53e5 +Movement_turn_waterfall_right: + ld a, STEP_BIKE << 2 | RIGHT + jp TurningStep -Function5317: ; 5317 (1:5317) - ld a, $0 - jp Function5407 +Movement_slow_slide_step_down: + ld a, STEP_SLOW << 2 | DOWN + jp SlideStep -Function531c: ; 531c (1:531c) - ld a, $1 - jp Function5407 +Movement_slow_slide_step_up: + ld a, STEP_SLOW << 2 | UP + jp SlideStep -Function5321: ; 5321 (1:5321) - ld a, $2 - jp Function5407 +Movement_slow_slide_step_left: + ld a, STEP_SLOW << 2 | LEFT + jp SlideStep -Function5326: ; 5326 (1:5326) - ld a, $3 - jp Function5407 +Movement_slow_slide_step_right: + ld a, STEP_SLOW << 2 | RIGHT + jp SlideStep -Function532b: ; 532b (1:532b) - ld a, $4 - jp Function5407 +Movement_slide_step_down: + ld a, STEP_WALK << 2 | DOWN + jp SlideStep -Function5330: ; 5330 (1:5330) - ld a, $5 - jp Function5407 +Movement_slide_step_up: + ld a, STEP_WALK << 2 | UP + jp SlideStep -Function5335: ; 5335 (1:5335) - ld a, $6 - jp Function5407 +Movement_slide_step_left: + ld a, STEP_WALK << 2 | LEFT + jp SlideStep -Function533a: ; 533a (1:533a) - ld a, $7 - jp Function5407 +Movement_slide_step_right: + ld a, STEP_WALK << 2 | RIGHT + jp SlideStep -Function533f: ; 533f (1:533f) - ld a, $8 - jp Function5407 +Movement_fast_slide_step_down: + ld a, STEP_BIKE << 2 | DOWN + jp SlideStep -Function5344: ; 5344 (1:5344) - ld a, $9 - jp Function5407 +Movement_fast_slide_step_up: + ld a, STEP_BIKE << 2 | UP + jp SlideStep -Function5349: ; 5349 (1:5349) - ld a, $a - jp Function5407 +Movement_fast_slide_step_left: + ld a, STEP_BIKE << 2 | LEFT + jp SlideStep -Function534e: ; 534e (1:534e) - ld a, $b - jp Function5407 +Movement_fast_slide_step_right: + ld a, STEP_BIKE << 2 | RIGHT + jp SlideStep -Function5353: ; 5353 (1:5353) - ld a, $0 - jp Function5429 +Movement_slow_jump_step_down: + ld a, STEP_SLOW << 2 | DOWN + jp JumpStep -Function5358: ; 5358 (1:5358) - ld a, $1 - jp Function5429 +Movement_slow_jump_step_up: + ld a, STEP_SLOW << 2 | UP + jp JumpStep -Function535d: ; 535d (1:535d) - ld a, $2 - jp Function5429 +Movement_slow_jump_step_left: + ld a, STEP_SLOW << 2 | LEFT + jp JumpStep -Function5362: ; 5362 (1:5362) - ld a, $3 - jp Function5429 +Movement_slow_jump_step_right: + ld a, STEP_SLOW << 2 | RIGHT + jp JumpStep -Function5367: ; 5367 (1:5367) - ld a, $4 - jp Function5429 +Movement_jump_step_down: + ld a, STEP_WALK << 2 | DOWN + jp JumpStep -Function536c: ; 536c (1:536c) - ld a, $5 - jp Function5429 +Movement_jump_step_up: + ld a, STEP_WALK << 2 | UP + jp JumpStep -Function5371: ; 5371 (1:5371) - ld a, $6 - jp Function5429 +Movement_jump_step_left: + ld a, STEP_WALK << 2 | LEFT + jp JumpStep -Function5376: ; 5376 (1:5376) - ld a, $7 - jp Function5429 +Movement_jump_step_right: + ld a, STEP_WALK << 2 | RIGHT + jp JumpStep -Function537b: ; 537b (1:537b) - ld a, $8 - jp Function5429 +Movement_fast_jump_step_down: + ld a, STEP_BIKE << 2 | DOWN + jp JumpStep -Function5380: ; 5380 (1:5380) - ld a, $9 - jp Function5429 +Movement_fast_jump_step_up: + ld a, STEP_BIKE << 2 | UP + jp JumpStep -Function5385: ; 5385 (1:5385) - ld a, $a - jp Function5429 +Movement_fast_jump_step_left: + ld a, STEP_BIKE << 2 | LEFT + jp JumpStep -Function538a: ; 538a (1:538a) - ld a, $b - jp Function5429 +Movement_fast_jump_step_right: + ld a, STEP_BIKE << 2 | RIGHT + jp JumpStep -Function538f: ; 538f (1:538f) - ld a, $0 - jr asm_539f +Movement_turn_step_down: + ld a, OW_DOWN + jr TurnStep -Function5393: ; 5393 (1:5393) - ld a, $4 - jr asm_539f +Movement_turn_step_up: + ld a, OW_UP + jr TurnStep -Function5397: ; 5397 (1:5397) - ld a, $8 - jr asm_539f +Movement_turn_step_left: + ld a, OW_LEFT + jr TurnStep -Function539b: ; 539b (1:539b) - ld a, $c - jr asm_539f +Movement_turn_step_right: + ld a, OW_RIGHT + jr TurnStep -asm_539f: - ld hl, $1d +TurnStep: + ld hl, OBJECT_1D ; new facing add hl, bc ld [hl], a - ld hl, $b + + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $2 - ld hl, $9 + ld [hl], OBJECT_ACTION_STEP + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $a + ld [hl], STEP_TYPE_HALF_STEP ret -Function53b1: ; 53b1 (1:53b1) +NormalStep: call InitStep - call UpdateGrassPriority - ld hl, $b + call UpdateTallGrassFlags + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $2 - ld hl, $e + ld [hl], OBJECT_ACTION_STEP + + ld hl, OBJECT_NEXT_TILE add hl, bc ld a, [hl] call CheckSuperTallGrassTile - jr z, .asm_53cc + jr z, .shake_grass + call CheckGrassTile - jr c, .asm_53cf -.asm_53cc - call Function54f5 -.asm_53cf + jr c, .skip_grass + +.shake_grass + call ShakeGrass + +.skip_grass ld hl, wCenteredObject - ldh a, [hConnectionStripLength] + ldh a, [hMapObjectIndexBuffer] cp [hl] - jr z, .asm_53de - ld hl, $9 + jr z, .player + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $2 + ld [hl], STEP_TYPE_NPC_WALK ret -.asm_53de - ld hl, $9 +.player + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $6 + ld [hl], STEP_TYPE_PLAYER_WALK ret -Function53e5: ; 53e5 (1:53e5) +TurningStep: call InitStep - call UpdateGrassPriority - ld hl, $b + call UpdateTallGrassFlags + + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $4 + ld [hl], OBJECT_ACTION_SPIN + ld hl, wCenteredObject ldh a, [hMapObjectIndexBuffer] cp [hl] - jr z, .asm_5400 - ld hl, $9 + jr z, .player + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $2 + ld [hl], STEP_TYPE_NPC_WALK ret -.asm_5400 - ld hl, $9 +.player + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $6 + ld [hl], STEP_TYPE_PLAYER_WALK ret -Function5407: ; 5407 (1:5407) +SlideStep: call InitStep - call UpdateGrassPriority - ld hl, $b + call UpdateTallGrassFlags + + ld hl, OBJECT_ACTION add hl, bc - ld [hl], $1 + ld [hl], OBJECT_ACTION_STAND + ld hl, wCenteredObject - ldh a, [hConnectionStripLength] + ldh a, [hMapObjectIndexBuffer] cp [hl] - jr z, .asm_5422 - ld hl, $9 + jr z, .player + + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_NPC_WALK + ret + +.player + ld hl, OBJECT_STEP_TYPE + add hl, bc + ld [hl], STEP_TYPE_PLAYER_WALK + ret + +JumpStep: + call InitStep + ld hl, OBJECT_1F + add hl, bc + ld [hl], $0 + + ld hl, OBJECT_FLAGS2 + add hl, bc + res OVERHEAD_F, [hl] + + ld hl, OBJECT_ACTION + add hl, bc + ld [hl], OBJECT_ACTION_STEP + call SpawnShadow + ld hl, wCenteredObject + ldh a, [hMapObjectIndexBuffer] + cp [hl] + jr z, .player + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $2 + ld [hl], STEP_TYPE_NPC_JUMP ret -.asm_5422 - ld hl, $9 +.player + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $6 + ld [hl], STEP_TYPE_PLAYER_JUMP ret diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm index e40f2b1c..c0b88a8b 100755 --- a/engine/overworld/npc_movement.asm +++ b/engine/overworld/npc_movement.asm @@ -1,4 +1,4 @@ -CheckNPCMovementPermissions: ; 6fa0 (1:6fa0) +CanObjectMoveInDirection: ; 6fa0 (1:6fa0) ld hl, $6 add hl, bc bit 5, [hl] diff --git a/engine/overworld/player_movement.asm b/engine/overworld/player_movement.asm index 98cce97d..21dd97ca 100755 --- a/engine/overworld/player_movement.asm +++ b/engine/overworld/player_movement.asm @@ -7,7 +7,7 @@ DoPlayerMovement:: ; 10000 (4:4000) call Function1002d ld c, a ld a, [wMovementAnimation] - ld [wce87], a + ld [wPlayerNextMovement], a ret Function10017: ; 10017 (4:4017) @@ -725,7 +725,7 @@ CheckStandingOnIce:: ret StopPlayerForEvent:: - ld hl, wce87 + ld hl, wPlayerNextMovement ld a, $3e cp [hl] ret z diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm index ee8ebe1b..627e3d3f 100755 --- a/engine/overworld/player_object.asm +++ b/engine/overworld/player_object.asm @@ -165,7 +165,7 @@ CopyMapObjectToTempObject: ; 870d (2:470d) add hl, bc ld [hl], a ldh a, [hMapObjectIndexBuffer] - ld [wce99], a + ld [wTempObjectCopyMapObjectIndex], a ld hl, $1 add hl, bc ld a, [hl] @@ -191,7 +191,7 @@ CopyMapObjectToTempObject: ; 870d (2:470d) ld hl, $9 add hl, bc ld a, [hl] - ld [wce9e], a + ld [wTempObjectCopyRange], a ld hl, $3 add hl, bc ld a, [hl] @@ -385,7 +385,7 @@ asm_882e: ret CopyTempObjectToObjectStruct: ; 8876 (2:4876) - ld a, [wce99] + ld a, [wTempObjectCopyMapObjectIndex] ld hl, $1 add hl, de ld [hl], a @@ -416,7 +416,7 @@ CopyTempObjectToObjectStruct: ; 8876 (2:4876) ld [hl], $ff ld a, [wcea1] call InitTempObjectRadius - ld a, [wce9e] + ld a, [wTempObjectCopyRange] ld hl, $20 add hl, de ld [hl], a @@ -434,7 +434,7 @@ InitTempObjectYCoord: ; 88c5 (2:48c5) sub [hl] and $f swap a - ld hl, wce82 + ld hl, wPlayerBGMapOffsetY sub [hl] ld hl, $18 add hl, de @@ -452,7 +452,7 @@ InitTempObjectXCoord: ; 88e1 (2:48e1) sub [hl] and $f swap a - ld hl, wce81 + ld hl, wPlayerBGMapOffsetX sub [hl] ld hl, $17 add hl, de @@ -606,7 +606,7 @@ FollowNotExact:: sub [hl] and $f swap a - ld hl, wce81 + ld hl, wPlayerBGMapOffsetX sub [hl] ld hl, $17 add hl, de @@ -619,7 +619,7 @@ FollowNotExact:: sub [hl] and $f swap a - ld hl, wce82 + ld hl, wPlayerBGMapOffsetY sub [hl] ld hl, $18 add hl, de diff --git a/engine/overworld/player_step.asm b/engine/overworld/player_step.asm index e55fc4e7..2653fd2e 100755 --- a/engine/overworld/player_step.asm +++ b/engine/overworld/player_step.asm @@ -26,12 +26,12 @@ _HandlePlayerStep:: ld d, a ld a, [wPlayerStepVectorY] ld e, a - ld a, [wce81] + ld a, [wPlayerBGMapOffsetX] sub d - ld [wce81], a - ld a, [wce82] + ld [wPlayerBGMapOffsetX], a + ld a, [wPlayerBGMapOffsetY] sub e - ld [wce82], a + ld [wPlayerBGMapOffsetY], a ret ScrollScreen:: diff --git a/engine/step_types.asm b/engine/step_types.asm deleted file mode 100755 index 91858f98..00000000 --- a/engine/step_types.asm +++ /dev/null @@ -1,719 +0,0 @@ -StepTypesJumptable: ; 4b1e - dw ObjectMovementReset - dw MapObjectMovementPattern - dw Function4e02 - dw Function4db4 - dw Function4df8 - dw Function4de3 - dw Function4e2d - dw Function4e1e - dw Function4b5d - dw Function4b96 - dw Function4e5a - dw Function4dd6 - dw Function4bef - dw Function4c60 - dw Function4ceb - dw Function4ea4 - dw Function4d55 - dw Function4d86 - dw Function4d9f - dw Function4edb - dw Function4f0a - dw Function4f0a - dw Function4f4e - dw Function4f51 - dw Function4dc7 - -Function4b50: ; 4b50 (1:4b50) - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4b5d: ; 4b5d (1:4b5d) - call Object28AnonymousJumptable - dw Function4b64 - dw Function4b80 - -Function4b64: - call AddStepVector - call Function4f7d - ld hl, $a - add hl, bc - dec [hl] - ret nz - call CopyNextCoordsTileToStandingCoordsTile - call GetNextTile - ld hl, $5 - add hl, bc - res 3, [hl] - call IncrementObjectStructField28 - ret - -Function4b80: - call AddStepVector - call Function4f7d - ld hl, $a - add hl, bc - dec [hl] - ret nz - call CopyNextCoordsTileToStandingCoordsTile - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4b96: ; 4b96 (1:4b96) - call Object28AnonymousJumptable - dw Function4ba1 - dw Function4ba9 - dw Function4bc9 - dw Function4bd4 - -Function4ba1: - ld hl, wPlayerStepFlags - set 7, [hl] - call IncrementObjectStructField28 -Function4ba9: - call Function4f7d - call UpdatePlayerStep - ld hl, $a - add hl, bc - dec [hl] - ret nz - call CopyNextCoordsTileToStandingCoordsTile - ld hl, $5 - add hl, bc - res 3, [hl] - ld hl, wPlayerStepFlags - set 6, [hl] - set 4, [hl] - call IncrementObjectStructField28 - ret - -Function4bc9: - call GetNextTile - ld hl, wPlayerStepFlags - set 7, [hl] - call IncrementObjectStructField28 -Function4bd4: - call Function4f7d - call UpdatePlayerStep - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, wPlayerStepFlags - set 6, [hl] - call CopyNextCoordsTileToStandingCoordsTile - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4bef: ; 4bef (1:4bef) - call Object28AnonymousJumptable - dw Function4bfa - dw Function4c09 - dw Function4c19 - dw Function4c34 - -Function4bfa: - ld hl, $c - add hl, bc - ld [hl], $0 - ld hl, $a - add hl, bc - ld [hl], $10 - call IncrementObjectStructField28 -Function4c09: - ld hl, $b - add hl, bc - ld [hl], $4 - ld hl, $a - add hl, bc - dec [hl] - ret nz - call IncrementObjectStructField28 - ret - -Function4c19: - ld hl, $c - add hl, bc - ld [hl], $0 - ld hl, $1f - add hl, bc - ld [hl], $10 - ld hl, $a - add hl, bc - ld [hl], $10 - ld hl, $5 - add hl, bc - res 3, [hl] - call IncrementObjectStructField28 -Function4c34: - ld hl, $b - add hl, bc - ld [hl], $4 - ld hl, $1f - add hl, bc - inc [hl] - ld a, [hl] - ld d, $60 - call Sine - ld a, h - sub $60 - ld hl, $1a - add hl, bc - ld [hl], a - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, $c - add hl, bc - ld [hl], $0 - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4c60: ; 4c60 (1:4c60) - call Object28AnonymousJumptable - dw Function4c71 - dw Function4c81 - dw Function4c8a - dw Function4ca0 - dw Function4cc2 - dw Function4ccc - dw Function4cd8 - -Function4c71: - ld hl, $b - add hl, bc - ld [hl], $0 - ld hl, $a - add hl, bc - ld [hl], $10 - call IncrementObjectStructField28 - ret - -Function4c81: - ld hl, $a - add hl, bc - dec [hl] - ret nz - call IncrementObjectStructField28 -Function4c8a: - ld hl, $c - add hl, bc - ld [hl], $0 - ld hl, $1f - add hl, bc - ld [hl], $0 - ld hl, $a - add hl, bc - ld [hl], $10 - call IncrementObjectStructField28 - ret - -Function4ca0: - ld hl, $b - add hl, bc - ld [hl], $4 - ld hl, $1f - add hl, bc - inc [hl] - ld a, [hl] - ld d, $60 - call Sine - ld a, h - sub $60 - ld hl, $1a - add hl, bc - ld [hl], a - ld hl, $a - add hl, bc - dec [hl] - ret nz - call IncrementObjectStructField28 -Function4cc2: - ld hl, $a - add hl, bc - ld [hl], $10 - call IncrementObjectStructField28 - ret - -Function4ccc: - ld hl, $b - add hl, bc - ld [hl], $4 - ld hl, $a - add hl, bc - dec [hl] - ret nz -Function4cd8: - ld hl, $c - add hl, bc - ld [hl], $0 - ld hl, $1a - add hl, bc - ld [hl], $0 - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4ceb: ; 4ceb (1:4ceb) - call Object28AnonymousJumptable - dw Function4cf6 - dw Function4d05 - dw Function4d26 - dw Function4d42 - -Function4cf6: - ld hl, $b - add hl, bc - ld [hl], $0 - ld hl, $a - add hl, bc - ld [hl], $10 - call IncrementObjectStructField28 -Function4d05: - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, $b - add hl, bc - ld [hl], $2 - ld hl, $c - add hl, bc - ld [hl], $0 - ld hl, $1f - add hl, bc - ld [hl], $0 - ld hl, $a - add hl, bc - ld [hl], $10 - call IncrementObjectStructField28 -Function4d26: - ld hl, $1f - add hl, bc - inc [hl] - ld a, [hl] - ld d, $60 - call Sine - ld a, h - sub $60 - ld hl, $1a - add hl, bc - ld [hl], a - ld hl, $a - add hl, bc - dec [hl] - ret nz - call IncrementObjectStructField28 -Function4d42: - ld hl, $c - add hl, bc - ld [hl], $0 - ld hl, $1a - add hl, bc - ld [hl], $0 - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4d55: ; 4d55 (1:4d55) - call Object28AnonymousJumptable - dw Function4d5c - dw Function4d6b - -Function4d5c: - ld hl, $a - add hl, bc - ld [hl], $8 - ld hl, $1a - add hl, bc - ld [hl], $0 - call IncrementObjectStructField28 -Function4d6b: - ld hl, $1a - add hl, bc - ld a, [hl] - xor $1 - ld [hl], a - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, $1a - add hl, bc - ld [hl], $0 - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4d86: ; 4d86 (1:4d86) - call Function4d8c - jp Function4b50 - -Function4d8c: ; 4d8c (1:4d8c) - ld hl, $a - add hl, bc - ld a, [hl] - and $1 - ld a, $1 - jr z, .asm_4d99 - ld a, $0 -.asm_4d99 - ld hl, $b - add hl, bc - ld [hl], a - ret - -Function4d9f: ; 4d9f (1:4d9f) - ld hl, $a - add hl, bc - ld a, [hl] - and $1 - ld a, $4 - jr z, .asm_4dac - ld a, $5 -.asm_4dac - ld hl, $b - add hl, bc - ld [hl], a - jp Function4b50 - -Function4db4: ; 4db4 (1:4db4) - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4dc7: ; 4dc7 (1:4dc7) - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $a - add hl, bc - dec [hl] - ret nz - jp DeleteMapObject - -Function4dd6: ; 4dd6 (1:4dd6) - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4de3: ; 4de3 (1:4de3) - call Object28AnonymousJumptable - dw Function4dea - dw Function4df8 - -Function4dea: - call RestoreDefaultMovement - call GetInitialFacing - ld hl, $8 - add hl, bc - ld [hl], a - call IncrementObjectStructField28 -Function4df8: ; 4df8 (1:4df8) - call Function4f5a - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -Function4e02: ; 4e02 (1:4e02) - call Function4f5a - call AddStepVector - ld hl, $a - add hl, bc - dec [hl] - ret nz - call CopyNextCoordsTileToStandingCoordsTile - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4e1e: ; 4e1e (1:4e1e) - call AddStepVector - ld hl, $a - add hl, bc - dec [hl] - ret nz - call CopyNextCoordsTileToStandingCoordsTile - jp Function4af6 - -Function4e2d: ; 4e2d (1:4e2d) - call Object28AnonymousJumptable - dw Function4e34 - dw Function4e3c - -Function4e34: - ld hl, wPlayerStepFlags - set 7, [hl] - call IncrementObjectStructField28 -Function4e3c: - call UpdatePlayerStep - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, wPlayerStepFlags - set 6, [hl] - call CopyNextCoordsTileToStandingCoordsTile - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4e5a: ; 4e5a (1:4e5a) - call Object28AnonymousJumptable - dw Function4e65 - dw Function4e7b - dw Function4e84 - dw Function4e97 - -Function4e65: - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $c - add hl, bc - ld a, [hl] - ld [hl], $2 - ld hl, $a - add hl, bc - ld [hl], $2 - call IncrementObjectStructField28 -Function4e7b: - ld hl, $a - add hl, bc - dec [hl] - ret nz - call IncrementObjectStructField28 -Function4e84: - ld hl, $1d - add hl, bc - ld a, [hl] - ld hl, $8 - add hl, bc - ld [hl], a - ld hl, $a - add hl, bc - ld [hl], $2 - call IncrementObjectStructField28 -Function4e97: - ld hl, $a - add hl, bc - dec [hl] - ret nz - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4ea4: ; 4ea4 (1:4ea4) - call AddStepVector - ld hl, $a - add hl, bc - dec [hl] - ret nz - push bc - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - ld hl, $1 - add hl, bc - ld a, [hl] - ld b, a - farcall CopyDECoordsToMapObject - pop bc - ld hl, $5 - add hl, bc - res 2, [hl] - call CopyNextCoordsTileToStandingCoordsTile - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function4edb: ; 4edb (1:4edb) - ld hl, $1d - add hl, bc - ld e, [hl] - inc hl - ld d, [hl] - ld hl, $0 - add hl, de - ld a, [hl] - and a - jr z, .asm_4f07 - ld hl, $17 - add hl, de - ld a, [hl] - ld hl, $17 - add hl, bc - ld [hl], a - ld hl, $18 - add hl, de - ld a, [hl] - ld hl, $18 - add hl, bc - ld [hl], a - ld hl, $a - add hl, bc - ld a, [hl] - and a - ret z - dec [hl] - ret nz -.asm_4f07 - jp DeleteMapObject - -Function4f0a: ; 4f0a (1:4f0a) - call Object28AnonymousJumptable - dw Function4f11 - dw Function4f1a - -Function4f11: - xor a - ld hl, $1d - add hl, bc - ld [hl], a - call IncrementObjectStructField28 -Function4f1a: - ld hl, $1d - add hl, bc - ld d, [hl] - ld a, [wPlayerStepVectorY] - sub d - ld [wPlayerStepVectorY], a - ld hl, $a - add hl, bc - dec [hl] - jr z, .asm_4f3f - ld a, [hl] - call Function4f43 - ld hl, $1d - add hl, bc - ld [hl], a - ld d, a - ld a, [wPlayerStepVectorY] - add d - ld [wPlayerStepVectorY], a - ret - -.asm_4f3f - call DeleteMapObject - ret - -Function4f43: ; 4f43 (1:4f43) - ld hl, $1e - add hl, bc - and $1 - ld a, [hl] - ret z - cpl - inc a - ret - -Function4f4e: ; 4f4e (1:4f4e) - call Object28AnonymousJumptable -Function4f51: ; 4f51 (1:4f51) - call Object28AnonymousJumptable - dw Function4f5a - dw Function4f5a - dw Function4f5a - -Function4f5a: ; 4f5a (1:4f5a) - ret - -Function4f5b: - ld hl, $1d - add hl, bc - inc [hl] - ld a, [hl] - srl a - srl a - and $7 - ld l, a - ld h, $0 - ld de, .data - add hl, de - ld a, [hl] - ld hl, $1a - add hl, bc - ld [hl], a - ret - -.data - db 0, -1, -2, -3, -4, -3, -2, -1 - -Function4f7d: ; 4f7d (1:4f7d) - call GetStepVector - ld a, h - ld hl, $1f - add hl, bc - ld e, [hl] - add e - ld [hl], a - nop - srl e - ld d, $0 - ld hl, .data - add hl, de - ld a, [hl] - ld hl, $1a - add hl, bc - ld [hl], a - ret - -.data - db -4, -6, -8, -10, -11, -12, -12, -12 - db -11, -10, -9, -8, -6, -4, 0, 0 - -Function4fa8: - ld a, [wce87] - ld hl, wce88 - ld [hl], a - ld a, $3e - ld [wce87], a - ld a, [hl] - ret @@ -92,12 +92,17 @@ NEXTU ; ffb5 hMGStatusFlags:: db ; ffbe ENDU ; ffbf +UNION hUsedSpriteIndex:: db ; ffbf hUsedSpriteTile:: db ; ffc0 -hFFC1:: db ; ffc1 -hFFC2:: db ; ffc2 -hFFC3:: db ; ffc3 -hFFC4:: db ; ffc4 +NEXTU +hCurSpriteXCoord:: db ; ffbf +hCurSpriteYCoord:: db ; ffc0 +hCurSpriteXPixel:: db ; ffc1 +hCurSpriteYPixel:: db ; ffc2 +hCurSpriteTile:: db ; ffc3 +hCurSpriteOAMFlags:: db ; ffc4 +ENDU UNION ; ffc5 hMoneyTemp:: ds 3 ; ffc5 diff --git a/macros/scripts/movement.asm b/macros/scripts/movement.asm index eeda6bd8..2896700e 100644 --- a/macros/scripts/movement.asm +++ b/macros/scripts/movement.asm @@ -213,8 +213,3 @@ return_dig: MACRO db movement_return_dig db \1 ; length ENDM - - enum movement_skyfall_top ; $59 -skyfall_top: MACRO - db movement_skyfall_top -ENDM @@ -691,9 +691,9 @@ ShakeHeadbuttTree:: dr $8ca8e, $8cbb8 OWCutAnimation:: dr $8cbb8, $8cd65 -FlyFromAnimation:: +FlyFromAnim:: dr $8cd65, $8cdab -FlyToAnimation:: +FlyToAnim:: dr $8cdab, $8ce7c MagnetTrain:: dr $8ce7c, $8d174 @@ -786,12 +786,16 @@ Function9188a:: Function919c1:: dr $919c1, $91a4f TownMap_:: - dr $91a4f, $91c7f + dr $91a4f, $91a61 +_FlyMap:: + dr $91a61, $91c7f Pokedex_GetArea:: dr $91c7f, $92364 GetLandmarkName:: - dr $92364, $92c36 + dr $92364, $9297a +Fish:: + dr $9297a, $92c36 Function92c36:: dr $92c36, $93f86 @@ -1802,16 +1802,16 @@ wce7d:: ds 1 ; ce7d wce7e:: ds 1 ; ce7e wce7f:: ds 1 ; ce7f wce80:: ds 1 ; ce80 -wce81:: ds 1 ; ce81 -wce82:: ds 1 ; ce82 +wPlayerBGMapOffsetX:: db ; ce81 +wPlayerBGMapOffsetY:: db ; ce82 wPlayerStepVectorX:: ds 1 ; ce83 wPlayerStepVectorY:: ds 1 ; ce84 wPlayerStepFlags:: ds 1 ; ce85 wPlayerStepDirection:: ds 1 ; ce86 -wce87:: ds 1 ; ce87 -wce88:: ds 1 ; ce88 +wPlayerNextMovement:: db ; ce87 +wPlayerMovement:: db ; ce88 wce89:: ds 1 ; ce89 wce8a:: ds 1 ; ce8a wMovementObject:: ds 1 ; ce8b @@ -1821,18 +1821,17 @@ wce8f:: ds 1 ; ce8f wce90:: ds 1 ; ce90 wce91:: ds 1 ; ce91 wce92:: ds 1 ; ce92 -wce93:: ds 1 ; ce93 -wce94:: ds 1 ; ce94 -wce95:: ds 1 ; ce95 -wce96:: ds 1 ; ce96 -wce97:: ds 1 ; ce97 -wce98:: ds 1 ; ce98 -wce99:: ds 1 ; ce99 +wMovementByteWasControlSwitch:: db ; ce93 +wMovementPointer:: dw ; ce94 + + ds 3 + +wTempObjectCopyMapObjectIndex:: db ; ce99 wce9a:: ds 1 ; ce9a wce9b:: ds 1 ; ce9b wce9c:: ds 1 ; ce9c wce9d:: ds 1 ; ce9d -wce9e:: ds 1 ; ce9e +wTempObjectCopyRange:: db ; ce9e wce9f:: ds 1 ; ce9f wcea0:: ds 1 ; cea0 wcea1:: ds 1 ; cea1 @@ -2751,7 +2750,7 @@ wd56a:: ds 1 ; d56a wd56b:: ds 1 ; d56b wd56c:: ds 1 ; d56c wd56d:: ds 1 ; d56d -wd56e:: ds 1 ; d56e +wTimeOfDayPalset:: ds 1 ; d56e wd56f:: ds 1 ; d56f wd570:: ds 1 ; d570 wPlayerData2End:: @@ -3265,10 +3264,9 @@ wd9bb:: ds 1 ; d9bb wd9bc:: ds 1 ; d9bc wStepCount:: db ; d9bd wPoisonStepCount:: db ; d9be -wd9bf:: ds 1 ; d9bf -wd9c0:: ds 1 ; d9c0 -wd9c1:: ds 1 ; d9c1 -wd9c2:: ds 1 ; d9c2 + ds 2 +wHappinessStepCount:: db ; d9c1 + ds 1 wParkBallsRemaining:: db ; d9c3 wd9c4:: ds 1 ; d9c4 wd9c5:: ds 1 ; d9c5 |