From 8710494e40c766dc321e7f6dd08e15e451d11c6f Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Tue, 5 Nov 2024 16:47:52 +0100 Subject: [PATCH 01/12] Fix asmdiff without devkitARM --- asmdiff.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/asmdiff.sh b/asmdiff.sh index 886d54f3f..f9c776291 100755 --- a/asmdiff.sh +++ b/asmdiff.sh @@ -1,6 +1,10 @@ #!/bin/bash -OBJDUMP_BIN="arm-none-eabi-objdump" +if [[ -n "$DEVKITARM" ]]; then + OBJDUMP_BIN="$DEVKITARM/bin/arm-none-eabi-objdump" +else + OBJDUMP_BIN="arm-none-eabi-objdump" +fi OBJDUMP="$OBJDUMP_BIN -D -bbinary -marmv4t -Mforce-thumb" From 56d2e0db9a0c7888b9d2d1297873d9ed5d481320 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Thu, 7 Nov 2024 11:14:54 +0100 Subject: [PATCH 02/12] Gitignore symbol dumps --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6af167552..9f69537f7 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ build/ *.ss[0-9] *.pyc __pycache__/ +*.syms From 2e61c49bdf53c2d8838b1d9400f2955598d42e08 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Thu, 7 Nov 2024 11:16:47 +0100 Subject: [PATCH 03/12] Rename 8-byte fixpoint --- include/math.h | 18 +-- include/number_util.h | 12 +- src/code_806E8B0.c | 48 +++---- src/code_8073CF0.c | 10 +- src/math.c | 284 +++++++++++++++++++-------------------- src/number_util.c | 6 +- src/type_effectiveness.c | 24 ++-- tmp/fixpoint.cocci | 17 +++ 8 files changed, 218 insertions(+), 201 deletions(-) create mode 100644 tmp/fixpoint.cocci diff --git a/include/math.h b/include/math.h index 243e67539..d2fe2bd1e 100644 --- a/include/math.h +++ b/include/math.h @@ -50,16 +50,16 @@ s32 sin_4096(s32 x); */ s24_8 s24_8_mul(s24_8 x, s24_8 y); -bool8 F48_16_IsZero(unkStruct_80943A8 *a); -void F48_16_SDiv(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b); -void F48_16_SMul(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b); +bool8 F48_16_IsZero(s48_16 *a); +void F48_16_SDiv(s48_16 *dst, s48_16 *a, s48_16 *b); +void F48_16_SMul(s48_16 *dst, s48_16 *a, s48_16 *b); s32 sub_8009FB8(s32 x, s32 y); -void sub_800A020(unkStruct_80943A8 *dst, u32); -u32 sub_800A048(unkStruct_80943A8 *a); -void sub_800A088(unkStruct_80943A8 *a, s32 b); -bool8 sub_800A2F0(unkStruct_80943A8 *a, unkStruct_80943A8 *b); -void sub_800A6D0(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b); -void sub_800A6F0(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b); +void sub_800A020(s48_16 *dst, u32); +u32 sub_800A048(s48_16 *a); +void sub_800A088(s48_16 *a, s32 b); +bool8 sub_800A2F0(s48_16 *a, s48_16 *b); +void sub_800A6D0(s48_16 *dst, s48_16 *a, s48_16 *b); +void sub_800A6F0(s48_16 *dst, s48_16 *a, s48_16 *b); #endif // GUARD_MATH_H diff --git a/include/number_util.h b/include/number_util.h index 468aae34b..b835a5fcb 100644 --- a/include/number_util.h +++ b/include/number_util.h @@ -7,11 +7,11 @@ typedef struct FixedPoint s16 unk2; } FixedPoint; -typedef struct unkStruct_80943A8 +typedef struct s48_16 { - s32 s0; - u32 s4; // some math.c funcs require this to be a u32, but other funcs check if it's negative (aka >= INT32_MAX) -} unkStruct_80943A8; + s32 hi; + u32 lo; // some math.c funcs require this to be a u32, but other funcs check if it's negative (aka >= INT32_MAX) +} s48_16; FixedPoint FixedPoint_Add(FixedPoint a, FixedPoint b); FixedPoint FixedPoint_Subtract(FixedPoint a, FixedPoint b); @@ -19,8 +19,8 @@ FixedPoint FixedPoint_Min(FixedPoint a, FixedPoint b); FixedPoint FixedPoint_Max(FixedPoint a, FixedPoint b); FixedPoint sub_8094370(FixedPoint param_1, FixedPoint param_2); FixedPoint IntToFixedPoint(s32 a); -FixedPoint FixedPoint_SetFromUnk(unkStruct_80943A8* param_1); +FixedPoint FixedPoint_SetFromUnk(s48_16* param_1); FixedPoint FixedPoint_Div(FixedPoint a, FixedPoint b); s32 FixedPointToInt(FixedPoint a); // Always rounded up -#endif \ No newline at end of file +#endif diff --git a/src/code_806E8B0.c b/src/code_806E8B0.c index 7d0a8051c..a747c92fa 100644 --- a/src/code_806E8B0.c +++ b/src/code_806E8B0.c @@ -28,7 +28,7 @@ void sub_80428B0(Entity *r0); void sub_80428C4(Entity *r0); extern void sub_806F500(void); -extern bool8 sub_806E100(struct unkStruct_80943A8 *param_1, Entity *pokemon, Entity *target, u8 type, struct DamageStruct *dmgStruct); +extern bool8 sub_806E100(s48_16 *param_1, Entity *pokemon, Entity *target, u8 type, struct DamageStruct *dmgStruct); extern void sub_8041B74(Entity *pokemon); extern void sub_8041B5C(Entity *pokemon); extern void HandleDealingDamage(Entity *attacker, Entity *target, struct DamageStruct *dmgStruct, bool32 isFalseSwipe, bool32 giveExp, s16 arg4, bool32 arg8, s32 argC); @@ -44,10 +44,10 @@ extern const s16 gUnknown_810AC68; extern const s16 gUnknown_810AC62; extern const s16 gUnknown_80F4DAE; extern const s16 gUnknown_80F4DB0; -extern struct unkStruct_80943A8 gUnknown_8106F24; -extern struct unkStruct_80943A8 gUnknown_8106F04; -extern struct unkStruct_80943A8 gUnknown_8106F1C; -extern struct unkStruct_80943A8 gUnknown_8106F14; +extern s48_16 gUnknown_8106F24; +extern s48_16 gUnknown_8106F04; +extern s48_16 gUnknown_8106F1C; +extern s48_16 gUnknown_8106F14; extern const u8 *const gUnknown_80FAE00; extern const u8 *const gUnknown_80FADD8; extern const u8 *const gUnknown_80FEE04; @@ -173,17 +173,17 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 s32 atkStat, defStat; s32 rand; s32 r6; - struct unkStruct_80943A8 unkSp1; - struct unkStruct_80943A8 unkSp2; - struct unkStruct_80943A8 unkSp3; - struct unkStruct_80943A8 unkSp4; - struct unkStruct_80943A8 unkSp5; - struct unkStruct_80943A8 unkSp6; - struct unkStruct_80943A8 unkSp7; - struct unkStruct_80943A8 unkSp8; - struct unkStruct_80943A8 unkSp9; - struct unkStruct_80943A8 unkSp10; - struct unkStruct_80943A8 unkSp11; + s48_16 unkSp1; + s48_16 unkSp2; + s48_16 unkSp3; + s48_16 unkSp4; + s48_16 unkSp5; + s48_16 unkSp6; + s48_16 unkSp7; + s48_16 unkSp8; + s48_16 unkSp9; + s48_16 unkSp10; + s48_16 unkSp11; bool8 r5; dmgStruct->type = moveType; @@ -281,8 +281,8 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 F48_16_SDiv(&unkSp1, &unkSp1, &unkSp2); if (!attackerInfo->isNotTeamMember) { sub_800A020(&unkSp2, attackerInfo->level); - unkSp3.s0 = 0; - unkSp3.s4 = 0xAAAA; + unkSp3.hi = 0; + unkSp3.lo = 0xAAAA; F48_16_SMul(&unkSp2, &unkSp2, &unkSp3); r6 = (attackerInfo->level * 2) / 3; } @@ -301,8 +301,8 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 unkSp5 = unkSp4; unkSp7 = unkSp4; F48_16_SMul(&unkSp5, &unkSp5, &unkSp5); - unkSp6.s0 = 0; - unkSp6.s4 = 0xCCC; + unkSp6.hi = 0; + unkSp6.lo = 0xCCC; F48_16_SMul(&unkSp5, &unkSp5, &unkSp6); sub_800A020(&unkSp6, 2); F48_16_SMul(&unkSp7, &unkSp7, &unkSp6); @@ -401,8 +401,8 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 gDungeon->unk134.unk150 = sub_800A048(&unkSp8); { s32 rnd = DungeonRandInt(0x4000); - unkSp9.s0 = 0; - unkSp9.s4 = 0xE000 + rnd; + unkSp9.hi = 0; + unkSp9.lo = 0xE000 + rnd; } F48_16_SMul(&unkSp8, &unkSp8, &unkSp9); sub_800A020(&unkSp11, 100); @@ -420,8 +420,8 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 void sub_806F2BC(Entity *attacker, Entity *target, u8 moveType, s32 a2, struct DamageStruct *dmgStruct) { - struct unkStruct_80943A8 unkSp1; - struct unkStruct_80943A8 unkSp2; + s48_16 unkSp1; + s48_16 unkSp2; s32 a2New = a2; if (a2New <= 0) a2New = 1; diff --git a/src/code_8073CF0.c b/src/code_8073CF0.c index c78e7b6f3..5509a78b4 100644 --- a/src/code_8073CF0.c +++ b/src/code_8073CF0.c @@ -105,7 +105,7 @@ extern const s16 gUnknown_80F4F74; extern const s16 gUnknown_80F4FC2; extern const s16 gUnknown_80F4F76; extern const s16 gUnknown_80F4F36; -extern unkStruct_80943A8 gUnknown_80F54F4[8]; +extern s48_16 gUnknown_80F54F4[8]; extern const s32 gUnknown_80F60DC[]; extern const Position gUnknown_80F4D44[]; @@ -309,7 +309,7 @@ void sub_8074094(Entity *entity) } if (entityInfo->isTeamLeader) { - unkStruct_80943A8 sp8, sp10; + s48_16 sp8, sp10; FixedPoint var_38; FixedPoint bellyBefore; bool8 sound; @@ -334,11 +334,11 @@ void sub_8074094(Entity *entity) if (r4 > 19) r4 = 19; - sp8.s0 = 0; - sp8.s4 = 6554; + sp8.hi = 0; + sp8.lo = 6554; F48_16_SMul(&sp10, &sp8, &gUnknown_80F54F4[r4]); if (entityInfo->unk153 > 1) - sp10.s4 += (gUnknown_80F60DC[entityInfo->unk153] << 0x10); + sp10.lo += (gUnknown_80F60DC[entityInfo->unk153] << 0x10); entityInfo->unk153 = 0; bellyBefore = entityInfo->belly; diff --git a/src/math.c b/src/math.c index 972407be5..64a7e2b3d 100644 --- a/src/math.c +++ b/src/math.c @@ -4,8 +4,8 @@ #include "data/math.h" -static void F48_16_UDiv(unkStruct_80943A8 *, unkStruct_80943A8 *, unkStruct_80943A8 *); -static void F48_16_UMul(unkStruct_80943A8 *, unkStruct_80943A8 *, unkStruct_80943A8 *); +static void F48_16_UDiv(s48_16 *, s48_16 *, s48_16 *); +static void F48_16_UMul(s48_16 *, s48_16 *, s48_16 *); static u24_8 u24_8_div(u24_8, u24_8); static u24_8 u24_8_mul(u24_8, u24_8); @@ -348,7 +348,7 @@ s32 sub_8009FB8(s32 x, s32 y) return r5; } -void sub_800A020(unkStruct_80943A8 *param_1, u32 param_2) +void sub_800A020(s48_16 *param_1, u32 param_2) { #ifndef NONMATCHING register u32 temp asm("r4"); @@ -357,20 +357,20 @@ void sub_800A020(unkStruct_80943A8 *param_1, u32 param_2) #endif temp = 0xFFFF0000; - param_1->s0 = param_2 >> 16; - param_1->s4 = param_2 << 16; + param_1->hi = param_2 >> 16; + param_1->lo = param_2 << 16; if (param_2 & 0x8000) - param_1->s0 |= temp; + param_1->hi |= temp; } -u32 sub_800A048(unkStruct_80943A8 *a) +u32 sub_800A048(s48_16 *a) { u32 uVar1; - uVar1 = ((u16)a->s0 << 16) | (a->s4 >> 16); - if (a->s4 & 0x8000) + uVar1 = ((u16) a->hi << 16) | (a->lo >> 16); + if (a->lo & 0x8000) uVar1++; return uVar1; @@ -387,26 +387,26 @@ UNUSED u32 sub_800A068(u32 *a) return uVar1; } -void sub_800A088(unkStruct_80943A8 *a, s32 b) +void sub_800A088(s48_16 *a, s32 b) { - a->s4 = b << 8; - a->s0 = b >> 24; + a->lo = b << 8; + a->hi = b >> 24; - if (a->s0 & 0x80) - a->s0 |= ~0x7F; + if (a->hi & 0x80) + a->hi |= ~0x7F; else - a->s0 &= 0x7f; + a->hi &= 0x7f; } -s32 sub_800A0B0(unkStruct_80943A8 *a) +s32 sub_800A0B0(s48_16 *a) { s32 r2; s32 r3; s32 idx; s32 divi; - r2 = a->s4; - r3 = a->s0; + r2 = a->lo; + r3 = a->hi; if (r2 == 0 && r3 == 0) return 0; @@ -515,95 +515,95 @@ s32 sub_800A0B0(unkStruct_80943A8 *a) } } -static void F48_16_Negate(unkStruct_80943A8 *a) +static void F48_16_Negate(s48_16 *a) { - a->s0 = ~a->s0; - a->s4 = ~a->s4 + 1; + a->hi = ~a->hi; + a->lo = ~a->lo + 1; - if (a->s4 == 0) - a->s0++; + if (a->lo == 0) + a->hi++; } -static void F48_16_Abs(unkStruct_80943A8 *a) +static void F48_16_Abs(s48_16 *a) { - if (a->s0 < 0) { - a->s0 = ~a->s0; - a->s4 = ~a->s4 + 1; + if (a->hi < 0) { + a->hi = ~a->hi; + a->lo = ~a->lo + 1; - if (a->s4 == 0) - a->s0++; + if (a->lo == 0) + a->hi++; } } -bool8 F48_16_IsZero(unkStruct_80943A8 *a) +bool8 F48_16_IsZero(s48_16 *a) { - if (a->s0 == 0 && a->s4 == 0) + if (a->hi == 0 && a->lo == 0) return TRUE; return FALSE; } -UNUSED bool8 F48_16_IsEqual(unkStruct_80943A8 *a, unkStruct_80943A8 *b) +UNUSED bool8 F48_16_IsEqual(s48_16 *a, s48_16 *b) { - if (a->s0 == b->s0 && a->s4 == b->s4) + if (a->hi == b->hi && a->lo == b->lo) return TRUE; return FALSE; } -static bool8 F48_16_IsNegative(unkStruct_80943A8 *a) +static bool8 F48_16_IsNegative(s48_16 *a) { - if (a->s0 < 0) + if (a->hi < 0) return TRUE; return FALSE; } -bool8 sub_800A2F0(unkStruct_80943A8 *a, unkStruct_80943A8 *b) +bool8 sub_800A2F0(s48_16 *a, s48_16 *b) { s32 r1; u32 a0; s32 b0; - a0 = a->s0; + a0 = a->hi; r1 = a0 >> 31; - b0 = b->s0; + b0 = b->hi; if (b0 < 0) r1 |= 0x2; switch (r1) { case 0: default: - return u32_pair_less_than(a0, a->s4, b0, b->s4); + return u32_pair_less_than(a0, a->lo, b0, b->lo); case 1: return TRUE; case 2: return FALSE; case 3: - return !u32_pair_less_than(a0, a->s4, b0, b->s4); + return !u32_pair_less_than(a0, a->lo, b0, b->lo); } } -void F48_16_SMul(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b) +void F48_16_SMul(s48_16 *dst, s48_16 *a, s48_16 *b) { bool8 aIsNegative; bool8 bIsNegative; - unkStruct_80943A8 aa; - unkStruct_80943A8 bb; - unkStruct_80943A8 res; + s48_16 aa; + s48_16 bb; + s48_16 res; - aa.s0 = a->s0; - aa.s4 = a->s4; - bb.s0 = b->s0; - bb.s4 = b->s4; + aa.hi = a->hi; + aa.lo = a->lo; + bb.hi = b->hi; + bb.lo = b->lo; aIsNegative = F48_16_IsNegative(&aa); bIsNegative = F48_16_IsNegative(&bb); if (F48_16_IsZero(&aa)) { - dst->s0 = 0; - dst->s4 = 0; + dst->hi = 0; + dst->lo = 0; } else if (F48_16_IsZero(&bb)) { - dst->s0 = 0; - dst->s4 = 0; + dst->hi = 0; + dst->lo = 0; } else { if (aIsNegative) @@ -616,33 +616,33 @@ void F48_16_SMul(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 if (aIsNegative != bIsNegative) F48_16_Negate(&res); - dst->s0 = res.s0; - dst->s4 = res.s4; + dst->hi = res.hi; + dst->lo = res.lo; } } -void F48_16_SDiv(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b) +void F48_16_SDiv(s48_16 *dst, s48_16 *a, s48_16 *b) { bool8 aIsNegative; bool8 bIsNegative; - unkStruct_80943A8 aa; - unkStruct_80943A8 bb; - unkStruct_80943A8 res; + s48_16 aa; + s48_16 bb; + s48_16 res; - aa.s0 = a->s0; - aa.s4 = a->s4; - bb.s0 = b->s0; - bb.s4 = b->s4; + aa.hi = a->hi; + aa.lo = a->lo; + bb.hi = b->hi; + bb.lo = b->lo; aIsNegative = F48_16_IsNegative(&aa); bIsNegative = F48_16_IsNegative(&bb); if (F48_16_IsZero(&bb)) { - dst->s0 = INT32_MAX; - dst->s4 = UINT32_MAX; + dst->hi = INT32_MAX; + dst->lo = UINT32_MAX; } else if (F48_16_IsZero(&aa)) { - dst->s0 = 0; - dst->s4 = 0; + dst->hi = 0; + dst->lo = 0; } else { if (aIsNegative) @@ -655,33 +655,33 @@ void F48_16_SDiv(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 if (aIsNegative != bIsNegative) F48_16_Negate(&res); - dst->s0 = res.s0; - dst->s4 = res.s4; + dst->hi = res.hi; + dst->lo = res.lo; } } -static void F48_16_Square(unkStruct_80943A8 *a) +static void F48_16_Square(s48_16 *a) { - unkStruct_80943A8 aa; - unkStruct_80943A8 res; + s48_16 aa; + s48_16 res; - aa.s0 = a->s0; - aa.s4 = a->s4; + aa.hi = a->hi; + aa.lo = a->lo; if (F48_16_IsZero(&aa)) { - a->s0 = 0; - a->s4 = 0; + a->hi = 0; + a->lo = 0; } else { F48_16_Abs(&aa); F48_16_UMul(&res, &aa, &aa); - a->s0 = res.s0; - a->s4 = res.s4; + a->hi = res.hi; + a->lo = res.lo; } } // Regswap https://decomp.me/scratch/HNmlz -static void F48_16_UMul(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b) +static void F48_16_UMul(s48_16 *dst, s48_16 *a, s48_16 *b) { u32 sl; u32 r1; @@ -697,18 +697,18 @@ static void F48_16_UMul(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_ s32 i; if (F48_16_IsZero(a)) { - dst->s0 = 0; - dst->s4 = 0; + dst->hi = 0; + dst->lo = 0; } else if (F48_16_IsZero(b)) { - dst->s0 = 0; - dst->s4 = 0; + dst->hi = 0; + dst->lo = 0; } else { - r1 = a->s0; - r4 = a->s4; - sl = b->s0; - r2 = b->s4; + r1 = a->hi; + r4 = a->lo; + sl = b->hi; + r2 = b->lo; r6 = 0; r5 = 0; @@ -745,13 +745,13 @@ static void F48_16_UMul(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_ if (r1 != 0) r5++; - dst->s0 = r6; - dst->s4 = r5; + dst->hi = r6; + dst->lo = r5; } } // Similar to u24_8_div -static void F48_16_UDiv(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b) +static void F48_16_UDiv(s48_16 *dst, s48_16 *a, s48_16 *b) { s32 temp; bool8 r1; @@ -766,18 +766,18 @@ static void F48_16_UDiv(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_ s32 i; if (F48_16_IsZero(b)) { - dst->s0 = INT32_MAX; - dst->s4 = UINT32_MAX; + dst->hi = INT32_MAX; + dst->lo = UINT32_MAX; } else if (F48_16_IsZero(a)) { - dst->s0 = 0; - dst->s4 = 0; + dst->hi = 0; + dst->lo = 0; } else { - r7 = (a->s0 << 16) | (a->s4 >> 16); - r6 = (a->s4 << 16) | 0x8000; - sp4 = b->s0; - sp8 = b->s4; + r7 = (a->hi << 16) | (a->lo >> 16); + r6 = (a->lo << 16) | 0x8000; + sp4 = b->hi; + sp8 = b->lo; spC = 0; // Effectively unused r9 = 0; r5 = 0; @@ -819,54 +819,54 @@ static void F48_16_UDiv(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_ r9 |= 0x1; } - dst->s0 = spC; - dst->s4 = r9; + dst->hi = spC; + dst->lo = r9; } } -void sub_800A6D0(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b) +void sub_800A6D0(s48_16 *dst, s48_16 *a, s48_16 *b) { s32 s0; u32 s4; - s0 = a->s0 + b->s0; - s4 = a->s4 + b->s4; - if (s4 < a->s4) + s0 = a->hi + b->hi; + s4 = a->lo + b->lo; + if (s4 < a->lo) s0++; - dst->s0 = s0; - dst->s4 = s4; + dst->hi = s0; + dst->lo = s4; } -void sub_800A6F0(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b) +void sub_800A6F0(s48_16 *dst, s48_16 *a, s48_16 *b) { s32 s0; u32 s4; - s0 = a->s0 - b->s0; - s4 = a->s4 - b->s4; - if (s4 > a->s4) + s0 = a->hi - b->hi; + s4 = a->lo - b->lo; + if (s4 > a->lo) s0--; - dst->s0 = s0; - dst->s4 = s4; + dst->hi = s0; + dst->lo = s4; } // Similar to sub_8009F68 -UNUSED void F48_16_Pow(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, s32 b) +UNUSED void F48_16_Pow(s48_16 *dst, s48_16 *a, s32 b) { - unkStruct_80943A8 aa; + s48_16 aa; s32 bb; - unkStruct_80943A8 res; + s48_16 res; - aa.s0 = a->s0; - aa.s4 = a->s4; + aa.hi = a->hi; + aa.lo = a->lo; bb = b; if (bb < 0) bb = -bb; - res.s0 = 0; - res.s4 = 0x10000; + res.hi = 0; + res.lo = 0x10000; for (; bb != 0; bb >>= 1) { if (bb & 1) @@ -876,25 +876,25 @@ UNUSED void F48_16_Pow(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, s32 b) } if (b < 0) { - unkStruct_80943A8 idk; - idk.s0 = 0; - idk.s4 = 0x10000; + s48_16 idk; + idk.hi = 0; + idk.lo = 0x10000; F48_16_SDiv(&res, &idk, &res); } - dst->s0 = res.s0; - dst->s4 = res.s4; + dst->hi = res.hi; + dst->lo = res.lo; } // Similar to sub_8009FB8 -UNUSED void sub_800A78C(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b) +UNUSED void sub_800A78C(s48_16 *dst, s48_16 *a, s48_16 *b) { u32 temp; s32 i; - unkStruct_80943A8 sp0; - unkStruct_80943A8 sp8; - unkStruct_80943A8 sp10; - unkStruct_80943A8 sp18; + s48_16 sp0; + s48_16 sp8; + s48_16 sp10; + s48_16 sp18; sp0 = *a; sp8 = *b; @@ -913,24 +913,24 @@ UNUSED void sub_800A78C(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_ do { F48_16_SDiv(&sp10, &sp8, &sp0); F48_16_Square(&sp10); - sp18.s0 = sp10.s0; - sp18.s4 = sp10.s4 + 0x40000; + sp18.hi = sp10.hi; + sp18.lo = sp10.lo + 0x40000; - if (sp18.s4 < sp10.s4) - sp18.s0++; + if (sp18.lo < sp10.lo) + sp18.hi++; F48_16_SDiv(&sp10, &sp10, &sp18); F48_16_SMul(&sp18, &sp0, &sp10); - sp18.s0 <<= 1; - if ((s32)sp18.s4 < 0) - sp18.s0 |= 0x1; + sp18.hi <<= 1; + if ((s32) sp18.lo < 0) + sp18.hi |= 0x1; - sp18.s4 <<= 1; - temp = sp0.s4; - sp0.s0 += sp18.s0; - sp0.s4 = temp + sp18.s4; - if (temp > sp0.s4) - sp0.s0++; + sp18.lo <<= 1; + temp = sp0.lo; + sp0.hi += sp18.hi; + sp0.lo = temp + sp18.lo; + if (temp > sp0.lo) + sp0.hi++; if (i == 2) break; @@ -941,4 +941,4 @@ UNUSED void sub_800A78C(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_ } *dst = sp0; -} \ No newline at end of file +} diff --git a/src/number_util.c b/src/number_util.c index 185774045..19c9c1bd8 100644 --- a/src/number_util.c +++ b/src/number_util.c @@ -84,12 +84,12 @@ FixedPoint IntToFixedPoint(s32 a) return p; } -FixedPoint FixedPoint_SetFromUnk(unkStruct_80943A8* param_1) +FixedPoint FixedPoint_SetFromUnk(s48_16* param_1) { FixedPoint s; - s.unk0 = param_1->s4 >> 0x10; - s.unk2 = (1000 * (param_1->s4 & 0xffff)) >> 0x10; + s.unk0 = param_1->lo >> 0x10; + s.unk2 = (1000 * (param_1->lo & 0xffff)) >> 0x10; return s; } diff --git a/src/type_effectiveness.c b/src/type_effectiveness.c index 9f5f57f7b..f332f3204 100644 --- a/src/type_effectiveness.c +++ b/src/type_effectiveness.c @@ -15,21 +15,21 @@ u32 gUnknown_8106EFC[] = { 0x00, 0x00 }; -unkStruct_80943A8 gUnknown_8106F04 = { 0x0, 0x10000 }; -unkStruct_80943A8 gUnknown_8106F0C = { 0x0, 0x20000 }; -unkStruct_80943A8 gUnknown_8106F14 = { 0x0, 0x18000 }; -unkStruct_80943A8 gUnknown_8106F1C = { 0x0, 0x8000 }; +s48_16 gUnknown_8106F04 = { 0x0, 0x10000 }; +s48_16 gUnknown_8106F0C = { 0x0, 0x20000 }; +s48_16 gUnknown_8106F14 = { 0x0, 0x18000 }; +s48_16 gUnknown_8106F1C = { 0x0, 0x8000 }; u8 gUnknown_8106F24[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x01, 0x00 }; -unkStruct_80943A8 gUnknown_8106F3C = {0x0, 0x8000}; -unkStruct_80943A8 gUnknown_8106F44 = {0x0, 0xE666}; -unkStruct_80943A8 gUnknown_8106F4C = {0x0, 0x18000}; +s48_16 gUnknown_8106F3C = {0x0, 0x8000}; +s48_16 gUnknown_8106F44 = {0x0, 0xE666}; +s48_16 gUnknown_8106F4C = {0x0, 0x18000}; struct dumb_struct { - unkStruct_80943A8 *unk0[NUM_EFFECTIVENESS]; + s48_16 *unk0[NUM_EFFECTIVENESS]; }; struct dumb_struct gUnknown_8106F54 = { @@ -39,7 +39,7 @@ struct dumb_struct gUnknown_8106F54 = { &gUnknown_8106F4C, // SUPER }; -unkStruct_80943A8 gUnknown_8106F64 = {0x0, 0xC000}; +s48_16 gUnknown_8106F64 = {0x0, 0xC000}; u32 gTypeEffectivenessMultipliers[] = {0, 1, 2, 4}; @@ -66,7 +66,7 @@ void sub_8042978(Entity *); void sub_804298C(Entity *); void sub_80428EC(Entity *); -bool8 sub_806E100(unkStruct_80943A8 *param_1, Entity *pokemon, Entity *target, u8 type, struct unkStruct_806D010 *param_5) +bool8 sub_806E100(s48_16 *param_1, Entity *pokemon, Entity *target, u8 type, struct unkStruct_806D010 *param_5) { bool8 torrentFlag; bool8 overgrowFlag; @@ -128,8 +128,8 @@ bool8 sub_806E100(unkStruct_80943A8 *param_1, Entity *pokemon, Entity *target, u bVar4 = TRUE; if ((param_5->effectiveness != EFFECTIVENESS_SUPER) && (bVar4 = FALSE, hasWonderGuard)) { temp = gUnknown_8106EFC[1]; - param_1->s0 = gUnknown_8106EFC[0]; - param_1->s4 = temp; + param_1->hi = gUnknown_8106EFC[0]; + param_1->lo = temp; } if (((type == TYPE_FIRE) || (type == TYPE_ICE)) && (HasAbility(target,ABILITY_THICK_FAT))) { diff --git a/tmp/fixpoint.cocci b/tmp/fixpoint.cocci new file mode 100644 index 000000000..1c25b8c31 --- /dev/null +++ b/tmp/fixpoint.cocci @@ -0,0 +1,17 @@ +@@ +s48_16 e; +s48_16 *ep; +@@ +( +- e.s0 ++ e.hi +| +- e.s4 ++ e.lo +| +- ep->s0 ++ ep->hi +| +- ep->s4 ++ ep->lo +) From 191282081358382e8c3e18168f40acc8b3151388 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Sat, 9 Nov 2024 15:16:30 +0100 Subject: [PATCH 04/12] math cleanup --- include/math.h | 14 ++++++------ include/number_util.h | 2 ++ src/code_806E8B0.c | 46 ++++++++++++++++++++-------------------- src/code_809D148.c | 2 +- src/file_system.c | 2 +- src/ground_script_1.c | 12 +++++------ src/math.c | 26 +++++++++++------------ src/type_effectiveness.c | 6 +++--- tmp/renames.sed | 26 +++++++++++++++++++++++ 9 files changed, 82 insertions(+), 54 deletions(-) create mode 100644 tmp/renames.sed diff --git a/include/math.h b/include/math.h index d2fe2bd1e..00b1308a0 100644 --- a/include/math.h +++ b/include/math.h @@ -54,12 +54,12 @@ bool8 F48_16_IsZero(s48_16 *a); void F48_16_SDiv(s48_16 *dst, s48_16 *a, s48_16 *b); void F48_16_SMul(s48_16 *dst, s48_16 *a, s48_16 *b); -s32 sub_8009FB8(s32 x, s32 y); -void sub_800A020(s48_16 *dst, u32); -u32 sub_800A048(s48_16 *a); -void sub_800A088(s48_16 *a, s32 b); -bool8 sub_800A2F0(s48_16 *a, s48_16 *b); -void sub_800A6D0(s48_16 *dst, s48_16 *a, s48_16 *b); -void sub_800A6F0(s48_16 *dst, s48_16 *a, s48_16 *b); +s32 FP24_8_Hypot(s32 x, s32 y); +void FP48_16_FromS32(s48_16 *dst, u32); +u32 FP48_16_ToS32(s48_16 *a); +void FP48_16_FromF248(s48_16 *a, s24_8 b); +bool8 FP48_16_SLessThan(s48_16 *a, s48_16 *b); +void FP48_16_Add(s48_16 *dst, s48_16 *a, s48_16 *b); +void FP48_16_Subtract(s48_16 *dst, s48_16 *a, s48_16 *b); #endif // GUARD_MATH_H diff --git a/include/number_util.h b/include/number_util.h index b835a5fcb..dfdbbead2 100644 --- a/include/number_util.h +++ b/include/number_util.h @@ -1,12 +1,14 @@ #ifndef GUARD_NUMBER_UTIL_H #define GUARD_NUMBER_UTIL_H +// Fixed point with an integer part and fraction part in thousandths typedef struct FixedPoint { s16 unk0; s16 unk2; } FixedPoint; +// Binary 48.16 fixed point typedef struct s48_16 { s32 hi; diff --git a/src/code_806E8B0.c b/src/code_806E8B0.c index a747c92fa..a8986d7d6 100644 --- a/src/code_806E8B0.c +++ b/src/code_806E8B0.c @@ -276,11 +276,11 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 attackerInfo->previousVisualFlags &= ~(0x100); attackerInfo->visualFlags &= ~(0x100); ApplyAtkDefStatBoosts(attacker, target, moveType, &atkStat, &defStat, rand); - sub_800A020(&unkSp1, atkStat - defStat); - sub_800A020(&unkSp2, 8); + FP48_16_FromS32(&unkSp1, atkStat - defStat); + FP48_16_FromS32(&unkSp2, 8); F48_16_SDiv(&unkSp1, &unkSp1, &unkSp2); if (!attackerInfo->isNotTeamMember) { - sub_800A020(&unkSp2, attackerInfo->level); + FP48_16_FromS32(&unkSp2, attackerInfo->level); unkSp3.hi = 0; unkSp3.lo = 0xAAAA; F48_16_SMul(&unkSp2, &unkSp2, &unkSp3); @@ -290,31 +290,31 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 s32 unkAtkStat2 = attackerInfo->atk[splitIndex]; s32 unkDefStat2 = 1; ApplyAtkDefStatBoosts(attacker, target, moveType, &unkAtkStat2, &unkDefStat2, rand); - sub_800A020(&unkSp2, unkAtkStat2); - sub_800A020(&unkSp3, 3); + FP48_16_FromS32(&unkSp2, unkAtkStat2); + FP48_16_FromS32(&unkSp3, 3); F48_16_SDiv(&unkSp2, &unkSp2, &unkSp3); r6 = unkAtkStat2 / 3; } - sub_800A6D0(&unkSp4, &unkSp1, &unkSp2); + FP48_16_Add(&unkSp4, &unkSp1, &unkSp2); gDungeon->unk134.unk140[5] = r6; - gDungeon->unk134.unk140[6] = sub_800A048(&unkSp4); + gDungeon->unk134.unk140[6] = FP48_16_ToS32(&unkSp4); unkSp5 = unkSp4; unkSp7 = unkSp4; F48_16_SMul(&unkSp5, &unkSp5, &unkSp5); unkSp6.hi = 0; unkSp6.lo = 0xCCC; F48_16_SMul(&unkSp5, &unkSp5, &unkSp6); - sub_800A020(&unkSp6, 2); + FP48_16_FromS32(&unkSp6, 2); F48_16_SMul(&unkSp7, &unkSp7, &unkSp6); - sub_800A020(&unkSp6, defStat); - sub_800A6F0(&unkSp7, &unkSp7, &unkSp6); - sub_800A020(&unkSp6, 10); - sub_800A6D0(&unkSp7, &unkSp7, &unkSp6); - sub_800A6D0(&unkSp8, &unkSp5, &unkSp7); - if (sub_800A2F0(&gUnknown_8106F24, &unkSp8)) { + FP48_16_FromS32(&unkSp6, defStat); + FP48_16_Subtract(&unkSp7, &unkSp7, &unkSp6); + FP48_16_FromS32(&unkSp6, 10); + FP48_16_Add(&unkSp7, &unkSp7, &unkSp6); + FP48_16_Add(&unkSp8, &unkSp5, &unkSp7); + if (FP48_16_SLessThan(&gUnknown_8106F24, &unkSp8)) { unkSp8 = gUnknown_8106F24; } - if (sub_800A2F0(&unkSp8, &gUnknown_8106F04)) { + if (FP48_16_SLessThan(&unkSp8, &gUnknown_8106F04)) { unkSp8 = gUnknown_8106F04; } r5 = sub_806E100(&unkSp9, attacker, target, moveType, dmgStruct); @@ -380,7 +380,7 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 } } - gDungeon->unk134.unk154 = sub_800A048(&unkSp8); + gDungeon->unk134.unk154 = FP48_16_ToS32(&unkSp8); F48_16_SMul(&unkSp8, &unkSp8, &unkSp9); { // Ugly hack needed to match @@ -392,25 +392,25 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 gDungeon->unk134.unk15C = arg8_Match = arg8; ASM_MATCH_TRICK(arg8); - sub_800A088(&unkSp10, arg8_Match); + FP48_16_FromF248(&unkSp10, arg8_Match); F48_16_SMul(&unkSp8, &unkSp8, &unkSp10); } // ALSO needed to match. unk694 chosen randomly and it worked with matching. ASM_MATCH_TRICK(gDungeon->unk644.unk50); - gDungeon->unk134.unk150 = sub_800A048(&unkSp8); + gDungeon->unk134.unk150 = FP48_16_ToS32(&unkSp8); { s32 rnd = DungeonRandInt(0x4000); unkSp9.hi = 0; unkSp9.lo = 0xE000 + rnd; } F48_16_SMul(&unkSp8, &unkSp8, &unkSp9); - sub_800A020(&unkSp11, 100); + FP48_16_FromS32(&unkSp11, 100); F48_16_SMul(&unkSp9, &unkSp11, &unkSp9); - gDungeon->unk134.unk158 = sub_800A048(&unkSp9); + gDungeon->unk134.unk158 = FP48_16_ToS32(&unkSp9); - dmgStruct->dmg = sub_800A048(&unkSp8); + dmgStruct->dmg = FP48_16_ToS32(&unkSp8); dmgStruct->residualDmgType = 0; if (dmgStruct->dmg == 0) { dmgStruct->isCrit = FALSE; @@ -429,9 +429,9 @@ void sub_806F2BC(Entity *attacker, Entity *target, u8 moveType, s32 a2, struct D dmgStruct->type = moveType; sub_806E100(&unkSp1, attacker, target, moveType, dmgStruct); - sub_800A020(&unkSp2, a2New); + FP48_16_FromS32(&unkSp2, a2New); F48_16_SMul(&unkSp2, &unkSp2, &unkSp1); - dmgStruct->dmg = sub_800A048(&unkSp2); + dmgStruct->dmg = FP48_16_ToS32(&unkSp2); dmgStruct->residualDmgType = 0; } diff --git a/src/code_809D148.c b/src/code_809D148.c index 4de71dd82..5f8e51d99 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -311,7 +311,7 @@ void sub_809D25C(void) case 3: r2 = (gUnknown_20399E8.unk1C.a0 - gUnknown_20399E8.unk14.a0) / 256; r1 = (gUnknown_20399E8.unk1C.a4 - gUnknown_20399E8.unk14.a4) / 256; - gUnknown_20399E8.unk10 = ((sub_8009FB8(r2 << 8, r1 << 8) / 256) << 8) / gUnknown_20399E8.unkC; + gUnknown_20399E8.unk10 = ((FP24_8_Hypot(r2 << 8, r1 << 8) / 256) << 8) / gUnknown_20399E8.unkC; if (gUnknown_20399E8.unk10 <= 0) gUnknown_20399E8.unk10 = 1; gUnknown_20399E8.unk8 = 2; diff --git a/src/file_system.c b/src/file_system.c index 73682e6a2..396265b9b 100644 --- a/src/file_system.c +++ b/src/file_system.c @@ -12,7 +12,7 @@ static EWRAM_DATA_2 u32 sFileCacheCursorPosition = {0}; // ??? extern s32 sprintf(char *, const char *, ...); -UNUSED static void sub_800A894(UnkFileStruct *r0, s32 r1) +UNUSED static void FP48_16_Log(UnkFileStruct *r0, s32 r1) { s32 temp; diff --git a/src/ground_script_1.c b/src/ground_script_1.c index 5c8578624..cb24ea8af 100644 --- a/src/ground_script_1.c +++ b/src/ground_script_1.c @@ -1062,7 +1062,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2.x = curCmd.arg1 << 8; scriptData->pos2.y = curCmd.arg2 << 8; if (curCmd.op == 0x7d || curCmd.op == 0x83) { - scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1074,7 +1074,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2.x = scriptData->pos1.x + (curCmd.arg1 << 8); scriptData->pos2.y = scriptData->pos1.y + (curCmd.arg2 << 8); if (curCmd.op == 0x7e || curCmd.op == 0x84) { - scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1097,7 +1097,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2.y = scriptData->pos1.y + ((OtherRandInt(curCmd.arg2 * 2 + 1) - curCmd.arg2) << 8); #endif if (curCmd.op == 0x7f || curCmd.op == 0x85) { - scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1109,7 +1109,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2 = scriptData->pos1; GroundLink_GetPos((s16)curCmd.arg1, &scriptData->pos2); if (curCmd.op == 0x80 || curCmd.op == 0x86) { - scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1123,7 +1123,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2.x = scriptData->pos2.x + ((OtherRandInt(cap) - curCmd.argShort) << 8); scriptData->pos2.y = scriptData->pos2.y + ((OtherRandInt(cap) - curCmd.argShort) << 8); if (curCmd.op == 0x81 || curCmd.op == 0x87) { - scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1136,7 +1136,7 @@ s32 ExecuteScriptCommand(Action *action) { action->callbacks->getHitboxCenter(action->parentObject, &scriptData->pos1); sub_80A8FD8(ret, &scriptData->pos2); if (curCmd.op == 0x82 || curCmd.op == 0x88) { - scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; diff --git a/src/math.c b/src/math.c index 64a7e2b3d..84c243b1b 100644 --- a/src/math.c +++ b/src/math.c @@ -289,7 +289,7 @@ static u24_8 u24_8_div(u24_8 x, u24_8 y) return r9; } -UNUSED s32 sub_8009F68(s32 x, s32 y) +UNUSED s32 FP24_8_Pow(s32 x, s32 y) { s32 uVar1; s32 sVar1; @@ -313,7 +313,7 @@ UNUSED s32 sub_8009F68(s32 x, s32 y) return s24_8_div(0x100, sVar1); } -s32 sub_8009FB8(s32 x, s32 y) +s32 FP24_8_Hypot(s32 x, s32 y) { s32 r4; s32 i; @@ -348,7 +348,7 @@ s32 sub_8009FB8(s32 x, s32 y) return r5; } -void sub_800A020(s48_16 *param_1, u32 param_2) +void FP48_16_FromS32(s48_16 *param_1, u32 param_2) { #ifndef NONMATCHING register u32 temp asm("r4"); @@ -365,7 +365,7 @@ void sub_800A020(s48_16 *param_1, u32 param_2) } -u32 sub_800A048(s48_16 *a) +u32 FP48_16_ToS32(s48_16 *a) { u32 uVar1; @@ -376,7 +376,7 @@ u32 sub_800A048(s48_16 *a) return uVar1; } -UNUSED u32 sub_800A068(u32 *a) +UNUSED u32 FP48_16_ToF248(u32 *a) { u32 uVar1; @@ -387,7 +387,7 @@ UNUSED u32 sub_800A068(u32 *a) return uVar1; } -void sub_800A088(s48_16 *a, s32 b) +void FP48_16_FromF248(s48_16 *a, s32 b) { a->lo = b << 8; a->hi = b >> 24; @@ -556,7 +556,7 @@ static bool8 F48_16_IsNegative(s48_16 *a) return FALSE; } -bool8 sub_800A2F0(s48_16 *a, s48_16 *b) +bool8 FP48_16_SLessThan(s48_16 *a, s48_16 *b) { s32 r1; u32 a0; @@ -824,7 +824,7 @@ static void F48_16_UDiv(s48_16 *dst, s48_16 *a, s48_16 *b) } } -void sub_800A6D0(s48_16 *dst, s48_16 *a, s48_16 *b) +void FP48_16_Add(s48_16 *dst, s48_16 *a, s48_16 *b) { s32 s0; u32 s4; @@ -838,7 +838,7 @@ void sub_800A6D0(s48_16 *dst, s48_16 *a, s48_16 *b) dst->lo = s4; } -void sub_800A6F0(s48_16 *dst, s48_16 *a, s48_16 *b) +void FP48_16_Subtract(s48_16 *dst, s48_16 *a, s48_16 *b) { s32 s0; u32 s4; @@ -852,7 +852,7 @@ void sub_800A6F0(s48_16 *dst, s48_16 *a, s48_16 *b) dst->lo = s4; } -// Similar to sub_8009F68 +// Similar to FP24_8_Pow UNUSED void F48_16_Pow(s48_16 *dst, s48_16 *a, s32 b) { s48_16 aa; @@ -886,8 +886,8 @@ UNUSED void F48_16_Pow(s48_16 *dst, s48_16 *a, s32 b) dst->lo = res.lo; } -// Similar to sub_8009FB8 -UNUSED void sub_800A78C(s48_16 *dst, s48_16 *a, s48_16 *b) +// Similar to FP24_8_Hypot +UNUSED void FP48_16_Hypot(s48_16 *dst, s48_16 *a, s48_16 *b) { u32 temp; s32 i; @@ -901,7 +901,7 @@ UNUSED void sub_800A78C(s48_16 *dst, s48_16 *a, s48_16 *b) F48_16_Abs(&sp0); F48_16_Abs(&sp8); - if (sub_800A2F0(&sp0, &sp8)) { + if (FP48_16_SLessThan(&sp0, &sp8)) { sp10 = sp0; sp0 = sp8; sp8 = sp10; diff --git a/src/type_effectiveness.c b/src/type_effectiveness.c index f332f3204..5853109dc 100644 --- a/src/type_effectiveness.c +++ b/src/type_effectiveness.c @@ -92,7 +92,7 @@ bool8 sub_806E100(s48_16 *param_1, Entity *pokemon, Entity *target, u8 type, str normalOrFightingType = FALSE; pokemonInfo = GetEntInfo(pokemon); targetInfo = GetEntInfo(target); - sub_800A020(param_1, 1); + FP48_16_FromS32(param_1, 1); param_5->unkD = 0; param_5->unkE = 0; hasWonderGuard = FALSE; @@ -138,7 +138,7 @@ bool8 sub_806E100(s48_16 *param_1, Entity *pokemon, Entity *target, u8 type, str } if ((type == TYPE_FIRE) && (GetFlashFireStatus(target) != FLASH_FIRE_STATUS_NONE)) { gDungeon->unk134.fill16E[0] = TRUE; - sub_800A020(param_1,0); + FP48_16_FromS32(param_1,0); param_5->effectiveness = EFFECTIVENESS_IMMUNE; param_5->unkD = 0; param_5->unkE = 1; @@ -146,7 +146,7 @@ bool8 sub_806E100(s48_16 *param_1, Entity *pokemon, Entity *target, u8 type, str } if ((type == TYPE_GROUND) && (HasAbility(target, ABILITY_LEVITATE))) { gDungeon->unk134.fill16E[1] = TRUE; - sub_800A020(param_1,0); + FP48_16_FromS32(param_1,0); param_5->effectiveness = EFFECTIVENESS_IMMUNE; param_5->unkD = 0; param_5->unkE = 1; diff --git a/tmp/renames.sed b/tmp/renames.sed new file mode 100644 index 000000000..39d202303 --- /dev/null +++ b/tmp/renames.sed @@ -0,0 +1,26 @@ +s/sub_8009DA4/FP24_8_SMul/g +s/sub_8009DD8/FP24_8_SDiv/g +s/sub_8009E14/FP24_8_UMul/g +s/sub_8009EA0/FP24_8_UDiv/g +s/sub_8009F68/FP24_8_Pow/g +s/sub_8009FB8/FP24_8_Hypot/g +s/sub_800A020/FP48_16_FromS32/g +s/sub_800A048/FP48_16_ToS32/g +s/sub_800A068/FP48_16_ToF248/g +s/sub_800A088/FP48_16_FromF248/g +s/sub_800A25C/FP48_16_Negate/g +s/sub_800A27C/FP48_16_Abs/g +s/sub_800A2A0/FP48_16_IsZero/g +s/sub_800A2BC/FP48_16_Equal/g +s/sub_800A2DC/FP48_16_IsNegative/g +s/sub_800A2F0/FP48_16_SLessThan/g +s/sub_800A34C/FP48_16_SMul/g +s/sub_800A3F0/FP48_16_SDiv/g +s/sub_800A4A0/FP48_16_Square/g +s/sub_800A4E4/FP48_16_UMul/g +s/sub_800A5A4/FP48_16_UDiv/g +s/sub_800A6D0/FP48_16_Add/g +s/sub_800A6F0/FP48_16_Subtract/g +s/sub_800A710/FP48_16_Pow/g +s/sub_800A78C/FP48_16_Hypot/g +s/sub_800A894/FP48_16_Log/g From bba6da7537075074f3fcb5c831077b87b8a38c25 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Sun, 10 Nov 2024 11:44:46 +0100 Subject: [PATCH 05/12] Convert callers to s24_8, use struct for type safety --- include/math.h | 50 +++++++++---- include/number_util.h | 37 +++++++++- include/status.h | 5 +- include/structs/dungeon_entity.h | 3 +- include/structs/str_dungeon.h | 2 +- include/structs/str_position.h | 4 +- src/code_8041AD0.c | 9 +-- src/code_806E8B0.c | 22 +++--- src/code_806FDF4.c | 3 +- src/code_8077274_1.c | 11 +-- src/code_809D148.c | 2 +- src/dungeon_cutscenes.c | 115 +++++++++++++++--------------- src/dungeon_util_1.c | 7 +- src/ground_script_1.c | 13 ++-- src/math.c | 116 +++++++++++++++---------------- src/move_actions.c | 10 +-- src/move_checks.c | 17 ++--- src/status.c | 44 ++++++------ 18 files changed, 265 insertions(+), 205 deletions(-) diff --git a/include/math.h b/include/math.h index 00b1308a0..2fdb563ec 100644 --- a/include/math.h +++ b/include/math.h @@ -4,20 +4,6 @@ #include "gba/types.h" #include "number_util.h" -/** - * This type represents a signed 24.8 fixed-point number, where the 24 most - * significant bits are the integer part and the 8 least significant bits are - * the fractional part. - */ -typedef s32 s24_8; - -/** - * This type represents an unsigned 24.8 fixed-point number, where the 24 most - * significant bits are the integer part and the 8 least significant bits are - * the fractional part. - */ -typedef u32 u24_8; - /** * This function computes the cosine of of `x` using a lookup table. The period of * the function is `4096`, and the range is `[-256, 256]`. @@ -54,7 +40,7 @@ bool8 F48_16_IsZero(s48_16 *a); void F48_16_SDiv(s48_16 *dst, s48_16 *a, s48_16 *b); void F48_16_SMul(s48_16 *dst, s48_16 *a, s48_16 *b); -s32 FP24_8_Hypot(s32 x, s32 y); +s24_8 FP24_8_Hypot(s24_8 x, s24_8 y); void FP48_16_FromS32(s48_16 *dst, u32); u32 FP48_16_ToS32(s48_16 *a); void FP48_16_FromF248(s48_16 *a, s24_8 b); @@ -62,4 +48,38 @@ bool8 FP48_16_SLessThan(s48_16 *a, s48_16 *b); void FP48_16_Add(s48_16 *dst, s48_16 *a, s48_16 *b); void FP48_16_Subtract(s48_16 *dst, s48_16 *a, s48_16 *b); +//static inline bool8 F248Equal(s24_8 x, s24_8 y) { +// return x.raw == y.raw; +//} + +#define F248LessThanInt(x, y) (x.raw < 0x100 * y) +#define F248LessThanFloat(x, y) (x.raw < (int)(y * 0x100)) +#define FloatLessThanF248(x, y) ((int)(x * 0x100) < y.raw) +//static inline bool8 F248LessThanOne(s24_8 x) { +// return x.raw < 0x100; +//} +#define F248LessThan(x, y) (x.raw < y.raw) +#define F248GreaterThan(x, y) (x.raw > y.raw) +#define F248Equal(x, y) (x.raw == y.raw) +#define F248EqualsInt(x, y) (x.raw == 0x100 * y) + +//static inline bool8 F248LessThan(s24_8 x, s24_8 y) { +// return x.raw < y.raw; +//} + +#define F248_AddInt(x, y) ((s24_8){x.raw + 0x100 * y}) +#define F248_SubInt(x, y) ((s24_8){x.raw - 0x100 * y}) + +static inline s24_8 F248_Add(s24_8 x, s24_8 y) { + return (s24_8){x.raw + y.raw}; +} + +static inline s24_8 F248_Sub(s24_8 x, s24_8 y) { + return (s24_8){x.raw - y.raw}; +} + +static inline s24_8 F248_MulInt(s24_8 x, s32 y) { + return (s24_8){x.raw * y}; +} + #endif // GUARD_MATH_H diff --git a/include/number_util.h b/include/number_util.h index dfdbbead2..d2e6741ed 100644 --- a/include/number_util.h +++ b/include/number_util.h @@ -1,14 +1,32 @@ #ifndef GUARD_NUMBER_UTIL_H #define GUARD_NUMBER_UTIL_H -// Fixed point with an integer part and fraction part in thousandths +/** + * This type represents a decimal, signed fixed-point number, where the first + * 16-bit field is the integer part and the second 16-bit field is the fraction, + * expressed in thousandths. + */ typedef struct FixedPoint { s16 unk0; s16 unk2; } FixedPoint; -// Binary 48.16 fixed point +/** + * This type represents a signed 24.8 fixed-point number, where the 24 most + * significant bits are the integer part and the 8 least significant bits are + * the fractional part. + */ +typedef struct s24_8 { + // It's almost certainly not an actual struct, but keep it as one until we decomp all structures that include it + s32 raw; +} s24_8; + +/** + * This type represents a signed 48.16 fixed-point number, where the 48 most + * significant bits are the integer part and the 16 least significant bits are + * the fractional part. + */ typedef struct s48_16 { s32 hi; @@ -25,4 +43,19 @@ FixedPoint FixedPoint_SetFromUnk(s48_16* param_1); FixedPoint FixedPoint_Div(FixedPoint a, FixedPoint b); s32 FixedPointToInt(FixedPoint a); // Always rounded up +#define IntToF248_2(x) ((s24_8){x * 0x100}) +#define FloatToF248_2(x) ((s24_8){(int)(x * 0x100)}) +static inline s24_8 IntToF248(s32 x) { + return (s24_8){x * 256}; +} + +static inline s24_8 FloatToF248(float x) { + return (s24_8){(int)(x * 256)}; +} + +static inline s32 F248ToInt(s24_8 x) { + return x.raw / 256; +} + + #endif diff --git a/include/status.h b/include/status.h index 0526c007a..9bd8ca56f 100644 --- a/include/status.h +++ b/include/status.h @@ -2,6 +2,7 @@ #define GUARD_STATUS_H #include "structs/dungeon_entity.h" +#include "number_util.h" #define FLASH_FIRE_STATUS_NONE 0 #define FLASH_FIRE_STATUS_MAXED 1 @@ -9,8 +10,8 @@ u8 GetFlashFireStatus(Entity *pokemon); void UpdateFlashFireBoost(Entity * pokemon, Entity *target); -void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s32 param_4, bool8 displayMessage); -void ChangeDefenseMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s32 param_4, bool8 displayMessage); +void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s24_8 param_4, bool8 displayMessage); +void ChangeDefenseMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s24_8 param_4, bool8 displayMessage); void RaiseAccuracyStageTarget(Entity * pokemon, Entity * target, s32 statStage); void LowerAccuracyStageTarget(Entity * pokemon, Entity * target, s32 statStage, bool8 displayMessage); void CringeStatusTarget(Entity * pokemon,Entity * target, bool8 displayMessage); diff --git a/include/structs/dungeon_entity.h b/include/structs/dungeon_entity.h index dbafaa253..7bb65b928 100644 --- a/include/structs/dungeon_entity.h +++ b/include/structs/dungeon_entity.h @@ -13,9 +13,8 @@ #include "sprite.h" #define MAX_STAT_STAGE 20 -#define STAT_MULTIPLIER_THRESHOLD 63 +#define STAT_MULTIPLIER_THRESHOLD 0.249 // one tick less than 0.25 #define DEFAULT_STAT_STAGE 10 -#define DEFAULT_STAT_MULTIPLIER 256 #define MAX_SPEED_STAGE 4 #define MAX_STOCKPILE_STAGE 3 #define NUM_SPEED_COUNTERS 5 diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 6296d3188..b95093631 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -170,7 +170,7 @@ struct unkStruct_Dungeon134_sub u32 unk150; u32 unk154; u32 unk158; - u32 unk15C; + s24_8 unk15C; u8 unk160; u8 unk161; u8 unk162; diff --git a/include/structs/str_position.h b/include/structs/str_position.h index cfd0f7701..a376af4bf 100644 --- a/include/structs/str_position.h +++ b/include/structs/str_position.h @@ -11,8 +11,8 @@ typedef struct Position // size: 0x8 typedef struct Position32 { - /* 0x0 */ s32 x; + /* 0x0 */ s32 x; // TODO: convert to s24_8 across the codebase /* 0x4 */ s32 y; } Position32; -#endif // GUARD_STR_POSITION_H \ No newline at end of file +#endif // GUARD_STR_POSITION_H diff --git a/src/code_8041AD0.c b/src/code_8041AD0.c index 49181d728..5788623d7 100644 --- a/src/code_8041AD0.c +++ b/src/code_8041AD0.c @@ -1,4 +1,5 @@ #include "global.h" +#include "math.h" #include "code_800E9A8.h" #include "code_803E46C.h" #include "code_803E724.h" @@ -223,10 +224,10 @@ void EntityUpdateStatusSprites(Entity *entity) if ((gDungeon->unk644.itemHoldersIdentified) && (entityInfo->heldItem.flags & ITEM_FLAG_EXISTS)) { spriteStatus = spriteStatus | STATUS_SPRITE_LOWHP; } - if ( (entityInfo->offensiveMultipliers[0] < DEFAULT_STAT_MULTIPLIER) || - (entityInfo->offensiveMultipliers[1] < DEFAULT_STAT_MULTIPLIER) || - (entityInfo->defensiveMultipliers[0] < DEFAULT_STAT_MULTIPLIER) || - (entityInfo->defensiveMultipliers[1] < DEFAULT_STAT_MULTIPLIER) || + if ((F248LessThanInt(entityInfo->offensiveMultipliers[0], 1)) || + (F248LessThanInt(entityInfo->offensiveMultipliers[1], 1)) || + (F248LessThanInt(entityInfo->defensiveMultipliers[0], 1)) || + (F248LessThanInt(entityInfo->defensiveMultipliers[1], 1)) || (entityInfo->offensiveStages[0] < DEFAULT_STAT_STAGE) || (entityInfo->offensiveStages[1] < DEFAULT_STAT_STAGE) || (entityInfo->defensiveStages[0] < DEFAULT_STAT_STAGE) || diff --git a/src/code_806E8B0.c b/src/code_806E8B0.c index a8986d7d6..ffcc4c37d 100644 --- a/src/code_806E8B0.c +++ b/src/code_806E8B0.c @@ -34,8 +34,8 @@ extern void sub_8041B5C(Entity *pokemon); extern void HandleDealingDamage(Entity *attacker, Entity *target, struct DamageStruct *dmgStruct, bool32 isFalseSwipe, bool32 giveExp, s16 arg4, bool32 arg8, s32 argC); extern const s32 gUnknown_80F54B4[NUM_EFFECTIVENESS][NUM_EFFECTIVENESS]; -extern const s32 gUnknown_80F504C[]; -extern const s32 gUnknown_80F50A0[]; +extern const s24_8 gUnknown_80F504C[]; +extern const s24_8 gUnknown_80F50A0[]; extern const s16 gUnknown_810AC60; extern const s16 gUnknown_810AC68; extern const s16 gUnknown_810AC64; @@ -154,7 +154,7 @@ static inline void SetDamageOne(struct DamageStruct *dmgStruct, u8 moveType) dmgStruct->tookNoDamage = FALSE; } -void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s32 critChance, struct DamageStruct *dmgStruct, s32 arg8, u16 moveId, bool8 arg_10) +void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s32 critChance, struct DamageStruct *dmgStruct, s24_8 arg8, u16 moveId, bool8 arg_10) { EntityInfo *attackerInfo = GetEntInfo(attacker); EntityInfo *targetInfo = GetEntInfo(target); @@ -169,7 +169,7 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 } else { s32 atkStatStage, defStatStage; - s32 statCalc; + s24_8 statCalc; s32 atkStat, defStat; s32 rand; s32 r6; @@ -210,9 +210,9 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 gDungeon->unk134.unk13E[0] = atkStatStage; gDungeon->unk134.unk140[0] = attackerInfo->atk[splitIndex] + movePower; - statCalc = s24_8_mul((attackerInfo->atk[splitIndex] + movePower) * 256, gUnknown_80F504C[atkStatStage]); + statCalc = s24_8_mul(IntToF248(attackerInfo->atk[splitIndex] + movePower), gUnknown_80F504C[atkStatStage]); statCalc = s24_8_mul(statCalc, attackerInfo->offensiveMultipliers[splitIndex]); - atkStat = statCalc / 256; + atkStat = F248ToInt(statCalc); defStatStage = targetInfo->defensiveStages[splitIndex]; if (splitIndex == 0 && targetInfo->bideClassStatus.status == STATUS_SKULL_BASH) { @@ -234,9 +234,9 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 gDungeon->unk134.unk13E[1] = defStatStage; gDungeon->unk134.unk140[1] = targetInfo->def[splitIndex]; - statCalc = s24_8_mul((targetInfo->def[splitIndex]) * 256, gUnknown_80F50A0[defStatStage]); + statCalc = s24_8_mul(IntToF248(targetInfo->def[splitIndex]), gUnknown_80F50A0[defStatStage]); statCalc = s24_8_mul(statCalc, targetInfo->defensiveMultipliers[splitIndex]); - defStat = statCalc / 256; + defStat = F248ToInt(statCalc); rand = DungeonRandInt(100); if (splitIndex == 0) { @@ -385,13 +385,13 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 { // Ugly hack needed to match #ifdef NONMATCHING - s32 arg8_Match; + s24_8 arg8_Match; #else - register s32 arg8_Match asm("r2"); + register s24_8 arg8_Match asm("r2"); #endif // NONMATCHING gDungeon->unk134.unk15C = arg8_Match = arg8; - ASM_MATCH_TRICK(arg8); + //ASM_MATCH_TRICK(arg8); FP48_16_FromF248(&unkSp10, arg8_Match); F48_16_SMul(&unkSp8, &unkSp8, &unkSp10); } diff --git a/src/code_806FDF4.c b/src/code_806FDF4.c index 7eb2ea2e6..553ffa59b 100644 --- a/src/code_806FDF4.c +++ b/src/code_806FDF4.c @@ -23,6 +23,7 @@ #include "text_util.h" #include "dungeon_util_1.h" #include "type_chart.h" +#include "math.h" extern u8 gFormatBuffer_FriendArea[]; extern u8 gUnknown_202EE70[MAX_TEAM_BODY_SIZE]; @@ -132,7 +133,7 @@ void sub_806F500(void) temp->unk140[6] = 0; temp->unk150 = 0; temp->unk158 = 0; - temp->unk15C = 0; + temp->unk15C = IntToF248(0); temp->unk160 = 0; temp->unk161 = 0; temp->unk162 = 0; diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index fadd47483..51b78451a 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -17,6 +17,7 @@ #include "dungeon_util.h" #include "move_effects_target.h" #include "moves.h" +#include "math.h" #include "pokemon.h" #include "pokemon_mid.h" #include "status_checks_1.h" @@ -704,7 +705,7 @@ void SetChargeStatusTarget(Entity *pokemon, Entity *target, u8 newStatus, Move * for (index = 0, iVar8 = 0xc7ff; index < 400; index++) { bVar2 = TRUE; if (entityInfo->unkFF == 1) - if(iVar7 = entityInfo->unk174, bVar2 = FALSE, iVar7 > iVar8) // unk174 -> u32 to s32 + if(iVar7 = entityInfo->unk174.raw, bVar2 = FALSE, iVar7 > iVar8) // unk174 -> u32 to s32 { bVar2 = TRUE; } @@ -1025,12 +1026,12 @@ void sub_8079E34(Entity * pokemon, Entity * target, bool8 param_3) entityInfo->hitChanceStages[index] = DEFAULT_STAT_STAGE; statChanged = TRUE; } - if (entityInfo->offensiveMultipliers[index] != DEFAULT_STAT_MULTIPLIER) { - entityInfo->offensiveMultipliers[index] = DEFAULT_STAT_MULTIPLIER; + if (!F248EqualsInt(entityInfo->offensiveMultipliers[index], 1)) { + entityInfo->offensiveMultipliers[index] = IntToF248(1); statChanged = TRUE; } - if (entityInfo->defensiveMultipliers[index] != DEFAULT_STAT_MULTIPLIER) { - entityInfo->defensiveMultipliers[index] = DEFAULT_STAT_MULTIPLIER; + if (!F248EqualsInt(entityInfo->defensiveMultipliers[index], 1)) { + entityInfo->defensiveMultipliers[index] = IntToF248(1); statChanged = TRUE; } } diff --git a/src/code_809D148.c b/src/code_809D148.c index 5f8e51d99..2224a7472 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -311,7 +311,7 @@ void sub_809D25C(void) case 3: r2 = (gUnknown_20399E8.unk1C.a0 - gUnknown_20399E8.unk14.a0) / 256; r1 = (gUnknown_20399E8.unk1C.a4 - gUnknown_20399E8.unk14.a4) / 256; - gUnknown_20399E8.unk10 = ((FP24_8_Hypot(r2 << 8, r1 << 8) / 256) << 8) / gUnknown_20399E8.unkC; + gUnknown_20399E8.unk10 = (F248ToInt(FP24_8_Hypot(IntToF248(r2), IntToF248(r1))) << 8) / gUnknown_20399E8.unkC; if (gUnknown_20399E8.unk10 <= 0) gUnknown_20399E8.unk10 = 1; gUnknown_20399E8.unk8 = 2; diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index 9dff6a6db..a0437d50e 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -30,6 +30,7 @@ #include "position_util.h" #include "exclusive_pokemon.h" #include "trap.h" +#include "math.h" extern u32 gDungeonBrightness; @@ -1013,11 +1014,11 @@ void ZapdosDropInEffect(Entity *zapdosEntity) GetEntInfo(zapdosEntity)->unk15C = 1; GetEntInfo(zapdosEntity)->unk15E = 0; - GetEntInfo(zapdosEntity)->unk174 = 200; + GetEntInfo(zapdosEntity)->unk174.raw = 200; // incorrect value? Overwritten immediately anyway PlaySoundEffect(0x1ea); for(iVar1 = 200; iVar1 >= 0; iVar1 -= 5) { - GetEntInfo(zapdosEntity)->unk174 = iVar1 * 256; + GetEntInfo(zapdosEntity)->unk174 = IntToF248_2(iVar1); sub_803E46C(0x46); } sub_803E708(0x1e,0x46); @@ -1262,11 +1263,11 @@ void MoltresDropInEffect(Entity * moltresEntity) GetEntInfo(moltresEntity)->unk15C = 1; GetEntInfo(moltresEntity)->unk15E = 0; - GetEntInfo(moltresEntity)->unk174 = 0xc800; + GetEntInfo(moltresEntity)->unk174 = IntToF248_2(200); PlaySoundEffect(0x1f8); for(iVar1 = 200; iVar1 >= 0; iVar1 -= 5) { - GetEntInfo(moltresEntity)->unk174 = iVar1 * 256; + GetEntInfo(moltresEntity)->unk174 = IntToF248_2(iVar1); sub_803E46C(0x46); } } @@ -1668,7 +1669,7 @@ void sub_8088484(Entity *param_1) PlaySoundEffect(0x1ea); for(iVar1 = 250; iVar1 >= 0; iVar1 -= 5) { - GetEntInfo(param_1)->unk174 = iVar1 * 256; + GetEntInfo(param_1)->unk174 = IntToF248_2(iVar1); SetDungeonBGColorRGB(iVar1,iVar1,iVar1 / 2,1,0); sub_803E46C(0x46); } @@ -2477,24 +2478,24 @@ void RayquazaPostStoryPreFightDialogue(void) void RayquazaDropInEffect(Entity *rayquazaEntity) { - s32 iVar1; - s32 iVar2; + s24_8 iVar1; + s24_8 iVar2; GetEntInfo(rayquazaEntity)->unk15E = 0; - iVar2 = 51200; - iVar1 = 0x600; + iVar2 = IntToF248_2(200); + iVar1 = IntToF248_2(6); PlaySoundEffect(0x1f8); while( 1 ) { - iVar2 = iVar2 - iVar1; - iVar1 -= 0x18; - if (iVar1 < 0x14) { - iVar1 = 0x14; + iVar2.raw = iVar2.raw - iVar1.raw; // must be .raw + iVar1 = F248_Sub(iVar1, FloatToF248_2(3./32.)); + if (F248LessThanFloat(iVar1, 0.08)) { + iVar1 = FloatToF248(0.08); } - if (iVar2 < 0) break; + if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(rayquazaEntity)->unk174 = iVar2; sub_803E46C(0x46); } - GetEntInfo(rayquazaEntity)->unk174 = 0; + GetEntInfo(rayquazaEntity)->unk174 = IntToF248_2(0); } void RayquazaScreenFlash(void) @@ -2750,24 +2751,24 @@ void MewtwoReFightDialogue(void) void MewtwoDropInEffect(Entity *mewtwoEntity) { - s32 iVar1; - s32 iVar2; + s24_8 iVar1; + s24_8 iVar2; GetEntInfo(mewtwoEntity)->unk15E = 0; - iVar2 = 51200; - iVar1 = 0x400; + iVar2 = IntToF248_2(200); + iVar1 = IntToF248_2(4); PlaySoundEffect(0x1f8); while( 1 ) { - iVar2 = iVar2 - iVar1; - iVar1 -= 11; - if (iVar1 < 0x1e) { - iVar1 = 0x1e; + iVar2.raw -= iVar1.raw; + iVar1 = F248_Sub(iVar1, FloatToF248_2(0.045)); + if (F248LessThanFloat(iVar1, 0.12)) { + iVar1 = FloatToF248_2(0.12); } - if (iVar2 < 0) break; + if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(mewtwoEntity)->unk174 = iVar2; sub_803E46C(0x46); } - GetEntInfo(mewtwoEntity)->unk174 = 0; + GetEntInfo(mewtwoEntity)->unk174 = IntToF248_2(0); } void MewtwoScreenFlash(void) @@ -3209,24 +3210,24 @@ void SuicunePostStoryPreFightDialogue(void) void sub_808A528(Entity * param_1) { - s32 iVar1; - s32 iVar2; + s24_8 iVar1; + s24_8 iVar2; GetEntInfo(param_1)->unk15E = 0; - iVar2 = 51200; - iVar1 = 3072; + iVar2 = IntToF248(200); + iVar1 = IntToF248(12); PlaySoundEffect(0x1f8); while( 1 ) { - iVar2 = iVar2 - iVar1; - iVar1 -= 96; - if (iVar1 < 20) { - iVar1 = 20; + iVar2.raw -= iVar1.raw; + iVar1 = F248_Sub(iVar1, FloatToF248(0.375)); + if (F248LessThanFloat(iVar1, 0.08)) { + iVar1 = FloatToF248_2(0.08); } - if (iVar2 < 0) break; + if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(param_1)->unk174 = iVar2; sub_803E46C(70); } - GetEntInfo(param_1)->unk174 = 0; + GetEntInfo(param_1)->unk174 = IntToF248_2(0); } void SuicuneScreenFlash(void) @@ -3387,24 +3388,24 @@ void HoOhReFightDialogue(void) void HoOhDropInEffect(Entity * param_1) { - s32 iVar1; - s32 iVar2; + s24_8 iVar1; + s24_8 iVar2; GetEntInfo(param_1)->unk15E = 0; - iVar2 = 51200; - iVar1 = 3072; + iVar2 = IntToF248(200); + iVar1 = IntToF248(12); PlaySoundEffect(0x1f8); while( 1 ) { - iVar2 = iVar2 - iVar1; - iVar1 -= 96; - if (iVar1 < 20) { - iVar1 = 20; + iVar2.raw -= iVar1.raw; + iVar1 = F248_Sub(iVar1, FloatToF248(0.375)); + if (F248LessThanFloat(iVar1, 0.08)) { + iVar1 = FloatToF248_2(0.08); } - if (iVar2 < 0) break; + if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(param_1)->unk174 = iVar2; sub_803E46C(70); } - GetEntInfo(param_1)->unk174 = 0; + GetEntInfo(param_1)->unk174 = IntToF248_2(0); } void HoOhScreenFlash(void) @@ -4244,25 +4245,25 @@ void sub_808BBA8(Entity *jirachiEntity) void JirachiDropInEffect(Entity *jirachiEntity) { - s32 iVar1; - s32 iVar2; + s24_8 iVar1; + s24_8 iVar2; sub_80861F8(0x1b,jirachiEntity,0); sub_8086A54(jirachiEntity); sub_80861B8(jirachiEntity,0xe,DIRECTION_SOUTH); - iVar1 = 0xa000; - iVar2 = 0x200; + iVar1 = IntToF248(160); + iVar2 = IntToF248(2); PlaySoundEffect(0x1f8); - while( 1 ) { - iVar1 = iVar1 - iVar2; - if (iVar1 < 0x1800) { - iVar2 = 0x100; + while (1) { + iVar1.raw = iVar1.raw - iVar2.raw; // FRAGILE! Subtraction and assignment below must use .raw + if (F248LessThanInt(iVar1, 24)) { + iVar2.raw = IntToF248_2(1).raw; } - if (iVar1 < 0) break; + if (F248LessThanInt(iVar1, 0)) break; GetEntInfo(jirachiEntity)->unk174 = iVar1; sub_803E46C(0x46); } - GetEntInfo(jirachiEntity)->unk174 = 0; + GetEntInfo(jirachiEntity)->unk174 = IntToF248_2(0); } void JirachiSpinEffect(Entity * jirachiEntity) @@ -4880,11 +4881,11 @@ void sub_808C8E0(Entity *entity) PlaySoundEffect(0x1a5); sub_806CDD4(entity, 0, DIRECTION_SOUTH); for(iVar1 = 0; iVar1 < 16; iVar1++){ - GetEntInfo(entity)->unk174 = iVar1 * 256; + GetEntInfo(entity)->unk174 = IntToF248_2(iVar1); sub_803E46C(0x46); } for(iVar1 = 16; iVar1 < 200; iVar1 += 4){ - GetEntInfo(entity)->unk174 = iVar1 * 256; + GetEntInfo(entity)->unk174 = IntToF248_2(iVar1); sub_803E46C(0x46); } sub_8086A3C(entity); diff --git a/src/dungeon_util_1.c b/src/dungeon_util_1.c index ce3acb3f1..d863debc7 100644 --- a/src/dungeon_util_1.c +++ b/src/dungeon_util_1.c @@ -11,6 +11,7 @@ #include "dungeon_leader.h" #include "dungeon_util.h" #include "random.h" +#include "math.h" #include "structs/str_dungeon.h" extern s32 gUnknown_202F3D8; @@ -179,7 +180,7 @@ void sub_80856E0(Entity * pokemon, s32 direction) for(counter = 0; counter < 5; counter++) { - entityInfo->unk174 += 0x200; + entityInfo->unk174 = F248_Add(entityInfo->unk174, IntToF248(2)); sub_803E46C(0x46); } entityInfo->action.direction = direction & DIRECTION_MASK; @@ -187,10 +188,10 @@ void sub_80856E0(Entity * pokemon, s32 direction) for(counter = 0; counter < 5; counter++) { - entityInfo->unk174 -= 0x200; + entityInfo->unk174 = F248_Sub(entityInfo->unk174, IntToF248(2)); sub_803E46C(0x46); } - entityInfo->unk174 = 0; + entityInfo->unk174.raw = 0; // weird one that doesn't match with struct assignment sub_803E46C(0x46); } diff --git a/src/ground_script_1.c b/src/ground_script_1.c index cb24ea8af..f426bf597 100644 --- a/src/ground_script_1.c +++ b/src/ground_script_1.c @@ -1058,11 +1058,12 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0x71: case 0x77: case 0x7d: case 0x83: { +#define HYPOT FP24_8_Hypot((s24_8){scriptData->pos2.x - scriptData->pos1.x}, (s24_8){scriptData->pos2.y - scriptData->pos1.y}).raw / curCmd.argShort action->callbacks->getHitboxCenter(action->parentObject, &scriptData->pos1); scriptData->pos2.x = curCmd.arg1 << 8; scriptData->pos2.y = curCmd.arg2 << 8; if (curCmd.op == 0x7d || curCmd.op == 0x83) { - scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = HYPOT; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1074,7 +1075,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2.x = scriptData->pos1.x + (curCmd.arg1 << 8); scriptData->pos2.y = scriptData->pos1.y + (curCmd.arg2 << 8); if (curCmd.op == 0x7e || curCmd.op == 0x84) { - scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = HYPOT; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1097,7 +1098,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2.y = scriptData->pos1.y + ((OtherRandInt(curCmd.arg2 * 2 + 1) - curCmd.arg2) << 8); #endif if (curCmd.op == 0x7f || curCmd.op == 0x85) { - scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = HYPOT; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1109,7 +1110,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2 = scriptData->pos1; GroundLink_GetPos((s16)curCmd.arg1, &scriptData->pos2); if (curCmd.op == 0x80 || curCmd.op == 0x86) { - scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = HYPOT; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1123,7 +1124,7 @@ s32 ExecuteScriptCommand(Action *action) { scriptData->pos2.x = scriptData->pos2.x + ((OtherRandInt(cap) - curCmd.argShort) << 8); scriptData->pos2.y = scriptData->pos2.y + ((OtherRandInt(cap) - curCmd.argShort) << 8); if (curCmd.op == 0x81 || curCmd.op == 0x87) { - scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = HYPOT; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; @@ -1136,7 +1137,7 @@ s32 ExecuteScriptCommand(Action *action) { action->callbacks->getHitboxCenter(action->parentObject, &scriptData->pos1); sub_80A8FD8(ret, &scriptData->pos2); if (curCmd.op == 0x82 || curCmd.op == 0x88) { - scriptData->unk2A = FP24_8_Hypot(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; + scriptData->unk2A = HYPOT; if (scriptData->unk2A <= 0) scriptData->unk2A = 1; } else { scriptData->unk2A = curCmd.argShort; diff --git a/src/math.c b/src/math.c index 84c243b1b..a63c1cf94 100644 --- a/src/math.c +++ b/src/math.c @@ -6,8 +6,8 @@ static void F48_16_UDiv(s48_16 *, s48_16 *, s48_16 *); static void F48_16_UMul(s48_16 *, s48_16 *, s48_16 *); -static u24_8 u24_8_div(u24_8, u24_8); -static u24_8 u24_8_mul(u24_8, u24_8); +static s24_8 u24_8_div(s24_8, s24_8); +static s24_8 u24_8_mul(s24_8, s24_8); /** * This function computes a value modulo 3, using a lookup table for values less @@ -92,25 +92,25 @@ s24_8 s24_8_mul(s24_8 x, s24_8 y) bool8 sgn0; bool8 sgn1; - sgn0 = x < 0; - sgn1 = y < 0; + sgn0 = x.raw < 0; + sgn1 = y.raw < 0; - if (x == 0) - return 0; + if (x.raw == 0) + return (s24_8){0}; - if (y == 0) - return 0; + if (y.raw == 0) + return (s24_8){0}; if (sgn0) - x = -x; + x.raw = -x.raw; if (sgn1) - y = -y; + y.raw = -y.raw; ret = u24_8_mul(x, y); if (sgn0 != sgn1) - ret = -ret; + ret.raw = -ret.raw; return ret; } @@ -129,25 +129,25 @@ static s24_8 s24_8_div(s24_8 x, s24_8 y) bool8 sgn0; bool8 sgn1; - sgn0 = x < 0; - sgn1 = y < 0; + sgn0 = x.raw < 0; + sgn1 = y.raw < 0; - if (y == 0) - return INT32_MAX; + if (y.raw == 0) + return (s24_8){INT32_MAX}; - if (x == 0) - return 0; + if (x.raw == 0) + return (s24_8){0}; if (sgn0) - x = -x; + x.raw = -x.raw; if (sgn1) - y = -y; + y.raw = -y.raw; ret = u24_8_div(x, y); if (sgn0 != sgn1) - ret = -ret; + ret.raw = -ret.raw; return ret; } @@ -160,7 +160,7 @@ static s24_8 s24_8_div(s24_8 x, s24_8 y) * * @return The product `x*y` as an unsigned 24.8 fixed-point number. */ -static u24_8 u24_8_mul(u24_8 x, u24_8 y) +static s24_8 u24_8_mul(s24_8 x, s24_8 y) { // We need 64 bits for intermediate steps of the multiplication. u32 x_h, x_l; @@ -171,13 +171,13 @@ static u24_8 u24_8_mul(u24_8 x, u24_8 y) u32 high_bit_mask; u32 round_up; - if (x == 0 || y == 0) - return 0; + if (x.raw == 0 || y.raw == 0) + return (s24_8){0}; x_h = 0; - x_l = x; + x_l = x.raw; y_h = 0; - y_l = y; + y_l = y.raw; out_h = 0; out_l = 0; high_bit_mask = 0x80 << 24; // high bit of u32 @@ -215,7 +215,7 @@ static u24_8 u24_8_mul(u24_8 x, u24_8 y) ++out_l; } - return out_l; + return (s24_8){out_l}; } /** @@ -226,7 +226,7 @@ static u24_8 u24_8_mul(u24_8 x, u24_8 y) * * @return The quotient `x/y` as an unsigned 24.8 fixed-point number. */ -static u24_8 u24_8_div(u24_8 x, u24_8 y) +static s24_8 u24_8_div(s24_8 x, s24_8 y) { bool8 bVar1; u32 r9; @@ -240,15 +240,15 @@ static u24_8 u24_8_div(u24_8 x, u24_8 y) s32 sl; s32 temp; - if (y == 0) - return INT32_MAX; + if (y.raw == 0) + return (s24_8){INT32_MAX}; - if (x == 0) - return 0; + if (x.raw == 0) + return (s24_8){0}; - r7 = x >> 24; - r6 = x << 8; - sl = y; + r7 = (u32)x.raw >> 24; + r6 = x.raw << 8; + sl = y.raw; r9 = 0; r5 = 0; r4 = 0; @@ -286,19 +286,19 @@ static u24_8 u24_8_div(u24_8 x, u24_8 y) r9 |= r8; } - return r9; + return (s24_8){r9}; } -UNUSED s32 FP24_8_Pow(s32 x, s32 y) +UNUSED s24_8 FP24_8_Pow(s24_8 x, s32 y) { s32 uVar1; - s32 sVar1; + s24_8 sVar1; uVar1 = y; if (uVar1 < 0) uVar1 = -uVar1; - sVar1 = 0x100; + sVar1 = IntToF248(1); for (; uVar1 != 0; uVar1 >>= 1) { if (uVar1 & 1) @@ -310,37 +310,37 @@ UNUSED s32 FP24_8_Pow(s32 x, s32 y) if (y >= 0) return sVar1; - return s24_8_div(0x100, sVar1); + return s24_8_div(IntToF248(1), sVar1); } -s32 FP24_8_Hypot(s32 x, s32 y) +s24_8 FP24_8_Hypot(s24_8 x, s24_8 y) { - s32 r4; + s24_8 r4; s32 i; - s32 r5; - s32 r6; + s24_8 r5; + s24_8 r6; r5 = x; r6 = y; - if (r5 < 0) - r5 = -r5; + if (r5.raw < 0) + r5.raw = -r5.raw; - if (r6 < 0) - r6 = -r6; + if (r6.raw < 0) + r6.raw = -r6.raw; - if (r5 < r6) { + if (r5.raw < r6.raw) { r4 = r5; r5 = r6; r6 = r4; } - if (r6 != 0) { + if (r6.raw != 0) { for (i = 2; i >= 0; i--) { r4 = s24_8_div(r6, r5); r4 = s24_8_mul(r4, r4); - r4 = s24_8_div(r4, r4 + 0x400); - r5 += s24_8_mul(r5, r4) * 2; + r4 = s24_8_div(r4, F248_Add(r4, IntToF248(4))); + r5 = F248_Add(r5, F248_MulInt(s24_8_mul(r5, r4), 2)); r6 = s24_8_mul(r6, r4); } } @@ -376,21 +376,21 @@ u32 FP48_16_ToS32(s48_16 *a) return uVar1; } -UNUSED u32 FP48_16_ToF248(u32 *a) +UNUSED s24_8 FP48_16_ToF248(s48_16 *a) { u32 uVar1; - uVar1 = ((u8)a[0] << 24) | a[1] >> 8; - if (a[1] & 0x8000) + uVar1 = ((u8)a->hi << 24) | a->lo >> 8; + if (a->lo & 0x8000) uVar1++; - return uVar1; + return (s24_8){uVar1}; } -void FP48_16_FromF248(s48_16 *a, s32 b) +void FP48_16_FromF248(s48_16 *a, s24_8 b) { - a->lo = b << 8; - a->hi = b >> 24; + a->lo = b.raw << 8; + a->hi = b.raw >> 24; if (a->hi & 0x80) a->hi |= ~0x7F; diff --git a/src/move_actions.c b/src/move_actions.c index 0f8b6bd9c..1a2d20ecd 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -361,7 +361,7 @@ bool32 sub_8057824(Entity *pokemon, Entity *target, Move *move, s32 param_4) bool32 sub_805783C(Entity *pokemon, Entity *target, Move *move, s32 param_4) { - ChangeAttackMultiplierTarget(pokemon,target,gUnknown_8106A4C,0x80,TRUE); + ChangeAttackMultiplierTarget(pokemon,target,gUnknown_8106A4C,FloatToF248(0.5),TRUE); return TRUE; } @@ -551,7 +551,7 @@ bool8 SnoreMoveAction(Entity *pokemon, Entity *target, Move * move, u32 param_4) bool8 sub_8057C68(Entity *pokemon, Entity *target, Move *move, s32 param_4) { - ChangeDefenseMultiplierTarget(pokemon, target, gUnknown_8106A4C, 0x40, 1); + ChangeDefenseMultiplierTarget(pokemon, target, gUnknown_8106A4C, FloatToF248(0.25), 1); return TRUE; } @@ -680,7 +680,7 @@ bool8 sub_8057ED0(Entity *pokemon, Entity *target, Move *move, u32 param_4) flag = TRUE; if(sub_805727C(pokemon, target, gUnknown_80F4E04)) { - ChangeAttackMultiplierTarget(pokemon, target, gUnknown_8106A4C, 0x80, FALSE); + ChangeAttackMultiplierTarget(pokemon, target, gUnknown_8106A4C, FloatToF248(0.5), FALSE); } } return flag; @@ -692,8 +692,8 @@ bool8 sub_8057F24(Entity *pokemon, Entity *target, Move *move, s32 param_4) entityInfo = GetEntInfo(pokemon); entityInfo->HP = 1; - ChangeAttackMultiplierTarget(pokemon,target,gUnknown_8106A4C,0x40,TRUE); - ChangeAttackMultiplierTarget(pokemon,target,gUnknown_8106A50,0x40,TRUE); + ChangeAttackMultiplierTarget(pokemon,target,gUnknown_8106A4C,FloatToF248(0.25),TRUE); + ChangeAttackMultiplierTarget(pokemon,target,gUnknown_8106A50,FloatToF248(0.25),TRUE); entityInfo->unk154 = 1; return TRUE; } diff --git a/src/move_checks.c b/src/move_checks.c index 0e9855955..d955fc4aa 100644 --- a/src/move_checks.c +++ b/src/move_checks.c @@ -1,4 +1,5 @@ #include "global.h" +#include "math.h" #include "constants/status.h" #include "constants/type.h" #include "constants/weather.h" @@ -586,7 +587,7 @@ bool8 CanUseOnTargetWithStatusChecker(Entity *user, Entity *target, Move *move) } break; case MOVE_CHARM: - if (targetData->offensiveMultipliers[STAT_STAGE_ATK] < STAT_MULTIPLIER_THRESHOLD) + if (F248LessThanFloat(targetData->offensiveMultipliers[STAT_STAGE_ATK], STAT_MULTIPLIER_THRESHOLD)) { return FALSE; } @@ -628,7 +629,7 @@ bool8 CanUseOnTargetWithStatusChecker(Entity *user, Entity *target, Move *move) } break; case MOVE_SCREECH: - if (targetData->defensiveMultipliers[STAT_STAGE_DEF] < STAT_MULTIPLIER_THRESHOLD) + if (F248LessThanFloat(targetData->defensiveMultipliers[STAT_STAGE_DEF], STAT_MULTIPLIER_THRESHOLD)) { return FALSE; } @@ -652,8 +653,8 @@ bool8 CanUseOnTargetWithStatusChecker(Entity *user, Entity *target, Move *move) } break; case MOVE_MEMENTO: - if (targetData->offensiveMultipliers[STAT_STAGE_ATK] < STAT_MULTIPLIER_THRESHOLD && - targetData->offensiveMultipliers[STAT_STAGE_SP_ATK] < STAT_MULTIPLIER_THRESHOLD) + if (F248LessThanFloat(targetData->offensiveMultipliers[STAT_STAGE_ATK], STAT_MULTIPLIER_THRESHOLD) && + F248LessThanFloat(targetData->offensiveMultipliers[STAT_STAGE_SP_ATK], STAT_MULTIPLIER_THRESHOLD)) { return FALSE; } @@ -728,8 +729,8 @@ bool8 CanUseOnTargetWithStatusChecker(Entity *user, Entity *target, Move *move) if (targetData->offensiveStages[i] < DEFAULT_STAT_STAGE) break; if (targetData->defensiveStages[i] < DEFAULT_STAT_STAGE) break; if (targetData->hitChanceStages[i] < DEFAULT_STAT_STAGE || - targetData->offensiveMultipliers[i] < DEFAULT_STAT_MULTIPLIER || - targetData->defensiveMultipliers[i] < DEFAULT_STAT_MULTIPLIER) + F248LessThanInt(targetData->offensiveMultipliers[i], 1) || + F248LessThanInt(targetData->defensiveMultipliers[i], 1)) { break; } @@ -753,8 +754,8 @@ bool8 CanUseOnTargetWithStatusChecker(Entity *user, Entity *target, Move *move) if (userData->offensiveStages[i] < targetData->offensiveStages[i]) break; if (userData->defensiveStages[i] < targetData->defensiveStages[i] || userData->hitChanceStages[i] < targetData->hitChanceStages[i] || - userData->offensiveMultipliers[i] < targetData->offensiveMultipliers[i] || - userData->defensiveMultipliers[i] < targetData->defensiveMultipliers[i]) + userData->offensiveMultipliers[i].raw < targetData->offensiveMultipliers[i].raw || + userData->defensiveMultipliers[i].raw < targetData->defensiveMultipliers[i].raw) { break; } diff --git a/src/status.c b/src/status.c index 8215879cc..4690c7e3d 100644 --- a/src/status.c +++ b/src/status.c @@ -223,10 +223,10 @@ void UpdateFlashFireBoost(Entity * pokemon, Entity *target) } } -void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s32 param_4, bool8 displayMessage) +void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s24_8 param_4, bool8 displayMessage) { EntityInfo *entityInfo; - s32 oldMulti; + s24_8 oldMulti; if (!EntityExists(target)) { return; @@ -238,17 +238,17 @@ void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage else { strcpy(gFormatBuffer_Items[0],*gUnknown_80FC0B8); } - if ((param_4 < 0x100) && sub_8071728(pokemon,target,displayMessage)) { + if (F248LessThanInt(param_4, 1) && sub_8071728(pokemon,target,displayMessage)) { return; } - if ((HasHeldItem(target,ITEM_TWIST_BAND)) && (param_4 < 0x100)) { + if ((HasHeldItem(target,ITEM_TWIST_BAND)) && F248LessThanInt(param_4, 1)) { SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FD550); return; } - if (HasAbility(target, ABILITY_HYPER_CUTTER) && (statStage == STAT_STAGE_ATK) && (param_4 < 0x100)) { + if (HasAbility(target, ABILITY_HYPER_CUTTER) && (statStage == STAT_STAGE_ATK) && F248LessThanInt(param_4, 1)) { if (displayMessage) { SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FCA60); @@ -260,7 +260,7 @@ void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); oldMulti = entityInfo->offensiveMultipliers[statStage]; - if (param_4 < 0x100) { + if (F248LessThanInt(param_4, 1)) { sub_8041FD8(target,statStage); } else { @@ -269,16 +269,16 @@ void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage entityInfo->offensiveMultipliers[statStage] = s24_8_mul(entityInfo->offensiveMultipliers[statStage],param_4); - if (entityInfo->offensiveMultipliers[statStage] < 2) { - entityInfo->offensiveMultipliers[statStage] = 2; + if (F248LessThanFloat(entityInfo->offensiveMultipliers[statStage], 0.01)) { + entityInfo->offensiveMultipliers[statStage] = FloatToF248(0.01); } - if (0x63fd < entityInfo->offensiveMultipliers[statStage]) { - entityInfo->offensiveMultipliers[statStage] = 0x63fd; // 25597 + if (FloatLessThanF248(99.99, entityInfo->offensiveMultipliers[statStage])) { + entityInfo->offensiveMultipliers[statStage] = FloatToF248(99.99); } - if (oldMulti > entityInfo->offensiveMultipliers[statStage]) { + if (F248GreaterThan(oldMulti, entityInfo->offensiveMultipliers[statStage])) { TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC11C); } - else if (oldMulti < entityInfo->offensiveMultipliers[statStage]) { + else if (F248LessThan(oldMulti, entityInfo->offensiveMultipliers[statStage])) { TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC118); } else @@ -288,10 +288,10 @@ void ChangeAttackMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage EntityUpdateStatusSprites(target); } -void ChangeDefenseMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s32 param_4, bool8 displayMessage) +void ChangeDefenseMultiplierTarget(Entity *pokemon, Entity *target, u32 statStage, s24_8 param_4, bool8 displayMessage) { EntityInfo *entityInfo; - s32 oldMulti; + s24_8 oldMulti; if (!EntityExists(target)) { return; @@ -303,7 +303,7 @@ void ChangeDefenseMultiplierTarget(Entity *pokemon, Entity *target, u32 statStag else { strcpy(gFormatBuffer_Items[0],*gUnknown_80FC09C); } - if ((param_4 < 0x100) && sub_8071728(pokemon,target,displayMessage)) { + if (F248LessThanInt(param_4, 1) && sub_8071728(pokemon,target,displayMessage)) { return; } @@ -311,7 +311,7 @@ void ChangeDefenseMultiplierTarget(Entity *pokemon, Entity *target, u32 statStag SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); oldMulti = entityInfo->defensiveMultipliers[statStage]; - if (param_4 < 0x100) { + if (F248LessThanInt(param_4, 1)) { sub_804201C(target,statStage); } else { @@ -320,16 +320,16 @@ void ChangeDefenseMultiplierTarget(Entity *pokemon, Entity *target, u32 statStag entityInfo->defensiveMultipliers[statStage] = s24_8_mul(entityInfo->defensiveMultipliers[statStage],param_4); - if (entityInfo->defensiveMultipliers[statStage] < 2) { - entityInfo->defensiveMultipliers[statStage] = 2; + if (F248LessThanFloat(entityInfo->defensiveMultipliers[statStage], 0.01)) { + entityInfo->defensiveMultipliers[statStage] = FloatToF248(0.01); } - if (0x63fd < entityInfo->defensiveMultipliers[statStage]) { - entityInfo->defensiveMultipliers[statStage] = 0x63fd; // 25597 + if (FloatLessThanF248(99.99, entityInfo->defensiveMultipliers[statStage])) { + entityInfo->defensiveMultipliers[statStage] = FloatToF248(99.99); } - if (oldMulti > entityInfo->defensiveMultipliers[statStage]) { + if (F248GreaterThan(oldMulti, entityInfo->defensiveMultipliers[statStage])) { TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC114); } - else if (oldMulti < entityInfo->defensiveMultipliers[statStage]) { + else if (F248LessThan(oldMulti, entityInfo->defensiveMultipliers[statStage])) { TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC0FC); } else From f46866840cc4f9466795656c967742a37a5428c3 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Tue, 12 Nov 2024 08:55:32 +0100 Subject: [PATCH 06/12] Move CompactPos struct to common header --- include/ground_script.h | 16 +++++----------- include/structs/str_position.h | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/ground_script.h b/include/ground_script.h index 678a54c25..f9e66fd9d 100644 --- a/include/ground_script.h +++ b/include/ground_script.h @@ -135,14 +135,8 @@ typedef struct ScriptRef extern const ScriptRef gFunctionScriptTable[]; -struct CompactPos { - u8 xTiles; - u8 yTiles; - u8 xFlags; - u8 yFlags; -}; struct GroundLink { - struct CompactPos pos; + CompactPos pos; u8 width; u8 height; u8 ret; @@ -153,7 +147,7 @@ typedef struct GroundLivesData { u8 unk1; u8 width; u8 height; - struct CompactPos pos; + CompactPos pos; const ScriptCommand *scripts[4]; } GroundLivesData; typedef struct GroundObjectData { @@ -161,7 +155,7 @@ typedef struct GroundObjectData { u8 unk1; u8 width; u8 height; - struct CompactPos pos; + CompactPos pos; const ScriptCommand *scripts[4]; } GroundObjectData; typedef struct GroundEffectData { @@ -169,7 +163,7 @@ typedef struct GroundEffectData { u8 unk1; u8 width; u8 height; - struct CompactPos pos; + CompactPos pos; const ScriptCommand *script; } GroundEffectData; typedef struct GroundEventData { @@ -177,7 +171,7 @@ typedef struct GroundEventData { u8 unk1; u8 width; u8 height; - struct CompactPos pos; + CompactPos pos; const ScriptRef *script; } GroundEventData; diff --git a/include/structs/str_position.h b/include/structs/str_position.h index a376af4bf..f767b80c4 100644 --- a/include/structs/str_position.h +++ b/include/structs/str_position.h @@ -8,6 +8,10 @@ typedef struct Position /* 0x2 */ s16 y; } Position; +/** + * Precise position expressed in pixel units, as s24_8 fixpoint. + * This type has subpixel precision to 1/256th of a pixel. + */ // size: 0x8 typedef struct Position32 { @@ -15,4 +19,17 @@ typedef struct Position32 /* 0x4 */ s32 y; } Position32; +/** + * Currently only used in script data, for entities and GroundLink data. + * Position expressed in terms of *graphics* tiles, 8 pixels per unit. + * Flags allow expressing half-tile offsets and allow using a current/default coordinate. + */ +// size: 0x4 +typedef struct CompactPos { + u8 xTiles; + u8 yTiles; + u8 xFlags; + u8 yFlags; +} CompactPos; + #endif // GUARD_STR_POSITION_H From 8ba2124f1e7b986f6f2dc269a7b50b1db1a3af33 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Tue, 12 Nov 2024 16:08:43 +0100 Subject: [PATCH 07/12] Rename Positions --- include/code_800DAC0.h | 4 +- include/code_800F958.h | 2 +- include/code_803E724.h | 2 +- include/code_80450F8.h | 4 +- include/code_8069D4C.h | 2 +- include/code_807CD9C.h | 2 +- include/dungeon_ai_items.h | 2 +- include/dungeon_cutscenes.h | 6 +-- include/dungeon_map_access.h | 4 +- include/dungeon_message.h | 2 +- include/dungeon_movement.h | 10 ++-- include/dungeon_pokemon_sprites.h | 4 +- include/dungeon_range.h | 6 +-- include/dungeon_util.h | 6 +-- include/dungeon_util_1.h | 2 +- include/dungeon_visibility.h | 4 +- include/ground_script.h | 16 +++---- include/position_util.h | 4 +- include/sprite.h | 2 +- include/string_format.h | 2 +- include/structs/axdata.h | 10 ++-- include/structs/dungeon_entity.h | 26 +++++----- include/structs/map.h | 2 +- include/structs/menu.h | 6 +-- include/structs/str_dungeon.h | 18 +++---- include/structs/str_position.h | 10 ++-- include/tile_types.h | 2 +- include/trap.h | 14 +++--- src/code_800558C.c | 18 +++---- src/code_800F958.c | 10 ++-- src/code_803E46C.c | 2 +- src/code_803E724.c | 2 +- src/code_8041AD0.c | 12 ++--- src/code_804267C.c | 12 ++--- src/code_8042B34.c | 13 ++--- src/code_8044CC8.c | 6 +-- src/code_80450F8.c | 4 +- src/code_8045A00.c | 4 +- src/code_8048480.c | 2 +- src/code_805D8C8_1.c | 21 ++++---- src/code_8066D04.c | 4 +- src/code_8069D4C.c | 2 +- src/code_806CD90.c | 4 +- src/code_80718D8.c | 4 +- src/code_8072B78.c | 2 +- src/code_8073CF0.c | 14 +++--- src/code_8075708.c | 2 +- src/code_807CD9C.c | 21 ++++---- src/code_807E1A0.c | 6 +-- src/code_8085E98.c | 5 +- src/code_80861A8.c | 4 +- src/code_80869E4.c | 8 ++-- src/dungeon_ai_attack.c | 2 +- src/dungeon_ai_items.c | 10 ++-- src/dungeon_ai_leader.c | 8 ++-- src/dungeon_ai_movement.c | 6 +-- src/dungeon_ai_targeting.c | 2 +- src/dungeon_cutscenes.c | 46 +++++++++--------- src/dungeon_items.c | 2 +- src/dungeon_map_access.c | 8 ++-- src/dungeon_message.c | 5 +- src/dungeon_move.c | 32 ++++++------- src/dungeon_movement.c | 10 ++-- src/dungeon_range.c | 8 ++-- src/dungeon_serializer.c | 22 ++++----- src/dungeon_util.c | 4 +- src/dungeon_util_1.c | 2 +- src/dungeon_visibility.c | 4 +- src/ground_script_1.c | 79 ++++++++++++++++--------------- src/menu_input.c | 6 +-- src/move_actions.c | 24 +++++----- src/position_util.c | 4 +- src/sprite.c | 4 +- src/status_actions.c | 20 ++++---- src/string_format.c | 6 +-- src/tile_types.c | 12 ++--- src/trap.c | 23 ++++----- src/trap_1.c | 4 +- tmp/fixpoint.cocci | 17 ------- tmp/position.cocci | 17 +++++++ tmp/renames.sed | 26 ---------- 81 files changed, 377 insertions(+), 392 deletions(-) delete mode 100644 tmp/fixpoint.cocci create mode 100644 tmp/position.cocci delete mode 100644 tmp/renames.sed diff --git a/include/code_800DAC0.h b/include/code_800DAC0.h index 9ad99d82e..efe6a6844 100644 --- a/include/code_800DAC0.h +++ b/include/code_800DAC0.h @@ -25,7 +25,7 @@ bool8 sub_800E9A8(s32); void sub_800DAC0(u32); void sub_800DB7C(void); void sub_800DBBC(void); -void sub_800E90C(Position *); -void sub_800E8AC(s32 a0, void *a1, void *a2, s32 a3, void *a4); // a2 could be Position +void sub_800E90C(DungeonPos *); +void sub_800E8AC(s32 a0, void *a1, void *a2, s32 a3, void *a4); // a2 could be DungeonPos #endif // GUARD_CODE_800DAC0_H diff --git a/include/code_800F958.h b/include/code_800F958.h index 884e9a7f9..112b73916 100644 --- a/include/code_800F958.h +++ b/include/code_800F958.h @@ -3,6 +3,6 @@ #include "structs/str_position.h" -void AddPokemonDungeonSprite(s32 id, s16 species, Position *pos, u32); +void AddPokemonDungeonSprite(s32 id, s16 species, DungeonPos *pos, u32); #endif // GUARD_CODE_800F958_H \ No newline at end of file diff --git a/include/code_803E724.h b/include/code_803E724.h index a72345f17..026600408 100644 --- a/include/code_803E724.h +++ b/include/code_803E724.h @@ -3,6 +3,6 @@ #include "structs/str_position.h" -bool8 sub_803F428(Position *pos); +bool8 sub_803F428(DungeonPos *pos); #endif // GUARD_CODE_803E724_H \ No newline at end of file diff --git a/include/code_80450F8.h b/include/code_80450F8.h index 82374dd0c..f86f4a608 100644 --- a/include/code_80450F8.h +++ b/include/code_80450F8.h @@ -3,8 +3,8 @@ #include "structs/dungeon_entity.h" -Entity *sub_8045684(u8 trapID, Position *pos, u8 c); -Entity *sub_8045708(Position *pos); +Entity *sub_8045684(u8 trapID, DungeonPos *pos, u8 c); +Entity *sub_8045708(DungeonPos *pos); void sub_80457DC(Entity* ent); #endif // GUARD_CODE_80227B8_H \ No newline at end of file diff --git a/include/code_8069D4C.h b/include/code_8069D4C.h index 6e4ab6f9a..1a174e7e6 100644 --- a/include/code_8069D4C.h +++ b/include/code_8069D4C.h @@ -14,7 +14,7 @@ struct unkStruct_8069D4C_sub struct unkStruct_8069D4C { s16 id; - Position pos; + DungeonPos pos; s16 HP; struct unkStruct_8069D4C_sub offense; u16 level; diff --git a/include/code_807CD9C.h b/include/code_807CD9C.h index 0f3c8dafc..e61d18766 100644 --- a/include/code_807CD9C.h +++ b/include/code_807CD9C.h @@ -2,7 +2,7 @@ #define CODE_807CD9C_H void sub_807CD9C(Entity *pokemon, Entity *target, u32 direction); -void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, Position *pos); +void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos); void sub_807D3CC(Entity *param_1); #endif /* ifndef CODE_807CD9C_H */ diff --git a/include/dungeon_ai_items.h b/include/dungeon_ai_items.h index 05d909cef..960b33009 100644 --- a/include/dungeon_ai_items.h +++ b/include/dungeon_ai_items.h @@ -6,7 +6,7 @@ void AIDecideUseItem(Entity *pokemon); void GetPossibleAIThrownItemDirections(Entity *pokemon, s32 thrownAIFlag, Item *item, bool8 ignoreRollChance); -void GetPossibleAIArcItemTargets(Entity *pokemon, Item *item, Position potentialTargets[], bool8 ignoreRollChance); +void GetPossibleAIArcItemTargets(Entity *pokemon, Item *item, DungeonPos potentialTargets[], bool8 ignoreRollChance); void TargetThrownItem(Entity *pokemon, Entity *targetPokemon, Item *item, s32 targetingFlags, bool8 ignoreRollChance); #endif diff --git a/include/dungeon_cutscenes.h b/include/dungeon_cutscenes.h index 1e8c4240a..8a190c10c 100644 --- a/include/dungeon_cutscenes.h +++ b/include/dungeon_cutscenes.h @@ -114,9 +114,9 @@ void sub_808AC3C(void); void sub_808ACC0(void); void sub_808AD48(void); void sub_808ADCC(void); -void sub_808AE54(u8, u8, Position *pos); -void sub_808AEC8(u8, u8, Position *pos); -void sub_808AF3C(u8, u8, Position *pos); +void sub_808AE54(u8, u8, DungeonPos *pos); +void sub_808AEC8(u8, u8, DungeonPos *pos); +void sub_808AF3C(u8, u8, DungeonPos *pos); void sub_808AFB0(u8); void sub_808B030(u8); void sub_808B0B0(u8); diff --git a/include/dungeon_map_access.h b/include/dungeon_map_access.h index d95b12019..adee8dc5b 100644 --- a/include/dungeon_map_access.h +++ b/include/dungeon_map_access.h @@ -12,6 +12,6 @@ Tile *GetTile(s32 x, s32 y); Tile *GetTileSafe(s32 x, s32 y); void sub_8049ED4(void); -void sub_804AC20(Position *pos); +void sub_804AC20(DungeonPos *pos); -#endif // GUARD_DUNGEON_MAP_ACCESS_H \ No newline at end of file +#endif // GUARD_DUNGEON_MAP_ACCESS_H diff --git a/include/dungeon_message.h b/include/dungeon_message.h index 693673b27..f8122c2c7 100644 --- a/include/dungeon_message.h +++ b/include/dungeon_message.h @@ -28,7 +28,7 @@ void LogMessageByIdWithPopupCheckUser(Entity *pokemon, const u8 *str); void TryDisplayDungeonLoggableMessage2(Entity *pokemon, const u8 *str); void TryDisplayDungeonLoggableMessage3(Entity *attacker, Entity *target, const u8 *str); void TryDisplayDungeonLoggableMessage4(Entity *attacker, Entity *target, const u8 *str); -void TryDisplayDungeonLoggableMessage5(Entity *pokemon, Position *pos, const u8 *str); +void TryDisplayDungeonLoggableMessage5(Entity *pokemon, DungeonPos *pos, const u8 *str); // As opposed to the above - these always display the string and save it in the message log. False/True stand for an unknown argument. Not sure what the practical difference is between these. void DisplayDungeonLoggableMessage(Entity *pokemon, const u8 *str); diff --git a/include/dungeon_movement.h b/include/dungeon_movement.h index be363c333..1549f1aa6 100644 --- a/include/dungeon_movement.h +++ b/include/dungeon_movement.h @@ -8,12 +8,12 @@ extern u8 gWalkableTileToCrossableTerrain[8]; u8 GetCrossableTerrain(s16 species); u8 sub_807034C(s16 id, struct Tile *tile); -u8 sub_80703A0(Entity *pokemon, Position *pos); +u8 sub_80703A0(Entity *pokemon, DungeonPos *pos); bool8 CanCrossWalls(Entity *pokemon); -bool8 sub_807049C(Entity *pokemon, Position *pos); -bool8 sub_8070564(Entity *pokemon, Position *pos); -bool8 sub_80705F0(Entity *pokemon, Position *pos); -bool8 sub_80706A4(Entity *pokemon, Position *pos); +bool8 sub_807049C(Entity *pokemon, DungeonPos *pos); +bool8 sub_8070564(Entity *pokemon, DungeonPos *pos); +bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos); +bool8 sub_80706A4(Entity *pokemon, DungeonPos *pos); s32 CalcSpeedStage(Entity *pokemon); #endif diff --git a/include/dungeon_pokemon_sprites.h b/include/dungeon_pokemon_sprites.h index 781c8af1b..b013ba9ab 100644 --- a/include/dungeon_pokemon_sprites.h +++ b/include/dungeon_pokemon_sprites.h @@ -20,8 +20,8 @@ typedef struct DungeonPokemonSprite /* 0xC */ u32 status; /* 0x10 */ u8 visible; /* 0x11 */ u8 unk11; - /* 0x14 */ Position pos; - /* 0x18 */ Position statusOffsets[2]; + /* 0x14 */ DungeonPos pos; + /* 0x18 */ DungeonPos statusOffsets[2]; /* 0x20 */ u32 unk20; /* 0x24 */ u32 unk24; /* 0x28 */ DungeonPokemonStatusSprite statusSprites[2]; diff --git a/include/dungeon_range.h b/include/dungeon_range.h index 905163fb5..9659a29a2 100644 --- a/include/dungeon_range.h +++ b/include/dungeon_range.h @@ -3,8 +3,8 @@ #include "structs/str_position.h" -bool8 IsPositionActuallyInSight(Position *pos1, Position *pos2); -bool8 IsPositionInSight(Position *pos1, Position *pos2); -bool8 IsTargetTwoTilesAway(Position *pos1, Position *pos2); +bool8 IsPositionActuallyInSight(DungeonPos *pos1, DungeonPos *pos2); +bool8 IsPositionInSight(DungeonPos *pos1, DungeonPos *pos2); +bool8 IsTargetTwoTilesAway(DungeonPos *pos1, DungeonPos *pos2); #endif diff --git a/include/dungeon_util.h b/include/dungeon_util.h index e2b1d27e2..5ecd4b111 100644 --- a/include/dungeon_util.h +++ b/include/dungeon_util.h @@ -6,13 +6,13 @@ #include "structs/str_position.h" #include "structs/str_traps.h" -extern const Position gAdjacentTileOffsets[NUM_DIRECTIONS]; +extern const DungeonPos gAdjacentTileOffsets[NUM_DIRECTIONS]; bool8 EntityExists(Entity *pokemon); u32 GetEntityType(Entity *entity); u8 GetEntityRoom(Entity *entity); struct Tile *GetTileAtEntitySafe(Entity *entity); -void sub_804535C(Entity *entity, Position32 *pos); +void sub_804535C(Entity *entity, PixelPos *pos); void SetEntityPixelPos(Entity *entity, s32 x, s32 y); void IncreaseEntityPixelPos(Entity *entity, s32 x, s32 y); @@ -25,4 +25,4 @@ Item *GetItemData_1(Entity *entity); Trap *GetTrapData(Entity *entity); Trap* GetTrapData_1(Entity *entity); -#endif // GUARD_DUNGEON_UTIL_H \ No newline at end of file +#endif // GUARD_DUNGEON_UTIL_H diff --git a/include/dungeon_util_1.h b/include/dungeon_util_1.h index 943647813..1923354fc 100644 --- a/include/dungeon_util_1.h +++ b/include/dungeon_util_1.h @@ -22,7 +22,7 @@ void sub_80856E0(Entity * pokemon, s32 direction); void sub_8085764(void); void sub_8085860(s32 x, s32 y); void sub_8085890(s32 x, s32 y); -void ShiftCameraToPosition(Position32 *posStruct, s32 cameraSteps); +void ShiftCameraToPosition(PixelPos *posStruct, s32 cameraSteps); void SetFacingDirection(Entity *pokemon, s32 direction); void sub_8085930(s32 direction); void sub_80859F0(s32 direction); diff --git a/include/dungeon_visibility.h b/include/dungeon_visibility.h index 935735e6f..0485e2080 100644 --- a/include/dungeon_visibility.h +++ b/include/dungeon_visibility.h @@ -6,7 +6,7 @@ bool8 CanSeeTarget(Entity *entity, Entity *targetEntity); bool8 CanTargetEntity(Entity *entity, Entity *targetEntity); bool8 sub_8045A70(Entity *entity, Entity *targetEntity); -bool8 sub_8045AAC(Entity *entity, Position *pos); -bool8 CanTargetPosition(Entity *entity, Position *pos); +bool8 sub_8045AAC(Entity *entity, DungeonPos *pos); +bool8 CanTargetPosition(Entity *entity, DungeonPos *pos); #endif diff --git a/include/ground_script.h b/include/ground_script.h index f9e66fd9d..50fb4d18d 100644 --- a/include/ground_script.h +++ b/include/ground_script.h @@ -57,8 +57,8 @@ typedef struct ScriptData /* 0x2C */ u16 unk2C; // padding /* 0x30 */ s32 unk30; - /* 0x34 */ Position32 pos1; - /* 0x3C */ Position32 pos2; + /* 0x34 */ PixelPos pos1; + /* 0x3C */ PixelPos pos2; /* 0x44 */ u8 unk44[4]; /* 0x48 */ s32 unk48; /* 0x4C */ u8 unk4C; @@ -78,14 +78,14 @@ typedef struct CallbackData // padding // All callbacks take the parentObject as first parameter /* 0x04 */ s16 (*getIndex)(void*); // id related - /* 0x08 */ void (*getSize)(void*, Position32 *out); - /* 0x0C */ void (*getHitboxCenter)(void*, Position32 *out); + /* 0x08 */ void (*getSize)(void*, PixelPos *out); + /* 0x0C */ void (*getHitboxCenter)(void*, PixelPos *out); /* 0x10 */ void (*getPosHeightAndUnk)(void*, u32 *height, u32 *unk); /* 0x14 */ void (*getDirection)(void*, s8 *dir); /* 0x18 */ void (*getFlags)(void*, u32 *flags); - /* 0x1C */ void (*setHitboxPos)(void*, Position32 *posOrNull); - /* 0x20 */ void (*setPositionBounds)(void*, Position32 *from, Position32 *to); - /* 0x24 */ bool8 (*moveReal)(void*, Position32*); + /* 0x1C */ void (*setHitboxPos)(void*, PixelPos *posOrNull); + /* 0x20 */ void (*setPositionBounds)(void*, PixelPos *from, PixelPos *to); + /* 0x24 */ bool8 (*moveReal)(void*, PixelPos*); /* 0x28 */ void (*setPosHeight)(void*, u32 height); /* 0x2C */ void (*setDirection)(void*, s8 dir); // direction must be signed char! /* 0x30 */ void (*setEventIndex)(void*, u16); @@ -94,7 +94,7 @@ typedef struct CallbackData /* 0x3C */ void (*setFlags)(void*, u32 bits); /* 0x40 */ void (*clearFlags)(void*, u32 bits); /* 0x44 */ void (*func44_livesOnlySpriteRelated)(void*, u32); - /* 0x48 */ void (*moveRelative)(void*, Position32*); + /* 0x48 */ void (*moveRelative)(void*, PixelPos*); /* 0x4C */ bool8 (*func4C_spriteRelatedCheck)(void*); /* 0x50 */ bool8 (*func50_spriteRelated)(void*); } CallbackData; diff --git a/include/position_util.h b/include/position_util.h index 03d5f9e29..d38e161f1 100644 --- a/include/position_util.h +++ b/include/position_util.h @@ -3,7 +3,7 @@ #include "structs/str_position.h" -s32 GetDirectionTowardsPosition(Position *originPos, Position *targetPos); -s32 GetDistance(Position *pos1, Position *pos2); +s32 GetDirectionTowardsPosition(DungeonPos *originPos, DungeonPos *targetPos); +s32 GetDistance(DungeonPos *pos1, DungeonPos *pos2); #endif diff --git a/include/sprite.h b/include/sprite.h index 09197daf1..c5369d187 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -34,7 +34,7 @@ void BlinkSavingIcon(void); void CopySpritesToOam(void); void InitSprites(void); void ResetSprites(bool8); -void SetSavingIconCoords(Position *); +void SetSavingIconCoords(DungeonPos *); void sub_8004E8C(unkStruct_2039DB0 *); void sub_8005180(void); void sub_8005304(void); diff --git a/include/string_format.h b/include/string_format.h index 0dd5e875a..3a8f24c7b 100644 --- a/include/string_format.h +++ b/include/string_format.h @@ -33,7 +33,7 @@ struct MonPortraitMsg { OpenedFile *faceFile; struct PortraitGfx *faceData; - Position pos; + DungeonPos pos; u8 spriteId; // Which mon's sprite to use. For example Kecleon has multiple sprites depending on whether it's green or purple. bool8 flip; // Whether the mon's sprite is flipped. u8 unkE; diff --git a/include/structs/axdata.h b/include/structs/axdata.h index a08151b7b..4f7002be9 100644 --- a/include/structs/axdata.h +++ b/include/structs/axdata.h @@ -14,9 +14,9 @@ typedef struct UnkSpriteMem // size: 0x20 typedef struct axdata1 { - /* 0x0 */ Position pos; - /* 0x4 */ Position offset; - /* 0x8 */ Position shadow; + /* 0x0 */ DungeonPos pos; + /* 0x4 */ DungeonPos offset; + /* 0x8 */ DungeonPos shadow; u32 unkC; u32 unk10; /* 0x14 */ s16 vramTileOrMaybeAnimTimer; @@ -43,8 +43,8 @@ typedef struct ax_anim /* 0x0 */ u8 frames; /* 0x1 */ u8 unkFlags; /* 0x2 */ s16 poseId; - /* 0x4 */ Position offset; - /* 0x8 */ Position shadow; + /* 0x4 */ DungeonPos offset; + /* 0x8 */ DungeonPos shadow; } ax_anim; // size: 0x3C diff --git a/include/structs/dungeon_entity.h b/include/structs/dungeon_entity.h index 7bb65b928..c89a0b466 100644 --- a/include/structs/dungeon_entity.h +++ b/include/structs/dungeon_entity.h @@ -33,7 +33,7 @@ typedef struct unkStruct_8044CC8 { /* 0x0 */ u8 actionUseIndex; - /* 0x4 */ Position lastItemThrowPosition; + /* 0x4 */ DungeonPos lastItemThrowPosition; } unkStruct_8044CC8; // size: 0x18 @@ -45,7 +45,7 @@ typedef struct ActionContainer // Additional parameter alongside actionIndex. Used for things like indicating which move a Pokémon should use from its moveset. /* 0x4 */ unkStruct_8044CC8 unk4[2]; // Position of the target that the Pokémon wants throw an item at. - /* 0x14 */ Position itemTargetPosition; + /* 0x14 */ DungeonPos itemTargetPosition; } ActionContainer; // size: 0x4 @@ -72,7 +72,7 @@ typedef struct AITarget /* 0x4 */ u16 aiTargetSpawnGenID; /* 0x8 */ struct Entity *aiTarget; /* 0xC */ u32 unkC; - /* 0x10 */ Position aiTargetPos; + /* 0x10 */ DungeonPos aiTargetPos; } AITarget; // size: 0x4 @@ -179,11 +179,11 @@ typedef struct Muzzled // size: 0x1C typedef struct Unk_Entity_x184 { - /* 0x184 - 0x0 */ Position previousTargetMovePosition1; - /* 0x188 - 0x4 */ Position32 previousTargetMovePosition2; + /* 0x184 - 0x0 */ DungeonPos previousTargetMovePosition1; + /* 0x188 - 0x4 */ PixelPos previousTargetMovePosition2; /* 0x190 - 0xC */ s32 lastMoveDirection; // The last direction that the Pokémon moved in. // Number of tiles that the Pokémon moved last, multiplied by 0x100. - /* 0x194 - 0x10*/ Position32 lastMoveIncrement; + /* 0x194 - 0x10*/ PixelPos lastMoveIncrement; /* 0x19C - 0x18 */ s16 walkAnimFramesLeft; // Set when the Pokémon starts moving, and counts down until the Pokémon's walk animation stops. /* 0x19e - 0x1a */ u8 unk1A; } Unk_Entity_x184; @@ -241,7 +241,7 @@ typedef struct EntityInfo /* 0x5E */ u8 abilities[2]; /* 0x60 */ Item heldItem; /* 0x64 */ u8 unk64; - /* 0x68 */ Position prevPos[NUM_PREV_POS]; + /* 0x68 */ DungeonPos prevPos[NUM_PREV_POS]; /* 0x78 */ AITarget aiTarget; // Bitwise flags corresponding to selected IQ skills. /* 0x8C */ u8 IQSkillMenuFlags[NUM_PICKED_IQ_SKILLS]; // IQ skills selected in the IQ skills menu. @@ -336,8 +336,8 @@ typedef struct EntityInfo /* 0x167 */ u8 unk167; /* 0x168 */ u8 unk168; /* 0x169 */ u8 turnsSinceWarpScarfActivation; - /* 0x16C */ Position targetPos; - /* 0x170 */ Position pixelPos; + /* 0x16C */ DungeonPos targetPos; + /* 0x170 */ DungeonPos pixelPos; s24_8 unk174; u16 abilityEffectFlags; // See enum AbilityEffectFlags /* 0x17A */ u16 mimicMoveIDs[MAX_MON_MOVES]; // All moves that Mimic has copied (not sure on size...) @@ -356,12 +356,12 @@ typedef struct EntityInfo typedef struct Entity { /* 0x0 */ u32 type; - /* 0x4 */ Position pos; - /* 0x8 */ Position prevPos; + /* 0x4 */ DungeonPos pos; + /* 0x8 */ DungeonPos prevPos; // The center of the entity acccording to pixel-space coordinates, using the same origin as posWorld. // X = (posWorld * 24 + 16) * 256, while Y = (posWorld * 24 + 12) * 256. - /* 0xC */ Position32 pixelPos; - /* 0x14 */ Position32 prevPixelPos; + /* 0xC */ PixelPos pixelPos; + /* 0x14 */ PixelPos prevPixelPos; s32 unk1C; /* 0x20 */ bool8 isVisible; // Turned off when a Pokémon faints. u8 fill21; diff --git a/include/structs/map.h b/include/structs/map.h index cda59ded2..b2127b929 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -56,7 +56,7 @@ typedef struct RoomData u8 unk0; u8 unk1; // All coordinates are inclusive. - // These are not aligned properly to use the Position struct. + // These are not aligned properly to use the DungeonPos struct. /* 0x2 */ s16 bottomRightCornerX; /* 0x4 */ s16 bottomRightCornerY; /* 0x6 */ s16 topLeftCornerX; diff --git a/include/structs/menu.h b/include/structs/menu.h index 96391e592..3d64a5760 100644 --- a/include/structs/menu.h +++ b/include/structs/menu.h @@ -25,11 +25,11 @@ typedef struct MenuInputStruct s32 unk0; u16 unk4; s16 unk6; - Position unk8; // Maybe Position - s16 unkC; // Maybe Position + DungeonPos unk8; // Maybe DungeonPos + s16 unkC; // Maybe DungeonPos s16 unkE; u32 unk10; - Position unk14; // Maybe Position + DungeonPos unk14; // Maybe DungeonPos /* 0x18 */ s16 menuIndex; s16 unk1A; s16 unk1C; diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index b95093631..e6866cf7c 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -77,10 +77,10 @@ typedef struct DungeonMusicPlayer // Size unknown? typedef struct UnkDungeonGlobal_unk181E8_sub { - /* 0x181E8 */ Position cameraPos; // x0 - /* 0x181EC */ Position cameraPosMirror; // x4 - /* 0x181F0 */ Position cameraPixelPos; // x8 - /* 0x181F4 */ Position cameraPixelPosMirror; // xC + /* 0x181E8 */ DungeonPos cameraPos; // x0 + /* 0x181EC */ DungeonPos cameraPosMirror; // x4 + /* 0x181F0 */ DungeonPos cameraPixelPos; // x8 + /* 0x181F4 */ DungeonPos cameraPixelPosMirror; // xC /* 0x181F8 */ Entity *cameraTarget; // x10 u32 unk181FC; // x14 u32 unk18200; // x18 @@ -370,9 +370,9 @@ typedef struct Dungeon /* 0x3A14 */ s16 bossBattleIndex; /* 0x3A16 */ s16 unk3A16; /* 0x3A18 */ Tile tiles[DUNGEON_MAX_SIZE_Y][DUNGEON_MAX_SIZE_X]; - Position unkE218; - Position unkE21C; // stair location? - Position unkE220[8]; + DungeonPos unkE218; + DungeonPos unkE21C; // stair location? + DungeonPos unkE220[8]; unkDungeonE240 unkE240; unkDungeonE240 unkE250; unkDungeonE260 unkE260; @@ -384,7 +384,7 @@ typedef struct Dungeon u8 unk104C0; /* 0x104C4 */ RoomData roomData[MAX_ROOM_COUNT]; /* 0x10844 */ s16 naturalJunctionListCounts[MAX_ROOM_COUNT]; - /* 0x10884 */ Position naturalJunctionList[MAX_ROOM_COUNT][MAX_ROOM_COUNT]; // Arrays of room exits for each room. + /* 0x10884 */ DungeonPos naturalJunctionList[MAX_ROOM_COUNT][MAX_ROOM_COUNT]; // Arrays of room exits for each room. u16 unk11884[250][9]; u16 unk12A18[20][9]; u16 unk12B80[9]; @@ -398,7 +398,7 @@ typedef struct Dungeon u8 fill1356D[0x13570 - 0x1356D]; /* 0x13570 */ u8 unk13570; u8 fill13571[0x13574 - 0x13571]; - /* 0x13574 */ Position trapPos; + /* 0x13574 */ DungeonPos trapPos; /* 0x13578 */ u8 trapID; /* 0x13579 */ u8 unk13579; u8 fill1357A[0x1357C - 0x1357A]; diff --git a/include/structs/str_position.h b/include/structs/str_position.h index f767b80c4..e56ee1d18 100644 --- a/include/structs/str_position.h +++ b/include/structs/str_position.h @@ -2,26 +2,26 @@ #define GUARD_STR_POSITION_H // size: 0x4 -typedef struct Position +typedef struct DungeonPos { /* 0x0 */ s16 x; /* 0x2 */ s16 y; -} Position; +} DungeonPos; /** * Precise position expressed in pixel units, as s24_8 fixpoint. * This type has subpixel precision to 1/256th of a pixel. */ // size: 0x8 -typedef struct Position32 +typedef struct PixelPos { /* 0x0 */ s32 x; // TODO: convert to s24_8 across the codebase /* 0x4 */ s32 y; -} Position32; +} PixelPos; /** * Currently only used in script data, for entities and GroundLink data. - * Position expressed in terms of *graphics* tiles, 8 pixels per unit. + * DungeonPos expressed in terms of *graphics* tiles, 8 pixels per unit. * Flags allow expressing half-tile offsets and allow using a current/default coordinate. */ // size: 0x4 diff --git a/include/tile_types.h b/include/tile_types.h index 78ce34014..46f765829 100644 --- a/include/tile_types.h +++ b/include/tile_types.h @@ -9,7 +9,7 @@ extern const u8 gDungeonWaterType[76]; -void sub_804AE84(Position *pos); +void sub_804AE84(DungeonPos *pos); bool8 IsTileGround(Tile *tile); bool8 IsWaterTileset(); diff --git a/include/trap.h b/include/trap.h index ba9ba7fdb..e6a6ad899 100644 --- a/include/trap.h +++ b/include/trap.h @@ -5,17 +5,17 @@ #include "structs/map.h" #include "structs/str_position.h" -bool8 CanLayTrap(Position *pos); -bool8 LayTrap(Position *pos, u8 trapID, u8 param_3); +bool8 CanLayTrap(DungeonPos *pos); +bool8 LayTrap(DungeonPos *pos, u8 trapID, u8 param_3); bool8 sub_807FD84(Entity *entity); -bool8 sub_807FE04(Position *pos, char param_2); -bool8 sub_807FE44(Position *pos, char param_2); +bool8 sub_807FE04(DungeonPos *pos, char param_2); +bool8 sub_807FE44(DungeonPos *pos, char param_2); void GetTrapName(u8 *buffer, u8 trapIndex); -void sub_807FE9C(Entity *pokemon, Position *pos, int param_3, char param_4); +void sub_807FE9C(Entity *pokemon, DungeonPos *pos, int param_3, char param_4); void HandleMudTrap(Entity *pokemon, Entity *target); void HandleStickyTrap(Entity *pokemon, Entity *target); void HandleGrimyTrap(Entity *pokemon, Entity *target); -void HandleSummonTrap(Entity *pokemon, Position *pos); +void HandleSummonTrap(Entity *pokemon, DungeonPos *pos); void HandlePitfallTrap(Entity *pokemon,Entity *target,Tile *tile); void HandleWarpTrap(Entity *pokemon, Entity *target); void HandleSpinTrap(Entity *pokemon, Entity *target); @@ -30,7 +30,7 @@ void HandleWonderTile(Entity *pokemon, Entity *target); // code_807FCD4.s extern void HandleSealTrap(Entity *pokemon, Entity *target); extern void HandleWhirlwindTrap(Entity *entity, Entity *target); -extern void HandlePokemonTrap(Entity *pokemon, Position *pos); +extern void HandlePokemonTrap(Entity *pokemon, DungeonPos *pos); // trap_1.c void HandleTripTrap(Entity *pokemon, Entity *target); diff --git a/src/code_800558C.c b/src/code_800558C.c index 8c54dff9e..0788f765f 100644 --- a/src/code_800558C.c +++ b/src/code_800558C.c @@ -84,11 +84,11 @@ const RGB *sub_8005674(struct axMapSprite *a0, s32 vramIdx) return a0->pal; } -void sub_800569C(Position *a0, struct axObject *a1, u8 a2) +void sub_800569C(DungeonPos *a0, struct axObject *a1, u8 a2) { - Position *ptr; - Position *ptr2; - Position *ptr3; + DungeonPos *ptr; + DungeonPos *ptr2; + DungeonPos *ptr3; a0->x = 0; a0->y = 0; @@ -97,7 +97,7 @@ void sub_800569C(Position *a0, struct axObject *a1, u8 a2) return; if (a1->axdata.paletteData != NULL) { - ptr = &((Position*)a1->axdata.paletteData)[a1->axdata.sub1.poseId * 4]; + ptr = &((DungeonPos*)a1->axdata.paletteData)[a1->axdata.sub1.poseId * 4]; ptr2 = &ptr[a2]; if (*&ptr2->x == 99 && *&ptr2->y == 99) { a0->x = 99; @@ -115,16 +115,16 @@ void sub_800569C(Position *a0, struct axObject *a1, u8 a2) } } -void sub_8005700(Position *a0, struct axObject *a1) +void sub_8005700(DungeonPos *a0, struct axObject *a1) { s32 i; - Position *ptr; + DungeonPos *ptr; if (!(a1->axdata.flags >> 15)) return; if (a1->axdata.paletteData != NULL) { - ptr = &((Position*)a1->axdata.paletteData)[a1->axdata.sub1.poseId * 4]; + ptr = &((DungeonPos*)a1->axdata.paletteData)[a1->axdata.sub1.poseId * 4]; for (i = 0; i < 4; i++) { if (*&ptr[i].x == 99 && *&ptr[i].y == 99) { a0->x = 99; @@ -159,7 +159,7 @@ void sub_8005770(s32 param_1, const RGB *color, s32 brightness, const RGB *ramp) SetBGPaletteBufferColorRGB((param_1 + 0x10) * 0x10 + i, &color[i], brightness, ramp); } -// Maybe Position +// Maybe DungeonPos void nullsub_7(s16 *a0) {} diff --git a/src/code_800F958.c b/src/code_800F958.c index 1538ea514..c928442bc 100644 --- a/src/code_800F958.c +++ b/src/code_800F958.c @@ -6,13 +6,12 @@ extern DungeonPokemonSprite *NewDungeonPokemonSprite(void); extern DungeonPokemonSprite* GetDungeonPokemonSprite(s32 id); -extern Position gUnknown_80D3564; +extern DungeonPos gUnknown_80D3564; -void AddPokemonDungeonSprite(s32 id, s16 species, Position *pos, u32 r3) -{ +void AddPokemonDungeonSprite(s32 id, s16 species, DungeonPos *pos, u32 r3) { DungeonPokemonSprite *dSprite; DungeonPokemonSprite *newSprite; - Position newPos; + DungeonPos newPos; s32 species_s32; species_s32 = species; @@ -57,7 +56,8 @@ void DeletePokemonDungeonSprite(s32 id) MemoryClear8((u8 *)dSprite, sizeof(DungeonPokemonSprite)); } -void sub_800F958(s32 dungeonSpriteID, Position *pos, Position *statusOffsets, u32 a3) +void sub_800F958(s32 dungeonSpriteID, DungeonPos *pos, + DungeonPos *statusOffsets, u32 a3) { DungeonPokemonSprite *dSprite; diff --git a/src/code_803E46C.c b/src/code_803E46C.c index cf05240e0..6dc8deae5 100644 --- a/src/code_803E46C.c +++ b/src/code_803E46C.c @@ -38,7 +38,7 @@ void sub_800E90C(); void sub_8042E5C(); void sub_8040B60(); void sub_8040788(); -void sub_800F7D0(Position *); +void sub_800F7D0(DungeonPos *); void sub_803E874(s32, s32); void sub_803EAF0(s32, s32); diff --git a/src/code_803E724.c b/src/code_803E724.c index f94ef844f..475f05814 100644 --- a/src/code_803E724.c +++ b/src/code_803E724.c @@ -899,7 +899,7 @@ void sub_803F38C(void) nullsub_5(0xFF, &gFontPalette[palId].pal[15]); } -bool8 sub_803F428(Position *pos) +bool8 sub_803F428(DungeonPos *pos) { UnkDungeonGlobal_unk181E8_sub *strPtr = &gDungeon->unk181e8; Entity *cameraEntity = strPtr->cameraTarget; diff --git a/src/code_8041AD0.c b/src/code_8041AD0.c index 5788623d7..eecc28c28 100644 --- a/src/code_8041AD0.c +++ b/src/code_8041AD0.c @@ -51,18 +51,18 @@ extern void sub_800EE5C(u32); extern void sub_800EF64(void); u32 sub_8041764(unkStruct_80416E0 *param_1, bool8 param_2); -s32 sub_80416E0(Position32 *pos, u32 param_2, bool8 param_3); +s32 sub_80416E0(PixelPos *pos, u32 param_2, bool8 param_3); -s32 sub_80416A4(Position *pos_1, u32 param_2, bool8 param_3) +s32 sub_80416A4(DungeonPos *pos_1, u32 param_2, bool8 param_3) { - Position32 pos; + PixelPos pos; pos.x = pos_1->x * 0x1800 + 0xc00; pos.y = pos_1->y * 0x1800 + 0x1000; return sub_80416E0(&pos, param_2, param_3); } -s32 sub_80416E0(Position32 *pos, u32 param_2, bool8 param_3) +s32 sub_80416E0(PixelPos *pos, u32 param_2, bool8 param_3) { int counter; s32 ret; @@ -850,7 +850,7 @@ void sub_804218C(Entity *pokemon, Entity *target) sub_804151C(target, 0x2A, 1); } -void sub_804219C(Position32 *pos) +void sub_804219C(PixelPos *pos) { sub_80416E0(pos, 0x90, TRUE); } @@ -868,7 +868,7 @@ void sub_80421C0(Entity *pokemon, u16 r1) PlaySoundEffect(r1); } -void sub_80421EC(Position *pos, u16 r1) +void sub_80421EC(DungeonPos *pos, u16 r1) { if(sub_803F428(pos)) PlaySoundEffect(r1); diff --git a/src/code_804267C.c b/src/code_804267C.c index 2493588d0..36f0c9ef6 100644 --- a/src/code_804267C.c +++ b/src/code_804267C.c @@ -23,7 +23,7 @@ extern const u8 *gPtrFeralFoundItemMessage[]; extern void sub_8040238(void); extern void sub_804151C(Entity *pokemon, u32 r1, u8 r2); extern void sub_804178C(u32); -extern void sub_80416A4(Position *r0, u32 r1, bool8 r2); +extern void sub_80416A4(DungeonPos *r0, u32 r1, bool8 r2); extern void sub_80429A0(Entity *); extern void sub_8042B34(u32, u32, u32); extern bool8 sub_8042CC0(void); @@ -236,13 +236,13 @@ void sub_80429E8(Entity *r0) sub_804151C(r0, 0x11d, 1); } -void sub_80429FC(Position *r0) +void sub_80429FC(DungeonPos *r0) { sub_80416A4(r0, 0x19E, TRUE); sub_80421C0(NULL, 0xD4); } -void sub_8042A14(Position *r0) +void sub_8042A14(DungeonPos *r0) { sub_80416A4(r0, 0x36, TRUE); } @@ -252,7 +252,7 @@ void sub_8042A24(Entity *r0) sub_804151C(r0, 0x15, 1); } -void sub_8042A34(Position *r0) +void sub_8042A34(DungeonPos *r0) { sub_80416A4(r0, 0x13E, FALSE); } @@ -262,12 +262,12 @@ void sub_8042A44(Entity *r0) sub_804151C(r0, 0xDA << 1, 1); } -void sub_8042A54(Position *r0) +void sub_8042A54(DungeonPos *r0) { sub_80416A4(r0, 0x37, TRUE); } -void sub_8042A64(Position *r0) +void sub_8042A64(DungeonPos *r0) { sub_80416A4(r0, 0x29, TRUE); } diff --git a/src/code_8042B34.c b/src/code_8042B34.c index 609a30bab..234c0267a 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -41,7 +41,7 @@ extern void sub_800EE5C(s32); extern void sub_800EF64(void); extern void sub_800F15C(s32); -struct Sub_UnkStruct_203B414 // Maybe Position? +struct Sub_UnkStruct_203B414 // Maybe DungeonPos? { s16 a0; s16 a2; @@ -218,8 +218,9 @@ void sub_8042E98(void) } } -extern void sub_800569C(Position *, axdata *, u8); -extern void sub_800EB24(s32 param_1, Position *param_2, Position *param_3, s32 param_4, s32 param_5); +extern void sub_800569C(DungeonPos *, axdata *, u8); +extern void sub_800EB24(s32 param_1, DungeonPos *param_2, DungeonPos *param_3, + s32 param_4, s32 param_5); void sub_8042EC8(Entity *a0, s32 a1) { @@ -228,8 +229,8 @@ void sub_8042EC8(Entity *a0, s32 a1) for (i = 0; i < 3; i++) { struct unkStruct_Dungeon5C4_sub *strPtr = &gDungeon->unk5C4[i]; if (strPtr->unk0 >= 0 && strPtr->unkC == a0) { - Position sp8 = {a0->pixelPos.x / 256, a0->pixelPos.y / 256}; - Position sp4 = {0}; + DungeonPos sp8 = {a0->pixelPos.x / 256, a0->pixelPos.y / 256}; + DungeonPos sp4 = {0}; EntityInfo *entInfo = GetEntInfo(a0); if (strPtr->unk8 != -1) { @@ -244,7 +245,7 @@ void sub_8042EC8(Entity *a0, s32 a1) } extern u8 gUnknown_203B40C; -extern Position gUnknown_203B410; +extern DungeonPos gUnknown_203B410; extern u8 *gSerializedData_203B41C; struct Substruct_xxx_dungeon_8042F6C diff --git a/src/code_8044CC8.c b/src/code_8044CC8.c index c55f1638b..8d9ead4b3 100644 --- a/src/code_8044CC8.c +++ b/src/code_8044CC8.c @@ -36,8 +36,8 @@ extern u8 *gUnknown_80F91EC[]; extern u8 sub_8043D10(void); extern bool8 sub_8045888(Entity *); -void sub_80460F8(Position *, Item *, u32); -bool8 sub_80461C8(Position *, u32); +void sub_80460F8(DungeonPos *, Item *, u32); +bool8 sub_80461C8(DungeonPos *, u32); Item * sub_8044CC8(Entity *param_1, unkStruct_8044CC8 *param_2) { @@ -134,7 +134,7 @@ void sub_8044E24(Entity *entity,int index,u32 unused) { Item *itemPtr; EntityInfo *info; - Position *pos; + DungeonPos *pos; Item item; itemPtr = sub_8044D90(entity,index,unused); diff --git a/src/code_80450F8.c b/src/code_80450F8.c index 1bab6d720..526a34b5a 100644 --- a/src/code_80450F8.c +++ b/src/code_80450F8.c @@ -524,7 +524,7 @@ Entity *sub_804550C(s16 a) ); } -Entity *sub_8045684(u8 trapID, Position *pos, u8 c) +Entity *sub_8045684(u8 trapID, DungeonPos *pos, u8 c) { Entity *entity; s32 i; @@ -548,7 +548,7 @@ Entity *sub_8045684(u8 trapID, Position *pos, u8 c) return NULL; } -Entity *sub_8045708(Position *pos) +Entity *sub_8045708(DungeonPos *pos) { s32 i; Entity *ent; diff --git a/src/code_8045A00.c b/src/code_8045A00.c index d6ef76284..fd8662e4b 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -18,7 +18,7 @@ extern struct unkStruct_8090F58 gUnknown_80F6990; void sub_8045BF8(u8 *, Item *); extern u32 sub_803D73C(u32); -void sub_80460F8(Position *, Item *, u32); +void sub_80460F8(DungeonPos *, Item *, u32); void sub_8045ACC(void) { @@ -135,7 +135,7 @@ void sub_8045CB0(void) u32 uVar5; int xCounter; Item item; - Position pos; + DungeonPos pos; u32 flag; x = DungeonRandInt(DUNGEON_MAX_SIZE_X); diff --git a/src/code_8048480.c b/src/code_8048480.c index cf2989089..da8e833d2 100644 --- a/src/code_8048480.c +++ b/src/code_8048480.c @@ -154,7 +154,7 @@ void sub_80482FC(Entity *, Entity *, u32, u8); extern void sub_8071DA4(Entity *); extern void SetShopkeeperAggression(Entity *, Entity *); -extern void sub_80464C8(Entity *, Position *, Item *); +extern void sub_80464C8(Entity *, DungeonPos *, Item *); extern void sub_806A6E8(Entity *); extern void sub_8042390(Entity *, Item *); diff --git a/src/code_805D8C8_1.c b/src/code_805D8C8_1.c index b2dba0630..6e13f4d04 100644 --- a/src/code_805D8C8_1.c +++ b/src/code_805D8C8_1.c @@ -68,8 +68,9 @@ extern void sub_8083D30(void); extern void sub_8083D08(void); extern void sub_806A6E8(Entity *); extern bool8 sub_8047084(s32 itemFlag); -extern void sub_807FE9C(Entity *pokemon, Position *pos, int param_3, char param_4); -extern void sub_8045DB4(Position *, u32); +extern void sub_807FE9C(Entity *pokemon, DungeonPos *pos, int param_3, + char param_4); +extern void sub_8045DB4(DungeonPos *, u32); bool8 sub_807EF48(void); void sub_806A2BC(Entity *a0, u8 a1); bool8 sub_805E874(void); @@ -116,7 +117,7 @@ void sub_8063A70(ActionContainer *a0, bool8 a1); void sub_8063CF0(ActionContainer *a0, bool8 a1); void sub_8067768(UNUSED ActionContainer *a0); void ShowTacticsMenu(ActionContainer *a0); -void sub_804A728(Position *pos, s32 a1, u8 a2, u8 a3); +void sub_804A728(DungeonPos *pos, s32 a1, u8 a2, u8 a3); extern bool8 sub_8071A8C(Entity *pokemon); extern void sub_80643AC(Entity *pokemon); extern u8 sub_8062F90(Entity *, u32, u32, u32, u32); @@ -1520,13 +1521,13 @@ bool8 sub_805E874(void) bool8 sub_805EC2C(Entity *a0, s32 x, s32 y) { - Position pos = {.x = x, .y = y}; + DungeonPos pos = {.x = x, .y = y}; return sub_8070564(a0, &pos); } bool8 sub_805EC4C(Entity *a0, u8 a1) { - Position pos; + DungeonPos pos; Tile *tile; EntityInfo *tileMonsterInfo; Entity *tileMonster; @@ -2378,7 +2379,7 @@ bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0) s32 sub_8060D64(s16 *a0, bool8 a1, bool8 a2, bool8 a3, Entity *a4); -void sub_8060890(Position *a0); +void sub_8060890(DungeonPos *a0); bool8 sub_8060860(s32 a0); void sub_8060900(Entity *a0); s32 sub_8060800(UnkTextStruct2_sub2 *a0, s32 a1); @@ -2849,7 +2850,7 @@ bool8 sub_8060860(s32 a0) return TRUE; } -void sub_8060890(Position *a0) +void sub_8060890(DungeonPos *a0) { s32 var = sUnknown_202F248[gUnknown_202EE10.unk1E]; switch (var) @@ -3088,7 +3089,7 @@ void sub_8060D24(UNUSED ActionContainer *a0) sub_803EAF0(0, NULL); } -extern bool8 PosHasItem(Position *pos); +extern bool8 PosHasItem(DungeonPos *pos); s32 sub_8060D64(s16 *a0, bool8 a1, bool8 a2, bool8 a3, Entity *a4) { @@ -3281,7 +3282,7 @@ bool8 sub_8060E38(Entity *a0) return ret; } -bool32 sub_8069D18(Position *a0, Entity *a1); +bool32 sub_8069D18(DungeonPos *a0, Entity *a1); extern const u8 gTeamFormat[]; extern const u8 gHeartRedTiny[]; @@ -3302,7 +3303,7 @@ extern void sub_8070968(u8 *buffer, EntityInfo *entityInfo, s32 colorNum); void DrawFieldTeamMenu(struct UnkFieldTeamMenuStruct *a0, UnkTextStruct3 *a1, bool8 a2) { s32 r0; - Position pos; + DungeonPos pos; s32 i; s32 count = 0; diff --git a/src/code_8066D04.c b/src/code_8066D04.c index 916169ae5..5beb3e648 100644 --- a/src/code_8066D04.c +++ b/src/code_8066D04.c @@ -28,12 +28,12 @@ extern u8 *gUnknown_80F8E28[]; extern Item *sub_8044D90(Entity *, s32, u32); void sub_8045BF8(u8 *, Item *); -u8 sub_80460F8(Position *, Item *, u32); +u8 sub_80460F8(DungeonPos *, Item *, u32); extern void sub_807AB38(Entity *, u32); extern Entity * sub_8044DA4(Entity *param_1,int param_2); extern void sub_806A6E8(Entity *); extern void sub_8044DF0(Entity *, u32, u32); -extern void sub_8045DB4(Position *, u32); +extern void sub_8045DB4(DungeonPos *, u32); void HandlePickUpPlayerAction(Entity *entity) { diff --git a/src/code_8069D4C.c b/src/code_8069D4C.c index 08a1a25e5..48c5e9210 100644 --- a/src/code_8069D4C.c +++ b/src/code_8069D4C.c @@ -3,7 +3,7 @@ #include "dungeon_util.h" #include "code_8069D4C.h" -u32 sub_8069D18(Position *pos,Entity *entity) +u32 sub_8069D18(DungeonPos *pos,Entity *entity) { EntityInfo *info; diff --git a/src/code_806CD90.c b/src/code_806CD90.c index f93e90836..e16c9d267 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -284,7 +284,7 @@ extern void sub_806F63C(Entity *r0); extern void sub_8078084(Entity * pokemon); extern void sub_800DBBC(void); extern void sub_8045C28(Item *Item, u8 itemID, u32 param_3); -extern void sub_80464C8(Entity *, Position *, Item *); +extern void sub_80464C8(Entity *, DungeonPos *, Item *); extern bool8 DoEnemiesEvolveWhenKOed(u8 dungeon); extern bool8 sub_806FA5C(Entity *, Entity *, struct unkStruct_8069D4C *); extern void EntityUpdateStatusSprites(Entity *); @@ -817,7 +817,7 @@ static bool8 HandleDealingDamageInternal(Entity *attacker, Entity *target, struc } } if (i != MAX_TEAM_MEMBERS) { - Position monPos; // r4 + DungeonPos monPos; // r4 sub_8042148(target); diff --git a/src/code_80718D8.c b/src/code_80718D8.c index f2195c485..aed02349e 100644 --- a/src/code_80718D8.c +++ b/src/code_80718D8.c @@ -23,7 +23,7 @@ struct unkStruct_806B7F8 u32 unk4; u16 level; u8 fillA[2]; - struct Position pos; + DungeonPos pos; u8 unk10; }; @@ -65,7 +65,7 @@ extern void sub_8042920(struct Entity *r0); extern s16 sub_803D970(u32); extern s32 sub_803DA20(s32 param_1); extern bool8 sub_806AA0C(s32, u32); -extern bool8 sub_8083660(struct Position *param_1); +extern bool8 sub_8083660(DungeonPos *param_1); void GetPokemonLevelData(LevelData* a1, s32 _id, s32 level); // TODO: change to s32 void sub_8071B48(void) diff --git a/src/code_8072B78.c b/src/code_8072B78.c index d3b1eddb1..7a96283c3 100644 --- a/src/code_8072B78.c +++ b/src/code_8072B78.c @@ -23,7 +23,7 @@ struct unkStruct_806B7F8 u32 unk4; u16 level; u8 fillA[0xC - 0xA]; - struct Position pos; + DungeonPos pos; u8 unk10; }; diff --git a/src/code_8073CF0.c b/src/code_8073CF0.c index 5509a78b4..2d69cbaf7 100644 --- a/src/code_8073CF0.c +++ b/src/code_8073CF0.c @@ -41,11 +41,11 @@ extern void sub_8067110(Entity *); extern void sub_80671A0(Entity *); extern void sub_8073D14(Entity *); extern void sub_8045BF8(u8 *, Item *); -extern bool8 sub_80461C8(Position *, u32); +extern bool8 sub_80461C8(DungeonPos *, u32); extern void sub_805229C(void); extern void sub_807E8F0(Entity *); extern void sub_80444F4(Entity *pokemon); -extern void sub_807D148(Entity *pokemon, Entity *r1, u32 r2, Position *r3); +extern void sub_807D148(Entity *pokemon, Entity *r1, u32 r2, DungeonPos *r3); extern void sub_80420B8(Entity *pokemon); extern void sub_8041C4C(Entity *pokemon, u32 r1); extern void sub_805E804(void); @@ -108,7 +108,7 @@ extern const s16 gUnknown_80F4F36; extern s48_16 gUnknown_80F54F4[8]; extern const s32 gUnknown_80F60DC[]; -extern const Position gUnknown_80F4D44[]; +extern const DungeonPos gUnknown_80F4D44[]; bool8 UseAttack(Entity *a0); void sub_8075050(EntityInfo *info, Unk_Entity_x184 *strPtr); @@ -797,7 +797,7 @@ void TickStatusHeal(Entity *entity) } } -void sub_8074FB0(Entity *entity, s32 a1, Position *pos) +void sub_8074FB0(Entity *entity, s32 a1, DungeonPos *pos) { Unk_Entity_x184 *strPtr; EntityInfo *entityInfo = GetEntInfo(entity); @@ -910,7 +910,7 @@ bool8 UseAttack(Entity *a0) } } else { - Position32 pos; + PixelPos pos; monInfo->flags |= 0x2000; pos.x = (monInfo->unk184[0].previousTargetMovePosition2.x * 0x1800) + 0xC00; @@ -948,7 +948,7 @@ bool8 UseAttack(Entity *a0) monInfo->numMoveTiles = 0; } else { - Position32 pos; + PixelPos pos; pos.x = (monInfo->unk184[monInfo->notMoving].previousTargetMovePosition2.x * 0x1800) + 0xC00; pos.y = (monInfo->unk184[monInfo->notMoving].previousTargetMovePosition2.y * 0x1800) + 0x1000; @@ -977,7 +977,7 @@ bool8 UseAttack(Entity *a0) sub_807AA30(); for (j = 0; j < 2; j++) { for (loop = 0; loop < DUNGEON_MAX_POKEMON; loop++) { - Position monPosBefore; + DungeonPos monPosBefore; EntityInfo *monInfo; Entity *mon = gDungeon->activePokemon[loop]; diff --git a/src/code_8075708.c b/src/code_8075708.c index 934fdabc6..c89b02c49 100644 --- a/src/code_8075708.c +++ b/src/code_8075708.c @@ -22,7 +22,7 @@ extern void sub_8073D14(Entity *); void sub_8075680(void) { u32 direction; - Position *targetPos; + DungeonPos *targetPos; Entity *entity; EntityInfo *info; int index; diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 4288937c1..68b97d534 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -42,25 +42,25 @@ void sub_806A5B8(Entity *); u8 sub_8045888(Entity *); void sub_807EC28(u32); void sub_80694C0(Entity *, s32, s32, s32); -void sub_807D068(Entity *, Position *); +void sub_807D068(Entity *, DungeonPos *); u8 sub_8044B28(void); extern void sub_806F370(Entity *pokemon, Entity *target, u32, u32, u8 *, u8 moveType, s32, u32, u32, u32); void sub_80421AC(Entity * pokemon, Entity * target); void sub_807BB78(Entity *pokemon); extern void sub_803F580(u32); -bool8 sub_808384C(Position *, Position *); -u8 sub_8083660(Position *); +bool8 sub_808384C(DungeonPos *, DungeonPos *); +u8 sub_8083660(DungeonPos *); void sub_807CD9C(Entity *pokemon, Entity *target, u32 direction) { Tile *tile; int iVar8; bool8 flag; - Position sp_0x18; + DungeonPos sp_0x18; Move move; int sp_0x24; Entity *sp_0x28; - Position32 sp_0x2C; + PixelPos sp_0x2C; sp_0x24 = 10; if (IsCurrentFixedRoomBossFight()) { @@ -162,7 +162,7 @@ void sub_807CD9C(Entity *pokemon, Entity *target, u32 direction) } } -void sub_807D068(Entity *pokemon, Position *pos) +void sub_807D068(Entity *pokemon, DungeonPos *pos) { int pixelX; int posY; @@ -171,7 +171,7 @@ void sub_807D068(Entity *pokemon, Position *pos) int counter; int iVar8; s32 diff; - Position32 local_34; + PixelPos local_34; int incrementX; int incrementY; @@ -215,12 +215,13 @@ _0807D11E: sub_803E46C(0x1a); } -void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, Position *pos) +void sub_807D148(Entity *pokemon, Entity *target, u32 param_3, + DungeonPos *pos) { EntityInfo *info; u32 direction; - Position local_2c; - Position pos2; + DungeonPos local_2c; + DungeonPos pos2; bool8 flag; info = GetEntInfo(target); diff --git a/src/code_807E1A0.c b/src/code_807E1A0.c index a93575b0f..8aa35e672 100644 --- a/src/code_807E1A0.c +++ b/src/code_807E1A0.c @@ -19,7 +19,7 @@ extern void sub_805E804(void); void sub_806A2BC(Entity *pokemon, u8 param_2); extern u8 sub_8044B28(void); extern void sub_8068FE0(Entity *, u32, Entity *r2); -extern void nullsub_93(Position *); +extern void nullsub_93(DungeonPos *); extern void sub_806F370(Entity *pokemon, Entity *target, u32, u32, u8 *, u8 moveType, s32, u32, u32, u32); extern void sub_80694C0(Entity *, s32, s32, u32); extern void sub_807EC28(bool8); @@ -69,8 +69,8 @@ void sub_807E1A0(Entity *pokemon,Entity *target,u8 moveType,s16 param_4,s32 para void sub_807E254(Entity *pokemon,Entity *target) { - Position pokemonPos; - Position targetPos; + DungeonPos pokemonPos; + DungeonPos targetPos; if (HasAbility(pokemon, ABILITY_SUCTION_CUPS)) { diff --git a/src/code_8085E98.c b/src/code_8085E98.c index 197679864..08d309c63 100644 --- a/src/code_8085E98.c +++ b/src/code_8085E98.c @@ -14,7 +14,7 @@ extern const unkStruct_2039DB0 gUnknown_8107374; void sub_800EF64(void); void sub_800EE5C(s32); void sub_8085F44(s32); -void sub_800E90C(Position *); +void sub_800E90C(DungeonPos *); void sub_8088EE8(void); void sub_8088848(void); void sub_808A718(void); @@ -30,7 +30,8 @@ void sub_8085EB0(void) gDungeon->unk181e8.unk18215 = 1; } -u32 sub_8085EC8(s16 param_1,u32 param_2,u32 param_3,Position *param_4,bool32 param_5) +u32 sub_8085EC8(s16 param_1,u32 param_2,u32 param_3,DungeonPos *param_4, + bool32 param_5) { u32 uVar1; unkStruct_80416E0 local_40; diff --git a/src/code_80861A8.c b/src/code_80861A8.c index e53b058e0..e0d050755 100644 --- a/src/code_80861A8.c +++ b/src/code_80861A8.c @@ -21,7 +21,7 @@ void sub_800EE5C(s32); void sub_800EF64(); void sub_803E46C(s32); s32 sub_800E700(s32); -void sub_800569C(Position *, axdata *, u8); +void sub_800569C(DungeonPos *, axdata *, u8); void sub_8085F44(void); void sub_8052FB8(const u8 *); @@ -78,7 +78,7 @@ s32 sub_80861F8(s16 param_1,Entity *param_2,bool32 param_3) EntityInfo *info; s32 uVar2; s32 uStack_38; - Position pos; + DungeonPos pos; unkStruct_80416E0 stack; #ifdef NONMATCHING diff --git a/src/code_80869E4.c b/src/code_80869E4.c index b11838214..710c0db20 100644 --- a/src/code_80869E4.c +++ b/src/code_80869E4.c @@ -44,7 +44,7 @@ void SpriteShockEffect(Entity *entity) static void sub_80862DC(Entity *entity) { - Position32 pos; + PixelPos pos; pos.x = entity->pixelPos.x; pos.y = entity->pixelPos.y + 0x3800; @@ -55,7 +55,7 @@ static void sub_80862DC(Entity *entity) static void sub_8086310(Entity *entity) { - Position32 pos; + PixelPos pos; pos.x = entity->pixelPos.x; pos.y = entity->pixelPos.y + 0x9000; @@ -67,7 +67,7 @@ static void sub_8086310(Entity *entity) static void sub_8086348(Entity *entity) { - Position32 pos; + PixelPos pos; pos.x = entity->pixelPos.x + 0x7800; pos.y = entity->pixelPos.y - 0x2000; @@ -78,7 +78,7 @@ static void sub_8086348(Entity *entity) static void sub_8086384(Entity *entity) { - Position32 pos; + PixelPos pos; pos.x = entity->pixelPos.x + 0x7800; pos.y = entity->pixelPos.y; diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index d56aeb209..1d22cc2ba 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -61,7 +61,7 @@ extern bool8 TryUseChosenMove(struct Entity *, u32, u32, u32, u32, struct Move * extern void sub_8045BF8(u8 *, struct Item *); extern void sub_8044DF0(struct Entity *, u32, u32); extern void sub_8071DA4(struct Entity *); -extern void sub_804AC20(struct Position *); +extern void sub_804AC20(DungeonPos *); extern void sub_807EC28(bool8); extern void sub_806A5B8(struct Entity *entity); diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 948b357fc..09a5934f7 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -110,7 +110,7 @@ void AIDecideUseItem(Entity *pokemon) } else if (itemType == CATEGORY_THROWN_ARC) { - Position potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; + DungeonPos potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; GetPossibleAIArcItemTargets(pokemon, item, potentialTargetPositions, TRUE); if (gAIThrowItemActionChoiceCount == 0) { @@ -233,7 +233,7 @@ void AIDecideUseItem(Entity *pokemon) u8 itemType = GetItemCategory(item->id); if (itemType == CATEGORY_THROWN_ARC) { - Position potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; + DungeonPos potentialTargetPositions[NUM_POTENTIAL_ROCK_TARGETS]; GetPossibleAIArcItemTargets(pokemon, item, potentialTargetPositions, FALSE); if (gAIThrowItemActionChoiceCount != 0) { @@ -312,7 +312,9 @@ void GetPossibleAIThrownItemDirections(Entity *pokemon, s32 thrownAIFlag, Item * } } -void GetPossibleAIArcItemTargets(Entity *pokemon, Item *item, Position potentialTargets[], bool8 ignoreRollChance) +void GetPossibleAIArcItemTargets(Entity *pokemon, Item *item, + DungeonPos potentialTargets[], + bool8 ignoreRollChance) { s32 i; gAIThrowItemActionChoiceCount = 0; @@ -340,7 +342,7 @@ void GetPossibleAIArcItemTargets(Entity *pokemon, Item *item, Position potential } if (distance <= 10) { - Position *newPotentialTarget; + DungeonPos *newPotentialTarget; if (!ignoreRollChance) { u32 itemWeight = GetAIUseItemProbability(targetPokemon, item, ITEM_TARGET_OTHER); diff --git a/src/dungeon_ai_leader.c b/src/dungeon_ai_leader.c index 5717ea90c..5c1204ac1 100644 --- a/src/dungeon_ai_leader.c +++ b/src/dungeon_ai_leader.c @@ -50,7 +50,7 @@ void sub_8041888(u8 param_1); void sub_8085140(void); void sub_807360C(void); void sub_805EFB4(Entity *, u8); -void sub_8074FB0(Entity *, u8, Position *); +void sub_8074FB0(Entity *, u8, DungeonPos *); void HandlePlaceItemAction(Entity *); void HandlePickUpPlayerAction(Entity *); @@ -72,7 +72,7 @@ extern u8 sub_8044B28(void); extern u8 UseAttack(Entity *); void sub_806A1E8(Entity *pokemon); extern void sub_80694C0(Entity *, s32, s32, u32); -bool8 sub_804AE08(Position *pos); +bool8 sub_804AE08(DungeonPos *pos); void HandlePickUpAIAction(Entity *pokemon); void HandleThrowItemAIAction(Entity *pokemon); void HandleEatAIAction(Entity *pokemon); @@ -114,8 +114,8 @@ bool8 sub_8072CF4(Entity *entity) s32 index; EntityInfo *info; bool8 bVar14; - Position pos; - Position pos1; + DungeonPos pos; + DungeonPos pos1; sub_804178C(1); gUnknown_203B434 = 1; diff --git a/src/dungeon_ai_movement.c b/src/dungeon_ai_movement.c index ea641c4e9..e6e435246 100644 --- a/src/dungeon_ai_movement.c +++ b/src/dungeon_ai_movement.c @@ -556,7 +556,7 @@ bool8 AvoidEnemies(Entity *pokemon) struct Tile *tile = GetTile(pokemon->pos.x, pokemon->pos.y); if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) { - Position aiTargetPos; + DungeonPos aiTargetPos; s32 targetDir; aiTargetPos.x = pokemon->pos.x; aiTargetPos.y = pokemon->pos.y; @@ -593,7 +593,7 @@ bool8 AvoidEnemies(Entity *pokemon) // If there are any room exits that the Pokémon can head towards without moving // closer to the target, head towards the furthest eligible exit. s32 naturalJunctionListCounts; - Position *naturalJunctionList = gDungeon->naturalJunctionList[room]; + DungeonPos *naturalJunctionList = gDungeon->naturalJunctionList[room]; s32 furthestTargetExitIndex; s32 furthestTargetToExitDistance; s32 distanceX; @@ -735,7 +735,7 @@ bool8 Wander(Entity *pokemon) else { s32 naturalJunctionListCounts = gDungeon->naturalJunctionListCounts[room]; - Position *naturalJunctionList = gDungeon->naturalJunctionList[room]; + DungeonPos *naturalJunctionList = gDungeon->naturalJunctionList[room]; if (pokemonInfo->moveRandomly) { s32 targetFacingDir = DungeonRandInt(NUM_DIRECTIONS); diff --git a/src/dungeon_ai_targeting.c b/src/dungeon_ai_targeting.c index 163b12173..1088795b3 100644 --- a/src/dungeon_ai_targeting.c +++ b/src/dungeon_ai_targeting.c @@ -62,7 +62,7 @@ const u8 gTreatmentData[3][2][2][2] = { } }; -bool8 sub_8070F3C(Entity * pokemon, Position *pos, s32 direction) +bool8 sub_8070F3C(Entity * pokemon, DungeonPos *pos, s32 direction) { u8 terrain; struct Tile *tile; diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index a0437d50e..0a08d442f 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -387,16 +387,16 @@ extern void sub_8041888(u32); extern u32 sub_80861F8(u32, Entity *, u32); extern u8 sub_80860A8(u32); extern void sub_8052D44(s16 *, Entity *, Entity *); -extern void sub_80464C8(Entity *, Position *, Item *); +extern void sub_80464C8(Entity *, DungeonPos *, Item *); extern void SetDungeonBGColorRGB(u32, u32, u32, u32, u32); -extern u32 sub_8085EC8(u32, u32, u32, Position *, u32); +extern u32 sub_8085EC8(u32, u32, u32, DungeonPos *, u32); extern void sub_807EAA0(u32, u32); extern void sub_8072008(Entity *, Entity *, s16, u32, u32); extern void sub_8085374(void); extern void sub_8045C28(Item *, u8 , u8 *); -extern void sub_8046860(Entity *, Position *, Item *, u32); +extern void sub_8046860(Entity *, DungeonPos *, Item *, u32); extern u32 sub_803D73C(u32); -extern void sub_80460F8(Position *, Item *, u8); +extern void sub_80460F8(DungeonPos *, Item *, u8); extern u8 sub_8044B28(void); extern bool8 sub_8085B80(struct_8085B80 *); @@ -453,7 +453,7 @@ void MoltresScreenFlash2(s32 r0, s32 r1); void MoltresScreenFlash3(void); void MoltresScreenDarken(void); void EnableJirachiWishWarpTile(void); -void sub_808BB3C(Position *pos); +void sub_808BB3C(DungeonPos *pos); void sub_8087144(); void SkarmoryEntry(Entity *); @@ -561,8 +561,8 @@ void SkarmoryPreFightDialogue(void) Entity * diglettEntity; Entity * skarmoryEntity; - Position32 pos1; - Position32 pos2; + PixelPos pos1; + PixelPos pos2; leaderEntity = xxx_call_GetLeader(); // Player partnerEntity = GetPartnerEntity(); // Partner @@ -618,7 +618,7 @@ void SkarmoryReFightDialogue(void) { Entity * leaderEntity; Entity * skarmoryEntity; - Position32 pos; + PixelPos pos; leaderEntity = xxx_call_GetLeader(); skarmoryEntity = GetEntityFromMonsterBehavior(BEHAVIOR_SKARMORY); @@ -2123,7 +2123,7 @@ void MagmaCavernMidDialogue(void) Entity * groudonEntity; Entity * alakazamEntity; s16 IDStack [2]; - Position32 pos; + PixelPos pos; leaderEntity = xxx_call_GetLeader(); partnerEntity = GetPartnerEntity(); @@ -3314,7 +3314,7 @@ void HoOhPreFightDialogue(void) { Entity * leaderEntity; Entity * HoOhEntity; - Position32 local_14; + PixelPos local_14; leaderEntity = xxx_call_GetLeader(); HoOhEntity = GetEntityFromMonsterBehavior(BEHAVIOR_HO_OH); @@ -3353,7 +3353,7 @@ void HoOhReFightDialogue(void) { Entity * leaderEntity; Entity * HoOhEntity; - Position32 local_14; + PixelPos local_14; leaderEntity = xxx_call_GetLeader(); HoOhEntity = GetEntityFromMonsterBehavior(BEHAVIOR_HO_OH); @@ -3494,8 +3494,8 @@ void LatiosPreFightDialogue(void) { Entity * leaderEntity; Entity * LatiosEntity; - Position32 local_18; - Position local_19; + PixelPos local_18; + DungeonPos local_19; leaderEntity = xxx_call_GetLeader(); LatiosEntity = GetEntityFromMonsterBehavior(BEHAVIOR_LATIOS); @@ -3652,7 +3652,7 @@ void sub_808ADCC(void) } } -void sub_808AE54(u8 param_1,u8 param_2,Position *param_3) +void sub_808AE54(u8 param_1,u8 param_2,DungeonPos *param_3) { Entity * leaderEntity; s16 IDStack[2]; @@ -3675,7 +3675,7 @@ void sub_808AE54(u8 param_1,u8 param_2,Position *param_3) } -void sub_808AEC8(u8 param_1,u8 param_2,Position *param_3) +void sub_808AEC8(u8 param_1,u8 param_2,DungeonPos *param_3) { Entity * leaderEntity; s16 IDStack[2]; @@ -3697,7 +3697,7 @@ void sub_808AEC8(u8 param_1,u8 param_2,Position *param_3) } } -void sub_808AF3C(u8 param_1,u8 param_2,Position *param_3) +void sub_808AF3C(u8 param_1,u8 param_2,DungeonPos *param_3) { Entity * leaderEntity; s16 IDStack[2]; @@ -3813,7 +3813,7 @@ void sub_808B1CC(u8 itemID) { Entity *entity; Tile *tile; - Position pos; + DungeonPos pos; Item item; pos.x = gDungeon->unk644.unk40; @@ -3992,7 +3992,7 @@ void JirachiWish(void) { u8 friendArea; Entity *jirachiEntity; - Position *LeaderPos; + DungeonPos *LeaderPos; Entity *leaderEntity; s32 wishChoice; s32 counter; @@ -4001,9 +4001,9 @@ void JirachiWish(void) Item auStack152 [9]; Item itemStack [9]; Item strengthItems [9]; - Position pos1; - Position pos2; - Position pos3; + DungeonPos pos1; + DungeonPos pos2; + DungeonPos pos3; jirachiEntity = GetEntityFromMonsterBehavior(BEHAVIOR_JIRACHI); CopyMonsterNameToBuffer(gFormatBuffer_Monsters[2], MONSTER_JIRACHI); @@ -4220,14 +4220,14 @@ void JirachiWishGrantFlash(void) sub_8085EB0(); } -void sub_808BB3C(Position *pos1) +void sub_808BB3C(DungeonPos *pos1) { #ifndef NONMATCHING register s32 iVar1 asm("r0"); #else s32 iVar1; #endif - Position newPos; + DungeonPos newPos; iVar1 = pos1->x * 0x1800 + 0xc00; newPos.x = iVar1 / 256; diff --git a/src/dungeon_items.c b/src/dungeon_items.c index b2eb9ffb7..84d27fab5 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -20,7 +20,7 @@ extern u8 *gUnknown_8105360[]; extern u8 *gUnknown_81053A8[]; extern u8 *gUnknown_8105434[]; -extern void sub_80416E0(Position32 *r0, u32, bool8); +extern void sub_80416E0(PixelPos *r0, u32, bool8); extern void sub_80855E4(void *); extern void PlaySoundEffect(u32); extern void sub_804178C(u32); diff --git a/src/dungeon_map_access.c b/src/dungeon_map_access.c index 4c377963d..98561554d 100644 --- a/src/dungeon_map_access.c +++ b/src/dungeon_map_access.c @@ -763,9 +763,9 @@ void sub_804A49C(s32 a0, s32 a1) sub_80098F8(3); } -void sub_804A728(Position *pos, s32 a1, u8 a2, u8 a3) +void sub_804A728(DungeonPos *pos, s32 a1, u8 a2, u8 a3) { - Position spArray[6]; + DungeonPos spArray[6]; u16 *src; s32 k; Entity *leader; @@ -774,7 +774,7 @@ void sub_804A728(Position *pos, s32 a1, u8 a2, u8 a3) s32 r5; s32 r10; s32 r9; - Position var_48; + DungeonPos var_48; s32 var_38, var_34; s32 x, x2, y; Dungeon *dungeon = gDungeon; @@ -983,7 +983,7 @@ void sub_804AAD4(void) gDungeon->unk104C0 = maxRooms + 1; } -void sub_804AC20(Position *pos) +void sub_804AC20(DungeonPos *pos) { s32 y; struct Tile *tile2; diff --git a/src/dungeon_message.c b/src/dungeon_message.c index 40f574d6f..610caeb7f 100644 --- a/src/dungeon_message.c +++ b/src/dungeon_message.c @@ -167,7 +167,8 @@ void TryDisplayDungeonLoggableMessage4(Entity *attacker, Entity *target, const u } } -void TryDisplayDungeonLoggableMessage5(Entity *pokemon, Position *pos, const u8 *str) +void TryDisplayDungeonLoggableMessage5(Entity *pokemon, DungeonPos *pos, + const u8 *str) { u8 flag; flag = sub_8045888(pokemon) ? TRUE : FALSE; @@ -416,7 +417,7 @@ void DisplayDungeonLoggableMessage(Entity *pokemon, const u8 *str) struct Struct_sub_808CDB0 { - Position pos; + DungeonPos pos; bool8 flip; }; diff --git a/src/dungeon_move.c b/src/dungeon_move.c index f82b768ed..d474afabd 100644 --- a/src/dungeon_move.c +++ b/src/dungeon_move.c @@ -55,14 +55,14 @@ extern void sub_80428A0(Entity *r0); extern bool8 sub_8040BB0(Entity *entity, Move *move, bool8); extern void sub_8040DA0(Entity *entity, Move *move); extern u16 sub_80412E0(u16 moveId, u8 weather, u8 a2); -extern void sub_800569C(Position *, axdata *, u8); +extern void sub_800569C(DungeonPos *, axdata *, u8); extern u8 GetBodySize(s16 index); extern void sub_800EF10(u16 r0); extern s32 sub_800E710(s16 a0, u16 a1); -extern void sub_800E3AC(s32 a0, Position *pos, s32 a2); -extern void sub_8041168(Entity *entity, Entity *entity2, Move *,Position *); +extern void sub_800E3AC(s32 a0, DungeonPos *pos, s32 a2); +extern void sub_8041168(Entity *entity, Entity *entity2, Move *,DungeonPos *); extern Entity *sub_80696A8(Entity *a0); -extern Entity *GetMonsterAtPos(Position *pos); +extern Entity *GetMonsterAtPos(DungeonPos *pos); extern Entity *sub_80696FC(Entity *); extern Entity *sub_806977C(Entity *); extern void sub_806F2BC(Entity *attacker, Entity *target, u8 moveType, s32 a2, struct DamageStruct *dmgStruct); @@ -2265,13 +2265,13 @@ struct UnkStruct_sub_800E308_1 { s16 unk0; s16 unk2; - Position unk4; - Position unk8; + DungeonPos unk4; + DungeonPos unk8; s32 unkC; s32 unk10; }; -// Maybe Position? Maybe not, sub_800E308 is called only by sub_8056564, so :shrug: +// Maybe DungeonPos? Maybe not, sub_800E308 is called only by sub_8056564, so :shrug: struct UnkStruct_sub_800E308_2 { s16 u0; @@ -2281,7 +2281,7 @@ struct UnkStruct_sub_800E308_2 extern s32 sub_800E308(struct UnkStruct_sub_800E308_1 *, struct UnkStruct_sub_800E308_2 *); #ifdef NONMATCHING // https://decomp.me/scratch/fTUsI -s32 sub_8056564(Entity *entity, Position *pos, Move *move, s32 r4) +s32 sub_8056564(Entity *entity, DungeonPos *pos, Move *move, s32 r4) { struct UnkStruct_sub_800E308_1 unkSp1; struct UnkStruct_sub_800E308_2 unkSp2; @@ -2291,7 +2291,7 @@ s32 sub_8056564(Entity *entity, Position *pos, Move *move, s32 r4) unkStruct_80BDBC4 *unkStruct = sub_800ECB8(sub_80412E0(move->id, GetApparentWeather(entity), 1)); s32 unk6 = unkStruct->unk6; // This part with unkPos doesn't match - Position32 unkPos = {pos->x * 0x1800, pos->y * 0x1800}; + PixelPos unkPos = {pos->x * 0x1800, pos->y * 0x1800}; unkPos.x += 0x1000; unkPos.y += 0xC00; @@ -2311,7 +2311,7 @@ s32 sub_8056564(Entity *entity, Position *pos, Move *move, s32 r4) someRetVal); } else { - unkSp1.unk8 = (Position) {0}; + unkSp1.unk8 = (DungeonPos) {0}; } unkSp1.unk0 = sub_80412E0(move->id, GetApparentWeather(entity), 1); unkSp1.unk2 = entInfo->apparentID; @@ -2327,7 +2327,7 @@ s32 sub_8056564(Entity *entity, Position *pos, Move *move, s32 r4) return -1; } #else -NAKED s32 sub_8056564(Entity *entity, Position *pos, Move *move, s32 r4) +NAKED s32 sub_8056564(Entity *entity, DungeonPos *pos, Move *move, s32 r4) { asm_unified("push {r4-r7,lr}\n" " mov r7, r9\n" @@ -2541,8 +2541,8 @@ static const s32 gUnknown_81069D4[NUM_DIRECTIONS] = // This function looks important, but what does it do? void sub_80566F8(Entity *attacker, Move *move, s32 a2, bool8 a3, s32 itemId, s32 isLinkedMove) { - Position var_68; - Position var_64; + DungeonPos var_68; + DungeonPos var_64; Entity *targetsArray[2]; // Only 2 hmm s32 var_4C, var_48; s32 i, j; @@ -2621,7 +2621,7 @@ void sub_80566F8(Entity *attacker, Move *move, s32 a2, bool8 a3, s32 itemId, s32 for (i = 0; i < a2; i++) { - Position var_68Before; + DungeonPos var_68Before; Tile *tile; if (var_68.x < 0 || var_68.y < 0 || var_68.x > 55 || var_68.y > 31) @@ -2631,7 +2631,7 @@ void sub_80566F8(Entity *attacker, Move *move, s32 a2, bool8 a3, s32 itemId, s32 var_68.x += var_4C; var_68.y += var_48; if (sub_803F428(&var_68) && !gDungeon->unk181e8.blinded) { - Position32 pos32; + PixelPos pos32; pos32.x = (var_68Before.x * 0x1800) + 0xC00; pos32.y = (var_68Before.y * 0x1800) + 0x1000; var_28 = var_30 * (var_4C << 8); @@ -2828,7 +2828,7 @@ static void SetTargetsForMove(Entity **targetsArray, Entity *attacker, Move *mov } for (i = 0; i < to; i++, direction++) { Entity *targetEntity; - Position unkPositon; + DungeonPos unkPositon; direction &= DIRECTION_MASK; unkPositon.x = attacker->pos.x + gAdjacentTileOffsets[direction].x ; diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c index c53e8b06e..70442bfbe 100644 --- a/src/dungeon_movement.c +++ b/src/dungeon_movement.c @@ -66,7 +66,7 @@ u8 sub_807034C(s16 id, struct Tile *tile) return TRUE; } -u8 sub_80703A0(Entity *pokemon, Position *pos) +u8 sub_80703A0(Entity *pokemon, DungeonPos *pos) { struct Tile *tile; u8 crossableTerrain; @@ -128,7 +128,7 @@ bool8 CanCrossWalls(Entity *pokemon) return FALSE; } -bool8 sub_807049C(Entity *pokemon, Position *pos) +bool8 sub_807049C(Entity *pokemon, DungeonPos *pos) { s32 crossableTerrain; struct Tile *tile; @@ -170,7 +170,7 @@ bool8 sub_807049C(Entity *pokemon, Position *pos) return TRUE; } -bool8 sub_8070564(Entity *pokemon, Position *pos) +bool8 sub_8070564(Entity *pokemon, DungeonPos *pos) { u8 crossableTerrain; struct Tile *tile; @@ -216,7 +216,7 @@ bool8 sub_8070564(Entity *pokemon, Position *pos) return TRUE; } -bool8 sub_80705F0(Entity *pokemon, Position *pos) +bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos) { s32 crossableTerrain; struct Tile *tile; @@ -256,7 +256,7 @@ bool8 sub_80705F0(Entity *pokemon, Position *pos) return TRUE; } -bool8 sub_80706A4(Entity *pokemon, Position *pos) +bool8 sub_80706A4(Entity *pokemon, DungeonPos *pos) { s32 crossableTerrain; struct Tile *tile; diff --git a/src/dungeon_range.c b/src/dungeon_range.c index 6cd4a3941..f06338f4a 100644 --- a/src/dungeon_range.c +++ b/src/dungeon_range.c @@ -5,7 +5,7 @@ #include "dungeon_map_access.h" #include "structs/map.h" -bool8 IsPositionActuallyInSight(Position *pos1, Position *pos2) +bool8 IsPositionActuallyInSight(DungeonPos *pos1, DungeonPos *pos2) { u8 pos1Room; u8 visibility = gDungeon->unk181e8.visibilityRange; @@ -47,7 +47,7 @@ bool8 IsPositionActuallyInSight(Position *pos1, Position *pos2) } } -bool8 IsPositionInSight(Position *pos1, Position *pos2) +bool8 IsPositionInSight(DungeonPos *pos1, DungeonPos *pos2) { struct Tile *tile; u8 pos1Room; @@ -97,7 +97,7 @@ returnFalse: return TRUE; } -void sub_80833E8(Position *param_1, s32 *param_2) +void sub_80833E8(DungeonPos *param_1, s32 *param_2) { struct Tile *tile; struct RoomData *mapRoom; @@ -125,7 +125,7 @@ void sub_80833E8(Position *param_1, s32 *param_2) } } -bool8 IsTargetTwoTilesAway(Position *pos1, Position *pos2) +bool8 IsTargetTwoTilesAway(DungeonPos *pos1, DungeonPos *pos2) { s32 i; struct Tile *tile; diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index 5b0a886f2..2e290f492 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -14,7 +14,7 @@ extern u8 gUnknown_202EE70[MAX_TEAM_BODY_SIZE]; extern u8 gUnknown_202EE76[DUNGEON_MAX_WILD_POKEMON_BODY_SIZE]; -extern Position gUnknown_203B410; +extern DungeonPos gUnknown_203B410; extern Entity *gLeaderPointer; // 203B450 #include "data/dungeon_serializer.h" @@ -66,7 +66,7 @@ static s32 ReadSpeedStage(DataSerializer *seri); static u8 ReadTactic(DataSerializer *seri); static u8 ReadDecoyAITracker(DataSerializer *seri); static void ReadTile(DataSerializer *seri, Tile *dst); -static void ReadTilePos(DataSerializer *seri, Position *dst); +static void ReadTilePos(DataSerializer *seri, DungeonPos *dst); static void ReadInvisibleClassStatus(DataSerializer *seri, InvisibleClassStatus *dst); static u8 ReadType(DataSerializer *seri); static u16 ReadU16(DataSerializer *seri); @@ -112,7 +112,7 @@ static void WriteSureShotClassStatus(DataSerializer *seri, SureShotClassStatus* static void WriteMuzzled(DataSerializer *seri, Muzzled *src); static void WriteBurnClassStatus(DataSerializer *seri, BurnClassStatus *src); static void WriteReflectClassStatus(DataSerializer *seri, ReflectClassStatus *src); -static void WriteTilePos(DataSerializer *seri, Position *src); +static void WriteTilePos(DataSerializer *seri, DungeonPos *src); static void WriteS16(DataSerializer *seri, s16 value); static void WriteSleepClassStatus(DataSerializer *seri, SleepClassStatus* src); static void WriteSpeedCounters(DataSerializer *seri, u8 *src, u32 numCounters); @@ -134,7 +134,7 @@ static Entity* sub_8082A08(s16 id, s16 apparentID, s32 index); // These externs are from other files extern u8 GetBodySize(s16 index); -extern void sub_80460F8(Position *, Item *, u32); +extern void sub_80460F8(DungeonPos *, Item *, u32); void SaveDungeonState(u8 *buffer, u32 bufLen) { @@ -868,7 +868,7 @@ static void ReadDungeonItems(DataSerializer *seri) { s32 i; Item item; - Position pos; + DungeonPos pos; ReadBlame(seri, sMisakiSan); @@ -894,7 +894,7 @@ static void ReadDungeonTraps(DataSerializer *seri) s32 counter; Tile *tile; Entity *entity; - Position pos; + DungeonPos pos; u8 isVisible; u8 unk1; u8 trapID; @@ -952,7 +952,7 @@ static void ReadMonster(DataSerializer *seri, bool8 isTeamMember, s32 index) s32 i; EntityInfo *monEntInfo; EntityInfo entInfo = {0}; - Position monPos; + DungeonPos monPos; bool8 shouldSpawnMon; u32 monIsVisible; u32 spawnGenID; @@ -1245,7 +1245,7 @@ void sub_8082B40(void) EntityInfo *info; Entity *entity; s32 i; - Position pos; + DungeonPos pos; for (i = 0; i < DUNGEON_MAX_POKEMON; i++) { entity = gDungeon->activePokemon[i]; @@ -1627,7 +1627,7 @@ static void WriteBool8(DataSerializer *seri, bool8 value) WriteBytes(seri, &local_8, 1); } -static void WriteTilePos(DataSerializer *seri, Position *src) +static void WriteTilePos(DataSerializer *seri, DungeonPos *src) { WriteBytes(seri, &src->x, 1); WriteBytes(seri, &src->y, 1); @@ -1708,7 +1708,7 @@ static bool8 ReadBool8(DataSerializer *seri) return local_8 != 0; } -static void ReadTilePos(DataSerializer *seri, Position *dst) +static void ReadTilePos(DataSerializer *seri, DungeonPos *dst) { dst->x = 0; dst->y = 0; @@ -1739,4 +1739,4 @@ static void ReadDungeonUnkE260(DataSerializer *seri, unkDungeonE260 *dst) static void ReadSpeedCounters(DataSerializer *seri, u8 *dst, u32 numCounters) { ReadBytes(seri, dst, numCounters); -} \ No newline at end of file +} diff --git a/src/dungeon_util.c b/src/dungeon_util.c index eebc9cbdb..096b35346 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -15,7 +15,7 @@ void sub_806C51C(Entity *entity); extern void sub_80462AC(Entity * ,u32, u32, u32, u32); extern void sub_807FA9C(); -const Position gAdjacentTileOffsets[] = { +const DungeonPos gAdjacentTileOffsets[] = { {0, 1}, {1, 1}, {1, 0}, @@ -177,7 +177,7 @@ void sub_804522C(void) { } } -void sub_804535C(Entity *entity, Position32 *pos) +void sub_804535C(Entity *entity, PixelPos *pos) { if (pos != NULL) { diff --git a/src/dungeon_util_1.c b/src/dungeon_util_1.c index d863debc7..70b4ee48a 100644 --- a/src/dungeon_util_1.c +++ b/src/dungeon_util_1.c @@ -248,7 +248,7 @@ void sub_8085890(s32 x, s32 y) sub_803F878(x, y); } -void ShiftCameraToPosition(Position32 *posStruct, s32 cameraSteps) +void ShiftCameraToPosition(PixelPos *posStruct, s32 cameraSteps) { s32 XPos; s32 YPos; diff --git a/src/dungeon_visibility.c b/src/dungeon_visibility.c index f2c862684..9697ba396 100644 --- a/src/dungeon_visibility.c +++ b/src/dungeon_visibility.c @@ -69,12 +69,12 @@ bool8 sub_8045A70(Entity *entity, Entity *targetEntity) return FALSE; } -bool8 sub_8045AAC(Entity *entity, Position *pos) +bool8 sub_8045AAC(Entity *entity, DungeonPos *pos) { return IsPositionActuallyInSight(&entity->pos, pos); } -bool8 CanTargetPosition(Entity *entity, Position *pos) +bool8 CanTargetPosition(Entity *entity, DungeonPos *pos) { return IsPositionInSight(&entity->pos, pos); } diff --git a/src/ground_script_1.c b/src/ground_script_1.c index f426bf597..aa340e4f9 100644 --- a/src/ground_script_1.c +++ b/src/ground_script_1.c @@ -52,7 +52,7 @@ void FatalError(void* loc, char* fmt, ...) __attribute__((noreturn)); char sub_8002984(s32, u8); u32 VecDirection8Radial(); u32 SizedDeltaDirection4(); -u8 SizedDeltaDirection8(Position32*, Position32*, Position32*, Position32*); +u8 SizedDeltaDirection8(PixelPos*, PixelPos*, PixelPos*, PixelPos*); bool8 sub_8021700(s32); bool8 sub_802FCF0(void); @@ -93,13 +93,13 @@ s32 HasItemInInventory(u8); u32 sub_809CC90(); void sub_809D0BC(void); void sub_809D124(s32, s32, s32); -void sub_809D158(s32, Position32*); +void sub_809D158(s32, PixelPos*); void sub_809D170(s32, s32); -void sub_809D190(s32, Position32*, s32); +void sub_809D190(s32, PixelPos*, s32); void sub_809D1A8(s32, s32, s32); -void sub_809D1CC(s32, Position32*, s32); +void sub_809D1CC(s32, PixelPos*, s32); void sub_809D1E4(s32, s32, s32); -void sub_809D208(s32, Position32*, s32); +void sub_809D208(s32, PixelPos*, s32); void sub_809D220(s32, s32, s32); u32 sub_809D52C(); bool8 GroundCancelAllEntities(void); @@ -111,14 +111,14 @@ void sub_80A8BD8(s16, s32*); u32 sub_80A8C2C(); u32 sub_80A8C98(); char *sub_80A8D54(s16); -s16 sub_80A8FD8(s32, Position32*); -s16 sub_80A8F9C(s32, Position32*); +s16 sub_80A8FD8(s32, PixelPos*); +s16 sub_80A8F9C(s32, PixelPos*); u32 sub_80A9050(); u32 sub_80A9090(); -s16 sub_80AC448(s16, Position32*); -s32 sub_80AC49C(s16, Position32*); -s16 sub_80AD360(s16, Position32*); -s16 sub_80AD3B4(s16, Position32*); +s16 sub_80AC448(s16, PixelPos*); +s32 sub_80AC49C(s16, PixelPos*); +s16 sub_80AD360(s16, PixelPos*); +s16 sub_80AD3B4(s16, PixelPos*); u32 GroundLink_GetPos(); u32 GroundLink_GetArea(); void DeleteGroundEvents(void); @@ -139,7 +139,7 @@ extern struct { const char *unk0; s32 unk4; } gChoices[9]; extern char gUnknown_2039D98[12]; extern int gNumChoices; -extern Position32 gUnknown_81164DC; +extern PixelPos gUnknown_81164DC; extern char gUnknown_81165D4[]; extern char gUnknown_81165F4[]; extern char gUnknown_811660C[]; @@ -404,7 +404,7 @@ s32 ExecuteScriptCommand(Action *action) { case 0x19: { s8 unk[4]; GroundObjectData *obj; - Position32 pos; + PixelPos pos; s16 res; s32 group; s32 sector; @@ -431,7 +431,7 @@ s32 ExecuteScriptCommand(Action *action) { case 0x1a: { s8 unk; GroundEffectData *eff; - Position32 pos; + PixelPos pos; s16 res; s32 group; s32 sector; @@ -541,10 +541,10 @@ s32 ExecuteScriptCommand(Action *action) { case 0x21: { s32 ret; s32 unk; - Position32 pos1; - Position32 pos2; - Position32 pos3; - Position32 pos4; + PixelPos pos1; + PixelPos pos2; + PixelPos pos3; + PixelPos pos4; s32 tmp; ret = (s16)sub_80A7AE8((s16)curCmd.arg1); if (ret >= 0) { @@ -864,7 +864,7 @@ s32 ExecuteScriptCommand(Action *action) { } case 0x50: { Action *ptr; - Position32 pos; + PixelPos pos; s8 c; { Action *tmp = (Action*)sub_809D52C(action->unkC.arr); @@ -880,9 +880,9 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0x51: { - Position32 posIn; - Position32 posOut1; - Position32 posOut2; + PixelPos posIn; + PixelPos posOut1; + PixelPos posOut2; action->callbacks->getHitboxCenter(action->parentObject, &posIn); GroundLink_GetArea(curCmd.argShort, &posOut1, &posOut2, &posIn); action->callbacks->setPositionBounds(action->parentObject, &posOut1, &posOut2); @@ -920,7 +920,7 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0x58: { - Position32 unk; + PixelPos unk; unk.x = curCmd.arg1 << 8; unk.y = curCmd.arg2 << 8; action->callbacks->moveReal(action->parentObject, &unk); @@ -928,7 +928,7 @@ s32 ExecuteScriptCommand(Action *action) { return 2; } case 0x59: { - Position32 unk; + PixelPos unk; unk.x = curCmd.argShort << 8; unk.y = curCmd.arg1 << 8; action->callbacks->moveRelative(action->parentObject, &unk); @@ -939,12 +939,13 @@ s32 ExecuteScriptCommand(Action *action) { u32 unk[2]; unk[0] = OtherRandInt(curCmd.argShort) << 8; unk[1] = OtherRandInt(curCmd.arg1) << 8; - action->callbacks->moveRelative(action->parentObject, (Position32*)unk); + action->callbacks->moveRelative(action->parentObject, + (PixelPos*)unk); scriptData->unk2A = (u8)curCmd.argByte; return 2; } case 0x5b: { - Position32 unk; + PixelPos unk; action->callbacks->getHitboxCenter(action->parentObject, &unk); GroundLink_GetPos((s16)curCmd.arg1, &unk); action->callbacks->moveReal(action->parentObject, &unk); // landing end of unwanted tailmerge @@ -952,7 +953,7 @@ s32 ExecuteScriptCommand(Action *action) { return 2; } case 0x5c: { - Position32 pos, pos1, pos2; + PixelPos pos, pos1, pos2; action->callbacks->getHitboxCenter(action->parentObject, &pos); GroundLink_GetArea((s16)curCmd.arg1, &pos1, &pos2, &pos); pos.x = pos1.x + OtherRandInt(pos2.x - pos1.x); @@ -962,7 +963,7 @@ s32 ExecuteScriptCommand(Action *action) { return 2; } case 0x5d: { - Position32 unk; + PixelPos unk; s16 res = sub_80A7AE8((s16)curCmd.arg1); if (res >= 0) { sub_80A8FD8(res, &unk); @@ -973,7 +974,7 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0x5e: { - Position32 pos; + PixelPos pos; s32 height; s32 dir; pos.x = GetScriptVarArrayValue(NULL, POSITION_X, (u16)curCmd.arg1); @@ -992,7 +993,7 @@ s32 ExecuteScriptCommand(Action *action) { return 2; } case 0x5f: { - Position32 pos; + PixelPos pos; u32 height; u32 wat; s8 dir; @@ -1018,7 +1019,7 @@ s32 ExecuteScriptCommand(Action *action) { return 2; } case 0x62: case 0x6a: { - Position32 pos; + PixelPos pos; action->callbacks->getHitboxCenter(action->parentObject, &pos); scriptData->pos2.x = pos.x + (curCmd.arg1 << 8); scriptData->pos2.y = pos.y + (curCmd.arg2 << 8); @@ -1196,7 +1197,7 @@ s32 ExecuteScriptCommand(Action *action) { case 0x8e: case 0x8f: case 0x90: { bool8 flag = FALSE; s8 dir; - Position32 pos1, pos2, pos3, pos4; + PixelPos pos1, pos2, pos3, pos4; switch (curCmd.op) { case 0x8e: { s32 val = (s16)sub_80A7AE8((s16)curCmd.arg1); @@ -1282,7 +1283,7 @@ s32 ExecuteScriptCommand(Action *action) { } case 0x99: { s32 id = action->callbacks->getIndex(action->parentObject); - Position32 unk; + PixelPos unk; switch(action->unk8[0]) { case 1: sub_80A8FD8(id, &unk); @@ -1321,7 +1322,7 @@ s32 ExecuteScriptCommand(Action *action) { } case 0x9c: { s32 id = action->callbacks->getIndex(action->parentObject); - Position32 unk; + PixelPos unk; switch(action->unk8[0]) { case 1: sub_80A8FD8(id, &unk); @@ -1360,7 +1361,7 @@ s32 ExecuteScriptCommand(Action *action) { } case 0x9f: { s32 id = action->callbacks->getIndex(action->parentObject); - Position32 unk; + PixelPos unk; switch(action->unk8[0]) { case 1: sub_80A8FD8(id, &unk); @@ -1399,7 +1400,7 @@ s32 ExecuteScriptCommand(Action *action) { } case 0xa2: { s32 id = action->callbacks->getIndex(action->parentObject); - Position32 unk; + PixelPos unk; switch(action->unk8[0]) { case 1: sub_80A8FD8(id, &unk); @@ -1571,7 +1572,7 @@ s32 ExecuteScriptCommand(Action *action) { } case 0xc0 ... 0xcb: { s32 val; - Position32 pos, pos2, pos3; + PixelPos pos, pos2, pos3; switch (curCmd.op) { case 0xc0: { val = GetScriptVarValue(scriptData->localVars.buf, curCmd.argShort); @@ -1625,7 +1626,7 @@ s32 ExecuteScriptCommand(Action *action) { case 0xc8: { s16 tmp = (s16)sub_80A7AE8((s16)curCmd.arg1); if (tmp >= 0) { - Position32 pos1, pos2, pos3, pos4; + PixelPos pos1, pos2, pos3, pos4; action->callbacks->getHitboxCenter(action->parentObject, &pos1); action->callbacks->getSize(action->parentObject, &pos2); sub_80A8FD8(tmp, &pos3); @@ -1642,7 +1643,7 @@ s32 ExecuteScriptCommand(Action *action) { case 0xc9: { s16 tmp = (s16)sub_80A7AE8((s16)curCmd.arg1); if (tmp >= 0) { - Position32 pos1, pos2, pos3; + PixelPos pos1, pos2, pos3; action->callbacks->getHitboxCenter(action->parentObject, &pos1); action->callbacks->getSize(action->parentObject, &pos2); sub_80A8FD8(tmp, &pos3); diff --git a/src/menu_input.c b/src/menu_input.c index 40e1245ab..e2a867cc5 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -66,7 +66,7 @@ const s32 gUnknown_80D4830[9] = { extern s16 sub_8009614(u32, u32); static void sub_8013134(MenuInputStruct *, u32, u32); -static void sub_801332C(Position *a0); +static void sub_801332C(DungeonPos *a0); static void sub_8013470(MenuInputStruct *); static bool8 sub_8013DD0(unkStructFor8013AA0 *); @@ -716,8 +716,8 @@ void nullsub_34(MenuInputStructSub *a0, s32 a1) { } -// Maybe Position -static void sub_801332C(Position *a0) +// Maybe DungeonPos +static void sub_801332C(DungeonPos *a0) { SpriteOAM sp = {}; SpriteOAM* ptr; diff --git a/src/move_actions.c b/src/move_actions.c index 1a2d20ecd..3226a0a5e 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -183,17 +183,18 @@ void sub_8075900(Entity *pokemon, u8 r1); extern u8 sub_8044B28(void); extern void sub_807EC28(bool8); extern void sub_806F370(Entity *r0, Entity *r1, u32, u32, u8 *, u8, s32, u32, u32, u32); -extern void sub_804652C(Entity *, Entity *, Item *, u32, Position *); +extern void sub_804652C(Entity *, Entity *, Item *, u32, DungeonPos *); extern void CalcDamage(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); extern void sub_8045C28(Item *, u8 , u8); -static void sub_805A7D4(Entity *, Entity *, Item *, Position *); +static void sub_805A7D4(Entity *, Entity *, Item *, DungeonPos *); extern void MudWaterSportEffect(u32); extern void CalcDamage(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); extern void sub_806A6E8(Entity *); extern void sub_806ABAC(Entity *, Entity *); extern u8 sub_806F4A4(Entity *, u32); -extern void sub_807DF38(Entity *pokemon, Entity *target, Position *pos, u32, u8 moveType, s16); +extern void sub_807DF38(Entity *pokemon, Entity *target, DungeonPos *pos, u32, + u8 moveType, s16); extern void nullsub_92(Entity *); extern u32 sub_8055864(Entity *pokemon, Entity *target, Move *param_3, s32 param_4, s32 param_5); extern u8 sub_807EAA0(u32, u32); @@ -2459,7 +2460,7 @@ bool8 sub_805A464(Entity *pokemon, Entity *target, Move *move, u32 param_4) { bool32 flag; Item item; - Position pos; + DungeonPos pos; flag = FALSE; if (HandleDamagingMove(pokemon, target, move, 0x100, param_4) != 0) { @@ -2592,7 +2593,7 @@ bool8 KnockOffMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_ EntityInfo *entityInfo; EntityInfo *targetEntityInfo; Item heldItem; - Position pos; + DungeonPos pos; entityInfo = GetEntInfo(pokemon); targetEntityInfo = GetEntInfo(target); @@ -2632,7 +2633,8 @@ bool8 KnockOffMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_ } } -static void sub_805A7D4(Entity * pokemon, Entity * target, Item *item, Position *pos) +static void sub_805A7D4(Entity * pokemon, Entity * target, Item *item, + DungeonPos *pos) { Entity stackEntity; @@ -2655,10 +2657,10 @@ bool8 sub_805A85C(Entity * pokemon, Entity * target, Move *move, u32 param_4) int x; int y; int counter; - Position *r9; - Position pos1; + DungeonPos *r9; + DungeonPos pos1; Move stackMove; - Position32 pos2; + PixelPos pos2; struct Tile *tile; Entity *entity; s32 temp; @@ -2735,9 +2737,9 @@ _0805A9FE: _0805AA5E: if (EntityExists(target)) { #ifndef NOMATCHING - register Position *pos asm("r1"); + register DungeonPos *pos asm("r1"); #else - Position *pos; + DungeonPos *pos; #endif sub_804535C(target, NULL); pos = r9; diff --git a/src/position_util.c b/src/position_util.c index 07fe6fb7e..159fc9aa7 100644 --- a/src/position_util.c +++ b/src/position_util.c @@ -9,7 +9,7 @@ const s32 gFacingDirMapping[3][3] = { {DIRECTION_SOUTHWEST, DIRECTION_SOUTH, DIRECTION_SOUTHEAST} }; -s32 GetDirectionTowardsPosition(Position *originPos, Position *targetPos) +s32 GetDirectionTowardsPosition(DungeonPos *originPos, DungeonPos *targetPos) { s32 direction; s32 yDiff; @@ -44,7 +44,7 @@ s32 GetDirectionTowardsPosition(Position *originPos, Position *targetPos) return direction; } -s32 GetDistance(Position *pos1, Position *pos2) +s32 GetDistance(DungeonPos *pos1, DungeonPos *pos2) { s32 distanceX = pos1->x - pos2->x; s32 distance; diff --git a/src/sprite.c b/src/sprite.c index 8d5128655..4d943836c 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -12,7 +12,7 @@ static EWRAM_DATA s16 sUnknown_2025672[8] = {0}; UNUSED // TODO: Remove the "UNUSED" attribute after AddAxSprite is done #endif static EWRAM_DATA s16 sUnknown_2025682[9] = {0}; -static EWRAM_DATA Position sUnknown_2025694 = {0}; +static EWRAM_DATA DungeonPos sUnknown_2025694 = {0}; static EWRAM_DATA u32 sUnknown_2025698 = {0}; UNUSED static EWRAM_DATA u32 sUnused1 = {0}; // 202569C static EWRAM_DATA SpriteList sUnknown_20256A0 = {0}; @@ -755,7 +755,7 @@ void CopySpritesToOam(void) sOAMSpriteCount = count; } -void SetSavingIconCoords(Position *pos) +void SetSavingIconCoords(DungeonPos *pos) { if (pos == NULL) { sUnknown_2025694.x = 0; diff --git a/src/status_actions.c b/src/status_actions.c index 57f45fb5f..8df3e799f 100644 --- a/src/status_actions.c +++ b/src/status_actions.c @@ -39,14 +39,14 @@ extern void sub_807F43C(Entity *, Entity *); extern void sub_807DC68(Entity *, Entity *); extern u32 sub_803D73C(u32); extern void sub_8045C28(Item *, u8 , u8); -extern void sub_80464C8(Entity *, Position *, Item *); +extern void sub_80464C8(Entity *, DungeonPos *, Item *); extern void sub_8068FE0(Entity *, u32, Entity *r2); extern void sub_806F370(Entity *r0, Entity *r1, u32, u32, u8 *, u8, s32, u32, u32, u32); -extern void sub_807FC3C(Position *, u32, u32); -extern void sub_8042A64(Position *); +extern void sub_807FC3C(DungeonPos *, u32, u32); +extern void sub_8042A64(DungeonPos *); extern void sub_8040A84(void); extern void sub_80498A8(s32, s32); -extern void sub_8042A54(Position *); +extern void sub_8042A54(DungeonPos *); extern void sub_8049BB0(s32, s32); extern s16 sub_8057600(Move*, u32); extern u32 sub_8055864(Entity *pokemon, Entity *target, Move *param_3, s32 param_4, s32 param_5); @@ -60,8 +60,8 @@ extern void sub_806BB6C(Entity *, s32); extern void sub_807E254(Entity *, Entity *, u32); extern u32 HandleDamagingMove(Entity *, Entity *, Move *, u32, u32); extern void sub_806A6E8(Entity *); -extern u8 sub_8069D18(Position *); -extern u8 sub_804AD34(Position *); +extern u8 sub_8069D18(DungeonPos *); +extern u8 sub_804AD34(DungeonPos *); // TODO include dungeon_ai.h when SqueezedStatusTarget is figured out extern void LowerDefenseStageTarget(Entity *, Entity *, s32, s32, u8, bool8); @@ -653,7 +653,7 @@ bool8 sub_805B968(Entity * pokemon, Entity * target, Move * move, s32 param_4) bool8 RockSmashMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) { - Position pos; + DungeonPos pos; bool8 flag = FALSE; if (sub_8069D18(&pos) != 0) { @@ -947,7 +947,7 @@ bool8 TrapbustOrbAction(Entity * pokemon,Entity * target, Move *move, s32 param_ s32 xCoord, yCoord; struct RoomData *room; s32 topLeftCornerX, topLeftCornerY; - Position pos; + DungeonPos pos; bool8 foundTrap = FALSE; tile = GetTileAtEntitySafe(target); if (IsBossFight()) { @@ -1099,7 +1099,7 @@ bool8 FillInOrbAction(Entity *pokemon,Entity *target, Move *move, s32 param_4) int y; bool8 filledInTile; int x; - Position tileCoords; + DungeonPos tileCoords; filledInTile = FALSE; targetInfo = GetEntInfo(target); @@ -1153,7 +1153,7 @@ bool8 TrapperOrbAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) bool8 sub_805C3F8(Entity *pokemon, Entity *target, Move *move, s32 param_4) { Item stack; - Position posStruct = target->pos; + DungeonPos posStruct = target->pos; if(GetEntInfo(target)->monsterBehavior != BEHAVIOR_FIXED_ENEMY) { diff --git a/src/string_format.c b/src/string_format.c index 6f359eb28..522ec0052 100644 --- a/src/string_format.c +++ b/src/string_format.c @@ -34,7 +34,7 @@ void sub_80140B4(UnkTextStruct2 *a0) void sub_80140DC(void) { - Position pos; + DungeonPos pos; pos.x = 200; pos.y = 128; @@ -44,7 +44,7 @@ void sub_80140DC(void) void sub_80140F8(void) { - Position pos; + DungeonPos pos; pos.x = 188; pos.y = 64; @@ -92,7 +92,7 @@ struct UnkStruct_203B198 UnkTextStruct2 unk0; u8 unk18; u32 unk1C; - Position unk20; + DungeonPos unk20; u16 unk24; u16 unk26; u16 unk28; diff --git a/src/tile_types.c b/src/tile_types.c index 947b3f246..440a643ae 100644 --- a/src/tile_types.c +++ b/src/tile_types.c @@ -87,9 +87,9 @@ const u8 gDungeonWaterType[76] = { extern void sub_80498A8(s32, s32); extern void sub_80402AC(s32, s32); extern void sub_8049BB0(s32, s32); -void sub_8042A14(Position *); +void sub_8042A14(DungeonPos *); -bool8 PosHasItem(Position *pos) +bool8 PosHasItem(DungeonPos *pos) { struct Tile *tile; Entity *entity; @@ -102,7 +102,7 @@ bool8 PosHasItem(Position *pos) return FALSE; } -Entity *GetMonsterAtPos(Position *pos) +Entity *GetMonsterAtPos(DungeonPos *pos) { struct Tile *tile; Entity *entity; @@ -115,7 +115,7 @@ Entity *GetMonsterAtPos(Position *pos) return NULL; } -bool8 sub_804AD34(Position *pos) +bool8 sub_804AD34(DungeonPos *pos) { struct Tile *tile; s32 x; @@ -155,7 +155,7 @@ bool8 sub_804AD34(Position *pos) return iVar8; } -bool8 sub_804AE08(Position *pos) +bool8 sub_804AE08(DungeonPos *pos) { struct Tile *tile; s32 x; @@ -182,7 +182,7 @@ bool8 sub_804AE08(Position *pos) return uVar6; } -void sub_804AE84(Position *pos) +void sub_804AE84(DungeonPos *pos) { struct Tile *tile; s32 x; diff --git a/src/trap.c b/src/trap.c index 291bb642b..2d51f8b40 100644 --- a/src/trap.c +++ b/src/trap.c @@ -64,7 +64,7 @@ struct unkStruct_806B7F8 u32 unk4; u16 level; u8 fillA[2]; - struct Position pos; + DungeonPos pos; u8 unk10; }; extern Entity* sub_806B7F8(struct unkStruct_806B7F8 *, bool8); @@ -73,7 +73,7 @@ void sub_806A9B4(Entity *, u32); s16 sub_803D970(u32); bool8 sub_806AA0C(s32, s32); -void sub_80421EC(Position *, u32); +void sub_80421EC(DungeonPos *, u32); bool8 sub_8045888(Entity *); u8 sub_8043D10(void); @@ -82,13 +82,14 @@ void sub_8045C28(Item *, u8 , u8); void sub_8045BF8(u8 *, Item *); void DealDamageToEntity(Entity *,s16,u32,u32); void sub_806F480(Entity *, u32); -void sub_804225C(Entity *, Position *, u8); +void sub_804225C(Entity *, DungeonPos *, u8); void sub_8071DA4(Entity *); void sub_806A1E8(Entity *pokemon); u8 sub_803D6FC(void); -extern void sub_807DF38(Entity *pokemon, Entity *target, Position *pos, u32, u8 moveType, s16); +extern void sub_807DF38(Entity *pokemon, Entity *target, DungeonPos *pos, u32, + u8 moveType, s16); -void sub_807FC3C(Position *pos, u32 trapID, u32 param_3) +void sub_807FC3C(DungeonPos *pos, u32 trapID, u32 param_3) { gDungeon->trapPos.x = pos->x; gDungeon->trapPos.y = pos->y; @@ -97,7 +98,7 @@ void sub_807FC3C(Position *pos, u32 trapID, u32 param_3) gDungeon->unk13570 = 1; } -bool8 CanLayTrap(Position *pos) +bool8 CanLayTrap(DungeonPos *pos) { struct Tile *tile = GetTileSafe(pos->x, pos->y); if (tile->terrainType & TERRAIN_TYPE_STAIRS || @@ -118,7 +119,7 @@ bool8 CanLayTrap(Position *pos) return TRUE; } -bool8 LayTrap(Position *pos, u8 trapID, u8 param_3) +bool8 LayTrap(DungeonPos *pos, u8 trapID, u8 param_3) { Tile *tile; Entity *entity; @@ -183,7 +184,7 @@ bool8 sub_807FD84(Entity *entity) return flag; } -bool8 sub_807FE04(Position *pos, char param_2) +bool8 sub_807FE04(DungeonPos *pos, char param_2) { Tile *tile; @@ -201,7 +202,7 @@ bool8 sub_807FE04(Position *pos, char param_2) } } -bool8 sub_807FE44(Position *pos, char param_2) +bool8 sub_807FE44(DungeonPos *pos, char param_2) { Tile *tile; @@ -223,7 +224,7 @@ void GetTrapName(u8 *buffer, u8 trapIndex) strcpy(buffer, gTrapNames[trapIndex]); } -void sub_807FE9C(Entity *pokemon, Position *pos, int param_3, char param_4) +void sub_807FE9C(Entity *pokemon, DungeonPos *pos, int param_3, char param_4) { Tile *tile; bool8 flag1; @@ -578,7 +579,7 @@ void HandlePitfallTrap(Entity *pokemon, Entity *target, Tile *tile) } } -void HandleSummonTrap(Entity *pokemon,Position *pos) +void HandleSummonTrap(Entity *pokemon,DungeonPos *pos) { s32 r4; u32 direction; diff --git a/src/trap_1.c b/src/trap_1.c index c16165703..0aa388a41 100644 --- a/src/trap_1.c +++ b/src/trap_1.c @@ -8,13 +8,13 @@ // TODO: Merge this file with trap.c after "HandlePokemonTrap" is in c -extern void sub_804687C(Entity *, Position *, Position *, Item *, u32); +extern void sub_804687C(Entity *, DungeonPos *, DungeonPos *, Item *, u32); void HandleTripTrap(Entity *pokemon, Entity *target) { u32 direction; EntityInfo *info; - Position pos; + DungeonPos pos; Item item; if (target != NULL) { diff --git a/tmp/fixpoint.cocci b/tmp/fixpoint.cocci deleted file mode 100644 index 1c25b8c31..000000000 --- a/tmp/fixpoint.cocci +++ /dev/null @@ -1,17 +0,0 @@ -@@ -s48_16 e; -s48_16 *ep; -@@ -( -- e.s0 -+ e.hi -| -- e.s4 -+ e.lo -| -- ep->s0 -+ ep->hi -| -- ep->s4 -+ ep->lo -) diff --git a/tmp/position.cocci b/tmp/position.cocci new file mode 100644 index 000000000..ff2de880e --- /dev/null +++ b/tmp/position.cocci @@ -0,0 +1,17 @@ +@@ +typedef Position; +@@ +- struct Position ++ Position +@@ +typedef Position32; +typedef PixelPos; +@@ +- Position32 ++ PixelPos +@@ +typedef Position; +typedef DungeonPos; +@@ +- Position ++ DungeonPos diff --git a/tmp/renames.sed b/tmp/renames.sed deleted file mode 100644 index 39d202303..000000000 --- a/tmp/renames.sed +++ /dev/null @@ -1,26 +0,0 @@ -s/sub_8009DA4/FP24_8_SMul/g -s/sub_8009DD8/FP24_8_SDiv/g -s/sub_8009E14/FP24_8_UMul/g -s/sub_8009EA0/FP24_8_UDiv/g -s/sub_8009F68/FP24_8_Pow/g -s/sub_8009FB8/FP24_8_Hypot/g -s/sub_800A020/FP48_16_FromS32/g -s/sub_800A048/FP48_16_ToS32/g -s/sub_800A068/FP48_16_ToF248/g -s/sub_800A088/FP48_16_FromF248/g -s/sub_800A25C/FP48_16_Negate/g -s/sub_800A27C/FP48_16_Abs/g -s/sub_800A2A0/FP48_16_IsZero/g -s/sub_800A2BC/FP48_16_Equal/g -s/sub_800A2DC/FP48_16_IsNegative/g -s/sub_800A2F0/FP48_16_SLessThan/g -s/sub_800A34C/FP48_16_SMul/g -s/sub_800A3F0/FP48_16_SDiv/g -s/sub_800A4A0/FP48_16_Square/g -s/sub_800A4E4/FP48_16_UMul/g -s/sub_800A5A4/FP48_16_UDiv/g -s/sub_800A6D0/FP48_16_Add/g -s/sub_800A6F0/FP48_16_Subtract/g -s/sub_800A710/FP48_16_Pow/g -s/sub_800A78C/FP48_16_Hypot/g -s/sub_800A894/FP48_16_Log/g From 4c8a8f4b301b840f50fef24d56fa3ab6c17e5fd3 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Wed, 13 Nov 2024 12:42:24 +0100 Subject: [PATCH 08/12] GetTile -> const Tile* --- asm/code_8045A00.s | 4 +- asm/code_804AFAC.s | 164 +++++++++++++++++------------------ asm/code_804FD30.s | 74 ++++++++-------- asm/code_805D8C8_1.s | 4 +- asm/code_8069E0C.s | 2 +- asm/code_8077274_1.s | 4 +- asm/code_807CD9C.s | 10 +-- asm/code_807E5AC.s | 2 +- include/dungeon_map_access.h | 4 +- include/dungeon_movement.h | 2 +- include/dungeon_util.h | 3 +- src/code_803E724.c | 2 +- src/code_8040094.c | 4 +- src/code_8042B34.c | 2 +- src/code_8044CC8.c | 4 +- src/code_80450F8.c | 2 +- src/code_8045A00.c | 2 +- src/code_804AFAC.c | 10 +-- src/code_805D8C8_1.c | 14 +-- src/code_8066D04.c | 2 +- src/code_806CD90.c | 2 +- src/code_80718D8.c | 2 +- src/code_8072B78.c | 2 +- src/code_8075708.c | 4 +- src/code_807CD9C.c | 4 +- src/dungeon_ai_attack.c | 6 +- src/dungeon_ai_item_weight.c | 2 +- src/dungeon_ai_items.c | 2 +- src/dungeon_ai_movement.c | 8 +- src/dungeon_ai_targeting.c | 15 ++-- src/dungeon_capabilities.c | 2 +- src/dungeon_cutscenes.c | 16 ++-- src/dungeon_map_access.c | 48 +++++----- src/dungeon_move.c | 4 +- src/dungeon_movement.c | 12 +-- src/dungeon_range.c | 8 +- src/dungeon_serializer.c | 6 +- src/dungeon_util.c | 4 +- src/move_actions.c | 6 +- src/move_checks.c | 2 +- src/move_effects_target.c | 10 +-- src/status.c | 2 +- src/status_actions.c | 8 +- src/tile_types.c | 16 ++-- src/trap.c | 10 +-- tmp/gettile.cocci | 42 +++++++++ tmp/position.cocci | 17 ---- 47 files changed, 301 insertions(+), 274 deletions(-) create mode 100644 tmp/gettile.cocci delete mode 100644 tmp/position.cocci diff --git a/asm/code_8045A00.s b/asm/code_8045A00.s index 5f79ba4d4..74dd85a19 100644 --- a/asm/code_8045A00.s +++ b/asm/code_8045A00.s @@ -442,7 +442,7 @@ _08046110: ldrsh r0, [r5, r1] movs r2, 0x2 ldrsh r1, [r5, r2] - bl GetTileSafe + bl GetTileMut str r4, [r0, 0x14] ldrh r1, [r0] movs r0, 0x20 @@ -528,7 +528,7 @@ sub_80461C8: ldrsh r0, [r2, r1] movs r3, 0x2 ldrsh r1, [r2, r3] - bl GetTileSafe + bl GetTileMut adds r6, r0, 0 ldr r5, [r6, 0x14] cmp r5, 0 diff --git a/asm/code_804AFAC.s b/asm/code_804AFAC.s index c2f4a3fea..48d8e5dd8 100644 --- a/asm/code_804AFAC.s +++ b/asm/code_804AFAC.s @@ -679,7 +679,7 @@ _0804B55A: adds r0, r5, 0 adds r1, r4, 0 str r3, [sp, 0xC] - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r0, [r2] ldr r6, _0804B630 @@ -1196,7 +1196,7 @@ _0804B962: ldr r2, _0804B9F0 add r2, sp str r3, [r2] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] mov r2, r9 ands r1, r2 @@ -1205,7 +1205,7 @@ _0804B962: strh r1, [r0] adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut ldr r1, _0804B9D0 add r1, sp ldrb r1, [r1] @@ -1294,7 +1294,7 @@ _0804B9F4: strh r0, [r7, 0x6] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, _0804BBF8 adds r2, r3, 0 @@ -1304,7 +1304,7 @@ _0804B9F4: strh r1, [r0] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0xFF strb r1, [r0, 0x9] _0804BA72: @@ -1805,7 +1805,7 @@ _0804BE84: ldr r2, _0804BEFC add r2, sp str r3, [r2] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] mov r2, r8 ands r1, r2 @@ -1814,7 +1814,7 @@ _0804BE84: strh r1, [r0] adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut ldr r1, _0804BEE0 add r1, sp ldrb r1, [r1] @@ -1902,7 +1902,7 @@ _0804BF00: strh r0, [r7, 0x6] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r6, _0804C090 adds r2, r6, 0 @@ -1912,7 +1912,7 @@ _0804BF00: strh r1, [r0] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0xFF strb r1, [r0, 0x9] _0804BF88: @@ -2563,7 +2563,7 @@ _0804C4C2: _0804C4CE: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ands r1, r7 movs r2, 0x1 @@ -3164,7 +3164,7 @@ _0804C95C: _0804C972: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] mov r2, r8 ands r1, r2 @@ -3173,7 +3173,7 @@ _0804C972: strh r1, [r0] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut mov r1, r9 strb r1, [r0, 0x9] adds r4, 0x1 @@ -3373,7 +3373,7 @@ _0804CB0C: lsls r2, 5 add r2, sp str r3, [r2] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] mov r2, r8 ands r1, r2 @@ -3382,7 +3382,7 @@ _0804CB0C: strh r1, [r0] adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0xE5 lsls r1, 5 add r1, sp @@ -3871,7 +3871,7 @@ _0804CEFA: beq _0804CF16 adds r0, r7, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, _0804D018 adds r2, r3, 0 @@ -4544,7 +4544,7 @@ _0804D3E0: adds r0, r4, 0 adds r1, r5, 0 str r3, [sp, 0x34] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] mov r2, r9 ands r1, r2 @@ -4553,7 +4553,7 @@ _0804D3E0: strh r1, [r0] adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut mov r1, sp ldrb r1, [r1, 0x10] strb r1, [r0, 0x9] @@ -4680,7 +4680,7 @@ _0804D4BA: strh r0, [r7, 0x6] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, _0804D530 adds r2, r3, 0 @@ -4690,7 +4690,7 @@ _0804D4BA: strh r1, [r0] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0xFE strb r1, [r0, 0x9] _0804D508: @@ -5815,7 +5815,7 @@ _0804DCF0: adds r0, r5, 0 adds r1, r4, 0 str r3, [sp, 0x54] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, [sp, 0x54] ands r1, r3 @@ -5945,7 +5945,7 @@ _0804DDE0: adds r0, r5, 0 adds r1, r4, 0 str r3, [sp, 0x54] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, [sp, 0x54] ands r1, r3 @@ -6076,7 +6076,7 @@ _0804DED0: adds r0, r5, 0 adds r1, r4, 0 str r3, [sp, 0x54] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, [sp, 0x54] ands r1, r3 @@ -6195,7 +6195,7 @@ _0804DFB6: adds r0, r5, 0 adds r1, r4, 0 str r3, [sp, 0x54] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] mov r2, r9 ands r1, r2 @@ -6617,7 +6617,7 @@ _0804E2AA: bne _0804E2F0 adds r0, r7, 0 mov r1, r8 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r4, _0804E2CC adds r1, r4, 0 @@ -6723,7 +6723,7 @@ _0804E360: beq _0804E390 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r3, _0804E38C adds r1, r3, 0 @@ -6773,7 +6773,7 @@ _0804E3BC: beq _0804E3EC adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r3, _0804E3E8 adds r1, r3, 0 @@ -6829,7 +6829,7 @@ _0804E420: beq _0804E450 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r3, _0804E44C adds r1, r3, 0 @@ -6883,7 +6883,7 @@ _0804E482: beq _0804E4B0 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r3, _0804E4AC adds r1, r3, 0 @@ -6930,7 +6930,7 @@ _0804E4D0: beq _0804E508 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r3, _0804E504 adds r1, r3, 0 @@ -6979,7 +6979,7 @@ _0804E52C: beq _0804E564 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r3, _0804E560 adds r1, r3, 0 @@ -7379,7 +7379,7 @@ _0804E848: ldrsh r0, [r6, r1] movs r2, 0x2 ldrsh r1, [r6, r2] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, _0804E99C adds r2, r3, 0 @@ -7494,7 +7494,7 @@ _0804E908: _0804E926: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] ldr r3, _0804E99C adds r1, r3, 0 @@ -7628,7 +7628,7 @@ _0804EA0E: ble _0804EA4E subs r0, r5, 0x1 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrb r0, [r2, 0x9] cmp r0, 0xFF @@ -7653,7 +7653,7 @@ _0804EA4E: ble _0804EA82 subs r1, r4, 0x1 adds r0, r5, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrb r0, [r2, 0x9] cmp r0, 0xFF @@ -7680,7 +7680,7 @@ _0804EA82: bgt _0804EABA adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrb r0, [r2, 0x9] cmp r0, 0xFF @@ -7707,7 +7707,7 @@ _0804EABA: bgt _0804EB0E mov r0, r10 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrb r0, [r2, 0x9] cmp r0, 0xFF @@ -7740,7 +7740,7 @@ _0804EAF4: bne _0804EB0E adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0xFF strb r1, [r0, 0x9] _0804EB0E: @@ -8099,7 +8099,7 @@ _0804ED98: adds r0, r5, 0 adds r1, r4, 0 str r3, [sp, 0x50] - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] movs r1, 0x20 orrs r1, r2 @@ -8185,7 +8185,7 @@ _0804EE18: _0804EE38: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x10 orrs r1, r2 @@ -8466,7 +8466,7 @@ _0804F046: _0804F05A: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] movs r1, 0x40 orrs r1, r2 @@ -8971,7 +8971,7 @@ _0804F40A: beq _0804F438 subs r0, r6, 0x1 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ands r1, r7 movs r2, 0x2 @@ -8982,7 +8982,7 @@ _0804F434: .4byte 0x0000fffc _0804F438: subs r0, r6, 0x1 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ands r1, r7 _0804F444: @@ -9057,7 +9057,7 @@ _0804F4BA: movs r7, 0 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut mov r1, r9 mov r3, r8 lsrs r2, r3, 24 @@ -9140,7 +9140,7 @@ _0804F550: _0804F55A: adds r0, r5, 0x1 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut mov r1, r9 mov r3, r8 lsrs r2, r3, 24 @@ -9150,7 +9150,7 @@ _0804F55A: _0804F570: subs r1, r4, 0x1 adds r0, r5, 0 - bl GetTileSafe + bl GetTileMut mov r1, r9 mov r3, r8 lsrs r2, r3, 24 @@ -9160,7 +9160,7 @@ _0804F570: _0804F586: subs r0, r5, 0x1 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut mov r1, r9 mov r3, r8 lsrs r2, r3, 24 @@ -9170,7 +9170,7 @@ _0804F586: _0804F59C: adds r1, r4, 0x1 adds r0, r5, 0 - bl GetTileSafe + bl GetTileMut mov r1, r9 mov r3, r8 lsrs r2, r3, 24 @@ -9220,7 +9220,7 @@ _0804F5E2: _0804F5F0: adds r0, r6, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x20 orrs r1, r2 @@ -9400,7 +9400,7 @@ _0804F730: _0804F73C: mov r0, r8 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 adds r4, 0x1 @@ -9425,7 +9425,7 @@ _0804F75E: _0804F76C: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] movs r1, 0x80 orrs r1, r2 @@ -9482,7 +9482,7 @@ _0804F7C8: _0804F7D4: adds r0, r4, 0 mov r1, r8 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 adds r4, 0x1 @@ -9507,7 +9507,7 @@ _0804F7F6: _0804F804: adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] movs r1, 0x80 orrs r1, r2 @@ -9568,7 +9568,7 @@ _0804F864: mov r10, r0 adds r0, r5, 0 mov r1, r10 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 ldr r1, [sp] @@ -9576,12 +9576,12 @@ _0804F864: mov r9, r1 mov r0, r9 mov r1, r10 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 ldr r0, [sp] mov r1, r10 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 ldr r2, [sp] @@ -9589,118 +9589,118 @@ _0804F864: mov r8, r2 mov r0, r8 mov r1, r10 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 ldr r6, [sp, 0x4] subs r6, 0x1 adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 adds r0, r5, 0 ldr r1, [sp, 0x4] - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 ldr r4, [sp, 0x4] adds r4, 0x1 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 mov r0, r9 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 ldr r0, [sp] adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 mov r0, r8 mov r1, r10 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 mov r0, r8 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 mov r0, r8 ldr r1, [sp, 0x4] - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 mov r0, r8 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x4 bl sub_804F5C4 mov r0, r9 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x4 orrs r1, r2 strh r1, [r0, 0x4] mov r0, r9 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] movs r2, 0x40 orrs r1, r2 strh r1, [r0, 0x4] ldr r0, [sp] adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] movs r4, 0x2 orrs r1, r4 strh r1, [r0, 0x4] mov r0, r9 ldr r1, [sp, 0x4] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] orrs r1, r4 strh r1, [r0, 0x4] ldr r0, [sp] ldr r1, [sp, 0x4] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] orrs r1, r4 strh r1, [r0, 0x4] mov r0, r9 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] movs r4, 0x10 orrs r1, r4 strh r1, [r0, 0x4] ldr r0, [sp] adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] orrs r1, r4 strh r1, [r0, 0x4] mov r0, r9 ldr r1, [sp, 0x4] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] orrs r1, r4 strh r1, [r0, 0x4] ldr r0, [sp] ldr r1, [sp, 0x4] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0, 0x4] orrs r4, r1 strh r4, [r0, 0x4] @@ -9789,7 +9789,7 @@ _0804FA6C: _0804FA76: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 adds r4, 0x1 @@ -9861,7 +9861,7 @@ _0804FAD4: movs r4, 0x2 ldrsh r1, [r7, r4] adds r1, r2 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 _0804FB14: @@ -9917,28 +9917,28 @@ _0804FB54: ble _0804FBAE adds r0, r5, 0x1 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 adds r1, r4, 0x1 adds r0, r5, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 subs r0, r5, 0x1 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 subs r1, r4, 0x1 adds r0, r5, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 _0804FBAE: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0 bl sub_804F5C4 b _0804FBD2 diff --git a/asm/code_804FD30.s b/asm/code_804FD30.s index 19dec61b2..0ef076dfb 100644 --- a/asm/code_804FD30.s +++ b/asm/code_804FD30.s @@ -106,7 +106,7 @@ _0804FFAA: adds r4, r1, r0 ldrb r0, [r4] ldrb r1, [r4, 0x1] - bl GetTileSafe + bl GetTileMut adds r5, r0, 0 ldrh r1, [r5, 0x4] movs r0, 0x1 @@ -137,7 +137,7 @@ _08050002: _08050004: adds r0, r6, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut adds r1, r0, 0 ldrh r2, [r1] movs r0, 0x3 @@ -245,7 +245,7 @@ _080500BC: _080500D8: ldrb r0, [r4] ldrb r1, [r4, 0x1] - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x2 orrs r1, r2 @@ -320,7 +320,7 @@ _08050128: _0805016C: ldrb r0, [r4] ldrb r1, [r4, 0x1] - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x2 orrs r1, r2 @@ -432,7 +432,7 @@ _0805024C: .4byte 0x00003a0c _08050250: .4byte gUnknown_80F4DA0 _08050254: ldrb r1, [r7, 0x1] - bl GetTileSafe + bl GetTileMut adds r4, r0, 0 movs r0, 0x2 bl DungeonRandInt @@ -549,7 +549,7 @@ _08050318: _08050334: ldrb r0, [r4] ldrb r1, [r4, 0x1] - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x4 orrs r1, r2 @@ -814,7 +814,7 @@ _0805051C: _0805053C: ldrb r0, [r4] ldrb r1, [r4, 0x1] - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x8 orrs r1, r2 @@ -969,7 +969,7 @@ _0805064E: _0805066A: ldrb r0, [r4] ldrb r1, [r4, 0x1] - bl GetTileSafe + bl GetTileMut ldrh r2, [r0, 0x4] movs r1, 0x8 orrs r1, r2 @@ -1137,7 +1137,7 @@ _080507A8: bne _080507B8 mov r0, r9 mov r1, r10 - bl GetTileSafe + bl GetTileMut bl sub_80506BC _080507B8: ldr r2, [sp, 0x68] @@ -1278,7 +1278,7 @@ _080508CC: cmp r1, 0 bne _080508DA adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut bl sub_80506BC _080508DA: ldr r1, [sp, 0x7C] @@ -1446,7 +1446,7 @@ _08050A0A: bne _08050A1A ldr r0, [sp, 0x90] ldr r1, [sp, 0x94] - bl GetTileSafe + bl GetTileMut bl sub_80506BC _08050A1A: adds r5, 0x1 @@ -1650,7 +1650,7 @@ _08050B7C: subs r0, r7, 0x5 adds r1, r6, 0 str r2, [sp, 0x9C] - bl GetTileSafe + bl GetTileMut bl sub_80506BC ldr r2, [sp, 0x9C] _08050B92: @@ -1683,7 +1683,7 @@ _08050BB8: _08050BC0: mov r0, r9 mov r1, r10 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r3, [r2] movs r0, 0x3 @@ -1777,7 +1777,7 @@ _08050C5C: _08050C68: adds r0, r7, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r0, [r2] movs r3, 0x3 @@ -2135,7 +2135,7 @@ _08050F00: _08050F08: adds r0, r7, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrb r1, [r4] movs r0, 0x87 @@ -2374,7 +2374,7 @@ _080510D6: adds r0, r5, 0 adds r1, r4, 0 str r3, [sp, 0x38] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] mov r2, r9 ands r1, r2 @@ -2383,7 +2383,7 @@ _080510D6: strh r1, [r0] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut mov r1, sp ldrb r1, [r1, 0x10] strb r1, [r0, 0x9] @@ -2469,7 +2469,7 @@ _08051162: strh r0, [r6, 0x6] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r3, _080511EC adds r2, r3, 0 @@ -2479,7 +2479,7 @@ _08051162: strh r1, [r0] adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0xFF strb r1, [r0, 0x9] ldr r4, [sp, 0x14] @@ -2663,7 +2663,7 @@ _080512EE: lsrs r4, 24 adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut movs r1, 0x1 str r1, [sp] adds r1, r4, 0 @@ -2711,7 +2711,7 @@ _08051338: _08051350: adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r1, [r2] movs r0, 0x10 @@ -2760,7 +2760,7 @@ _080513B8: _080513BC: adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] movs r1, 0x10 orrs r1, r2 @@ -2788,7 +2788,7 @@ _080513EC: _080513F0: adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r1, [r2] movs r0, 0x3 @@ -2923,7 +2923,7 @@ _080514EE: lsrs r5, 24 adds r0, r7, 0 mov r1, r8 - bl GetTileSafe + bl GetTileMut adds r6, r0, 0 ldr r1, [sp, 0x4] ldr r2, _080515D0 @@ -3047,7 +3047,7 @@ _080515F6: lsrs r4, 24 adds r0, r7, 0 mov r1, r8 - bl GetTileSafe + bl GetTileMut adds r5, r0, 0 ldrb r6, [r5, 0x9] movs r0, 0x1 @@ -3154,7 +3154,7 @@ _080516CA: ldr r0, [r5] adds r1, r4, 0 str r2, [sp, 0xC] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r2, [sp, 0xC] ands r1, r2 @@ -3187,7 +3187,7 @@ _0805170A: ldr r0, [r5, 0x8] adds r1, r4, 0 str r2, [sp, 0xC] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r2, [sp, 0xC] ands r1, r2 @@ -3233,7 +3233,7 @@ _08051762: ldr r1, [r5, 0x4] adds r0, r4, 0 str r2, [sp, 0xC] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r2, [sp, 0xC] ands r1, r2 @@ -3266,7 +3266,7 @@ _080517A2: ldr r1, [r5, 0xC] adds r0, r4, 0 str r2, [sp, 0xC] - bl GetTileSafe + bl GetTileMut ldrh r1, [r0] ldr r2, [sp, 0xC] ands r1, r2 @@ -3306,7 +3306,7 @@ _080517EC: adds r0, r7, 0 adds r1, r5, 0 str r3, [sp, 0x10] - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r1, [r2] movs r0, 0x20 @@ -3370,7 +3370,7 @@ _08051864: adds r0, r7, 0 adds r1, r5, 0 str r3, [sp, 0x10] - bl GetTileSafe + bl GetTileMut adds r6, r0, 0 ldrh r1, [r6] movs r0, 0x20 @@ -3446,7 +3446,7 @@ sub_80518F0: _080518F8: adds r0, r5, 0 movs r1, 0x1 - bl GetTileSafe + bl GetTileMut adds r4, r0, 0 bl sub_804FD10 cmp r5, 0 @@ -3460,7 +3460,7 @@ _0805190E: _08051914: adds r0, r5, 0 movs r1, 0x1E - bl GetTileSafe + bl GetTileMut adds r4, r0, 0 bl sub_804FD10 cmp r5, 0 @@ -3614,7 +3614,7 @@ sub_8051A24: mov r8, r3 adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut adds r7, r0, 0 lsls r4, 16 lsls r5, 16 @@ -4067,7 +4067,7 @@ _08051E42: _08051E46: adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrb r0, [r2, 0xE] cmp r0, 0xF @@ -4107,7 +4107,7 @@ sub_8051E7C: movs r3, 0x6 ldrsh r1, [r2, r3] subs r1, 0x1 - bl GetTileSafe + bl GetTileMut str r0, [sp, 0x8] ldrh r1, [r0] movs r0, 0x80 @@ -4207,7 +4207,7 @@ _08051F10: bge _08051FCA adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut adds r4, r0, 0 ldrh r0, [r4] movs r3, 0x80 diff --git a/asm/code_805D8C8_1.s b/asm/code_805D8C8_1.s index f06cb8e2d..f2259e3f7 100644 --- a/asm/code_805D8C8_1.s +++ b/asm/code_805D8C8_1.s @@ -1489,7 +1489,7 @@ sub_80694C0: mov r9, r3 adds r0, r7, 0 mov r1, r8 - bl GetTileSafe + bl GetTileMut mov r10, r0 ldr r5, [r4, 0x70] adds r6, r5, 0 @@ -1536,7 +1536,7 @@ _08069522: blt _08069552 adds r1, r0, 0 adds r0, r2, 0 - bl GetTileSafe + bl GetTileMut adds r1, r0, 0 ldr r0, [r1, 0x10] cmp r0, r4 diff --git a/asm/code_8069E0C.s b/asm/code_8069E0C.s index 97672b2e2..7e590a7a2 100644 --- a/asm/code_8069E0C.s +++ b/asm/code_8069E0C.s @@ -102,7 +102,7 @@ _0806A488: movs r2, 0x6 ldrsh r1, [r6, r2] adds r1, r7 - bl GetTileSafe + bl GetTileMut adds r4, r0, 0 ldr r0, [r4, 0x10] cmp r0, 0 diff --git a/asm/code_8077274_1.s b/asm/code_8077274_1.s index 01c3324eb..65cdb1b1b 100644 --- a/asm/code_8077274_1.s +++ b/asm/code_8077274_1.s @@ -86,7 +86,7 @@ _0807ABC6: adds r0, r4, 0 adds r1, r6, 0 str r2, [sp, 0x1A4] - bl GetTileSafe + bl GetTileMut adds r1, r0, 0 ldr r0, [r1, 0x10] ldr r2, [sp, 0x1A4] @@ -176,7 +176,7 @@ _0807AC72: adds r0, r4, 0 adds r1, r6, 0 str r2, [sp, 0x1A4] - bl GetTileSafe + bl GetTileMut adds r1, r0, 0 ldr r0, [r1, 0x10] ldr r2, [sp, 0x1A4] diff --git a/asm/code_807CD9C.s b/asm/code_807CD9C.s index 358e4db4c..604aa7cea 100644 --- a/asm/code_807CD9C.s +++ b/asm/code_807CD9C.s @@ -831,7 +831,7 @@ _0807DBB6: _0807DBB8: adds r0, r4, 0 adds r1, r5, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r1, [r2] movs r0, 0x3 @@ -971,7 +971,7 @@ _0807DCD8: movs r6, 0 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r1, [r2] ldr r3, _0807DD6C @@ -1094,7 +1094,7 @@ _0807DDC8: _0807DDCA: adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut adds r2, r0, 0 ldrh r1, [r2] movs r3, 0x80 @@ -1141,7 +1141,7 @@ _0807DE1A: beq _0807DE30 adds r0, r5, 0 adds r1, r4, 0 - bl GetTileSafe + bl GetTileMut ldrh r2, [r0] movs r1, 0x40 orrs r1, r2 @@ -1402,7 +1402,7 @@ _0807E014: bgt _0807E112 cmp r1, 0x1F bgt _0807E112 - bl GetTileSafe + bl GetTileMut mov r8, r0 ldr r0, [sp, 0x18] movs r2, 0 diff --git a/asm/code_807E5AC.s b/asm/code_807E5AC.s index 9ecbe863e..eaf80cb03 100644 --- a/asm/code_807E5AC.s +++ b/asm/code_807E5AC.s @@ -2468,7 +2468,7 @@ _0807FA1E: _0807FA22: adds r0, r5, 0 adds r1, r6, 0 - bl GetTileSafe + bl GetTileMut adds r4, r0, 0 ldrh r1, [r4, 0x4] movs r0, 0x4 diff --git a/include/dungeon_map_access.h b/include/dungeon_map_access.h index adee8dc5b..5defb8029 100644 --- a/include/dungeon_map_access.h +++ b/include/dungeon_map_access.h @@ -8,8 +8,8 @@ typedef struct unkStruct_202F190 Tile *unk0[6]; } unkStruct_202F190; -Tile *GetTile(s32 x, s32 y); -Tile *GetTileSafe(s32 x, s32 y); +const Tile *GetTile(s32 x, s32 y); +Tile *GetTileMut(s32 x, s32 y); void sub_8049ED4(void); void sub_804AC20(DungeonPos *pos); diff --git a/include/dungeon_movement.h b/include/dungeon_movement.h index 1549f1aa6..3d3973d23 100644 --- a/include/dungeon_movement.h +++ b/include/dungeon_movement.h @@ -7,7 +7,7 @@ extern u8 gWalkableTileToCrossableTerrain[8]; u8 GetCrossableTerrain(s16 species); -u8 sub_807034C(s16 id, struct Tile *tile); +u8 sub_807034C(s16 id, const Tile *tile); u8 sub_80703A0(Entity *pokemon, DungeonPos *pos); bool8 CanCrossWalls(Entity *pokemon); bool8 sub_807049C(Entity *pokemon, DungeonPos *pos); diff --git a/include/dungeon_util.h b/include/dungeon_util.h index 5ecd4b111..845a2ec51 100644 --- a/include/dungeon_util.h +++ b/include/dungeon_util.h @@ -5,13 +5,14 @@ #include "structs/dungeon_entity.h" #include "structs/str_position.h" #include "structs/str_traps.h" +#include "structs/map.h" extern const DungeonPos gAdjacentTileOffsets[NUM_DIRECTIONS]; bool8 EntityExists(Entity *pokemon); u32 GetEntityType(Entity *entity); u8 GetEntityRoom(Entity *entity); -struct Tile *GetTileAtEntitySafe(Entity *entity); +Tile *GetTileAtEntitySafe(Entity *entity); void sub_804535C(Entity *entity, PixelPos *pos); void SetEntityPixelPos(Entity *entity, s32 x, s32 y); void IncreaseEntityPixelPos(Entity *entity, s32 x, s32 y); diff --git a/src/code_803E724.c b/src/code_803E724.c index 475f05814..42be68d70 100644 --- a/src/code_803E724.c +++ b/src/code_803E724.c @@ -1081,7 +1081,7 @@ void sub_803F580(u8 a0) void sub_803F7BC(void) { UnkDungeonGlobal_unk181E8_sub *strPtr = &gDungeon->unk181e8; - Tile *tile = GetTile(strPtr->cameraPos.x, strPtr->cameraPos.y); + const Tile *tile = GetTile(strPtr->cameraPos.x, strPtr->cameraPos.y); u32 roomId = tile->room; if (strPtr->unk1820B != 0 || strPtr->unk1820C != 0 || strPtr->unk18217 != 0) { diff --git a/src/code_8040094.c b/src/code_8040094.c index 91c14d244..4386cd74c 100644 --- a/src/code_8040094.c +++ b/src/code_8040094.c @@ -26,7 +26,7 @@ extern const char *gUnknown_80FD040; // It became brighter on the floor // Luminous Orb??? void HandleLuminousOrbAction(Entity *pokemon) { - struct Tile *mapTile; + Tile *mapTile; int XCoord; int YCoord; @@ -36,7 +36,7 @@ void HandleLuminousOrbAction(Entity *pokemon) { for(XCoord = 0; XCoord < DUNGEON_MAX_SIZE_X; XCoord++) { - mapTile = GetTileSafe(XCoord, YCoord); + mapTile = GetTileMut(XCoord, YCoord); mapTile->unk4 = mapTile->unk4 | 1; } } diff --git a/src/code_8042B34.c b/src/code_8042B34.c index 234c0267a..89bbcd7c5 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -1055,7 +1055,7 @@ void sub_8043D60(void) for (y = 0; y < 32; y++) { for (x = 0; x < 56; x++) { - Entity *object = GetTileSafe(x, y)->object; + Entity *object = GetTileMut(x, y)->object; if (EntityExists(object) && GetEntityType(object) == ENTITY_TRAP) { Trap *trapData = GetTrapData(object); if (trapData->id == 27) { diff --git a/src/code_8044CC8.c b/src/code_8044CC8.c index 8d9ead4b3..826c67265 100644 --- a/src/code_8044CC8.c +++ b/src/code_8044CC8.c @@ -41,7 +41,7 @@ bool8 sub_80461C8(DungeonPos *, u32); Item * sub_8044CC8(Entity *param_1, unkStruct_8044CC8 *param_2) { - Tile *tile; + const Tile *tile; Item *item; EntityInfo *info; @@ -282,4 +282,4 @@ void sub_8045064(void) } } } -} \ No newline at end of file +} diff --git a/src/code_80450F8.c b/src/code_80450F8.c index 526a34b5a..38f2308b9 100644 --- a/src/code_80450F8.c +++ b/src/code_80450F8.c @@ -554,7 +554,7 @@ Entity *sub_8045708(DungeonPos *pos) Entity *ent; if (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_LAVA - && (GetTileSafe(pos->x, pos->y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_SECONDARY) { + && (GetTileMut(pos->x, pos->y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_SECONDARY) { return NULL; } diff --git a/src/code_8045A00.c b/src/code_8045A00.c index fd8662e4b..28f217f54 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -131,7 +131,7 @@ void sub_8045CB0(void) u32 x; int y; int yCounter; - struct Tile *tile; + const Tile *tile; u32 uVar5; int xCounter; Item item; diff --git a/src/code_804AFAC.c b/src/code_804AFAC.c index 5f2549bc0..f46979a1e 100644 --- a/src/code_804AFAC.c +++ b/src/code_804AFAC.c @@ -13,7 +13,7 @@ void sub_804FBE8(void) { for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - tile = GetTileSafe(x,y); + tile = GetTileMut(x,y); if ((tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) != TERRAIN_TYPE_NORMAL) { if ((tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL)) != 0) { tile->unk4 &= 0xfffd; @@ -42,7 +42,7 @@ void sub_804FC74(void) for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { if ((GetTile(x, y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_SECONDARY) { - tile = GetTileSafe(x,y); + tile = GetTileMut(x,y); tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); tile->terrainType |= (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); } @@ -61,7 +61,7 @@ void sub_804FCCC(void) for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { if ((GetTile(x, y)->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) != 0) { - tile = GetTileSafe(x,y); + tile = GetTileMut(x,y); tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); } } @@ -100,7 +100,7 @@ void sub_804FD30(void) { for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { - sub_804FD10(GetTileSafe(x,y)); + sub_804FD10(GetTileMut(x,y)); if ((boundsCheck(x, y - 1)) || (boundsCheck(x + 1, y - 1)) || @@ -111,7 +111,7 @@ void sub_804FD30(void) (boundsCheck(x - 1, y)) || (boundsCheck(x - 1, y - 1))) { - GetTileSafe(x,y)->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; + GetTileMut(x,y)->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; } } } diff --git a/src/code_805D8C8_1.c b/src/code_805D8C8_1.c index 6e13f4d04..e8cfceb52 100644 --- a/src/code_805D8C8_1.c +++ b/src/code_805D8C8_1.c @@ -1347,7 +1347,7 @@ NAKED static void TryCreateModeArrows(Entity *leader) void sub_805E738(Entity *a0) { - Tile *tile; + const Tile *tile; s32 i, j; EntityInfo *entityInfo = GetEntInfo(a0); if (entityInfo->blinkerClassStatus.status != 1 && entityInfo->blinkerClassStatus.status != 2) { @@ -1401,7 +1401,7 @@ bool8 sub_805E874(void) s32 direction = GetEntInfo(leader)->action.direction; s32 x = leader->pos.x; s32 y = leader->pos.y; - Tile *leaderTile = GetTile(x, y); + const Tile *leaderTile = GetTile(x, y); s32 xAdjacent = x + gAdjacentTileOffsets[direction].x; s32 yAdjacent = y + gAdjacentTileOffsets[direction].y; s32 room; @@ -1426,7 +1426,7 @@ bool8 sub_805E874(void) } for (j = -1; j < 2; j++) { - Tile *tile = GetTile(x + gAdjacentTileOffsets[(direction + j) & 7].x, y + gAdjacentTileOffsets[(direction + j) & 7].y); + const Tile *tile = GetTile(x + gAdjacentTileOffsets[(direction + j) & 7].x, y + gAdjacentTileOffsets[(direction + j) & 7].y); if (tile->monster != NULL) return FALSE; if (tile->terrainType & TERRAIN_TYPE_STAIRS) @@ -1443,7 +1443,7 @@ bool8 sub_805E874(void) for (i = -1; i < 2; i++) { for (j = -1; j < 2; j++) { - Tile *tile = GetTile(x + i, y + j); + const Tile *tile = GetTile(x + i, y + j); if (tile->object != NULL) { for (k = 0; k < 3; k++) { if (x + i == xArray[k] && y + j == yArray[k]) @@ -1528,7 +1528,7 @@ bool8 sub_805EC2C(Entity *a0, s32 x, s32 y) bool8 sub_805EC4C(Entity *a0, u8 a1) { DungeonPos pos; - Tile *tile; + const Tile *tile; EntityInfo *tileMonsterInfo; Entity *tileMonster; EntityInfo *entityInfo = GetEntInfo(a0); @@ -2054,7 +2054,7 @@ void ShowFieldMenu(u8 a0_, bool8 a1) } else if (var_28 == 4) { Entity *leader = GetLeader(); - Tile *tile = GetTile(leader->pos.x, leader->pos.y); + const Tile *tile = GetTile(leader->pos.x, leader->pos.y); Entity *tileObject = tile->object; if (tileObject != NULL) { if (GetEntityType(tileObject) == ENTITY_ITEM) { @@ -2757,7 +2757,7 @@ static void CreateFieldItemMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, UnkTextS } break; case 2: { - Tile *tile = GetTile(a1->pos.x, a1->pos.y); + const Tile *tile = GetTile(a1->pos.x, a1->pos.y); Item *item = GetItemData(tile->object); PrintFormattedStringOnWindow(x, 0, gFieldItemMenuGroundTextPtr, 0, 0); if (item->flags & ITEM_FLAG_EXISTS) { diff --git a/src/code_8066D04.c b/src/code_8066D04.c index 5beb3e648..80adc5407 100644 --- a/src/code_8066D04.c +++ b/src/code_8066D04.c @@ -282,7 +282,7 @@ void HandleUseItemAction(Entity *param_1) void HandlePlaceItemAction(Entity *param_1) { Item *item; - Tile *tile; + const Tile *tile; EntityInfo *info; #ifndef NONMATCHING register Entity *entity asm("r4"); diff --git a/src/code_806CD90.c b/src/code_806CD90.c index e16c9d267..4bfc23693 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -237,7 +237,7 @@ void sub_806CF60(void) u32 sub_806CF98(Entity *entity) { - struct Tile *mapTile; + const Tile *mapTile; u32 shadowSize; u16 terrainType; EntityInfo *entityInfo; diff --git a/src/code_80718D8.c b/src/code_80718D8.c index aed02349e..0b5b4c9f8 100644 --- a/src/code_80718D8.c +++ b/src/code_80718D8.c @@ -70,7 +70,7 @@ void GetPokemonLevelData(LevelData* a1, s32 _id, s32 level); // TODO: change to void sub_8071B48(void) { - struct Tile *tile; + const Tile *tile; struct Entity *entity2; struct Entity *entity; int index; diff --git a/src/code_8072B78.c b/src/code_8072B78.c index 7a96283c3..cee32ad69 100644 --- a/src/code_8072B78.c +++ b/src/code_8072B78.c @@ -100,7 +100,7 @@ static inline void fu(EntityInfo *entityInfo, s16 id) void sub_8072B78(Entity *pokemon, Entity *target, s16 id) { OpenedFile *file; - Tile *tile; + const Tile *tile; int index; s32 id_s32; EntityInfo *entityInfo; diff --git a/src/code_8075708.c b/src/code_8075708.c index c89b02c49..5eeefe47b 100644 --- a/src/code_8075708.c +++ b/src/code_8075708.c @@ -56,7 +56,7 @@ void sub_8075708(Entity *entity) { bool8 bVar1; bool8 bVar2; - Tile *tile; + const Tile *tile; Trap *trapData; Entity *trap; EntityInfo *info; @@ -121,7 +121,7 @@ void sub_8075708(Entity *entity) u32 sub_8075818(Entity *entity) { - struct Tile *tile; + const Tile *tile; EntityInfo *entityInfo; Entity *subEntity; Item *item; diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 68b97d534..81986f847 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -53,7 +53,7 @@ u8 sub_8083660(DungeonPos *); void sub_807CD9C(Entity *pokemon, Entity *target, u32 direction) { - Tile *tile; + const Tile *tile; int iVar8; bool8 flag; DungeonPos sp_0x18; @@ -370,7 +370,7 @@ void sub_807D3CC(Entity *param_1) bool8 ExposeTrap(s32 x,s32 y) { - Tile *tile; + const Tile *tile; Entity *trap; tile = GetTile(x,y); diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 1d22cc2ba..2ed23d4f9 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -399,7 +399,7 @@ s32 AIConsiderMove(struct AIPossibleMove *aiPossibleMove, Entity *pokemon, Move { // Double assignment to fix a regswap. s16 rangeTargetingFlags = rangeTargetingFlags2 = targetingFlags & 0xF0; - struct Tile *adjacentTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[i].x, + const Tile *adjacentTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[i].x, pokemon->pos.y + gAdjacentTileOffsets[i].y); Entity *adjacentPokemon = adjacentTile->monster; if (adjacentPokemon != NULL && GetEntityType(adjacentPokemon) == ENTITY_MONSTER) @@ -433,7 +433,7 @@ s32 AIConsiderMove(struct AIPossibleMove *aiPossibleMove, Entity *pokemon, Move { for (i = 0; i < NUM_DIRECTIONS; i++) { - struct Tile *targetTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[i].x, + const Tile *targetTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[i].x, pokemon->pos.y + gAdjacentTileOffsets[i].y); if (CanAttackInDirection(pokemon, i)) { @@ -917,7 +917,7 @@ bool8 IsTargetInRange(Entity *pokemon, Entity *targetPokemon, s32 direction, s32 s32 i; for (i = 0; i <= effectiveMaxRange; i++) { - struct Tile *mapTile; + const Tile *mapTile; currentPosX += adjacentTileOffsetX; currentPosY += adjacentTileOffsetY; if (currentPosX <= 0 || currentPosY <= 0 || diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c index 5ee42ce9f..c6b036c7b 100644 --- a/src/dungeon_ai_item_weight.c +++ b/src/dungeon_ai_item_weight.c @@ -448,7 +448,7 @@ bool8 IsAdjacentToEnemy(Entity *pokemon) s32 direction; for (direction = 0; direction < NUM_DIRECTIONS; direction++) { - struct Tile *mapTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[direction].x, pokemon->pos.y + gAdjacentTileOffsets[direction].y); + const Tile *mapTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[direction].x, pokemon->pos.y + gAdjacentTileOffsets[direction].y); Entity *adjacentPokemon = mapTile->monster; if (adjacentPokemon != NULL && GetEntityType(adjacentPokemon) != ENTITY_NOTHING && GetTreatmentBetweenMonsters(pokemon, adjacentPokemon, FALSE, TRUE) == TREATMENT_TREAT_AS_ENEMY) diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 09a5934f7..6f1685096 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -156,7 +156,7 @@ void AIDecideUseItem(Entity *pokemon) else if (toolboxIndex == 0) { // This seems unused. toolboxIndex can never be 0. - struct Tile *mapTile = GetTile(pokemon->pos.x, pokemon->pos.y); + const Tile *mapTile = GetTile(pokemon->pos.x, pokemon->pos.y); Entity *object = mapTile->object; if (object != null) { diff --git a/src/dungeon_ai_movement.c b/src/dungeon_ai_movement.c index e6e435246..64f095c17 100644 --- a/src/dungeon_ai_movement.c +++ b/src/dungeon_ai_movement.c @@ -104,7 +104,7 @@ void AIMovement(Entity *pokemon, bool8 showRunAwayEffect) bool8 CanTakeItem(Entity *pokemon) { EntityInfo *pokemonInfo = GetEntInfo(pokemon); - struct Tile *mapTile; + const Tile *mapTile; Entity *object; if (!EntityExists(pokemon) || CheckVariousConditions(pokemon)) { @@ -310,7 +310,7 @@ bool8 ChooseTargetPosition(Entity *pokemon) { for (x = minX; x <= maxX; x++) { - Entity *object = GetTileSafe(x, y)->object; + Entity *object = GetTileMut(x, y)->object; if (object && GetEntityType(object) == ENTITY_ITEM) { pokemonInfo->aiTarget.aiObjective = AI_TAKE_ITEM; @@ -553,7 +553,7 @@ bool8 AvoidEnemies(Entity *pokemon) { if (room == closestTargetRoom && room != CORRIDOR_ROOM) { - struct Tile *tile = GetTile(pokemon->pos.x, pokemon->pos.y); + const Tile *tile = GetTile(pokemon->pos.x, pokemon->pos.y); if (tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) { DungeonPos aiTargetPos; @@ -563,7 +563,7 @@ bool8 AvoidEnemies(Entity *pokemon) // Scan for a direction leading outside the room. for (targetDir = 0; targetDir < NUM_DIRECTIONS; targetDir++) { - struct Tile *adjacentTile; + const Tile *adjacentTile; aiTargetPos.x = pokemon->pos.x + gAdjacentTileOffsets[targetDir].x; aiTargetPos.y = pokemon->pos.y + gAdjacentTileOffsets[targetDir].y; adjacentTile = GetTile(aiTargetPos.x, aiTargetPos.y); diff --git a/src/dungeon_ai_targeting.c b/src/dungeon_ai_targeting.c index 1088795b3..760dda6e9 100644 --- a/src/dungeon_ai_targeting.c +++ b/src/dungeon_ai_targeting.c @@ -65,7 +65,7 @@ const u8 gTreatmentData[3][2][2][2] = { bool8 sub_8070F3C(Entity * pokemon, DungeonPos *pos, s32 direction) { u8 terrain; - struct Tile *tile; + const Tile *tile; terrain = GetCrossableTerrain(GetEntInfo(pokemon)->id); @@ -109,7 +109,7 @@ bool8 sub_8070F3C(Entity * pokemon, DungeonPos *pos, s32 direction) bool8 sub_8070F14(Entity * pokemon, s32 direction) { - struct Tile *tile; + const Tile *tile; tile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[direction].x, pokemon->pos.y + gAdjacentTileOffsets[direction].y); @@ -128,7 +128,7 @@ bool8 sub_8070F14(Entity * pokemon, s32 direction) bool8 sub_8070F80(Entity * pokemon, s32 direction) { u8 terrain; - struct Tile *tile; + const Tile *tile; terrain = GetCrossableTerrain(GetEntInfo(pokemon)->id); @@ -173,7 +173,7 @@ bool8 sub_8070F80(Entity * pokemon, s32 direction) bool8 sub_8071058(Entity * pokemon, s32 direction) { u8 terrain; - struct Tile *tile; + const Tile *tile; terrain = GetCrossableTerrain(GetEntInfo(pokemon)->id); @@ -218,7 +218,7 @@ bool8 sub_8071058(Entity * pokemon, s32 direction) bool8 CanAttackInDirection(Entity *pokemon, s32 direction) { u8 crossableTerrain = GetCrossableTerrain(GetEntInfo(pokemon)->id); - struct Tile *tile; + const Tile *tile; if (crossableTerrain < CROSSABLE_TERRAIN_CREVICE) { crossableTerrain = CROSSABLE_TERRAIN_CREVICE; @@ -265,7 +265,8 @@ bool8 CanAttackInDirection(Entity *pokemon, s32 direction) bool8 CanAIMonsterMoveInDirection(Entity *pokemon, s32 direction, bool8 *pokemonInFront) { u8 crossableTerrain = GetCrossableTerrain(GetEntInfo(pokemon)->id); - struct Tile *frontTile, *currentTile; + const Tile *currentTile; + const Tile *frontTile; *pokemonInFront = FALSE; frontTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[direction].x, pokemon->pos.y + gAdjacentTileOffsets[direction].y); @@ -365,7 +366,7 @@ bool8 IsAtJunction(Entity *pokemon) } else { - struct Tile *mapTile; + const Tile *mapTile; char walkableNeighborFlags; if (gDungeonWaterType[gDungeon->tileset] == DUNGEON_WATER_TYPE_LAVA && crossableTerrain == CROSSABLE_TERRAIN_LIQUID diff --git a/src/dungeon_capabilities.c b/src/dungeon_capabilities.c index 94985585a..4c9dcc716 100644 --- a/src/dungeon_capabilities.c +++ b/src/dungeon_capabilities.c @@ -132,7 +132,7 @@ bool8 CannotAttack(Entity *pokemon, bool8 skipSleep) bool8 CanMoveInDirection(Entity *pokemon, u32 direction) { u8 crossableTerrain = GetCrossableTerrain(GetEntInfo(pokemon)->id); - struct Tile *currentMapTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[direction].x, + const Tile *currentMapTile = GetTile(pokemon->pos.x + gAdjacentTileOffsets[direction].x, pokemon->pos.y + gAdjacentTileOffsets[direction].y); if (currentMapTile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL || currentMapTile->monster != NULL) diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index 0a08d442f..597bf11f6 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -3828,7 +3828,7 @@ void sub_808B1CC(u8 itemID) pos.y = entity->pos.y; } sub_807FE04(&pos, 0); - tile = GetTileSafe(pos.x, pos.y); + tile = GetTileMut(pos.x, pos.y); tile->terrainType = tile->terrainType | TERRAIN_TYPE_STAIRS; if (((itemID != ITEM_NOTHING) && (sub_80860A8(itemID) == 0)) && (sub_80860A8(ITEM_MUSIC_BOX) == 0)) { @@ -4060,7 +4060,7 @@ void JirachiWish(void) } pos1.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1); pos1.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1); - if ((GetTileSafe(pos1.x, pos1.y)->terrainType & 3) != 0) { + if ((GetTileMut(pos1.x, pos1.y)->terrainType & 3) != 0) { PlaySoundEffect(0x14c); sub_808BB3C(&pos1); sub_8046860(jirachiEntity,&pos1,auStack152,9); @@ -4086,7 +4086,7 @@ void JirachiWish(void) pos2.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1); pos2.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1); - if ((GetTileSafe(pos2.x, pos2.y)->terrainType & 3) != 0) { + if ((GetTileMut(pos2.x, pos2.y)->terrainType & 3) != 0) { PlaySoundEffect(400); sub_808BB3C(&pos2); sub_8046860(jirachiEntity,&pos2,itemStack,9); @@ -4140,7 +4140,7 @@ void JirachiWish(void) pos3.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1); pos3.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1); - if ((GetTileSafe(pos3.x, pos3.y)->terrainType & 3) != 0) { + if ((GetTileMut(pos3.x, pos3.y)->terrainType & 3) != 0) { PlaySoundEffect(400); sub_808BB3C(&pos3); sub_8046860(jirachiEntity,&pos3,strengthItems,4); @@ -4303,9 +4303,9 @@ void JirachiWishGrantDialogue(Entity *jirachiEntity) // Warp Tile is created but not enabled until the Wish is done with EnableJirachiWishWarpTile void CreateJirachiWishWarpTile(void) { - struct Tile *tile; + Tile *tile; - tile = GetTileSafe(gDungeon->unkE220[7].x, gDungeon->unkE220[7].y); + tile = GetTileMut(gDungeon->unkE220[7].x, gDungeon->unkE220[7].y); tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); tile->terrainType |= TERRAIN_TYPE_IMPASSABLE_WALL; tile->terrainType &= ~TERRAIN_TYPE_STAIRS; @@ -4317,9 +4317,9 @@ void CreateJirachiWishWarpTile(void) void EnableJirachiWishWarpTile(void) { - struct Tile *tile; + Tile *tile; - tile = GetTileSafe(gDungeon->unkE220[7].x, gDungeon->unkE220[7].y); + tile = GetTileMut(gDungeon->unkE220[7].x, gDungeon->unkE220[7].y); tile->terrainType &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); tile->terrainType |= TERRAIN_TYPE_NORMAL; tile->terrainType &= ~TERRAIN_TYPE_IMPASSABLE_WALL; diff --git a/src/dungeon_map_access.c b/src/dungeon_map_access.c index 98561554d..37a903e8c 100644 --- a/src/dungeon_map_access.c +++ b/src/dungeon_map_access.c @@ -16,8 +16,8 @@ #include "game_options.h" #include "dungeon_visibility.h" -extern unkStruct_202F190 gUnknown_80F69D4; -extern unkStruct_202F190 gUnknown_80F69EC; +extern const unkStruct_202F190 gUnknown_80F69D4; +extern const unkStruct_202F190 gUnknown_80F69EC; extern u8 gUnknown_80F6A04[]; extern u8 gUnknown_80F6A10[]; extern u8 gUnknown_80F6A28[]; @@ -32,9 +32,9 @@ extern const s16 gUnknown_80F6C06[]; EWRAM_DATA OpenedFile *gDungeonPaletteFile = {0}; EWRAM_DATA unkStruct_202EE8C gUnknown_202EE8C[32] = {0}; EWRAM_DATA OpenedFile *gUnknown_202F18C = {0}; -EWRAM_DATA unkStruct_202F190 gUnknown_202F190 = {0}; +EWRAM_DATA unkStruct_202F190 gOutOfBoundsTileData = {0}; -EWRAM_DATA_2 unkStruct_202F190 *gUnknown_203B430 = {0}; +EWRAM_DATA_2 const unkStruct_202F190 *gUnknown_203B430 = {0}; extern u8 sub_8043CE4(u32); extern void sub_80402AC(s32, s32); @@ -42,7 +42,7 @@ extern int sprintf(char *, const char *, ...); void sub_8049BB0(s32, s32); void sub_80498A8(s32, s32); -Tile *GetTile(s32 x, s32 y) +const Tile *GetTile(s32 x, s32 y) { if (x >= 0 && y >= 0 && x < DUNGEON_MAX_SIZE_X && y < DUNGEON_MAX_SIZE_Y) { @@ -51,12 +51,12 @@ Tile *GetTile(s32 x, s32 y) return (Tile *) gUnknown_203B430->unk0; } -Tile *GetTileSafe(s32 x, s32 y) +Tile *GetTileMut(s32 x, s32 y) { if (x < 0 || y < 0 || x >= DUNGEON_MAX_SIZE_X || y >= DUNGEON_MAX_SIZE_Y) { - Tile *tile = (Tile *) gUnknown_202F190.unk0; - gUnknown_202F190 = *gUnknown_203B430; + Tile *tile = (Tile *) gOutOfBoundsTileData.unk0; + gOutOfBoundsTileData = *gUnknown_203B430; return tile; } return gDungeon->tilePointers[y][x]; @@ -190,10 +190,10 @@ void sub_80498A8(int x,int y) sp_0x20 = GetTile(x, y)->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); if (gDungeon->tileset >= 0x40) { if ((0x17 >= x) && (0x17 >= y)) { - GetTileSafe(x,y)->unk8 = gDungeon->unk12C24[y * 0x18 + x]; + GetTileMut(x,y)->unk8 = gDungeon->unk12C24[y * 0x18 + x]; } else { - GetTileSafe(x,y)->unk8 = 0; + GetTileMut(x,y)->unk8 = 0; } } else @@ -325,7 +325,7 @@ void sub_80498A8(int x,int y) if (IsBossFight()) { r4 = 0; } - GetTileSafe(x,y)->unk8 = gDungeon->unk12C24[r4 + r7 * 3]; + GetTileMut(x,y)->unk8 = gDungeon->unk12C24[r4 + r7 * 3]; } } @@ -436,17 +436,17 @@ void sub_8049BB0(s32 x, s32 y) if (y > 29) flags[CROSSABLE_TERRAIN_WALL] &= ~(0x80 | 0x1 | 0x2); - GetTileSafe(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_REGULAR] = flags[CROSSABLE_TERRAIN_REGULAR]; - GetTileSafe(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_LIQUID] = flags[CROSSABLE_TERRAIN_LIQUID]; - GetTileSafe(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_CREVICE] = flags[CROSSABLE_TERRAIN_CREVICE]; - GetTileSafe(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_WALL] = flags[CROSSABLE_TERRAIN_WALL]; + GetTileMut(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_REGULAR] = flags[CROSSABLE_TERRAIN_REGULAR]; + GetTileMut(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_LIQUID] = flags[CROSSABLE_TERRAIN_LIQUID]; + GetTileMut(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_CREVICE] = flags[CROSSABLE_TERRAIN_CREVICE]; + GetTileMut(x, y)->walkableNeighborFlags[CROSSABLE_TERRAIN_WALL] = flags[CROSSABLE_TERRAIN_WALL]; } void sub_8049ED4(void) { bool32 hallucinating, unk1820F; u16 *src; - Tile *tile; + const Tile *tile; s32 r7; s32 i; s32 r10; @@ -562,7 +562,7 @@ void sub_8049ED4(void) void sub_804A1F0(s32 a0, s32 a1) { - Tile *tile; + const Tile *tile; u16 *src; bool32 hallucinating, unk1820F; s32 xTemp, yTemp; @@ -664,7 +664,7 @@ void sub_804A1F0(s32 a0, s32 a1) void sub_804A49C(s32 a0, s32 a1) { - Tile *tile; + const Tile *tile; u16 *src; bool32 hallucinating, unk1820F; s32 xTemp, yTemp; @@ -906,12 +906,12 @@ void sub_804AAAC(void) { s32 x; s32 y; - struct Tile *tile; + Tile *tile; for(y = 0; y < DUNGEON_MAX_SIZE_Y; y++) { for(x = 0; x < DUNGEON_MAX_SIZE_X; x++) { - tile = GetTileSafe(x,y); + tile = GetTileMut(x,y); tile->unk4 = 0; } } @@ -919,7 +919,7 @@ void sub_804AAAC(void) void sub_804AAD4(void) { - struct Tile *tile; + const Tile *tile; struct RoomData *room1; struct RoomData *room2; s32 roomIndex; @@ -986,8 +986,8 @@ void sub_804AAD4(void) void sub_804AC20(DungeonPos *pos) { s32 y; - struct Tile *tile2; - struct Tile *tile; + const Tile *tile2; + Tile *tile; s32 yMax; u32 visibilityRange; s32 xMin; @@ -1023,7 +1023,7 @@ void sub_804AC20(DungeonPos *pos) } for (y = yMin; y <= yMax; y++) { for (x = xMin; x <= xMax; x++) { - tile = GetTileSafe(x,y); + tile = GetTileMut(x,y); tile->unk4 = tile->unk4 | 3; sub_80402AC(x,y); } diff --git a/src/dungeon_move.c b/src/dungeon_move.c index d474afabd..6c0898b1a 100644 --- a/src/dungeon_move.c +++ b/src/dungeon_move.c @@ -2577,7 +2577,7 @@ void sub_80566F8(Entity *attacker, Move *move, s32 a2, bool8 a3, s32 itemId, s32 var_48 = gAdjacentTileOffsets[attackerInfo->action.direction].y; for (i = 0; i < a2; i++) { - Tile *tile; + const Tile *tile; if (var_68.x < 0 || var_68.y < 0 || var_68.x > 55 || var_68.y > 31) break; @@ -2622,7 +2622,7 @@ void sub_80566F8(Entity *attacker, Move *move, s32 a2, bool8 a3, s32 itemId, s32 for (i = 0; i < a2; i++) { DungeonPos var_68Before; - Tile *tile; + const Tile *tile; if (var_68.x < 0 || var_68.y < 0 || var_68.x > 55 || var_68.y > 31) break; diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c index 70442bfbe..bd072f1d6 100644 --- a/src/dungeon_movement.c +++ b/src/dungeon_movement.c @@ -38,7 +38,7 @@ u8 GetCrossableTerrain(s16 species) } } -u8 sub_807034C(s16 id, struct Tile *tile) +u8 sub_807034C(s16 id, const Tile *tile) { s32 crossableTerrain; u16 tileFlags; @@ -68,7 +68,7 @@ u8 sub_807034C(s16 id, struct Tile *tile) u8 sub_80703A0(Entity *pokemon, DungeonPos *pos) { - struct Tile *tile; + const Tile *tile; u8 crossableTerrain; u16 tileFlags; EntityInfo *entityInfo; @@ -131,7 +131,7 @@ bool8 CanCrossWalls(Entity *pokemon) bool8 sub_807049C(Entity *pokemon, DungeonPos *pos) { s32 crossableTerrain; - struct Tile *tile; + const Tile *tile; u16 tileFlags; EntityInfo *entityInfo; @@ -173,7 +173,7 @@ bool8 sub_807049C(Entity *pokemon, DungeonPos *pos) bool8 sub_8070564(Entity *pokemon, DungeonPos *pos) { u8 crossableTerrain; - struct Tile *tile; + const Tile *tile; u16 tileFlags; EntityInfo *entityInfo; #ifndef NONMATCHING @@ -219,7 +219,7 @@ bool8 sub_8070564(Entity *pokemon, DungeonPos *pos) bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos) { s32 crossableTerrain; - struct Tile *tile; + const Tile *tile; u16 tileFlags; EntityInfo *entityInfo; @@ -259,7 +259,7 @@ bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos) bool8 sub_80706A4(Entity *pokemon, DungeonPos *pos) { s32 crossableTerrain; - struct Tile *tile; + const Tile *tile; u16 tileFlags; EntityInfo *entityInfo; diff --git a/src/dungeon_range.c b/src/dungeon_range.c index f06338f4a..1c933b0b3 100644 --- a/src/dungeon_range.c +++ b/src/dungeon_range.c @@ -9,7 +9,7 @@ bool8 IsPositionActuallyInSight(DungeonPos *pos1, DungeonPos *pos2) { u8 pos1Room; u8 visibility = gDungeon->unk181e8.visibilityRange; - struct Tile *tile1; + const Tile *tile1; if (visibility == 0) { visibility = 2; @@ -49,7 +49,7 @@ bool8 IsPositionActuallyInSight(DungeonPos *pos1, DungeonPos *pos2) bool8 IsPositionInSight(DungeonPos *pos1, DungeonPos *pos2) { - struct Tile *tile; + const Tile *tile; u8 pos1Room; s32 xDiff; s32 yDiff; @@ -99,7 +99,7 @@ returnFalse: void sub_80833E8(DungeonPos *param_1, s32 *param_2) { - struct Tile *tile; + const Tile *tile; struct RoomData *mapRoom; u32 visibility; u32 room; @@ -128,7 +128,7 @@ void sub_80833E8(DungeonPos *param_1, s32 *param_2) bool8 IsTargetTwoTilesAway(DungeonPos *pos1, DungeonPos *pos2) { s32 i; - struct Tile *tile; + const Tile *tile; s32 diff; s32 x1; s32 y1; diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index 2e290f492..e3f42f5f6 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -910,7 +910,7 @@ static void ReadDungeonTraps(DataSerializer *seri) ReadTilePos(seri, &pos); if (trapID != 0xFF) { - tile = GetTileSafe(pos.x, pos.y); + tile = GetTileMut(pos.x, pos.y); entity = sub_8045684(trapID, &pos, unk1); if (entity) { tile->object = entity; @@ -1090,7 +1090,7 @@ static void ReadMonster(DataSerializer *seri, bool8 isTeamMember, s32 index) if (mon != NULL) { monEntInfo = GetEntInfo(mon); - tile = GetTileSafe(monPos.x, monPos.y); + tile = GetTileMut(monPos.x, monPos.y); mon->prevPos = monPos; mon->pos = monPos; tile->monster = mon; @@ -1255,7 +1255,7 @@ void sub_8082B40(void) sub_806CCB4(entity, sub_806CEBC(entity)); pos = entity->pos; AddPokemonDungeonSprite(info->unk98, info->apparentID, &pos, 3); - entity->room = GetTileSafe(entity->pos.x, entity->pos.y)->room; + entity->room = GetTileMut(entity->pos.x, entity->pos.y)->room; } } } diff --git a/src/dungeon_util.c b/src/dungeon_util.c index 096b35346..b414cc1ac 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -65,14 +65,14 @@ Item* GetItemData_1(Entity *entity) return entity->axObj.info.item; } -Tile *GetTileAtEntity(Entity *entity) +const Tile *GetTileAtEntity(Entity *entity) { return GetTile(entity->pos.x, entity->pos.y); } Tile *GetTileAtEntitySafe(Entity *entity) { - return GetTileSafe(entity->pos.x, entity->pos.y); + return GetTileMut(entity->pos.x, entity->pos.y); } void sub_804513C(void) diff --git a/src/move_actions.c b/src/move_actions.c index 3226a0a5e..8543a2eb9 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -333,7 +333,7 @@ bool8 VitalThrowMoveAction(Entity * pokemon, Entity * target, Move *move, s32 pa bool8 DigMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param_4) { - struct Tile *tile; + Tile *tile; bool8 flag; flag = FALSE; @@ -2661,7 +2661,7 @@ bool8 sub_805A85C(Entity * pokemon, Entity * target, Move *move, u32 param_4) DungeonPos pos1; Move stackMove; PixelPos pos2; - struct Tile *tile; + Tile *tile; Entity *entity; s32 temp; s32 temp2; @@ -2704,7 +2704,7 @@ _0805A8C2: sub_803E46C(0x2c); } } - tile = GetTileSafe(pos1.x,pos1.y); + tile = GetTileMut(pos1.x,pos1.y); entity = tile->monster; if (entity != NULL) { if (GetEntityType(entity) == ENTITY_MONSTER) { diff --git a/src/move_checks.c b/src/move_checks.c index d955fc4aa..f45de8ee4 100644 --- a/src/move_checks.c +++ b/src/move_checks.c @@ -359,7 +359,7 @@ bool8 CanUseOnSelfWithStatusChecker(Entity *pokemon, Move *move) break; case MOVE_DIG: { - struct Tile *tile = GetTileAtEntitySafe(pokemon); + Tile *tile = GetTileAtEntitySafe(pokemon); if (!IsTileGround(tile) || (tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) != TERRAIN_TYPE_NORMAL) { return FALSE; diff --git a/src/move_effects_target.c b/src/move_effects_target.c index ec2624629..f34bd5771 100644 --- a/src/move_effects_target.c +++ b/src/move_effects_target.c @@ -468,8 +468,8 @@ void BurnedStatusTarget(Entity * pokemon, Entity * target, u8 param_3, bool8 dis bool8 isNotBurned; bool8 hasSynchronized; EntityInfo *entityInfo; - struct Tile *tile_1; - struct Tile *tile_2; + const Tile *tile_1; + const Tile *tile_2; Entity *entity; s32 index; @@ -556,7 +556,7 @@ void PoisonedStatusTarget(Entity * pokemon, Entity * target, bool8 displayMessag bool8 isNotPoisoned; bool8 hasSynchronized; EntityInfo *entityInfo; - struct Tile *tile; + const Tile *tile; Entity *entity; s32 index; @@ -645,7 +645,7 @@ void BadlyPoisonedStatusTarget(Entity * pokemon, Entity * target, bool8 displayM bool8 isNotBadlyPoisoned; bool8 hasSynchronized; EntityInfo *entityInfo; - struct Tile *tile; + const Tile *tile; Entity *entity; s32 index; @@ -725,7 +725,7 @@ void BadlyPoisonedStatusTarget(Entity * pokemon, Entity * target, bool8 displayM void FrozenStatusTarget(Entity * pokemon, Entity * target, bool8 displayMessage) { EntityInfo *entityInfo; - struct Tile *tile; + const Tile *tile; if (!EntityExists(target)) { return; diff --git a/src/status.c b/src/status.c index 4690c7e3d..03d770618 100644 --- a/src/status.c +++ b/src/status.c @@ -433,7 +433,7 @@ void CringeStatusTarget(Entity * pokemon,Entity * target, bool8 displayMessage) void ParalyzeStatusTarget(Entity * pokemon, Entity * target, bool8 displayMessage) { - struct Tile *mapTile; + const Tile *mapTile; EntityInfo *entityInfo; Entity *mapPokemonEntity; int index; diff --git a/src/status_actions.c b/src/status_actions.c index 8df3e799f..82c782218 100644 --- a/src/status_actions.c +++ b/src/status_actions.c @@ -940,7 +940,7 @@ bool8 sub_805BF34(Entity * pokemon, Entity * target, Move *move, s32 param_4) bool8 TrapbustOrbAction(Entity * pokemon,Entity * target, Move *move, s32 param_4) { - struct Tile *tile; + const Tile *tile; Entity *object; Trap *trapData; s32 bottomRightCornerX, bottomRightCornerY; @@ -972,7 +972,7 @@ bool8 TrapbustOrbAction(Entity * pokemon,Entity * target, Move *move, s32 param_ ++topLeftCornerY; --topLeftCornerY; for (xCoord = bottomRightCornerX; xCoord <= topLeftCornerX; xCoord++) { for (yCoord = bottomRightCornerY; yCoord <= topLeftCornerY; yCoord++) { - object = GetTileSafe(xCoord, yCoord)->object; + object = GetTileMut(xCoord, yCoord)->object; if (((object != 0) && (GetEntityType(object) == ENTITY_TRAP)) && (trapData = GetTrapData(object), trapData->id != TRAP_WONDER_TILE)) { pos.y = yCoord; @@ -1094,7 +1094,7 @@ bool8 sub_805C2A0(Entity *pokemon, Entity *target, Move *move, s32 param_4) bool8 FillInOrbAction(Entity *pokemon,Entity *target, Move *move, s32 param_4) { - struct Tile *tileToFill; + Tile *tileToFill; EntityInfo *targetInfo; int y; bool8 filledInTile; @@ -1114,7 +1114,7 @@ bool8 FillInOrbAction(Entity *pokemon,Entity *target, Move *move, s32 param_4) tileCoords.y = target->pos.y + gAdjacentTileOffsets[targetInfo->action.direction].y; sub_8042A54(&tileCoords); - tileToFill = GetTileSafe(tileCoords.x,tileCoords.y); + tileToFill = GetTileMut(tileCoords.x,tileCoords.y); if ((tileToFill->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == TERRAIN_TYPE_SECONDARY) { tileToFill->terrainType = (tileToFill->terrainType & ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) | TERRAIN_TYPE_NORMAL; diff --git a/src/tile_types.c b/src/tile_types.c index 440a643ae..f489665f8 100644 --- a/src/tile_types.c +++ b/src/tile_types.c @@ -91,7 +91,7 @@ void sub_8042A14(DungeonPos *); bool8 PosHasItem(DungeonPos *pos) { - struct Tile *tile; + const Tile *tile; Entity *entity; tile = GetTile(pos->x,pos->y); @@ -104,7 +104,7 @@ bool8 PosHasItem(DungeonPos *pos) Entity *GetMonsterAtPos(DungeonPos *pos) { - struct Tile *tile; + const Tile *tile; Entity *entity; tile = GetTile(pos->x,pos->y); @@ -117,7 +117,7 @@ Entity *GetMonsterAtPos(DungeonPos *pos) bool8 sub_804AD34(DungeonPos *pos) { - struct Tile *tile; + Tile *tile; s32 x; Entity * entity; s32 y; @@ -125,7 +125,7 @@ bool8 sub_804AD34(DungeonPos *pos) s32 index; iVar8 = 0; - tile = GetTileSafe(pos->x,pos->y); + tile = GetTileMut(pos->x,pos->y); if (!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) if(!(tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL))){ iVar8 = 1; @@ -157,13 +157,13 @@ bool8 sub_804AD34(DungeonPos *pos) bool8 sub_804AE08(DungeonPos *pos) { - struct Tile *tile; + Tile *tile; s32 x; s32 y; bool8 uVar6; uVar6 = FALSE; - tile = GetTileSafe(pos->x,pos->y); + tile = GetTileMut(pos->x,pos->y); if (!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) if(!(tile->terrainType & (TERRAIN_TYPE_UNK_8 | TERRAIN_TYPE_IMPASSABLE_WALL))) { @@ -184,13 +184,13 @@ bool8 sub_804AE08(DungeonPos *pos) void sub_804AE84(DungeonPos *pos) { - struct Tile *tile; + Tile *tile; s32 x; Entity * entity; s32 index; s32 y; - tile = GetTileSafe(pos->x,pos->y); + tile = GetTileMut(pos->x,pos->y); if ((tile->unk4 & 0x10) != 0) { tile->unk4 = tile->unk4 & 0xffef; diff --git a/src/trap.c b/src/trap.c index 2d51f8b40..71e798fdb 100644 --- a/src/trap.c +++ b/src/trap.c @@ -100,7 +100,7 @@ void sub_807FC3C(DungeonPos *pos, u32 trapID, u32 param_3) bool8 CanLayTrap(DungeonPos *pos) { - struct Tile *tile = GetTileSafe(pos->x, pos->y); + Tile *tile = GetTileMut(pos->x, pos->y); if (tile->terrainType & TERRAIN_TYPE_STAIRS || tile->room == CORRIDOR_ROOM || tile->terrainType & TERRAIN_TYPE_NATURAL_JUNCTION) @@ -126,7 +126,7 @@ bool8 LayTrap(DungeonPos *pos, u8 trapID, u8 param_3) int counter; u16 terrainType; - tile = GetTileSafe(pos->x, pos->y); + tile = GetTileMut(pos->x, pos->y); if (TRAP_SPIKE_TRAP < trapID) { counter = 0; while ((counter < 0x1e && (trapID = sub_803D6FC(), trapID == TRAP_WONDER_TILE))) { @@ -188,7 +188,7 @@ bool8 sub_807FE04(DungeonPos *pos, char param_2) { Tile *tile; - tile = GetTileSafe(pos->x,pos->y); + tile = GetTileMut(pos->x,pos->y); if ((tile->object != NULL) && (GetEntityType(tile->object) == ENTITY_TRAP)) { tile->object->type = 0; tile->object = NULL; @@ -204,7 +204,7 @@ bool8 sub_807FE04(DungeonPos *pos, char param_2) bool8 sub_807FE44(DungeonPos *pos, char param_2) { - Tile *tile; + const Tile *tile; tile = GetTile(pos->x,pos->y); if ((tile->object != NULL) && (GetEntityType(tile->object) == ENTITY_TRAP)) { @@ -236,7 +236,7 @@ void sub_807FE9C(Entity *pokemon, DungeonPos *pos, int param_3, char param_4) Entity *target; u8 *text; - tile = GetTileSafe(pos->x,pos->y); + tile = GetTileMut(pos->x,pos->y); entity = tile->object; flag1 = FALSE; if (entity == NULL) { diff --git a/tmp/gettile.cocci b/tmp/gettile.cocci new file mode 100644 index 000000000..ce7dc37b0 --- /dev/null +++ b/tmp/gettile.cocci @@ -0,0 +1,42 @@ +@ r1 disable optional_qualifier exists @ +identifier tile; +@@ +- Tile *tile; +++ const Tile *tile; + ... + tile = GetTile(...) +@ r2 disable optional_qualifier exists @ +identifier tile; +@@ +- Tile *tile +++ const Tile *tile + = GetTile(...); +@ decls disable optional_qualifier @ +identifier tile; +@@ +( + Tile *tile; +| + Tile *tile = ...; +) +@ mutated depends on decls exists @ +identifier decls.tile; +assignment operator op; +identifier f; +@@ +( + tile->f op ...; +| + f(<+... tile ...+>) +) +@ notmutated depends on decls && !mutated disable optional_qualifier @ +identifier decls.tile; +@@ +( +- Tile *tile; +++ const Tile *tile; +| +- Tile *tile +++ const Tile *tile + = ...; +) diff --git a/tmp/position.cocci b/tmp/position.cocci deleted file mode 100644 index ff2de880e..000000000 --- a/tmp/position.cocci +++ /dev/null @@ -1,17 +0,0 @@ -@@ -typedef Position; -@@ -- struct Position -+ Position -@@ -typedef Position32; -typedef PixelPos; -@@ -- Position32 -+ PixelPos -@@ -typedef Position; -typedef DungeonPos; -@@ -- Position -+ DungeonPos From 9ab3ae9aaa82fd3c80ae290fb36d99e98eeb1327 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Wed, 13 Nov 2024 19:36:23 +0100 Subject: [PATCH 09/12] Math refactoring/cleanup --- asm/code_800F990.s | 4 +- include/math.h | 2 +- include/number_util.h | 7 ++ src/code_806FDF4.c | 2 +- src/code_8077274_1.c | 4 +- src/data/math.h | 10 ++- src/math.c | 159 +++++++++++++++++++++--------------------- tmp/gettile.cocci | 42 ----------- 8 files changed, 96 insertions(+), 134 deletions(-) delete mode 100644 tmp/gettile.cocci diff --git a/asm/code_800F990.s b/asm/code_800F990.s index 1fa0545f6..711c1a5d2 100644 --- a/asm/code_800F990.s +++ b/asm/code_800F990.s @@ -609,7 +609,7 @@ _0800FE3C: lsls r0, 8 str r0, [sp, 0x10] add r0, sp, 0xC - bl sub_800A0B0 + bl Atan2_4096 adds r2, r0, 0 ldr r0, [sp, 0xC] cmp r0, 0 @@ -1294,7 +1294,7 @@ _08010392: str r0, [sp, 0xC] str r3, [sp, 0x10] add r0, sp, 0xC - bl sub_800A0B0 + bl Atan2_4096 ldr r1, _08010474 adds r3, r0, r1 cmp r3, 0 diff --git a/include/math.h b/include/math.h index 2fdb563ec..74f659d2d 100644 --- a/include/math.h +++ b/include/math.h @@ -41,7 +41,7 @@ void F48_16_SDiv(s48_16 *dst, s48_16 *a, s48_16 *b); void F48_16_SMul(s48_16 *dst, s48_16 *a, s48_16 *b); s24_8 FP24_8_Hypot(s24_8 x, s24_8 y); -void FP48_16_FromS32(s48_16 *dst, u32); +void FP48_16_FromS32(s48_16 *dst, s32 src); u32 FP48_16_ToS32(s48_16 *a); void FP48_16_FromF248(s48_16 *a, s24_8 b); bool8 FP48_16_SLessThan(s48_16 *a, s48_16 *b); diff --git a/include/number_util.h b/include/number_util.h index d2e6741ed..ed5c06d0e 100644 --- a/include/number_util.h +++ b/include/number_util.h @@ -22,6 +22,10 @@ typedef struct s24_8 { s32 raw; } s24_8; +#define F248_ZERO ((s24_8){}) +#define F248_ONE ((s24_8){0x100}) +#define F248_MAX ((s24_8){0x7FFFFFFF}) + /** * This type represents a signed 48.16 fixed-point number, where the 48 most * significant bits are the integer part and the 16 least significant bits are @@ -32,6 +36,9 @@ typedef struct s48_16 s32 hi; u32 lo; // some math.c funcs require this to be a u32, but other funcs check if it's negative (aka >= INT32_MAX) } s48_16; +#define F4816_ZERO ((s48_16){}) +#define F4816_ONE ((s48_16){0, 0x10000}) +#define F4816_MAX ((s48_16){0x7FFFFFFF, 0xFFFFFFFF}) FixedPoint FixedPoint_Add(FixedPoint a, FixedPoint b); FixedPoint FixedPoint_Subtract(FixedPoint a, FixedPoint b); diff --git a/src/code_806FDF4.c b/src/code_806FDF4.c index 553ffa59b..134ea7ce6 100644 --- a/src/code_806FDF4.c +++ b/src/code_806FDF4.c @@ -133,7 +133,7 @@ void sub_806F500(void) temp->unk140[6] = 0; temp->unk150 = 0; temp->unk158 = 0; - temp->unk15C = IntToF248(0); + temp->unk15C = F248_ZERO; temp->unk160 = 0; temp->unk161 = 0; temp->unk162 = 0; diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index 51b78451a..98a093482 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -1027,11 +1027,11 @@ void sub_8079E34(Entity * pokemon, Entity * target, bool8 param_3) statChanged = TRUE; } if (!F248EqualsInt(entityInfo->offensiveMultipliers[index], 1)) { - entityInfo->offensiveMultipliers[index] = IntToF248(1); + entityInfo->offensiveMultipliers[index] = F248_ONE; statChanged = TRUE; } if (!F248EqualsInt(entityInfo->defensiveMultipliers[index], 1)) { - entityInfo->defensiveMultipliers[index] = IntToF248(1); + entityInfo->defensiveMultipliers[index] = F248_ONE; statChanged = TRUE; } } diff --git a/src/data/math.h b/src/data/math.h index b563999e1..fff6c880d 100644 --- a/src/data/math.h +++ b/src/data/math.h @@ -1,5 +1,3 @@ -// gFastMod3Lookup - const u8 gFastMod3Lookup[0x100] = { 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0 }; @@ -9,8 +7,8 @@ const u8 gFastDiv3Lookup[0x100] = { }; -// gFastSinLookup[i] = floor(256 * sin(iπ / 2048)) -static const s16 gFastSinLookup[] = { +// sFastSinLookup[i] = floor(256 * sin(iπ / 2048)) +static const s16 sFastSinLookup[] = { 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, @@ -141,8 +139,8 @@ static const s16 gFastSinLookup[] = { 255, 255, 255, 255, 255, 255, 255, 255, }; - -const u32 gFastUnknownFn1Lookup[] = { +// sFastAtan2Lookup256[256*y/x] = atan2(x,y) for x>y>=0, in units of 2π/256 +static const u32 sFastAtan2Lookup256[] = { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, diff --git a/src/math.c b/src/math.c index a63c1cf94..1f43fec47 100644 --- a/src/math.c +++ b/src/math.c @@ -3,6 +3,7 @@ #include "math.h" #include "data/math.h" +#include "structs/str_position.h" static void F48_16_UDiv(s48_16 *, s48_16 *, s48_16 *); static void F48_16_UMul(s48_16 *, s48_16 *, s48_16 *); @@ -32,13 +33,13 @@ s32 sin_4096(s32 x) { switch (x & 0xc00) { case 0x000: - return gFastSinLookup[x & 0x3ff]; + return sFastSinLookup[x & 0x3ff]; case 0x400: - return gFastSinLookup[0x3ff - (x & 0x3ff)]; + return sFastSinLookup[0x3ff - (x & 0x3ff)]; case 0x800: - return -gFastSinLookup[x & 0x3ff]; + return -sFastSinLookup[x & 0x3ff]; case 0xc00: - return -gFastSinLookup[0x3ff - (x & 0x3ff)]; + return -sFastSinLookup[0x3ff - (x & 0x3ff)]; } return 0; @@ -48,13 +49,13 @@ s32 cos_4096(s32 x) { switch (x & 0xc00) { case 0x000: - return gFastSinLookup[0x3ff - (x & 0x3ff)]; + return sFastSinLookup[0x3ff - (x & 0x3ff)]; case 0x400: - return -gFastSinLookup[x & 0x3ff]; + return -sFastSinLookup[x & 0x3ff]; case 0x800: - return -gFastSinLookup[0x3ff - (x & 0x3ff)]; + return -sFastSinLookup[0x3ff - (x & 0x3ff)]; case 0xc00: - return gFastSinLookup[x & 0x3ff]; + return sFastSinLookup[x & 0x3ff]; } return 0; @@ -172,7 +173,7 @@ static s24_8 u24_8_mul(s24_8 x, s24_8 y) u32 round_up; if (x.raw == 0 || y.raw == 0) - return (s24_8){0}; + return F248_ZERO; x_h = 0; x_l = x.raw; @@ -241,10 +242,10 @@ static s24_8 u24_8_div(s24_8 x, s24_8 y) s32 temp; if (y.raw == 0) - return (s24_8){INT32_MAX}; + return F248_MAX; if (x.raw == 0) - return (s24_8){0}; + return F248_ZERO; r7 = (u32)x.raw >> 24; r6 = x.raw << 8; @@ -298,7 +299,7 @@ UNUSED s24_8 FP24_8_Pow(s24_8 x, s32 y) if (uVar1 < 0) uVar1 = -uVar1; - sVar1 = IntToF248(1); + sVar1 = F248_ONE; for (; uVar1 != 0; uVar1 >>= 1) { if (uVar1 & 1) @@ -310,7 +311,7 @@ UNUSED s24_8 FP24_8_Pow(s24_8 x, s32 y) if (y >= 0) return sVar1; - return s24_8_div(IntToF248(1), sVar1); + return s24_8_div(F248_ONE, sVar1); } s24_8 FP24_8_Hypot(s24_8 x, s24_8 y) @@ -348,21 +349,18 @@ s24_8 FP24_8_Hypot(s24_8 x, s24_8 y) return r5; } -void FP48_16_FromS32(s48_16 *param_1, u32 param_2) +void FP48_16_FromS32(s48_16 *dst, s32 src) { -#ifndef NONMATCHING - register u32 temp asm("r4"); + dst->hi = (src & ~0xFFFFu) >> 16; + dst->lo = (src & 0xFFFFu) << 16; + + // BUG: Should be checking top bit of src, or using dst->hi here (see FP48_16_FromF248) +#ifdef BUGFIX + if (dst->hi & 0x8000) #else - u32 temp; + if (src & 0x8000) #endif - - temp = 0xFFFF0000; - param_1->hi = param_2 >> 16; - param_1->lo = param_2 << 16; - - if (param_2 & 0x8000) - param_1->hi |= temp; - + dst->hi |= ~0xFFFF; } u32 FP48_16_ToS32(s48_16 *a) @@ -398,118 +396,119 @@ void FP48_16_FromF248(s48_16 *a, s24_8 b) a->hi &= 0x7f; } -s32 sub_800A0B0(s48_16 *a) +// returns 12-bit angle +s32 Atan2_4096(PixelPos *a) { - s32 r2; - s32 r3; + s32 y; + s32 x; s32 idx; s32 divi; - r2 = a->lo; - r3 = a->hi; - if (r2 == 0 && r3 == 0) + y = a->y; + x = a->x; + if (y == 0 && x == 0) return 0; - if (r2 > 0) { - if (r3 > 0) { - if (r2 < r3) { - divi = r3 / 256; + if (y > 0) { + if (x > 0) { + if (y < x) { + divi = F248ToInt((s24_8){x}); if (divi == 0) return 0x200; - idx = r2 / divi; + idx = y / divi; if (idx > 0xFF) idx = 0xFF; - - return gFastUnknownFn1Lookup[idx] << 4; + + return sFastAtan2Lookup256[idx] << 4; } - else { // r2 >= r3 - divi = r2 / 256; + else { // y >= x + divi = F248ToInt((s24_8){y}); if (divi == 0) return 0x200; - idx = r3 / divi; + idx = x / divi; if (idx > 0xFF) idx = 0xFF; - - return (0x40 - gFastUnknownFn1Lookup[idx]) << 4; + + return (0x40 - sFastAtan2Lookup256[idx]) << 4; } } - else { // r3 <= 0 - r3 = -r3; - if (r2 < r3) { - divi = r3 / 256; + else { // x <= 0 + x = -x; + if (y < x) { + divi = F248ToInt((s24_8){x}); if (divi == 0) return 0x600; - idx = r2 / divi; + idx = y / divi; if (idx > 0xFF) idx = 0xFF; - - return (0x80 - gFastUnknownFn1Lookup[idx]) << 4; + + return (0x80 - sFastAtan2Lookup256[idx]) << 4; } - else { // r2 >= r3 - divi = r2 / 256; + else { // y >= x + divi = F248ToInt((s24_8){y}); if (divi == 0) return 0x600; - idx = r3 / divi; + idx = x / divi; if (idx > 0xFF) idx = 0xFF; - - return (gFastUnknownFn1Lookup[idx] + 0x40) << 4; + + return (sFastAtan2Lookup256[idx] + 0x40) << 4; } } } - else { // r2 <= 0 - r2 = -r2; - if (r3 > 0) { - if (r2 < r3) { - divi = r3 / 256; + else { // y <= 0 + y = -y; + if (x > 0) { + if (y < x) { + divi = F248ToInt((s24_8){x}); if (divi == 0) return 0xE00; - idx = r2 / divi; + idx = y / divi; if (idx > 0xFF) idx = 0xFF; - - return (0x100 - gFastUnknownFn1Lookup[idx]) << 4; + + return (0x100 - sFastAtan2Lookup256[idx]) << 4; } - else { // r2 >= r3 - divi = r2 / 256; + else { // y >= x + divi = F248ToInt((s24_8){y}); if (divi == 0) return 0xE00; - idx = r3 / divi; + idx = x / divi; if (idx > 0xFF) idx = 0xFF; - - return (gFastUnknownFn1Lookup[idx] + 0xC0) << 4; + + return (sFastAtan2Lookup256[idx] + 0xC0) << 4; } } - else { // r3 <= 0 - r3 = -r3; - if (r2 < r3) { - divi = r3 / 256; + else { // x <= 0 + x = -x; + if (y < x) { + divi = F248ToInt((s24_8){x}); if (divi == 0) return 0xA00; - idx = r2 / divi; + idx = y / divi; if (idx > 0xFF) idx = 0xFF; - - return (gFastUnknownFn1Lookup[idx] + 0x80) << 4; + + return (sFastAtan2Lookup256[idx] + 0x80) << 4; } - else { // r2 >= r3 - divi = r2 / 256; + else { // y >= x + divi = F248ToInt((s24_8){y}); if (divi == 0) return 0xA00; - idx = r3 / divi; + idx = x / divi; if (idx > 0xFF) idx = 0xFF; - - return (0xC0 - gFastUnknownFn1Lookup[idx]) << 4; + + return (0xC0 - sFastAtan2Lookup256[idx]) << 4; } } } diff --git a/tmp/gettile.cocci b/tmp/gettile.cocci deleted file mode 100644 index ce7dc37b0..000000000 --- a/tmp/gettile.cocci +++ /dev/null @@ -1,42 +0,0 @@ -@ r1 disable optional_qualifier exists @ -identifier tile; -@@ -- Tile *tile; -++ const Tile *tile; - ... - tile = GetTile(...) -@ r2 disable optional_qualifier exists @ -identifier tile; -@@ -- Tile *tile -++ const Tile *tile - = GetTile(...); -@ decls disable optional_qualifier @ -identifier tile; -@@ -( - Tile *tile; -| - Tile *tile = ...; -) -@ mutated depends on decls exists @ -identifier decls.tile; -assignment operator op; -identifier f; -@@ -( - tile->f op ...; -| - f(<+... tile ...+>) -) -@ notmutated depends on decls && !mutated disable optional_qualifier @ -identifier decls.tile; -@@ -( -- Tile *tile; -++ const Tile *tile; -| -- Tile *tile -++ const Tile *tile - = ...; -) From f8f076d14dc229dd6b69acd93b60811411285464 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Thu, 14 Nov 2024 23:00:15 +0100 Subject: [PATCH 10/12] Clean up some script stuff, based on blue ROM --- asm/ground_script.s | 81 ---------------------------------------- src/event_flag.c | 67 +++++++++++++++++---------------- src/ground_script_1.c | 18 +++++---- src/ground_script_2.c | 86 ++++++++++++++++++++----------------------- 4 files changed, 86 insertions(+), 166 deletions(-) diff --git a/asm/ground_script.s b/asm/ground_script.s index 6e5c25195..808df9384 100644 --- a/asm/ground_script.s +++ b/asm/ground_script.s @@ -1710,85 +1710,4 @@ _080A236C: bx r1 thumb_func_end sub_80A14E8 - thumb_func_start GroundScript_Unlock -GroundScript_Unlock: - push {r4-r7,lr} - ldr r1, _080A241C - ldrb r0, [r1] - cmp r0, 0 - beq _080A2414 - movs r0, 0 - strb r0, [r1] - movs r6, 0 -_080A2390: - ldr r0, _080A2420 - adds r7, r6, r0 - ldrb r0, [r7] - cmp r0, 0 - beq _080A240E - movs r0, 0x1 - ldr r1, _080A2424 - adds r2, r6, 0 - bl Log - lsls r5, r6, 16 - asrs r5, 16 - adds r0, r5, 0 - bl GroundMapNotifyAll - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - bl GroundLivesNotifyAll - orrs r4, r0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - bl GroundObjectsNotifyAll - orrs r4, r0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - bl GroundEffectsNotifyAll - orrs r4, r0 - lsls r4, 24 - lsrs r4, 24 - ldr r0, _080A2428 - adds r5, r6, r0 - ldrb r0, [r5] - cmp r0, 0 - beq _080A240C - cmp r4, 0 - beq _080A240E - movs r0, 0x80 - adds r4, r6, 0 - orrs r4, r0 - lsls r4, 16 - asrs r4, 16 - adds r0, r4, 0 - bl GroundMapNotifyAll - adds r0, r4, 0 - bl GroundLivesNotifyAll - adds r0, r4, 0 - bl GroundObjectsNotifyAll - adds r0, r4, 0 - bl GroundEffectsNotifyAll - movs r0, 0 - strb r0, [r5] -_080A240C: - strb r0, [r7] -_080A240E: - adds r6, 0x1 - cmp r6, 0x80 - ble _080A2390 -_080A2414: - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080A241C: .4byte gAnyScriptLocked -_080A2420: .4byte gScriptLocks -_080A2424: .4byte gUnknown_8116848 -_080A2428: .4byte gScriptLockConds - thumb_func_end GroundScript_Unlock - .align 2,0 diff --git a/src/event_flag.c b/src/event_flag.c index 4b7680007..3609feb8c 100644 --- a/src/event_flag.c +++ b/src/event_flag.c @@ -177,49 +177,54 @@ void ScenarioCalc(s16 param_1,s32 param_2,s32 param_3) } } -bool8 ScriptVarScenarioBefore(s16 param_1,u32 param_2,s32 param_3) +bool8 ScriptVarScenarioBefore(s16 varId,u32 pMain,s32 pSub) { - s32 uVar1; - s32 iVar2; - - uVar1 = GetScriptVarArrayValue(NULL,param_1,0); - iVar2 = GetScriptVarArrayValue(NULL,param_1,1); - if ((uVar1 != 0x3a) && - (uVar1 < param_2 || (param_3 >= 0 && (uVar1 == param_2) && (iVar2 < param_3)))) { + s32 sMain; + s32 sSub; + + sMain = GetScriptVarArrayValue(NULL, varId, 0); + sSub = GetScriptVarArrayValue(NULL, varId, 1); + if (sMain == 0x3a) { + // DS: Assert(FALSE, "debug mode scenario comp %3d %3d %3d", varId, pMain, pSub) + return FALSE; + } else if (sMain < pMain) { return TRUE; - } - else { + } else if (pSub >= 0 && sMain == pMain && sSub < pSub) { + return TRUE; + } else { return FALSE; } } -bool8 ScriptVarScenarioEqual(s16 param_1,u32 param_2,s32 param_3) +bool8 ScriptVarScenarioEqual(s16 varId,u32 pMain,s32 pSub) { - s32 uVar1; - s32 iVar2; - - uVar1 = GetScriptVarArrayValue(NULL, param_1, 0); - iVar2 = GetScriptVarArrayValue(NULL, param_1, 1); - if (((uVar1 == param_2 && (((param_3 < 0) || (iVar2 == param_3)))))) { - return TRUE; - } - else { - return FALSE; + s32 sMain; + s32 sSub; + + sMain = GetScriptVarArrayValue(NULL, varId, 0); + sSub = GetScriptVarArrayValue(NULL, varId, 1); + if (sMain == pMain) { + if (pSub < 0) return TRUE; + if (sSub == pSub) return TRUE; } + return FALSE; } -bool8 ScriptVarScenarioAfter(s16 param_1,u32 param_2,s32 param_3) +bool8 ScriptVarScenarioAfter(s16 varId,u32 pMain,s32 pSub) { - s32 uVar1; - s32 iVar2; - - uVar1 = GetScriptVarArrayValue(NULL, param_1, 0); - iVar2 = GetScriptVarArrayValue(NULL, param_1, 1); - if ((uVar1 != 0x3a) && - ((uVar1 > param_2 || (((param_3 >= 0 && (uVar1 == param_2)) && (iVar2 > param_3)))))) { + s32 sMain; + s32 sSub; + + sMain = GetScriptVarArrayValue(NULL, varId, 0); + sSub = GetScriptVarArrayValue(NULL, varId, 1); + if (sMain == 0x3a) { + // DS: Assert(FALSE, "debug mode scenario comp %3d %3d %3d", varId, pMain, pSub) + return FALSE; + } else if (sMain > pMain) { return TRUE; - } - else { + } else if (pSub >= 0 && sMain == pMain && sSub > pSub) { + return TRUE; + } else { return FALSE; } } diff --git a/src/ground_script_1.c b/src/ground_script_1.c index aa340e4f9..f21d6f0b9 100644 --- a/src/ground_script_1.c +++ b/src/ground_script_1.c @@ -1683,6 +1683,7 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0xd2 ... 0xd8: { + // DS: Assert(TRUE, "Script command call error SWITCH MENY") [sic] const char *out = curCmd.argPtr; gNumChoices = 0; scriptData->branchDiscriminant = 0; @@ -1765,21 +1766,21 @@ s32 ExecuteScriptCommand(Action *action) { case 0xe6: { scriptData->savedScript = scriptData->script; } //fallthrough - case 0xe7: { // ??? + case 0xe7: { scriptData->script.ptr = FindLabel(action, curCmd.argShort); break; } - case 0xe8: { // SAVE_AND_TRIGGER + case 0xe8: { scriptData->savedScript = scriptData->script; } // fallthrough - case 0xe9: { // TRIGGER + case 0xe9: { scriptData->script.ptr2 = scriptData->script.ptr = gFunctionScriptTable[curCmd.argShort].script; break; } - case 0xea: { // SAVE_AND_RUN_STATION + case 0xea: { scriptData->savedScript = scriptData->script; } // fallthrough - case 0xeb: { // RUN_STATION + case 0xeb: { ScriptInfoSmall info; u32 group, sector; u32 tmp = gUnknown_2039A34; @@ -1804,13 +1805,15 @@ s32 ExecuteScriptCommand(Action *action) { GroundMap_ExecuteEnter(gUnknown_2039A34); break; } - case 0xed: { // DELETE_SAVED + case 0xed: { + // DS: if (scriptData->savedScript.ptr == NULL) Assert(FALSE, "Script flash stack error"); scriptData->savedScript.ptr = NULL; scriptData->savedScript.ptr2 = NULL; break; } - case 0xee: { // RESTORE_SAVED + case 0xee: { if (scriptData->savedScript.ptr == NULL) { + // DS: Assert(FALSE, "Script return stack error"); return 0; } scriptData->script = scriptData->savedScript; @@ -1819,6 +1822,7 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0xef: + // DS: if (scriptData->savedScript.ptr != NULL) Assert(FALSE, "Script end stack error"); return 0; case 0xf0: return 1; diff --git a/src/ground_script_2.c b/src/ground_script_2.c index 004db16f8..2956ce789 100644 --- a/src/ground_script_2.c +++ b/src/ground_script_2.c @@ -10,51 +10,43 @@ extern u32 gUnlockBranchLabels[]; extern u8 gScriptLockConds[]; extern u8 gUnknown_8116848[]; -s32 GroundLivesNotifyAll(s16); -s32 GroundObjectsNotifyAll(s16); -s32 GroundEffectsNotifyAll(s16); +bool8 GroundLivesNotifyAll(s16); +bool8 GroundObjectsNotifyAll(s16); +bool8 GroundEffectsNotifyAll(s16); // TODO: this is still WIP -// void GroundScript_Unlock(void) -// { -// s32 index; -// u8 temp; -// s16 temp_s16; -// -// if(gAnyScriptLocked != 0) -// { -// gAnyScriptLocked = 0; -// for(index = 0; index < 0x81; index++) -// { -// if(gScriptLocks[index] != 0) -// { -// Log(1, gUnknown_8116848, index); -// temp = GroundMapNotifyAll(index); -// temp |= GroundLivesNotifyAll(index); -// temp |= GroundObjectsNotifyAll(index); -// temp |= GroundEffectsNotifyAll(index); -// -// if(gScriptLockConds[index] != 0) -// { -// if (temp != 0) -// { -// temp_s16 = index; -// temp_s16 |= 0x80; -// GroundMapNotifyAll(temp_s16); -// GroundLivesNotifyAll(temp_s16); -// GroundObjectsNotifyAll(temp_s16); -// GroundEffectsNotifyAll(temp_s16); -// gScriptLockConds[index] = 0; -// } -// } -// else { -// gScriptLocks[index] = 0; -// } -// } -// } -// } -// } +void GroundScript_Unlock(void) +{ + s32 index; + bool8 cond; + + if(gAnyScriptLocked == 0) return; + + gAnyScriptLocked = 0; + index = 0; + for (index = 0; index <= 0x80; index++) { + if(gScriptLocks[index] != 0) { + Log(1, gUnknown_8116848, index); + cond = GroundMapNotifyAll(index); + cond |= GroundLivesNotifyAll(index); + cond |= GroundObjectsNotifyAll(index); + cond |= GroundEffectsNotifyAll(index); + + if(gScriptLockConds[index] != 0) { + if (cond) { + GroundMapNotifyAll(index | 0x80); + GroundLivesNotifyAll(index | 0x80); + GroundObjectsNotifyAll(index | 0x80); + GroundEffectsNotifyAll(index | 0x80); + gScriptLocks[index] = gScriptLockConds[index] = 0; + } + } else { + gScriptLocks[index] = 0; + } + } + } +} const ScriptCommand *FindLabel(Action *action, s32 r1) { @@ -69,12 +61,12 @@ const ScriptCommand *FindLabel(Action *action, s32 r1) script = *scriptPtr; scriptPtr++; - if(script.op == 0xF4) - { - if(r1 == script.argShort) - return scriptPtr; - } + if(script.op == 0xF4 && r1 == script.argShort) break; + + // DS: Assert(script.op != 0, "script search label error %d", label) + // DS: Assert(script.op != 0xF6, "script search label error %d", label) } + return scriptPtr; } const ScriptCommand *ResolveJump(Action *action, s32 r1) From 8103f5e69394daa3acef6937d6632b0072e9f0be Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Sat, 16 Nov 2024 18:50:25 +0100 Subject: [PATCH 11/12] Address review comments --- src/code_806E8B0.c | 1 - src/ground_script_2.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/code_806E8B0.c b/src/code_806E8B0.c index ffcc4c37d..71b55a305 100644 --- a/src/code_806E8B0.c +++ b/src/code_806E8B0.c @@ -391,7 +391,6 @@ void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s3 #endif // NONMATCHING gDungeon->unk134.unk15C = arg8_Match = arg8; - //ASM_MATCH_TRICK(arg8); FP48_16_FromF248(&unkSp10, arg8_Match); F48_16_SMul(&unkSp8, &unkSp8, &unkSp10); } diff --git a/src/ground_script_2.c b/src/ground_script_2.c index 2956ce789..a5b63f7d8 100644 --- a/src/ground_script_2.c +++ b/src/ground_script_2.c @@ -14,8 +14,6 @@ bool8 GroundLivesNotifyAll(s16); bool8 GroundObjectsNotifyAll(s16); bool8 GroundEffectsNotifyAll(s16); -// TODO: this is still WIP - void GroundScript_Unlock(void) { s32 index; From a9ff59b103c2e606a24212041e8221f24f8a4d99 Mon Sep 17 00:00:00 2001 From: Mateon1 Date: Sat, 16 Nov 2024 19:29:02 +0100 Subject: [PATCH 12/12] Clean up related Tile stuff --- data/data_80F59C8.s | 8 ++++---- include/dungeon_map_access.h | 5 ----- src/dungeon_map_access.c | 18 +++++++++--------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/data/data_80F59C8.s b/data/data_80F59C8.s index 5a7191cc1..4bc061a0b 100644 --- a/data/data_80F59C8.s +++ b/data/data_80F59C8.s @@ -522,14 +522,14 @@ gUnknown_80F69A8: @ 80F69A8 .byte 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64 .byte 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 -.global gUnknown_80F69D4 -gUnknown_80F69D4: @ 80F69D4 +.global gOtherOobTile +gOtherOobTile: @ 80F69D4 @ replacing .incbin "baserom.gba", 0xF69D4, 0x18 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.global gUnknown_80F69EC -gUnknown_80F69EC: @ 80F69EC +.global gWaterOobTile +gWaterOobTile: @ 80F69EC @ replacing .incbin "baserom.gba", 0xF69EC, 0x18 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 diff --git a/include/dungeon_map_access.h b/include/dungeon_map_access.h index 5defb8029..3fe6c492e 100644 --- a/include/dungeon_map_access.h +++ b/include/dungeon_map_access.h @@ -3,11 +3,6 @@ #include "structs/map.h" -typedef struct unkStruct_202F190 -{ - Tile *unk0[6]; -} unkStruct_202F190; - const Tile *GetTile(s32 x, s32 y); Tile *GetTileMut(s32 x, s32 y); diff --git a/src/dungeon_map_access.c b/src/dungeon_map_access.c index 37a903e8c..c5d82dde6 100644 --- a/src/dungeon_map_access.c +++ b/src/dungeon_map_access.c @@ -16,8 +16,8 @@ #include "game_options.h" #include "dungeon_visibility.h" -extern const unkStruct_202F190 gUnknown_80F69D4; -extern const unkStruct_202F190 gUnknown_80F69EC; +extern const Tile gOtherOobTile; +extern const Tile gWaterOobTile; extern u8 gUnknown_80F6A04[]; extern u8 gUnknown_80F6A10[]; extern u8 gUnknown_80F6A28[]; @@ -32,9 +32,9 @@ extern const s16 gUnknown_80F6C06[]; EWRAM_DATA OpenedFile *gDungeonPaletteFile = {0}; EWRAM_DATA unkStruct_202EE8C gUnknown_202EE8C[32] = {0}; EWRAM_DATA OpenedFile *gUnknown_202F18C = {0}; -EWRAM_DATA unkStruct_202F190 gOutOfBoundsTileData = {0}; +EWRAM_DATA Tile gOutOfBoundsTileData = {0}; -EWRAM_DATA_2 const unkStruct_202F190 *gUnknown_203B430 = {0}; +EWRAM_DATA_2 const Tile *gCurTilesetOobTile = {0}; extern u8 sub_8043CE4(u32); extern void sub_80402AC(s32, s32); @@ -48,15 +48,15 @@ const Tile *GetTile(s32 x, s32 y) { return gDungeon->tilePointers[y][x]; } - return (Tile *) gUnknown_203B430->unk0; + return gCurTilesetOobTile; } Tile *GetTileMut(s32 x, s32 y) { if (x < 0 || y < 0 || x >= DUNGEON_MAX_SIZE_X || y >= DUNGEON_MAX_SIZE_Y) { - Tile *tile = (Tile *) gOutOfBoundsTileData.unk0; - gOutOfBoundsTileData = *gUnknown_203B430; + Tile *tile = &gOutOfBoundsTileData; + gOutOfBoundsTileData = *gCurTilesetOobTile; return tile; } return gDungeon->tilePointers[y][x]; @@ -139,10 +139,10 @@ void sub_8049820(void) void sub_8049840(void) { if (sub_8043CE4(gDungeon->tileset) != 0) { - gUnknown_203B430 = &gUnknown_80F69EC; + gCurTilesetOobTile = &gWaterOobTile; } else { - gUnknown_203B430 = &gUnknown_80F69D4; + gCurTilesetOobTile = &gOtherOobTile; } }