From 9d723ee37cb20db9886c05fcc3fd31568e283eea Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 26 Feb 2025 15:09:10 +0100 Subject: [PATCH] Make pos->pixelPos conversion more readable --- include/structs/str_position.h | 3 +++ src/code_8041AD0.c | 4 ++-- src/code_8073CF0.c | 8 ++++---- src/code_807CD9C.c | 4 ++-- src/code_807E5AC.c | 4 ++-- src/dungeon_cutscenes.c | 18 ++++++------------ src/dungeon_move.c | 18 ++++++------------ src/dungeon_util.c | 9 ++++----- src/dungeon_util_1.c | 2 +- src/move_actions.c | 11 ++--------- 10 files changed, 32 insertions(+), 49 deletions(-) diff --git a/include/structs/str_position.h b/include/structs/str_position.h index e56ee1d18..42b312f96 100644 --- a/include/structs/str_position.h +++ b/include/structs/str_position.h @@ -19,6 +19,9 @@ typedef struct PixelPos /* 0x4 */ s32 y; } PixelPos; +#define X_POS_TO_PIXELPOS(x)((((x) * 24) + 12) << 8) +#define Y_POS_TO_PIXELPOS(y)((((y) * 24) + 16) << 8) + /** * Currently only used in script data, for entities and GroundLink data. * DungeonPos expressed in terms of *graphics* tiles, 8 pixels per unit. diff --git a/src/code_8041AD0.c b/src/code_8041AD0.c index 53be37e00..6e87e719c 100644 --- a/src/code_8041AD0.c +++ b/src/code_8041AD0.c @@ -58,8 +58,8 @@ s32 sub_80416A4(DungeonPos *pos_1, u32 param_2, bool8 param_3) { PixelPos pos; - pos.x = pos_1->x * 0x1800 + 0xc00; - pos.y = pos_1->y * 0x1800 + 0x1000; + pos.x = X_POS_TO_PIXELPOS(pos_1->x); + pos.y = Y_POS_TO_PIXELPOS(pos_1->y); return sub_80416E0(&pos, param_2, param_3); } diff --git a/src/code_8073CF0.c b/src/code_8073CF0.c index f2ad85430..6a06e5be5 100644 --- a/src/code_8073CF0.c +++ b/src/code_8073CF0.c @@ -892,8 +892,8 @@ bool8 UseAttack(Entity *a0) PixelPos pos; monInfo->flags |= 0x2000; - pos.x = (monInfo->unk184[0].previousTargetMovePosition2.x * 0x1800) + 0xC00; - pos.y = (monInfo->unk184[0].previousTargetMovePosition2.y * 0x1800) + 0x1000; + pos.x = X_POS_TO_PIXELPOS(monInfo->unk184[0].previousTargetMovePosition2.x); + pos.y = Y_POS_TO_PIXELPOS(monInfo->unk184[0].previousTargetMovePosition2.y); sub_804535C(mon, &pos); sub_806CDFC(mon, 0, monInfo->unk184[0].lastMoveDirection); monInfo->notMoving = 0; @@ -929,8 +929,8 @@ bool8 UseAttack(Entity *a0) else { PixelPos pos; - pos.x = (monInfo->unk184[monInfo->notMoving].previousTargetMovePosition2.x * 0x1800) + 0xC00; - pos.y = (monInfo->unk184[monInfo->notMoving].previousTargetMovePosition2.y * 0x1800) + 0x1000; + pos.x = X_POS_TO_PIXELPOS(monInfo->unk184[monInfo->notMoving].previousTargetMovePosition2.x); + pos.y = Y_POS_TO_PIXELPOS(monInfo->unk184[monInfo->notMoving].previousTargetMovePosition2.y); sub_804535C(mon, &pos); sub_806CDFC(mon, 0, monInfo->unk184[monInfo->notMoving].lastMoveDirection); } diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 8f4874380..1edaa4117 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -202,8 +202,8 @@ void sub_807D068(Entity *pokemon, DungeonPos *pos) int incrementX; int incrementY; - posX = pos->x * 0x1800 + 0xc00; - posY = pos->y * 0x1800 + 0x1000; + posX = X_POS_TO_PIXELPOS(pos->x); + posY = Y_POS_TO_PIXELPOS(pos->y); diff = (pokemon->pixelPos).x - posX; if (diff < 0) { diff = -diff; diff --git a/src/code_807E5AC.c b/src/code_807E5AC.c index be276ce13..d3fd624f9 100644 --- a/src/code_807E5AC.c +++ b/src/code_807E5AC.c @@ -742,8 +742,8 @@ void sub_807F43C(Entity *target, Entity *attacker) newDir = GetDirectionTowardsPosition(&attackerPos, &attacker->pos); - pixelPosX = (((attackerPos.x * 24) + 12) << 8) + ((gAdjacentTileOffsets[newDir].x << 8) / 3); - pixelPosY = (((attackerPos.y * 24) + 16) << 8) + ((gAdjacentTileOffsets[newDir].y << 8) / 3); + pixelPosX = X_POS_TO_PIXELPOS(attackerPos.x) + ((gAdjacentTileOffsets[newDir].x << 8) / 3); + pixelPosY = Y_POS_TO_PIXELPOS(attackerPos.y) + ((gAdjacentTileOffsets[newDir].y << 8) / 3); var_30 = (pixelPosX - attacker->pixelPos.x) / r6; r10 = (pixelPosY - attacker->pixelPos.y) / r6; diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index 0760645f4..010fe490c 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -1270,12 +1270,10 @@ void MoltresScreenFlash1(s32 xArg, s32 yArg) s32 x, y; DungeonPos newPos; - x = (xArg * 3) << 11; - x += 0xC00; + x = X_POS_TO_PIXELPOS(xArg); newPos.x = x / 256; - y = (yArg * 3) << 11; - y += 0x1000; + y = Y_POS_TO_PIXELPOS(yArg); newPos.y = y / 256; sub_8085EC8(370,16,0,&newPos,0); @@ -1287,12 +1285,10 @@ void MoltresScreenFlash2(s32 xArg, s32 yArg) s32 i, x, y; DungeonPos newPos; - x = (xArg * 3) << 11; - x += 0xC00; + x = X_POS_TO_PIXELPOS(xArg); newPos.x = x / 256; - y = (yArg * 3) << 11; - y += 0x1000; + y = Y_POS_TO_PIXELPOS(yArg); newPos.y = y / 256; r6 = sub_8085EC8(370,22,0,&newPos,0); @@ -4102,12 +4098,10 @@ void sub_808BB3C(DungeonPos *pos1) s32 x, y; DungeonPos newPos; - x = (pos1->x * 3) << 11; - x += 0xC00; + x = X_POS_TO_PIXELPOS(pos1->x); newPos.x = x / 256; - y = (pos1->y * 3) << 11; - y += 0x1000; + y = Y_POS_TO_PIXELPOS(pos1->y); newPos.y = y / 256; sub_8085EC8(100,0,0,&newPos,0); diff --git a/src/dungeon_move.c b/src/dungeon_move.c index b87d60d73..95881ee7a 100644 --- a/src/dungeon_move.c +++ b/src/dungeon_move.c @@ -2274,17 +2274,11 @@ s32 sub_8056564(Entity *entity, DungeonPos *pos, Move *move, s32 r4) if (!gDungeon->unk181e8.blinded && (GetBodySize(entInfo->apparentID) < 4 || r4 != 1)) { s32 unk6 = sub_800ECB8(sub_80412E0(move->id, GetApparentWeather(entity), 1))->unk6; - s32 x = (pos->x * 3 << 11); - s32 y = (pos->y * 3 << 11); - // This is needed for matching purposes. - s32 y2; + s32 pixelPosX = X_POS_TO_PIXELPOS(pos->x); + s32 pixelPosY = Y_POS_TO_PIXELPOS(pos->y); - x += 0xC00; - y += 0x1000; - y2 = y; - - unkSp2.x = x / 256; - unkSp2.y = y2 / 256; + unkSp2.x = pixelPosX / 256; + unkSp2.y = pixelPosY / 256; if (unk6 != 0) { s32 someRetVal; @@ -2422,8 +2416,8 @@ void sub_80566F8(Entity *attacker, Move *move, s32 a2, bool8 a3, s32 itemId, s32 var_68.y += var_48; if (sub_803F428(&var_68) && !gDungeon->unk181e8.blinded) { PixelPos pos32; - pos32.x = (var_68Before.x * 0x1800) + 0xC00; - pos32.y = (var_68Before.y * 0x1800) + 0x1000; + pos32.x = X_POS_TO_PIXELPOS(var_68Before.x); + pos32.y = Y_POS_TO_PIXELPOS(var_68Before.y); var_28 = var_30 * (var_4C << 8); var_24 = var_30 * (var_48 << 8); for (j = 0; j < 24 / var_30; j++) { diff --git a/src/dungeon_util.c b/src/dungeon_util.c index e7b32e641..fc06a04a2 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -179,14 +179,13 @@ void sub_804522C(void) { void sub_804535C(Entity *entity, PixelPos *pos) { - if (pos != NULL) { - (entity->pixelPos).x = pos->x; - (entity->pixelPos).y = pos->y; + entity->pixelPos.x = pos->x; + entity->pixelPos.y = pos->y; } else { - (entity->pixelPos).x = (entity->pos).x * 0x1800 + 0xc00; - (entity->pixelPos).y = (entity->pos).y * 0x1800 + 0x1000; + entity->pixelPos.x = X_POS_TO_PIXELPOS(entity->pos.x); + entity->pixelPos.y = Y_POS_TO_PIXELPOS(entity->pos.y); } } diff --git a/src/dungeon_util_1.c b/src/dungeon_util_1.c index d4873ae97..fa1d66152 100644 --- a/src/dungeon_util_1.c +++ b/src/dungeon_util_1.c @@ -239,7 +239,7 @@ void sub_80857B8(void) void sub_8085860(s32 x, s32 y) { sub_803F4A0(0); - sub_803F878(x * 0x1800 + 0xc00, y * 0x1800 + 0x1000); + sub_803F878(X_POS_TO_PIXELPOS(x), Y_POS_TO_PIXELPOS(y)); } void sub_8085890(s32 x, s32 y) diff --git a/src/move_actions.c b/src/move_actions.c index 17e6816ce..a50f494ed 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -2585,8 +2585,6 @@ bool8 SplashMoveAction(Entity * pokemon, Entity * target, Move *move, u32 param_ PixelPos pos2; Tile *tile; Entity *entity; - s32 temp; - s32 temp2; u8 check; @@ -2610,14 +2608,9 @@ _0805A8C2: TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FEBDC); return FALSE; } - temp = pos1.x * 0x1800; - temp += (0xC00); - pos2.x = (temp - target->pixelPos.x) / 0xc; - - temp2 = pos1.y * 0x1800; - temp2 += (0x80 << 5); - pos2.y = ((temp2 - target->pixelPos.y) / 0xc); + pos2.x = (X_POS_TO_PIXELPOS(pos1.x) - target->pixelPos.x) / 0xc; + pos2.y = (Y_POS_TO_PIXELPOS(pos1.y) - target->pixelPos.y) / 0xc; if (((check = sub_803F428(&target->pos), r9 = &target->pos, check)) || (sub_803F428(&pos1))) { for(counter = 0; counter < 0xC; counter++)