diff --git a/data/data.s b/data/data.s deleted file mode 100644 index 22d2638ad..000000000 --- a/data/data.s +++ /dev/null @@ -1,7 +0,0 @@ - .section .rodata - - .align 2, 0 - -@ ??? -.string "pksdir0\0" - .fill 28, 1, 0 diff --git a/include/code_8002774.h b/include/code_8002774.h deleted file mode 100644 index 69e492d90..000000000 --- a/include/code_8002774.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GUARD_CODE_8002774_H -#define GUARD_CODE_8002774_H - -#include "structs/str_position.h" - -void sub_800290C(PixelPos *param_1, s32 param_2); -void sub_8002934(PixelPos *param_1, PixelPos *param_2, PixelPos *param_3, s32 param_4, s32 param_5); -s32 sub_8002A70(s32 a0, s32 a1, s32 a2); -s32 sub_8002B04(s32, s32); -s32 VecDirection8Radial(PixelPos *param_1); -s8 SizedDeltaDirection4(const PixelPos *r0, const PixelPos *r1, const PixelPos *r2, const PixelPos *r3); -s8 SizedDeltaDirection8(const PixelPos *r0, const PixelPos *r1, const PixelPos *r2, const PixelPos *r3); - -#endif // GUARD_CODE_8002774_H diff --git a/include/direction_util.h b/include/direction_util.h new file mode 100644 index 000000000..a96f0f5a4 --- /dev/null +++ b/include/direction_util.h @@ -0,0 +1,14 @@ +#ifndef GUARD_DIRECTION_UTIL_H +#define GUARD_DIRECTION_UTIL_H + +#include "structs/str_position.h" + +s32 sub_8002984(s32 _direction1, u32 caseID); +s32 sub_8002A70(s32 _direction1, s32 _direction2, s32 _caseId); +s32 sub_8002B04(s32 _direction1, s32 _direction2); +PixelPos SetVecFromDirectionSpeed(s32 _dir, u32 speed); +s32 VecDirection8Radial(PixelPos *pixelPos); +s8 SizedDeltaDirection4(const PixelPos *p1, const PixelPos *p2, const PixelPos *p3, const PixelPos *p4); +s8 SizedDeltaDirection8(const PixelPos *p1, const PixelPos *p2, const PixelPos *p3, const PixelPos *p4); + +#endif // GUARD_DIRECTION_UTIL_H diff --git a/include/dungeon_ai_movement.h b/include/dungeon_ai_movement.h index 1b7df916f..c4c9c3035 100644 --- a/include/dungeon_ai_movement.h +++ b/include/dungeon_ai_movement.h @@ -9,5 +9,6 @@ bool8 ChooseTargetPosition(Entity *pokemon); void DecideMovement(Entity *pokemon, bool8 showRunAwayEffect); bool8 AvoidEnemies(Entity *pokemon); bool8 Wander(Entity *pokemon); +void sub_807BB78(Entity *pokemon); #endif diff --git a/include/pixelpos_math.h b/include/pixelpos_math.h new file mode 100644 index 000000000..dc7e77357 --- /dev/null +++ b/include/pixelpos_math.h @@ -0,0 +1,9 @@ +#ifndef GUARD_PIXELPOS_MATH_H +#define GUARD_PIXELPOS_MATH_H + +#include "structs/str_position.h" + +void ClampPixelPos(PixelPos *pos, s32 limit); +void InterpolatePixelPos(PixelPos *out, const PixelPos *a, const PixelPos *b, s32 weightA, s32 weightB); + +#endif // GUARD_PIXELPOS_MATH_H diff --git a/ld_script.ld b/ld_script.ld index 5656463f3..2d16116dc 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -52,7 +52,8 @@ SECTIONS { src/main_loops.o(.text); src/event_flag.o(.text); src/gba_color_util.o(.text); - src/code_8002774.o(.text); + src/pixelpos_math.o(.text); + src/direction_util.o(.text); src/memory.o(.text); src/palette_fade_util.o(.text); src/other_random.o(.text); @@ -429,8 +430,8 @@ SECTIONS { src/event_flag.o(.rodata); src/script_vars_info.o(.rodata); src/gba_color_util.o(.rodata); - data/data.o(.rodata); - src/code_8002774.o(.rodata); + src/pixelpos_math.o(.rodata); + src/direction_util.o(.rodata); data/pksdir_5.o(.rodata); src/memory.o(.rodata); src/palette_fade_util.o(.rodata); diff --git a/src/blow_away.c b/src/blow_away.c index 0953c8476..a25a7e078 100644 --- a/src/blow_away.c +++ b/src/blow_away.c @@ -34,9 +34,6 @@ #include "move_orb_effects_5.h" #include "expose_trap.h" -extern void sub_804EB30(); -extern void sub_807BB78(Entity *pokemon); - void BlowAwayTarget(Entity *pokemon, Entity *target, u32 direction) { bool8 flag; diff --git a/src/code_809D148.c b/src/code_809D148.c index 65b19a83d..cf978c03a 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -2,7 +2,7 @@ #include "globaldata.h" #include "code_809D148.h" #include "structs/str_position.h" -#include "code_8002774.h" +#include "pixelpos_math.h" #include "math.h" #include "memory.h" #include "other_random.h" @@ -218,7 +218,7 @@ void sub_809D25C(void) case 1: sp4.x = sUnknown_20399E8.unk1C.x - sUnknown_20399E8.unk14.x; sp4.y = sUnknown_20399E8.unk1C.y - sUnknown_20399E8.unk14.y; - sub_800290C(&sp4, sUnknown_20399E8.unkC); + ClampPixelPos(&sp4, sUnknown_20399E8.unkC); if (sp4.x == 0 && sp4.y == 0) { sUnknown_20399E8.unk8 = 0; @@ -238,7 +238,7 @@ void sub_809D25C(void) sUnknown_20399E8.unk8 = 2; // Breakthrough case 2: - sub_8002934(&spC, &sUnknown_20399E8.unk14, &sUnknown_20399E8.unk1C, sUnknown_20399E8.unk10, 1); + InterpolatePixelPos(&spC, &sUnknown_20399E8.unk14, &sUnknown_20399E8.unk1C, sUnknown_20399E8.unk10, 1); sUnknown_20399E8.unk14 = spC; if (--sUnknown_20399E8.unk10 <= 0) sUnknown_20399E8.unk8 = 0; diff --git a/src/debug_field_map.c b/src/debug_field_map.c index 4f129fb44..5b3b5d43d 100644 --- a/src/debug_field_map.c +++ b/src/debug_field_map.c @@ -18,10 +18,10 @@ #include "input.h" #include "structs/str_position.h" #include "code_809D148.h" +#include "direction_util.h" extern void sub_8012A18(s32 unused); extern void sub_80999E8(s32 a0); -extern PixelPos SetVecFromDirectionSpeed(s8 r1, u32 r2); UNUSED static void DebugMapViewer(void) { diff --git a/src/code_8002774.c b/src/direction_util.c similarity index 60% rename from src/code_8002774.c rename to src/direction_util.c index 4c0175283..304ced132 100644 --- a/src/code_8002774.c +++ b/src/direction_util.c @@ -1,13 +1,13 @@ #include "global.h" #include "globaldata.h" -#include "code_8002774.h" +#include "direction_util.h" #include "constants/direction.h" #include "structs/str_position.h" #include "other_random.h" -const u8 sUnknown_8002774[] = {0, 0, 0, 0, 0, 0, 0, 0}; +UNUSED static const u8 sUnusedZeroArray[] = {0, 0, 0, 0, 0, 0, 0, 0}; -const PixelPos gVectorDirections[NUM_DIRECTIONS] = { +static const PixelPos sVectorDirections[NUM_DIRECTIONS] = { {0, 1}, // N {1, 1}, // NE {1, 0}, // E @@ -18,47 +18,10 @@ const PixelPos gVectorDirections[NUM_DIRECTIONS] = { {-1, 1}, // NW }; + static s8 VecDirection4Radial(PixelPos *pixelPos); - -// TODO: File split here - - - - -// arm9.bin::02010314 -void sub_800290C(PixelPos *param_1, s32 param_2) -{ - if (param_1->x > param_2) - param_1->x = param_2; - else if (param_1->x < -param_2) - param_1->x = -param_2; - - if (param_1->y > param_2) - param_1->y = param_2; - else if(param_1->y < -param_2) - param_1->y = -param_2; -} - -// arm9.bin::020102B8 -void sub_8002934(PixelPos *param_1, PixelPos *param_2, PixelPos *param_3, s32 param_4, s32 param_5) -{ - s32 r9 = (param_4 + param_5); - param_1->x = (param_4 * param_2->x + param_5 * param_3->x) / r9; - param_1->y = (param_4 * param_2->y + param_5 * param_3->y) / r9; -} - - - - -// TODO: File split here - - - - - - -static inline s8 sub_8002984_sub(s32 direction1, s32 rand, s32 add, s32 multi) +static inline s8 GetRandomizedDirection(s32 direction1, s32 rand, s32 add, s32 multi) { return (s8)(((direction1 + add) + OtherRandInt(rand) * multi) % NUM_DIRECTIONS); } @@ -66,62 +29,59 @@ static inline s8 sub_8002984_sub(s32 direction1, s32 rand, s32 add, s32 multi) // arm9.bin::020109F4 s32 sub_8002984(s32 _direction1, u32 caseID) { - s32 direction1; - - direction1 = (s8)_direction1; - switch((u8)caseID) { - case 1: - if (direction1 >= 0) { - direction1 += 7; - direction1 &= DIRECTION_MASK; - } - break; - case 2: - if (direction1 >= 0) { - direction1 += 1; - direction1 &= DIRECTION_MASK; - } - break; - case 3: - if (direction1 >= 0) { - direction1 += 6; - direction1 &= DIRECTION_MASK; - } - break; - case 4: - if (direction1 >= 0) { - direction1 += 2; - direction1 &= DIRECTION_MASK; - } - break; - case 5: - if (direction1 >= 0) { - direction1 += 4; - direction1 &= DIRECTION_MASK; - } - break; - case 6: - if ((direction1 & 1) != 0) { - direction1 = sub_8002984_sub(direction1, 2, 7, 2); - } - else - { - direction1 = sub_8002984_sub(direction1, 3, 6, 2); - } - break; - case 7: - direction1 = sub_8002984_sub(direction1, 3, 7, 1); - break; - case 8: - direction1 = (s8)(OtherRandInt(NUM_DIRECTIONS) & 0xfe); - break; - case 9: - direction1 = (s8)OtherRandInt(NUM_DIRECTIONS); - break; - default: - break; - } - return direction1; + s32 direction1 = (s8) _direction1; + switch((u8)caseID) { + case 1: + if (direction1 >= 0) { + direction1 += 7; + direction1 &= DIRECTION_MASK; + } + break; + case 2: + if (direction1 >= 0) { + direction1 += 1; + direction1 &= DIRECTION_MASK; + } + break; + case 3: + if (direction1 >= 0) { + direction1 += 6; + direction1 &= DIRECTION_MASK; + } + break; + case 4: + if (direction1 >= 0) { + direction1 += 2; + direction1 &= DIRECTION_MASK; + } + break; + case 5: + if (direction1 >= 0) { + direction1 += 4; + direction1 &= DIRECTION_MASK; + } + break; + case 6: + if ((direction1 & 1) != 0) { + direction1 = GetRandomizedDirection(direction1, 2, 7, 2); + } + else { + direction1 = GetRandomizedDirection(direction1, 3, 6, 2); + } + break; + case 7: + direction1 = GetRandomizedDirection(direction1, 3, 7, 1); + break; + case 8: + direction1 = (s8)(OtherRandInt(NUM_DIRECTIONS) & 0xfe); + break; + case 9: + direction1 = (s8) OtherRandInt(NUM_DIRECTIONS); + break; + default: + break; + } + return direction1; } // arm9.bin::020108EC @@ -219,11 +179,12 @@ UNUSED static s32 sub_8002B5C(s32 _direction1, s32 _direction2) #endif // arm9.bin::02010790 -PixelPos SetVecFromDirectionSpeed(s8 r1, u32 r2) +PixelPos SetVecFromDirectionSpeed(s32 _dir, u32 speed) { - const PixelPos *vec = &gVectorDirections[r1]; + s32 dir = (s8) _dir; + const PixelPos *vec = &sVectorDirections[dir]; - return (PixelPos){ .x = vec->x * r2, .y = vec->y * r2 }; + return (PixelPos){ .x = vec->x * speed, .y = vec->y * speed }; } UNUSED static s32 VecDirection8Sign(PixelPos *param_1) @@ -366,89 +327,83 @@ static s8 VecDirection4Radial(PixelPos *pixelPos) } // arm9.bin::02010478 -s8 SizedDeltaDirection4(const PixelPos *r0, const PixelPos *r1, const PixelPos *r2, const PixelPos *r3) +s8 SizedDeltaDirection4(const PixelPos *p1, const PixelPos *p2, const PixelPos *p3, const PixelPos *p4) { - PixelPos stack; - s32 iVar1; - s32 iVar2; - s32 iVar3; + PixelPos newPos; - stack.x = r2->x - r0->x; - stack.y = r2->y - r0->y; + newPos.x = p3->x - p1->x; + newPos.y = p3->y - p1->y; - if(stack.x >= 0) - { - iVar3 = (stack.x + 1); - iVar3 -= ((r1->x + r3->x) / 2); - stack.x = iVar3; - if(stack.x < 0) stack.x = 0; + if (newPos.x >= 0) { + s32 x = (newPos.x + 1); + x -= ((p2->x + p4->x) / 2); + newPos.x = x; + if (newPos.x < 0) + newPos.x = 0; } - else - { - iVar1 = (stack.x - 1); - iVar1 += ((r1->x + r3->x) / 2); - stack.x = iVar1; - if(stack.x > 0) stack.x = 0; + else { + s32 x = (newPos.x - 1); + x += ((p2->x + p4->x) / 2); + newPos.x = x; + if (newPos.x > 0) + newPos.x = 0; } - if(stack.y >= 0) - { - iVar2 = (stack.y + 1); - iVar2 -= ((r1->y + r3->y) / 2); - stack.y = iVar2; - if(stack.y < 0) stack.y = 0; + if (newPos.y >= 0) { + s32 y = (newPos.y + 1); + y -= ((p2->y + p4->y) / 2); + newPos.y = y; + if (newPos.y < 0) + newPos.y = 0; } - else - { - iVar1 = (stack.y - 1); - iVar1 += ((r1->y + r3->y) / 2); - stack.y = iVar1; - if(stack.y > 0) stack.y = 0; + else { + s32 y = (newPos.y - 1); + y += ((p2->y + p4->y) / 2); + newPos.y = y; + if (newPos.y > 0) + newPos.y = 0; } - return VecDirection4Radial(&stack); + return VecDirection4Radial(&newPos); } // arm9.bin::02010350 -s8 SizedDeltaDirection8(const PixelPos *r0, const PixelPos *r1, const PixelPos *r2, const PixelPos *r3) +s8 SizedDeltaDirection8(const PixelPos *p1, const PixelPos *p2, const PixelPos *p3, const PixelPos *p4) { - PixelPos stack; - s32 iVar1; - s32 iVar2; - s32 iVar3; + PixelPos newPos; - stack.x = r2->x - r0->x; - stack.y = r2->y - r0->y; + newPos.x = p3->x - p1->x; + newPos.y = p3->y - p1->y; - if (stack.x >= 0) { - iVar3 = stack.x + 1; - iVar3 -= (r1->x + r3->x) / 2; - stack.x = iVar3; - if (stack.x < 0) - stack.x = 0; + if (newPos.x >= 0) { + s32 x = newPos.x + 1; + x -= (p2->x + p4->x) / 2; + newPos.x = x; + if (newPos.x < 0) + newPos.x = 0; } else { - iVar1 = stack.x - 1; - iVar1 += (r1->x + r3->x) / 2; - stack.x = iVar1; - if (stack.x > 0) - stack.x = 0; + s32 x = newPos.x - 1; + x += (p2->x + p4->x) / 2; + newPos.x = x; + if (newPos.x > 0) + newPos.x = 0; } - if (stack.y >= 0) { - iVar2 = stack.y + 1; - iVar2 -= (r1->y + r3->y) / 2; - stack.y = iVar2; - if (stack.y < 0) - stack.y = 0; + if (newPos.y >= 0) { + s32 y = newPos.y + 1; + y -= (p2->y + p4->y) / 2; + newPos.y = y; + if (newPos.y < 0) + newPos.y = 0; } else { - iVar1 = stack.y - 1; - iVar1 += (r1->y + r3->y) / 2; - stack.y = iVar1; - if (stack.y > 0) - stack.y = 0; + s32 y = newPos.y - 1; + y += (p2->y + p4->y) / 2; + newPos.y = y; + if (newPos.y > 0) + newPos.y = 0; } - return (s8) VecDirection8Radial(&stack); + return (s8) VecDirection8Radial(&newPos); } diff --git a/src/dungeon_cutscene.c b/src/dungeon_cutscene.c index 56534c386..7a3154f85 100644 --- a/src/dungeon_cutscene.c +++ b/src/dungeon_cutscene.c @@ -37,6 +37,7 @@ #include "dungeon_tilemap.h" #include "dungeon_map.h" #include "dungeon_mon_spawn.h" +#include "direction_util.h" struct RgbS16 { @@ -56,8 +57,6 @@ extern void sub_8088848(void); extern void sub_808A718(void); extern s32 sub_800E700(s32); extern void sub_8052FB8(const u8 *); -extern u32 sub_8002A70(u32, s32, u8); -extern s8 sub_8002984(s8, u8); struct unkData_8107234 { @@ -1919,25 +1918,14 @@ void sub_808692C(void) void SpriteLookAroundEffect(Entity *entity) { - s8 r4; - s8 r3; - - r4 = sub_8002984(GetEntInfo(entity)->action.direction, 4); - - sub_80869E4(entity, 4, 2, r4); + s8 dir = sub_8002984((s8) GetEntInfo(entity)->action.direction, 4); + sub_80869E4(entity, 4, 2, dir); sub_803E708(15, 70); - - r4 = sub_8002984(r4, 5); - - sub_80869E4(entity, 4, 1, r4); - + dir = sub_8002984(dir, 5); + sub_80869E4(entity, 4, 1, dir); sub_803E708(15, 70); - - r3 = sub_8002984(r4, 4); - - sub_80869E4(entity, 4, 2, r3); - + sub_80869E4(entity, 4, 2, (s8) sub_8002984(dir, 4)); sub_803E708(15, 70); } diff --git a/src/ground_lives.c b/src/ground_lives.c index 0589dd29b..a8961df75 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -14,7 +14,7 @@ #include "debug.h" #include "other_random.h" #include "text_util.h" -#include "code_8002774.h" +#include "direction_util.h" #include "friend_area_dialogue.h" #include "ground_lives_helper.h" #include "ground_sprite_monster.h" @@ -109,7 +109,6 @@ extern const struct GroundLiveTypeData gGroundLivesTypeData_811E63C[]; extern s32 sub_8002984(s32 _direction1, u32 caseID); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); -extern PixelPos SetVecFromDirectionSpeed(s32 r1, u32 r2); extern Pokemon *sub_80A8D54(s32); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); diff --git a/src/ground_script.c b/src/ground_script.c index a3de80601..2ef43f74f 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -6,7 +6,8 @@ #include "constants/item.h" #include "constants/monster.h" #include "constants/move_id.h" -#include "code_8002774.h" +#include "direction_util.h" +#include "pixelpos_math.h" #include "music_util.h" #include "code_8099360.h" #include "code_8094F88.h" @@ -58,10 +59,8 @@ // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files -char sub_8002984(s32, u8); bool8 sub_802FCF0(void); bool8 sub_8099B94(void); -PixelPos SetVecFromDirectionSpeed(s8, s32); bool8 sub_80961D8(void); void ResetMailbox(void); void sub_80963FC(void); @@ -584,7 +583,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) action->callbacks->getHitboxCenter(action->parentObject, &pos); pos2.x = action->scriptData.pos2.x - pos.x; pos2.y = action->scriptData.pos2.y - pos.y; - sub_800290C(&pos2, action->scriptData.unk30); + ClampPixelPos(&pos2, action->scriptData.unk30); if (pos2.x == 0 && pos2.y == 0) { action->scriptData.savedState = 3; break; @@ -618,7 +617,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) action->callbacks->getHitboxCenter(action->parentObject, &pos); pos2.x = action->scriptData.pos2.x - pos.x; pos2.y = action->scriptData.pos2.y - pos.y; - sub_800290C(&pos2, action->scriptData.unk30); + ClampPixelPos(&pos2, action->scriptData.unk30); if (pos2.x == 0 && pos2.y == 0) { action->scriptData.savedState = 3; break; @@ -653,7 +652,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) case 0x7d ... 0x82: { if (action->scriptData.unk2A > 0) { PixelPos pos; - sub_8002934(&pos, &action->scriptData.pos1, &action->scriptData.pos2, action->scriptData.unk2A, action->scriptData.unk2C); + InterpolatePixelPos(&pos, &action->scriptData.pos1, &action->scriptData.pos2, action->scriptData.unk2A, action->scriptData.unk2C); action->callbacks->moveReal(action->parentObject, &pos); action->callbacks->setEventIndex(action->parentObject, 0x1000); action->scriptData.unk2A--; @@ -674,7 +673,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) s8 dirS8; action->callbacks->getHitboxCenter(action->parentObject, &pos1); - sub_8002934(&pos2, &action->scriptData.pos1, &action->scriptData.pos2, action->scriptData.unk2A, action->scriptData.unk2C); + InterpolatePixelPos(&pos2, &action->scriptData.pos1, &action->scriptData.pos2, action->scriptData.unk2A, action->scriptData.unk2C); pos3.x = pos2.x - pos1.x; pos3.y = pos2.y - pos1.y; dir = (s8) VecDirection8Radial(&pos3); @@ -2279,7 +2278,7 @@ static s32 ExecuteScriptCommand(Action *action) case 0x8a: { s8 dir; action->callbacks->getDirection(action->parentObject, &dir); - action->scriptData.unk26 = sub_8002984(dir, (s8)curCmd.arg1); + action->scriptData.unk26 = sub_8002984(dir, (u8)curCmd.arg1); action->callbacks->setDirection(action->parentObject, action->scriptData.unk26); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = (u8)curCmd.argByte; @@ -2296,7 +2295,7 @@ static s32 ExecuteScriptCommand(Action *action) s8 dir; if (ret >= 0) { sub_80A9050(ret, &dir); - action->scriptData.unk26 = sub_8002984(dir, curCmd.argShort); + action->scriptData.unk26 = sub_8002984(dir, (u8)curCmd.argShort); action->callbacks->setDirection(action->parentObject, action->scriptData.unk26); } scriptData->unk2A = (u8)curCmd.argByte; @@ -2305,7 +2304,7 @@ static s32 ExecuteScriptCommand(Action *action) case 0x8d: { s8 dir; action->callbacks->getDirection(action->parentObject, &dir); - action->scriptData.unk26 = sub_8002984(dir, curCmd.argShort); + action->scriptData.unk26 = sub_8002984(dir, (u8)curCmd.argShort); action->callbacks->setDirection(action->parentObject, action->scriptData.unk26); scriptData->unk2A = (u8)curCmd.argByte; return 2; @@ -2356,7 +2355,7 @@ static s32 ExecuteScriptCommand(Action *action) if (dir == tmp) { action->callbacks->getDirection(action->parentObject, &dir); } - action->scriptData.unk26 = sub_8002984(dir, (s8)curCmd.argShort); + action->scriptData.unk26 = sub_8002984(dir, (u8)curCmd.argShort); action->callbacks->setDirection(action->parentObject, action->scriptData.unk26); } scriptData->unk2A = (u8)curCmd.argByte; @@ -2374,7 +2373,7 @@ static s32 ExecuteScriptCommand(Action *action) case 0x92: { s8 unk; action->callbacks->getDirection(action->parentObject, &unk); - action->scriptData.unk4D = sub_8002984(unk, (s8)curCmd.arg1); + action->scriptData.unk4D = sub_8002984(unk, (u8)curCmd.arg1); scriptData->unk2A = 0; return 2; } @@ -3719,7 +3718,7 @@ static s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) if((s8)dir != -1) { s32 to; - sp_368 = SetVecFromDirectionSpeed(dir,0x100); + sp_368 = SetVecFromDirectionSpeed((s8) dir,0x100); to = 2; if(held & B_BUTTON) { diff --git a/src/pixelpos_math.c b/src/pixelpos_math.c new file mode 100644 index 000000000..269acc12b --- /dev/null +++ b/src/pixelpos_math.c @@ -0,0 +1,27 @@ +#include "global.h" +#include "globaldata.h" +#include "pixelpos_math.h" + +UNUSED static const u8 sUnusedZeroArray[28] = {0}; + +// arm9.bin::02010314 +void ClampPixelPos(PixelPos *pos, s32 limit) +{ + if (pos->x > limit) + pos->x = limit; + else if (pos->x < -limit) + pos->x = -limit; + + if (pos->y > limit) + pos->y = limit; + else if (pos->y < -limit) + pos->y = -limit; +} + +// arm9.bin::020102B8 +void InterpolatePixelPos(PixelPos *out, const PixelPos *a, const PixelPos *b, s32 weightA, s32 weightB) +{ + s32 weight = (weightA + weightB); + out->x = (weightA * a->x + weightB * b->x) / weight; + out->y = (weightA * a->y + weightB * b->y) / weight; +} diff --git a/src/warp_target.c b/src/warp_target.c index 886f26874..f7eefb725 100644 --- a/src/warp_target.c +++ b/src/warp_target.c @@ -28,9 +28,7 @@ #include "dungeon_kecleon_shop.h" #include "dungeon_range.h" #include "move_orb_effects_5.h" - -void sub_80421AC(Entity * pokemon, Entity * target); -void sub_807BB78(Entity *pokemon); +#include "dungeon_ai_movement.h" void WarpTarget(Entity *pokemon, Entity *target, u32 param_3, DungeonPos *pos) {