From 94df3c5aa3f7426d48e51567c55037e35161fa33 Mon Sep 17 00:00:00 2001 From: Idain Date: Wed, 26 Jul 2023 20:50:16 -0400 Subject: [PATCH] Replace magic numbers with TILE_WIDTH (#1056) * Replace magic numbers with TILE_WIDTH * Address more instances --- engine/battle/trainer_huds.asm | 20 ++++++++++---------- engine/battle_anims/core.asm | 6 +++--- engine/events/field_moves.asm | 2 +- engine/games/slot_machine.asm | 14 +++++++------- engine/gfx/color.asm | 4 ++-- engine/gfx/mon_icons.asm | 12 ++++++------ engine/gfx/sprite_anims.asm | 6 +++--- engine/menus/intro_menu.asm | 8 ++++---- engine/menus/naming_screen.asm | 2 +- engine/overworld/map_objects.asm | 6 +++--- engine/pokegear/pokegear.asm | 8 ++++---- engine/pokemon/breeding.asm | 6 +++--- engine/pokemon/health.asm | 4 ++-- macros/scripts/battle_anims.asm | 4 ++-- mobile/fixed_words.asm | 6 +++--- mobile/mobile_42.asm | 8 ++++---- mobile/mobile_46.asm | 8 ++++---- 17 files changed, 62 insertions(+), 62 deletions(-) diff --git a/engine/battle/trainer_huds.asm b/engine/battle/trainer_huds.asm index 158b35846..2be4d64bb 100644 --- a/engine/battle/trainer_huds.asm +++ b/engine/battle/trainer_huds.asm @@ -20,11 +20,11 @@ ShowPlayerMonsRemaining: ld de, wPartyCount call StageBallTilesData ; ldpixel wPlaceBallsX, 12, 12 - ld a, 12 * 8 + ld a, 12 * TILE_WIDTH ld hl, wPlaceBallsX ld [hli], a ld [hl], a - ld a, 8 + ld a, TILE_WIDTH ld [wPlaceBallsDirection], a ld hl, wShadowOAMSprite00 jp LoadTrainerHudOAM @@ -36,10 +36,10 @@ ShowOTTrainerMonsRemaining: call StageBallTilesData ; ldpixel wPlaceBallsX, 9, 4 ld hl, wPlaceBallsX - ld a, 9 * 8 + ld a, 9 * TILE_WIDTH ld [hli], a - ld [hl], 4 * 8 - ld a, -8 + ld [hl], 4 * TILE_WIDTH + ld a, -TILE_WIDTH ld [wPlaceBallsDirection], a ld hl, wShadowOAMSprite00 + PARTY_LENGTH * SPRITEOAMSTRUCT_LENGTH jp LoadTrainerHudOAM @@ -182,10 +182,10 @@ LinkBattle_TrainerHuds: ld de, wPartyCount call StageBallTilesData ld hl, wPlaceBallsX - ld a, 10 * 8 + ld a, 10 * TILE_WIDTH ld [hli], a - ld [hl], 8 * 8 - ld a, 8 + ld [hl], 8 * TILE_WIDTH + ld a, TILE_WIDTH ld [wPlaceBallsDirection], a ld hl, wShadowOAMSprite00 call LoadTrainerHudOAM @@ -194,9 +194,9 @@ LinkBattle_TrainerHuds: ld de, wOTPartyCount call StageBallTilesData ld hl, wPlaceBallsX - ld a, 10 * 8 + ld a, 10 * TILE_WIDTH ld [hli], a - ld [hl], 13 * 8 + ld [hl], 13 * TILE_WIDTH ld hl, wShadowOAMSprite00 + PARTY_LENGTH * SPRITEOAMSTRUCT_LENGTH jp LoadTrainerHudOAM diff --git a/engine/battle_anims/core.asm b/engine/battle_anims/core.asm index 7043ea249..ca22fcf87 100644 --- a/engine/battle_anims/core.asm +++ b/engine/battle_anims/core.asm @@ -243,7 +243,7 @@ InitBattleAnimBuffer: add hl, bc ld a, [hli] ld d, a - ld a, (-10 * 8) + 4 + ld a, (-10 * TILE_WIDTH) + 4 sub d ld [wBattleAnimTempXCoord], a ld a, [hli] @@ -251,7 +251,7 @@ InitBattleAnimBuffer: ld a, [wBattleAnimTempFixY] cp $ff jr nz, .check_kinesis_softboiled_milkdrink - ld a, 5 * 8 + ld a, 5 * TILE_WIDTH add d jr .done @@ -270,7 +270,7 @@ InitBattleAnimBuffer: jr nz, .no_sub .do_sub pop af - sub 1 * 8 + sub 1 * TILE_WIDTH jr .done .no_sub diff --git a/engine/events/field_moves.asm b/engine/events/field_moves.asm index addefb888..6e94f1693 100644 --- a/engine/events/field_moves.asm +++ b/engine/events/field_moves.asm @@ -348,7 +348,7 @@ FlyToAnim: ld [hl], SPRITE_ANIM_SEQ_FLY_TO ld hl, SPRITEANIMSTRUCT_VAR4 add hl, bc - ld [hl], 11 * 8 + ld [hl], 11 * TILE_WIDTH ld a, 64 ld [wFrameCounter], a .loop diff --git a/engine/games/slot_machine.asm b/engine/games/slot_machine.asm index 0aaa63614..3a42172b9 100644 --- a/engine/games/slot_machine.asm +++ b/engine/games/slot_machine.asm @@ -681,7 +681,7 @@ Slots_InitReelTiles: ld [hl], d ld hl, REEL_X_COORD add hl, bc - ld [hl], 6 * 8 + ld [hl], 6 * TILE_WIDTH call .OAM ld bc, wReel2 @@ -699,7 +699,7 @@ Slots_InitReelTiles: ld [hl], d ld hl, REEL_X_COORD add hl, bc - ld [hl], 10 * 8 + ld [hl], 10 * TILE_WIDTH call .OAM ld bc, wReel3 @@ -717,7 +717,7 @@ Slots_InitReelTiles: ld [hl], d ld hl, REEL_X_COORD add hl, bc - ld [hl], 14 * 8 + ld [hl], 14 * TILE_WIDTH call .OAM ret @@ -785,7 +785,7 @@ Slots_UpdateReelPositionAndOAM: add hl, bc ld a, [hl] ld [wCurReelXCoord], a - ld a, 10 * 8 + ld a, 10 * TILE_WIDTH ld [wCurReelYCoord], a ld hl, REEL_POSITION add hl, bc @@ -2019,7 +2019,7 @@ Slots_AnimateGolem: jr c, .play_sound dec [hl] ld e, a - ld d, 14 * 8 + ld d, 14 * TILE_WIDTH farcall BattleAnim_Sine_e ld a, e ld hl, SPRITEANIMSTRUCT_YOFFSET @@ -2046,7 +2046,7 @@ Slots_AnimateGolem: ld a, [hl] inc [hl] inc [hl] - cp 9 * 8 + cp 9 * TILE_WIDTH jr nc, .restart and $3 ret nz @@ -2090,7 +2090,7 @@ Slots_AnimateChansey: add hl, bc ld a, [hl] inc [hl] - cp 13 * 8 + cp 13 * TILE_WIDTH jr z, .limit and $f ret nz diff --git a/engine/gfx/color.asm b/engine/gfx/color.asm index e5b027a18..2ae8b0335 100644 --- a/engine/gfx/color.asm +++ b/engine/gfx/color.asm @@ -882,7 +882,7 @@ InitCGBPals:: ldh [rVBK], a ld a, 1 << rBGPI_AUTO_INCREMENT ldh [rBGPI], a - ld c, 4 * 8 + ld c, 4 * TILE_WIDTH .bgpals_loop ld a, LOW(PALRGB_WHITE) ldh [rBGPD], a @@ -892,7 +892,7 @@ InitCGBPals:: jr nz, .bgpals_loop ld a, 1 << rOBPI_AUTO_INCREMENT ldh [rOBPI], a - ld c, 4 * 8 + ld c, 4 * TILE_WIDTH .obpals_loop ld a, LOW(PALRGB_WHITE) ldh [rOBPD], a diff --git a/engine/gfx/mon_icons.asm b/engine/gfx/mon_icons.asm index 412d4833b..db8519e66 100644 --- a/engine/gfx/mon_icons.asm +++ b/engine/gfx/mon_icons.asm @@ -88,11 +88,11 @@ Mobile_InitAnimatedMonIcon: ld [hl], a ld hl, SPRITEANIMSTRUCT_XCOORD add hl, bc - ld a, 9 * 8 + ld a, 9 * TILE_WIDTH ld [hl], a ld hl, SPRITEANIMSTRUCT_YCOORD add hl, bc - ld a, 9 * 8 + ld a, 9 * TILE_WIDTH ld [hl], a ret @@ -105,11 +105,11 @@ Mobile_InitPartyMenuBGPal71: ld [hl], a ld hl, SPRITEANIMSTRUCT_XCOORD add hl, bc - ld a, 3 * 8 + ld a, 3 * TILE_WIDTH ld [hl], a ld hl, SPRITEANIMSTRUCT_YCOORD add hl, bc - ld a, 12 * 8 + ld a, 12 * TILE_WIDTH ld [hl], a ld a, c ld [wc608], a @@ -234,8 +234,8 @@ MoveList_InitAnimatedMonIcon: ld [wCurIcon], a xor a call GetIconGFX - ld d, 3 * 8 + 2 ; depixel 3, 4, 2, 4 - ld e, 4 * 8 + 4 + ld d, 3 * TILE_WIDTH + 2 ; depixel 3, 4, 2, 4 + ld e, 4 * TILE_WIDTH + 4 ld a, SPRITE_ANIM_INDEX_PARTY_MON call _InitSpriteAnimStruct ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID diff --git a/engine/gfx/sprite_anims.asm b/engine/gfx/sprite_anims.asm index d74db175d..b9978e35d 100644 --- a/engine/gfx/sprite_anims.asm +++ b/engine/gfx/sprite_anims.asm @@ -380,7 +380,7 @@ AnimSeq_SlotsChanseyEgg: ld hl, SPRITEANIMSTRUCT_XCOORD add hl, bc ld a, [hl] - cp 15 * 8 + cp 15 * TILE_WIDTH jr c, .move_right call DeinitializeSprite ld a, $4 @@ -682,7 +682,7 @@ AnimSeq_FlyLeaf: ld hl, SPRITEANIMSTRUCT_XCOORD add hl, bc ld a, [hl] - cp -9 * 8 + cp -9 * TILE_WIDTH jr nc, .delete_leaf inc [hl] inc [hl] @@ -711,7 +711,7 @@ AnimSeq_FlyTo: ld hl, SPRITEANIMSTRUCT_YCOORD add hl, bc ld a, [hl] - cp 10 * 8 + 4 + cp 10 * TILE_WIDTH + 4 ret z ld hl, SPRITEANIMSTRUCT_YCOORD diff --git a/engine/menus/intro_menu.asm b/engine/menus/intro_menu.asm index 8689335e2..ae0dd259f 100644 --- a/engine/menus/intro_menu.asm +++ b/engine/menus/intro_menu.asm @@ -955,10 +955,10 @@ Intro_PlacePlayerSprite: .sprites db 4 ; y pxl, x pxl, tile offset - db 9 * 8 + 4, 9 * 8, 0 - db 9 * 8 + 4, 10 * 8, 1 - db 10 * 8 + 4, 9 * 8, 2 - db 10 * 8 + 4, 10 * 8, 3 + db 9 * TILE_WIDTH + 4, 9 * TILE_WIDTH, 0 + db 9 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 1 + db 10 * TILE_WIDTH + 4, 9 * TILE_WIDTH, 2 + db 10 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 3 const_def diff --git a/engine/menus/naming_screen.asm b/engine/menus/naming_screen.asm index eb075ae03..6db429157 100644 --- a/engine/menus/naming_screen.asm +++ b/engine/menus/naming_screen.asm @@ -375,7 +375,7 @@ NamingScreenJoypadLoop: depixel 10, 3 call NamingScreen_IsTargetBox jr nz, .got_cursor_position - ld d, 8 * 8 + ld d, 8 * TILE_WIDTH .got_cursor_position ld a, SPRITE_ANIM_INDEX_NAMING_SCREEN_CURSOR call InitSpriteAnimStruct diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 990d7f838..44e547db7 100644 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -880,12 +880,12 @@ MovementFunction_Shadow: add hl, de ld a, [hl] maskbits NUM_DIRECTIONS - ld d, 1 * 8 + 6 + ld d, 1 * TILE_WIDTH + 6 cp DOWN jr z, .ok cp UP jr z, .ok - ld d, 1 * 8 + 4 + ld d, 1 * TILE_WIDTH + 4 .ok ld hl, OBJECT_SPRITE_Y_OFFSET add hl, bc @@ -909,7 +909,7 @@ MovementFunction_Emote: ld [hl], 0 ld hl, OBJECT_SPRITE_Y_OFFSET add hl, bc - ld [hl], -2 * 8 + ld [hl], -2 * TILE_WIDTH ld hl, OBJECT_SPRITE_X_OFFSET add hl, bc ld [hl], 0 diff --git a/engine/pokegear/pokegear.asm b/engine/pokegear/pokegear.asm index 32e6a0503..8f094388e 100644 --- a/engine/pokegear/pokegear.asm +++ b/engine/pokegear/pokegear.asm @@ -2555,10 +2555,10 @@ Pokedex_GetArea: .PlayerOAM: ; y pxl, x pxl, tile offset - db -1 * 8, -1 * 8, 0 ; top left - db -1 * 8, 0 * 8, 1 ; top right - db 0 * 8, -1 * 8, 2 ; bottom left - db 0 * 8, 0 * 8, 3 ; bottom right + db -1 * TILE_WIDTH, -1 * TILE_WIDTH, 0 ; top left + db -1 * TILE_WIDTH, 0 * TILE_WIDTH, 1 ; top right + db 0 * TILE_WIDTH, -1 * TILE_WIDTH, 2 ; bottom left + db 0 * TILE_WIDTH, 0 * TILE_WIDTH, 3 ; bottom right db $80 ; terminator .CheckPlayerLocation: diff --git a/engine/pokemon/breeding.asm b/engine/pokemon/breeding.asm index 747cf4de1..f8b70d4a6 100644 --- a/engine/pokemon/breeding.asm +++ b/engine/pokemon/breeding.asm @@ -779,9 +779,9 @@ EggHatch_CrackShell: ret nc swap a srl a - add 9 * 8 + 4 + add 9 * TILE_WIDTH + 4 ld d, a - ld e, 11 * 8 + ld e, 11 * TILE_WIDTH ld a, SPRITE_ANIM_INDEX_EGG_CRACK call InitSpriteAnimStruct ld hl, SPRITEANIMSTRUCT_TILE_ID @@ -838,7 +838,7 @@ Hatch_InitShellFragments: MACRO shell_fragment ; y tile, y pxl, x tile, x pxl, frameset offset, ??? - db (\1 * 8) % $100 + \2, (\3 * 8) % $100 + \4, \5 - SPRITE_ANIM_FRAMESET_EGG_HATCH_1, \6 + db (\1 * TILE_WIDTH) % $100 + \2, (\3 * TILE_WIDTH) % $100 + \4, \5 - SPRITE_ANIM_FRAMESET_EGG_HATCH_1, \6 ENDM .SpriteData: diff --git a/engine/pokemon/health.asm b/engine/pokemon/health.asm index d11a073b5..6bd11e3d2 100644 --- a/engine/pokemon/health.asm +++ b/engine/pokemon/health.asm @@ -53,7 +53,7 @@ HealPartyMon: ret ComputeHPBarPixels: -; e = bc * (6 * 8) / de +; e = bc * HP_BAR_LENGTH_PX / de ld a, b or c jr z, .zero @@ -64,7 +64,7 @@ ComputeHPBarPixels: ldh [hMultiplicand + 1], a ld a, c ldh [hMultiplicand + 2], a - ld a, 6 * 8 + ld a, HP_BAR_LENGTH_PX ldh [hMultiplier], a call Multiply ; We need de to be under 256 because hDivisor is only 1 byte. diff --git a/macros/scripts/battle_anims.asm b/macros/scripts/battle_anims.asm index d944b5ec3..9410f015e 100644 --- a/macros/scripts/battle_anims.asm +++ b/macros/scripts/battle_anims.asm @@ -18,8 +18,8 @@ MACRO anim_obj else ; LEGACY: Support the tile+offset format db \1 ; object - db (\2) * 8 + (\3) ; x_tile, x - db (\4) * 8 + (\5) ; y_tile, y + db (\2) * TILE_WIDTH + (\3) ; x_tile, x + db (\4) * TILE_WIDTH + (\5) ; y_tile, y db \6 ; param endc ENDM diff --git a/mobile/fixed_words.asm b/mobile/fixed_words.asm index a736dfaf2..0b990f7d4 100644 --- a/mobile/fixed_words.asm +++ b/mobile/fixed_words.asm @@ -2623,12 +2623,12 @@ AnimateEZChatCursor: ret .nine - ld d, -13 * 8 + ld d, -13 * TILE_WIDTH ld a, SPRITE_ANIM_FRAMESET_EZCHAT_CURSOR_7 jr .eight_nine_load .eight - ld d, 2 * 8 + ld d, 2 * TILE_WIDTH ld a, SPRITE_ANIM_FRAMESET_EZCHAT_CURSOR_6 .eight_nine_load push de @@ -2640,7 +2640,7 @@ AnimateEZChatCursor: ld e, a sla a add e - add 8 * 8 + add 8 * TILE_WIDTH ld hl, SPRITEANIMSTRUCT_YCOORD add hl, bc ld [hld], a diff --git a/mobile/mobile_42.asm b/mobile/mobile_42.asm index 87b85814a..18f6280ff 100644 --- a/mobile/mobile_42.asm +++ b/mobile/mobile_42.asm @@ -1516,9 +1516,9 @@ MobileTradeAnim_AnimateSentPulse: ld hl, SPRITEANIMSTRUCT_YCOORD add hl, bc ld a, [hl] - cp -1 * 8 - 6 + cp -1 * TILE_WIDTH - 6 jr z, .delete - sub 1 * 8 + sub 1 * TILE_WIDTH ld [hl], a ret @@ -1530,9 +1530,9 @@ MobileTradeAnim_AnimateOTPulse: ld hl, SPRITEANIMSTRUCT_YCOORD add hl, bc ld a, [hl] - cp 9 * 8 + 2 + cp 9 * TILE_WIDTH + 2 ret z - add 1 * 8 + add 1 * TILE_WIDTH ld [hl], a ret diff --git a/mobile/mobile_46.asm b/mobile/mobile_46.asm index 40a4183bb..7f4263d95 100644 --- a/mobile/mobile_46.asm +++ b/mobile/mobile_46.asm @@ -6758,10 +6758,10 @@ Function11b3d9: jr .loop1 .skip - ld b, 14 * 8 + ld b, 14 * TILE_WIDTH .load_sprites - ld a, 2 * 8 + 5 + ld a, 2 * TILE_WIDTH + 5 add b pop hl ld [hli], a @@ -6778,7 +6778,7 @@ Function11b3d9: jr z, .version2 .version1 - ld a, 19 * 8 + 3 + ld a, 19 * TILE_WIDTH + 3 ld [hli], a ld a, [wcd4c] add $3c @@ -6789,7 +6789,7 @@ Function11b3d9: ret .version2 - ld a, 19 * 8 + 3 + ld a, 19 * TILE_WIDTH + 3 ld [hli], a ld a, $39 ld [hli], a